27 #define SAVE_ITEMCARGO_ITEM "item"
28 #define SAVE_ITEMCARGO_ITEMID "itemid"
29 #define SAVE_ITEMCARGO_AMOUNT "amount"
30 #define SAVE_ITEMCARGO_LOOSEAMOUNT "looseamount"
43 if (amount == 0 && looseAmount == 0)
47 if (item->objDef != od)
50 if (amount + item->amount < 0)
52 if (looseAmount + item->looseAmount < 0)
55 item->amount += amount;
56 item->looseAmount += looseAmount;
57 if (od->
ammo > 0 && item->looseAmount >= od->
ammo) {
58 const int magazine = item->looseAmount / od->
ammo;
59 this->
add(od, magazine, -magazine * od->
ammo);
62 if (item->amount == 0 && item->looseAmount == 0)
63 cgi->LIST_Remove(&this->
cargo, (
void*)item);
68 if (amount < 0 || looseAmount < 0)
71 itemCargo_t cargoItem = { od, amount, looseAmount };
73 if (
cgi->
LIST_Add(&this->cargo, (
const void*)&cargoItem,
sizeof(cargoItem))) {
93 return this->
add(od, amount, looseAmount);
109 return (this->
cargo ==
nullptr);
120 if (item->objDef == od)
161 if (!
cgi->
LIST_Add(&listing, (
void*)item,
sizeof(*item))) {
162 cgi->LIST_Delete(&listing);
176 count += item->amount;
188 size += item->amount * item->objDef->size;
208 if (!
add(objDefId, amount, looseAmount))
209 cgi->Com_Printf(
"ItemCargo::load: Could add items to cargo: %s, %d, %d\n", objDefId, amount, looseAmount);
251 cgi->LIST_Delete(&list);
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
virtual bool add(const objDef_t *od, int amount, int looseAmount)
Add items to the cargo.
int getLooseAmount(const objDef_t *od) const
Returns amount of loose item in the cargo.
#define SAVE_ITEMCARGO_AMOUNT
#define SAVE_ITEMCARGO_LOOSEAMOUNT
#define SAVE_ITEMCARGO_ITEMID
itemCargo_t * get(const objDef_t *od) const
Returns a cargo item by its object definition.
void empty(void)
Empties the cargo.
bool load(xmlNode_t *root)
Load item cargo from xml savegame.
Defines all attributes of objects used in the inventory.
#define SAVE_ITEMCARGO_ITEM
int size(void) const
Calculate size of all items in the cargo.
const cgame_import_t * cgi
bool isEmpty(void) const
Checks if the cargo is empty.
ItemCargo(void)
Creates and initializes ItemCargo object.
virtual ~ItemCargo(void)
Destroys ItemCargo with it's internal data.
int count(void) const
Count all items in the cargo.
xmlNode_t *IMPORT * XML_GetNextNode(xmlNode_t *current, xmlNode_t *parent, const char *name)
bool save(xmlNode_t *root) const
Save item cargo to xml savegame.
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
xmlNode_t *IMPORT * XML_AddNode(xmlNode_t *parent, const char *name)
linkedList_t * list(void) const
Returns a copy of the cargo list.
linkedList_t *IMPORT * LIST_Add(linkedList_t **list, void const *data, size_t length)
const char *IMPORT * XML_GetString(xmlNode_t *parent, const char *name)
xmlNode_t *IMPORT * XML_GetNode(xmlNode_t *parent, const char *name)
int getAmount(const objDef_t *od) const
Returns amount of an item in the cargo.