Core.Object | +--Engine.Actor | +--Engine.Inventory | +--Engine.Pickup | +--Engine.Ammo
int
AmmoAmount
MaxAmmo
Ammo
PAmmo
class
ParentAmmo
byte
UsedInWeaponSlot[10]
bool
AddAmmo(int AmmoToAdd)
// If we can, add ammo and return true. // We we are at max ammo, return false //
HandlePickupQuery(Inventory Item)
Inventory
SpawnCopy(Pawn Other)
UseAmmo(int AmountNeeded)
// This function is called by an actor that wants to use ammo. // Return true if ammo exists //
00001 //============================================================================= 00002 // Ammo. 00003 //============================================================================= 00004 class Ammo extends Pickup 00005 abstract 00006 native 00007 nativereplication; 00008 00009 #exec Texture Import File=Textures\Ammo.pcx Name=S_Ammo Mips=Off Flags=2 00010 00011 var() travel int AmmoAmount; 00012 var() travel int MaxAmmo; 00013 var() class<ammo> ParentAmmo; // Class of ammo to be represented in inventory 00014 var() byte UsedInWeaponSlot[10]; 00015 var ammo PAmmo; 00016 00017 00018 00019 // Network replication 00020 // 00021 replication 00022 { 00023 // Things the server should send to the client. 00024 reliable if( bNetOwner && (Role==ROLE_Authority) ) 00025 AmmoAmount; 00026 } 00027 00028 event float BotDesireability(Pawn Bot) 00029 { 00030 local Ammo AlreadyHas; 00031 00032 if ( ParentAmmo != None ) 00033 AlreadyHas = Ammo(Bot.FindInventoryType(ParentAmmo)); 00034 else 00035 AlreadyHas = Ammo(Bot.FindInventoryType(Class)); 00036 if ( AlreadyHas == None ) 00037 return (0.35 * MaxDesireability); 00038 if ( AlreadyHas.AmmoAmount == 0 ) 00039 return MaxDesireability; 00040 if (AlreadyHas.AmmoAmount >= AlreadyHas.MaxAmmo) 00041 return -1; 00042 00043 return ( MaxDesireability * FMin(1, 0.15 * MaxAmmo/AlreadyHas.AmmoAmount) ); 00044 } 00045 00046 function bool HandlePickupQuery( inventory Item ) 00047 { 00048 if ( (class == item.class) || 00049 (ClassIsChildOf(item.class, class'Ammo') && (class == Ammo(item).parentammo)) ) 00050 { 00051 if (AmmoAmount==MaxAmmo) return true; 00052 if (Level.Game.LocalLog != None) 00053 Level.Game.LocalLog.LogPickup(Item, Pawn(Owner)); 00054 if (Level.Game.WorldLog != None) 00055 Level.Game.WorldLog.LogPickup(Item, Pawn(Owner)); 00056 if (Item.PickupMessageClass == None) 00057 Pawn(Owner).ClientMessage( Item.PickupMessage, 'Pickup' ); 00058 else 00059 Pawn(Owner).ReceiveLocalizedMessage( Item.PickupMessageClass, 0, None, None, item.Class ); 00060 item.PlaySound( item.PickupSound ); 00061 AddAmmo(Ammo(item).AmmoAmount); 00062 item.SetRespawn(); 00063 return true; 00064 } 00065 if ( Inventory == None ) 00066 return false; 00067 00068 return Inventory.HandlePickupQuery(Item); 00069 } 00070 00071 // This function is called by an actor that wants to use ammo. 00072 // Return true if ammo exists 00073 // 00074 function bool UseAmmo(int AmountNeeded) 00075 { 00076 if (AmmoAmount < AmountNeeded) return False; // Can't do it 00077 AmmoAmount -= AmountNeeded; 00078 return True; 00079 } 00080 00081 // If we can, add ammo and return true. 00082 // We we are at max ammo, return false 00083 // 00084 function bool AddAmmo(int AmmoToAdd) 00085 { 00086 If (AmmoAmount >= MaxAmmo) return false; 00087 AmmoAmount += AmmoToAdd; 00088 if (AmmoAmount > MaxAmmo) AmmoAmount = MaxAmmo; 00089 return true; 00090 } 00091 00092 function inventory SpawnCopy( Pawn Other ) 00093 { 00094 local Inventory Copy; 00095 00096 if ( parentammo != None ) 00097 { 00098 Copy = spawn(parentammo,Other,,,rot(0,0,0)); 00099 Copy.Tag = Tag; 00100 Copy.Event = Event; 00101 Copy.Instigator = Other; 00102 Ammo(Copy).AmmoAmount = AmmoAmount; 00103 Copy.BecomeItem(); 00104 Other.AddInventory( Copy ); 00105 Copy.GotoState(''); 00106 if ( Level.Game.ShouldRespawn(self) ) 00107 GotoState('Sleeping'); 00108 else 00109 Destroy(); 00110 return Copy; 00111 } 00112 Copy = Super.SpawnCopy(Other); 00113 Ammo(Copy).AmmoAmount = AmmoAmount; 00114 return Copy; 00115 } 00116 00117 defaultproperties 00118 { 00119 PickupMessage="You picked up some ammo." 00120 RespawnTime=30.000000 00121 MaxDesireability=0.200000 00122 Texture=Texture'Engine.S_Ammo' 00123 bCollideActors=False 00124 }