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

Common object-, inventory-, container- and firemode-related functions. More...

#include "q_shared.h"

Go to the source code of this file.

Functions

void INVSH_InitCSI (const csi_t *import)
 Initializes client server shared data pointer. This works because the client and the server are both using exactly the same pointer. More...
 
static bool INVSH_CheckShapeCollision (const uint32_t *shape, const uint32_t itemShape, const int x, const int y)
 Will check if the item-shape is colliding with something else in the container-shape at position x/y. More...
 
static bool INVSH_CheckToInventory_shape (const Inventory *const inv, const invDef_t *container, const uint32_t itemShape, const int x, const int y, const Item *ignoredItem)
 Checks if an item-shape can be put into a container at a certain position... ignores any 'special' types of containers. More...
 
static bool INVSH_CheckShapeSmall (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...
 
static bool INVSH_ShapeCheckPosition (const Item *item, const int x, const int y)
 Check if a position in a container is used by an item (i.e. collides with the shape). 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 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_GetItemByID (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_GetImplantByIDSilent (const char *id)
 Returns the implant that belongs to the given id or nullptr if it wasn't found. More...
 
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 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...
 
static uint32_t INVSH_ShapeSetBit (uint32_t shape, const int x, const int y)
 Sets one bit in a shape to true/1. More...
 

Variables

static const csi_tCSI
 
static int cacheCheckToInventory = INV_DOES_NOT_FIT
 

Detailed Description

Common object-, inventory-, container- and firemode-related functions.

Note
Shared inventory management functions prefix: INVSH_
Shared firemode management functions prefix: FIRESH_

Definition in file inv_shared.cpp.

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

static bool INVSH_CheckShapeCollision ( const uint32_t *  shape,
const uint32_t  itemShape,
const int  x,
const int  y 
)
static

Will check if the item-shape is colliding with something else in the container-shape at 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 99 of file inv_shared.cpp.

References Com_DPrintf(), DEBUG_SHARED, i, SHAPE_BIG_MAX_HEIGHT, SHAPE_SMALL_MAX_HEIGHT, and SHAPE_SMALL_MAX_WIDTH.

Referenced by INVSH_CheckToInventory_shape().

static bool INVSH_CheckShapeSmall ( const uint32_t  shape,
const int  x,
const int  y 
)
static

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

Parameters
[in]shapeThe shape to check in. (8x4)
[in]xThe x value in the shape (1 << x in the shape bitmask)
[in]yThe y value in the shape (SHAPE_SMALL_MAX_HEIGHT is the max)

Definition at line 188 of file inv_shared.cpp.

References SHAPE_SMALL_MAX_HEIGHT, and SHAPE_SMALL_MAX_WIDTH.

Referenced by objDef_s::getShapeRotated(), and INVSH_ShapeCheckPosition().

static bool INVSH_CheckToInventory_shape ( const Inventory *const  inv,
const invDef_t container,
const uint32_t  itemShape,
const int  x,
const int  y,
const Item ignoredItem 
)
static

Checks if an item-shape can be put into a container at a certain position... ignores any 'special' types of containers.

Parameters
[in]invThe inventory
[in]containerThe container (index) to look into.
[in]itemShapeThe shape info of an item to fit into the container.
[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)
[in]ignoredItemYou can ignore one item in the container (most often the currently dragged one). Use nullptr if you want to check against all items in the container.
See also
canHoldItem
Returns
false if the item does not fit, true if it fits.

Definition at line 142 of file inv_shared.cpp.

References cacheCheckToInventory, Item::def(), Inventory::getContainer(), objDef_s::getShapeRotated(), Item::getX(), Item::getY(), invDef_s::id, INVSH_CheckShapeCollision(), INVSH_MergeShapes(), Item::rotated, invDef_s::scroll, objDef_s::shape, invDef_s::shape, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, and Sys_Error().

Referenced by Inventory::canHoldItem().

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 csi_t import)

Initializes client server shared data pointer. This works because the client and the server are both using exactly the same pointer.

Parameters
[in]importThe client server interface pointer
See also
G_Init
Com_ParseScripts

Definition at line 39 of file inv_shared.cpp.

Referenced by Com_ParseScripts(), G_Init(), and GAME_CP_InitStartup().

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

static bool INVSH_ShapeCheckPosition ( const Item item,
const int  x,
const int  y 
)
static

Check if a position in a container is used by an item (i.e. collides with the shape).

Parameters
[in]itemA pointer to the Item in question.
[in]x,yThe location in the container.

Definition at line 203 of file inv_shared.cpp.

References Item::def(), objDef_s::getShapeRotated(), Item::getX(), Item::getY(), INVSH_CheckShapeSmall(), Item::rotated, and objDef_s::shape.

Referenced by Item::getFirstShapePosition(), and Inventory::getItemAtPos().

static uint32_t INVSH_ShapeSetBit ( uint32_t  shape,
const int  x,
const int  y 
)
static

Sets one bit in a shape to true/1.

Note
Only works for V_SHAPE_SMALL! If the bit is already set the shape is not changed.
Parameters
[in]shapeThe shape to modify. (8x4)
[in]xThe x (width) position of the bit to set.
[in]yThe y (height) position of the bit to set.
Returns
The new shape.

Definition at line 455 of file inv_shared.cpp.

References Com_Printf(), SHAPE_SMALL_MAX_HEIGHT, and SHAPE_SMALL_MAX_WIDTH.

Referenced by objDef_s::getShapeRotated().

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

Variable Documentation

int cacheCheckToInventory = INV_DOES_NOT_FIT
static

Definition at line 89 of file inv_shared.cpp.

Referenced by Inventory::findSpace(), and INVSH_CheckToInventory_shape().

const csi_t* CSI
static

Definition at line 30 of file inv_shared.cpp.