XIII
Class GrenadB

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

class GrenadB
extends XIII.XIIIWeapon

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 float ProjectileLifeTime
           to make the projectile live less if hold a long time (GD request)
 bool bAltFiring
           to play altfiring anim whule using fire behaviour
 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
NormalFire, for, PendingFire

Function Summary
 
simulated
AltFire(float value)
     
//_____________________________________________________________________________
 void DropFrom(vector StartLocation)
     
//_____________________________________________________________________________
// Toss this weapon out
 
simulated
Fire(float value)
     
//_____________________________________________________________________________
 string GetAmmoText(out int)
     
//_____________________________________________________________________________
// ELR Text to be displayed in HUD
 bool HasAltAmmo()
     
//_____________________________________________________________________________
 float RateSelf()
     
//_____________________________________________________________________________
// FRD
 void ServerSetProjectileLifeTime(bool bAlt)
     
//_____________________________________________________________________________
// Replicate to server because projectiles spawned need their life time
 
simulated
UnFire(float value)
     
//_____________________________________________________________________________


State NormalFire Function Summary
 void Timer()


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 GrenadB 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 bool bAltFiring;            // to play altfiring anim whule using fire behaviour
00009	var float ProjectileLifeTime;   // to make the projectile live less if hold a long time (GD request)
00010	var sound hStopFireSound;       // To stop tic-tac sound if killed before throwing
00011	
00012	CONST DBGren=false;
00013	
00014	//_____________________________________________________________________________
00015	replication
00016	{
00017	    Reliable if( Role<ROLE_Authority )
00018	      ServerSetProjectileLifeTime;
00019	}
00020	
00021	//_____________________________________________________________________________
00022	simulated function bool HasAltAmmo()
00023	{ // because we can stun only if we have ammo (bAllowEmptyShot=false, must down weapon after last fire)
00024	    return HasAmmo();
00025	}
00026	
00027	//_____________________________________________________________________________
00028	// ELR Text to be displayed in HUD
00029	simulated function string GetAmmoText(out int bDrawbulletIcon)
00030	{
00031	    local string AmmoText,AltAmmoText;
00032	
00033	    bDrawbulletIcon = 1;
00034	
00035	    // Setup ammotext
00036	    AmmoText = string(Ammotype.AmmoAmount);
00037	    return AmmoText;
00038	}
00039	
00040	//_____________________________________________________________________________
00041	// FRD
00042	function float RateSelf()
00043	{
00044	    local float distance;
00045	    local vector PositionRelative;
00046	
00047	    if ( !HasAmmo() )
00048	      return -2;
00049	    if (instigator.controller.enemy!=none)
00050	    {
00051	      PositionRelative=instigator.controller.enemy.location-instigator.location;
00052	      distance=Vsize(PositionRelative);
00053	      if (distance>1170)
00054	        return 0.23;
00055	      else if (distance<500)
00056	        return 0.25;
00057	      if (PositionRelative.z>400) // enemy au dessus donc pas prendre
00058	        return (AIRating-2);
00059	     }
00060	     return AIRating;
00061	}
00062	
00063	//_____________________________________________________________________________
00064	simulated function Fire(float value)
00065	{
00066	    if ( DBGren ) Log(">>> Fire call for "$self$" in state "$GetStateName());
00067	
00068	    if ( Pawn(Owner).HeadVolume.bWaterVolume )
00069	      return;
00070	
00071	    bAltFiring = false;
00072	
00073	    bUnFired = false;
00074	    bPendingEnded = false;
00075	    ProjectileLifeTime = Level.TimeSeconds + 5.0;
00076	    if ( DBGren ) Log("  > Calling ServerSetProjectileLifeTime from Fire");
00077	    ServerSetProjectileLifeTime(false);
00078	    SetTimer(5.0, false);
00079	    GotoState('PendingFire');
00080	}
00081	
00082	//_____________________________________________________________________________
00083	simulated function AltFire(float value)
00084	{
00085	    if ( DBGren ) Log(">>> AltFire call for "$self$" in state "$GetStateName());
00086	
00087	    if ( Pawn(Owner).HeadVolume.bWaterVolume )
00088	      return;
00089	
00090	    bAltFiring = true;
00091	
00092	    bUnFired = false;
00093	    bPendingEnded = false;
00094	    ProjectileLifeTime = Level.TimeSeconds + 5.0;
00095	    if ( DBGren ) Log("  > Calling ServerSetProjectileLifeTime from Fire");
00096	    ServerSetProjectileLifeTime(true);
00097	    SetTimer(5.0, false);
00098	    GotoState('PendingFire');
00099	}
00100	
00101	//_____________________________________________________________________________
00102	// Replicate to server because projectiles spawned need their life time
00103	function ServerSetProjectileLifeTime(bool bAlt)
00104	{
00105	    if ( DBGren ) Log(">>> ServerSetProjectileLifeTime call Altfiring="$bAlt);
00106	    ProjectileLifeTime = Level.TimeSeconds + 5.0;
00107	    bAltFiring = bAlt;
00108	}
00109	
00110	//_____________________________________________________________________________
00111	simulated function UnFire( float value )
00112	{
00113	    if ( DBGren ) Log(">>> Global UnFire call for "$self$" in state "$GetStateName());
00114	    bUnFired = true;
00115	}
00116	
00117	//_____________________________________________________________________________
00118	// Toss this weapon out
00119	function DropFrom(vector StartLocation)
00120	{
00121	    /*if ( DBGren )*/ Log(">>> Global DropFrom call for "$self$" in state "$GetStateName()@"hStopFireSound="$hStopFireSound);
00122	    Instigator.PlayRolloffSound(hStopFireSound, self);
00123	//    Instigator.PlayRSound(hStopFireSound); // don't work either
00124	    Super.DropFrom(StartLocation);
00125	}
00126	
00127	//_____________________________________________________________________________
00128	simulated state PendingFire
00129	{
00130	    simulated event BeginState()
00131	    {
00132	      if ( DBGren ) Log(">>> PendingFire BeginState for "$self$" in state "$GetStateName());
00133	      PlayThrowPrep();
00134	    }
00135	    simulated function Fire(float F) {}
00136	    simulated function AltFire(float F) {}
00137	    simulated function UnFire( float value )
00138	    {
00139	      if ( DBGren ) Log(">>> PendingFire UnFire for "$self$" in state "$GetStateName());
00140	      Global.UnFire(value);
00141	      if ( bPendingEnded )
00142	      {
00143	        Instigator.controller.bFire = 1;
00144	        Super(XIIIWeapon).Fire(2.0);
00145	        Instigator.controller.bFire = 0;
00146	        bUnFired = false;
00147	        bPendingEnded = false;
00148	      }
00149	    }
00150	    simulated function bool PutDown()
00151	    {
00152	      UnFire(0);
00153	      if ( Instigator.PendingWeapon != none )
00154	        bChangeWeapon = true;
00155	      return True;
00156	    }
00157	    simulated event AnimEnd(int channel)
00158	    {
00159	      if ( DBGren ) Log(">>> PendingFire AnimEnd for "$self$" in state "$GetStateName());
00160	      bPendingEnded = true;
00161	      if ( bUnFired )
00162	      {
00163	        Instigator.controller.bFire = 1;
00164	        Super(XIIIWeapon).Fire(2.0);
00165	        Instigator.controller.bFire = 0;
00166	        bUnFired = false;
00167	        bPendingEnded = false;
00168	      }
00169	    }
00170	    //_____________________________________________________________________________
00171	    // ELR Text to be displayed in HUD
00172	    simulated function string GetAmmoText(out int bDrawbulletIcon)
00173	    {
00174	      local string AmmoText,AltAmmoText;
00175	      local int iSec, iMillisec;
00176	      local string sT;
00177	
00178	      iSec = ProjectileLifeTime - Level.TimeSeconds;
00179	      iMilliSec = (ProjectileLifeTime*10.0 - Level.TimeSeconds*10.0 - iSec*10.0);
00180	
00181	      if( iSec < 0 ) iSec = 0;
00182	      if( iMilliSec < 0 ) iMilliSec = 0;
00183	
00184	      sT = iSec$":"$iMilliSec$"0";
00185	
00186	      bDrawbulletIcon = 1;
00187	
00188	      AmmoText = "["$sT$"]"@string(Ammotype.AmmoAmount);
00189	      return AmmoText;
00190	    }
00191	/*
00192	    simulated event Tick(float dT)
00193	    {
00194	
00195	      Log("dif="$(ProjectileLifeTime - Level.TimeSeconds)$" >>"$sT);
00196	      XIIIBaseHUD(Playercontroller(Pawn(Owner).Controller).MyHud).AddChronoDisplay(sT, 0.1);
00197	    }
00198	*/
00199	    Simulated Event Timer()
00200	    { // Force player to throw gren & make himself blow up
00201	      if ( DBGren ) Log(">>> PendingFire Timer for "$self$" in state "$GetStateName());
00202	      UnFire(0);
00203	    }
00204	}
00205	
00206	//_____________________________________________________________________________
00207	// specific : Handle projectile direction for bAltFiring = true
00208	state NormalFire
00209	{
00210	    function Timer()
00211	    {
00212	      local Vector Start, X,Y,Z;
00213	
00214	      if ( !AmmoType.bInstantHit )
00215	      {
00216	        MakeNoise(FireNoise);
00217	        GetAxes(Instigator.GetViewRotation(),X,Y,Z);
00218	        Start = GetFireStart(X,Y,Z);
00219	        if ( DBGren ) Log("NormalFire Timer for FGrenad, bAltFiring="$bAltFiring);
00220	        if ( !bAltFiring )
00221	        {
00222	          AdjustedAim = Instigator.AdjustAim(AmmoType, Start, 0);
00223	//        if ( (Default.ReloadCount != 0) && (ReLoadCount > 0) || ((Default.ReloadCount == 0) && HasAmmo()) )
00224	          FeedBack();
00225	          AmmoType.SpawnProjectile(Start,AdjustedAim);
00226	        }
00227	        else
00228	        {
00229	//        if ( (Default.ReloadCount != 0) && (ReLoadCount > 0) || ((Default.ReloadCount == 0) && HasAmmo()) )
00230	          FeedBack();
00231	          AmmoType.SpawnProjectile(Start,rotator(vect(0,0,-1)));
00232	        }
00233	      }
00234	      else
00235	      {
00236	        RealTraceFire(fVarAccuracy,0,0);
00237	      }
00238	    }
00239	}
00240	
00241	//_____________________________________________________________________________
00242	simulated function PlayIdleAnim()
00243	{
00244	    if ( HasAmmo() )
00245	    {
00246	      if ( bHaveBoredSfx && Pawn(Owner).IsPlayerPawn() && (iBoredCount > BOREDSFXTHRESHOLD) )
00247	      {
00248	        iBoredCount = 0;
00249	        if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
00250	          Instigator.PlayRolloffSound(hActWaitSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 0 );
00251	        PlayAnim('WaitAct', 1.0, 0.3);
00252	      }
00253	      else
00254	        PlayAnim('Wait', 1.0, 0.3);
00255	    }
00256	    else
00257	    {
00258	      if ( bHaveBoredSfx && Pawn(Owner).IsPlayerPawn() && (iBoredCount > BOREDSFXTHRESHOLD) )
00259	      {
00260	        iBoredCount = 0;
00261	        if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
00262	          Instigator.PlayRolloffSound(hActWaitSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 0 );
00263	        PlayAnim('WaitActVide', 1.0, 0.3);
00264	      }
00265	      else
00266	        PlayAnim('WaitVide', 1.0, 0.3);
00267	    }
00268	}
00269	
00270	//_____________________________________________________________________________
00271	simulated function TweenDown()
00272	{
00273	    if ( HasAmmo() )
00274	      PlayAnim('Down', 1.0);
00275	    else
00276	      PlayAnim('DownVide', 1.0);
00277	}
00278	
00279	//_____________________________________________________________________________
00280	simulated function PlayThrowPrep()
00281	{
00282	    if ( bAltFiring )
00283	      PlayAnim('PendingFireAlt', 1.0);
00284	    else
00285	      PlayAnim('PendingFire', 1.0);
00286	    PlayPendingFiringSound();
00287	}
00288	
00289	//_____________________________________________________________________________
00290	simulated function PlayFiring()
00291	{
00292	//    if ( HasAmmo() ) // ELR Can't use HasAmmo as the ammo will be used after
00293	    if ( bAltFiring )
00294	    {
00295	      if ( AmmoType.Ammoamount > 1 )
00296	        PlayAnim(LoadedAltFiringAnim, 1.0);
00297	      else
00298	        PlayAnim(EmptyAltFiringAnim, 1.0);
00299	    }
00300	    else
00301	    {
00302	      if ( AmmoType.Ammoamount > 1 )
00303	        PlayAnim(LoadedFiringAnim, 1.0);
00304	      else
00305	        PlayAnim(EmptyFiringAnim, 1.0);
00306	    }
00307	
00308	    if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
00309	      PlayFiringSound();
00310	
00311	    if ( !HasAmmo() )
00312	      return;
00313	
00314	    IncrementFlashCount();
00315	    if ( bDrawMuzzleflash )
00316	      SetUpMuzzleFlash();
00317	}
00318	
00319	//_____________________________________________________________________________
00320	simulated function PlayPendingFiringSound()
00321	{
00322	//    Log("GRENAD PlayPendingFiringSound Instigator="$Instigator);
00323	    if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
00324	    {
00325	      if ( bEmptyShot )
00326	        Instigator.PlayRolloffSound(hNoAmmoSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 3 );
00327	      else
00328	      {
00329	        if ( HasSilencer() )
00330	          Instigator.PlayRolloffSound(hFireSound, self, 1, int(Pawn(Owner).IsPlayerPawn()), 3 );
00331	        else
00332	          Instigator.PlayRolloffSound(hFireSound, self, 0, int(Pawn(Owner).IsPlayerPawn()), 3 );
00333	      }
00334	    }
00335	}
00336	
00337	//_____________________________________________________________________________
00338	simulated function NotifyOwnerKilled(controller Killer)
00339	{
00340	    Super.NotifyOwnerKilled(Killer);
00341	    if ( Level.NetMode == NM_StandAlone )
00342	    {
00343	//      Log("GRENAD NotifyOwnerKilled should drop grenad");
00344	      bAltFiring = true;
00345	      bPendingEnded = true;
00346	      UnFire(2.0);
00347	    }
00348	    else
00349	    {
00350	//      Log("GRENAD NotifyOwnerKilled should stop sound instigator="$instigator);
00351	      if ( Instigator.IsLocallyControlled() || (Level.NetMode == NM_StandAlone) )
00352	        Instigator.PlayRolloffSound(hStopFireSound, self);
00353	      gotoState('');
00354	    }
00355	}
00356	
00357	/*
00358	//_____________________________________________________________________________
00359	simulated function NotifyOwnerKilled(controller Killer)
00360	{
00361	    Log("GRENAD NotifyOwnerKilled should stop sound"$hStopFireSound);
00362	    Instigator.PlayRolloffSound(hStopFireSound, self);
00363	    UnFire(2.0);
00364	}
00365	*/
00366	
00367	
00368	
00369	defaultproperties
00370	{
00371	     hStopFireSound=Sound'XIIIsound.Guns__GrenFire.GrenFire__hGrenStop'
00372	     bHaveAltFire=True
00373	     bAllowEmptyShot=False
00374	     bHaveBoredSfx=True
00375	     WHand=WHA_2HShot
00376	     WeaponMode=WM_SemiAuto
00377	     AmmoName=Class'XIII.GrenadAmmo'
00378	     AltAmmoName=Class'XIII.GrenadAmmo'
00379	     PickupAmmoCount=1
00380	     MeshName="XIIIArmes.FpsGrenade_ExploM"
00381	     FireOffset=(Y=5.000000,Z=-2.000000)
00382	     ShotTime=2.000000
00383	     FiringMode="FM_Throw"
00384	     FireNoise=0.000000
00385	     LoadedAltFiringAnim="FireAlt"
00386	     EmptyAltFiringAnim="FireAltVide"
00387	     AIRating=0.450000
00388	     TraceDist=0.000000
00389	     hFireSound=Sound'XIIIsound.Guns__GrenFire.GrenFire__hGrenFire'
00390	     hSelectWeaponSound=Sound'XIIIsound.Guns__GrenSelWp.GrenSelWp__hGrenSelWp'
00391	     hAltFireSound=Sound'XIIIsound.Guns__GrenFire.GrenFire__hGrenFire'
00392	     hActWaitSound=Sound'XIIIsound.Guns__GrenWait.GrenWait__hGrenWait'
00393	     InventoryGroup=4
00394	     PickupClassName="XIII.GrenadPick"
00395	     NonPlayerTransferClassName="XIII.Grenad"
00396	     PlayerViewOffset=(X=5.000000,Y=4.000000,Z=-4.200000)
00397	     ThirdPersonRelativeLocation=(X=7.000000,Y=-5.000000,Z=2.000000)
00398	     ThirdPersonRelativeRotation=(Yaw=16384)
00399	     AttachmentClass=Class'XIII.GrenadAttach'
00400	     ItemName="GRENADE"
00401	     DrawScale=0.300000
00402	}

End Source Code