XIIIMP
Class MPBomb

source: C:\XIII\XIIIMP\Classes\MPBomb.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Inventory
         |
         +--Engine.Weapon
            |
            +--XIII.XIIIWeapon
               |
               +--XIIIMP.MPBomb
Direct Known Subclasses:None

class MPBomb
extends XIII.XIIIWeapon

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 MPBombingBase ActiveBombBase
           To allow respawn of bomb once used
 XIIIMPBombPick PickupSource
           To allow respawn of bomb once used
 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
 sndBomdDesactived, sndBomdClick
           To allow respawn of bomb once used

States
for, PendingFire, NormalFire

Function Summary
 
simulated
Fire(float value)
     
//_____________________________________________________________________________
 bool HandlePickupQuery(Pickup Item)
     
//_____________________________________________________________________________
 void ServerBombFire()
     
//_____________________________________________________________________________
 void ServerBombUnFire(float value)
     
//_____________________________________________________________________________
 void ServerResetPickupSource()
     
//_____________________________________________________________________________
 void ServerRespawnPickupSource()
     
//    LifeSpan = 5.0;
//    destroy();
}
*/
 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


State PendingFire Function Summary


State NormalFire Function Summary
 void Timer()



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class MPBomb 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	
00010	const DBGren=false;
00011	const ACTIVATEDELAY=12.0;  // amount of time needed to prepare bomb & drop it
00012	CONST BLOWDELAY=4.0;      // delay once prepared before blowing
00013	
00014	var XIIIMPBombPick PickupSource;  // To allow respawn of bomb once used
00015	var MPBombingBase ActiveBombBase;
00016	var sound sndBombIsActived, sndBomdDesactived, sndBomdClick;
00017	
00018	//_____________________________________________________________________________
00019	replication
00020	{
00021	    Reliable if( Role<ROLE_Authority )
00022	      ServerSetProjectileLifeTime, /*ServerResetPickupSource, */ServerBombFire, ServerBombUnFire;
00023	}
00024	
00025	/*
00026	//_____________________________________________________________________________
00027	function ServerResetPickupSource()
00028	{
00029	    // A Bomb should be made to respawn there
00030	    //log( "BOMBING-]"@self@"ServerResetPickupSource "@PickupSource);
00031	    PickupSource.GotoState('DelayBeforePickable');
00032	//    LifeSpan = 5.0;
00033	//    destroy();
00034	}
00035	*/
00036	
00037	function ServerRespawnPickupSource() //Respawn BOMB if owner is disconnected
00038	{
00039	    // A Bomb should be made to respawn there
00040	    //log( "BOMBING-]"@self@"ServerRespawnPickupSource "@PickupSource);
00041	//    log("--- Pickup ServerRespawnPickupSource ---");
00042	    PickupSource.GotoState('Pickup');
00043	}
00044	
00045	//_____________________________________________________________________________
00046	event Destroyed()      //if owner disconnected
00047	{
00048		ServerBombUnFire(0);
00049		ServerRespawnPickupSource();
00050		Super.Destroyed();
00051	}
00052	
00053	//_____________________________________________________________________________
00054	function bool HandlePickupQuery( Pickup Item )
00055	{
00056	    local int OldAmmo, NewAmmo;
00057	    local Pawn P;
00058	
00059	//    Log("HandlePickupQuery"@Item@"for"@self);
00060	
00061	    if (Item.InventoryType == Class)
00062	    {
00063	      if ( WeaponPickup(item).bWeaponStay && ((item.inventory == None) || item.inventory.bTossedOut) )
00064	        return true;
00065	      P = Pawn(Owner);
00066	      if ( AmmoType != None )
00067	      {
00068	        OldAmmo = AmmoType.AmmoAmount;
00069	        if ( Item.Inventory != None )
00070	          NewAmmo = Weapon(Item.Inventory).PickupAmmoCount;
00071	        else
00072	          NewAmmo = class<Weapon>(Item.InventoryType).Default.PickupAmmoCount;
00073	        if ( AmmoType.AddAmmo(NewAmmo) && (OldAmmo == 0)
00074	          && (P.Weapon.class != item.InventoryType) )
00075	          ClientWeaponSet(true);
00076	      }
00077	      Item.AnnouncePickup(Pawn(Owner));
00078	      return true;
00079	    }
00080	    if ( Inventory == None )
00081	      return false;
00082	
00083	    return Inventory.HandlePickupQuery(Item);
00084	}
00085	
00086	//_____________________________________________________________________________
00087	function ServerBombUnFire( float value )
00088	{
00089	//    Log("ServerBomb-Un-Fire");
00090	    if( ActiveBombBase != none )
00091	    {
00092	      ActiveBombBase.BombTime = -1;
00093	      Owner.PlayMenu(sndBomdClick);
00094	    }
00095	}
00096	
00097	//_____________________________________________________________________________
00098	function ServerBombFire()
00099	{
00100	    local int TouchingBombBase;
00101	
00102	//    Log("ServerBomb-Fire");
00103	    foreach Pawn(Owner).TouchingActors(class'MPBombingBase', ActiveBombBase)
00104	    {
00105	      ActiveBombBase.BombTime = Level.TimeSeconds;
00106	      ActiveBombBase.BombingCount ++;
00107	      break;
00108	    }
00109	}
00110	
00111	//_____________________________________________________________________________
00112	simulated function Fire(float value)
00113	{
00114	    local int TouchingBombBase;
00115	    local SabotageBotController Bot;
00116	
00117	      foreach Pawn(Owner).TouchingActors(class'MPBombingBase', ActiveBombBase)
00118	      {
00119	        TouchingBombBase++;
00120	        break;
00121	      }
00122	      if( TouchingBombBase == 0 )
00123	        return;
00124	
00125	      if( ActiveBombBase.CurrentTeam == 0 )
00126	        return;
00127	
00128	
00129	    if( Level.NetMode == NM_Standalone )
00130	    {
00131	      ActiveBombBase.BombTime = Level.TimeSeconds;
00132	    }
00133	    else
00134	      ServerBombFire();
00135	
00136	    Owner.PlayMenu(sndBomdClick);
00137	
00138	    if( Level.NetMode == NM_Standalone )
00139	    {
00140	      foreach DynamicActors(class'SabotageBotController', BOT)
00141	      {
00142	        BOT.BombIsActivated(ActiveBombBase);
00143	      }
00144	    }
00145	
00146	    if ( DBGren ) Log(">>> Fire call for "$self$" in state "$GetStateName());
00147	    bUnFired = false;
00148	    bPendingEnded = false;
00149	    ProjectileLifeTime = Level.TimeSeconds + ACTIVATEDELAY;
00150	    if ( DBGren ) Log("  > Calling ServerSetProjectileLifeTime from Fire");
00151	    ServerSetProjectileLifeTime();
00152	    SetTimer(ACTIVATEDELAY, false);
00153	    GotoState('PendingFire');
00154	}
00155	
00156	//_____________________________________________________________________________
00157	// Replicate to server because projectiles spawned need their life time
00158	function ServerSetProjectileLifeTime()
00159	{
00160	    if ( DBGren ) Log(">>> ServerSetProjectileLifeTime call");
00161	    ProjectileLifeTime = Level.TimeSeconds + ACTIVATEDELAY;
00162	}
00163	
00164	//_____________________________________________________________________________
00165	simulated function UnFire( float value )
00166	{
00167	    if ( DBGren ) Log(">>> Global UnFire call for "$self$" in state "$GetStateName());
00168	    bUnFired = true;
00169	}
00170	
00171	//_____________________________________________________________________________
00172	// Server
00173	state NormalFire
00174	{
00175	    function Timer()
00176	    {
00177	      local Vector Start, X,Y,Z;
00178	
00179	      if ( !AmmoType.bInstantHit )
00180	      {
00181	        MakeNoise(FireNoise);
00182	        GetAxes(Instigator.GetViewRotation(),X,Y,Z);
00183	        Start = GetFireStart(X,Y,Z);
00184	        AdjustedAim = Instigator.AdjustAim(AmmoType, Start, 0);
00185	//        if ( (Default.ReloadCount != 0) && (ReLoadCount > 0) || ((Default.ReloadCount == 0) && HasAmmo()) )
00186	          FeedBack();
00187	        AmmoType.SpawnProjectile(Start,AdjustedAim);
00188	        LifeSpan = 1.0;
00189	//        Destroy();
00190	      }
00191	      else
00192	      {
00193	        RealTraceFire(fVarAccuracy,0,0);
00194	      }
00195	    }
00196	}
00197	//_____________________________________________________________________________
00198	state PendingFire
00199	{
00200	    simulated event BeginState()
00201	    {
00202	      if ( DBGren )
00203	        Log(">>> ClientPendingFire BeginState for "$self$" in state "$GetStateName());
00204	      PlayBeginArming();
00205	      SetTimer2( 0.5, true );
00206	    }
00207	
00208	    simulated event Timer2()
00209	    {
00210	      local int TouchingBombBase;
00211	      local SabotageBotController Bot;
00212	      local MPBombingBase TmpBombBase;
00213	
00214	      if ( bChangeWeapon )
00215	      {
00216	        UnFire(0);
00217	        GotoState('DownWeapon');
00218	        return;
00219	      }
00220	
00221	      foreach Pawn(Owner).TouchingActors(class'MPBombingBase', TmpBombBase)
00222	      {
00223	        TouchingBombBase++;
00224	        break;
00225	      }
00226	
00227	      if( TouchingBombBase == 0 )
00228	      {
00229	        SetTimer2( 0.0, false );
00230	        UnFire( 0 );
00231	      }
00232	    }
00233	
00234	    simulated function Fire(float F) {}
00235	    simulated function AltFire(float F) {}
00236	    simulated function UnFire( float value )
00237	    {
00238	      if ( DBGren )
00239	        Log(">>> ClientPendingFire UnFire for "$self$" in state "$GetStateName());
00240	
00241	      if( Level.NetMode == NM_Standalone )
00242	      {
00243	        if ( (value>0) || (ProjectileLifeTime - Level.TimeSeconds <= 0.0) )
00244	        { // the bomb is armed, drop it
00245	          ProjectileLifeTime = Level.TimeSeconds + BLOWDELAY;
00246	          if ( DBGren ) Log("  > Calling ServerSetProjectileLifeTime from UnFire");
00247	          ServerSetProjectileLifeTime();
00248	          Instigator.controller.bFire = 1;
00249	          Super(XIIIWeapon).Fire(0);
00250	          Instigator.controller.bFire = 0;
00251	//          ServerResetPickupSource();
00252	        }
00253	        else
00254	        { // bomb not armed, return to wait state
00255	          if( ActiveBombBase != none )
00256	          {
00257	            ActiveBombBase.BombTime = -1;
00258	            Owner.PlayMenu(sndBomdClick);
00259	          }
00260	          GotoState('Idle');
00261	        }
00262	      }
00263	      else
00264	      {
00265	        if ( (value>0) || (ProjectileLifeTime - Level.TimeSeconds <= 0.0) )
00266	        { // the bomb is armed, drop it
00267	          ProjectileLifeTime = Level.TimeSeconds + BLOWDELAY;
00268	          if ( DBGren ) Log("  > Calling ServerSetProjectileLifeTime from UnFire");
00269	          ServerSetProjectileLifeTime();
00270	          Instigator.controller.bFire = 1;
00271	          Super(XIIIWeapon).Fire(0);
00272	          Instigator.controller.bFire = 0;
00273	//          ServerResetPickupSource();
00274	        }
00275	        else
00276	        { // bomb not armed, return to wait state
00277	          Owner.PlayMenu(sndBomdClick);
00278	          ServerBombUnFire(value);
00279	
00280	          GotoState('Idle');
00281	        }
00282	      }
00283	    }
00284	    //_____________________________________________________________________________
00285	    // ELR Text to be displayed in HUD
00286	    simulated function string GetAmmoText(out int bDrawbulletIcon)
00287	    {
00288	      local string AmmoText,AltAmmoText;
00289	      local int iSec, iMillisec;
00290	      local string sT;
00291	
00292	      iSec = ProjectileLifeTime - Level.TimeSeconds;
00293	      iMilliSec = (ProjectileLifeTime*10.0 - Level.TimeSeconds*10.0 - iSec*10.0);
00294	      sT = iSec$":"$iMilliSec$"0";
00295	
00296	      bDrawbulletIcon = 1;
00297	
00298	      AmmoText = "["$sT$"]"@string(Ammotype.AmmoAmount);
00299	      return AmmoText;
00300	    }
00301	    Simulated Event Timer()
00302	    { // Force player to throw gren & make himself blow up
00303	      UnFire(1.0);
00304	    }
00305	}
00306	
00307	//_____________________________________________________________________________
00308	simulated function PlayIdleAnim()
00309	{
00310	    PlayAnim('Wait', 1.0, 0.3);
00311	}
00312	
00313	//_____________________________________________________________________________
00314	simulated function TweenDown()
00315	{
00316	    if ( HasAmmo() )
00317	      PlayAnim('Down', 1.0);
00318	    else
00319	      AnimEnd(0);
00320	}
00321	
00322	//_____________________________________________________________________________
00323	simulated function PlayBeginArming()
00324	{
00325	    PlayAnim('Wait', 1.0);
00326	    PlayPendingFiringSound();
00327	}
00328	
00329	//_____________________________________________________________________________
00330	simulated function PlayPendingFiringSound()
00331	{
00332	    if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
00333	    {
00334	      if ( bEmptyShot )
00335	        Instigator.PlayRolloffSound(hNoAmmoSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 3 );
00336	      else
00337	      {
00338	        if ( HasSilencer() )
00339	          Instigator.PlayRolloffSound(hFireSound, self, 1, int(Pawn(Owner).IsPlayerPawn()), 3 );
00340	        else
00341	          Instigator.PlayRolloffSound(hFireSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 3 );
00342	      }
00343	    }
00344	}
00345	
00346	
00347	
00348	defaultproperties
00349	{
00350	     sndBombIsActived=Sound'XIIIsound.Multi__SFXMulti.SFXMulti__hBomBing'
00351	     sndBomdDesactived=Sound'XIIIsound.Multi__SFXMulti.SFXMulti__hBombOut'
00352	     sndBomdClick=Sound'XIIIsound.Multi__SFXMulti.SFXMulti__hBombClick'
00353	     bAllowEmptyShot=False
00354	     WHand=WHA_2HShot
00355	     WeaponMode=WM_SemiAuto
00356	     AmmoName=Class'XIIIMP.MPBombAmmo'
00357	     PickupAmmoCount=1
00358	     MeshName="XIIIArmes.fpsBombeMagnetM"
00359	     FireOffset=(Y=5.000000,Z=-2.000000)
00360	     CrossHair=Texture'XIIIMenu.HUD.MireCouteau'
00361	     ShotTime=2.000000
00362	     FiringMode="FM_Throw"
00363	     FireNoise=0.000000
00364	     AIRating=-2.000000
00365	     TraceDist=0.000000
00366	     hFireSound=Sound'XIIIsound.Guns__GrenFire.GrenFire__hGrenFire'
00367	     hSelectWeaponSound=Sound'XIIIsound.Guns__GrenSelWp.GrenSelWp__hGrenSelWp'
00368	     InventoryGroup=24
00369	     PickupClassName="XIIIMP.XIIIMPBombPick"
00370	     PlayerViewOffset=(X=5.000000,Y=4.000000,Z=-4.200000)
00371	     ThirdPersonRelativeLocation=(X=7.000000,Y=-5.000000,Z=2.000000)
00372	     ThirdPersonRelativeRotation=(Yaw=16384)
00373	     AttachmentClass=Class'XIIIMP.MPBombAttach'
00374	     Icon=Texture'XIIIMenu.HUD.BombemagnetIcon'
00375	     ItemName="BOMB"
00376	     DrawScale=0.300000
00377	}

End Source Code