//=============================================================================
// Fly.
//=============================================================================
class Fly expands ScriptedPawn;

#exec MESH IMPORT MESH=Fly ANIVFILE=MODELS\fly_a.3D DATAFILE=MODELS\fly_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=Fly X=0 Y=-30 Z=70 YAW=64 ROLL=-62

#exec MESH SEQUENCE MESH=Fly SEQ=All      STARTFRAME=0     NUMFRAMES=118
#exec MESH SEQUENCE MESH=Fly SEQ=Dead     STARTFRAME=0     NUMFRAMES=16
#exec MESH SEQUENCE MESH=Fly SEQ=TakeHit  STARTFRAME=0     NUMFRAMES=1
#exec MESH SEQUENCE MESH=Fly SEQ=Flying   STARTFRAME=16    NUMFRAMES=20
#exec MESH SEQUENCE MESH=Fly SEQ=Land     STARTFRAME=36    NUMFRAMES=21
#exec MESH SEQUENCE MESH=Fly SEQ=Shoot1   STARTFRAME=57    NUMFRAMES=25   Group=Attack
#exec MESH SEQUENCE MESH=Fly SEQ=Takeoff  STARTFRAME=82    NUMFRAMES=25
#exec MESH SEQUENCE MESH=Fly SEQ=Waiting  STARTFRAME=108   NUMFRAMES=1
#exec MESH SEQUENCE MESH=Fly SEQ=Walking  STARTFRAME=107   NUMFRAMES=10

#exec TEXTURE IMPORT NAME=JFly1 FILE=MODELS\fly.PCX GROUP=Skins FLAGS=2
#exec MESHMAP SCALE MESHMAP=fly X=0.06 Y=0.06 Z=0.12
#exec MESHMAP SETTEXTURE MESHMAP=fly NUM=1 TEXTURE=Jfly1

#exec AUDIO IMPORT FILE="Sounds\Razorfly\buzz3rf.WAV" NAME="buzz3rf" GROUP="Razorfly"
#exec AUDIO IMPORT FILE="Sounds\Razorfly\injur1rf.WAV" NAME="injur1rf" GROUP="Razorfly"
#exec AUDIO IMPORT FILE="Sounds\Razorfly\injur2rf.WAV" NAME="injur2rf" GROUP="Razorfly"
#exec AUDIO IMPORT FILE="Sounds\Razorfly\death1rf.WAV" NAME="death1rf" GROUP="Razorfly"


//-----------------------------------------------------------------------------
// Fly variables.

//-----------------------------------------------------------------------------
// Fly functions.

function PreSetMovement()
{
	bCanJump = true;
	bCanWalk = true;
	bCanSwim = false;
	bCanFly = true;
	MinHitWall = -0.6;
	bCanOpenDoors = false;
	bCanDoSpecial = false;
}

function SetMovementPhysics()
{
	if (Enemy != None)
		SetPhysics(PHYS_Flying); 
	else if (Physics != PHYS_Falling)
		SetPhysics(PHYS_Walking);
}

singular function Falling()
{
	SetPhysics(PHYS_Flying);
	if (bIsPlayer)
	{
		PlayInAir();
		return;
	}
		
	if (health > 0)
		SetFall();
}

function PlayWaiting()
{
	if ( Physics == PHYS_Walking )
		TweenAnim('Waiting', 10.0);
	else
		LoopAnim('Flying', 0.4);
}

function PlayPatrolStop()
{
	PlayWaiting();
}

function PlayWaitingAmbush()
{
	PlayWaiting();
}

function PlayChallenge()
{
	PlayAnim('Shoot1', 1.0, 0.1);
}

function TweenToFighter(float tweentime)
{
	TweenAnim('Flying', tweentime);
}

function TweenToRunning(float tweentime)
{
	if ( (AnimSequence != 'Flying') || !bAnimLoop )
		TweenAnim('Flying', tweentime);
}

function TweenToWalking(float tweentime)
{
	if (Physics == PHYS_Walking)
		TweenAnim('Walking', tweentime);
	else if ( (AnimSequence != 'Flying') || !bAnimLoop )
		TweenAnim('Flying', tweentime);
}

function TweenToWaiting(float tweentime)
{
	PlayAnim('Land', 0.2 + 0.5 * FRand());
	SetPhysics(PHYS_Falling);
}

function TweenToPatrolStop(float tweentime)
{
	TweenAnim('Flying', tweentime);
}

function PlayRunning()
{
	LoopAnim('Flying');
}

function PlayWalking()
{
	if (Physics == PHYS_Walking)
		LoopAnim('Walking', -1.0/GroundSpeed,, 0.4);
	else
		LoopAnim('Flying');
}

function PlayThreatening()
{
	if ( FRand() < 0.8 )
		LoopAnim('Flying');
	else
		LoopAnim('Shoot1', 0.4);
}

function PlayTurning()
{
	if (Physics == PHYS_Walking)
		LoopAnim('Walking');
	else
		LoopAnim('Flying');
}

function PlayDying(name DamageType, vector HitLocation)
{
	PlaySound(Die, SLOT_Talk);
	PlayAnim('Dead', 0.7, 0.1);
}

function PlayTakeHit(float tweentime, vector HitLoc, int damage)
{
	TweenAnim('TakeHit', tweentime);
}

function TweenToFalling()
{
	TweenAnim('Flying', 0.2);
}

function PlayInAir()
{
	LoopAnim('Flying');
}

function PlayLanded(float impactVel)
{
	PlayAnim('Land');
}

function PlayVictoryDance()
{
	if ( FRand() < 0.4 )
		TweenToWaiting(0.25);
	else
		PlayAnim('Flying',1.0, 0.05);

}
	
function PlayMeleeAttack()
{
	PlayAnim('Shoot1');
	if ( MeleeDamageTarget(15, (15 * 1000.0 * Normal(Target.Location - Location))) )
		PlaySound(Threaten, SLOT_Talk); //FIXME - stingdamage instead of projectile
	Acceleration = AccelRate * Normal(Location - Enemy.Location);
	Acceleration.Z *= 0.5;
}

function PlayRangedAttack()
{
	local vector projStart;
	local vector adjust;

	PlayAnim('Shoot1');
	/*
	adjust = vect(0,0,0);
	adjust.Z = Target.CollisionHeight + 20;
	Acceleration = AccelRate * Normal(Target.Location - Location + adjust);
	projStart = Location - 0.5 * CollisionHeight * vect(0,0,1);
	spawn(RangedProjectile ,self,'',projStart,AdjustAim(ProjectileSpeed, projStart, 400, false, false));
	*/
}

function PlayMovingAttack()
{
	PlayRangedAttack();
}

state Roaming
{
	function PickDestination()
	{
		GotoState('Wandering');
	}

Begin:
	GotoState('Wandering');
}

