RuneI
Class Jellyfish

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

class Jellyfish
extends RuneI.ScriptPawn

//============================================================================= // Jellyfish. //=============================================================================
Variables
 vector HomeBase
 float MaxMoveZ
           Maximum upward thrust amount
 float MaxZDeviation
           Maximum deviation on the Z axis allowed
 float MinMoveZ
           Minimum upward thrust amount
 bool bDrifting
 bool glowingUp
           glow is increasing

States
Dead, OutOfWater, Flee, Swimming

Function Summary
 void CheckForEnemies()
 void FootStep()
     
//=============================================================================
//
// FootStep Notify
// 
//=============================================================================
 bool JointDamaged(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType, int joint)
 Texture PainSkin(int BodyPart)
 void PlayDeath(name DamageType)
     
//============================================================
// Animation functions
//============================================================
 void PostBeginPlay()
 void PreSetMovement()
 void VaryGlow(float rate)
     
// Rate is in range [0..1]
 void ZoneChange(ZoneInfo newZone)


State Dead Function Summary
 void Timer()
 void BeginState()


State OutOfWater Function Summary
 void Timer()
 void Landed(vector HitNormal, Actor HitActor)


State Flee Function Summary
 void Timer()
 void HitWall(vector HitNormal, Actor HitWall)


State Swimming Function Summary
 void Timer()
 void BeginState()
 void Touch(Actor Other)
 void HitWall(vector HitNormal, Actor HitWall)
 void PickDestination()



Source Code


