UnrealShare
Class BiterFishSchool

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

class BiterFishSchool
extends UnrealShare.FlockMasterPawn

//============================================================================= // BiterFishSchool. //=============================================================================
Variables
 vector StartLocation
 byte activeFish
 bool bNonAggressive
 bool bSawPlayer
 byte fishcolor
 float schoolradius
 byte schoolsize
 bool validDest

States
wandering, stasis

Function Summary
 void FishDied()
 void HeadZoneChange(ZoneInfo NewZone)
 void PostBeginPlay()
 void PreSetMovement()
 void Remove(BiterFish aFish)
 void RemoveFish()
 void SpawnAFish()
 void SpawnFish()
 void Timer()
 void ZoneChange(ZoneInfo NewZone)


State wandering Function Summary
 void PickDestination()
 void EnemyNotVisible()
 void SeePlayer(Actor SeenPlayer)


State stasis Function Summary
 void SeePlayer(Actor SeenPlayer)



Source Code


00001	//=============================================================================
00002	// BiterFishSchool.
00003	//=============================================================================
00004	class BiterFishSchool extends FlockMasterPawn;
00005	
00006	var() byte schoolsize;
00007	var  byte	activeFish;
00008	var() float schoolradius;
00009	var() bool	bNonAggressive;
00010	var bool	validDest;
00011	var bool	bSawPlayer;
00012	var vector StartLocation;
00013	var() byte fishcolor;
00014	
00015	function PreSetMovement()
00016	{
00017		bCanSwim = true;
00018		bCanFly = true;
00019		MinHitWall = -0.6;
00020	}
00021	
00022	function PostBeginPlay()
00023	{
00024		StartLocation = Location;
00025		Super.PostBeginPlay();
00026	}
00027	
00028	singular function ZoneChange( ZoneInfo NewZone )
00029	{
00030		local biterfish aFish;
00031		if (!NewZone.bWaterZone)
00032		{
00033			if ( !SetLocation(OldLocation) || (!Region.Zone.bWaterZone) )
00034				SetLocation(StartLocation);
00035			Velocity = vect(0,0,0);
00036			Acceleration = vect(0,0,0);
00037			MoveTimer = -1.0;
00038		}
00039		SetPhysics(PHYS_Swimming);
00040	}
00041	
00042	singular function HeadZoneChange( ZoneInfo NewZone )
00043	{
00044		local biterfish aFish;
00045		if ( (MoveTarget!=Enemy) && !NewZone.bWaterZone)
00046		{
00047			Destination.Z = Location.Z - 50;
00048			Velocity = vect(0,0,0);
00049			Acceleration = vect(0,0,0);
00050			MoveTimer = -1.0;
00051		}
00052	}
00053	
00054	function FishDied()
00055	{
00056		activeFish--;
00057		if (activeFish == 0)
00058			destroy();
00059	}
00060	
00061	function RemoveFish()
00062	{
00063		local biterfish aFish;
00064		local Pawn aPawn;
00065	
00066		aPawn = Level.PawnList;
00067		While ( aPawn != None )
00068		{
00069			aFish = biterfish(aPawn);
00070			if ( (aFish != None) && (aFish.School == self) && !aFish.PlayerCanSeeMe() )
00071				Remove(aFish);
00072			aPawn = aPawn.NextPawn;
00073		}
00074	}	
00075	
00076	function Remove(biterfish aFish)
00077	{
00078		aFish.Destroy();
00079		schoolsize++;
00080		activeFish--;
00081	}
00082	
00083	function SpawnFish()
00084	{
00085		if ( schoolsize > 0 )
00086			Timer();
00087	}
00088	
00089	function Timer()
00090	{
00091		if ( schoolsize > 0 )
00092			SpawnAFish();
00093		if ( schoolsize > 0 )
00094			SpawnAFish();
00095		if ( schoolsize > 0 )
00096			SpawnAFish();
00097		if ( schoolsize > 0 )
00098			SetTimer(0.1, false);
00099	}
00100	
00101	function SpawnAFish()
00102	{
00103		local BiterFish fish;
00104	
00105		fish = spawn(class 'BiterFish',self,'', Location + VRand() * CollisionRadius);
00106		if (fish != None)
00107		{
00108			schoolsize--;
00109			activeFish++;
00110		}
00111	}
00112	
00113	auto state stasis
00114	{
00115	ignores EncroachedBy, FootZoneChange;
00116		
00117		function SeePlayer(Actor SeenPlayer)
00118		{
00119			enemy = Pawn(SeenPlayer);
00120			SpawnFish();
00121			Gotostate('wandering');
00122		}
00123	
00124	Begin:
00125		SetPhysics(PHYS_None);
00126	CleanUp:
00127		if ( activeFish > 0 )
00128		{
00129			Sleep(1.0);
00130			RemoveFish();
00131			Goto('Cleanup');
00132		}
00133	}		
00134	
00135	state wandering
00136	{
00137	ignores EncroachedBy, FootZoneChange;
00138	
00139		function SeePlayer(Actor SeenPlayer)
00140		{
00141			bSawPlayer = true;
00142			Enemy = Pawn(SeenPlayer);
00143			Disable('SeePlayer');
00144			Enable('EnemyNotVisible');
00145		}
00146	
00147		function EnemyNotVisible()
00148		{
00149			Enemy = None;
00150			Disable('EnemyNotVisible');
00151			Enable('SeePlayer');
00152		}
00153		
00154		function PickDestination()
00155		{
00156			local actor hitactor;
00157			local vector hitnormal, hitlocation;
00158			
00159			Destination = Location + VRand() * 1000;
00160			Destination.Z = 0.5 * (Destination.Z - 250 + Location.Z);
00161			HitActor = Trace(HitLocation, HitNormal, Destination, Location, false);
00162			if ( (HitActor != None) && (VSize(HitLocation - Location) < 1.5 * CollisionRadius) )
00163			{
00164				Destination = 2 * Location - Destination;
00165				HitActor = Trace(HitLocation, HitNormal, Destination, Location, false);
00166			}
00167			if (HitActor != None)
00168				Destination = HitLocation - CollisionRadius * Normal(Destination - Location);
00169		}
00170		
00171	Begin:
00172		SetPhysics(PHYS_Swimming);
00173		
00174	Wander:
00175		if (Enemy == None)
00176		{
00177			bSawPlayer = false;
00178			Sleep(5.0);
00179			if ( !bSawPlayer )
00180			{
00181				RemoveFish();
00182				GotoState('Stasis');
00183			}
00184			else if ( Enemy == None )
00185				Goto('Wander');
00186		}
00187	
00188		validDest = false;		
00189		if ( !bNonAggressive && (Enemy != None) && Enemy.Region.Zone.bWaterZone && !Enemy.Region.Zone.bPainZone)
00190			MoveToward(Enemy);	
00191		else
00192		{
00193			MoveTarget = None;
00194			PickDestination();
00195			MoveTo(Destination);
00196		}
00197		validDest = true;
00198		if ( FRand() < 0.1 )
00199			Sleep(5 + 6 * FRand());
00200		else
00201			Sleep(0.5 + 2 * FRand());
00202		Goto('Wander');
00203	}
00204	
00205	defaultproperties
00206	{
00207	     schoolsize=12
00208	     schoolradius=120.000000
00209	     fishcolor=8
00210	     WaterSpeed=800.000000
00211	     AirSpeed=800.000000
00212	     AccelRate=4000.000000
00213	     PeripheralVision=-5.000000
00214	     UnderWaterTime=-1.000000
00215	     bHidden=True
00216	     CollisionRadius=50.000000
00217	     CollisionHeight=100.000000
00218	     Mass=10.000000
00219	     Buoyancy=10.000000
00220	     NetPriority=1.400000
00221	}

End Source Code