UnrealShare
Class BiterFish

source: e:\games\UnrealTournament\UnrealShare\Classes\BiterFish.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Pawn
         |
         +--UnrealShare.FlockPawn
            |
            +--UnrealShare.BiterFish
Direct Known Subclasses:None

class BiterFish
extends UnrealShare.FlockPawn

//============================================================================= // BiterFish. // Do not add directly - rather add BiterFishSchools to the world //=============================================================================
Variables
 float AirTime
 byte BiteDamage
 Texture FishSkins[6]
 vector OldSchoolDestination
 BiterFishSchool School

States
Dying, Flopping, Swimming

Function Summary
 void Died(Pawn Killer, name damageType, vector HitLocation)
 void FootZoneChange(ZoneInfo newFootZone)
 void Landed(vector HitNormal)
 void PostBeginPlay()
 void PreSetMovement()
 void TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
 void ZoneChange(ZoneInfo NewZone)


State Dying Function Summary
 void Timer()
 void Landed(vector HitNormal)


State Flopping Function Summary
 void BeginState()
 void AnimEnd()
 void Timer()
 void Landed(vector HitNormal)


State Swimming Function Summary
 void Touch(Actor Other)
 void PickDestination()



Source Code


00001	//=============================================================================
00002	// BiterFish.
00003	// Do not add directly - rather add BiterFishSchools to the world
00004	//=============================================================================
00005	class BiterFish extends FlockPawn;
00006	
00007	#exec MESH IMPORT MESH=AmbientFish ANIVFILE=MODELS\fish1_a.3D DATAFILE=MODELS\fish1_d.3D ZEROTEX=1
00008	#exec MESH ORIGIN MESH=AmbientFish X=00 Y=-20 Z=00 YAW=-64
00009	
00010	#exec MESH SEQUENCE MESH=AmbientFish SEQ=All    STARTFRAME=0   NUMFRAMES=11
00011	#exec MESH SEQUENCE MESH=AmbientFish SEQ=Swim1  STARTFRAME=0   NUMFRAMES=8
00012	#exec MESH SEQUENCE MESH=AmbientFish SEQ=Bite   STARTFRAME=8   NUMFRAMES=3
00013	
00014	#exec TEXTURE IMPORT NAME=Jfish21  FILE=MODELS\fish1.PCX GROUP=Skins 
00015	#exec MESHMAP SCALE MESHMAP=AmbientFish X=0.06 Y=0.06 Z=0.12
00016	#exec MESHMAP SETTEXTURE MESHMAP=AmbientFish NUM=0 TEXTURE=Jfish21 TLOD=200 
00017	
00018	#exec TEXTURE IMPORT NAME=Jfish22  FILE=MODELS\fish2.PCX GROUP=Skins 
00019	#exec TEXTURE IMPORT NAME=Jfish23  FILE=MODELS\fish3.PCX GROUP=Skins 
00020	#exec TEXTURE IMPORT NAME=Jfish24  FILE=MODELS\fish4.PCX GROUP=Skins 
00021	#exec TEXTURE IMPORT NAME=Jfish25  FILE=MODELS\fish5.PCX GROUP=Skins 
00022	#exec TEXTURE IMPORT NAME=Jfish26  FILE=MODELS\fish6.PCX GROUP=Skins 
00023	
00024	var() byte BiteDamage;
00025	var float AirTime;
00026	var vector OldSchoolDestination;
00027	var BiterFishSchool School;
00028	var texture FishSkins[6];
00029	
00030	function PostBeginPlay()
00031	{
00032		School = BiterfishSchool(Owner); 
00033		Super.PostBeginPlay();
00034		if ( School == None )
00035		{
00036			log("Warning - can't add biterfish independently from biterfish schools");
00037			destroy();
00038		}
00039		else if ( School.fishcolor > 5 )
00040			skin = FishSkins[Rand(6)];
00041		else
00042			skin = FishSkins[School.fishcolor];
00043	}
00044	
00045	function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, 
00046							Vector momentum, name damageType)
00047	{
00048		local bool bAlreadyDead;
00049	
00050		bAlreadyDead = (Health <= 0);
00051	
00052		if (Physics == PHYS_None)
00053			SetMovementPhysics();
00054		if (Physics == PHYS_Walking)
00055			momentum.Z = 0.4 * Vsize(momentum);
00056		if ( instigatedBy == self )
00057			momentum *= 0.6;
00058		momentum = momentum/Mass;
00059		AddVelocity( momentum ); 
00060		Health -= Damage;
00061		if ( Health < -20 )
00062		{
00063			Spawn(class'Bloodspurt');
00064			Destroy();
00065		}
00066		else if ( !bAlreadyDead && (Health < 0) )
00067			Died(instigatedBy, damageType, hitLocation);
00068	}
00069	
00070	function Landed(vector HitNormal)
00071	{
00072		local rotator newRotation;
00073	
00074		SetPhysics(PHYS_None);
00075		SetTimer(0.2 + FRand(), false);
00076		newRotation = Rotation;
00077		newRotation.Pitch = 0;
00078		newRotation.Roll = 16384;
00079		SetRotation(newRotation);
00080		GotoState('Flopping');
00081	}
00082	
00083	function PreSetMovement()
00084	{
00085		bCanSwim = true;
00086		if (Region.Zone.bWaterZone)
00087			SetPhysics(PHYS_Swimming);
00088		else
00089			SetPhysics(PHYS_Falling);
00090		MinHitWall = -0.6;
00091	}
00092	
00093	function ZoneChange( ZoneInfo NewZone )
00094	{
00095		local rotator newRotation;
00096		if (NewZone.bWaterZone)
00097		{
00098			if ( !Region.Zone.bWaterZone && (Physics != PHYS_Swimming) )
00099			{
00100				newRotation = Rotation;
00101				newRotation.Roll = 0;
00102				SetRotation(newRotation);
00103				MoveTimer = -1.0;
00104			}
00105			AirTime = 0;
00106			SetPhysics(PHYS_Swimming);
00107			if ( !IsInState('Swimming') ) 
00108				GotoState('Swimming');
00109		}
00110		else if (Physics != PHYS_Falling)
00111		{
00112			MoveTimer = -1;
00113			SetPhysics(PHYS_Falling);
00114		}
00115	}
00116	
00117	function FootZoneChange(ZoneInfo newFootZone)
00118	{
00119		if ( (Level.TimeSeconds - SplashTime > 3) && 
00120		 	!FootRegion.Zone.bWaterZone && newFootZone.bWaterZone )
00121		{
00122			SplashTime = Level.TimeSeconds;
00123			PlaySound(sound 'LSplash', SLOT_Interact, 0.4,,500);
00124			Spawn(class 'WaterImpact',,,Location - CollisionHeight * vect(0,0,1));
00125		}
00126		
00127		if ( FootRegion.Zone.bPainZone )
00128		{
00129			if ( !newFootZone.bPainZone )
00130				PainTime = -1.0;
00131		}
00132		else if (newFootZone.bPainZone)
00133			PainTime = 0.01;
00134	}
00135	
00136	function Died(pawn Killer, name damageType, vector HitLocation)
00137	{
00138		local rotator newRot;
00139	
00140		newRot = Rotation;
00141		if ( FRand() < 0.5 )
00142			newRot.Roll = 16384;
00143		else 
00144			newRot.Roll = -16384;
00145		SetRotation(newRot);
00146		SetPhysics(PHYS_Falling);
00147		SetCollision(true,false,false);
00148		Buoyancy = 1.05 * mass;
00149		Velocity.Z = FMax(0, Velocity.Z);
00150		AnimRate = 0.0;
00151	
00152		school.FishDied();
00153		RemoteRole = ROLE_DumbProxy;
00154		GotoState('Dying');
00155	}
00156	
00157	Auto State Swimming
00158	{
00159		function PickDestination()
00160		{
00161			if ( (School.IsInState('Stasis')) && !PlayerCanSeeMe() )
00162			{
00163				School.Remove(self);
00164				return;
00165			}
00166			if ( School.validDest )
00167				OldSchoolDestination = School.Location;
00168			Destination = OldSchoolDestination +
00169				 0.5 * School.schoolradius * ( Normal(Location - School.Location) + VRand());
00170		}
00171	
00172		function Touch(Actor Other)
00173		{
00174			if ( Pawn(Other) == School.Enemy )
00175				Other.TakeDamage(2, self, location, vect(0,0,0), 'bitten');
00176		}
00177			
00178	Begin:
00179		if ( School.bNonAggressive )
00180			Disable('Touch');
00181		if (!Region.Zone.bWaterZone)
00182			GotoState('Flopping');
00183		SetPhysics(PHYS_Swimming);
00184	Swim:
00185		Enable('HitWall');
00186		LoopAnim('Swim1', 0.7 + FRand());
00187	 	if ( (!School.bNonAggressive || (FRand() < 0.5)) 
00188			&& (School.Enemy!=None) && (School.MoveTarget == School.Enemy) && (FRand()<0.5) )
00189	 		MoveToward(School.Enemy);
00190	 	else
00191	 	{
00192			PickDestination();
00193			MoveTo(Destination);
00194	School:
00195			if ( (FRand() < 0.75) && (OldSchoolDestination == School.Location) 
00196				&& ((School.Enemy == None) || !School.Enemy.Region.Zone.bWaterZone) )
00197			{
00198				Velocity = vect(0,0,0);
00199				Acceleration = vect(0,0,0);
00200				Sleep(3.3 * FRand());
00201				Goto('School');
00202			}
00203	 	}
00204		Velocity = vect(0,0,0);
00205		Acceleration = vect(0,0,0);
00206		Sleep(0.7 * FRand());
00207		Goto('Swim');
00208	}
00209	
00210	State Flopping
00211	{
00212	
00213		function Landed(vector HitNormal)
00214		{
00215			local rotator newRotation;
00216	
00217			SetPhysics(PHYS_None);
00218			SetTimer(0.3 + 0.3 * AirTime * FRand(), false);
00219			newRotation = Rotation;
00220			newRotation.Pitch = 0;
00221			newRotation.Roll = 16384;
00222			SetRotation(newRotation);
00223		}
00224			
00225		function Timer()
00226		{
00227			AirTime += 1;
00228			if (AirTime > 25 + 20 * FRand())
00229				GotoState('Dying');
00230			else
00231			{
00232				SetPhysics(PHYS_Falling);
00233				Velocity = 200 * VRand();
00234				Velocity.Z = 60 + 160 * FRand();
00235				DesiredRotation.Pitch = Rand(8192) - 4096;
00236				DesiredRotation.Yaw = Rand(65535);
00237			}		
00238		}
00239	
00240		function AnimEnd()
00241		{
00242			if (FRand() < 0.5)
00243				PlayAnim('Swim1', 0.1 * FRand());
00244			else
00245				PlayAnim('Bite', 0.1 * FRand());
00246		}
00247	
00248		function BeginState()
00249		{
00250			SetPhysics(PHYS_Falling);
00251		}
00252	}
00253	
00254	State Dying
00255	{
00256		ignores zonechange, headzonechange, falling, hitwall;
00257	
00258		function Landed(vector HitNormal)
00259		{
00260			SetPhysics(PHYS_None);
00261		}	
00262	
00263		function Timer()
00264		{
00265			if ( !PlayerCanSeeMe() )
00266				Destroy();
00267		}
00268	
00269	Begin:
00270		Sleep(12);
00271		SetTimer(4.0, true);
00272	}			
00273			
00274	
00275	defaultproperties
00276	{
00277	     FishSkins(0)=Texture'UnrealShare.Skins.Jfish21'
00278	     FishSkins(1)=Texture'UnrealShare.Skins.Jfish22'
00279	     FishSkins(2)=Texture'UnrealShare.Skins.Jfish23'
00280	     FishSkins(3)=Texture'UnrealShare.Skins.Jfish24'
00281	     FishSkins(4)=Texture'UnrealShare.Skins.Jfish25'
00282	     FishSkins(5)=Texture'UnrealShare.Skins.Jfish26'
00283	     bCanStrafe=True
00284	     WaterSpeed=180.000000
00285	     AccelRate=700.000000
00286	     SightRadius=3000.000000
00287	     Health=5
00288	     ReducedDamageType=exploded
00289	     ReducedDamagePct=0.900000
00290	     UnderWaterTime=-1.000000
00291	     DrawType=DT_Mesh
00292	     Skin=Texture'UnrealShare.Skins.Jfish21'
00293	     Mesh=LodMesh'UnrealShare.AmbientFish'
00294	     CollisionRadius=8.000000
00295	     CollisionHeight=6.000000
00296	     bBlockPlayers=False
00297	     Buoyancy=5.000000
00298	     RotationRate=(Pitch=8192,Yaw=128000,Roll=16384)
00299	}

End Source Code