## Engine
Class Inventory

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

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

Direct Known Subclasses:Ammunition, Armor, Powerups, Weapon, XIIILeftHand, Beret, MarioSuperBonus, XIIIMPSpecialMatos

class Inventory
extends Engine.Actor

    //=============================================================================
    // Inventory
    //
    // Inventory is the parent class of all actors that can be carried by other actors.
    // Inventory items are placed in the holding actor's inventory chain, a linked list
    // of inventory actors.  Each inventory class knows what pickup can spawn it (its
    // PickupClass).  When tossed out (using the DropFrom() function), inventory items
    // replace themselves with an actor of their Pickup class.
    //
    //=============================================================================

Variables
`class` | `AttachmentClass` Attachment class to spawn ThirdPersonActor
`float` | `BobDamping` how much to damp view bob
`int` | `Charge` Charge (for example, armor remaining if an armor)
`byte` | `GroupOffset` position within inventory group. (used by prevweapon and nextweapon)
`Texture` | `Icon` Attachment class to spawn ThirdPersonActor
`byte` | `InventoryGroup` The weapon/inventory set, 0-9.
`string` | `ItemName` ELR Added travel because need to memorize names of keys & similar stuff
`class` | `NonPlayerTransferClass` Class to give when transfered from plyer to a nonplayer (to give player grenads to bots
`string` | `NonPlayerTransferClassName` class to give when transfered from plyer to a nonplayer (to give player grenads to bots
`class` | `PickupClass` what class of pickup is associated with this inventory item
`string` | `PickupClassName` to dynamicload ref (avoid ref to pickup class so avoid loading all pickups defaults)
`class` | `PlayerTransferClass` Class to give when transfered from enemy to a player (to avoid infinite ammo weapon for player)
`string` | `PlayerTransferClassName` class to give when transfered from enemy to a player (to avoid infinite ammo weapon for player)
`vector` | `PlayerViewOffset` Offset from view center.
`Actor` | `ThirdPersonActor` the third person actor showing this inv on pawn
`vector` | `ThirdPersonRelativeLocation` the third person actor showing this inv on pawn
`rotator` | `ThirdPersonRelativeRotation` the third person actor showing this inv on pawn
`float` | `ThirdPersonScale` the third person actor showing this inv on pawn
`bool` | `bDisplayableInv` Item displayed in HUD.
`bool` | `bTossedOut` true if weapon/inventory was tossed out (so players can't cheat w/ weaponstay)

Function Summary
`void` | `AttachToPawn(Pawn P)`
    //_____________________________________________________________________________
    // DO NOT SIMULATE else double attachspawn on clients & graphical bug.
`simulated` | `DetachFromPawn(Pawn P)`
    //_____________________________________________________________________________
`void` | `DropFrom(vector StartLocation)`
    //_____________________________________________________________________________
    // Toss this item out.
`String` | `GetHumanReadableName()`
    //_____________________________________________________________________________
`void` | `GiveTo(Pawn Other)`
    //_____________________________________________________________________________
    // Give this inventory item to a pawn.
`bool` | `HandlePickupQuery(Pickup Item)`
    //_____________________________________________________________________________
    // Function which lets existing items in a pawn's inventory
    // prevent the pawn from picking something up. Return true to abort pickup
    // or if item handles pickup, otherwise keep going through inventory list.
`Powerups` | `NextItem(Powerups CurrentChoice, Powerups CurrentItem)`
    //_____________________________________________________________________________
    // Find the next weapon (using the Inventory group)
`Weapon` | `NextWeapon(Weapon CurrentChoice, Weapon CurrentWeapon)`
    //_____________________________________________________________________________
    // Find the next weapon (using the Inventory group)
`void` | `NotifyOwnerKilled(Controller Killer)`
    //_____________________________________________________________________________
`void` | `OwnerEvent(name EventName)`
    //_____________________________________________________________________________
    // Used to inform inventory when owner event occurs (for example jumping or weapon change)
`void` | `PickupFunction(Pawn Other)`
    //_____________________________________________________________________________
    // this function is called once a pawn has been given/announced the item
`simulated` | `PostBeginPlay()`
    //_____________________________________________________________________________
`Powerups` | `PrevItem(Powerups CurrentChoice, Powerups CurrentItem)`
    //_____________________________________________________________________________
    // Find the previous weapon (using the Inventory group)
`Weapon` | `PrevWeapon(Weapon CurrentChoice, Weapon CurrentWeapon)`
    //_____________________________________________________________________________
    // Find the previous weapon (using the Inventory group)
`Weapon` | `RecommendWeapon(out float)`
    //_____________________________________________________________________________
    // AI inventory functions.
`Powerups` | `SelectNext()`
    //_____________________________________________________________________________
    // Select first activatable powerup.
`void` | `SetOwnerDisplay()`
    //_____________________________________________________________________________
    // used to ask inventory if it needs to affect its owners display properties
`void` | `StaticParseDynamicLoading(LevelInfo MyLI)`
    //_____________________________________________________________________________
    // this function is called when the class if given to enemy as initial inventory (so need to dynamiload everything else except the class)
`void` | `Transfer(Pawn Other)`
    //_____________________________________________________________________________
    // Transfer this inventory to Player (for SearchCorpse)
`void` | `TravelPostAccept()`
`void` | `Use(float Value)`
    //_____________________________________________________________________________
`Weapon` | `WeaponChange(byte F)`
    //_____________________________________________________________________________
    // Find a weapon in inventory that has an Inventory Group matching F.
`Weapon` | `WeaponSelect(byte F)`
    //_____________________________________________________________________________
    // ELR Same as WeaponChange but to be used for SelectWeapon, use new to avoid new bugs

Source Code

    00001	//=============================================================================
    00002	// Inventory
    00003	//
    00004	// Inventory is the parent class of all actors that can be carried by other actors.
    00005	// Inventory items are placed in the holding actor's inventory chain, a linked list
    00006	// of inventory actors.  Each inventory class knows what pickup can spawn it (its
    00007	// PickupClass).  When tossed out (using the DropFrom() function), inventory items
    00008	// replace themselves with an actor of their Pickup class.
    00009	//
    00010	//=============================================================================
    00011	class Inventory extends Actor
    00012	  abstract
    00013	  native
    00014	  nativereplication;
    00015
    00016	#exec Texture Import File=Textures\Inventry.pcx Name=S_Inventory Mips=Off MASKED=1 COMPRESS=DXT1
    00017
    00018	//_____________________________________________________________________________
    00019	var byte InventoryGroup;        // The weapon/inventory set, 0-9.
    00020	var byte GroupOffset;           // position within inventory group. (used by prevweapon and nextweapon)
    00021	var bool bDisplayableInv;       // Item displayed in HUD.
    00022	var bool bTossedOut;            // true if weapon/inventory was tossed out (so players can't cheat w/ weaponstay)
    00023	var class<Pickup> PickupClass;  // what class of pickup is associated with this inventory item
    00024	var string PickupClassName;     // to dynamicload ref (avoid ref to pickup class so avoid loading all pickups defaults)
    00025	var travel int Charge;          // Charge (for example, armor remaining if an armor)
    00026	var string PlayerTransferClassName;    // class to give when transfered from enemy to a player (to avoid infinite ammo weapon for player)
    00027	var string NonPlayerTransferClassName; // class to give when transfered from plyer to a nonplayer (to give player grenads to bots
    00028	var class<Inventory> PlayerTransferClass;    // Class to give when transfered from enemy to a player (to avoid infinite ammo weapon for player)
    00029	var class<Inventory> NonPlayerTransferClass; // Class to give when transfered from plyer to a nonplayer (to give player grenads to bots
    00030
    00031	//_____________________________________________________________________________
    00032	// Rendering information.
    00033	// Player view rendering info.
    00034	var vector PlayerViewOffset;    // Offset from view center.
    00035	var float BobDamping;           // how much to damp view bob
    00036	// 3rd person mesh.
    00037	var actor ThirdPersonActor;     // the third person actor showing this inv on pawn
    00038	//var mesh ThirdPersonMesh;
    00039	//var staticMesh ThirdPersonStaticMesh;
    00040	var float ThirdPersonScale;
    00041	var() vector ThirdPersonRelativeLocation;
    00042	var() rotator ThirdPersonRelativeRotation;
    00043	var class<InventoryAttachment> AttachmentClass; // Attachment class to spawn ThirdPersonActor
    00044
    00045	//_____________________________________________________________________________
    00046	// HUD graphics.
    00047	var texture Icon;
    00048	//var texture StatusIcon;         // Icon used with ammo/charge/power count on HUD.
    00049	var travel string ItemName;     // ELR Added travel because need to memorize names of keys & similar stuff
    00050
    00051	//_____________________________________________________________________________
    00052	// Network replication.
    00053	replication
    00054	{
    00055	  // Things the server should send to the client.
    00056	  reliable if( bNetOwner && bNetDirty && (Role==ROLE_Authority) )
    00057	    Charge,ThirdPersonActor;
    00058	}
    00059
    00060	//_____________________________________________________________________________
    00061	// this function is called when the class if given to enemy as initial inventory (so need to dynamiload everything else except the class)
    00062	Static function StaticParseDynamicLoading(LevelInfo MyLI)
    00063	{
    00064	    Log("Inventory StaticParseDynamicLoading class="$default.class);
    00065	    MyLI.ForcedClasses[MyLI.ForcedClasses.Length] = default.class;
    00066	    if ( default.PickupClassName != "" )
    00067	      MyLI.ForcedClasses[MyLI.ForcedClasses.Length] =
    00068	        class(DynamicLoadObject(default.PickupClassName, class'Class'));
    00069	    if ( default.PlayerTransferClassName != "" )
    00070	      MyLI.ForcedClasses[MyLI.ForcedClasses.Length] =
    00071	        class(DynamicLoadObject(default.PlayerTransferClassName, class'Class'));
    00072	    if ( default.NonPlayerTransferClassName != "" )
    00073	      MyLI.ForcedClasses[MyLI.ForcedClasses.Length] =
    00074	        class(DynamicLoadObject(default.NonPlayerTransferClassName, class'Class'));
    00075	    if ( default.AttachmentClass != none )
    00076	      (default.AttachmentClass).Static.StaticParseDynamicLoading(MyLI);
    00077	}
    00078
    00079	//_____________________________________________________________________________
    00080	event ParseDynamicLoading(LevelInfo MyLI)
    00081	{
    00082	    Log("ParseDynamicLoading Actor="$self);
    00083	    if ( default.PickupClassName != "" )
    00084	      MyLI.ForcedClasses[MyLI.ForcedClasses.Length] =
    00085	        class(DynamicLoadObject(default.PickupClassName, class'Class'));
    00086	    if ( default.AttachmentClass != none )
    00087	      (default.AttachmentClass).Static.StaticParseDynamicLoading(MyLI);
    00088	    if ( default.PlayerTransferClassName != "" )
    00089	    {
    00090	      MyLI.ForcedClasses[MyLI.ForcedClasses.Length] =
    00091	        class(DynamicLoadObject(default.PlayerTransferClassName, class'Class'));
    00092	      class<Inventory>(MyLI.ForcedClasses[MyLI.ForcedClasses.Length-1]).Static.StaticParseDynamicLoading(MyLI);
    00093	    }
    00094	    if ( default.NonPlayerTransferClassName != "" )
    00095	    {
    00096	      MyLI.ForcedClasses[MyLI.ForcedClasses.Length] =
    00097	        class(DynamicLoadObject(default.NonPlayerTransferClassName, class'Class'));
    00098	      class<Inventory>(MyLI.ForcedClasses[MyLI.ForcedClasses.Length-1]).Static.StaticParseDynamicLoading(MyLI);
    00099	    }
    00100	}
    00101
    00102	//_____________________________________________________________________________
    00103	simulated function PostBeginPlay()
    00104	{
    00105	    Super.PostBeginPlay();
    00106	    if ( (PickupClass == none) && (PickupClassName != "") )
    00107	      PickupClass = class<Pickup>(DynamicLoadObject(PickupClassName, class'Class')); // ParseDynMade
    00108	}
    00109
    00110	//_____________________________________________________________________________
    00111	// DO NOT SIMULATE else double attachspawn on clients & graphical bug.
    00112	function AttachToPawn(Pawn P)
    00113	{
    00114	    local name BoneName;
    00115
    00116	    if ( ThirdPersonActor == None )
    00117	    {
    00118	      ThirdPersonActor = Spawn(AttachmentClass,Owner);
    00119	      InventoryAttachment(ThirdPersonActor).InitFor(self);
    00120	    }
    00121	    BoneName = P.GetWeaponBoneFor(self);
    00122	    if ( BoneName == '' )
    00123	    {
    00124	//      ThirdPersonActor.SetLocation(P.Location);
    00125	//      ThirdPersonActor.SetBase(P);
    00126	      P.AttachToBone(ThirdPersonActor, 'X R Hand');
    00127	    }
    00128	    else
    00129	      P.AttachToBone(ThirdPersonActor,BoneName);
    00130
    00131	    ThirdPersonActor.SetRelativeLocation(ThirdPersonRelativeLocation);
    00132	    ThirdPersonActor.SetRelativeRotation(ThirdPersonRelativeRotation);
    00133	//    LOG("^ ATTACHED"@ThirdPersonActor@"to"@self);
    00134	}
    00135
    00136	//_____________________________________________________________________________
    00137	simulated function DetachFromPawn(Pawn P)
    00138	{
    00139	//    LOG("^ DETACHING"@ThirdPersonActor@"from"@self);
    00140	    if ( ThirdPersonActor != None )
    00141	    {
    00142	      ThirdPersonActor.Destroy();
    00143	      ThirdPersonActor = None;
    00144	    }
    00145	}
    00146
    00147	//_____________________________________________________________________________
    00148	// RenderOverlays() - Draw add. info for first person view of inventory
    00149	// the weapon/item first person rendering if made as everything else, using bHidden & Refreshdisplaying
    00150	simulated event RenderOverlays( canvas Canvas )
    00151	{
    00152	/*
    00153	  if ( (Instigator == None) || (Instigator.Controller == None))
    00154	    return;
    00155	  SetLocation( Instigator.Location + Instigator.CalcDrawOffset(self) );
    00156	  SetRotation( Instigator.GetViewRotation() );
    00157	  Canvas.DrawActor(self, false);
    00158	*/
    00159	}
    00160
    00161	//_____________________________________________________________________________
    00162	function String GetHumanReadableName()
    00163	{
    00164	    if ( ItemName == "" )
    00165	      ItemName = GetItemName(string(Class));
    00166	    return ItemName;
    00167	}
    00168
    00169	//_____________________________________________________________________________
    00170	// this function is called once a pawn has been given/announced the item
    00171	function PickupFunction(Pawn Other);
    00172
    00173	//_____________________________________________________________________________
    00174	// AI inventory functions.
    00175	simulated function Weapon RecommendWeapon( out float rating )
    00176	{
    00177	    if ( inventory != None )
    00178	      return inventory.RecommendWeapon(rating);
    00179	    else
    00180	    {
    00181	      rating = -1;
    00182	      return None;
    00183	    }
    00184	}
    00185
    00186	//_____________________________________________________________________________
    00187	// Called after a travelling inventory item has been accepted into a level.
    00188	event TravelPreAccept()
    00189	{
    00190	    Super.TravelPreAccept();
    00191	    GiveTo( Pawn(Owner) );
    00192	}
    00193
    00194	function TravelPostAccept()
    00195	{
    00196	    Super.TravelPostAccept();
    00197	    PickupFunction(Pawn(Owner));
    00198	}
    00199
    00200	// Called by engine when destroyed.
    00201	simulated event Destroyed()
    00202	{
    00203	//  Log("    DESTROY"@self@"Attached="$ThirdPersonActor);
    00204	  // Remove from owner's inventory.
    00205	  if( Pawn(Owner)!=None )
    00206	    Pawn(Owner).DeleteInventory( Self );
    00207	  else if ( Instigator != none )
    00208	    Instigator.DeleteInventory( Self );
    00209	  if ( ThirdPersonActor != None )
    00210	    ThirdPersonActor.Destroy();
    00211	}
    00212
    00213	//_____________________________________________________________________________
    00214	// Give this inventory item to a pawn.
    00215	function GiveTo( pawn Other )
    00216	{
    00217	    if ( Other.IsPlayerPawn() )
    00218	      DebugLog("GIVETO (inventory)"@self@"to"@Other);
    00219	    Instigator = Other;
    00220	    Other.AddInventory( Self );
    00221	    GotoState('');
    00222	}
    00223
    00224	//_____________________________________________________________________________
    00225	// Transfer this inventory to Player (for SearchCorpse)
    00226	function Transfer( pawn Other )
    00227	{
    00228	    if ( Other.IsPlayerPawn() )
    00229	    {
    00230	      DebugLog("TRANSFER (inventory)"@self@"to"@Other);
    00231	    }
    00232	    if ( Instigator != none )
    00233	    {
    00234	      DetachFromPawn(Instigator);
    00235	      Instigator.DeleteInventory(self);
    00236	    }
    00237	    GiveTo(Other);
    00238	}
    00239
    00240
    00241	//_____________________________________________________________________________
    00242	// Function which lets existing items in a pawn's inventory
    00243	// prevent the pawn from picking something up. Return true to abort pickup
    00244	// or if item handles pickup, otherwise keep going through inventory list.
    00245
function bool HandlePickupQuery( pickup Item ) 00246 { 00247 // Log(">> HandlePickupQuery for "$self); 00248 if ( Item.InventoryType == Class ) 00249 return true; 00250 if ( Inventory == None ) 00251 return false; 00252 00253 return Inventory.HandlePickupQuery(Item); 00254 } 00255 00256 //_____________________________________________________________________________ 00257 // Select first activatable powerup. 00258 function Powerups SelectNext() 00259 { 00260 if ( Inventory != None ) 00261 return Inventory.SelectNext(); 00262 else 00263 return None; 00264 } 00265 00266 //_____________________________________________________________________________ 00267 // Toss this item out. 00268 function DropFrom(vector StartLocation) 00269 { 00270 local Pickup P; 00271 00272 if ( Instigator != None ) 00273 { 00274 DetachFromPawn(Instigator); 00275 Instigator.DeleteInventory(self); 00276 } 00277 SetDefaultDisplayProperties(); 00278 Inventory = None; 00279 Instigator = None; 00280 StopAnimating(); 00281 GotoState(''); 00282 00283 P = spawn(PickupClass,,,StartLocation); 00284 00285 if ( P == None ) 00286 { 00287 destroy(); 00288 return; 00289 } 00290 P.InitDroppedPickupFor(self); 00291 P.Velocity = Velocity; 00292 Velocity = vect(0,0,0); 00293 } 00294 00295 //_____________________________________________________________________________ 00296 function Use( float Value ); 00297 00298 //_____________________________________________________________________________ 00299 // Find a weapon in inventory that has an Inventory Group matching F. 00300 simulated function Weapon WeaponChange( byte F ) 00301 { 00302 if( Inventory == None) 00303 return None; 00304 else 00305 return Inventory.WeaponChange( F ); 00306 } 00307 00308 //_____________________________________________________________________________ 00309 // ELR Same as WeaponChange but to be used for SelectWeapon, use new to avoid new bugs 00310 simulated function Weapon WeaponSelect( byte F ) 00311 { 00312 if( Inventory == None) 00313 return None; 00314 else 00315 return Inventory.WeaponSelect( F ); 00316 } 00317 00318 //_____________________________________________________________________________ 00319 // Find the previous weapon (using the Inventory group) 00320 simulated function Weapon PrevWeapon(Weapon CurrentChoice, Weapon CurrentWeapon) 00321 { 00322 if ( Inventory == None ) 00323 return CurrentChoice; 00324 else 00325 return Inventory.PrevWeapon(CurrentChoice,CurrentWeapon); 00326 } 00327 00328 //_____________________________________________________________________________ 00329 // Find the next weapon (using the Inventory group) 00330 simulated function Weapon NextWeapon(Weapon CurrentChoice, Weapon CurrentWeapon) 00331 { 00332 if ( Inventory == None ) 00333 return CurrentChoice; 00334 else 00335 return Inventory.NextWeapon(CurrentChoice,CurrentWeapon); 00336 } 00337 00338 //_____________________________________________________________________________ 00339 // Find the previous weapon (using the Inventory group) 00340 simulated function PowerUps PrevItem(PowerUps CurrentChoice, PowerUps CurrentItem) 00341 { 00342 if ( Inventory == None ) 00343 return CurrentChoice; 00344 else 00345 return Inventory.PrevItem(CurrentChoice,CurrentItem); 00346 } 00347 00348 //_____________________________________________________________________________ 00349 // Find the next weapon (using the Inventory group) 00350 simulated function PowerUps NextItem(PowerUps CurrentChoice, PowerUps CurrentItem) 00351 { 00352 if ( Inventory == None ) 00353 return CurrentChoice; 00354 else 00355 return Inventory.NextItem(CurrentChoice,CurrentItem); 00356 } 00357 00358 /* XIIIUNUSED 00359 //_____________________________________________________________________________ 00360 // Used to inform inventory when owner event occurs (for example jumping or weapon change) 00361 function OwnerEvent(name EventName) 00362 { 00363 if( Inventory != None ) 00364 Inventory.OwnerEvent(EventName); 00365 } 00366 */ 00367 00368 //_____________________________________________________________________________ 00369 // used to ask inventory if it needs to affect its owners display properties 00370 function SetOwnerDisplay() 00371 { 00372 if( Inventory != None ) 00373 Inventory.SetOwnerDisplay(); 00374 } 00375 00376 //_____________________________________________________________________________ 00377 function NotifyOwnerKilled(controller Killer); 00378 00379 defaultproperties 00380 { 00381 BobDamping=0.960000 00382 ThirdPersonScale=1.000000 00383 AttachmentClass=Class'Engine.InventoryAttachment' 00384 bHidden=True 00385 bOnlyOwnerSee=True 00386 bClientAnim=True 00387 bAcceptsProjectors=True 00388 bInteractive=False 00389 bReplicateMovement=False 00390 bTravel=True 00391 RemoteRole=ROLE_SimulatedProxy 00392 DrawType=DT_None 00393 NetPriority=1.400000 00394 }

End Source Code