UnrealI
Class BigRock

source: e:\games\UnrealTournament\UnrealI\Classes\BigRock.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Projectile
         |
         +--UnrealI.BigRock
Direct Known Subclasses:CatapultRock, Boulder1, Magma

class BigRock
extends Engine.Projectile

//============================================================================= // BigRock. //=============================================================================
States
Sitting, Flying

Function Summary
 void InitFrag(BigRock myParent, float scale)
 void PostBeginPlay()
 void SpawnChunks(int num)
 void TakeDamage(int NDamage, Pawn instigatedBy, Vector hitlocation, Vector momentum, name damageType)


State Sitting Function Summary


State Flying Function Summary
 void MakeSound()
 void ProcessTouch(Actor Other, Vector HitLocation)



Source Code


00001	//=============================================================================
00002	// BigRock.
00003	//=============================================================================
00004	class BigRock extends Projectile;
00005	
00006	#exec MESH IMPORT MESH=TBoulder ANIVFILE=..\UnrealShare\MODELS\rock_a.3D DATAFILE=..\UnrealShare\MODELS\rock_d.3D X=0 Y=0 Z=0
00007	#exec MESH ORIGIN MESH=TBoulder X=0 Y=0 Z=0 YAW=64
00008	
00009	#exec MESH SEQUENCE MESH=TBoulder SEQ=All  STARTFRAME=0  NUMFRAMES=4
00010	#exec MESH SEQUENCE MESH=TBoulder SEQ=Pos1  STARTFRAME=0   NUMFRAMES=1
00011	#exec MESH SEQUENCE MESH=TBoulder SEQ=Pos2  STARTFRAME=1   NUMFRAMES=1
00012	#exec MESH SEQUENCE MESH=TBoulder SEQ=Pos3  STARTFRAME=2   NUMFRAMES=1
00013	#exec MESH SEQUENCE MESH=TBoulder SEQ=Pos4  STARTFRAME=3   NUMFRAMES=1
00014	
00015	#exec TEXTURE IMPORT NAME=JBoulder1 FILE=..\UnrealShare\MODELS\rock.PCX GROUP=Skins
00016	#exec MESHMAP SCALE MESHMAP=TBoulder X=0.01 Y=0.01 Z=0.02
00017	#exec MESHMAP SETTEXTURE MESHMAP=TBoulder NUM=1 TEXTURE=JBoulder1
00018	
00019	#exec AUDIO IMPORT FILE="Sounds\Titan\Rockhit1.wav" NAME="Rockhit" GROUP="Titan"
00020	
00021	function PostBeginPlay()
00022	{
00023		local float decision;
00024	
00025		Super.PostBeginPlay();
00026		Velocity = Vector(Rotation) * (0.8 + (0.3 * FRand())) * speed;
00027		DesiredRotation.Pitch = Rotation.Pitch + Rand(2000) - 1000;
00028		DesiredRotation.Roll = Rotation.Roll + Rand(2000) - 1000;
00029		DesiredRotation.Yaw = Rotation.Yaw + Rand(2000) - 1000; 
00030		decision = FRand();
00031		if (decision<0.25) 
00032			PlayAnim('Pos2', 1.0, 0.0);
00033		else if (decision<0.5) 
00034			PlayAnim('Pos3', 1.0, 0.0);
00035		else if (decision <0.75) 
00036			PlayAnim('Pos4', 1.0, 0.0);
00037		if (FRand() < 0.5)
00038			RotationRate.Pitch = Rand(180000);
00039		if ( (RotationRate.Pitch == 0) || (FRand() < 0.8) )
00040			RotationRate.Roll = Max(0, 50000 + Rand(200000) - RotationRate.Pitch);
00041	}
00042	
00043	function TakeDamage( int NDamage, Pawn instigatedBy, 
00044					Vector hitlocation, Vector momentum, name damageType) {
00045	
00046		// If a rock is shot, it will fragment into a number of smaller
00047		// pieces.  The player can fragment a giant boulder which would
00048		// otherwise crush him/her, and escape with minor or no wounds
00049		// when a multitude of smaller rocks hit.
00050		
00051		//log ("Rock gets hit by something...");
00052		Velocity += Momentum/(DrawScale * 10);
00053		if (Physics == PHYS_None )
00054		{
00055			SetPhysics(PHYS_Falling);
00056			Velocity.Z += 0.4 * VSize(momentum);
00057		}
00058		SpawnChunks(4);
00059	}
00060	
00061	function SpawnChunks(int num)
00062	{
00063		local int    NumChunks,i;
00064		local BigRock   TempRock;
00065		local float scale;
00066	
00067		if ( DrawScale < 1 + FRand() )
00068			return;
00069	
00070		NumChunks = 1+Rand(num);
00071		scale = sqrt(0.52/NumChunks);
00072		if ( scale * DrawScale < 1 )
00073		{
00074			NumChunks *= scale * DrawScale;
00075			scale = 1/DrawScale;
00076		}
00077		speed = VSize(Velocity);
00078		for (i=0; i<NumChunks; i++) 
00079		{
00080			TempRock = Spawn(class'BigRock');
00081			if (TempRock != None )
00082				TempRock.InitFrag(self, scale);
00083		}
00084		InitFrag(self, 0.5);
00085	}
00086	
00087	function InitFrag(BigRock myParent, float scale)
00088	{
00089		local rotator newRot;
00090	
00091		// Pick a random size for the chunks
00092		RotationRate = RotRand();
00093		scale *= (0.5 + FRand());
00094		DrawScale = scale * myParent.DrawScale;
00095		if ( DrawScale <= 2 )
00096			SetCollisionSize(0,0);
00097		else
00098			SetCollisionSize(CollisionRadius * DrawScale/Default.DrawScale, CollisionHeight * DrawScale/Default.DrawScale);
00099	
00100		Velocity = Normal(VRand() + myParent.Velocity/myParent.speed) 
00101					* (myParent.speed * (0.4 + 0.3 * (FRand() + FRand())));
00102	}	
00103	
00104	auto state Flying
00105	{
00106		function ProcessTouch (Actor Other, Vector HitLocation)
00107		{
00108			local int hitdamage;
00109	
00110			if ( Other == instigator )
00111				return;
00112			PlaySound(ImpactSound, SLOT_Interact, DrawScale/10);	
00113	
00114			if ( !Other.IsA('BigRock') && !Other.IsA('Titan') )
00115			{
00116				Hitdamage = Damage * 0.00002 * (DrawScale**3) * speed;
00117				if ( (HitDamage > 6) && (speed > 150) )
00118					Other.TakeDamage(hitdamage, instigator,HitLocation,
00119						(35000.0 * Normal(Velocity)), 'crushed' );
00120			}
00121		}
00122		
00123		simulated function Landed(vector HitNormal)
00124		{
00125			HitWall(HitNormal, None);
00126		}
00127	
00128		function MakeSound()
00129		{
00130			local float soundRad;
00131	
00132			if ( Drawscale > 2.0 )
00133				soundRad = 500 * DrawScale;
00134			else
00135				soundRad = 100;
00136			PlaySound(ImpactSound, SLOT_Misc, DrawScale/8,,soundRad);	
00137		}
00138	
00139		simulated function HitWall (vector HitNormal, actor Wall)
00140		{
00141			local vector RealHitNormal;
00142	
00143			if ( (Role == ROLE_Authority) && (Mover(Wall) != None) && Mover(Wall).bDamageTriggered )
00144				Wall.TakeDamage( Damage, instigator, Location, MomentumTransfer * Normal(Velocity), '');
00145			speed = VSize(velocity);
00146			MakeSound();
00147			if ( (HitNormal.Z > 0.8) && (speed < 60 - DrawScale) )
00148			{
00149				SetPhysics(PHYS_None);
00150				GotoState('Sitting');	
00151			}
00152			else
00153			{			
00154				SetPhysics(PHYS_Falling);
00155				RealHitNormal = HitNormal;
00156				if ( FRand() < 0.5 )
00157					RotationRate.Pitch = Max(RotationRate.Pitch, 100000);
00158				else
00159					RotationRate.Roll = Max(RotationRate.Roll, 100000);
00160				HitNormal = Normal(HitNormal + 0.5 * VRand()); 
00161				if ( (RealHitNormal Dot HitNormal) < 0 )
00162					HitNormal.Z *= -0.7;
00163				Velocity = 0.7 * (Velocity - 2 * HitNormal * (Velocity Dot HitNormal));
00164				DesiredRotation = rotator(HitNormal);
00165				if ( (speed > 150) && (FRand() * 30 < DrawScale) )
00166					SpawnChunks(4);
00167			}
00168		}
00169	
00170	Begin:
00171		Sleep(5.0);
00172		SetPhysics(PHYS_Falling);
00173	}
00174	
00175	State Sitting
00176	{
00177	Begin:
00178		SetPhysics(PHYS_None);
00179		Sleep(DrawScale * 0.5);
00180		Destroy();
00181	}
00182	
00183	defaultproperties
00184	{
00185	     speed=900.000000
00186	     MaxSpeed=1000.000000
00187	     Damage=40.000000
00188	     ImpactSound=Sound'UnrealI.Titan.Rockhit'
00189	     bNetTemporary=False
00190	     Physics=PHYS_Falling
00191	     RemoteRole=ROLE_SimulatedProxy
00192	     LifeSpan=20.000000
00193	     AnimSequence=Pos1
00194	     Mesh=LodMesh'UnrealI.TBoulder'
00195	     DrawScale=7.500000
00196	     CollisionRadius=30.000000
00197	     CollisionHeight=30.000000
00198	     bBounce=True
00199	     bFixedRotationDir=True
00200	}

End Source Code