## Engine
Class Fragment

source: C:\XIII\Engine\Classes\Fragment.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Effects
             |
             +--Engine.Fragment

Direct Known Subclasses:FragmentExplo

class Fragment
extends Engine.Effects

    //=============================================================================
    // Fragment.
    //=============================================================================

Variables
`ImpactSound,` | `AltImpactSound`
`MESH` | `Fragments[11]`
`float` | `SplashTime`
`bool` | `bFirstHit`
`int` | `numFragmentTypes`

States
Dying, Flying

Function Summary
`simulated` | `CalcVelocity(vector Momentum)`
`bool` | `CanSplash()`
`simulated` | `HitWall(vector HitNormal, Actor HitWall)`
`void` | `RandSpin(float spinRate)`

State Dying Function Summary

State Flying Function Summary
`void` | `PhysicsVolumeChange(PhysicsVolume NewVolume)`

Source Code

    00001	//=============================================================================
    00002	// Fragment.
    00003	//=============================================================================
    00004	class Fragment extends Effects;
    00005
    00006	var() MESH Fragments[11];
    00007	var int numFragmentTypes;
    00008	var bool bFirstHit;
    00009	var() sound    ImpactSound, AltImpactSound;
    00010	var()	float  SplashTime;
    00011
    00012	function bool CanSplash()
    00013	{
    00014		if ( (Level.TimeSeconds - SplashTime > 0.25)
    00015			&& (Physics == PHYS_Falling)
    00016			&& (Abs(Velocity.Z) > 100) )
    00017		{
    00018			SplashTime = Level.TimeSeconds;
    00019			return true;
    00020		}
    00021		return false;
    00022	}
    00023
    00024
    00025	simulated function CalcVelocity(vector Momentum)
    00026	{
    00027		local float ExplosionSize;
    00028
    00029		ExplosionSize = 0.011 * VSize(Momentum);
    00030		Velocity = 0.0033 * Momentum + 0.7 * VRand()*(ExplosionSize+FRand()*100.0+100.0);
    00031		Velocity.z += 0.5 * ExplosionSize;
    00032	}
    00033
    00034	simulated function HitWall (vector HitNormal, actor HitWall)
    00035	{
    00036		local float speed;
    00037
    00038		Velocity = 0.5*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);   // Reflect off Wall w/damping
    00039		speed = VSize(Velocity);
    00040		if (bFirstHit && speed<400)
    00041		{
    00042			bFirstHit=False;
    00043			bRotatetoDesired=True;
    00044			bFixedRotationDir=False;
    00045			DesiredRotation.Pitch=0;
    00046			DesiredRotation.Yaw=FRand()*65536;
    00047			DesiredRotation.roll=0;
    00048		}
    00049		RotationRate.Yaw = RotationRate.Yaw*0.75;
    00050		RotationRate.Roll = RotationRate.Roll*0.75;
    00051		RotationRate.Pitch = RotationRate.Pitch*0.75;
    00052		if ( (speed < 60) && (HitNormal.Z > 0.7) )
    00053		{
    00054			SetPhysics(PHYS_none);
    00055			bBounce = false;
    00056			GoToState('Dying');
    00057		}
    00058		else if (speed > 80)
    00059		{
    00060			if (FRand()<0.5)
    00061				PlaySound(ImpactSound);
    00062			else
    00063				PlaySound(AltImpactSound);
    00064		}
    00065	}
    00066
    00067	simulated final function RandSpin(float spinRate)
    00068	{
    00069		DesiredRotation = RotRand();
    00070		RotationRate.Yaw = spinRate * 2 *FRand() - spinRate;
    00071		RotationRate.Pitch = spinRate * 2 *FRand() - spinRate;
    00072		RotationRate.Roll = spinRate * 2 *FRand() - spinRate;
    00073	}
    00074
    00075	auto state Flying
    00076	{
    00077		simulated function timer()
    00078		{
    00079			GoToState('Dying');
    00080		}
    00081
    00082		simulated singular function PhysicsVolumeChange( PhysicsVolume NewVolume )
    00083		{
    00084			if ( NewVolume.bWaterVolume )
    00085			{
    00086				Velocity = 0.2 * Velocity;
    00087				if (bFirstHit)
    00088				{
    00089					bFirstHit=False;
    00090					bRotatetoDesired=True;
    00091					bFixedRotationDir=False;
    00092					DesiredRotation.Pitch=0;
    00093					DesiredRotation.Yaw=FRand()*65536;
    00094					DesiredRotation.roll=0;
    00095				}
    00096
    00097				RotationRate = 0.2 * RotationRate;
    00098				GotoState('Dying');
    00099			}
    00100		}
    00101
    00102		simulated function BeginState()
    00103		{
    00104			RandSpin(125000);
    00105			if (abs(RotationRate.Pitch)<10000)
    00106				RotationRate.Pitch=10000;
    00107			if (abs(RotationRate.Roll)<10000)
    00108				RotationRate.Roll=10000;
    00109			Mesh = Fragments[int(FRand()*numFragmentTypes)];
    00110			if ( Level.NetMode == NM_Standalone )
    00111				LifeSpan = 20 + 40 * FRand();
    00112			SetTimer(5.0,True);
    00113		}
    00114	}
    00115
    00116	state Dying
    00117	{
    00118		function TakeDamage( int Dam, Pawn instigatedBy, Vector hitlocation,
    00119								Vector momentum, class<DamageType> damageType)
    00120		{
    00121			Destroy();
    00122		}
    00123
    00124		simulated function timer()
    00125		{
    00126			if ( !PlayerCanSeeMe() )
    00127				Destroy();
    00128		}
    00129
    00130		simulated function BeginState()
    00131		{
    00132			SetTimer(1 + FRand(),True);
    00133			SetCollision(true, false, false);
    00134		}
    00135	}
    00136
    00137	defaultproperties
    00138	{
    00139	     bFirstHit=True
    00140	     bDestroyInPainVolume=True
    00141	     bCollideWorld=True
    00142	     bBounce=True
    00143	     bFixedRotationDir=True
    00144	     Physics=PHYS_Falling
    00145	     DrawType=DT_Mesh
    00146	     LifeSpan=20.000000
    00147	     CollisionRadius=18.000000
    00148	     CollisionHeight=4.000000
    00149	}

End Source Code