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

#include <inventory.h>

Collaboration diagram for InventoryInterface:
Collaboration graph

Public Member Functions

 InventoryInterface ()
void initInventory (const char *name, const csi_t *csi, const inventoryImport_t *import)
 Initializes the inventory definition by linking the ->next pointers properly.
bool removeFromInventory (Inventory *const inv, const invDef_t *container, Item *fItem) __attribute__((warn_unused_result))
ItemaddToInventory (Inventory *const inv, const Item *const item, const invDef_t *container, int x, int y, int amount) __attribute__((warn_unused_result))
 Add an item to a specified container in a given inventory.
inventory_action_t moveInInventory (Inventory *const inv, const invDef_t *from, Item *item, const invDef_t *to, int tx, int ty, int *TU, Item **icp)
 Conditions for moving items between containers.
bool tryAddToInventory (Inventory *const inv, const Item *const item, const invDef_t *container)
 Tries to add an item to a container (in the inventory inv).
void destroyInventory (Inventory *const inv)
 Destroys inventory.
void destroyInventoryInterface (void)
void emptyContainer (Inventory *const inv, const containerIndex_t container)
 Clears the linked list of a container - removes all items from this container.
void EquipActor (character_t *const chr, const equipDef_t *ed, const objDef_t *weapon, int maxWeight)
void EquipActorNormal (character_t *const chr, const equipDef_t *ed, int maxWeight)
 Fully equip one actor. The equipment that is added to the inventory of the given actor is taken from the equipment script definition.
void EquipActorMelee (Inventory *const inv, const teamDef_t *td)
 Equip melee actor with item defined per teamDefs.
void EquipActorRobot (Inventory *const inv, const objDef_t *weapon)
 Equip robot actor with default weapon. (defined in ugv_t->weapon).
int GetUsedSlots ()
 Calculate the number of used inventory slots.

Protected Member Functions

voidalloc (size_t size)
void free (void *data)
void removeInvList (Item *invList)
ItemaddInvList (Inventory *const inv, const invDef_t *container)
float GetInventoryState (const Inventory *inventory, int &slowestFd)
 Get the state of the given inventory: the items weight and the min TU needed to make full use of all the items.
int PackAmmoAndWeapon (character_t *const chr, const objDef_t *weapon, int missedPrimary, const equipDef_t *ed, int maxWeight)
 Pack a weapon, possibly with some ammo.

Private Attributes

const inventoryImport_timport
Item_invList
Item cacheItem
const csi_tcsi
const char * invName

Detailed Description

Definition at line 40 of file inventory.h.

Constructor & Destructor Documentation

◆ InventoryInterface()

InventoryInterface::InventoryInterface ( )

Definition at line 27 of file inventory.cpp.

References _invList, csi, import, invName, and nullptr.

Member Function Documentation

◆ addInvList()

Item * InventoryInterface::addInvList ( Inventory *const inv,
const invDef_t * container )
protected

◆ addToInventory()

Item * InventoryInterface::addToInventory ( Inventory *const inv,
const Item *const item,
const invDef_t * container,
int x,
int y,
int amount )

Add an item to a specified container in a given inventory.

