UFO: Alien Invasion
Loading...
Searching...
No Matches
inv_shared.h File Reference

common object-, inventory-, container- and firemode-related functions headers. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  itemEffect_t
struct  implantDef_t
struct  fireDef_t
 this is a fire definition for our weapons/ammo More...
struct  craftItem
 Aircraft items. More...
struct  objDef_t
 Defines all attributes of objects used in the inventory. More...
struct  invDef_t
 inventory definition for our menus More...
class  Item
 item instance data, with linked list capability More...
class  Container
class  Inventory
 inventory definition with all its containers More...
struct  equipDef_t
struct  damageType_t

Macros

#define DROPSHIP_MAX   8
#define INTERCEPTOR_MAX   12
#define AIRCRAFTTYPE_MAX   (DROPSHIP_MAX + INTERCEPTOR_MAX)
#define MAX_OBJDEFS   144
#define MAX_IMPLANTS   16
#define MAX_MAPDEFS   256
#define MAX_WEAPONS_PER_OBJDEF   4
#define MAX_AMMOS_PER_OBJDEF   4
#define MAX_FIREDEFS_PER_WEAPON   8
#define WEAPON_BALANCE   0.5f
#define SKILL_BALANCE   1.0f
#define CID_RIGHT   0
#define CID_LEFT   1
#define CID_IMPLANT   2
#define CID_HEADGEAR   3
#define CID_BACKPACK   4
#define CID_BELT   5
#define CID_HOLSTER   6
#define CID_ARMOUR   7
#define CID_FLOOR   8
#define CID_EQUIP   9
#define CID_MAX   10
#define SHAPE_SMALL_MAX_WIDTH   8
 The max width and height of an item-shape.
#define SHAPE_SMALL_MAX_HEIGHT   4
#define SHAPE_BIG_MAX_HEIGHT   16
 defines the max height of an inventory container
#define SHAPE_BIG_MAX_WIDTH   32
 32 bit mask
#define MAX_DAMAGETYPES   64
#define MAX_INVDEFS   16
#define MAX_CONTAINERS   MAX_INVDEFS
#define MAX_EQUIPDEFS   64
#define MAX_TEAMS_PER_MISSION   MAX_TEAMDEFS
#define foreachhand(hand)
#define THIS_FIREMODE(fm, HAND, fdIdx)
#define FIRESH_IsMedikit(firedef)

Typedefs

typedef short humanAircraftType_t
typedef int32_t containerIndex_t
typedef int32_t weaponFireDefIndex_t
typedef int32_t fireDefIndex_t

Enumerations

enum  inventory_action_t {
  IA_NONE , IA_MOVE , IA_ARMOUR , IA_RELOAD ,
  IA_RELOAD_SWAP , IA_NOTIME , IA_NORELOAD
}
 Possible inventory actions for moving items between containers. More...
enum  effectStages_t {
  EFFECT_ACTIVE , EFFECT_INACTIVE , EFFECT_OVERDOSE , EFFECT_STRENGTHEN ,
  EFFECT_MAX
}
enum  aircraftItemType_t {
  AC_ITEM_BASE_MISSILE , AC_ITEM_BASE_LASER , AC_ITEM_WEAPON , AC_ITEM_SHIELD ,
  AC_ITEM_ELECTRONICS , AC_ITEM_PILOT , AC_ITEM_AMMO , AC_ITEM_AMMO_MISSILE ,
  AC_ITEM_AMMO_LASER , MAX_ACITEMS
}
 All different types of craft items. More...
enum  aircraftParams_t {
  AIR_STATS_SPEED , AIR_STATS_MAXSPEED , AIR_STATS_SHIELD , AIR_STATS_ECM ,
  AIR_STATS_DAMAGE , AIR_STATS_ACCURACY , AIR_STATS_FUELSIZE , AIR_STATS_WRANGE ,
  AIR_STATS_ANTIMATTER , AIR_STATS_MAX
}
 Aircraft parameters. More...
enum  { INV_DOES_NOT_FIT = 0 , INV_FITS = 1 , INV_FITS_ONLY_ROTATED = 2 , INV_FITS_BOTH = 3 }
 Return values for canHoldItem. More...
enum  actorHands_t { ACTOR_HAND_NOT_SET = 0 , ACTOR_HAND_RIGHT = 1 , ACTOR_HAND_LEFT = 2 , ACTOR_HAND_ENSURE_32BIT = 0x7FFFFFFF }

Functions

