RuneI
Class DealieFishSchool

source: c:\runehov\RuneI\Classes\DealieFishSchool.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Pawn
         |
         +--RuneI.FlockMasterPawn
            |
            +--RuneI.DealieFishSchool
Direct Known Subclasses:None

class DealieFishSchool
extends RuneI.FlockMasterPawn

//============================================================================= // DealieFishSchool. //=============================================================================
Variables
 vector StartLocation
 byte activeFish
 bool bSawPlayer
 float schoolradius
 byte schoolsize
 bool validDest

States
wandering, stasis

Function Summary
 void FishDied()
 void HeadZoneChange(ZoneInfo NewZone)
 Texture PainSkin(int BodyPart)
 void PostBeginPlay()
 void PreSetMovement()
 void Remove(DealieFish aFish)
 void RemoveFish()
 void ReplentishOne()
 void SpawnAFish()
 void SpawnFish()
 void Timer()
 void ZoneChange(ZoneInfo NewZone)


State wandering Function Summary
 void Trigger(Actor other, Pawn eventInstigator)
     
//------------------------------------------------------------
//
// STATE SplinePath
//
// Used to script a dealie fish school swimming on a particular path
//------------------------------------------------------------
 void PickDestination()
 void EnemyNotVisible()
 void SeePlayer(Actor SeenPlayer)


State stasis Function Summary
 void SeePlayer(Actor SeenPlayer)



Source Code


