UFO: Alien Invasion
Loading...
Searching...
No Matches
Inventory Class Reference

inventory definition with all its containers More...

#include <inv_shared.h>

Collaboration diagram for Inventory:
Collaboration graph

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.
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.
ItemfindInContainer (const containerIndex_t contId, const Item *const item) const
 Searches a specific item in the inventory&container.
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.
int getWeight () const
 Get the weight of the items in the given inventory (excluding those in temp containers).
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.
bool holdsReactionFireWeapon () const
 Checks if there is a weapon in the hands that can be used for reaction fire.
const ContainergetNextCont (const Container *prev, bool inclTemp=false) const
int countItems () const
 Count the number of items in the inventory (without temp containers).

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::Inventory ( )

Definition at line 692 of file inv_shared.cpp.

References init().

◆ ~Inventory()

virtual Inventory::~Inventory ( )
inlinevirtual

Definition at line 534 of file inv_shared.h.

Member Function Documentation

◆ _getNextCont()

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().

◆ canHoldItem()

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_t::all, invDef_t::armour, CID_LEFT, CID_RIGHT, Com_DPrintf(), containsItem(), DEBUG_SHARED, objDef_t::fireTwoHanded, getContainer2(), objDef_t::getShapeRotated(), invDef_t::headgear, objDef_t::headgear, objDef_t::holdTwoHanded, invDef_t::id, invDef_t::implant, objDef_t::implant, INV_DOES_NOT_FIT, INV_FITS, INV_FITS_ONLY_ROTATED, INVSH_CheckToInventory_shape(), objDef_t::isArmour(), invDef_t::isEquipDef(), invDef_t::isFloorDef(), invDef_t::isLeftDef(), invDef_t::isRightDef(), invDef_t::scroll, objDef_t::shape, invDef_t::single, and invDef_t::unique.

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

◆ canHoldItemWeight()

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 CSI, getArmour(), getWeight(), Item::getWeight(), and Item::isArmour().

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

◆ containsItem()

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(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ countItems()

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().

◆ findInContainer()

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().

◆ findSpace()

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_t::id, INV_DOES_NOT_FIT, INV_FITS, invDef_t::name, NONE, invDef_t::scroll, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, and objDef_t::type.

Referenced by InventoryInterface::addToInventory(), G_ActorInvMove(), InventoryInterface::moveInInventory(), TEST_F(), TEST_F(), and InventoryInterface::tryAddToInventory().

◆ getArmour()

Item * Inventory::getArmour ( ) const

◆ getContainer()

const Container & Inventory::getContainer ( const containerIndex_t idx) const
inline

◆ getContainer2()

◆ getEquipContainer()

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 UI_ContainerNodeUpdateEquipment().

◆ getFloorContainer()

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().

◆ getHeadgear()

Item * Inventory::getHeadgear ( ) const

Definition at line 965 of file inv_shared.cpp.

References CID_HEADGEAR, and getContainer2().

Referenced by G_PrepareShot(), HUD_UpdateActorFireMode(), and HUD_UpdateButtons().

◆ getHolsterContainer()

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().

◆ getImplantContainer()

Item * Inventory::getImplantContainer ( ) const

Definition at line 985 of file inv_shared.cpp.

References CID_IMPLANT, and getContainer2().

◆ getItemAtPos()

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_t::id, INVSH_ShapeCheckPosition(), invDef_t::name, invDef_t::scroll, invDef_t::single, and Sys_Error().

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

◆ getLeftHandContainer()

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

Definition at line 960 of file inv_shared.cpp.

References CID_LEFT, and getContainer2().

Referenced by CL_ActorCvars(), and holdsReactionFireWeapon().

◆ getNextCont()

◆ getRightHandContainer()

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

Definition at line 955 of file inv_shared.cpp.

References CID_RIGHT, and getContainer2().

Referenced by CL_ActorCvars(), CL_GetSkillIndicator(), CP_CleanupAircraftTeam(), CP_CleanupTeam(), and holdsReactionFireWeapon().

◆ getWeight()

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(), and INV_UpdateActorLoad_f().

◆ holdsReactionFireWeapon()

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().

◆ init()

void Inventory::init ( )

Definition at line 703 of file inv_shared.cpp.

References _containers, CID_MAX, i, and OBJZERO.

Referenced by B_LoadXML(), InventoryInterface::destroyInventory(), and Inventory().

◆ resetContainer()

void Inventory::resetContainer ( const containerIndex_t idx)
inline

◆ resetTempContainers()

void Inventory::resetTempContainers ( )
inline

◆ setContainer()

void Inventory::setContainer ( const containerIndex_t idx,
Item * cont )
inline

◆ setFloorContainer()

void Inventory::setFloorContainer ( Item * cont)

Definition at line 950 of file inv_shared.cpp.

References CID_FLOOR, and setContainer().

Field Documentation

◆ _containers

Container Inventory::_containers[MAX_CONTAINERS]
protected

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