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);
249 cgi->LIST_Add(&this->
cargo, (
void*)cargoItem,
sizeof(*cargoItem));
virtual ~ItemCargo(void)
Destroys ItemCargo with it's internal data.
int size(void) const
Calculate size of all items in the cargo.
void empty(void)
Empties the cargo.
bool load(xmlNode_t *root)
Load item cargo from xml savegame.
ItemCargo(void)
Creates and initializes ItemCargo object.
bool save(xmlNode_t *root) const
Save item cargo to xml savegame.
bool isEmpty(void) const
Checks if the cargo is empty.
int count(void) const
Count all items in the cargo.
itemCargo_t * get(const objDef_t *od) const
Returns a cargo item by its object definition.
int getLooseAmount(const objDef_t *od) const
Returns amount of loose item in the cargo.
linkedList_t * list(void) const
Returns a copy of the cargo list.
virtual bool add(const objDef_t *od, int amount, int looseAmount)
Add items to the cargo.
int getAmount(const objDef_t *od) const
Returns amount of an item in the cargo.
const cgame_import_t * cgi
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
#define SAVE_ITEMCARGO_ITEM
#define SAVE_ITEMCARGO_LOOSEAMOUNT
#define SAVE_ITEMCARGO_AMOUNT
#define SAVE_ITEMCARGO_ITEMID
#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 ...
Defines all attributes of objects used in the inventory.