## XIII
Class GrenadFlying

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

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Projectile
             |
             +--XIII.XIIIProjectile
                |
                +--XIII.GrenadFlying

Direct Known Subclasses:FGrenadFlying

class GrenadFlying
extends XIII.XIIIProjectile

    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------

Variables
`int` | `NumExtraGrenades` recorded in order tobe detected by a basesoldier
`Count,` | `SmokeRate` recorded in order tobe detected by a basesoldier
`bool` | `bArmed`
`bool` | `bExploded` duration before explosion
`bCanHitOwner,` | `bHitWater`
`bool` | `bLastWallHit` duration before explosion
`bool` | `bPreExplode` duration before explosion
`bool` | `bRecordedByGenAlerte` recorded in order tobe detected by a basesoldier
`float` | `fLifeTime` duration before explosion
`float` | `fPreExplodeTime` duration before explosion
`vector` | `vLastWallHit` duration before explosion

Function Summary
`simulated` | `BeginPlay()`
    //_____________________________________________________________________________
`simulated` | `Explosion(vector HitLocation)`
    //_____________________________________________________________________________
`simulated` | `HitWall(vector HitNormal, Actor Wall)`
    //_____________________________________________________________________________
`simulated` | `Landed(vector HitNormal)`
    //_____________________________________________________________________________
`simulated` | `PostBeginPlay()`
    //_____________________________________________________________________________
    // Set up speed
`void` | `PreExplode()`
    //_____________________________________________________________________________
`simulated` | `ProcessTouch(Actor Other, vector HitLocation)`
    //_____________________________________________________________________________
`void` | `SetPreExplosion(float time)`
    //_____________________________________________________________________________
