UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
inv_shared.h File Reference

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

Go to the source code of this file.

Data Structures

struct  itemEffect_s
 
struct  implantDef_s
 
struct  fireDef_s
 this is a fire definition for our weapons/ammo More...
 
struct  craftitem_s
 Aircraft items. More...
 
struct  objDef_s
 Defines all attributes of objects used in the inventory. More...
 
struct  invDef_s
 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_s
 
struct  damageType_s
 

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. More...
 
#define SHAPE_SMALL_MAX_HEIGHT   4
 
#define SHAPE_BIG_MAX_HEIGHT   16
 defines the max height of an inventory container More...
 
#define SHAPE_BIG_MAX_WIDTH   32
 32 bit mask More...
 
#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)   ((fm)->getHand() == (HAND) && (fm)->getFmIdx() == (fdIdx))
 
#define FIRESH_IsMedikit(firedef)   ((firedef)->damage[0] < 0)
 

Typedefs

typedef short humanAircraftType_t
 
typedef int32_t containerIndex_t
 
typedef int32_t weaponFireDefIndex_t
 
typedef int32_t fireDefIndex_t
 
typedef struct itemEffect_s itemEffect_t
 
typedef struct implantDef_s implantDef_t
 
typedef struct fireDef_s fireDef_t
 this is a fire definition for our weapons/ammo More...
 
typedef struct craftitem_s craftItem
 Aircraft items. More...
 
typedef struct objDef_s objDef_t
 Defines all attributes of objects used in the inventory. More...
 
typedef struct invDef_s invDef_t
 inventory definition for our menus More...
 
typedef struct equipDef_s equipDef_t
 
typedef struct damageType_s damageType_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. More...
 
const objDef_tINVSH_GetItemByIDX (int index)
 Returns the item that belongs to the given index or nullptr if the index is invalid. More...
 
const objDef_tINVSH_GetItemByIDSilent (const char *id)
 Returns the item that belongs to the given id or nullptr if it wasn't found. More...
 
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. More...
 
const implantDef_tINVSH_GetImplantByIDSilent (const char *id)
 Returns the implant that belongs to the given id or nullptr if it wasn't found. More...
 
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. More...
 
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. More...
 
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. More...
 
int INVSH_ShapeSize (const uint32_t shape)
 Counts the used bits in a shape (item shape). More...
 

Detailed Description

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

Definition in file inv_shared.h.

Macro Definition Documentation

#define AIRCRAFTTYPE_MAX   (DROPSHIP_MAX + INTERCEPTOR_MAX)

Definition at line 34 of file inv_shared.h.

#define CID_BELT   5
#define DROPSHIP_MAX   8

Definition at line 32 of file inv_shared.h.

Referenced by Com_ParseAircraftNames().

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

Definition at line 661 of file inv_shared.h.

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

#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

Definition at line 634 of file inv_shared.h.

Referenced by HUD_CheckFiremodeReservation(), and HUD_PopupFiremodeReservation().

#define INTERCEPTOR_MAX   12

Definition at line 33 of file inv_shared.h.

Referenced by Com_ParseAircraftNames().

#define MAX_AMMOS_PER_OBJDEF   4

Definition at line 41 of file inv_shared.h.

Referenced by Com_AddObjectLinks().

#define MAX_CONTAINERS   MAX_INVDEFS

Definition at line 394 of file inv_shared.h.

Referenced by UI_ContainerNodeUpdateEquipment().

#define MAX_DAMAGETYPES   64

Definition at line 258 of file inv_shared.h.

Referenced by Com_ParseDamageTypes(), and Com_ValueToStr().

#define MAX_EQUIPDEFS   64

Definition at line 603 of file inv_shared.h.

Referenced by Com_ParseEquipment().

#define MAX_IMPLANTS   16

Definition at line 38 of file inv_shared.h.

Referenced by Com_ParseImplant().

#define MAX_INVDEFS   16

Definition at line 368 of file inv_shared.h.

Referenced by CL_InvAmmo(), and CL_InvReload().

#define MAX_MAPDEFS   256

Definition at line 39 of file inv_shared.h.

#define MAX_OBJDEFS   144

Definition at line 37 of file inv_shared.h.

Referenced by Com_ParseItem().

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

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

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

#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_s::getShapeRotated(), INVSH_CheckShapeCollision(), INVSH_CheckShapeSmall(), INVSH_MergeShapes(), INVSH_ShapeSetBit(), and INVSH_ShapeSize().

#define SKILL_BALANCE   1.0f

Definition at line 44 of file inv_shared.h.

Referenced by CL_GetHitProbability(), and G_CalcEffectiveSpread().

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

Definition at line 654 of file inv_shared.h.

Referenced by HUD_DisplayFiremodeEntry().

#define WEAPON_BALANCE   0.5f

Definition at line 43 of file inv_shared.h.

Referenced by CL_GetHitProbability(), and G_CalcEffectiveSpread().

Typedef Documentation

typedef int32_t containerIndex_t

Definition at line 46 of file inv_shared.h.

typedef struct craftitem_s craftItem

Aircraft items.

Note
This is a part of objDef, only filled for aircraft items (weapons, shield, electronics).
See also
objDef_t
Todo:
move into campaign only structure
typedef struct damageType_s damageType_t
typedef struct equipDef_s equipDef_t
typedef struct fireDef_s fireDef_t

this is a fire definition for our weapons/ammo

typedef int32_t fireDefIndex_t

Definition at line 78 of file inv_shared.h.

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

Definition at line 28 of file inv_shared.h.

typedef struct implantDef_s implantDef_t
typedef struct invDef_s invDef_t

inventory definition for our menus

typedef struct itemEffect_s itemEffect_t
typedef struct objDef_s objDef_t

Defines all attributes of objects used in the inventory.

Note
See also http://ufoai.org/wiki/index.php/UFO-Scripts/weapon_%2A.ufo
typedef int32_t weaponFireDefIndex_t

Definition at line 77 of file inv_shared.h.

Enumeration Type Documentation

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.

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.

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.

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.

Enumerator
EFFECT_ACTIVE 
EFFECT_INACTIVE 
EFFECT_OVERDOSE 
EFFECT_STRENGTHEN 
EFFECT_MAX 

Definition at line 80 of file inv_shared.h.

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

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_s::fd, objDef_s::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().

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(), f, SHAPE_BIG_MAX_HEIGHT, and SHAPE_BIG_MAX_WIDTH.

Referenced by UI_ContainerNodeDrawFreeSpace().

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

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 i, implantDef_s::id, csi_s::implants, csi_s::numImplants, and Q_streq.

Referenced by INVSH_GetImplantByID().

const implantDef_t* INVSH_GetImplantForObjDef ( const objDef_t od)
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, i, csi_s::ids, invDef_s::name, and Q_streq.

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

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 i, objDef_s::id, csi_s::numODs, csi_s::ods, 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(), and UP_TechGetsDisplayed().

void INVSH_InitCSI ( const struct csi_s import)
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().

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

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