UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Item Class Reference

item instance data, with linked list capability More...

#include <inv_shared.h>

Public Member Functions

 Item ()
 Item constructor with all default values. More...
 
 Item (const objDef_t *_itemDef, const objDef_t *ammo=nullptr, int ammoLeft=0)
 Item constructor with the 3 most often changed attributes. More...
 
void setNext (Item *nx)
 
void setX (const int val)
 
void setY (const int val)
 
void setAmmoDef (const objDef_t *od)
 
void setAmount (int value)
 
void setAmmoLeft (int value)
 
void setDef (const objDef_t *objDef)
 
ItemgetNext () const
 
int getX () const
 
int getY () const
 
const objDef_tammoDef (void) const
 
int getAmount () const
 
int getAmmoLeft () const
 
const objDef_tdef (void) const
 
bool isHeldTwoHanded () const
 
bool isReloadable () const
 
bool mustReload () const
 
bool isWeapon () const
 
bool isArmour () const
 
bool isSameAs (const Item *const other) const
 Check if the (physical) information of 2 items is exactly the same. More...
 
void addAmount (int value)
 
int getWeight () const
 Return the weight of an item. More...
 
void getFirstShapePosition (int *const x, int *const y) const
 Calculates the first "true" bit in the shape and returns its position in the item. More...
 
const objDef_tgetReactionFireWeaponType () const
 Checks whether this item is a reaction fire enabled weapon. More...
 
const fireDef_tgetFiredefs () const
 Returns the firedefinitions for a given weapon/ammo. More...
 
int getNumFiredefs () const
 
const fireDef_tgetSlowestFireDef () const
 Get the firedef that uses the most TU for this item. More...
 
const fireDef_tgetFastestFireDef () const
 

Data Fields

int rotated
 

Private Attributes

const objDef_t_itemDef
 
const objDef_t_ammoDef
 
Item_next
 
int _x
 
int _y
 
int _amount
 
int _ammoLeft
 

Detailed Description

item instance data, with linked list capability

Note
the item and ammo indices are transfered as shorts over the net - a value of NONE means that there is no item - e.g. a value of NONE for the ammo means, that there is no ammo loaded or assigned to this weapon

Definition at line 402 of file inv_shared.h.

Constructor & Destructor Documentation

Item::Item ( )

Item constructor with all default values.

Definition at line 497 of file inv_shared.cpp.

References _itemDef, _next, _x, _y, NONE_AMMO, rotated, setAmmoDef(), setAmmoLeft(), and setAmount().

Item::Item ( const objDef_t _itemDef,
const objDef_t ammo = nullptr,
int  ammoLeft = 0 
)

Item constructor with the 3 most often changed attributes.

Definition at line 508 of file inv_shared.cpp.

References _itemDef, _next, _x, _y, rotated, setAmmoDef(), setAmmoLeft(), and setAmount().

Member Function Documentation

void Item::addAmount ( int  value)
inline
const objDef_t* Item::def ( void  ) const
inline

Definition at line 469 of file inv_shared.h.

References _itemDef.

Referenced by equipDef_s::addClip(), InventoryInterface::addToInventory(), AI_FindBestFiredef(), AI_SearchGrenade(), AII_CarriedItems(), AIL_roundsleft(), AIL_weapontype(), AIR_GetStorageRoom(), AIR_MoveEmployeeInventoryIntoStorage(), AIR_TransferItemsCarriedByCharacterToBase(), AM_MoveCharacterInventoryIntoItemCargo(), CHRSH_CharGetBody(), CHRSH_CharGetHead(), CL_ActorCvars(), CL_ActorGetMuzzle(), CL_ActorReload(), CL_GetSkillIndicator(), CL_InvAdd(), CL_InvReload(), CL_NetReceiveItem(), CP_AddWeaponAmmo(), CP_CleanupAircraftTeam(), CP_CleanupContainerWeapons(), CP_CleanupTeam(), uiItemNode::draw(), uiBaseInventoryNode::draw(), uiContainerNode::draw(), E_RemoveInventoryFromStorage(), InventoryInterface::EquipActorMelee(), Inventory::findSpace(), G_ActorGetTUForReactionFire(), G_ActorInvMove(), G_ActorReload(), G_ApplyProtection(), G_ClientCanReload(), G_ClientGetWeaponFromInventory(), G_ClientReadInventory(), G_ClientShoot(), G_EventActorAppear(), G_EventInventoryReload(), G_InventoryDropToFloorCheck(), G_InventoryRemoveItemByID(), G_InventoryToFloor(), G_MissionThink(), G_MissionTouch(), G_SendInventory(), G_ShootGrenade(), G_ShootSingle(), G_ShotMorale(), G_WriteItem(), GAME_CollectItems(), GAME_LoadInventory(), GAME_LoadItem(), GAME_NetSendItem(), GAME_SaveItem(), getFiredefs(), getNumFiredefs(), getReactionFireWeaponType(), getWeight(), HUD_CheckReload(), HUD_CheckShooting(), HUD_DisplayActions(), HUD_GetFireDefinitionForHand(), HUD_GetMinimumTUsForUsage(), HUD_UpdateActor(), HUD_UpdateActorCvar(), HUD_UpdateActorFireMode(), HUD_UpdateActorLoad_f(), HUD_UpdateActorStats(), HUD_WeaponCanBeReloaded(), INV_LoadWeapon(), INV_UnloadWeapon(), INVSH_CheckToInventory_shape(), INVSH_ShapeCheckPosition(), isSameAs(), LE_BiggestItem(), InventoryInterface::moveInInventory(), uiContainerNode::onDndFinished(), uiContainerNode::onDndMove(), uiBaseInventoryNode::onMouseDown(), uiContainerNode::onMouseDown(), InventoryInterface::PackAmmoAndWeapon(), InventoryInterface::removeFromInventory(), TEST_F(), TR_Add_f(), InventoryInterface::tryAddToInventory(), UI_BaseInventoryNodeDrawItems(), UI_ContainerNodeAutoPlaceItem(), UI_ContainerNodeDrawDropPreview(), UI_ContainerNodeDrawFreeSpace(), UI_ContainerNodeDrawGrid(), UI_ContainerNodeDrawSingle(), UI_ContainerNodeUpdateEquipment(), UI_DrawItem(), and UI_GetItemTooltip().