`simulated` | `Timer()`
    //_____________________________________________________________________________

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class GrenadFlying extends XIIIProjectile;
    00005
    00006	var bool bCanHitOwner, bHitWater;
    00007	var bool bArmed;
    00008	var bool bRecordedByGenAlerte; //recorded in order tobe detected by a basesoldier
    00009	var float Count, SmokeRate;
    00010	var int NumExtraGrenades;
    00011	var float fLifeTime;                // duration before explosion
    00012	// SouthEnd XBOX specific use
    00013	var vector vLastWallHit;
    00014	var bool bLastWallHit;
    00015	var bool bPreExplode;
    00016	var float fPreExplodeTime;
    00017	var bool bExploded;
    00018	// SouthEnd XBOX END
    00019
    00020	replication
    00021	{
    00022	    Reliable if ( Role == ROLE_Authority )
    00023	      fLifeTime;
    00024	}
    00025
    00026	//_____________________________________________________________________________
    00027	// Set up speed
    00028	simulated function PostBeginPlay()
    00029	{
    00030	    local vector X,Y,Z;
    00031	    local rotator RandRot;
    00032
    00033	    Super.PostBeginPlay();
    00034	    bArmed=false;
    00035	    fLifeTime = 3.0;        // Set this just in case it will be thrown by no player thus intialized after postbeginplay
    00036	    SetTimer(0.1,false);    // Call it again later with the right intialized lifetime
    00037
    00038	    if ( Role == ROLE_Authority )
    00039	    {
    00040	      GetAxes(Instigator.GetViewRotation(),X,Y,Z);
    00041	      Velocity = X * (Instigator.Velocity Dot X)*0.4 + Vector(Rotation) * (Speed + FRand() * 100);
    00042	      Velocity.z += 210;
    00043	      MaxSpeed = 1000;
    00044	      RandSpin(50000);
    00045	      bCanHitOwner = False;
    00046	      if (Instigator.HeadVolume.bWaterVolume)
    00047	      {
    00048	        bHitWater = True;
    00049	        Disable('Tick');
    00050	        Velocity=0.6*Velocity;
    00051	      }
    00052	    }
    00053	    //FRD   appel GenAlerte pour gestion grenade
    00054	    if (level.bLonePlayer && instigator.controller!=none && instigator.controller.bIsPlayer)
    00055	    {
    00056	      XIIIGameInfo(level.game).genalerte.trigger(self, instigator);
    00057	      bRecordedByGenAlerte = true;
    00058	    }
    00059
    00060	    if ( (Instigator != none) && (Instigator.Base.Velocity == vect(0,0,0)) )
    00061	    {
    00062	      MyTrail = Spawn(MyTrailClass,self,,Location);
    00063	      MyTrail.Init();
    00064	    }
    00065	}
    00066
    00067	//_____________________________________________________________________________
    00068	simulated function BeginPlay()
    00069	{
    00070	    SmokeRate = 0.15;
    00071	}
    00072
    00073	//_____________________________________________________________________________
    00074	function SetPreExplosion(float time)
    00075	{
    00076	  if ( (Level.Game != none) && (Level.Game.DetailLevel < 2) )
    00077	    return;
    00078	  if ( !Level.bLonePlayer )
    00079	    return;
    00080	  fPreExplodeTime = time;
    00081	  bPreExplode = true;
    00082	}
    00083
    00084	//_____________________________________________________________________________
    00085	simulated function Timer()
    00086	{
    00087	    if ( !bArmed )
    00088	    { // set the timer back one the fLifeTime has been initialized by the weapon
    00089	      bArmed=true;
    00090	      fLifeTime = fMax(0.05, fLifeTime);
    00091	      if (bPreExplode) //SOUTHEND Set a timer to PreExplode (a call just before the explosion occurs)
    00092	        SetTimer(fPreExplodeTime, false);
    00093	      else
    00094	        SetTimer(fLifeTime, false);
    00095	      return;
    00096	    }
    00097
    00098	    //SOUTHEND
    00099	    // Check if we this is the call to PreExplode before the actual explosion
    00100	    if ( bPreExplode )
    00101	    {
    00102	      bPreExplode = false;
    00103	      SetTimer(fLifeTime-fPreExplodeTime, false);
    00104	      PreExplode();
    00105	      return;
    00106	    }
    00107
    00108	    if ( bSpawnDecal )
    00109	    {
    00110	      if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) )
    00111	        Spawn(ExplosionDecal,self,,Location, rotator(vect(0,0,-1)));
    00112	      Destroy();
    00113	    }
    00114	    else
    00115	    {
    00116	      Explosion(Location+Vect(0,0,1)*16);
    00117	      bSpawnDecal = true;
    00118	      SetTimer(0.2, false);
    00119	    }
    00120	}
    00121
    00122	//_____________________________________________________________________________
    00123	simulated function Landed( vector HitNormal )
    00124	{
    00125	//    Log("GRENAD Landed Base="$Base);
    00126	    HitWall( HitNormal, Base );
    00127	}
    00128
    00129	//_____________________________________________________________________________
    00130	simulated function ProcessTouch( actor Other, vector HitLocation )
    00131	{
    00132	    Local vector vt;
    00133
    00134	    if ( Pawn(Other) != none )
    00135	    {
    00136	      vT = Location - Other.Location;
    00137	      if ( VT.Z > Other.CollisionRadius * 0.9 )
    00138	      {
    00139	//        Log("GRENAD should bounce off pawn"@other@"head");
    00140	        vt = HitLocation - Other.Location;
    00141	        vT.Z = 0;
    00142	        Velocity = 0.3*Speed*(normal(vT) + vect(0,0,1));
    00143	//        Velocity = normal(vT)*vSize(Velocity);
    00144	        Speed = vSize(Velocity);
    00145	//        HitWall( normal(normal(vt) + vect(0,0,1)), Other );
    00146	        return;
    00147	      }
    00148	//      else
    00149	//        Log("GRENAD Hit pawn side, std bounce");
    00150	    }
    00151	    if ( (Other != instigator) || bCanHitOwner )
    00152	    {
    00153	      Velocity = 0.2*Velocity;
    00154	      vt = HitLocation - Other.Location;
    00155	      HitWall( normal(vt), None );
    00156	    }
    00157	}
    00158
    00159	//_____________________________________________________________________________
    00160	simulated function HitWall( vector HitNormal, actor Wall )
    00161	{
    00162	    Local vector vt;
    00163
    00164	    MakeNoise(ImpactNoise);
    00165	    if ( MyTrail != none )
    00166	      MyTrail.RotationSpeed *= 2.0;
    00167	//    Log("GRENAD HitWall"@Wall);
    00168
    00169	    if ( (Wall != none) && (Pawn(Wall) != none) )
    00170	    {
    00171	      vT = Location - Wall.Location;
    00172	      if ( VT.Z > Wall.CollisionRadius * 0.9 )
    00173	      {
    00174	//        Log("GRENAD should bounce off pawn"@Wall@"head");
    00175	        vt = Location - Wall.Location;
    00176	        vT.Z = 0;
    00177	        Velocity = 0.3*Speed*(normal(vT) + vect(0,0,1));
    00178	//        Velocity = normal(vT)*vSize(Velocity);
    00179	        Speed = vSize(Velocity);
    00180	//        HitWall( normal(normal(vt) + vect(0,0,1)), Other );
    00181	        return;
    00182	      }
    00183	//      else
    00184	//        Log("GRENAD Hit pawn side, std bounce");
    00185	    }
    00186
    00187	    if (Wall != none)
    00188	    {
    00189	      PlayImpactSound(-normal(velocity), Wall);
    00190	      if ( (Level.NetMode == NM_StandAlone) && level.bLonePlayer && !bRecordedByGenAlerte ) //grenad launched by a basesoldier
    00191	      {
    00192	        XIIIGameInfo(level.game).genalerte.trigger(self, instigator);
    00193	        bRecordedByGenAlerte = true;
    00194	      }
    00195	    }
    00196	    bCanHitOwner = True;
    00197	    Velocity = 0.25*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);   // Reflect off Wall w/damping
    00198	    speed = VSize(Velocity);
    00199	    if ( Velocity.Z > 400 )
    00200	      Velocity.Z = 0.5 * (400 + Velocity.Z);
    00201	    else if ( (speed < 10) && (Wall != none) ) // don't stop of touching and not hitting real wall.
    00202	    {
    00203	      bBounce = False;
    00204	      SetPhysics(PHYS_None);
    00205	    }
    00206
    00207	    if (!bExploded && abs(HitNormal dot Vect(0,0,1))<0.5)
    00208	    {
    00209	      vLastWallHit = location + 0.25*HitNormal*200.0/2.54;
    00210	      bLastWallHit = true;
    00211	    }
    00212	//    Log("      NEW Velocity="$Velocity);
    00213	}
    00214
    00215	//_____________________________________________________________________________
    00216	function PreExplode()
    00217	{
    00218	  //SOUTHEND
    00219	  // Added this code to generate a CWndExplosion when a grenade thrown by a
    00220	  // human player explodes and he cannot see it.
    00221	  local CWndExplosion CWnd;
    00222	  local vector aim;
    00223	  if (instigator != none && XIIIPlayerController(instigator.Controller) != none
    00224	   && XIIIPlayerController(instigator.Controller).multiViewport==none
    00225	   && XIIIPlayerController(instigator.Controller).fCamViewPercent==0.0)
    00226	  {
    00227	    aim = XIIIPlayerController(instigator.controller).OldAdjustAim;
    00228	    if ((aim dot normal(location-instigator.location) < 0.707) || !instigator.controller.LineOfSightTo(self))
    00229	    {
    00230	      CWnd = Spawn(class'XIII.CWndExplosion',self);
    00231	      if ( CWnd != none )
    00232	      {
    00233	        CWnd.Explosion = self;
    00234	        if (bLastWallHit && VSize(vLastWallHit-location)>1.5*200.0/2.54)
    00235	        {
    00236	          CWnd.CamPos = vLastWallHit + normal(location-vLastWallHit)*0.5*200.0/2.54;
    00237	        }
    00238	        else
    00239	        {
    00240	          CWnd.CamPos = OrgFrom + vect(0,0,30);
    00241	        }
    00242	        CWnd.MyHudForFX = XIIIBaseHUD(XIIIPlayerController(Pawn(Owner).Controller).MyHud);
    00243	        CWnd.Timer();
    00244	      }
    00245
} 00246 } 00247 } 00248 00249 //_____________________________________________________________________________ 00250 simulated function Explosion(vector HitLocation) 00251 { 00252 bExploded = true; 00253 00254 //FRD appel GenAlerte pour gestion grenade 00255 if (level.bLonePlayer) XIIIGameInfo(level.game).genalerte.untrigger(self,instigator); 00256 00257 BlowUp(HitLocation); 00258 if ( Level.NetMode != NM_DedicatedServer ) 00259 { 00260 spawn(ExplosionEmitterClass,,,Location + vect(0,0,1)*50,rotator(vect(0,0,1))); 00261 if ( PhysicsVolume.bWaterVolume ) 00262 { 00263 SpawnWaterExplo(HitLocation); 00264 } 00265 } 00266 } 00267 00268 00269 00270 defaultproperties 00271 { 00272 fLifeTime=-5.000000 00273 bSpawnDecal=False 00274 HitSoundType=4 00275 MyTrailClass=Class'XIII.GrenadTrail' 00276 StaticMeshName="MeshArmesPickup.Grenade_explo" 00277 ShakeMag=900.000000 00278 shaketime=7.000000 00279 ShakeVert=(X=5.000000,Y=10.000000,Z=-25.000000) 00280 ShakeSpeed=(X=300.000000,Y=300.000000,Z=300.000000) 00281 ShakeCycles=2.000000 00282 ExplosionEmitterClass=Class'XIII.GrenadExplosionEmitter' 00283 Speed=800.000000 00284 MaxSpeed=1000.000000 00285 Damage=350.000000 00286 DamageRadius=1200.000000 00287 MomentumTransfer=80000.000000 00288 MyDamageType=Class'XIII.DTGrenaded' 00289 ExplosionDecal=Class'XIII.GrenadBlast' 00290 bBlockActors=True 00291 bBounce=True 00292 bFixedRotationDir=True 00293 Physics=PHYS_Falling 00294 DrawType=DT_StaticMesh 00295 LifeSpan=7.000000 00296 SaturationDistance=600.000000 00297 StabilisationDistance=3500.000000 00298 StabilisationVolume=-10.000000 00299 }

End Source Code