## Engine
Class Ammunition

source: C:\XIII\Engine\Classes\Ammunition.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Inventory
             |
             +--Engine.Ammunition

Direct Known Subclasses:XIIIAmmo

class Ammunition
extends Engine.Inventory

    //=============================================================================
    // Ammunition: the base class of weapon ammunition
    // CHANGENOTE:  All changes to this class since v739 are related to the Weapon code updates.
    //
    // This is a built-in Unreal class and it shouldn't be modified.
    //=============================================================================

Variables
`int` | `AmmoAmount` Current amount of Ammo
`sound` | `HitSoundMem` HitSound
`int` | `HitSoundType` Type of sound vs type of impact
`class` | `ImpactEmitterMem` Visual Impact SFX to run when impacting
`float` | `ImpactNoise` Noise made by the ammo when hitting something
`int` | `MaxAmmo` Maximum ammo holdable
`class` | `MyDamageType` Damage Type
`class` | `ProjectileClass` ProjectileClass to spawn (if not bInstantHit)
`float` | `SoftImpactNoise` Noise made by the ammo when hitting someone
`Texture` | `TBTexture` texture used if bool above true
`int` | `Tracetype` Used to allow Autoaim through objetcs that do have special weapon flags
`float` | `WarnTargetPct` Damage Type
`bool` | `bDisplayNameInHUD` this ammo should have it's name in hud
`bool` | `bDrawTracingBullets` Do we draw the 2D effect for tracing bullets
`bool` | `bHandToHand` hand to hand ammo
`bool` | `bInstantHit` Instant hit ammo (TraceFire)
`bool` | `bPlayHitSound` if we should play sound for the next impact.
`float` | `fFireDelay` Delay before Fire is effective
`float` | `fTraceFrequency` trace frequency if bool above

Function Summary
`bool` | `AddAmmo(int AmmoToAdd)`
    //_____________________________________________________________________________
    // If we can, add ammo and return true.
    // If we are at max ammo, return false
`simulated` | `DisplayDebug(Canvas Canvas, out float, out float)`
    //_____________________________________________________________________________
`void` | `DropFrom(vector StartLocation)`
    //_____________________________________________________________________________
    // Toss this item out.
`void` | `GiveTo(Pawn Other)`
    //_____________________________________________________________________________
    // Give this inventory item to a pawn.
`bool` | `HandlePickupQuery(Pickup Item)`
    //_____________________________________________________________________________
`bool` | `HasAmmo()`
    //_____________________________________________________________________________
`void` | `PlayImpactSound(Sound S)`
    //_____________________________________________________________________________
`void` | `ProcessTraceHit(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)`
    //_____________________________________________________________________________
`void` | `ProcessTraceHitNoAmmo(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)`
    //_____________________________________________________________________________
    // ELR to be defined in subclasses, used for weapon w/ multiple shots w/ only one ammo (ShotGun, Hunting Gun)
`float` | `RateSelf(Pawn Shooter, out name)`
    //_____________________________________________________________________________
`void` | `SetUpImpactEmitter(Sound S)`
    //_____________________________________________________________________________
`void` | `SpawnProjectile(vector Start, rotator Dir)`
    //_____________________________________________________________________________
`void` | `StaticParseDynamicLoading(LevelInfo MyLI)`
    //_____________________________________________________________________________
`void` | `Transfer(Pawn Other)`
    //_____________________________________________________________________________
    // Transfer this inventory to Player (for SearchCorpse)
`void` | `WarnTarget(Actor Target, Pawn P, vector FireDir)`
    //_____________________________________________________________________________

