UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_inventory.cpp File Reference

General actor related inventory function for are used in every game mode. More...

#include "client.h"
#include "cl_inventory.h"
#include "cl_inventory_callbacks.h"
#include "../shared/parse.h"
#include "ui/ui_popup.h"
#include "cgame/cl_game.h"
Include dependency graph for cl_inventory.cpp:

Go to the source code of this file.

Functions

const equipDef_tINV_GetEquipmentDefinitionByID (const char *name)
 Gets equipment definition by id.
bool INV_MoveItem (Inventory *inv, const invDef_t *toContainer, int toX, int toY, const invDef_t *fromContainer, Item *fItem, Item **uponItem)
 Move item between containers.
bool INV_LoadWeapon (const Item *weaponList, Inventory *inv, const invDef_t *srcContainer, const invDef_t *destContainer)
 Load a weapon with ammo.
bool INV_UnloadWeapon (Item *weapon, Inventory *inv, const invDef_t *container)
 Unload a weapon and put the ammo in a container.
static bool INV_EquipmentDefSanityCheck (void)
 Make sure equipment definitions used to generate teams are proper.
itemFilterTypes_t INV_GetFilterFromItem (const objDef_t *obj)
bool INV_ItemMatchesFilter (const objDef_t *obj, const itemFilterTypes_t filterType)
 Checks if the given object/item matched the given filter type.
ItemINV_SearchInInventoryWithFilter (const Inventory *const inv, const invDef_t *container, const objDef_t *itemType, const itemFilterTypes_t filterType)
 Searches if there is an item at location (x/y) in a scrollable container. You can also provide an item to search for directly (x/y is ignored in that case).
 CASSERT (lengthof(filterTypeNames)==MAX_FILTERTYPES)
itemFilterTypes_t INV_GetFilterTypeID (const char *filterTypeID)
 Searches for a filter type name (as used in console functions) and returns the matching itemFilterTypes_t enum.
const char * INV_GetFilterType (itemFilterTypes_t id)
void INV_InitStartup (void)

Variables

static char const *const filterTypeNames []

Detailed Description

General actor related inventory function for are used in every game mode.

Note
Inventory functions prefix: INV_

Definition in file cl_inventory.cpp.

Function Documentation

◆ CASSERT()

◆ INV_EquipmentDefSanityCheck()

bool INV_EquipmentDefSanityCheck ( void )
static

Make sure equipment definitions used to generate teams are proper.

Note
Check that the sum of all probabilities is smaller or equal to 100 for a weapon type.
See also
INVSH_EquipActor

Definition at line 187 of file cl_inventory.cpp.

References Com_Printf(), csi, objDef_t::deplete, FILTER_S_ARMOUR, FILTER_S_HEAVY, FILTER_S_PRIMARY, FILTER_S_SECONDARY, objDef_t::fireTwoHanded, i, equipDef_t::id, INV_ItemMatchesFilter(), INVSH_GetItemByIDX(), objDef_t::isReloadable(), equipDef_t::numItems, Q_strstart(), and objDef_t::weapon.

Referenced by INV_InitStartup().

◆ INV_GetEquipmentDefinitionByID()

const equipDef_t * INV_GetEquipmentDefinitionByID ( const char * name)

Gets equipment definition by id.

Parameters
[in]nameAn id taken from scripts.
Returns
Found equipDef_t or nullptr if no equipment definition found.

Definition at line 39 of file cl_inventory.cpp.

References Com_Error(), csi, ERR_DROP, i, equipDef_t::id, name, and Q_streq.

Referenced by GAME_AutoTeam(), GAME_ChangeEquip(), GAME_GetCGameAPI(), GAME_GetEquipment(), GAME_GetImportData(), and GAME_Spawn().

◆ INV_GetFilterFromItem()

◆ INV_GetFilterType()

const char * INV_GetFilterType ( itemFilterTypes_t id)
Parameters
[in]idThe filter type index

Definition at line 419 of file cl_inventory.cpp.

References filterTypeNames, id, and MAX_FILTERTYPES.

Referenced by GAME_GetImportData().

◆ INV_GetFilterTypeID()

itemFilterTypes_t INV_GetFilterTypeID ( const char * filterTypeID)

Searches for a filter type name (as used in console functions) and returns the matching itemFilterTypes_t enum.

Parameters
[in]filterTypeIDFilter type name so search for.
See also
filterTypeNames.

Definition at line 397 of file cl_inventory.cpp.

References FILTER_S_PRIMARY, filterTypeNames, i, MAX_FILTERTYPES, and Q_streq.

Referenced by GAME_GetImportData(), and cgame_import_t::itemFilterTypes_t().

◆ INV_InitStartup()

void INV_InitStartup ( void )

Definition at line 425 of file cl_inventory.cpp.

References Cmd_AddCommand(), INV_EquipmentDefSanityCheck(), and INV_InitCallbacks().

Referenced by CL_InitLocal().