const fireDef_t * Item::getFastestFireDef ( ) const
void Item::getFirstShapePosition ( int *const  x,
int *const  y 
) const

Calculates the first "true" bit in the shape and returns its position in the item.

Note
Use this to get the first "grab-able" grid-location of an item (not in the container !).
Parameters
[out]xThe x location inside the item.
[out]yThe x location inside the item.
See also
canHoldItem

Definition at line 557 of file inv_shared.cpp.

References getX(), getY(), INVSH_ShapeCheckPosition(), NONE, and SHAPE_SMALL_MAX_HEIGHT.

Referenced by CL_ActorReload(), G_ActorInvMove(), and INV_LoadWeapon().

int Item::getNumFiredefs ( ) const
const objDef_t * Item::getReactionFireWeaponType ( ) const

Checks whether this item is a reaction fire enabled weapon.

Note
The item is supposed to be in the right or left hand
Returns
nullptr if no reaction fire enabled weapon, the reaction fire enabled object otherwise.

Definition at line 649 of file inv_shared.cpp.

References def(), getFiredefs(), and fireDef_s::reaction.

Referenced by G_ReactionFireSettingsSetDefault().

const fireDef_t * Item::getSlowestFireDef ( ) const

Get the firedef that uses the most TU for this item.

Returns
The firedef that uses the most TU for this item or nullptr.

Definition at line 610 of file inv_shared.cpp.

References getFiredefs(), i, and MAX_FIREDEFS_PER_WEAPON.

Referenced by InventoryInterface::EquipActorNormal().

int Item::getWeight ( ) const

Return the weight of an item.

Returns
The weight of the given item including any ammo loaded.

Definition at line 522 of file inv_shared.cpp.

References ammoDef(), def(), getAmmoLeft(), and objDef_s::weight.

Referenced by Inventory::canHoldItemWeight(), InventoryInterface::EquipActorNormal(), and Inventory::getWeight().

bool Item::isReloadable ( ) const
inline
bool Item::isSameAs ( const Item *const  other) const

Check if the (physical) information of 2 items is exactly the same.

Parameters
[in]otherSecond item to compare.
Returns
true if they are identical or false otherwise.

Definition at line 536 of file inv_shared.cpp.

References ammoDef(), def(), and getAmmoLeft().

Referenced by InventoryInterface::addToInventory(), and Inventory::findInContainer().

bool Item::mustReload ( ) const
inline
Note
!mustReload() is not equivalent to 'usable' e.g. medikits are not reloadable, but they do have ammo

Definition at line 483 of file inv_shared.h.

References getAmmoLeft(), and isReloadable().

Referenced by AI_ActorThink(), AI_GetItemFromInventory(), AI_SearchGrenade(), G_ClientGetWeaponFromInventory(), ReactionFire::getFireDef(), HUD_CheckShooting(), HUD_UpdateActorFireMode(), and UI_DrawItem().

void Item::setAmount ( int  value)
inline
void Item::setDef ( const objDef_t objDef)
inline
void Item::setNext ( Item nx)
inline
void Item::setX ( const int  val)
inline
void Item::setY ( const int  val)
inline

Field Documentation

const objDef_t* Item::_ammoDef
private

Pointer to ammo definition.

Definition at line 404 of file inv_shared.h.

Referenced by ammoDef().

int Item::_ammoLeft
private

Number of ammo rounds left - see NONE_AMMO

Definition at line 410 of file inv_shared.h.

Referenced by getAmmoLeft().

int Item::_amount
private

The amount of items of this type on the same x and y location in the container

Definition at line 409 of file inv_shared.h.

Referenced by getAmount().

const objDef_t* Item::_itemDef
private

The weapon definition.

Definition at line 403 of file inv_shared.h.

Referenced by def(), and Item().

Item* Item::_next
private

Next entry in this list.

Definition at line 405 of file inv_shared.h.

Referenced by getNext(), and Item().

int Item::_x
private

Definition at line 406 of file inv_shared.h.

Referenced by getX(), and Item().

int Item::_y
private

Position (aka origin location) of the item in the container/invlist.

Note
ATTENTION Do not use this to get an item by comparing it against a x/y value. The shape as defined in the Item may be empty at this location!

Definition at line 406 of file inv_shared.h.

Referenced by getY(), and Item().

int Item::rotated

If the item is currently displayed rotated (true or 1) or not (false or 0)

Note
don't change this to anything smaller than 4 bytes - the network parsing functions are expecting this to be at least 4 bytes

Definition at line 412 of file inv_shared.h.

Referenced by InventoryInterface::addToInventory(), CL_NetReceiveItem(), G_ReadItem(), G_WriteItem(), GAME_LoadItem(), GAME_NetSendItem(), GAME_SaveItem(), INVSH_CheckToInventory_shape(), INVSH_ShapeCheckPosition(), Item(), InventoryInterface::moveInInventory(), uiContainerNode::onDndFinished(), InventoryInterface::tryAddToInventory(), UI_ContainerNodeDrawDropPreview(), and UI_DrawItem().


The documentation for this class was generated from the following files: