UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Inventory Class Reference

inventory definition with all its containers More...

#include <inv_shared.h>

Public Member Functions

 Inventory ()
 
virtual ~Inventory ()
 
void init ()
 
const ContainergetContainer (const containerIndex_t idx) const
 
ItemgetContainer2 (const containerIndex_t idx) const
 
void setContainer (const containerIndex_t idx, Item *cont)
 
void resetContainer (const containerIndex_t idx)
 
void resetTempContainers ()
 
bool containsItem (const containerIndex_t contId, const Item *const item) const
 Searches if there is a specific item already in the inventory&container. More...
 
ItemgetArmour () const
 
ItemgetHeadgear () const
 
ItemgetRightHandContainer () const
 
ItemgetLeftHandContainer () const
 
ItemgetHolsterContainer () const
 
ItemgetEquipContainer () const
 
ItemgetImplantContainer () const
 
ItemgetFloorContainer () const
 
void setFloorContainer (Item *cont)
 
void findSpace (const invDef_t *container, const Item *item, int *const px, int *const py, const Item *ignoredItem) const
 Finds space for item in inv at container. More...
 
ItemfindInContainer (const containerIndex_t contId, const Item *const item) const
 Searches a specific item in the inventory&container. More...
 
ItemgetItemAtPos (const invDef_t *container, const int x, const int y) const
 Searches if there is an item at location (x,y) in a container. More...
 
int getWeight () const
 Get the weight of the items in the given inventory (excluding those in temp containers). More...
 
int canHoldItem (const invDef_t *container, const objDef_t *od, const int x, const int y, const Item *ignoredItem) const
 
bool canHoldItemWeight (containerIndex_t from, containerIndex_t to, const Item &item, int maxWeight) const
 Check that adding an item to the inventory won't exceed the max permitted weight. More...
 
bool holdsReactionFireWeapon () const
 Checks if there is a weapon in the hands that can be used for reaction fire. More...
 
const ContainergetNextCont (const Container *prev, bool inclTemp=false) const
 
int countItems () const
 Count the number of items in the inventory (without temp containers) More...
 

Protected Member Functions

const Container_getNextCont (const Container *prev) const
 

Protected Attributes

Container _containers [MAX_CONTAINERS]
 

Detailed Description

inventory definition with all its containers

Definition at line 525 of file inv_shared.h.

Constructor & Destructor Documentation

Inventory::Inventory ( )

Definition at line 692 of file inv_shared.cpp.

References init().

virtual Inventory::~Inventory ( )
inlinevirtual

Definition at line 534 of file inv_shared.h.

Member Function Documentation

const Container * Inventory::_getNextCont ( const Container prev) const
protected
Todo:
: convert into iterator

Definition at line 710 of file inv_shared.cpp.

References _containers, and CID_MAX.

Referenced by getNextCont().

int Inventory::canHoldItem ( const invDef_t container,
const objDef_t od,
const int  x,
const int  y,
const Item ignoredItem 
) const
Parameters
[in]containerThe index of the container in the inventory to check the item in.
[in]odThe type of item to check in the inventory.
[in]xThe x value in the container (1 << x in the shape bitmask)
[in]yThe y value in the container (SHAPE_BIG_MAX_HEIGHT is the max)
[in]ignoredItemYou can ignore one item in the container (most often the currently dragged one). Use nullptr if you want to check against all items in the container.
Returns
INV_DOES_NOT_FIT if the item does not fit
INV_FITS if it fits and
INV_FITS_ONLY_ROTATED if it fits only when rotated 90 degree (to the left).
INV_FITS_BOTH if it fits either normally or when rotated 90 degree (to the left).

< Return INV_FITS_BOTH if both if statements where true above.

< We are returning with status true (1) if the item does not fit at all - unlikely but not impossible.

Todo:
aren't both (equip and floor) temp container?

< Return INV_FITS_BOTH if both if statements where true above.

Definition at line 761 of file inv_shared.cpp.

References invDef_s::all, invDef_s::armour, CID_LEFT, CID_RIGHT, Com_DPrintf(), containsItem(), DEBUG_SHARED, objDef_s::fireTwoHanded, getContainer2(), objDef_s::getShapeRotated(), objDef_s::headgear, invDef_s::headgear, objDef_s::holdTwoHanded, invDef_s::id, objDef_s::implant, invDef_s::implant, INV_DOES_NOT_FIT, INV_FITS, INV_FITS_ONLY_ROTATED, INVSH_CheckToInventory_shape(), objDef_s::isArmour(), invDef_s::isEquipDef(), invDef_s::isFloorDef(), Item::isHeldTwoHanded(), invDef_s::isLeftDef(), invDef_s::isRightDef(), invDef_s::scroll, objDef_s::shape, invDef_s::single, and invDef_s::unique.

Referenced by InventoryInterface::addToInventory(), findSpace(), InventoryInterface::moveInInventory(), uiContainerNode::onDndMove(), InventoryInterface::tryAddToInventory(), UI_ContainerNodeDrawDropPreview(), and UI_ContainerNodeDrawFreeSpace().

bool Inventory::canHoldItemWeight ( containerIndex_t  from,
containerIndex_t  to,
const Item item,
int  maxWeight 
) const

Check that adding an item to the inventory won't exceed the max permitted weight.

Parameters
[in]fromIndex of the container the item comes from.
[in]toIndex of the container the item is being placed.
[in]itemThe item that is being added.
[in]maxWeightThe max permitted weight.
Returns
true if it is Ok to add the item false otherwise.

Definition at line 919 of file inv_shared.cpp.

References getArmour(), Item::getWeight(), getWeight(), csi_s::ids, Item::isArmour(), and invDef_s::temp.

Referenced by CL_ActorInvMove(), G_ActorInvMove(), G_ClientReadInventory(), GAME_LoadInventory(), and INV_MoveItem().

bool Inventory::containsItem ( const containerIndex_t  contId,
const Item *const  item 
) const
inline

Searches if there is a specific item already in the inventory&container.

Parameters
[in]contIdContainer in the inventory.
[in]itemThe item to search for.
Returns
true if there already is at least one item of this type, otherwise false.

Definition at line 572 of file inv_shared.h.

References findInContainer().

Referenced by canHoldItem(), uiContainerNode::onDndMove(), and TEST_F().

int Inventory::countItems ( ) const

Count the number of items in the inventory (without temp containers)

Definition at line 741 of file inv_shared.cpp.

References Container::countItems(), and getNextCont().

Referenced by GAME_NetSendInventory().

Item * Inventory::findInContainer ( const containerIndex_t  contId,
const Item *const  searchItem 
) const

Searches a specific item in the inventory&container.

Parameters
[in]contIdContainer in the inventory.
[in]searchItemThe item to search for.
Returns
Pointer to the first item of this type found, otherwise nullptr.

Definition at line 1001 of file inv_shared.cpp.

References getContainer(), Container::getNextItem(), and Item::isSameAs().

Referenced by containsItem(), and G_ActorInvMove().

void Inventory::findSpace ( const invDef_t container,
const Item item,
int *const  px,
int *const  py,
const Item ignoredItem 
) const

Finds space for item in inv at container.

Parameters
[in]itemThe item to check the space for
[in]containerThe container to search in
[out]pxThe x position in the container
[out]pyThe y position in the container
[in]ignoredItemYou can ignore one item in the container (most often the currently dragged one). Use nullptr if you want to check against all items in the container.
See also
canHoldItem
Note
x and y are NONE if no free space is available
Todo:
optimize for single containers

Definition at line 876 of file inv_shared.cpp.

References cacheCheckToInventory, canHoldItem(), Com_DPrintf(), DEBUG_SHARED, Item::def(), objDef_s::id, INV_DOES_NOT_FIT, INV_FITS, invDef_s::name, NONE, invDef_s::scroll, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, and objDef_s::type.

Referenced by InventoryInterface::addToInventory(), G_ActorInvMove(), InventoryInterface::moveInInventory(), uiContainerNode::onDndMove(), InventoryInterface::tryAddToInventory(), and UI_ContainerNodeAddItem().

Item * Inventory::getArmour ( ) const
Item * Inventory::getEquipContainer ( ) const
Todo:
this should return a reference - can't be null

Definition at line 980 of file inv_shared.cpp.

References CID_EQUIP, and getContainer2().

Referenced by GAME_ActorSelect_f(), and UI_ContainerNodeUpdateEquipment().

Item * Inventory::getFloorContainer ( ) const
Todo:
this should return a reference - can't be null

Definition at line 975 of file inv_shared.cpp.

References CID_FLOOR, and getContainer2().

Referenced by Edict::getFloor(), and le_s::getFloorContainer().

Item * Inventory::getHeadgear ( ) const
Item * Inventory::getHolsterContainer ( ) const
Todo:
this should return a reference - can't be null

Definition at line 970 of file inv_shared.cpp.

References CID_HOLSTER, and getContainer2().

Referenced by CL_GetSkillIndicator().

Item * Inventory::getImplantContainer ( ) const

Definition at line 985 of file inv_shared.cpp.

References CID_IMPLANT, and getContainer2().

Item * Inventory::getItemAtPos ( const invDef_t container,
const int  x,
const int  y 
) const

Searches if there is an item at location (x,y) in a container.

Parameters
[in]containerContainer in the inventory.
[in]x/yPosition in the container that you want to check.
Returns
Item Pointer to the Item/item that is located at x/y.

Definition at line 844 of file inv_shared.cpp.

References getContainer(), getContainer2(), Container::getNextItem(), invDef_s::id, INVSH_ShapeCheckPosition(), invDef_s::name, invDef_s::scroll, invDef_s::single, and Sys_Error().

Referenced by CL_ActorInvMove(), CL_InvAmmo(), CL_InvDel(), CL_InvReload(), G_ActorInvMove(), G_ClientAction(), INV_LoadWeapon(), InventoryInterface::moveInInventory(), uiContainerNode::onDndFinished(), uiContainerNode::onDndMove(), and UI_ContainerNodeGetItemAtPosition().

Item * Inventory::getLeftHandContainer ( ) const
Item * Inventory::getRightHandContainer ( ) const
int Inventory::getWeight ( ) const

Get the weight of the items in the given inventory (excluding those in temp containers).

Returns
The total weight of the inventory items (excluding those in temp containers)

Definition at line 937 of file inv_shared.cpp.

References getNextCont(), Container::getNextItem(), and Item::getWeight().

Referenced by canHoldItemWeight(), G_ActorCalculateMaxTU(), G_ClientAssignDefaultActorValues(), G_UpdateCarriedWeight(), InventoryInterface::GetInventoryState(), HUD_UpdateActorLoad_f(), and INV_UpdateActorLoad_f().

bool Inventory::holdsReactionFireWeapon ( ) const

Checks if there is a weapon in the hands that can be used for reaction fire.

Definition at line 1016 of file inv_shared.cpp.

References getLeftHandContainer(), and getRightHandContainer().

Referenced by G_ReactionFireCanBeEnabled(), HUD_ToggleReaction_f(), and HUD_UpdateButtons().

void Inventory::init ( void  )
void Inventory::resetContainer ( const containerIndex_t  idx)
inline
void Inventory::resetTempContainers ( )
inline
void Inventory::setFloorContainer ( Item cont)

Field Documentation

Container Inventory::_containers[MAX_CONTAINERS]
protected

Definition at line 527 of file inv_shared.h.

Referenced by _getNextCont(), getNextCont(), and init().


The documentation for this class was generated from the following files: