UnrealShare
Class CreatureCarcass

source: e:\games\UnrealTournament\UnrealShare\Classes\CreatureCarcass.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Decoration
         |
         +--Engine.Carcass
            |
            +--UnrealShare.CreatureCarcass
Direct Known Subclasses:GassiusCarcass, KrallCarcass, MercCarcass, PupaeCarcass, QueenCarcass, SquidCarcass, TitanCarcass, TrooperCarcass, WarlordCarcass, BruteCarcass, CowCarcass, DevilfishCarcass, FlyCarcass, HumanCarcass, MantaCarcass, NaliCarcass, SkaarjCarcass, SlithCarcass, TentacleCarcass

class CreatureCarcass
extends Engine.Carcass

//============================================================================= // CreatureCarcass. //=============================================================================
Variables
 ZoneInfo DeathZone
 float ExistTime
 sound GibOne
 sound GibTwo
 sound LandedSound
 float Trails[8]
 float ZOffset[8]
 bool bGreenBlood
 mesh bodyparts[8]

States
Corroding, Gibbing, Dead, Dying

Function Summary
 void AnimEnd()
 void ChunkUp(int Damage)
 void CreateReplacement()
 void Destroyed()
 void GibSound()
 
simulated
HitWall(vector HitNormal, Actor Wall)
 void Initfor(Actor Other)
 void LandThump()
 void Landed(vector HitNormal)
 void LieStill()
 void PostBeginPlay()
 void ReduceCylinder()
 void TakeDamage(int Damage, Pawn InstigatedBy, Vector Hitlocation, Vector Momentum, name DamageType)
 void ThrowOthers()


State Corroding Function Summary
 void BeginState()
 void Tick(float DeltaTime)


State Gibbing Function Summary


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


State Dying Function Summary



Source Code