00001	//=============================================================================
00002	// Jellyfish.
00003	//=============================================================================
00004	class Jellyfish expands ScriptPawn;
00005	
00006	
00007	/* Description:
00008		Stays close to home roaming up and drifting down.  Sink upon death.
00009		
00010	   TODO:
00011	*/
00012	
00013	var bool bDrifting;
00014	var vector HomeBase;
00015	var() float MaxZDeviation;		// Maximum deviation on the Z axis allowed
00016	var() float MinMoveZ;			// Minimum upward thrust amount
00017	var() float MaxMoveZ;			// Maximum upward thrust amount
00018	var bool glowingUp;				// glow is increasing
00019	
00020	var(Sounds) sound	ThrustSound;
00021	
00022	
00023	function PreSetMovement()
00024	{
00025		bCanWalk = false;
00026		bCanJump = false;
00027		bCanFly = false;
00028		bCanSwim = false;
00029		MinHitWall = -0.6;
00030	}
00031	
00032	
00033	function CheckForEnemies()
00034	{
00035	}
00036	
00037	function PostBeginPlay()
00038	{
00039		Super.PostBeginPlay();
00040		HomeBase = Location;
00041		Destination = Location;
00042	}
00043	
00044	function Texture PainSkin(int BodyPart)
00045	{
00046	}
00047	
00048	function ZoneChange(ZoneInfo newZone)
00049	{
00050		if (!newZone.bWaterZone)
00051		{
00052			AmbientSound = None;
00053			SetPhysics(PHYS_Falling);
00054			GotoState('OutOfWater');
00055		}
00056		else
00057		{
00058			if (AmbientSound == None)
00059				AmbientSound=Default.AmbientSound;
00060	
00061			if (Physics != PHYS_Swimming)
00062				SetPhysics(PHYS_Swimming);
00063		}
00064	}
00065	
00066	
00067	function bool JointDamaged( int Damage, Pawn instigatedBy, Vector hitlocation, 
00068							Vector momentum, name damageType, int joint)
00069	{
00070		local bool bAlreadyDead;
00071	
00072		bAlreadyDead = (Health <= 0);
00073	
00074		momentum = momentum/Mass;
00075		AddVelocity( momentum ); 
00076		Health -= Damage;
00077		if ( Health < -20 )
00078		{
00079			//Spawn(class'Bloodspurt');
00080			Destroy();
00081		}
00082		else if ( !bAlreadyDead && (Health <= 0) )
00083		{
00084			GotoState('Dead');
00085		}
00086		return true;
00087	}
00088	
00089	// Rate is in range [0..1]
00090	function VaryGlow(float rate)
00091	{
00092		if (glowingUp)
00093		{
00094			ScaleGlow += rate;
00095			if (ScaleGlow>0.7)
00096				glowingUp = false;
00097		}
00098		else
00099		{
00100			ScaleGlow -= rate;
00101			if (ScaleGlow<0.2)
00102				glowingUp = true;
00103		}
00104	}
00105	
00106	//=============================================================================
00107	//
00108	// FootStep Notify
00109	// 
00110	//=============================================================================
00111	function FootStep()
00112	{
00113		local EMatterType matter;
00114		local vector end;
00115		local sound snd;
00116		local int i;
00117	
00118		if(bFootsteps && Region.Zone.bWaterZone)
00119		{
00120			PlaySound(ThrustSound, SLOT_Interact, 0.33, false,, 0.95 + (FRand() * 0.1));
00121		}
00122	}
00123	
00124	
00125	//============================================================
00126	// Animation functions
00127	//============================================================
00128	function PlayDeath(name DamageType)	          { PlayAnim  ('death', 1.0, 0.1);     }
00129	
00130	
00131	
00132	//============================================================
00133	// States
00134	//============================================================
00135	
00136	auto State Swimming
00137	{
00138		ignores Bump, SeePlayer, HearNoise;
00139		
00140		function PickDestination()
00141		{
00142			local vector deviation, correction;
00143			local float correctionamount;
00144			
00145			deviation = Location - HomeBase;
00146			if (deviation.Z > MaxZDeviation-MaxMoveZ)
00147				bDrifting = true;
00148			else if (deviation.Z < -MaxZDeviation)
00149				bDrifting = false;
00150			else if (bDrifting)
00151				bDrifting = false;
00152			else if (deviation.Z <= 0)
00153				bDrifting = false;
00154			else
00155				bDrifting = FRand() < 0.4;
00156				
00157			if (!bDrifting)
00158			{
00159				correction = HomeBase - Location;
00160				correctionamount = FRand() * 0.2;
00161				Destination = Location + VRand() + correction*correctionamount;
00162				Destination.Z += RandRange(MinMoveZ, MaxMoveZ);
00163			}
00164		}
00165		
00166		function HitWall(vector HitNormal, actor HitWall)
00167		{
00168			Destination = Location + (HitNormal * 100);
00169			Buoyancy = Mass;
00170			SetTimer(0, false);
00171			GotoState('Flee');
00172		}
00173	
00174		function Touch(actor Other)
00175		{	// Sting and move
00176			Disable('Touch');
00177			Other.JointDamaged(2, self, location, vect(0,0,0), 'stung', 0);
00178			Destination = Location + (Location - Other.Location) * 4;
00179			Buoyancy = Mass;
00180			SetTimer(0, false);
00181			GotoState('Flee');
00182		}
00183		
00184		function BeginState()
00185		{
00186			ZoneChange(Region.Zone);
00187		}
00188	
00189		function Timer()
00190		{
00191			local vector tohome;
00192	
00193			VaryGlow(0.05);
00194			if (bDrifting)
00195			{
00196				// Check if reached destination
00197				tohome = HomeBase - Location;
00198				if (Abs(tohome.Z) > MaxZDeviation)
00199				{
00200	//				SetTimer(0, false);
00201					GotoState('swimming', 'swim');
00202				}
00203			}
00204		}
00205		
00206	Begin:
00207		SetTimer(0.1, true);
00208		if (Physics!=PHYS_Swimming)
00209			SetPhysics(PHYS_Swimming);
00210		Enable('Touch');
00211		Enable('HitWall');
00212	Swim:
00213		PickDestination();
00214		if (bDrifting)
00215		{
00216			Buoyancy = Mass * 0.95;		// accel.z is -950 * .05
00217			PlayAnim('drift_tran', 1.0, 1.0);
00218		}
00219		else
00220		{
00221			Buoyancy = Mass;
00222			PlayAnim('walk', 1.0, 0.1);
00223			MoveTo(Destination);
00224			FinishAnim();
00225			Sleep(0.5);
00226			GotoState('Swimming');
00227		}
00228	}
00229	
00230	
00231	state Flee
00232	{
00233		ignores Touch, Bump, SeePlayer, HearNoise;
00234	
00235		function HitWall(vector HitNormal, actor HitWall)
00236		{
00237			Destination = Location + (HitNormal * 100);
00238			GotoState('Flee', 'Move');
00239		}
00240	
00241		function Timer()
00242		{
00243			VaryGlow(0.2);
00244		}
00245		
00246	Begin:
00247		SetTimer(0.1, true);
00248	Move:
00249		MoveTo(Destination);
00250		GotoState('Swimming');
00251	}
00252	
00253	
00254	// If leaves water permanently, kill him
00255	state OutOfWater
00256	{
00257		function Landed(vector HitNormal, actor HitActor)
00258		{	// Landed on ground, kill him
00259			JointDamaged(Health+1, self, Location, vect(0,0,0), 'Suffocated', 0);
00260			SetTimer(0, false);
00261			GotoState('Dead');
00262		}
00263		
00264		function Timer()
00265		{	// Air exposure
00266			JointDamaged(Health+1, self, Location, vect(0,0,0), 'Suffocated', 0);
00267			GotoState('Dead');
00268		}
00269	Begin:
00270		SetTimer(5, false);
00271	}
00272	
00273	
00274	State Dead
00275	{
00276		ignores zonechange, footzonechange, headzonechange, falling, hitwall;
00277	
00278		function BeginState()
00279		{
00280			local rotator newrot;
00281			
00282			SkelGroupFlags[2] = SkelGroupFlags[2] | POLYFLAG_INVISIBLE;
00283			PlayAnim('Death', 1.0, 0.1);
00284			SetCollision(false,false,false);
00285			SetCollisionSize(CollisionRadius, 1);
00286			newrot = rot(0,0,0);
00287			newrot.Yaw = Rotation.Yaw;
00288			SetRotation(newrot);
00289			Buoyancy = 0.95 * Mass;
00290			Velocity.Z = FMax(0, Velocity.Z);
00291		}
00292		
00293		function Timer()
00294		{	// When lands on ground
00295			SetPhysics(PHYS_None);
00296			AnimRate = 0.0;
00297			RemoteRole = ROLE_DumbProxy;
00298		}
00299		
00300	Begin:
00301		SetTimer(20, false);
00302	}			
00303			
00304	
00305	simulated function Debug(Canvas canvas, int mode)
00306	{
00307		Super.Debug(canvas, mode);
00308		
00309		Canvas.DrawText("Jellyfish:");
00310		Canvas.CurY -= 8;
00311		Canvas.DrawText(" Destination:  "$Destination);
00312		Canvas.CurY -= 8;
00313		Canvas.DrawText(" MaxZDeviation:"$MaxZDeviation);
00314		Canvas.CurY -= 8;
00315		Canvas.DrawText(" bDrifting:    "$bDrifting);
00316		Canvas.CurY -= 8;
00317	
00318		Canvas.DrawLine3D(HomeBase, Location, 255, 0, 0);
00319	}
00320	
00321	defaultproperties
00322	{
00323	     MaxZDeviation=100.000000
00324	     MinMoveZ=50.000000
00325	     MaxMoveZ=75.000000
00326	     bBurnable=False
00327	     bCanStrafe=True
00328	     GroundSpeed=0.000000
00329	     ClassID=19
00330	     SightRadius=1000.000000
00331	     PeripheralVision=-1.000000
00332	     BaseEyeHeight=18.000000
00333	     bGibbable=False
00334	     UnderWaterTime=-1.000000
00335	     AttitudeToPlayer=ATTITUDE_Ignore
00336	     Intelligence=BRAINS_REPTILE
00337	     HitSound1=Sound'CreaturesSnd.Fish.fish08'
00338	     HitSound2=Sound'CreaturesSnd.Fish.fish08'
00339	     HitSound3=Sound'CreaturesSnd.Fish.fish08'
00340	     Die=Sound'CreaturesSnd.Fish.fish05'
00341	     Die2=Sound'CreaturesSnd.Fish.fish05'
00342	     Die3=Sound'CreaturesSnd.Fish.fish05'
00343	     LookDegPerSec=0.000000
00344	     bStasis=False
00345	     Physics=PHYS_Swimming
00346	     Style=STY_Translucent
00347	     LODCurve=LOD_CURVE_NONE
00348	     SoundRadius=21
00349	     SoundVolume=152
00350	     SoundPitch=30
00351	     AmbientSound=Sound'CreaturesSnd.Fish.fish03L'
00352	     TransientSoundRadius=800.000000
00353	     CollisionRadius=18.000000
00354	     CollisionHeight=18.000000
00355	     bBlockActors=False
00356	     bBlockPlayers=False
00357	     bRotateToDesired=False
00358	     Buoyancy=100.000000
00359	     RotationRate=(Pitch=0,Roll=0)
00360	     Skeletal=SkelModel'creatures.jellyfish'
00361	}

End Source Code