inventory.c File Reference

#include "inventory.h"
Include dependency graph for inventory.c:

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_tI_AddInvList (inventoryInterface_t *self, invList_t **invList)
static invList_tI_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 Documentation

#define WEAPONLESS_BONUS   0.4

Definition at line 528 of file inventory.c.

Referenced by I_EquipActor().


Enumeration Type Documentation

Types of weapon that can be selected.

Enumerator:
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.


Function Documentation

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.

Note:
Set x and y to NONE if the item should get added to an automatically chosen free spot in the container.
Parameters:
[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")
See also:
I_RemoveFromInventory
Returns:
the 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.

Parameters:
[in] i Pointer to the inventory which should be erased.
Note:
Loops through all containers in inventory. NULL for temp containers are skipped, for real containers I_EmptyContainer is called.
See also:
I_EmptyContainer

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.

Parameters:
[in] i The inventory where the container is located.
[in] container Index of the container which will be cleared.
See also:
I_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 NULL for a temp container like idEquip or idFloor

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.

Parameters:
[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.
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 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.

Parameters:
[in] inv The inventory that will get the weapon.
[in] chr Pointer to character data.
Note:
Weapons assigned here cannot be collected in any case. These are dummy "actor weapons".

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).

Parameters:
[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.

Returns:
The number of free 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.

Parameters:
[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 
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 trough these things.

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.

Parameters:
[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.
See also:
INVSH_LoadableInWeapon

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]
Parameters:
[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.
Returns:
qtrue If removal was successful.
qfalse If nothing was removed or an error occurred.
See also:
I_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.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).

Parameters:
[in] inv Inventory pointer to add the item.
[in] item Item to add to inventory.
[in] container Container id.
See also:
INVSH_FindSpace
I_AddToInventory

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  ) 
void INV_InitInventory ( const char *  name,
inventoryInterface_t interface,
csi_t csi,
const inventoryImport_t import 
)

Generated by  doxygen 1.6.2