00001	//=============================================================================
00002	// CreatureCarcass.
00003	//=============================================================================
00004	class CreatureCarcass 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 MESH IMPORT MESH=CowBody2 ANIVFILE=MODELS\g_cowb_a.3D DATAFILE=MODELS\g_cowb_d.3D X=0 Y=0 Z=0
00015	#exec MESH ORIGIN MESH=CowBody2 X=0 Y=0 Z=0 YAW=64
00016	#exec MESH SEQUENCE MESH=CowBody2 SEQ=All    STARTFRAME=0   NUMFRAMES=1
00017	#exec MESH SEQUENCE MESH=CowBody2 SEQ=Still  STARTFRAME=0   NUMFRAMES=1
00018	#exec TEXTURE IMPORT NAME=JGCow1  FILE=MODELS\Nc_1.PCX GROUP=Skins 
00019	#exec MESHMAP SCALE MESHMAP=CowBody2 X=0.04 Y=0.04 Z=0.08
00020	#exec MESHMAP SETTEXTURE MESHMAP=CowBody2 NUM=1 TEXTURE=JGCow1
00021	
00022	#exec MESH IMPORT MESH=LiverM ANIVFILE=MODELS\g_gut1_a.3D DATAFILE=MODELS\g_gut1_d.3D X=0 Y=0 Z=0
00023	#exec MESH ORIGIN MESH=LiverM X=0 Y=0 Z=0 YAW=64
00024	#exec MESH SEQUENCE MESH=LiverM SEQ=All    STARTFRAME=0   NUMFRAMES=1
00025	#exec MESH SEQUENCE MESH=LiverM SEQ=Still  STARTFRAME=0   NUMFRAMES=1
00026	#exec TEXTURE IMPORT NAME=Jparts1  FILE=MODELS\g_parts.PCX GROUP=Skins
00027	#exec MESHMAP SCALE MESHMAP=LiverM X=0.02 Y=0.02 Z=0.04
00028	#exec MESHMAP SETTEXTURE MESHMAP=LiverM NUM=1 TEXTURE=Jparts1
00029	
00030	#exec AUDIO IMPORT FILE="Sounds\Gibs\biggib1.WAV" NAME="Gib1" GROUP="Gibs"
00031	#exec AUDIO IMPORT FILE="Sounds\Gibs\biggib2.WAV" NAME="Gib4" GROUP="Gibs"
00032	#exec AUDIO IMPORT FILE="Sounds\Gibs\biggib3.WAV" NAME="Gib5" GROUP="Gibs"
00033	#exec AUDIO IMPORT FILE="Sounds\Gibs\gib1.WAV" NAME="Gib2" GROUP="Gibs"
00034	#exec AUDIO IMPORT FILE="Sounds\Gibs\gib3.WAV" NAME="Gib3" GROUP="Gibs"
00035	#exec AUDIO IMPORT FILE="Sounds\Gibs\bthump1.WAV" NAME="Thump" GROUP="Gibs"
00036	
00037	var() mesh	bodyparts[8];
00038	var() float Trails[8];
00039	var() float ZOffset[8];
00040	var() bool bGreenBlood;
00041	var() sound GibOne;
00042	var() sound GibTwo;
00043	var() sound LandedSound;
00044	var	  bool bThumped;
00045	var	  bool bPermanent;
00046	var	  bool bCorroding;
00047	var   ZoneInfo DeathZone;
00048	var	  float	ReducedHeightFactor;
00049	var   float ExistTime;
00050	
00051		function PostBeginPlay()
00052		{
00053			if ( !bDecorative )
00054			{
00055				DeathZone = Region.Zone;
00056				DeathZone.NumCarcasses++;
00057			}
00058			Super.PostBeginPlay();
00059			if ( Physics == PHYS_None )
00060				SetCollision(bCollideActors, false, false);
00061		}
00062	
00063		function Destroyed()
00064		{
00065			if ( !bDecorative )
00066				DeathZone.NumCarcasses--;
00067			Super.Destroyed();
00068		}
00069	
00070		function Initfor(actor Other)
00071		{
00072			local rotator carcRotation;
00073	
00074			if ( bDecorative )
00075			{
00076				DeathZone = Region.Zone;
00077				DeathZone.NumCarcasses++;
00078			}
00079			bDecorative = false;
00080			bMeshCurvy = Other.bMeshCurvy;	
00081			bMeshEnviroMap = Other.bMeshEnviroMap;	
00082			Mesh = Other.Mesh;
00083			Skin = Other.Skin;
00084			Texture = Other.Texture;
00085			Fatness = Other.Fatness;
00086			DrawScale = Other.DrawScale;
00087			SetCollisionSize(Other.CollisionRadius + 4, Other.CollisionHeight);
00088			if ( !SetLocation(Location) )
00089				SetCollisionSize(CollisionRadius - 4, CollisionHeight);
00090	
00091			DesiredRotation = other.Rotation;
00092			DesiredRotation.Roll = 0;
00093			DesiredRotation.Pitch = 0;
00094			AnimSequence = Other.AnimSequence;
00095			AnimFrame = Other.AnimFrame;
00096			AnimRate = Other.AnimRate;
00097			TweenRate = Other.TweenRate;
00098			AnimMinRate = Other.AnimMinRate;
00099			AnimLast = Other.AnimLast;
00100			bAnimLoop = Other.bAnimLoop;
00101			SimAnim.X = 10000 * AnimFrame;
00102			SimAnim.Y = 5000 * AnimRate;
00103			SimAnim.Z = 1000 * TweenRate;
00104			SimAnim.W = 10000 * AnimLast;
00105			bAnimFinished = Other.bAnimFinished;
00106			Velocity = other.Velocity;
00107			Mass = Other.Mass;
00108			if ( Buoyancy < 0.8 * Mass )
00109				Buoyancy = 0.9 * Mass;
00110		}
00111	
00112		function TakeDamage( int Damage, Pawn InstigatedBy, Vector Hitlocation, 
00113								Vector Momentum, name DamageType)
00114		{	
00115			local BloodSpurt b;
00116		
00117			b = Spawn(class'BloodSpurt',,,HitLocation,rot(16384,0,0));
00118			if ( bGreenBlood )
00119				b.GreenBlood();		
00120			if ( !bPermanent )
00121			{
00122				if ( (DamageType == 'Corroded') && (Damage >= 100) )
00123				{
00124					bCorroding = true;
00125					GotoState('Corroding');
00126				}
00127				else
00128					Super.TakeDamage(Damage, instigatedBy, HitLocation, Momentum, DamageType);
00129			}
00130		}
00131	
00132		function CreateReplacement()
00133		{
00134			local CreatureChunks carc;
00135			
00136			if (bHidden)
00137				return;
00138			if ( bodyparts[0] != None )
00139				carc = Spawn(class 'CreatureChunks',,, Location + ZOffset[0] * CollisionHeight * vect(0,0,1)); 
00140			if (carc != None)
00141			{
00142				carc.TrailSize = Trails[0];
00143				carc.Mesh = bodyparts[0];
00144				carc.bMasterChunk = true;
00145				carc.Initfor(self);
00146				carc.Bugs = Bugs;
00147				if ( Bugs != None )
00148					Bugs.SetBase(carc);
00149				Bugs = None;
00150			}
00151			else if ( Bugs != None )
00152				Bugs.Destroy();
00153		}
00154	
00155		function ChunkUp(int Damage)
00156		{
00157			if ( bPermanent )
00158				return;
00159			if ( Region.Zone.bPainZone && (Region.Zone.DamagePerSec > 0) )
00160			{
00161				if ( Bugs != None )
00162					Bugs.Destroy();
00163			}
00164			else
00165				CreateReplacement();
00166			SetPhysics(PHYS_None);
00167			bHidden = true;
00168			SetCollision(false,false,false);
00169			bProjTarget = false;
00170			GotoState('Gibbing');
00171		}
00172	
00173		function Landed(vector HitNormal)
00174		{
00175			local rotator finalRot;
00176			local float OldHeight;
00177			local BloodSpurt b;
00178	
00179			if ( (Velocity.Z < -1000) && !bPermanent )
00180			{
00181				ChunkUp(200);
00182				return;
00183			}
00184	
00185			finalRot = Rotation;
00186			finalRot.Roll = 0;
00187			finalRot.Pitch = 0;
00188			setRotation(finalRot);
00189			SetPhysics(PHYS_None);
00190		 	SetCollision(bCollideActors, false, false);
00191			if ( HitNormal.Z < 0.99 )
00192				ReducedHeightFactor = 0.1;
00193			if ( HitNormal.Z < 0.93 )
00194				ReducedHeightFactor = 0.0;
00195			if ( !IsAnimating() )
00196				LieStill();
00197		}
00198	
00199		function AnimEnd()
00200		{
00201			if ( Physics == PHYS_None )
00202				LieStill();
00203			else if ( Region.Zone.bWaterZone )
00204			{
00205				bThumped = true;
00206				LieStill();
00207			}
00208		}
00209	
00210		function LieStill()
00211		{
00212			SimAnim.X = 10000 * AnimFrame;
00213			SimAnim.Y = 5000 * AnimRate;
00214			if ( !bThumped && !bDecorative )
00215				LandThump();
00216			if ( !bReducedHeight )
00217				ReduceCylinder();
00218		}
00219	
00220		function ThrowOthers()
00221		{
00222			local float dist, shake;
00223			local pawn Thrown;
00224			local PlayerPawn aPlayer;
00225			local vector Momentum;
00226	
00227			Thrown = Level.PawnList;
00228			While ( Thrown != None )
00229			{
00230				aPlayer = PlayerPawn(Thrown);
00231				if ( aPlayer != None )
00232				{	
00233					dist = VSize(Location - aPlayer.Location);
00234					shake = FMax(500, 1500 - dist);
00235					aPlayer.ShakeView( FMax(0, 0.35 - dist/20000),shake, 0.015 * shake );
00236					if ( (aPlayer.Physics == PHYS_Walking) && (dist < 1500) )
00237					{
00238						Momentum = -0.5 * aPlayer.Velocity + 100 * VRand();
00239						Momentum.Z =  7000000.0/((0.4 * dist + 350) * aPlayer.Mass);
00240						aPlayer.AddVelocity(Momentum);
00241					}
00242				}
00243			Thrown = Thrown.nextPawn;
00244			}
00245		}
00246	
00247		function LandThump()
00248		{
00249			local float impact;
00250	
00251			if ( Physics == PHYS_None)
00252			{
00253				bThumped = true;
00254				if ( Role == ROLE_Authority )
00255				{
00256					impact = 0.75 + Velocity.Z * 0.004;
00257					impact = Mass * impact * impact * 0.015;
00258					PlaySound(LandedSound,, impact);
00259					if ( Mass >= 500 )
00260						ThrowOthers();
00261				}
00262			}
00263		}
00264	
00265		function ReduceCylinder()
00266		{
00267			local float OldHeight;
00268	
00269			RemoteRole=ROLE_DumbProxy;
00270			bReducedHeight = true;
00271			SetCollision(bCollideActors,False,False);
00272			OldHeight = CollisionHeight;
00273			if ( ReducedHeightFactor < Default.ReducedHeightFactor )
00274				SetCollisionSize(CollisionRadius, CollisionHeight * ReducedHeightFactor);
00275			else
00276				SetCollisionSize(CollisionRadius + 4, CollisionHeight * ReducedHeightFactor);
00277			PrePivot = vect(0,0,1) * (OldHeight - CollisionHeight); 
00278			if ( !SetLocation(Location - PrePivot) )
00279			{
00280				SetCollisionSize(CollisionRadius - 4, CollisionHeight);
00281				if ( !SetLocation(Location - PrePivot) )
00282				{
00283					SetCollisionSize(CollisionRadius, OldHeight);
00284					SetCollision(false, false, false);
00285					PrePivot = vect(0,0,0);
00286				}
00287			}
00288			PrePivot = PrePivot + vect(0,0,2);
00289			Mass = Mass * 0.8;
00290			Buoyancy = Buoyancy * 0.8;
00291		}
00292	
00293		simulated function HitWall(vector HitNormal, actor Wall)
00294		{
00295			local BloodSpurt b;
00296		
00297			b = Spawn(class 'Bloodspurt',,,,Rotator(HitNormal));
00298			if ( bGreenBlood )	
00299				b.GreenBlood();
00300			b.RemoteRole = ROLE_None;		
00301			Velocity = 0.7 * (Velocity - 2 * HitNormal * (Velocity Dot HitNormal));
00302			Velocity.Z *= 0.9;
00303			if ( Abs(Velocity.Z) < 120 )
00304			{
00305				bBounce = false;
00306				Disable('HitWall');
00307			}
00308		}
00309	
00310		function GibSound()
00311		{
00312			local float decision;
00313	
00314			decision = FRand();
00315			if (decision < 0.2)
00316				PlaySound(GibOne, SLOT_Interact, 0.06 * Mass);
00317			else if ( decision < 0.35 )
00318				PlaySound(GibTwo, SLOT_Interact, 0.06 * Mass);
00319			else if ( decision < 0.5 )
00320				PlaySound(sound'Gib3', SLOT_Interact, 0.06 * Mass);
00321			else if ( decision < 0.8 )
00322				PlaySound(sound'Gib4', SLOT_Interact, 0.06 * Mass);
00323			else 
00324				PlaySound(sound'Gib5', SLOT_Interact, 0.06 * Mass);
00325		}
00326	
00327	auto state Dying
00328	{
00329		ignores TakeDamage;
00330	
00331	Begin:
00332		if ( bCorroding )
00333			GotoState('Corroding');
00334		if ( bDecorative && !bReducedHeight )
00335		{
00336			ReduceCylinder();
00337			SetPhysics(PHYS_None);
00338		}
00339		Sleep(0.2);
00340		if ( bCorroding )
00341			GotoState('Corroding');
00342		GotoState('Dead');
00343	}
00344	
00345	state Dead 
00346	{
00347		function AddFliesAndRats()
00348		{
00349			if ( (flies > 0) && (Bugs == None) && (Level.NetMode == NM_Standalone) )
00350			{
00351				Bugs = Spawn(class 'DeadBodySwarm');
00352				if (Bugs != None)
00353				{
00354					Bugs.SetBase(Self);
00355					DeadBodySwarm(Bugs).swarmsize = flies * (FRand() + 0.5);
00356					DeadBodySwarm(Bugs).swarmradius = collisionradius;
00357				}
00358			}
00359		}
00360	
00361		function CheckZoneCarcasses()
00362		{
00363			local CreatureCarcass C, Best;
00364	
00365			if ( !bDecorative && (DeathZone.NumCarcasses > DeathZone.MaxCarcasses) )
00366			{
00367				Best = self;
00368				ForEach AllActors(class'CreatureCarcass', C)
00369					if ( (C != Self) && !C.bDecorative && (C.DeathZone == DeathZone) && !C.IsAnimating() )
00370					{
00371						if ( Best == self )
00372							Best = C;
00373						else if ( !C.PlayerCanSeeMe() )
00374						{
00375							Best = C;
00376							break;
00377						}
00378					}
00379				Best.Destroy();
00380			}
00381		}
00382	
00383		function Timer()
00384		{
00385			if ( ExistTime <= 0 )
00386				Super.Timer();
00387			else
00388			{
00389				SetPhysics(Phys_Falling);
00390				ExistTime -= 3.0;
00391			}
00392		}
00393	
00394		singular event BaseChange()
00395		{
00396			if ( (Mover(Base) != None) && (ExistTime == 0) )
00397			{
00398				ExistTime = FClamp(30.0 - 2 * DeathZone.NumCarcasses, 5, 12);
00399				SetTimer(3.0, true);
00400			}
00401	
00402			Super.BaseChange();
00403		}
00404	
00405		function BeginState()
00406		{
00407			if ( bDecorative || bPermanent )
00408				lifespan = 0.0;
00409			else
00410			{
00411				if ( Mover(Base) != None )
00412				{
00413					ExistTime = FMax(12.0, 30.0 - 2 * DeathZone.NumCarcasses);
00414					SetTimer(3.0, true);
00415				}
00416				else
00417					SetTimer(FMax(12.0, 30.0 - 2 * DeathZone.NumCarcasses), false); 
00418			}
00419		}
00420	
00421	}
00422	
00423	state Gibbing
00424	{
00425		ignores Landed, HitWall, AnimEnd, TakeDamage, ZoneChange;
00426	
00427	Begin:
00428		Sleep(0.2);
00429		GibSound();
00430		if ( !bPlayerCarcass )
00431			Destroy();
00432	}
00433	
00434	state Corroding
00435	{
00436		ignores Landed, HitWall, AnimEnd, TakeDamage, ZoneChange;
00437	
00438		function Tick( float DeltaTime )
00439		{
00440			local int NewFatness; 
00441			local float splashSize;
00442			local actor splash;
00443	
00444			NewFatness = fatness - 80 * DeltaTime;
00445			if ( NewFatness < 85 )
00446			{
00447				if ( Region.Zone.bWaterZone && Region.Zone.bDestructive )
00448				{
00449					splashSize = FClamp(0.0002 * Mass * (250 - 0.5 * FMax(-600,Velocity.Z)), 1.0, 4.0 );
00450					if ( Region.Zone.ExitSound != None )
00451						PlaySound(Region.Zone.ExitSound, SLOT_Interact, splashSize);
00452					if ( Region.Zone.ExitActor != None )
00453					{
00454						splash = Spawn(Region.Zone.ExitActor); 
00455						if ( splash != None )
00456							splash.DrawScale = splashSize;
00457					}
00458				}			
00459				Destroy();
00460			}
00461			fatness = Clamp(NewFatness, 0, 255);
00462		}
00463		
00464		function BeginState()
00465		{
00466			Disable('Tick');
00467		}
00468		
00469	Begin:
00470		Sleep(0.5);
00471		Enable('Tick');	
00472	}
00473	
00474	defaultproperties
00475	{
00476	     bodyparts(0)=LodMesh'UnrealShare.CowBody1'
00477	     bodyparts(1)=LodMesh'UnrealShare.CowBody1'
00478	     bodyparts(2)=LodMesh'UnrealShare.CowBody2'
00479	     bodyparts(3)=LodMesh'UnrealShare.CowBody2'
00480	     bodyparts(4)=LodMesh'UnrealShare.LiverM'
00481	     bodyparts(5)=LodMesh'UnrealShare.LiverM'
00482	     Trails(0)=0.500000
00483	     Trails(1)=0.500000
00484	     Trails(2)=0.500000
00485	     Trails(3)=0.500000
00486	     Trails(4)=0.500000
00487	     Trails(5)=0.500000
00488	     Trails(6)=0.500000
00489	     Trails(7)=0.500000
00490	     ZOffset(0)=0.500000
00491	     ZOffset(1)=-0.500000
00492	     GibOne=Sound'UnrealShare.Gibs.Gib1'
00493	     GibTwo=Sound'UnrealShare.Gibs.Gib2'
00494	     LandedSound=Sound'UnrealShare.Gibs.Thump'
00495	     ReducedHeightFactor=0.300000
00496	     flies=4
00497	     bSlidingCarcass=True
00498	     RemoteRole=ROLE_SimulatedProxy
00499	     TransientSoundVolume=3.000000
00500	     bBlockActors=True
00501	     bBlockPlayers=True
00502	     NetPriority=2.500000
00503	}

End Source Code