UnrealShare
Class CreatureChunks

source: e:\games\UnrealTournament\UnrealShare\Classes\CreatureChunks.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Decoration
         |
         +--Engine.Carcass
            |
            +--UnrealShare.CreatureChunks
Direct Known Subclasses:MasterCreatureChunk, PlayerChunks

class CreatureChunks
extends Engine.Carcass

//============================================================================= // CreatureChunks. //=============================================================================
States
Dead, Dying

Function Summary
 void ChunkUp(int Damage)
 
simulated
ClientExtraChunks(bool bSpawnChunks)
 
simulated
Destroyed()
 
simulated
HitWall(vector HitNormal, Actor Wall)
 void Initfor(Actor Other)
 
simulated
Landed(vector HitNormal)
 
simulated
PostBeginPlay()
 void SetAsMaster(Actor Other)
 void TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)
 
simulated
Timer()
 
simulated
ZoneChange(ZoneInfo NewZone)


State Dead Function Summary
 void BeginState()


State Dying Function Summary



Source Code


00001	//=============================================================================
00002	// CreatureChunks.
00003	//=============================================================================
00004	class CreatureChunks extends Carcass;
00005	
00006	#exec MESH IMPORT MESH=CowBody1 ANIVFILE=MODELS\g_cow2_a.3D DATAFILE=MODELS\g_cow2_d.3D X=0 Y=0 Z=0
00007	#exec MESH ORIGIN MESH=CowBody1 X=0 Y=0 Z=0 YAW=64
00008	#exec MESH SEQUENCE MESH=CowBody1 SEQ=All    STARTFRAME=0   NUMFRAMES=1
00009	#exec MESH SEQUENCE MESH=CowBody1 SEQ=Still  STARTFRAME=0   NUMFRAMES=1
00010	#exec TEXTURE IMPORT NAME=JGCow1  FILE=MODELS\Nc_1.PCX GROUP=Skins 
00011	#exec MESHMAP SCALE MESHMAP=CowBody1 X=0.06 Y=0.06 Z=0.12
00012	#exec MESHMAP SETTEXTURE MESHMAP=CowBody1 NUM=1 TEXTURE=JGCow1
00013	
00014	#exec AUDIO IMPORT FILE="Sounds\Gibs\gibP1.WAV" NAME="gibP1" GROUP="Gibs"
00015	#exec AUDIO IMPORT FILE="Sounds\Gibs\gibP3.WAV" NAME="gibP3" GROUP="Gibs"
00016	#exec AUDIO IMPORT FILE="Sounds\Gibs\gibP4.WAV" NAME="gibP4" GROUP="Gibs"
00017	#exec AUDIO IMPORT FILE="Sounds\Gibs\gibP5.WAV" NAME="gibP5" GROUP="Gibs"
00018	#exec AUDIO IMPORT FILE="Sounds\Gibs\gibP6.WAV" NAME="gibP6" GROUP="Gibs"
00019	
00020	var		Bloodtrail		trail;
00021	var		float			TrailSize;
00022	var		bool			bGreenBlood;
00023	var		bool			bMasterChunk;
00024	var		bool			bMustSpawnChunks;
00025	var		class<CreatureCarcass>	CarcassClass;
00026	var		name			CarcassAnim;	   	
00027	var		Vector			CarcLocation;
00028	var		float			CarcHeight;
00029	
00030	replication
00031	{
00032		// Things the server should send to the client.
00033		unreliable if( Role==ROLE_Authority )
00034			bGreenBlood, bMasterChunk, CarcassClass, CarcassAnim, CarcLocation, CarcHeight;
00035	}
00036	
00037	simulated function PostBeginPlay()
00038	{
00039		if ( Region.Zone.bDestructive || ((Level.Game != None) && Level.Game.bLowGore) )
00040		{
00041			Destroy();
00042			return;
00043		}
00044		if ( bMasterChunk && (Level.NetMode == NM_Client) ) //only if client
00045			ClientExtraChunks(true);
00046		else if ( Level.NetMode == NM_Client )
00047			SetTimer(0.05, false);
00048	
00049		Super.PostBeginPlay();
00050	}
00051	
00052	simulated function ClientExtraChunks(bool bSpawnChunks)
00053	{
00054		local CreatureChunks carc;
00055		local bloodpuff Blood;
00056		local bloodspurt b;
00057		local int n;
00058	
00059		If ( Level.NetMode == NM_DedicatedServer )
00060			return;
00061	
00062		bMustSpawnChunks = false;
00063		b = Spawn(class 'Bloodspurt',,,,rot(16384,0,0));
00064		if ( bGreenBlood )
00065			b.GreenBlood();
00066		b.RemoteRole = ROLE_None;
00067	
00068		if ( !bSpawnChunks || (CarcassClass == None) )
00069			return;
00070	
00071		n = 1;
00072	
00073		while ( (n<8) && (CarcassClass.Default.bodyparts[n] != none) )
00074		{
00075			if ( CarcassClass.Static.AllowChunk(n, CarcassAnim) )
00076			{
00077				if ( CarcLocation == vect(0,0,0) ) CarcLocation = Location; 
00078				carc = Spawn(class 'CreatureChunks',,, CarcLocation 
00079							+ CarcassClass.Default.ZOffset[n] * CarcHeight * vect(0,0,1));
00080				if (carc != None)
00081				{
00082					carc.TrailSize = CarcassClass.Default.Trails[n];
00083					carc.Mesh = CarcassClass.Default.bodyparts[n];
00084					carc.Initfor(self);
00085					carc.RemoteRole = ROLE_None;
00086				}
00087			}
00088			n++;
00089		}
00090	
00091		if ( Level.bHighDetailMode && !bGreenBlood )
00092		{
00093			Blood = spawn(class'BloodPuff',,, CarcLocation);
00094			Blood.drawscale = 0.2 * CollisionRadius;
00095			Blood.RemoteRole = ROLE_None;
00096		}
00097	}
00098	
00099	simulated function ZoneChange( ZoneInfo NewZone )
00100	{
00101		local float splashsize;
00102		local actor splash;
00103	
00104		if ( NewZone.bWaterZone )
00105		{
00106			if ( trail != None )
00107			{
00108				if ( Level.bHighDetailMode )
00109					bUnlit = false;
00110				trail.Destroy();
00111			}
00112			if ( Mass <= Buoyancy )
00113				SetCollisionSize(0,0);
00114			if ( bSplash && !Region.Zone.bWaterZone && (Abs(Velocity.Z) < 80) )
00115				RotationRate *= 0.6;
00116			else if ( !Region.Zone.bWaterZone && (Velocity.Z < -200) )
00117			{
00118				// else play a splash
00119				splashSize = FClamp(0.0001 * Mass * (250 - 0.5 * FMax(-600,Velocity.Z)), 1.0, 3.0 );
00120				if ( NewZone.EntrySound != None )
00121					PlaySound(NewZone.EntrySound, SLOT_Interact, splashSize);
00122				if ( NewZone.EntryActor != None )
00123				{
00124					splash = Spawn(NewZone.EntryActor); 
00125					if ( splash != None )
00126						splash.DrawScale = splashSize;
00127				}
00128			}
00129			bSplash = true;
00130		}
00131	
00132		if ( NewZone.bDestructive || (NewZone.bPainZone  && (NewZone.DamagePerSec > 0)) )
00133			Destroy();
00134	}
00135		
00136	simulated function Destroyed()
00137	{
00138		if ( trail != None )
00139			trail.Destroy();
00140		Super.Destroyed();
00141	}
00142	
00143	function Initfor(actor Other)
00144	{
00145		local vector RandDir;
00146	
00147		if ( Other.IsA('Carcass') )
00148			PlayerOwner = Carcass(Other).PlayerOwner;
00149		bDecorative = false;
00150		DrawScale = Other.DrawScale;
00151		if ( DrawScale != 1.0 )
00152			SetCollisionSize(CollisionRadius * 0.5 * (1 + DrawScale), CollisionHeight * 0.5 * (1 + DrawScale));
00153		RotationRate.Yaw = Rand(200000) - 100000;
00154		RotationRate.Pitch = Rand(200000 - Abs(RotationRate.Yaw)) - 0.5 * (200000 - Abs(RotationRate.Yaw));
00155		RandDir = 700 * FRand() * VRand();
00156		RandDir.Z = 200 * FRand() - 50;
00157		if ( bMasterChunk )
00158			SetAsMaster(Other);
00159		else
00160		{
00161			Velocity = (0.2 + FRand()) * (other.Velocity + RandDir);
00162			If (Region.Zone.bWaterZone)
00163				Velocity *= 0.5;
00164		}
00165		if ( TrailSize > 0 )
00166		{
00167			if ( CreatureCarcass(Other) != None )
00168				bGreenBlood = CreatureCarcass(Other).bGreenBlood;
00169			else if ( (CreatureChunks(Other) != None) )
00170				bGreenBlood = CreatureChunks(Other).bGreenBlood;
00171		}
00172				
00173		if ( FRand() < 0.3 )
00174			Buoyancy = 1.06 * Mass; // float corpse
00175		else
00176			Buoyancy = 0.94 * Mass;
00177	
00178		if ( bMasterChunk ) // only if server
00179			ClientExtraChunks(bMustSpawnChunks);
00180	}
00181	
00182	function SetAsMaster(Actor Other)
00183	{
00184		Velocity = Other.Velocity;
00185		CarcassClass = class<CreatureCarcass>(Other.Class);
00186		CarcassAnim = Other.AnimSequence;
00187		CarcLocation = Other.Location;
00188		CarcHeight = Other.CollisionHeight;
00189	}
00190	
00191	function ChunkUp(int Damage)
00192	{
00193		local BloodSpurt b;
00194	
00195		if (bHidden)
00196			return;
00197		b = Spawn(class 'Bloodspurt',,,,rot(16384,0,0));
00198		if ( bGreenBlood )		
00199			b.GreenBlood();	
00200		if (bPlayerCarcass)
00201		{
00202			bHidden = true;
00203			SetPhysics(PHYS_None);
00204			SetCollision(false,false,false);
00205			bProjTarget = false;
00206			if ( Trail != None )
00207				Trail.Destroy();
00208		}
00209		else
00210			destroy();
00211	}
00212	
00213	simulated function Landed(vector HitNormal)
00214	{
00215		local rotator finalRot;
00216		local BloodSpurt b;
00217	
00218		if ( trail != None )
00219		{
00220			if ( Level.bHighDetailMode )
00221				bUnlit = false;
00222			trail.Destroy();
00223			trail = None;
00224		}
00225		finalRot = Rotation;
00226		finalRot.Roll = 0;
00227		finalRot.Pitch = 0;
00228		setRotation(finalRot);
00229		if ( Level.NetMode != NM_DedicatedServer )
00230		{
00231			b = Spawn(class 'Bloodspurt',,,,rot(16384,0,0));
00232			if ( bGreenBlood )
00233				b.GreenBlood();		
00234			b.RemoteRole = ROLE_None;
00235		}
00236		SetPhysics(PHYS_None);
00237		SetCollision(true, false, false);
00238	}
00239	
00240	simulated function HitWall(vector HitNormal, actor Wall)
00241	{
00242		local float speed, decision;
00243		local BloodSpurt b;
00244	
00245		Velocity = 0.8 * (Velocity - 2 * HitNormal * (Velocity Dot HitNormal));
00246		Velocity.Z = FMin(Velocity.Z * 0.8, 700);
00247		speed = VSize(Velocity);
00248		if ( speed < 250 )
00249		{
00250			if ( trail != None )
00251			{
00252				if ( Level.bHighDetailMode )
00253					bUnlit = false;
00254				trail.Destroy();
00255				trail = None;
00256			}
00257			if ( speed < 120 )
00258			{
00259				bBounce = false;
00260				Disable('HitWall');
00261			}
00262		}
00263		else if ( speed > 350 )
00264		{
00265			if ( speed > 700 )
00266				velocity *= 0.8;
00267			if (  Level.NetMode != NM_DedicatedServer )
00268			{
00269				decision = FRand();
00270				if ( decision < 0.2 )
00271					PlaySound(sound 'gibP1');
00272				else if ( decision < 0.4 )
00273					PlaySound(sound 'gibP3');
00274				else if ( decision < 0.6 )
00275					PlaySound(sound 'gibP4');
00276				else if ( decision < 0.8 )
00277					PlaySound(sound 'gibP5');
00278				else 
00279					PlaySound(sound 'gibP6');
00280			}
00281		}
00282		if ( (trail == None) && (Level.NetMode != NM_DedicatedServer) )
00283		{
00284			b = Spawn(class 'Bloodspurt',,,,Rotator(HitNormal));
00285			if ( bGreenBlood )
00286				b.GreenBlood();		
00287			b.RemoteRole = ROLE_None;
00288		}
00289	}
00290	
00291	function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, 
00292							Vector momentum, name damageType)
00293	{
00294		SetPhysics(PHYS_Falling);
00295		bBobbing = false;
00296		Velocity += momentum/Mass;
00297		CumulativeDamage += Damage;
00298		If ( Damage > FMin(15, Mass) || (CumulativeDamage > Mass) )
00299			ChunkUp(Damage);
00300	}
00301	
00302	simulated function Timer()
00303	{
00304		if ( (Level.NetMode == NM_Client) && bMasterChunk )
00305			ClientExtraChunks(bMustSpawnChunks);
00306	}
00307				
00308	
00309	auto state Dying
00310	{
00311		ignores TakeDamage;
00312	
00313	Begin:
00314		if ( bDecorative )
00315			SetPhysics(PHYS_None);
00316		else if ( (TrailSize > 0) && !Region.Zone.bWaterZone )
00317		{
00318			trail = Spawn(class'BloodTrail',self);
00319	//		trail.DrawScale = TrailSize;
00320			if ( bGreenBlood )
00321				trail.GreenBlood();
00322		}
00323		Sleep(0.35);
00324		SetCollision(true, false, false);
00325		bMasterChunk = false;
00326		GotoState('Dead');
00327	}	
00328	
00329	state Dead 
00330	{
00331		function BeginState()
00332		{
00333			if ( bDecorative )
00334				lifespan = 0.0;
00335			else
00336				SetTimer(5.0, false);
00337		}
00338	}
00339	
00340	defaultproperties
00341	{
00342	     TrailSize=3.000000
00343	     bMustSpawnChunks=True
00344	     RemoteRole=ROLE_SimulatedProxy
00345	     LifeSpan=20.000000
00346	     Mesh=LodMesh'UnrealShare.CowBody1'
00347	     bUnlit=True
00348	     bCollideActors=False
00349	     bBounce=True
00350	     bFixedRotationDir=True
00351	     Mass=30.000000
00352	     Buoyancy=27.000000
00353	     RotationRate=(Pitch=30000,Roll=30000)
00354	}

End Source Code