◆ INV_ItemMatchesFilter()

bool INV_ItemMatchesFilter ( const objDef_t * obj,
const itemFilterTypes_t filterType )

◆ INV_LoadWeapon()

bool INV_LoadWeapon ( const Item * weaponList,
Inventory * inv,
const invDef_t * srcContainer,
const invDef_t * destContainer )

Load a weapon with ammo.

Parameters
[in]weaponListPointer to weapon to load.
[in]invPointer to inventory where the change happen.
[in]srcContainerPointer to inventorydef where to search ammo.
[in]destContainerPointer to inventorydef where the weapon is.

Definition at line 99 of file cl_inventory.cpp.

References objDef_t::ammo, objDef_t::ammos, Item::def(), Item::getFirstShapePosition(), Inventory::getItemAtPos(), Item::getX(), Item::getY(), i, INV_GetFilterFromItem(), INV_MoveItem(), INV_SearchInInventoryWithFilter(), objDef_t::isReloadable(), objDef_t::numAmmos, Item::setAmmoDef(), Item::setAmmoLeft(), and objDef_t::weapons.

Referenced by uiContainerNode::onDndFinished(), and UI_ContainerNodeAutoPlaceItem().

◆ INV_MoveItem()

bool INV_MoveItem ( Inventory * inv,
const invDef_t * toContainer,
int toX,
int toY,
const invDef_t * fromContainer,
Item * fItem,
Item ** uponItem )

Move item between containers.

Parameters
[in]invPointer to the inventory we are working on.
[in]toContainerPointer to target container, to place the item in.
[in]toXtarget x position in the toContainer container.
[in]toYtarget y position in the toContainer container.
[in]fromContainerPointer to source container, the item is in.
[in]fItemPointer to item being moved.
[out]uponItemThe item the moving item is eventually dropped upon.
Note
If you set toX or toY to -1/NONE the item is automatically placed on
a free spot in the targetContainer
Returns
true if the move was successful.

Definition at line 63 of file cl_inventory.cpp.

References _, Inventory::canHoldItemWeight(), cls, GAME_GetChrMaxLoad(), GAME_GetSelectedChr(), IA_ARMOUR, IA_MOVE, IA_RELOAD, IA_RELOAD_SWAP, invDef_t::id, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, and UI_Popup().

Referenced by INV_LoadWeapon(), uiContainerNode::onDndFinished(), UI_ContainerNodeAddItem(), and UI_ContainerNodeAutoPlaceItem().

◆ INV_SearchInInventoryWithFilter()

Item * INV_SearchInInventoryWithFilter ( const Inventory *const inv,
const invDef_t * container,
const objDef_t * itemType,
const itemFilterTypes_t filterType )

Searches if there is an item at location (x/y) in a scrollable container. You can also provide an item to search for directly (x/y is ignored in that case).

Note
x = x-th item in a row, y = row. i.e. x/y does not equal the "grid" coordinates as used in those containers.
Parameters
[in]invPointer to the inventory where we will search.
[in]containerContainer in the inventory.
[in]itemTypeThe item to search. Will ignore "x" and "y" if set, it'll also search invisible items.
[in]filterTypeEnum definition of type (types of items for filtering purposes).
Returns
Item Pointer to the Item/item that is located at x/y or equals "item".
See also
Inventory::getItemAtPos

Definition at line 357 of file cl_inventory.cpp.

References Inventory::getContainer2(), Item::getNext(), invDef_t::id, INV_ItemMatchesFilter(), and MAX_FILTERTYPES.

Referenced by INV_LoadWeapon(), uiContainerNode::onDndFinished(), and UI_ContainerNodeGetExistingItem().

◆ INV_UnloadWeapon()

bool INV_UnloadWeapon ( Item * weapon,
Inventory * inv,
const invDef_t * container )

Unload a weapon and put the ammo in a container.

Parameters
[in,out]weaponThe weapon to unload ammo.
[in,out]invinventory where the change happen.
[in]containerInventory definition where to put the removed ammo.
Returns
true if the ammo was moved to the container, false otherwise

Definition at line 136 of file cl_inventory.cpp.

References Item::ammoDef(), cls, Item::def(), Item::getAmmoLeft(), NONE, Item::setAmmoDef(), and Item::setAmmoLeft().

Referenced by uiContainerNode::onDndFinished(), and UI_ContainerNodeAutoPlaceItem().

Variable Documentation

◆ filterTypeNames

char const* const filterTypeNames[]
static
Initial value:
= {
"primary",
"secondary",
"heavy",
"misc",
"armour",
"implant",
"",
"craftitem",
"ugvitem",
"aircraft",
"dummy",
"disassembly"
}

Names of the filter types as used in console function. e.g. in .ufo files.

See also
inv_shared.h:itemFilterTypes_t

Definition at line 377 of file cl_inventory.cpp.

Referenced by CASSERT(), INV_GetFilterType(), and INV_GetFilterTypeID().