## XIIIMP
Class FlashBang

source: C:\XIII\XIIIMP\Classes\flashbang.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Inventory
             |
             +--Engine.Weapon
                |
                +--XIII.XIIIWeapon
                   |
                   +--XIIIMP.FlashBang

Direct Known Subclasses:None

class FlashBang
extends XIII.XIIIWeapon

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

Variables
`float` | `ProjectileLifeTime` to make the projectile live less if hold a long time (GD request)
`bool` | `bPendingEnded` to not thrown before ending the pendingfire anim
`bool` | `bUnFired` to not thrown before ending the pendingfire anim
`sound` | `hStopFireSound` To stop tic-tac sound if killed before throwing

States
for, PendingFire

Function Summary
`simulated` | `Fire(float value)`
    //_____________________________________________________________________________
`float` | `RateSelf()`
    //_____________________________________________________________________________
    // FRD
`void` | `ServerSetProjectileLifeTime()`
    //_____________________________________________________________________________
    // Replicate to server because projectiles spawned need their life time
`simulated` | `UnFire(float value)`
    //_____________________________________________________________________________

State for Function Summary
`string` | `GetAmmoText(out int)`
    // ELR Text to be displayed in HUD
`bool` | `PutDown()`

State PendingFire Function Summary

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class FlashBang extends XIIIWeapon;
    00005
    00006	var bool bPendingEnded;         // to not thrown before ending the pendingfire anim
    00007	var bool bUnFired;              // to not thrown before ending the pendingfire anim
    00008	var float ProjectileLifeTime;   // to make the projectile live less if hold a long time (GD request)
    00009	var sound hStopFireSound;       // To stop tic-tac sound if killed before throwing
    00010
    00011	CONST DBGren=false;
    00012
    00013	//_____________________________________________________________________________
    00014	replication
    00015	{
    00016	    Reliable if( Role<ROLE_Authority )
    00017	      ServerSetProjectileLifeTime;
    00018	}
    00019
    00020	//_____________________________________________________________________________
    00021	// FRD
    00022	function float RateSelf()
    00023	{
    00024	    local float distance;
    00025	    local vector PositionRelative;
    00026
    00027	    if ( !HasAmmo() )
    00028	      return -2;
    00029	    if (instigator.controller.enemy!=none)
    00030	    {
    00031	      PositionRelative=instigator.controller.enemy.location-instigator.location;
    00032	      distance=Vsize(PositionRelative);
    00033	      if (distance>1170)
    00034	        return 0.23;
    00035	      else if (distance<500)
    00036	        return 0.25;
    00037	      if (PositionRelative.z>400) // enemy au dessus donc pas prendre
    00038	        return (AIRating-2);
    00039	     }
    00040	     return AIRating;
    00041	}
    00042
    00043	//_____________________________________________________________________________
    00044	simulated function Fire(float value)
    00045	{
    00046	    if ( DBGren ) Log(">>> Fire call for "$self$" in state "$GetStateName());
    00047	    bUnFired = false;
    00048	    bPendingEnded = false;
    00049	    ProjectileLifeTime = Level.TimeSeconds + 5.0;
    00050	    if ( DBGren ) Log("  > Calling ServerSetProjectileLifeTime from Fire");
    00051	    ServerSetProjectileLifeTime();
    00052	    SetTimer(5.0, false);
    00053	    GotoState('PendingFire');
    00054	}
    00055
    00056	//_____________________________________________________________________________
    00057	// Replicate to server because projectiles spawned need their life time
    00058	function ServerSetProjectileLifeTime()
    00059	{
    00060	    if ( DBGren ) Log(">>> ServerSetProjectileLifeTime call");
    00061	    ProjectileLifeTime = Level.TimeSeconds + 5.0;
    00062	}
    00063
    00064	//_____________________________________________________________________________
    00065	simulated function UnFire( float value )
    00066	{
    00067	    if ( DBGren ) Log(">>> Global UnFire call for "$self$" in state "$GetStateName());
    00068	    bUnFired = true;
    00069	}
    00070
    00071	//_____________________________________________________________________________
    00072	state PendingFire
    00073	{
    00074	    simulated event BeginState()
    00075	    {
    00076	      if ( DBGren ) Log(">>> ClientPendingFire BeginState for "$self$" in state "$GetStateName());
    00077	      PlayThrowPrep();
    00078	    }
    00079	    simulated function Fire(float F) {}
    00080	    simulated function AltFire(float F) {}
    00081	    simulated function UnFire( float value )
    00082	    {
    00083	      if ( DBGren ) Log(">>> ClientPendingFire UnFire for "$self$" in state "$GetStateName());
    00084	      Global.UnFire(value);
    00085	      if ( bPendingEnded )
    00086	      {
    00087	        Instigator.controller.bFire = 1;
    00088	        Super(XIIIWeapon).Fire(0);
    00089	        Instigator.controller.bFire = 0;
    00090	        bUnFired = false;
    00091	        bPendingEnded = false;
    00092	      }
    00093	    }
    00094	    simulated function bool PutDown()
    00095	    {
    00096	      UnFire(0);
    00097	      if ( Instigator.PendingWeapon != none )
    00098	        bChangeWeapon = true;
    00099	      return True;
    00100	    }
    00101	    simulated event AnimEnd(int channel)
    00102	    {
    00103	      if ( DBGren ) Log(">>> ClientPendingFire AnimEnd for "$self$" in state "$GetStateName());
    00104	      bPendingEnded = true;
    00105	      if ( bUnFired )
    00106	      {
    00107	        Instigator.controller.bFire = 1;
    00108	        Super(XIIIWeapon).Fire(0);
    00109	        Instigator.controller.bFire = 0;
    00110	        bUnFired = false;
    00111	        bPendingEnded = false;
    00112	      }
    00113	    }
    00114	    //_____________________________________________________________________________
    00115	    // ELR Text to be displayed in HUD
    00116	    simulated function string GetAmmoText(out int bDrawbulletIcon)
    00117	    {
    00118	      local string AmmoText,AltAmmoText;
    00119	      local int iSec, iMillisec;
    00120	      local string sT;
    00121
    00122	      iSec = ProjectileLifeTime - Level.TimeSeconds;
    00123	      iMilliSec = (ProjectileLifeTime*10.0 - Level.TimeSeconds*10.0 - iSec*10.0);
    00124
    00125	      if( iSec < 0 ) iSec = 0;
    00126	      if( iMilliSec < 0 ) iMilliSec = 0;
    00127
    00128	      sT = iSec$":"$iMilliSec$"0";
    00129
    00130	      bDrawbulletIcon = 1;
    00131
    00132	      AmmoText = "["$sT$"]"@string(Ammotype.AmmoAmount);
    00133	      return AmmoText;
    00134	    }
    00135	/*
    00136	    simulated event Tick(float dT)
    00137	    {
    00138
    00139	      Log("dif="$(ProjectileLifeTime - Level.TimeSeconds)$" >>"$sT);
    00140	      XIIIBaseHUD(Playercontroller(Pawn(Owner).Controller).MyHud).AddChronoDisplay(sT, 0.1);
    00141	    }
    00142	*/
    00143	    Simulated Event Timer()
    00144	    { // Force player to throw gren & make himself blow up
    00145	      UnFire(0);
    00146	    }
    00147	}
    00148
    00149	//_____________________________________________________________________________
    00150	simulated function PlayIdleAnim()
    00151	{
    00152	    if ( HasAmmo() )
    00153	      PlayAnim('Wait', 1.0, 0.3);
    00154	    else
    00155	      PlayAnim('WaitVide', 1.0, 0.3);
    00156	}
    00157
    00158	//_____________________________________________________________________________
    00159	simulated function TweenDown()
    00160	{
    00161	    if ( HasAmmo() )
    00162	      PlayAnim('Down', 1.0);
    00163	    else
    00164	      PlayAnim('DownVide', 1.0);
    00165	}
    00166
    00167	//_____________________________________________________________________________
    00168	simulated function PlayThrowPrep()
    00169	{
    00170	    PlayAnim('PendingFire', 1.0);
    00171	    PlayPendingFiringSound();
    00172	}
    00173
    00174	//_____________________________________________________________________________
    00175	simulated function PlayFiring()
    00176	{
    00177	//    if ( HasAmmo() ) // ELR Can't use HasAmmo as the ammo will be used after
    00178	    if ( AmmoType.Ammoamount > 1 )
    00179	      PlayAnim(LoadedFiringAnim, 1.0);
    00180	    else
    00181	      PlayAnim(EmptyFiringAnim, 1.0);
    00182
    00183	    if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
    00184	      PlayFiringSound();
    00185
    00186	    if ( !HasAmmo() )
    00187	      return;
    00188
    00189	    IncrementFlashCount();
    00190	    if ( bDrawMuzzleflash )
    00191	      SetUpMuzzleFlash();
    00192	}
    00193	//_____________________________________________________________________________
    00194	simulated function PlayPendingFiringSound()
    00195	{
    00196	    if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
    00197	    {
    00198	      if ( bEmptyShot )
    00199	        Instigator.PlayRolloffSound(hNoAmmoSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 3 );
    00200	      else
    00201	      {
    00202	        if ( HasSilencer() )
    00203	          Instigator.PlayRolloffSound(hFireSound, self, 1, int(Pawn(Owner).IsPlayerPawn()), 3 );
    00204	        else
    00205	          Instigator.PlayRolloffSound(hFireSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 3 );
    00206	      }
    00207	    }
    00208	}
    00209
    00210	//_____________________________________________________________________________
    00211	simulated function NotifyOwnerKilled(controller Killer)
    00212	{
    00213	    Super.NotifyOwnerKilled(Killer);
    00214	    if ( Level.NetMode == NM_StandAlone )
    00215	    {
    00216	//      Log("GRENAD NotifyOwnerKilled should drop grenad");
    00217	      bPendingEnded = true;
    00218	      UnFire(2.0);
    00219	    }
    00220	    else
    00221	    {
    00222	//      Log("GRENAD NotifyOwnerKilled should stop sound instigator="$instigator);
    00223	      if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
    00224	        Instigator.PlayRolloffSound(hStopFireSound, self);
    00225	      gotoState('');
    00226	    }
    00227	}
    00228
    00229	//    Icon=texture'XIIIMenu.FlashbIcon'
    00230
    00231
    00232	defaultproperties
    00233	{
    00234	     hStopFireSound=Sound'XIIIsound.Guns__GrenFire.GrenFire__hGrenStop'
    00235	     bAllowEmptyShot=False
    00236	     WHand=WHA_2HShot
    00237	     WeaponMode=WM_SemiAuto
    00238	     AmmoName=Class'XIIIMP.FlashBangAmmo'
    00239
PickupAmmoCount=1 00240 MeshName="XIIIArmes.FpsFlashBangM" 00241 FireOffset=(Y=5.000000,Z=-2.000000) 00242 CrossHair=Texture'XIIIMenu.HUD.MireCouteau' 00243 ShotTime=2.000000 00244 FiringMode="FM_Throw" 00245 FireNoise=0.000000 00246 AIRating=0.450000 00247 TraceDist=0.000000 00248 hFireSound=Sound'XIIIsound.Guns__GrenFire.GrenFire__hGrenFire' 00249 hSelectWeaponSound=Sound'XIIIsound.Guns__GrenSelWp.GrenSelWp__hGrenSelWp' 00250 InventoryGroup=17 00251 PickupClassName="XIIIMP.FlashBangPick" 00252 NonPlayerTransferClass=Class'XIIIMP.FlashBangBot' 00253 PlayerViewOffset=(X=5.000000,Y=4.000000,Z=-4.200000) 00254 ThirdPersonRelativeLocation=(X=7.000000,Y=-5.000000,Z=2.000000) 00255 ThirdPersonRelativeRotation=(Yaw=16384) 00256 AttachmentClass=Class'XIIIMP.FlashBangAttach' 00257 ItemName="FLASHBANG" 00258 DrawScale=0.300000 00259 }

End Source Code