|
UFO: Alien Invasion
|
#include <inventory.h>

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)) |
| Item * | addToInventory (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 | |
| void * | alloc (size_t size) |
| void | free (void *data) |
| void | removeInvList (Item *invList) |
| Item * | addInvList (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_t * | import |
| Item * | _invList |
| Item | cacheItem |
| const csi_t * | csi |
| const char * | invName |
Definition at line 40 of file inventory.h.
| InventoryInterface::InventoryInterface | ( | ) |
|
protected |
Definition at line 57 of file inventory.cpp.
References alloc(), Com_DPrintf(), DEBUG_SHARED, Inventory::getContainer2(), Item::getNext(), invDef_t::id, invName, Inventory::setContainer(), and Item::setNext().
Referenced by 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.
| [in,out] | inv | Pointer to inventory definition, to which we will add item. |
| [in] | item | Item to add to given container (needs to have "rotated" tag already set/checked, this is NOT checked here!) |
| [in] | container | Container in given inventory definition, where the new item will be stored. |
| [in] | x,y | The location in the container. |
| [in] | amount | How many items of this type should be added. (this will overwrite the amount as defined in "item.amount") |
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().
|
inlineprotected |
Definition at line 75 of file inventory.h.
Referenced by addInvList().
Destroys inventory.
| [in] | inv | Pointer to the inventory which should be erased. |
nullptr for temp containers are skipped, for real containers emptyContainer is called. Definition at line 521 of file inventory.cpp.
References emptyContainer(), Inventory::getNextCont(), Container::id, and Inventory::init().
Definition at line 997 of file inventory.cpp.
References initInventory().
| void InventoryInterface::emptyContainer | ( | Inventory *const | inv, |
| const containerIndex_t | containerId ) |
Clears the linked list of a container - removes all items from this container.
| [in] | inv | The inventory where the container is located. |
| [in] | containerId | Index of the container which will be cleared. |
Definition at line 501 of file inventory.cpp.
References Inventory::getContainer2(), Item::getNext(), removeInvList(), and Inventory::resetContainer().
Referenced by destroyInventory().
| void InventoryInterface::EquipActor | ( | character_t *const | chr, |
| const equipDef_t * | ed, | ||
| const objDef_t * | weapon, | ||
| int | maxWeight ) |
Definition at line 947 of file inventory.cpp.
References Com_Printf(), EquipActorMelee(), EquipActorNormal(), EquipActorRobot(), objDef_t::fireTwoHanded, objDef_t::id, character_t::inv, objDef_t::numAmmos, teamDef_t::robot, character_t::teamDef, and teamDef_t::weapons.
Equip melee actor with item defined per teamDefs.
| [in] | inv | The inventory that will get the weapon. |
| [in] | td | Pointer to a team definition. |
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().
| 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.
| [in] | chr | The character that will get the weapon. |
| [in] | ed | The equipment that is added from to the actors inventory |
| [in] | maxWeight | The max weight this actor is allowed to carry. |
< 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().
Equip robot actor with default weapon. (defined in ugv_t->weapon).
| [in] | inv | The inventory that will get the weapon. |
| [in] | weapon | Pointer 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().
|
protected |
Get the state of the given inventory: the items weight and the min TU needed to make full use of all the items.
| [in] | inventory | The pointer to the inventory to evaluate. |
| [out] | slowestFd | The TU needed to use the slowest fireDef in the inventory. |
Definition at line 540 of file inventory.cpp.
References Container::_invList, Inventory::getNextCont(), Inventory::getWeight(), and fireDef_t::time.
Referenced by EquipActorNormal(), and PackAmmoAndWeapon().
| int InventoryInterface::GetUsedSlots | ( | ) |
Calculate the number of used inventory slots.
Definition at line 966 of file inventory.cpp.
References _invList, Com_DPrintf(), DEBUG_SHARED, Item::getNext(), i, and invName.
| void InventoryInterface::initInventory | ( | const char * | name, |
| const csi_t * | csi, | ||
| const inventoryImport_t * | import ) |
Initializes the inventory definition by linking the ->next pointers properly.
| [in] | name | The name that is shown in the output |
| [in] | csi | The client-server-information structure |
| [in] | import | Pointers to the lifecycle functions |
Definition at line 986 of file inventory.cpp.
References _invList, cacheItem, csi, invName, and name.
Referenced by destroyInventoryInterface().
| 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.
| [in] | inv | The inventory to move in. |
| [in] | from | Source container. |
| [in] | fItem | The item to be moved. |
| [in] | to | Destination container. |
| [in] | tx | X coordinate in destination container. |
| [in] | ty | Y coordinate in destination container. |
| [in,out] | TU | pointer to entity available TU at this moment or nullptr if TU doesn't matter (outside battlescape) |
| [out] | uponItem | The item fItem is evetually dropped upon |
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().
|
protected |
Pack a weapon, possibly with some ammo.
| [in] | chr | The character that will get the weapon |
| [in] | weapon | The weapon type index in gi.csi->ods |
| [in] | ed | The equipment for debug messages |
| [in] | missedPrimary | if actor didn't get primary weapon, this is 0-100 number to increase ammo number. |
| [in] | maxWeight | The max weight this actor is allowed to carry. |
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().
| bool InventoryInterface::removeFromInventory | ( | Inventory *const | inv, |
| const invDef_t * | container, | ||
| Item * | fItem ) |
| [in] | inv | The inventory the container is in. |
| [in] | container | The container where the item should be removed. |
| [in] | fItem | The item to be removed. |
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().
Definition at line 32 of file inventory.cpp.
References _invList, Com_DPrintf(), DEBUG_SHARED, free(), Item::getNext(), invName, and Item::setNext().
Referenced by emptyContainer(), and removeFromInventory().
| 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).
| [in] | inv | The inventory to add the item to. |
| [in] | item | Item to add to inventory (actually a copy of it). |
| [in] | container | Container id. |
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().
|
private |
Definition at line 43 of file inventory.h.
Referenced by GetUsedSlots(), initInventory(), InventoryInterface(), and removeInvList().
|
private |
Definition at line 44 of file inventory.h.
Referenced by initInventory(), moveInInventory(), and removeFromInventory().
|
private |
Definition at line 45 of file inventory.h.
Referenced by EquipActorMelee(), EquipActorNormal(), EquipActorRobot(), initInventory(), InventoryInterface(), moveInInventory(), and PackAmmoAndWeapon().
|
private |
Definition at line 42 of file inventory.h.
Referenced by InventoryInterface().
|
private |
Definition at line 46 of file inventory.h.
Referenced by addInvList(), addToInventory(), EquipActorMelee(), EquipActorNormal(), GetUsedSlots(), initInventory(), InventoryInterface(), moveInInventory(), PackAmmoAndWeapon(), removeFromInventory(), and removeInvList().