00001	//=============================================================================
00002	// DealieFishSchool.
00003	//=============================================================================
00004	class DealieFishSchool extends FlockMasterPawn;
00005	
00006	var() byte schoolsize;
00007	var  byte	activeFish;
00008	var() float schoolradius;
00009	var bool	validDest;
00010	var bool	bSawPlayer;
00011	var vector StartLocation;
00012	
00013	function Texture PainSkin(int BodyPart)
00014	{
00015	}
00016	
00017	function PreSetMovement()
00018	{
00019		bCanSwim = true;
00020		bCanFly = true;
00021		MinHitWall = -0.6;
00022	}
00023	
00024	function PostBeginPlay()
00025	{
00026		StartLocation = Location;
00027		Super.PostBeginPlay();
00028	}
00029	
00030	singular function ZoneChange( ZoneInfo NewZone )
00031	{
00032		local Dealiefish aFish;
00033		if (!NewZone.bWaterZone)
00034		{
00035			if ( !SetLocation(OldLocation) || (!Region.Zone.bWaterZone) )
00036				SetLocation(StartLocation);
00037			Velocity = vect(0,0,0);
00038			Acceleration = vect(0,0,0);
00039			MoveTimer = -1.0;
00040		}
00041		SetPhysics(PHYS_Swimming);
00042	}
00043	
00044	singular function HeadZoneChange( ZoneInfo NewZone )
00045	{
00046		local Dealiefish aFish;
00047		if ( (MoveTarget!=Enemy) && !NewZone.bWaterZone)
00048		{
00049			Destination.Z = Location.Z - 50;
00050			Velocity = vect(0,0,0);
00051			Acceleration = vect(0,0,0);
00052			MoveTimer = -1.0;
00053		}
00054	}
00055	
00056	function FishDied()
00057	{
00058		activeFish--;
00059		if (activeFish == 0)
00060			destroy();
00061	}
00062	
00063	function RemoveFish()
00064	{
00065		local Dealiefish aFish;
00066		local Pawn aPawn;
00067	
00068		aPawn = Level.PawnList;
00069		While ( aPawn != None )
00070		{
00071			aFish = Dealiefish(aPawn);
00072			if ( (aFish != None) && (aFish.School == self) && !aFish.PlayerCanSeeMe() )
00073				Remove(aFish);
00074			aPawn = aPawn.NextPawn;
00075		}
00076	}	
00077	
00078	function Remove(Dealiefish aFish)
00079	{
00080		schoolsize++;
00081		activeFish--;
00082		SetTimer(1.0, false);		// Replentish the school
00083		aFish.Destroy();
00084	}
00085	
00086	function ReplentishOne()
00087	{
00088		schoolsize++;
00089		activeFish--;
00090		SetTimer(1.0, false);		// Replentish the school
00091	}
00092	
00093	function SpawnFish()
00094	{
00095		if ( schoolsize > 0 )
00096			Timer();
00097	}
00098	
00099	function Timer()
00100	{
00101		if ( schoolsize > 0 )
00102			SpawnAFish();
00103		if ( schoolsize > 0 )
00104			SpawnAFish();
00105		if ( schoolsize > 0 )
00106			SpawnAFish();
00107		if ( schoolsize > 0 )
00108			SetTimer(0.1, false);
00109	}
00110	
00111	function SpawnAFish()
00112	{
00113		local DealieFish fish;
00114	
00115		fish = spawn(class 'DealieFish', self, '', Location + VRand() * CollisionRadius);
00116		if (fish != None)
00117		{
00118			schoolsize--;
00119			activeFish++;
00120		}
00121	}
00122	
00123	auto state stasis
00124	{
00125	ignores EncroachedBy, FootZoneChange;
00126		
00127		function SeePlayer(Actor SeenPlayer)
00128		{
00129			enemy = Pawn(SeenPlayer);
00130			SpawnFish();
00131			Gotostate('wandering');
00132		}
00133	
00134	Begin:
00135		SetPhysics(PHYS_None);
00136	CleanUp:
00137		if ( activeFish > 0 )
00138		{
00139			Sleep(1.0);
00140			RemoveFish();
00141			Goto('Cleanup');
00142		}
00143	}		
00144	
00145	state wandering
00146	{
00147	ignores EncroachedBy, FootZoneChange;
00148	
00149		function SeePlayer(Actor SeenPlayer)
00150		{
00151			bSawPlayer = true;
00152			Enemy = Pawn(SeenPlayer);
00153			Disable('SeePlayer');
00154			Enable('EnemyNotVisible');
00155		}
00156	
00157		function EnemyNotVisible()
00158		{
00159			Enemy = None;
00160			Disable('EnemyNotVisible');
00161			Enable('SeePlayer');
00162		}
00163		
00164		function PickDestination()
00165		{
00166			local actor hitactor;
00167			local vector hitnormal, hitlocation;
00168			
00169			Destination = Location + VRand() * 1000;
00170			Destination.Z = 0.5 * (Destination.Z - 250 + Location.Z);
00171			HitActor = Trace(HitLocation, HitNormal, Destination, Location, false);
00172			if ( (HitActor != None) && (VSize(HitLocation - Location) < 1.5 * CollisionRadius) )
00173			{
00174				Destination = 2 * Location - Destination;
00175				HitActor = Trace(HitLocation, HitNormal, Destination, Location, false);
00176			}
00177			if (HitActor != None)
00178				Destination = HitLocation - CollisionRadius * Normal(Destination - Location);
00179		}
00180		
00181	Begin:
00182		SetPhysics(PHYS_Swimming);
00183		
00184	Wander:
00185		if (Enemy == None)
00186		{
00187			bSawPlayer = false;
00188			Sleep(5.0);
00189			if ( !bSawPlayer )
00190			{
00191				RemoveFish();
00192				GotoState('Stasis');
00193			}
00194			else if ( Enemy == None )
00195				Goto('Wander');
00196		}
00197	
00198		validDest = false;	
00199		MoveTarget = None;
00200		PickDestination();
00201		MoveTo(Destination);
00202	
00203		validDest = true;
00204		if ( FRand() < 0.1 )
00205			Sleep(5 + 6 * FRand());
00206		else
00207			Sleep(0.5 + 2 * FRand());
00208		Goto('Wander');
00209	}
00210	
00211	//------------------------------------------------------------
00212	//
00213	// STATE SplinePath
00214	//
00215	// Used to script a dealie fish school swimming on a particular path
00216	//------------------------------------------------------------
00217	
00218	state() SplinePath
00219	{
00220	ignores SeePlayer, EnemyNotVisible, HearNoise, Bump, HitWall, HeadZoneChange, FootZoneChange, ZoneChange, Falling, WarnTarget, LongFall, PainTimer, Landed;
00221	
00222		function Trigger(actor other, pawn eventInstigator)
00223		{
00224			local InterpolationPoint i;
00225	
00226			if(Event != 'None')
00227				foreach AllActors(class 'InterpolationPoint', i, Event)
00228					if(i.Position == 0)
00229					{ // Found a matching path
00230						SpawnFish(); // Spawn the fish to follow this leader
00231						validDest = true; // Tell the fish that this school location is always valid
00232	
00233						SetCollision(true, false, false);
00234						bCollideWorld = False;
00235						Target = i;
00236						SetPhysics(PHYS_Interpolating);
00237						PhysRate = 1.0;
00238						PhysAlpha = 0.0;
00239						bInterpolating = true;
00240						return;
00241					}
00242		}
00243	
00244	begin:
00245	}
00246	
00247	defaultproperties
00248	{
00249	     schoolsize=12
00250	     schoolradius=150.000000
00251	     WaterSpeed=500.000000
00252	     AirSpeed=800.000000
00253	     AccelRate=4000.000000
00254	     PeripheralVision=-5.000000
00255	     UnderWaterTime=-1.000000
00256	     bHidden=True
00257	     SoundRadius=7
00258	     SoundVolume=66
00259	     SoundPitch=137
00260	     AmbientSound=Sound'EnvironmentalSnd.Bubbles.bubbleswater01L'
00261	     CollisionRadius=50.000000
00262	     CollisionHeight=100.000000
00263	     Mass=10.000000
00264	     Buoyancy=10.000000
00265	}

End Source Code