Source Code

    00001	//=============================================================================
    00002	// Ammunition: the base class of weapon ammunition
    00003	// CHANGENOTE:  All changes to this class since v739 are related to the Weapon code updates.
    00004	//
    00005	// This is a built-in Unreal class and it shouldn't be modified.
    00006	//=============================================================================
    00007
    00008	class Ammunition extends Inventory
    00009	    abstract
    00010	    native
    00011	    nativereplication;
    00012
    00013	var bool bInstantHit;               // Instant hit ammo (TraceFire)
    00014	var bool bPlayHitSound;             // if we should play sound for the next impact.
    00015	var bool bDrawTracingBullets;       // Do we draw the 2D effect for tracing bullets
    00016	var bool bDisplayNameInHUD;         // this ammo should have it's name in hud
    00017	var bool bHandToHand;               // hand to hand ammo
    00018	var travel int MaxAmmo;             // Maximum ammo holdable
    00019	var travel int AmmoAmount;          // Current amount of Ammo
    00020
    00021	var class<Projectile> ProjectileClass;    // ProjectileClass to spawn (if not bInstantHit)
    00022	var class<DamageType> MyDamageType;       // Damage Type
    00023	var float WarnTargetPct;
    00024	var float ImpactNoise;              // Noise made by the ammo when hitting something
    00025	var float SoftImpactNoise;          // Noise made by the ammo when hitting someone
    00026	var int Tracetype;                  // Used to allow Autoaim through objetcs that do have special weapon flags
    00027	var int HitSoundType;               // Type of sound vs type of impact
    00028	        // 0 = bullet
    00029	        // 1 = Fists
    00030	        // 2 = CommandoKnife // UNUSED
    00031	        // 3 = Bolt/Harpon
    00032	        // 4 = Grenade bounce
    00033	        // 5 = TKnife
    00034	var sound HitSoundMem;              // HitSound
    00035	var texture TBTexture;              // texture used if bool above true
    00036	var float fTraceFrequency;          // trace frequency if bool above
    00037	var float fFireDelay;               // Delay before Fire is effective
    00038	var class<ImpactEmitter> ImpactEmitterMem;  // Visual Impact SFX to run when impacting
    00039
    00040	//_____________________________________________________________________________
    00041	// Network replication
    00042	replication
    00043	{
    00044	    // Things the server should send to the client.
    00045	    reliable if( bNetOwner && bNetDirty && (Role==ROLE_Authority) )
    00046	      AmmoAmount;
    00047	}
    00048
    00049	//_____________________________________________________________________________
    00050	Static function StaticParseDynamicLoading(LevelInfo MyLI)
    00051	{
    00052	    Log("Ammunition StaticParseDynamicLoading class="$default.class);
    00053	    Super.StaticParseDynamicLoading(MyLI);
    00054	    if ( default.ProjectileClass != none )
    00055	      (default.ProjectileClass).Static.StaticParseDynamicLoading(MyLI);
    00056	}
    00057
    00058	//_____________________________________________________________________________
    00059	// Toss this item out.
    00060	function DropFrom(vector StartLocation)
    00061	{
    00062	    local Pickup P;
    00063
    00064	    if ( Instigator != None )
    00065	    {
    00066	      DetachFromPawn(Instigator);
    00067	      Instigator.DeleteInventory(self);
    00068	    }
    00069	    SetDefaultDisplayProperties();
    00070	    Inventory = None;
    00071	    Instigator = None;
    00072	    StopAnimating();
    00073	    GotoState('');
    00074
    00075	    P = spawn(PickupClass,,,StartLocation);
    00076
    00077	    if ( P == None )
    00078	    {
    00079	      destroy();
    00080	      return;
    00081	    }
    00082	    P.InitDroppedPickupFor(self);
    00083	    Ammo(P).Ammoamount = AmmoAmount;
    00084	    P.Velocity = Velocity;
    00085	    Velocity = vect(0,0,0);
    00086	}
    00087
    00088	//_____________________________________________________________________________
    00089	// Give this inventory item to a pawn.
    00090	function GiveTo( pawn Other )
    00091	{
    00092	    local ammunition Dual;
    00093
    00094	    Dual = ammunition(Other.FindInventoryType(class));
    00095	    if ( Dual == none )
    00096	    {
    00097	      Super.GiveTo(other);
    00098	      if ( Other.IsPlayerPawn() )
    00099	      {
    00100	        DebugLog("GIVETO (ammunition)"@self@"to"@Other@"Ammoamount="$AmmoAmount);
    00101	      }
    00102	    }
    00103	    else
    00104	    {
    00105	      if ( Other.IsPlayerPawn() )
    00106	      {
    00107	        DebugLog("GIVETO (ammunition)"@self@"to"@Other@"give ammo AmmoAmount="$AmmoAmount@"then Destroy because already owned");
    00108	      }
    00109	      if ( AmmoAmount > 0 )
    00110	        Dual.AddAmmo(AmmoAmount);
    00111	//        Dual.AmmoAmount += AmmoAmount;
    00112	      else
    00113	        Dual.AddAmmo(class<Ammo>(PickupClass).default.AmmoAmount);
    00114	//        Dual.AmmoAmount += class<Ammo>(PickupClass).default.AmmoAmount;
    00115	      Destroy();
    00116	    }
    00117	}
    00118
    00119	//_____________________________________________________________________________
    00120	// Transfer this inventory to Player (for SearchCorpse)
    00121	function Transfer( pawn Other )
    00122	{
    00123	    local ammunition Dual;
    00124
    00125	    if ( Other.IsPlayerPawn() )
    00126	    {
    00127	      DebugLog("TRANSFER (ammunition)"@self@"to"@Other@"AmmoAmount="$AmmoAmount);
    00128	    }
    00129	//		DetachFromPawn(Instigator); // no need ammos are not attached
    00130	    Instigator.DeleteInventory(self);
    00131
    00132	    // convert class if needed
    00133	    if ( (PlayerTransferClass == none) && (PlayerTransferClassName != "") )
    00134	      PlayerTransferClass = class<Inventory>(DynamicLoadObject(PlayerTransferClassName, class'class'));
    00135
    00136	    if ( class<Ammo>(PickupClass) != none )
    00137	      AmmoAmount = fMin(AmmoAmount, class<Ammo>(PickupClass).Default.AmmoAmount);
    00138
    00139	    if ( (PlayerTransferClass != none) && Other.IsHumanControlled() )
    00140	    {
    00141	      Dual = ammunition(Spawn(PlayerTransferClass,,,Other.Location));
    00142	      Dual.AmmoAmount = AmmoAmount;
    00143	      Dual.Transfer(Other);
    00144	      Destroy();
    00145	      return;
    00146	    }
    00147
    00148	    Dual = ammunition(Other.FindInventoryType(class));
    00149	    if ( Dual == none )
    00150	    {
    00151	      GiveTo(Other);
    00152	/*
    00153	      if ( (PickupClass != none) && (class<Ammo>(PickupClass) != none) ) // last test to avoid double message for ammos that have weapon as pickup (knives, grenads)
    00154	      {
    00155	        Other.PlaySound(PickupClass.default.PickupSound);
    00156	        Other.ReceiveLocalizedMessage( PickupClass.default.MessageClass, 0, None, None, PickupClass );
    00157	      }
    00158	*/
    00159	    }
    00160	    else
    00161	    {
    00162	//      Log("         (ammunition)"@self@"to"@Other@"give ammo then Destroy because already owned");
    00163	      Dual.AddAmmo(AmmoAmount);
    00164	/*
    00165	      if ( (PickupClass != none) && (class<Ammo>(PickupClass) != none) )
    00166	      {
    00167	        Other.PlaySound(PickupClass.default.PickupSound);
    00168	        Other.ReceiveLocalizedMessage( PickupClass.default.MessageClass, 0, None, None, PickupClass );
    00169	      }
    00170	*/
    00171	      Destroy();
    00172	      return;
    00173	    }
    00174	}
    00175
    00176	//_____________________________________________________________________________
    00177	native function bool HasAmmo();
    00178	/*
    00179	{
    00180	    return ( AmmoAmount > 0 );
    00181	}
    00182	*/
    00183
    00184	//_____________________________________________________________________________
    00185	function float RateSelf(Pawn Shooter, out name RecommendedFiringMode)
    00186	{
    00187	    return 0.5;
    00188	}
    00189
    00190	//_____________________________________________________________________________
    00191	function WarnTarget(Actor Target,Pawn P,vector FireDir)
    00192	{
    00193	//    Log("Warntarget call w/ Target="$Target@"Pawn="$P);
    00194	    if ( (Pawn(Target) != None) && (Pawn(Target).Controller != None) )
    00195	    {
    00196	      if ( bInstantHit )
    00197	      {
    00198	        if (FRand() < WarnTargetPct)
    00199	          Pawn(Target).Controller.ReceiveWarning(P, 10000, FireDir);
    00200	      }
    00201	      else if ( P.PressingFire() )
    00202	        Pawn(Target).Controller.ReceiveWarning(P, ProjectileClass.Default.Speed, FireDir);
    00203	    }
    00204	}
    00205
    00206	//_____________________________________________________________________________
    00207	function SpawnProjectile(vector Start, rotator Dir)
    00208	{
    00209	    AmmoAmount -= 1;
    00210	    Spawn(ProjectileClass,,, Start,Dir);
    00211	}
    00212
    00213	//_____________________________________________________________________________
    00214	function ProcessTraceHit(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
    00215	{
    00216	    AmmoAmount -= 1;
    00217	}
    00218
    00219	//_____________________________________________________________________________
    00220	// ELR to be defined in subclasses, used for weapon w/ multiple shots w/ only one ammo (ShotGun, Hunting Gun)
    00221	function ProcessTraceHitNoAmmo(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z);
    00222
    00223	//_____________________________________________________________________________
    00224	simulated function DisplayDebug(Canvas Canvas, out float YL, out float YPos)
    00225	{
    00226	    Canvas.DrawText("Ammunition "$GetItemName(string(self))$" amount "$AmmoAmount);
    00227	    YPos += YL;
    00228	    Canvas.SetPos(4,YPos);
    00229	}
    00230
    00231	//_____________________________________________________________________________
    00232	function bool HandlePickupQuery( pickup Item )
    00233	{
    00234	    if ( class == item.InventoryType )
    00235	    {
    00236	      if (AmmoAmount==MaxAmmo)
    00237	        return true;
    00238	      item.AnnouncePickup(Pawn(Owner));
    00239	      AddAmmo(Ammo(item).AmmoAmount);
    00240	      return true;
    00241	    }
    00242	    if ( Inventory == None )
    00243	      return false;
    00244
    00245
return Inventory.HandlePickupQuery(Item); 00246 } 00247 00248 //_____________________________________________________________________________ 00249 // If we can, add ammo and return true. 00250 // If we are at max ammo, return false 00251 function bool AddAmmo(int AmmoToAdd) 00252 { 00253 if ( Pawn(Owner).IsPlayerPawn() ) 00254 { 00255 DebugLog(self@"AddAmmo"@AmmoToAdd); 00256 } 00257 00258 If (AmmoAmount >= MaxAmmo) 00259 return false; 00260 AmmoAmount = Min(MaxAmmo, AmmoAmount+AmmoToAdd); 00261 return true; 00262 } 00263 00264 //_____________________________________________________________________________ 00265 function PlayImpactSound(Sound S) 00266 { 00267 if ( !Level.bLonePlayer ) 00268 { // Antibug, remove impact sounds in multiplayer 00269 bPlayHitSound = false; 00270 SetUpImpactEmitter(S); 00271 return; 00272 } 00273 if ( HitSoundType >= 0 ) 00274 { 00275 bPlayHitSound = true; 00276 HitSoundMem = S; 00277 SetUpImpactEmitter(S); 00278 } 00279 } 00280 00281 //_____________________________________________________________________________ 00282 function SetUpImpactEmitter(Sound S); 00283 00284 defaultproperties 00285 { 00286 bInstantHit=True 00287 MaxAmmo=666 00288 MyDamageType=Class'Engine.DamageType' 00289 WarnTargetPct=0.200000 00290 HitSoundType=-1 00291 }

End Source Code