Note
Set x and y to NONE if the item should get added to an automatically chosen free spot in the container.
Parameters
[in,out]invPointer to inventory definition, to which we will add item.
[in]itemItem to add to given container (needs to have "rotated" tag already set/checked, this is NOT checked here!)
[in]containerContainer in given inventory definition, where the new item will be stored.
[in]x,yThe location in the container.
[in]amountHow many items of this type should be added. (this will overwrite the amount as defined in "item.amount")
See also
removeFromInventory
Returns
the Item pointer the item was added to, or nullptr in case of an error (item wasn't added)

Definition at line 91 of file inventory.cpp.

References Item::addAmount(), addInvList(), Inventory::canHoldItem(), Com_DPrintf(), DEBUG_SHARED, Item::def(), Inventory::findSpace(), Item::getAmount(), Inventory::getContainer2(), Item::getNext(), invDef_t::id, INV_FITS_ONLY_ROTATED, invName, Item::isSameAs(), objDef_t::name, NONE, Item::rotated, Item::setAmount(), Item::setNext(), Item::setX(), Item::setY(), SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, invDef_t::single, and invDef_t::temp.

Referenced by moveInInventory(), and tryAddToInventory().

◆ alloc()

void * InventoryInterface::alloc ( size_t size)
inlineprotected

Definition at line 75 of file inventory.h.

Referenced by addInvList().

◆ destroyInventory()

void InventoryInterface::destroyInventory ( Inventory *const inv)

Destroys inventory.

Parameters
[in]invPointer to the inventory which should be erased.
Note
Loops through all containers in inventory. nullptr for temp containers are skipped, for real containers emptyContainer is called.
See also
emptyContainer

Definition at line 521 of file inventory.cpp.

References emptyContainer(), Inventory::getNextCont(), Container::id, and Inventory::init().

◆ destroyInventoryInterface()

void InventoryInterface::destroyInventoryInterface ( void )

Definition at line 997 of file inventory.cpp.

References initInventory().

◆ emptyContainer()

void InventoryInterface::emptyContainer ( Inventory *const inv,
const containerIndex_t containerId )

Clears the linked list of a container - removes all items from this container.

Parameters
[in]invThe inventory where the container is located.
[in]containerIdIndex of the container which will be cleared.
See also
destroyInventory
Note
This should only be called for temp containers if the container is really a temp container e.g. the container of a dropped weapon in tactical mission (ET_ITEM) in every other case just set the pointer to nullptr for a temp container like CID_EQUIP or CID_FLOOR

Definition at line 501 of file inventory.cpp.

References Inventory::getContainer2(), Item::getNext(), removeInvList(), and Inventory::resetContainer().

Referenced by destroyInventory().

◆ EquipActor()

◆ EquipActorMelee()

void InventoryInterface::EquipActorMelee ( Inventory *const inv,
const teamDef_t * td )

Equip melee actor with item defined per teamDefs.

Parameters
[in]invThe inventory that will get the weapon.
[in]tdPointer to a team definition.
Note
Weapons assigned here cannot be collected in any case. These are dummy "actor weapons".

Definition at line 682 of file inventory.cpp.

References CID_RIGHT, csi, Item::def(), objDef_t::fireTwoHanded, objDef_t::id, teamDef_t::id, invName, NONE_AMMO, teamDef_t::onlyWeapon, Item::setAmmoDef(), Item::setAmmoLeft(), Sys_Error(), and tryAddToInventory().

Referenced by EquipActor().

◆ EquipActorNormal()

void InventoryInterface::EquipActorNormal ( character_t *const chr,
const equipDef_t * ed,
int maxWeight )

Fully equip one actor. The equipment that is added to the inventory of the given actor is taken from the equipment script definition.

Parameters
[in]chrThe character that will get the weapon.
[in]edThe equipment that is added from to the actors inventory
[in]maxWeightThe max weight this actor is allowed to carry.
Note
The code below is a complete implementation of the scheme sketched at the beginning of equipment_missions.ufo. Beware: If two weapons in the same category have the same price, only one will be considered for inventory.

< If actor has a primary weapon, this is zero. Otherwise, this is the probability * 100 that the actor had to get a primary weapon (used to compensate the lack of primary weapon)

Definition at line 741 of file inventory.cpp.

References ABILITY_POWER, ABILITY_SPEED, objDef_t::ammo, teamDef_t::armour, CID_ARMOUR, CID_BACKPACK, CID_HEADGEAR, CID_IMPLANT, Com_DPrintf(), csi, DEBUG_SHARED, objDef_t::deplete, objDef_t::fireTwoHanded, frand(), GET_ENCUMBRANCE_PENALTY, GET_TU, GetInventoryState(), Item::getSlowestFireDef(), Item::getWeight(), i, equipDef_t::id, objDef_t::id, objDef_t::idx, character_t::inv, invName, INVSH_GetItemByIDX(), objDef_t::isArmour(), objDef_t::isMisc, objDef_t::isPrimary, objDef_t::isReloadable(), objDef_t::isSecondary, lengthof, teamDef_t::name, NONE_AMMO, equipDef_t::numItems, objDef_t::oneshot, PackAmmoAndWeapon(), objDef_t::price, character_t::score, chrScoreGlobal_t::skills, character_t::teamDef, fireDef_t::time, tryAddToInventory(), objDef_t::weapon, WEAPON_NO_PRIMARY, WEAPON_OTHER, WEAPON_PARTICLE_OR_NORMAL, WEAPONLESS_BONUS, teamDef_t::weapons, and WEIGHT_FACTOR.

Referenced by EquipActor().

◆ EquipActorRobot()

void InventoryInterface::EquipActorRobot ( Inventory *const inv,
const objDef_t * weapon )

Equip robot actor with default weapon. (defined in ugv_t->weapon).

Parameters
[in]invThe inventory that will get the weapon.
[in]weaponPointer to the item which being added to robot's inventory.

Definition at line 705 of file inventory.cpp.

References objDef_t::ammo, objDef_t::ammos, CID_RIGHT, csi, objDef_t::numAmmos, Item::setAmmoDef(), Item::setAmmoLeft(), and tryAddToInventory().

Referenced by EquipActor().

◆ free()

void InventoryInterface::free ( void * data)
inlineprotected

Definition at line 80 of file inventory.h.

References data.

Referenced by removeInvList().

◆ GetInventoryState()

float InventoryInterface::GetInventoryState ( const Inventory * inventory,
int & slowestFd )
protected

Get the state of the given inventory: the items weight and the min TU needed to make full use of all the items.

Parameters
[in]inventoryThe pointer to the inventory to evaluate.
[out]slowestFdThe TU needed to use the slowest fireDef in the inventory.
Note
temp containers are excluded.

Definition at line 540 of file inventory.cpp.

References Container::_invList, Inventory::getNextCont(), Inventory::getWeight(), and fireDef_t::time.

Referenced by EquipActorNormal(), and PackAmmoAndWeapon().

◆ GetUsedSlots()

int InventoryInterface::GetUsedSlots ( )

Calculate the number of used inventory slots.

Returns
The number of free inventory slots

Definition at line 966 of file inventory.cpp.

References _invList, Com_DPrintf(), DEBUG_SHARED, Item::getNext(), i, and invName.

◆ initInventory()

void InventoryInterface::initInventory ( const char * name,
const csi_t * csi,
const inventoryImport_t * import )

Initializes the inventory definition by linking the ->next pointers properly.

Parameters
[in]nameThe name that is shown in the output
[in]csiThe client-server-information structure
[in]importPointers to the lifecycle functions
See also
G_Init
CL_InitLocal

Definition at line 986 of file inventory.cpp.

References _invList, cacheItem, csi, invName, and name.

Referenced by destroyInventoryInterface().

◆ moveInInventory()

inventory_action_t InventoryInterface::moveInInventory ( Inventory *const inv,
const invDef_t * from,
Item * fItem,
const invDef_t * to,
int tx,
int ty,
int * TU,
Item ** uponItem )

Conditions for moving items between containers.

Parameters
[in]invThe inventory to move in.
[in]fromSource container.
[in]fItemThe item to be moved.
[in]toDestination container.
[in]txX coordinate in destination container.
[in]tyY coordinate in destination container.
[in,out]TUpointer to entity available TU at this moment or nullptr if TU doesn't matter (outside battlescape)
[out]uponItemThe item fItem is evetually dropped upon
Returns
IA_NOTIME when not enough TU.
IA_NONE if no action possible.
IA_NORELOAD if you cannot reload a weapon.
IA_RELOAD_SWAP in case of exchange of ammo in a weapon.
IA_RELOAD when reloading.
IA_ARMOUR when placing an armour on the actor.
IA_MOVE when just moving an item.
Todo
change the other code to browse through these things.

Definition at line 239 of file inventory.cpp.

References addToInventory(), objDef_t::ammo, Item::ammoDef(), invDef_t::armour, cacheItem, Inventory::canHoldItem(), CID_RIGHT, Com_DPrintf(), Com_Printf(), csi, DEBUG_SHARED, Item::def(), Inventory::findSpace(), objDef_t::fireTwoHanded, Item::getAmmoLeft(), Item::getAmount(), Inventory::getContainer(), Inventory::getItemAtPos(), Container::getNextItem(), objDef_t::getReloadTime(), Item::getX(), Item::getY(), invDef_t::headgear, objDef_t::headgear, IA_ARMOUR, IA_MOVE, IA_NONE, IA_NORELOAD, IA_NOTIME, IA_RELOAD, IA_RELOAD_SWAP, invDef_t::id, invDef_t::implant, objDef_t::implant, invDef_t::in, INV_DOES_NOT_FIT, INV_FITS, INV_FITS_BOTH, INV_FITS_ONLY_ROTATED, invName, Item::isArmour(), invDef_t::isArmourDef(), invDef_t::isEquipDef(), invDef_t::isFloorDef(), invDef_t::isLeftDef(), objDef_t::isLoadableInWeapon(), invDef_t::isRightDef(), moveInInventory(), NONE, invDef_t::out, removeFromInventory(), Item::rotated, invDef_t::scroll, Item::setAmmoDef(), Item::setAmmoLeft(), Item::setX(), Item::setY(), invDef_t::single, Sys_Error(), and invDef_t::temp.

Referenced by moveInInventory().

◆ PackAmmoAndWeapon()

int InventoryInterface::PackAmmoAndWeapon ( character_t *const chr,
const objDef_t * weapon,
int missedPrimary,
const equipDef_t * ed,
int maxWeight )
protected

Pack a weapon, possibly with some ammo.

Parameters
[in]chrThe character that will get the weapon
[in]weaponThe weapon type index in gi.csi->ods
[in]edThe equipment for debug messages
[in]missedPrimaryif actor didn't get primary weapon, this is 0-100 number to increase ammo number.
[in]maxWeightThe max weight this actor is allowed to carry.
See also
isLoadableInWeapon()

Definition at line 566 of file inventory.cpp.

References ABILITY_POWER, ABILITY_SPEED, objDef_t::ammo, Item::ammoDef(), CID_BACKPACK, CID_BELT, CID_HOLSTER, CID_LEFT, CID_RIGHT, Com_DPrintf(), Com_Printf(), csi, DEBUG_SHARED, Item::def(), objDef_t::fireTwoHanded, GET_ENCUMBRANCE_PENALTY, GET_TU, Inventory::getContainer2(), GetInventoryState(), Item::getWeight(), i, equipDef_t::id, objDef_t::id, objDef_t::idx, character_t::inv, invName, INVSH_GetItemByIDX(), objDef_t::isArmour(), objDef_t::isLoadableInWeapon(), objDef_t::isReloadable(), equipDef_t::numItems, objDef_t::oneshot, character_t::score, Item::setAmmoDef(), Item::setAmmoLeft(), chrScoreGlobal_t::skills, tryAddToInventory(), and WEIGHT_FACTOR.

Referenced by EquipActorNormal().

◆ removeFromInventory()

bool InventoryInterface::removeFromInventory ( Inventory *const inv,
const invDef_t * container,
Item * fItem )
Parameters
[in]invThe inventory the container is in.
[in]containerThe container where the item should be removed.
[in]fItemThe item to be removed.
Returns
true If removal was successful.
false If nothing was removed or an error occurred.
See also
addToInventory
Todo
the problem here is, that in case of a move inside the same container the item don't just get updated x and y values but it is tried to remove one of the items => crap - maybe we have to change the inventory move function to check for this case of move and only update the x and y coordinates instead of calling the add and remove functions

Definition at line 152 of file inventory.cpp.

References Item::addAmount(), cacheItem, Com_DPrintf(), Com_Printf(), DEBUG_SHARED, Item::def(), Item::getAmount(), Inventory::getContainer2(), Item::getNext(), invDef_t::id, invName, invDef_t::name, objDef_t::name, removeInvList(), Inventory::setContainer(), invDef_t::single, and invDef_t::temp.

Referenced by moveInInventory().

◆ removeInvList()

void InventoryInterface::removeInvList ( Item * invList)
protected

◆ tryAddToInventory()

bool InventoryInterface::tryAddToInventory ( Inventory *const inv,
const Item *const item,
const invDef_t * container )

Tries to add an item to a container (in the inventory inv).

Parameters
[in]invThe inventory to add the item to.
[in]itemItem to add to inventory (actually a copy of it).
[in]containerContainer id.
See also
findSpace
addToInventory

Definition at line 470 of file inventory.cpp.

References addToInventory(), Inventory::canHoldItem(), Item::def(), Inventory::findSpace(), INV_FITS_ONLY_ROTATED, NONE, and Item::rotated.

Referenced by EquipActorMelee(), EquipActorNormal(), EquipActorRobot(), and PackAmmoAndWeapon().

Field Documentation

◆ _invList

Item* InventoryInterface::_invList
private

Definition at line 43 of file inventory.h.

Referenced by GetUsedSlots(), initInventory(), InventoryInterface(), and removeInvList().

◆ cacheItem

Item InventoryInterface::cacheItem
private

Definition at line 44 of file inventory.h.

Referenced by initInventory(), moveInInventory(), and removeFromInventory().

◆ csi

const csi_t* InventoryInterface::csi
private

◆ import

const inventoryImport_t* InventoryInterface::import
private

Definition at line 42 of file inventory.h.

Referenced by InventoryInterface().

◆ invName


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