XIIIMP
Class FlashBangFlying

source: C:\XIII\XIIIMP\Classes\FlashBangFlying.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Projectile
         |
         +--XIII.XIIIProjectile
            |
            +--XIIIMP.FlashBangFlying
Direct Known Subclasses:None

class FlashBangFlying
extends XIII.XIIIProjectile

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 array FlashController
           duration before explosion
 int NumExtraGrenades
 Count, SmokeRate
 bool bArmed
 bool bCleanFlash
 bCanHitOwner, bHitWater
 float fLifeTime
           duration before explosion


Function Summary
 
simulated
BeginPlay()
     
//_____________________________________________________________________________
 
simulated
Explosion(vector HitLocation)
     
//_____________________________________________________________________________
 void Flash(vector Loc)
     
//_____________________________________________________________________________
 
simulated
HitWall(vector HitNormal, Actor Wall)
     
//_____________________________________________________________________________
 
simulated
Landed(vector HitNormal)
     
//_____________________________________________________________________________
 
simulated
PostBeginPlay()
     
//_____________________________________________________________________________
// Set up speed
 
simulated
ProcessTouch(Actor Other, vector HitLocation)
     
//_____________________________________________________________________________
 
simulated
Timer()
     
//_____________________________________________________________________________
 void UnFlash()
     
