#include "inventory.h"
Go to the source code of this file.
Defines | |
#define | WEAPONLESS_BONUS 0.4 |
Enumerations | |
enum | equipPrimaryWeaponType_t { WEAPON_PARTICLE_OR_NORMAL = 0, WEAPON_OTHER = 1, WEAPON_NO_PRIMARY = 2 } |
Types of weapon that can be selected. More... | |
Functions | |
static void | I_Free (inventoryInterface_t *self, void *data) |
static void * | I_Alloc (inventoryInterface_t *self, size_t size) |
static void | I_RemoveInvList (inventoryInterface_t *self, invList_t *invList) |
static invList_t * | I_AddInvList (inventoryInterface_t *self, invList_t **invList) |
static invList_t * | I_AddToInventory (inventoryInterface_t *self, inventory_t *const i, item_t item, const invDef_t *container, int x, int y, int amount) |
Add an item to a specified container in a given inventory. | |
static qboolean | I_RemoveFromInventory (inventoryInterface_t *self, inventory_t *const i, const invDef_t *container, invList_t *fItem) |
static int | I_MoveInInventory (inventoryInterface_t *self, inventory_t *const i, const invDef_t *from, invList_t *fItem, const invDef_t *to, int tx, int ty, int *TU, invList_t **icp) |
Conditions for moving items between containers. | |
static qboolean | I_TryAddToInventory (inventoryInterface_t *self, inventory_t *const inv, item_t item, const invDef_t *container) |
Tries to add an item to a container (in the inventory inv). | |
static void | I_EmptyContainer (inventoryInterface_t *self, inventory_t *const i, const invDef_t *container) |
Clears the linked list of a container - removes all items from this container. | |
static void | I_DestroyInventory (inventoryInterface_t *self, inventory_t *const i) |
Destroys inventory. | |
static int | I_PackAmmoAndWeapon (inventoryInterface_t *self, inventory_t *const inv, objDef_t *weapon, int missedPrimary, const equipDef_t *ed) |
Pack a weapon, possibly with some ammo. | |
static void | I_EquipActorMelee (inventoryInterface_t *self, inventory_t *const inv, const teamDef_t *td) |
Equip melee actor with item defined per teamDefs. | |
static void | I_EquipActorRobot (inventoryInterface_t *self, inventory_t *const inv, objDef_t *weapon) |
Equip robot actor with default weapon. (defined in ugv_t->weapon). | |
static void | I_EquipActor (inventoryInterface_t *self, inventory_t *const inv, const equipDef_t *ed, const teamDef_t *td) |
Fully equip one actor. The equipment that is added to the inventory of the given actor is taken from the equipment script definition. | |
static int | I_GetUsedSlots (inventoryInterface_t *self) |
Calculate the number of used inventory slots. | |
void | INV_InitInventory (const char *name, inventoryInterface_t *interface, csi_t *csi, const inventoryImport_t *import) |
Initializes the inventory definition by linking the ->next pointers properly. | |
void | INV_DestroyInventory (inventoryInterface_t *interface) |
#define WEAPONLESS_BONUS 0.4 |
Definition at line 528 of file inventory.c.
Referenced by I_EquipActor().
Types of weapon that can be selected.
WEAPON_PARTICLE_OR_NORMAL |
primary weapon is a particle or normal weapon |
WEAPON_OTHER |
primary weapon is not a particle or normal weapon |
WEAPON_NO_PRIMARY |
no primary weapon |
Definition at line 697 of file inventory.c.
static invList_t* I_AddInvList | ( | inventoryInterface_t * | self, | |
invList_t ** | invList | |||
) | [static] |
Definition at line 37 of file inventory.c.
References Com_DPrintf(), DEBUG_SHARED, I_Alloc(), and invList_s::next.
Referenced by I_AddToInventory().
static invList_t* I_AddToInventory | ( | inventoryInterface_t * | self, | |
inventory_t *const | i, | |||
item_t | item, | |||
const invDef_t * | container, | |||
int | x, | |||
int | y, | |||
int | amount | |||
) | [static] |
Add an item to a specified container in a given inventory.
[in] | i | 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 | The x location in the container. |
[in] | y | The x 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") |
invList_t
pointer the item was added to, or NULL
in case of an error (item wasn't added) What we are doing here. invList_t array looks like that: [u]->next = [w]; [w]->next = [x]; [...]; [z]->next = NULL. i->c[container->id] as well as ic are such invList_t. Now we want to add new item to this container and that means, we need to create some [t] and make sure, that [t]->next points to [u] (so the [t] will be the first in array). ic = i->c[container->id]; So, we are storing old value of i->c[container->id] in ic to remember what was in the original container. If the i->c[container->id]->next pointed to [abc], the ic->next will also point to [abc]. The ic is our [u] and [u]->next still points to our [w]. i->c[container->id] = invUnused; Now we are creating new container - the "original" i->c[container->id] is being set to empty invUnused. This is our [t]. invUnused = invUnused->next; Now we need to make sure, that our [t] will point to next free slot in our inventory. Remember, that invUnused was empty before, so invUnused->next will point to next free slot. i->c[container->id]->next = ic; We assigned our [t]->next to [u] here. Thanks to that we still have the correct ->next chain in our inventory list. ic = i->c[container->id]; And now ic will be our [t], that is the newly added container. After that we can easily add the item (item.t, x and y positions) to our [t] being ic.
Definition at line 74 of file inventory.c.
References item_s::amount, inventory_s::c, Com_DPrintf(), DEBUG_SHARED, I_AddInvList(), invDef_s::id, INVSH_CompareItem(), INVSH_FindSpace(), invList_s::item, objDef_s::name, invList_s::next, NONE, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, invDef_s::single, item_s::t, invDef_s::temp, invList_s::x, and invList_s::y.
Referenced by INV_InitInventory().
static void* I_Alloc | ( | inventoryInterface_t * | self, | |
size_t | size | |||
) | [inline, static] |
Definition at line 8 of file inventory.c.
Referenced by I_AddInvList().
static void I_DestroyInventory | ( | inventoryInterface_t * | self, | |
inventory_t *const | i | |||
) | [static] |
Destroys inventory.
[in] | i | Pointer to the inventory which should be erased. |
NULL
for temp containers are skipped, for real containers I_EmptyContainer
is called. Definition at line 511 of file inventory.c.
References invDef_s::temp.
Referenced by INV_InitInventory().
static void I_EmptyContainer | ( | inventoryInterface_t * | self, | |
inventory_t *const | i, | |||
const invDef_t * | container | |||
) | [static] |
Clears the linked list of a container - removes all items from this container.
[in] | i | The inventory where the container is located. |
[in] | container | Index of the container which will be cleared. |
Definition at line 489 of file inventory.c.
References inventory_s::c, I_RemoveInvList(), invDef_s::id, and invList_s::next.
Referenced by INV_InitInventory().
static void I_EquipActor | ( | inventoryInterface_t * | self, | |
inventory_t *const | inv, | |||
const equipDef_t * | ed, | |||
const teamDef_t * | td | |||
) | [static] |
Fully equip one actor. The equipment that is added to the inventory of the given actor is taken from the equipment script definition.
[in] | inv | The inventory that will get the weapon. |
[in] | ed | The equipment that is added from to the actors inventory |
[in] | td | Pointer to teamdef data - to get the weapon and armour bools. |
< if you got a one-handed secondary weapon (and no primary weapon), this is the chance to get another one (between 0 and 1)
< 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 714 of file inventory.c.
References teamDef_s::armour, Com_DPrintf(), csi, DEBUG_SHARED, objDef_s::deplete, objDef_s::extension, objDef_s::fireTwoHanded, frand(), objDef_s::headgear, i, I_PackAmmoAndWeapon(), objDef_s::id, objDef_s::idx, INV_IsArmour, INVSH_GetItemByIDX(), INVSH_LoadableInWeapon(), objDef_s::isMisc, objDef_s::isPrimary, objDef_s::isSecondary, lengthof, teamDef_s::name, equipDef_s::name, NONE_AMMO, equipDef_s::numItems, csi_s::numODs, objDef_s::price, objDef_s::reload, objDef_s::weapon, WEAPON_NO_PRIMARY, WEAPON_PARTICLE_OR_NORMAL, WEAPONLESS_BONUS, and teamDef_s::weapons.
Referenced by INV_InitInventory().
static void I_EquipActorMelee | ( | inventoryInterface_t * | self, | |
inventory_t *const | inv, | |||
const teamDef_t * | td | |||
) | [static] |
Equip melee actor with item defined per teamDefs.
[in] | inv | The inventory that will get the weapon. |
[in] | chr | Pointer to character data. |
Definition at line 649 of file inventory.c.
References item_s::a, objDef_s::fireTwoHanded, teamDef_s::id, objDef_s::id, item_s::m, NONE_AMMO, teamDef_s::onlyWeapon, Sys_Error(), and item_s::t.
Referenced by INV_InitInventory().
static void I_EquipActorRobot | ( | inventoryInterface_t * | self, | |
inventory_t *const | inv, | |||
objDef_t * | weapon | |||
) | [static] |
Equip robot actor with default weapon. (defined in ugv_t->weapon).
[in] | inv | The inventory that will get the weapon. |
[in] | chr | Pointer to character data. |
[in] | weapon | Pointer to the item which being added to robot's inventory. |
Definition at line 676 of file inventory.c.
References item_s::a, objDef_s::ammos, item_s::m, NONE_AMMO, objDef_s::numAmmos, and item_s::t.
Referenced by INV_InitInventory().
static void I_Free | ( | inventoryInterface_t * | self, | |
void * | data | |||
) | [inline, static] |
Definition at line 3 of file inventory.c.
Referenced by I_RemoveInvList().
static int I_GetUsedSlots | ( | inventoryInterface_t * | self | ) | [static] |
Calculate the number of used inventory slots.
Definition at line 915 of file inventory.c.
References Com_DPrintf(), DEBUG_SHARED, i, and invList_s::next.
Referenced by INV_InitInventory().
static int I_MoveInInventory | ( | inventoryInterface_t * | self, | |
inventory_t *const | i, | |||
const invDef_t * | from, | |||
invList_t * | fItem, | |||
const invDef_t * | to, | |||
int | tx, | |||
int | ty, | |||
int * | TU, | |||
invList_t ** | icp | |||
) | [static] |
Conditions for moving items between containers.
[in] | i | 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 NULL if TU doesn't matter (outside battlescape) |
[out] | icp |
Definition at line 239 of file inventory.c.
References item_s::a, objDef_s::ammo, item_s::amount, invDef_s::armour, inventory_s::c, Com_DPrintf(), DEBUG_SHARED, objDef_s::extension, invDef_s::extension, objDef_s::fireTwoHanded, objDef_s::headgear, invDef_s::headgear, IA_ARMOUR, IA_MOVE, IA_NONE, IA_NORELOAD, IA_NOTIME, IA_RELOAD, IA_RELOAD_SWAP, invDef_s::id, invDef_s::in, INV_DOES_NOT_FIT, INV_FITS, INV_FITS_ONLY_ROTATED, INV_IsArmour, INV_IsArmourDef(), INV_IsEquipDef(), INV_IsFloorDef(), INV_IsLeftDef(), INV_IsRightDef(), INVSH_CheckToInventory(), INVSH_FindSpace(), INVSH_LoadableInWeapon(), INVSH_SearchInInventory(), invList_s::item, item_s::m, invList_s::next, NONE, NONE_AMMO, invDef_s::out, qfalse, qtrue, objDef_s::reload, item_s::rotated, invDef_s::scroll, invDef_s::single, Sys_Error(), item_s::t, invDef_s::temp, invList_s::x, and invList_s::y.
Referenced by INV_InitInventory().
static int I_PackAmmoAndWeapon | ( | inventoryInterface_t * | self, | |
inventory_t *const | inv, | |||
objDef_t * | weapon, | |||
int | missedPrimary, | |||
const equipDef_t * | ed | |||
) | [static] |
Pack a weapon, possibly with some ammo.
[in] | inv | The inventory 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. |
Definition at line 538 of file inventory.c.
References item_s::a, objDef_s::ammo, inventory_s::c, Com_DPrintf(), Com_Printf(), DEBUG_SHARED, objDef_s::fireTwoHanded, i, objDef_s::id, objDef_s::idx, INV_IsArmour, INVSH_GetItemByIDX(), INVSH_LoadableInWeapon(), invList_s::item, item_s::m, equipDef_s::name, NONE_AMMO, equipDef_s::numItems, objDef_s::oneshot, qtrue, objDef_s::reload, and item_s::t.
Referenced by I_EquipActor().
static qboolean I_RemoveFromInventory | ( | inventoryInterface_t * | self, | |
inventory_t *const | i, | |||
const invDef_t * | container, | |||
invList_t * | fItem | |||
) | [static] |
[in] | i | 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.c.
References item_s::amount, inventory_s::c, Com_DPrintf(), Com_Printf(), DEBUG_SHARED, I_RemoveInvList(), invDef_s::id, invList_s::item, invDef_s::name, objDef_s::name, invList_s::next, qfalse, qtrue, invDef_s::single, item_s::t, and invDef_s::temp.
Referenced by INV_InitInventory().
static void I_RemoveInvList | ( | inventoryInterface_t * | self, | |
invList_t * | invList | |||
) | [static] |
Definition at line 13 of file inventory.c.
References Com_DPrintf(), DEBUG_SHARED, I_Free(), and invList_s::next.
Referenced by I_EmptyContainer(), and I_RemoveFromInventory().
static qboolean I_TryAddToInventory | ( | inventoryInterface_t * | self, | |
inventory_t *const | inv, | |||
item_t | item, | |||
const invDef_t * | container | |||
) | [static] |
Tries to add an item to a container (in the inventory inv).
[in] | inv | Inventory pointer to add the item. |
[in] | item | Item to add to inventory. |
[in] | container | Container id. |
Definition at line 458 of file inventory.c.
References INV_FITS_ONLY_ROTATED, INVSH_CheckToInventory(), INVSH_FindSpace(), NONE, qfalse, qtrue, item_s::rotated, and item_s::t.
Referenced by INV_InitInventory().
void INV_DestroyInventory | ( | inventoryInterface_t * | interface | ) |
Definition at line 961 of file inventory.c.
References inventoryImport_s::FreeAll, and inventoryInterface_s::import.
Referenced by GAME_SetMode(), GAME_Spawn(), and ResetInventoryList().
void INV_InitInventory | ( | const char * | name, | |
inventoryInterface_t * | interface, | |||
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,out] | invList | Pointer to invList_t definition being initialized. |
[in] | length | The size of the invList array. |
[out] | interface | The inventory interface pointer which should be initialized in this function. |
Definition at line 937 of file inventory.c.
References inventoryInterface_s::AddToInventory, inventoryInterface_s::cacheItem, inventoryInterface_s::csi, inventoryInterface_s::DestroyInventory, inventoryInterface_s::EmptyContainer, inventoryInterface_s::EquipActor, inventoryInterface_s::EquipActorMelee, inventoryInterface_s::EquipActorRobot, inventoryInterface_s::GetUsedSlots, I_AddToInventory(), I_DestroyInventory(), I_EmptyContainer(), I_EquipActor(), I_EquipActorMelee(), I_EquipActorRobot(), I_GetUsedSlots(), I_MoveInInventory(), I_RemoveFromInventory(), I_TryAddToInventory(), inventoryInterface_s::import, inventoryInterface_s::invList, inventoryInterface_s::MoveInInventory, inventoryInterface_s::name, NONE_AMMO, inventoryInterface_s::RemoveFromInventory, and inventoryInterface_s::TryAddToInventory.
Referenced by G_Init(), GAME_SetMode(), GAME_Spawn(), and ResetInventoryList().