bool isValidContId (const containerIndex_t id)
void INVSH_InitCSI (const struct csi_s *import) __attribute__((nonnull))
const objDef_tINVSH_GetItemByID (const char *id)
 Returns the item that belongs to the given id or nullptr if it wasn't found.
const objDef_tINVSH_GetItemByIDX (int index)
 Returns the item that belongs to the given index or nullptr if the index is invalid.
const objDef_tINVSH_GetItemByIDSilent (const char *id)
 Returns the item that belongs to the given id or nullptr if it wasn't found.
const implantDef_tINVSH_GetImplantForObjDef (const objDef_t *od)
const implantDef_tINVSH_GetImplantByID (const char *id)
 Returns the implant that belongs to the given id or nullptr if it wasn't found.
const implantDef_tINVSH_GetImplantByIDSilent (const char *id)
 Returns the implant that belongs to the given id or nullptr if it wasn't found.
const invDef_tINVSH_GetInventoryDefinitionByID (const char *id)
const fireDef_tFIRESH_GetFiredef (const objDef_t *obj, const weaponFireDefIndex_t weapFdsIdx, const fireDefIndex_t fdIdx)
 Get the fire definitions for a given object.
void INVSH_MergeShapes (uint32_t *shape, const uint32_t itemShape, const int x, const int y)
 Will merge the second shape (=itemShape) into the first one (=big container shape) on the position x/y.
bool INVSH_CheckShape (const uint32_t *shape, const int x, const int y)
 Checks the shape if there is a 1-bit on the position x/y.
int INVSH_ShapeSize (const uint32_t shape)
 Counts the used bits in a shape (item shape).

Detailed Description

common object-, inventory-, container- and firemode-related functions headers.

Definition in file inv_shared.h.

Macro Definition Documentation

◆ AIRCRAFTTYPE_MAX

#define AIRCRAFTTYPE_MAX   (DROPSHIP_MAX + INTERCEPTOR_MAX)

Definition at line 34 of file inv_shared.h.

◆ CID_ARMOUR

◆ CID_BACKPACK

◆ CID_BELT

#define CID_BELT   5

◆ CID_EQUIP

◆ CID_FLOOR

◆ CID_HEADGEAR

◆ CID_HOLSTER

◆ CID_IMPLANT

◆ CID_LEFT

◆ CID_MAX

◆ CID_RIGHT

◆ DROPSHIP_MAX

#define DROPSHIP_MAX   8

Definition at line 32 of file inv_shared.h.

Referenced by Com_ParseAircraftNames().

◆ FIRESH_IsMedikit

#define FIRESH_IsMedikit ( firedef)
Value:
((firedef)->damage[0] < 0)

Definition at line 661 of file inv_shared.h.

Referenced by CL_GetHitProbability(), G_ClientShoot(), and G_ShootSingle().

◆ foreachhand