//_____________________________________________________________________________



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class FlashBangFlying extends XIIIProjectile;
00005	
00006	var bool bCanHitOwner, bHitWater;
00007	var bool bArmed;
00008	var bool bCleanFlash;
00009	
00010	var float Count, SmokeRate;
00011	var int NumExtraGrenades;
00012	var float fLifeTime;                // duration before explosion
00013	var array<Controller> FlashController;
00014	
00015	replication
00016	{
00017	    Reliable if ( Role == ROLE_Authority )
00018	      fLifeTime;
00019	}
00020	
00021	//_____________________________________________________________________________
00022	// Set up speed
00023	simulated function PostBeginPlay()
00024	{
00025	    local vector X,Y,Z;
00026	    local rotator RandRot;
00027	
00028	    Super.PostBeginPlay();
00029	    bArmed=false;
00030	    fLifeTime = 5.0;        // Set this just in case it will be thrown by no player thus intialized after postbeginplay
00031	    SetTimer(0.1,false);    // Call it again later with the right intialized lifetime
00032	
00033	    if ( Role == ROLE_Authority )
00034	    {
00035	      GetAxes(Instigator.GetViewRotation(),X,Y,Z);
00036	      Velocity = X * (Instigator.Velocity Dot X)*0.4 + Vector(Rotation) * (Speed + FRand() * 100);
00037	      Velocity.z += 210;
00038	      MaxSpeed = 1000;
00039	      RandSpin(50000);
00040	      bCanHitOwner = False;
00041	      if (Instigator.HeadVolume.bWaterVolume)
00042	      {
00043	        bHitWater = True;
00044	        Disable('Tick');
00045	        Velocity=0.6*Velocity;
00046	      }
00047	    }
00048	    //FRD   appel GenAlerte pour gestion grenade
00049	    // ELR No use for FlashBangs as multi only
00050	//    if (level.bLonePlayer) XIIIGameInfo(level.game).genalerte.trigger(self, instigator);
00051	
00052	    MyTrail = Spawn(MyTrailClass,self,,Location);
00053	    MyTrail.Init();
00054	}
00055	
00056	//_____________________________________________________________________________
00057	simulated function BeginPlay()
00058	{
00059	    SmokeRate = 0.15;
00060	}
00061	
00062	//_____________________________________________________________________________
00063	simulated function Timer()
00064	{
00065	//    Log("GRENAD"@self@"Timer");
00066	
00067	    if ( !bArmed )
00068	    { // set the timer back one the fLifeTime has been initialized by the weapon
00069	      bArmed=true;
00070	      fLifeTime = fMax(0.05, fLifeTime);
00071	      SetTimer(fLifeTime, false);
00072	      return;
00073	    }
00074	
00075	    if ( bSpawnDecal )
00076	    {
00077	      if ( bCleanFlash )
00078	      {
00079	        UnFlash();
00080	        Destroy();
00081	      }
00082	      else
00083	      {
00084	        if ( (ExplosionDecal != None) && (Level.NetMode != NM_DedicatedServer) )
00085	          Spawn(ExplosionDecal,self,,Location, rotator(vect(0,0,-1)));
00086	        bCleanFlash = true;
00087	        SetTimer(4.8, false);
00088	      }
00089	    }
00090	    else
00091	    {
00092	      Explosion(Location+Vect(0,0,1)*16);
00093	      bSpawnDecal = true;
00094	      SetTimer(0.2, false);
00095	    }
00096	}
00097	
00098	//_____________________________________________________________________________
00099	simulated function Landed( vector HitNormal )
00100	{
00101	//    Log("GRENAD"@self@"Landed");
00102	    HitWall( HitNormal, Base );
00103	}
00104	
00105	//_____________________________________________________________________________
00106	simulated function ProcessTouch( actor Other, vector HitLocation )
00107	{
00108	    Local vector vt;
00109	
00110	    if ( Pawn(Other) != none )
00111	    {
00112	      vT = Location - Other.Location;
00113	      if ( VT.Z > Other.CollisionRadius * 0.9 )
00114	      {
00115	//        Log("GRENAD should bounce off pawn"@other@"head");
00116	        vt = HitLocation - Other.Location;
00117	        vT.Z = 0;
00118	        Velocity = 0.3*Speed*(normal(vT) + vect(0,0,1));
00119	//        Velocity = normal(vT)*vSize(Velocity);
00120	        Speed = vSize(Velocity);
00121	//        HitWall( normal(normal(vt) + vect(0,0,1)), Other );
00122	        return;
00123	      }
00124	//      else
00125	//        Log("GRENAD Hit pawn side, std bounce");
00126	    }
00127	    if ( (Other!=instigator) || bCanHitOwner )
00128	    {
00129	      Velocity = 0.2*Velocity;
00130	      vt = HitLocation - Other.Location;
00131	      HitWall( normal(vt), None );
00132	    }
00133	}
00134	
00135	//_____________________________________________________________________________
00136	simulated function HitWall( vector HitNormal, actor Wall )
00137	{
00138	//    Log("GRENAD"@self@"HitWall"@Wall@"HitNormal="@HitNormal);
00139	    Local vector vt;
00140	
00141	    MakeNoise(ImpactNoise);
00142	    MyTrail.RotationSpeed *= 2.0;
00143	
00144	    if ( Pawn(Wall) != none )
00145	    {
00146	      vT = Location - Wall.Location;
00147	      if ( VT.Z > Wall.CollisionRadius * 0.9 )
00148	      {
00149	//        Log("GRENAD should bounce off pawn"@Wall@"head");
00150	        vt = Location - Wall.Location;
00151	        vT.Z = 0;
00152	        Velocity = 0.3*Speed*(normal(vT) + vect(0,0,1));
00153	//        Velocity = normal(vT)*vSize(Velocity);
00154	        Speed = vSize(Velocity);
00155	//        HitWall( normal(normal(vt) + vect(0,0,1)), Other );
00156	        return;
00157	      }
00158	//      else
00159	//        Log("GRENAD Hit pawn side, std bounce");
00160	    }
00161	
00162	    if (Wall != none)
00163	      PlayImpactSound(-normal(velocity), Wall);
00164	
00165	    bCanHitOwner = True;
00166	    Velocity = 0.25*(( Velocity dot HitNormal ) * HitNormal * (-2.0) + Velocity);   // Reflect off Wall w/damping
00167	    speed = VSize(Velocity);
00168	    if ( Velocity.Z > 400 )
00169	      Velocity.Z = 0.5 * (400 + Velocity.Z);
00170	    else if ( (speed < 10) && (Wall != none) ) // don't stop of touching and not hitting real wall.
00171	    {
00172	      bBounce = False;
00173	      SetPhysics(PHYS_None);
00174	    }
00175	}
00176	
00177	//_____________________________________________________________________________
00178	simulated function Explosion(vector HitLocation)
00179	{
00180	//    Log("GRENAD"@self@"Explosion");
00181	    //FRD   appel GenAlerte pour gestion grenade
00182	    // ELR No use for FlashBangs as multi only
00183	//    if (level.bLonePlayer) XIIIGameInfo(level.game).genalerte.untrigger(self,instigator);
00184	
00185	//    BlowUp(HitLocation);
00186	// FlashBangs don't blow up but set flashes on controllers.
00187	    Flash(Location);
00188	    SetDrawType(DT_None);
00189	    SetPhysics(PHYS_none);
00190	    Velocity = vect(0,0,0);
00191	    if ( Level.NetMode != NM_DedicatedServer )
00192	    {
00193	      spawn(ExplosionEmitterClass,,,Location + vect(0,0,1)*50,rotator(vect(0,0,1)));
00194	    }
00195	    PlaySound(hExploSound,0,1,2);
00196	}
00197	
00198	//_____________________________________________________________________________
00199	function Flash(vector Loc)
00200	{
00201	    local Controller C;
00202	    local actor A;
00203	    local vector hitLoc, HitNorm;
00204	    local material HitMat;
00205	
00206	    Log("FLASH");
00207	    for (C=Level.ControllerList; C!=none; C=C.NextController)
00208	    {
00209	      if ( (PlayerController(C) != none) )
00210	      {
00211	        Log("  test on flashing "$C);
00212	        if ( FastTrace(Location, C.Pawn.Location + C.Pawn.EyePosition()) )
00213	        {
00214	//          Log("FlashBang angle="$vector(C.Rotation) dot normal(Location - C.Pawn.Location + C.Pawn.EyePosition()));
00215	          if ( vector(C.Rotation) dot normal(Location - C.Pawn.Location - C.Pawn.EyePosition()) > 0.68 )
00216	          {
00217	            Log("   Flashing "$C);
00218	            FlashController[FlashController.Length] = C; // Add C to UnFlash list, optimize the unflash process
00219	            PlayerController(C).ClientFilter(
00220	              class'Canvas'.Static.MakeColor(255,255,255,255),
00221	              class'Canvas'.Static.MakeColor(255,255,255,255),
00222	              0.5
00223	              );
00224	            PlayerController(C).ClientHighLight( class'Canvas'.Static.MakeColor(255,255,255,75), 0.75);
00225	            XIIIPlayerController(C).ClientTargetHighLight( 75, 0.0, 16.0);
00226	          }
00227	        }
00228	        else
00229	        { // long trace because CanSeeThrough
00230	          A = Trace(HitLoc, HitNorm, Location, C.Pawn.Location + C.Pawn.EyePosition(), true, vect(0,0,0), HitMat, TRACETYPE_DiscardIfCanSeeThrough);
00231	          if ( A == none )
00232	          {
00233	            if ( vector(C.Rotation) dot normal(Location - C.Pawn.Location - C.Pawn.EyePosition()) > 0.68 )
00234	            {
00235	              Log("   Flashing "$C);
00236	              FlashController[FlashController.Length] = C; // Add C to UnFlash list, optimize the unflash process
00237	              PlayerController(C).ClientFilter(
00238	                class'Canvas'.Static.MakeColor(255,255,255,255),
00239	                class'Canvas'.Static.MakeColor(255,255,255,255),
00240	                0.5
00241	                );
00242	                PlayerController(C).ClientHighLight( class'Canvas'.Static.MakeColor(255,255,255,75), 0.75);
00243	                XIIIPlayerController(C).ClientTargetHighLight( 75, 0.0, 16.0);
00244	            }
00245	          }
00246	        }
00247	      }
00248	      else if( BotController(C) != none  )
00249	      {
00250	        if ( FastTrace(Location, C.Pawn.Location + C.Pawn.EyePosition()) )
00251	        {
00252	          if ( vector(C.Rotation) dot normal(Location - C.Pawn.Location + C.Pawn.EyePosition()) > 0.707 )
00253	          {
00254	            FlashController[FlashController.Length] = C; // Add C to UnFlash list, optimize the unflash process
00255	            BotController(C).Flashed();
00256	          }
00257	        }
00258	      }
00259	    }
00260	}
00261	
00262	//_____________________________________________________________________________
00263	function UnFlash()
00264	{
00265	    local Controller C;
00266	    local int i;
00267	
00268	    Log("UNFLASH");
00269	    for (i=0; i<FlashController.Length; i++)
00270	    {
00271	      C = FlashController[i];
00272	      Log("  unflashing "$C);
00273	      if ( (PlayerController(C) != none) )
00274	      {
00275	        PlayerController(FlashController[i]).ClientFilter(
00276	          class'Canvas'.Static.MakeColor(255,255,255,255),
00277	          class'Canvas'.Static.MakeColor(128,128,128,255),
00278	          0.15
00279	        );
00280	        XIIIPlayerController(C).ClientTargetHighLight( 0, 0, 2.0);
00281	      }
00282	      else if( BotController(C) != none  )
00283	        BotController(C).DamnedImFlashed = False;
00284	    }
00285	}
00286	
00287	
00288	
00289	
00290	defaultproperties
00291	{
00292	     fLifeTime=-5.000000
00293	     bSpawnDecal=False
00294	     HitSoundType=4
00295	     hExploSound=Sound'XIIIsound.Multi.flashbang'
00296	     MyTrailClass=Class'XIIIMP.FlashBangTrail'
00297	     StaticMeshName="MeshArmesPickup.FlashBang"
00298	     ShakeMag=900.000000
00299	     shaketime=7.000000
00300	     ShakeVert=(X=5.000000,Y=10.000000,Z=-25.000000)
00301	     ShakeSpeed=(X=300.000000,Y=300.000000,Z=300.000000)
00302	     ShakeCycles=2.000000
00303	     ExplosionEmitterClass=Class'XIII.GrenadExplosionEmitter'
00304	     Speed=800.000000
00305	     MaxSpeed=1000.000000
00306	     Damage=350.000000
00307	     DamageRadius=1200.000000
00308	     MomentumTransfer=80000.000000
00309	     MyDamageType=Class'XIII.DTGrenaded'
00310	     ExplosionDecal=Class'XIII.GrenadBlast'
00311	     bBlockActors=True
00312	     bBounce=True
00313	     bFixedRotationDir=True
00314	     Physics=PHYS_Falling
00315	     DrawType=DT_StaticMesh
00316	     LifeSpan=15.000000
00317	     SaturationDistance=600.000000
00318	     StabilisationDistance=3500.000000
00319	     StabilisationVolume=-10.000000
00320	}

End Source Code