Engine
Class Debris

source: c:\runehov\Engine\Classes\Debris.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Effects
         |
         +--Engine.Debris
Direct Known Subclasses:DebrisFlesh, DebrisIce, DebrisStone, DebrisWood, DiscardedHealth

class Debris
extends Engine.Effects

//============================================================================= // Debris. // May want to move this to Projectiles so it can be simulated in netplay //=============================================================================
States
OnGround

Function Summary
 
simulated
HitWall(vector HitNormal, Actor HitWall)
 
simulated
Landed(vector HitNormal, Actor HitActor)
 
simulated
PlayLandSound()
 
simulated
PreBeginPlay()
 void SetMomentum(vector Mom)
 void SetSize(float Size)
 void SetTexture(Texture tex)
 
simulated
SpawnDebrisDecal(vector HitNormal)
 
simulated
Spawned()


State OnGround Function Summary



Source Code


00001	//=============================================================================
00002	// Debris.
00003	// May want to move this to Projectiles so it can be simulated in netplay
00004	//=============================================================================
00005	class Debris extends Effects
00006		abstract;
00007	
00008	
00009	var(Sounds) sound	LandSound;
00010	
00011	simulated function PreBeginPlay()
00012	{
00013		Super.PreBeginPlay();
00014		SkelMesh=Rand(6);
00015	}
00016	
00017	simulated function Spawned()
00018	{
00019		Velocity = (VRand()+vect(0,0,1)) * RandRange(100,400);
00020		RotationRate.Yaw = RandRange(-64000, 64000);
00021		RotationRate.Pitch = RandRange(-64000, 64000);
00022		RotationRate.Roll = RandRange(-64000, 64000);
00023	}
00024	
00025	function SetSize(float Size)
00026	{
00027		Size=Min(Size, 2.5);
00028		Size += FRand()-0.5;
00029		DrawScale=Size;
00030		SetCollisionSize(Default.CollisionRadius*Size, Default.CollisionHeight*Size);
00031	}
00032	
00033	function SetTexture(Texture tex)
00034	{
00035		if (tex != None)
00036		{
00037			SkelGroupSkins[1] = tex;
00038		}
00039	}
00040	
00041	function SetMomentum(vector Mom)
00042	{
00043		if (Mom != vect(0,0,0))
00044			Velocity = (Normal(Mom)*2 + VRand() + vect(0,0,1)) * RandRange(50,300);
00045		else
00046			Velocity = (VRand()*2+vect(0,0,2)) * RandRange(50,400);
00047	}
00048	
00049	simulated function SpawnDebrisDecal(vector HitNormal) {}
00050	
00051	simulated function PlayLandSound()
00052	{
00053		PlaySound(LandSound);
00054	}
00055	
00056	simulated function Landed(vector HitNormal, actor HitActor)
00057	{
00058		HitWall(HitNormal, HitActor);
00059	}
00060		
00061	simulated function HitWall(vector HitNormal, actor HitWall)
00062	{
00063		local float speed;
00064		
00065		speed = VSize(velocity);
00066		LifeSpan = RandRange(10, 20);
00067		if (DrawScale < 0.5)
00068			Destroy();
00069	
00070		if (speed>300 && DrawScale>0.3 && FRand()>0.6)
00071		{
00072			if (!Region.Zone.bWaterZone)
00073				PlayLandSound();
00074		}
00075	
00076		if(((HitNormal.Z > 0.8) && (speed < 60)) || (speed < 20))
00077		{
00078			SetPhysics(PHYS_None);
00079			bBounce = false;
00080			bFixedRotationDir = false;
00081			SetCollision(false, false, false);
00082			bCollideWorld = false;
00083			bLookFocusPlayer = false; // Player isn't interested anymore
00084			bSimFall=false;
00085			GotoState('OnGround');
00086	
00087			if (!Region.Zone.bWaterZone)
00088				SpawnDebrisDecal(HitNormal);
00089			if (Level.NetMode != NM_Standalone)
00090				Destroy();
00091		}
00092		else
00093		{			
00094			SetPhysics(PHYS_Falling);
00095			RotationRate.Yaw = VSize(Velocity) * 100;
00096			RotationRate.Pitch = VSize(Velocity) * 50;
00097			
00098			Velocity = 0.45 * (Velocity - 2 * HitNormal * (Velocity Dot HitNormal));
00099			if(VSize(Velocity) < 20)
00100			{
00101				self.HitWall(HitNormal, HitWall); // Force the actor to stop
00102			}
00103			DesiredRotation = rotator(HitNormal);
00104	
00105			if (!Region.Zone.bWaterZone)
00106	//		if (speed > 200 || FRand() > 0.3)
00107	//		{
00108				SpawnDebrisDecal(HitNormal);
00109	//		}
00110		}
00111	}
00112	
00113	
00114	State OnGround
00115	{
00116	}
00117	
00118	defaultproperties
00119	{
00120	     bNetOptional=True
00121	     bSimFall=True
00122	     Physics=PHYS_Falling
00123	     DrawType=DT_SkeletalMesh
00124	     CollisionRadius=10.000000
00125	     CollisionHeight=5.000000
00126	     bCollideWorld=True
00127	     bBounce=True
00128	     bFixedRotationDir=True
00129	     Buoyancy=50.000000
00130	}

End Source Code