#define foreachhand ( hand)
Value:
for (int hand##__loop = 0; hand##__loop < 2; ++hand##__loop) \
if (hand = (hand##__loop == 0 ? ACTOR_HAND_RIGHT : ACTOR_HAND_LEFT), false) {} else
@ ACTOR_HAND_LEFT
Definition inv_shared.h:629
@ ACTOR_HAND_RIGHT
Definition inv_shared.h:628

Definition at line 634 of file inv_shared.h.

Referenced by HUD_CheckFiremodeReservation(), and HUD_PopupFiremodeReservation().

◆ INTERCEPTOR_MAX

#define INTERCEPTOR_MAX   12

Definition at line 33 of file inv_shared.h.

Referenced by Com_ParseAircraftNames().

◆ MAX_AMMOS_PER_OBJDEF

#define MAX_AMMOS_PER_OBJDEF   4

Definition at line 41 of file inv_shared.h.

Referenced by Com_AddObjectLinks().

◆ MAX_CONTAINERS

#define MAX_CONTAINERS   MAX_INVDEFS

Definition at line 394 of file inv_shared.h.

Referenced by UI_ContainerNodeUpdateEquipment().

◆ MAX_DAMAGETYPES

#define MAX_DAMAGETYPES   64

Definition at line 258 of file inv_shared.h.

Referenced by Com_ParseDamageTypes(), and Com_ValueToStr().

◆ MAX_EQUIPDEFS

#define MAX_EQUIPDEFS   64

Definition at line 603 of file inv_shared.h.

Referenced by Com_ParseEquipment().

◆ MAX_FIREDEFS_PER_WEAPON

◆ MAX_IMPLANTS

#define MAX_IMPLANTS   16

Definition at line 38 of file inv_shared.h.

Referenced by Com_ParseImplant().

◆ MAX_INVDEFS

#define MAX_INVDEFS   16

Definition at line 368 of file inv_shared.h.

Referenced by CL_InvAmmo(), and CL_InvReload().

◆ MAX_MAPDEFS

#define MAX_MAPDEFS   256

Definition at line 39 of file inv_shared.h.

◆ MAX_OBJDEFS

#define MAX_OBJDEFS   144

Definition at line 37 of file inv_shared.h.

Referenced by Com_ParseItem().

◆ MAX_TEAMS_PER_MISSION

#define MAX_TEAMS_PER_MISSION   MAX_TEAMDEFS

Definition at line 618 of file inv_shared.h.

Referenced by BATTLE_SetVars(), CP_ParseAlienTeam(), and GAME_SK_SetMissionParameters().

◆ MAX_WEAPONS_PER_OBJDEF

#define MAX_WEAPONS_PER_OBJDEF   4

Definition at line 40 of file inv_shared.h.

Referenced by Com_ParseFireDefinition(), Com_ParseItem(), FIRESH_GetFiredef(), and RunImplant().

◆ SHAPE_BIG_MAX_HEIGHT

#define SHAPE_BIG_MAX_HEIGHT   16

defines the max height of an inventory container

Note
the max width is 32 - because uint32_t has 32 bits and we are using a bitmask for the x values
See also
SHAPE_SMALL_MAX_WIDTH
SHAPE_SMALL_MAX_HEIGHT
Note
This is also used for bit shifting, so please don't change this until you REALLY know what you are doing

Definition at line 188 of file inv_shared.h.

Referenced by InventoryInterface::addToInventory(), Com_ParseValue(), Com_SetValue(), Inventory::findSpace(), INV_MoveItem(), INVSH_CheckShape(), INVSH_CheckShapeCollision(), INVSH_CheckToInventory_shape(), INVSH_MergeShapes(), uiContainerNode::onDndMove(), uiContainerNode::onLoaded(), and UI_ContainerNodeDrawFreeSpace().

◆ SHAPE_BIG_MAX_WIDTH

◆ SHAPE_SMALL_MAX_HEIGHT

◆ SHAPE_SMALL_MAX_WIDTH

#define SHAPE_SMALL_MAX_WIDTH   8

The max width and height of an item-shape.

Note
these values depend on the usage of an uint32_t that has 32 bits and a width of 8bit => 4 rows
See also
SHAPE_BIG_MAX_HEIGHT
SHAPE_BIG_MAX_WIDTH
Note
This is also used for bit shifting, so please don't change this until you REALLY know what you are doing

Definition at line 176 of file inv_shared.h.

Referenced by Com_ParseItem(), Com_ParseValue(), objDef_t::getShapeRotated(), INVSH_CheckShapeCollision(), INVSH_CheckShapeSmall(), INVSH_MergeShapes(), INVSH_ShapeSetBit(), and INVSH_ShapeSize().

◆ SKILL_BALANCE

#define SKILL_BALANCE   1.0f

Definition at line 44 of file inv_shared.h.

Referenced by CL_GetHitProbability(), and G_CalcEffectiveSpread().

◆ THIS_FIREMODE

#define THIS_FIREMODE ( fm,
HAND,
fdIdx )
Value:
((fm)->getHand() == (HAND) && (fm)->getFmIdx() == (fdIdx))

Definition at line 654 of file inv_shared.h.

Referenced by HUD_DisplayFiremodeEntry().

◆ WEAPON_BALANCE

#define WEAPON_BALANCE   0.5f

Definition at line 43 of file inv_shared.h.

Referenced by CL_GetHitProbability(), and G_CalcEffectiveSpread().

Typedef Documentation

◆ containerIndex_t

typedef int32_t containerIndex_t

Definition at line 46 of file inv_shared.h.

◆ fireDefIndex_t

typedef int32_t fireDefIndex_t

Definition at line 78 of file inv_shared.h.

◆ humanAircraftType_t

typedef short humanAircraftType_t
Todo
doesn't belong here, but AIRCRAFTTYPE_MAX is needed for the equipment definitions

Definition at line 31 of file inv_shared.h.

◆ weaponFireDefIndex_t

typedef int32_t weaponFireDefIndex_t

Definition at line 77 of file inv_shared.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Return values for canHoldItem.

Enumerator
INV_DOES_NOT_FIT 

Item does not fit.

INV_FITS 

The item fits without rotation (only)

INV_FITS_ONLY_ROTATED 

The item fits only when rotated (90! to the left)

INV_FITS_BOTH 

The item fits either rotated or not.

Definition at line 361 of file inv_shared.h.

◆ actorHands_t

Todo
remove this and use the container id - not every unit must have two hands
Enumerator
ACTOR_HAND_NOT_SET 
ACTOR_HAND_RIGHT 
ACTOR_HAND_LEFT 
ACTOR_HAND_ENSURE_32BIT 

Definition at line 626 of file inv_shared.h.

◆ aircraftItemType_t

All different types of craft items.

Note
must begin with weapons and end with ammos
Todo
move into campaign only structure
Enumerator
AC_ITEM_BASE_MISSILE 

base weapon

AC_ITEM_BASE_LASER 

base weapon

AC_ITEM_WEAPON 

aircraft weapon

AC_ITEM_SHIELD 

aircraft shield

AC_ITEM_ELECTRONICS 

aircraft electronics

AC_ITEM_PILOT 
AC_ITEM_AMMO 

aircraft ammos

AC_ITEM_AMMO_MISSILE 

base ammos

AC_ITEM_AMMO_LASER 

base ammos

MAX_ACITEMS 

Definition at line 197 of file inv_shared.h.

◆ aircraftParams_t

Aircraft parameters.

Note
This is a list of all aircraft parameters that depends on aircraft items. those values doesn't change with shield or weapon assigned to aircraft
AIR_STATS_WRANGE must be the last parameter (see AII_UpdateAircraftStats)
Todo
move into campaign only structure
Enumerator
AIR_STATS_SPEED 

Aircraft cruising speed.

AIR_STATS_MAXSPEED 

Aircraft max speed.

AIR_STATS_SHIELD 

Aircraft shield.

AIR_STATS_ECM 

Aircraft electronic warfare level.

AIR_STATS_DAMAGE 

Aircraft damage points (= hit points of the aircraft).

AIR_STATS_ACCURACY 

Aircraft accuracy - base accuracy (without weapon).

AIR_STATS_FUELSIZE 

Aircraft fuel capacity.

AIR_STATS_WRANGE 

Aircraft weapon range - the maximum distance aircraft can open fire. for aircraft, the value is in millidegree (because this is an int)

AIR_STATS_ANTIMATTER 

amount of antimatter needed for a full refill.

AIR_STATS_MAX 

Definition at line 225 of file inv_shared.h.

◆ effectStages_t

Enumerator
EFFECT_ACTIVE 
EFFECT_INACTIVE 
EFFECT_OVERDOSE 
EFFECT_STRENGTHEN 
EFFECT_MAX 

Definition at line 80 of file inv_shared.h.

◆ inventory_action_t

Possible inventory actions for moving items between containers.

Enumerator
IA_NONE 

no move possible

IA_MOVE 

normal inventory item move

IA_ARMOUR 

move or swap armour

IA_RELOAD 

reload weapon

IA_RELOAD_SWAP 

switch loaded ammo

IA_NOTIME 

not enough TUs to make this inv move

IA_NORELOAD 

not loadable or already fully loaded

Definition at line 65 of file inv_shared.h.

Function Documentation

◆ FIRESH_GetFiredef()

const fireDef_t * FIRESH_GetFiredef ( const objDef_t * obj,
const weaponFireDefIndex_t weapFdsIdx,
const fireDefIndex_t fdIdx )

Get the fire definitions for a given object.

Parameters
[in]objThe object to get the firedef for
[in]weapFdsIdxthe weapon index in the fire definition array
[in]fdIdxthe fire definition index for the weapon (given by weapFdsIdx)
Returns
Will never return nullptr
See also
getFiredefs

Definition at line 385 of file inv_shared.cpp.

References objDef_t::fd, objDef_t::id, MAX_FIREDEFS_PER_WEAPON, MAX_WEAPONS_PER_OBJDEF, and Sys_Error().

Referenced by CL_ActorDoShoot(), CL_ActorDoShootTime(), CL_ActorDoThrow(), CL_ActorShootHidden(), CL_ActorShootHiddenTime(), and HUD_UpdateActorFireMode().

◆ INVSH_CheckShape()

bool INVSH_CheckShape ( const uint32_t * shape,
const int x,
const int y )

Checks the shape if there is a 1-bit on the position x/y.

Parameters
[in]shapePointer to 'uint32_t shape[SHAPE_BIG_MAX_HEIGHT]'
[in]xThe x value in the container (1 << x in the shape bitmask)
[in]yThe y value in the container (SHAPE_BIG_MAX_HEIGHT is the max)

Definition at line 414 of file inv_shared.cpp.

References Com_Printf(), SHAPE_BIG_MAX_HEIGHT, and SHAPE_BIG_MAX_WIDTH.

Referenced by UI_ContainerNodeDrawFreeSpace().

◆ INVSH_GetImplantByID()

const implantDef_t * INVSH_GetImplantByID ( const char * id)

Returns the implant that belongs to the given id or nullptr if it wasn't found.

Parameters
[in]idthe implant id in our implant definition array (csi.implants)
See also
INVSH_GetImplantByIDSilent

Definition at line 326 of file inv_shared.cpp.

References Com_Printf(), and INVSH_GetImplantByIDSilent().

Referenced by GAME_LoadCharacter().

◆ INVSH_GetImplantByIDSilent()

const implantDef_t * INVSH_GetImplantByIDSilent ( const char * id)

Returns the implant that belongs to the given id or nullptr if it wasn't found.

Parameters
[in]idthe implant id in our implant definition array (csi.implants)
See also
INVSH_GetImplantByID

Definition at line 307 of file inv_shared.cpp.

References CSI, i, implantDef_t::id, and Q_streq.

Referenced by INVSH_GetImplantByID().

◆ INVSH_GetImplantForObjDef()

const implantDef_t * INVSH_GetImplantForObjDef ( const objDef_t * od)

Definition at line 291 of file inv_shared.cpp.

References Com_Printf(), CSI, i, id, and objDef_t::id.

Referenced by HOS_ImplantDetails_f().

◆ INVSH_GetInventoryDefinitionByID()

const invDef_t * INVSH_GetInventoryDefinitionByID ( const char * id)

Searched an inventory container by a given container id

Parameters
[in]idID or name of the inventory container to search for
Returns
nullptr if not found

Definition at line 340 of file inv_shared.cpp.

References CID_MAX, CSI, i, invDef_t::name, and Q_streq.

Referenced by uiBaseInventoryNode::onLoaded(), uiContainerNode::onLoaded(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ INVSH_GetItemByID()

◆ INVSH_GetItemByIDSilent()

const objDef_t * INVSH_GetItemByIDSilent ( const char * id)

Returns the item that belongs to the given id or nullptr if it wasn't found.

Parameters
[in]idthe item id in our object definition array (csi.ods)
See also
INVSH_GetItemByID

Definition at line 249 of file inv_shared.cpp.

References CSI, i, objDef_t::id, and Q_streq.

Referenced by ItemCargo::add(), AIM_UpdateItemDescription(), B_AddAntimatter(), BDEF_SelectItem_f(), Com_ParseImplant(), Com_ParseItem(), COMP_ParseComponents(), CP_AddItemAsCollected_f(), uiItemNode::draw(), G_AddItemToFloor(), INVSH_GetItemByID(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and UP_TechGetsDisplayed().

◆ INVSH_GetItemByIDX()

◆ INVSH_InitCSI()

void INVSH_InitCSI ( const struct csi_s * import)

References index.

◆ INVSH_MergeShapes()

void INVSH_MergeShapes ( uint32_t * shape,
const uint32_t itemShape,
const int x,
const int y )

Will merge the second shape (=itemShape) into the first one (=big container shape) on the position x/y.

Note
The function expects an already rotated shape for itemShape. Use getShapeRotated() if needed.
Parameters
[in]shapeThe shape of the container [SHAPE_BIG_MAX_HEIGHT]'
[in]itemShapeThe shape of the item [SHAPE_SMALL_MAX_HEIGHT]
[in]xThe x value in the container (1 << x in the shape bitmask)
[in]yThe y value in the container (SHAPE_BIG_MAX_HEIGHT is the max)

Definition at line 402 of file inv_shared.cpp.

References i, SHAPE_BIG_MAX_HEIGHT, SHAPE_SMALL_MAX_HEIGHT, and SHAPE_SMALL_MAX_WIDTH.

Referenced by INVSH_CheckToInventory_shape(), and UI_ContainerNodeDrawFreeSpace().

◆ INVSH_ShapeSize()

int INVSH_ShapeSize ( const uint32_t shape)

Counts the used bits in a shape (item shape).

Parameters
[in]shapeThe shape to count the bits in.
Returns
Number of bits.
Note
Used to calculate the real field usage in the inventory

Definition at line 435 of file inv_shared.cpp.

References i, SHAPE_SMALL_MAX_HEIGHT, and SHAPE_SMALL_MAX_WIDTH.

Referenced by LE_BiggestItem().

◆ isValidContId()

bool isValidContId ( const containerIndex_t id)
inline

Definition at line 59 of file inv_shared.h.

References CID_MAX.

Referenced by G_ClientAction(), and G_ReadItem().