UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_inventory.h File Reference

Header file for inventory handling and Equipment menu. More...

Go to the source code of this file.

Enumerations

enum  itemFilterTypes_t {
  FILTER_S_PRIMARY, FILTER_S_SECONDARY, FILTER_S_HEAVY, FILTER_S_MISC,
  FILTER_S_ARMOUR, FILTER_S_IMPLANT, MAX_SOLDIER_FILTERTYPES, FILTER_CRAFTITEM,
  FILTER_UGVITEM, FILTER_AIRCRAFT, FILTER_DUMMY, FILTER_DISASSEMBLY,
  MAX_FILTERTYPES, FILTER_ENSURE_32BIT = 0x7FFFFFFF
}
 A list of filter types in the market and production view. More...
 

Functions

bool INV_MoveItem (Inventory *inv, const invDef_t *toContainer, int px, int py, const invDef_t *fromContainer, Item *fItem, Item **tItem)
 Move item between containers. More...
 
bool INV_LoadWeapon (const Item *weapon, Inventory *inv, const invDef_t *srcContainer, const invDef_t *destContainer)
 Load a weapon with ammo. More...
 
bool INV_UnloadWeapon (Item *weapon, Inventory *inv, const invDef_t *container)
 Unload a weapon and put the ammo in a container. More...
 
const equipDef_tINV_GetEquipmentDefinitionByID (const char *name)
 Gets equipment definition by id. More...
 
void INV_InitStartup (void)
 
itemFilterTypes_t INV_GetFilterFromItem (const objDef_t *obj)
 
const char * INV_GetFilterType (itemFilterTypes_t id)
 
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. More...
 
bool INV_ItemMatchesFilter (const objDef_t *obj, const itemFilterTypes_t filterType)
 Checks if the given object/item matched the given filter type. More...
 
ItemINV_SearchInInventoryWithFilter (const Inventory *const i, const invDef_t *container, const objDef_t *item, const itemFilterTypes_t filterType) __attribute__((nonnull(1)))
 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). More...
 
void INV_ItemDescription (const objDef_t *od)
 Prints the description for items (weapons, armour, ...) More...
 

Detailed Description

Header file for inventory handling and Equipment menu.

Definition in file cl_inventory.h.

Enumeration Type Documentation

A list of filter types in the market and production view.

Note
Run-time only, please do not use this in savegame/structures and the like. Please also do not use hardcoded numbers to access this (e.g. in a .ufo script).
See also
inv_shared.c:INV_ItemMatchesFilter
inv_shared.c:INV_GetFilterTypeID
Enumerator
FILTER_S_PRIMARY 

All 'Primary' weapons and their ammo for soldiers (Except for heavy weapons).

FILTER_S_SECONDARY 

All 'Secondary' weapons and their ammo for soldiers.

FILTER_S_HEAVY 

Heavy weapons for soldiers.

FILTER_S_MISC 

Misc. soldier equipment (i.e. everything else that is not in the other soldier-item filters)

FILTER_S_ARMOUR 

Armour for soldiers.

FILTER_S_IMPLANT 

Implants

MAX_SOLDIER_FILTERTYPES 
FILTER_CRAFTITEM 

Aircraft equipment.

FILTER_UGVITEM 

Heavy equipment like tanks (i.e. these are actually employees) and their parts. Some of the content are special normal items (like for soldiers). The UGVs themself are specially handled.

FILTER_AIRCRAFT 

Aircrafts.

FILTER_DUMMY 

Everything that is not in any of the other filter types. Mostly plot-relevant stuff, unproducible stuff and stuff.

FILTER_DISASSEMBLY 
MAX_FILTERTYPES 
FILTER_ENSURE_32BIT 

Definition at line 35 of file cl_inventory.h.

Function Documentation

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, csi_s::eds, ERR_DROP, i, equipDef_s::id, csi_s::numEDs, and Q_streq.

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

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

Definition at line 419 of file cl_inventory.cpp.

References MAX_FILTERTYPES.

Referenced by GAME_GetImportData().

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, i, MAX_FILTERTYPES, and Q_streq.

Referenced by GAME_GetImportData().

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

void INV_ItemDescription ( const objDef_t od)
bool INV_ItemMatchesFilter ( const objDef_t obj,
const itemFilterTypes_t  filterType 
)

Checks if the given object/item matched the given filter type.

Parameters
[in]objA pointer to an objDef_t item.
[in]filterTypeFilter type to check against.
Returns
true if obj is in filterType
Todo:
Should we handle FILTER_AIRCRAFT here as well?
Todo:
I guess we should search for components matching this item here.

Definition at line 268 of file cl_inventory.cpp.

References Com_Printf(), FILTER_AIRCRAFT, FILTER_CRAFTITEM, FILTER_DISASSEMBLY, FILTER_DUMMY, FILTER_ENSURE_32BIT, FILTER_S_ARMOUR, FILTER_S_HEAVY, FILTER_S_IMPLANT, FILTER_S_MISC, FILTER_S_PRIMARY, FILTER_S_SECONDARY, FILTER_UGVITEM, i, objDef_s::implant, INV_ItemMatchesFilter(), objDef_s::isArmour(), objDef_s::isCraftItem(), objDef_s::isDummy, objDef_s::isHeavy, objDef_s::isMisc, objDef_s::isPrimary, objDef_s::isSecondary, objDef_s::isUGVitem, MAX_FILTERTYPES, MAX_SOLDIER_FILTERTYPES, objDef_s::numWeapons, Q_streq, objDef_s::type, and objDef_s::weapons.

Referenced by GAME_GetImportData(), INV_EquipmentDefSanityCheck(), INV_ItemMatchesFilter(), INV_SearchInInventoryWithFilter(), and UI_ContainerItemIteratorNext().

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_s::ammo, objDef_s::ammos, Item::def(), Item::getFirstShapePosition(), Inventory::getItemAtPos(), Item::getX(), Item::getY(), i, INV_GetFilterFromItem(), INV_MoveItem(), INV_SearchInInventoryWithFilter(), objDef_s::isReloadable(), objDef_s::numAmmos, Item::setAmmoDef(), Item::setAmmoLeft(), and objDef_s::weapons.

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

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(), client_static_s::i, IA_ARMOUR, IA_MOVE, IA_RELOAD, IA_RELOAD_SWAP, invDef_s::id, InventoryInterface::moveInInventory(), SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, and UI_Popup().

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

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_s::id, INV_ItemMatchesFilter(), and MAX_FILTERTYPES.

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

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 InventoryInterface::addToInventory(), Item::ammoDef(), cls, Item::def(), Item::getAmmoLeft(), client_static_s::i, NONE, Item::setAmmoDef(), and Item::setAmmoLeft().

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