## XIII
Class InteractiveCan

source: C:\XIII\XIII\Classes\InteractiveCan.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Decoration
             |
             +--XIII.InteractiveCan

Direct Known Subclasses:None

class InteractiveCan
extends Engine.Decoration

    //-----------------------------------------------------------
    // ELR Some can that can be shot using no physic but a 'weird behavioring' system ;)
    //-----------------------------------------------------------

Variables
`Trail` | `MyTrail` Should be spawned & init() in child classes (because spec inits needed).
`class` | `MyTrailClass`
`int` | `NbSpins`
`bool` | `bFirstTimeGetOffThisWay`

Function Summary
`simulated` | `Spin(float spinRate)`
    //_____________________________________________________________________________

Source Code

    00001	//-----------------------------------------------------------
    00002	// ELR Some can that can be shot using no physic but a 'weird behavioring' system ;)
    00003	//-----------------------------------------------------------
    00004	class InteractiveCan extends Decoration;
    00005
    00006	var() bool bFirstTimeGetOffThisWay;
    00007
    00008	var int NbSpins;
    00009	var class<Trail> MyTrailClass;
    00010	var Trail MyTrail;            // Should be spawned & init() in child classes (because spec inits needed).
    00011	var(sound) sound hHitSound;
    00012	var(sound) sound hWallBounceSound;
    00013	var(sound) sound hGroundHitSound;
    00014
    00015	//_____________________________________________________________________________
    00016	simulated function Spin(float spinRate)
    00017	{
    00018	    NbSpins = Max(NbSpins, 0);
    00019	    DesiredRotation.Roll = 16384;
    00020	    DesiredRotation.Pitch = 0;
    00021	    DesiredRotation.Yaw = Rand(65535);
    00022	    RotationRate.Yaw = spinRate * ( DesiredRotation.Yaw - rotation.Yaw ) * NbSpins;
    00023	    RotationRate.Pitch = spinRate * ( DesiredRotation.Pitch - rotation.Pitch ) * NbSpins;
    00024	    RotationRate.Roll = spinRate * ( DesiredRotation.Roll - rotation.Roll ) * NbSpins;
    00025	    SetCollisionSize(8,6); // reduce coll height to have can on ground
    00026	}
    00027
    00028	//_____________________________________________________________________________
    00029	event TakeDamage( int Damage, Pawn EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType)
    00030	{
    00031	    local ImpactEmitter B;
    00032
    00033	    PlaySound(hHitSound);
    00034
    00035	    Instigator = EventInstigator;
    00036	    if ( Instigator.Base == self )
    00037	      return;
    00038
    00039	    SetPhysics(PHYS_Falling);
    00040	    if ( bFirstTimeGetOffThisWay )
    00041	    {
    00042	      Velocity = 300.0*vector(Rotation)*(0.8+fRand()*0.4);
    00043	      Velocity.Z = fMin(100.0, Velocity.Z);
    00044	      Acceleration = vect(0,0,-1.0)*abs(Velocity.Z);
    00045	      bFirstTimeGetOffThisWay = false;
    00046	    }
    00047	    else
    00048	    {
    00049	      Velocity = vSize(Momentum)/50.0*normal(Location-HitLocation)*(0.8+fRand()*0.4);
    00050	      Velocity.Z = fMin(100.0, Velocity.Z);
    00051	      Acceleration = vect(0,0,-1.0)*abs(Velocity.Z);
    00052	    }
    00053	    bBounce = true;
    00054	    NbSpins = 3;
    00055	    Spin(3);
    00056	    B = Spawn(class'BulletMetalEmitter',self,, HitLocation+Normal(-Momentum), Rotator(-Momentum));
    00057	//    if ( B!=none && (EventInstigator != none) )
    00058	//      B.NoiseMake(XIIIPawn(EventInstigator), 0.3);
    00059	    MakeNoise(0.3);
    00060	    if ( MyTrail == none )
    00061	    {
    00062	      MyTrail = Spawn(MyTrailClass,self,,Location);
    00063	      MyTrail.Init();
    00064	    }
    00065	}
    00066
    00067	//_____________________________________________________________________________
    00068	event EndedRotation();
    00069
    00070	//_____________________________________________________________________________
    00071	event HitWall( vector HitNormal, actor HitWall )
    00072	{
    00073	    local float fSpeed;
    00074
    00075	//    Log(self@"HitWall="$HitNormal@"NbSpin"@NbSpins);
    00076	//    MyTrail.RotationSpeed *= 2.0;
    00077
    00078	//    if (Wall != none)
    00079	//      PlayImpactSound(HitNormal, Wall);
    00080	    NbSpins --;
    00081	    Spin(3);
    00082
    00083	    if ( abs(HitNormal.z) < 0.5 )
    00084	      PlaySound(hWallBounceSound);
    00085	    else
    00086	      PlaySound(hGroundHitSound);
    00087
    00088	    // Reflect off Wall
    00089	    if ( HitNormal.Z < 0.85 )
    00090	      Velocity = 0.5*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);
    00091	    else
    00092	    { // On ground
    00093	      if ( NbSpins > 0 )
    00094	        Velocity = 0.25*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);
    00095	      else
    00096	        Velocity = vect(0,0,0);
    00097	    }
    00098	    fSpeed = VSize(Velocity);
    00099	    if ( Velocity.Z > 400 )
    00100	      Velocity.Z = 0.5 * (400 + Velocity.Z);
    00101	    else if ( (fSpeed < 10) && (HitWall != none) ) // don't stop of touching and not hitting real wall.
    00102	    {
    00103	      bBounce = False;
    00104	      SetPhysics(PHYS_None);
    00105	    }
    00106	}
    00107
    00108
    00109
    00110	defaultproperties
    00111	{
    00112	     MyTrailClass=Class'XIII.ICanTrail'
    00113	     hHitSound=Sound'XIIIsound.Items__InteractiveCan.InteractiveCan__hCanTip1'
    00114	     hWallBounceSound=Sound'XIIIsound.Items__InteractiveCan.InteractiveCan__hCanRebound1'
    00115	     hGroundHitSound=Sound'XIIIsound.Items__InteractiveCan.InteractiveCan__hCanFall1'
    00116	     bStatic=False
    00117	     bStasis=False
    00118	     bInteractive=False
    00119	     bCollideActors=True
    00120	     bCollideWorld=True
    00121	     bBlockActors=True
    00122	     bBlockPlayers=True
    00123	     bUseCylinderCollision=True
    00124	     bBounce=True
    00125	     bFixedRotationDir=True
    00126	     DrawType=DT_StaticMesh
    00127	     StaticMesh=StaticMesh'MeshObjetsPickup.conserve'
    00128	     CollisionRadius=8.000000
    00129	     CollisionHeight=10.000000
    00130	     bDirectional=True
    00131	}

End Source Code