70 Item* list = firstEntry;
107 if (container->
temp) {
119 inv->
findSpace(container, item, &x, &y,
nullptr);
124 const int checkedTo = inv->
canHoldItem(container, item->
def(), x, y,
nullptr);
167 if (container->
single || ic == fItem) {
178 Com_Printf(
"removeFromInventory: Error: single container %s has many items. (%s)\n", container->
name,
invName);
211 previous->setNext(ic->
getNext());
247 if (from == to && fItem->
getX() == tx && fItem->
getY() == ty)
250 int time = from->
out + to->
in;
258 if (TU && *TU < time)
271 Item* item =
nullptr;
309 inv->
findSpace(to, fItem, &tx, &ty, fItem);
318 bool alreadyRemovedSource =
false;
319 if (to->
armour && from != to && !checkedTo) {
322 const int cacheFromX = fItem->
getX();
323 const int cacheFromY = fItem->
getY();
328 if (fItem->
def() == icTo->
def())
336 alreadyRemovedSource =
true;
341 moveInInventory(inv, to, icTo, from, cacheFromX, cacheFromY, TU, uponItem);
346 }
else if (!checkedTo) {
359 if (!TU || *TU >= time) {
374 if (
addToInventory(inv, &item, from, cacheFromX, cacheFromY, 1) ==
nullptr)
375 Sys_Error(
"Could not reload the weapon - add to inventory failed (%s)",
invName);
399 if (ic && to->
temp) {
404 inv->
findSpace(to, fItem, &tx, &ty, fItem);
421 Com_Printf(
"MoveInInventory: Item doesn't fit into container.");
437 if (!alreadyRemovedSource)
474 inv->
findSpace(container, item, &x, &y,
nullptr);
480 const int checkedTo = inv->
canHoldItem(container, item->
def(), x, y,
nullptr);
485 Item itemRotation = *item;
486 itemRotation.
rotated = rotated;
488 return addToInventory(inv, &itemRotation, container, x, y, 1) !=
nullptr;
546 next = ic->getNext();
547 const fireDef_t* fireDef = ic->getSlowestFireDef();
548 if (slowestFd == 0 || (fireDef && fireDef->
time > slowestFd))
549 slowestFd = fireDef->
time;
555 #define WEAPONLESS_BONUS 0.4
574 item.setAmmoLeft(weapon->
ammo);
575 item.setAmmoDef(weapon);
579 item.setAmmoDef(weapon);
583 int totalAvailableAmmo = 0;
587 totalAvailableAmmo++;
590 if (totalAvailableAmmo) {
591 int randNumber = rand() % totalAvailableAmmo;
596 if (randNumber < 0) {
605 Com_DPrintf(
DEBUG_SHARED,
"PackAmmoAndWeapon: no ammo for sidearm or primary weapon '%s' in equipment '%s' (%s).\n",
610 item.setAmmoLeft(weapon->
ammo);
611 item.setAmmoDef(ammo);
614 if (!item.ammoDef()) {
615 Com_Printf(
"PackAmmoAndWeapon: no ammo for sidearm or primary weapon '%s' in equipment '%s' (%s).\n",
638 if (!packed && allowLeft)
655 * (
float) (1.0f + missedPrimary / 100.0);
667 if (numpacked > ammoMult || numpacked * weapon->
ammo > 11)
695 Sys_Error(
"INVSH_EquipActorMelee: melee weapon %s for team %s is not firetwohanded! (%s)",
715 assert(weapon->
ammos[0]);
748 int missedPrimary = 0;
750 const objDef_t* primaryWeapon =
nullptr;
752 const int maxWeaponIdx = std::min(this->
csi->
numODs - 1, numEquip - 1);
753 int randNumber = rand() % 100;
754 for (
int i = 0;
i < maxWeaponIdx;
i++) {
759 if (!primaryWeapon && randNumber < 0)
772 for (ammo = 0; ammo < this->
csi->
numODs; ammo++)
773 if (ed->
numItems[ammo] && this->csi->ods[ammo].isLoadableInWeapon(primaryWeapon))
788 Com_DPrintf(
DEBUG_SHARED,
"INVSH_EquipActor: primary weapon '%s' couldn't be equipped in equipment '%s' (%s).\n",
796 int randNumber = rand() % 100;
797 const objDef_t* secondaryWeapon =
nullptr;
802 if (randNumber < 0) {
803 secondaryWeapon = obj;
809 if (secondaryWeapon) {
810 hasWeapon +=
PackAmmoAndWeapon(chr, secondaryWeapon, missedPrimary, ed, maxWeight);
812 }
while (!hasWeapon && repeat--);
834 int randNumber = rand() % sum;
835 const objDef_t* secondaryWeapon =
nullptr;
841 if (randNumber < 0) {
842 secondaryWeapon = obj;
848 if (secondaryWeapon) {
861 Com_DPrintf(
DEBUG_SHARED,
"INVSH_EquipActor: no weapon picked in equipment '%s', defaulting to the most expensive secondary weapon without reload. (%s)\n",
866 if (obj->
price > maxPrice) {
867 maxPrice = obj->
price;
877 Com_DPrintf(
DEBUG_SHARED,
"INVSH_EquipActor: cannot add any weapon; no secondary weapon without reload detected for equipment '%s' (%s).\n",
881 repeat = (float) missedPrimary >
frand() * 100.0;
890 int randNumber = rand() % 100;
895 if (randNumber < 0) {
896 const Item item(armour);
909 }
while (repeat-- > 0);
916 int randNumber = rand() % 10;
922 if (randNumber < 0) {
923 const bool oneShot = miscItem->
oneshot;
924 const Item item(miscItem, oneShot ? miscItem :
nullptr, oneShot ? miscItem->
ammo :
NONE_AMMO);
931 if (miscItem->headgear)
933 else if (miscItem->implant)
937 if (weight > maxWeight *
WEIGHT_FACTOR || tuNeed > maxTU || (itemFd && itemFd->
time > maxTU))
955 Com_Printf(
"EquipActor: weapon %s has no ammo assigned and must not be fired two handed\n", weapon->
id);
959 Com_Printf(
"EquipActor: actor with no equipment\n");
992 this->
import =
import;
1001 if (this->
import ==
nullptr)
1003 this->
import->FreeAll();
const objDef_t * onlyWeapon
#define SHAPE_BIG_MAX_HEIGHT
defines the max height of an inventory container
inventory_action_t
Possible inventory actions for moving items between containers.
bool tryAddToInventory(Inventory *const inv, const Item *const item, const invDef_t *container)
Tries to add an item to a container (in the inventory inv).
void destroyInventory(Inventory *const inv)
Destroys inventory.
void Sys_Error(const char *error,...)
void setAmmoLeft(int value)
this is a fire definition for our weapons/ammo
int PackAmmoAndWeapon(character_t *const chr, const objDef_t *weapon, int missedPrimary, const equipDef_t *ed, int maxWeight)
Pack a weapon, possibly with some ammo.
const teamDef_t * teamDef
void resetContainer(const containerIndex_t idx)
void * alloc(size_t size)
Item * getContainer2(const containerIndex_t idx) const
int getReloadTime() const
inventory_action_t moveInInventory(Inventory *const inv, const invDef_t *from, Item *item, const invDef_t *to, int tx, int ty, int *TU, Item **icp)
Conditions for moving items between containers.
bool isRightDef() const
Checks whether the inventory definition is the right Hand.
const objDef_t * def(void) const
invDef_t ids[MAX_INVDEFS]
bool isLeftDef() const
Checks whether a given inventory definition is of special type.
void Com_Printf(const char *const fmt,...)
bool isReloadable() const
bool isSameAs(const Item *const other) const
Check if the (physical) information of 2 items is exactly the same.
const struct objDef_s * ammos[MAX_AMMOS_PER_OBJDEF]
Defines all attributes of objects used in the inventory.
int getWeight() const
Return the weight of an item.
item instance data, with linked list capability
inventory definition with all its containers
#define SHAPE_BIG_MAX_WIDTH
32 bit mask
void findSpace(const invDef_t *container, const Item *item, int *const px, int *const py, const Item *ignoredItem) const
Finds space for item in inv at container.
void EquipActor(character_t *const chr, const equipDef_t *ed, const objDef_t *weapon, int maxWeight)
The csi structure is the client-server-information structure which contains all the static data neede...
int getWeight() const
Get the weight of the items in the given inventory (excluding those in temp containers).
void addAmount(int value)
void initInventory(const char *name, const csi_t *csi, const inventoryImport_t *import)
Initializes the inventory definition by linking the ->next pointers properly.
void EquipActorNormal(character_t *const chr, const equipDef_t *ed, int maxWeight)
Fully equip one actor. The equipment that is added to the inventory of the given actor is taken from ...
Item * addInvList(Inventory *const inv, const invDef_t *container)
int canHoldItem(const invDef_t *container, const objDef_t *od, const int x, const int y, const Item *ignoredItem) const
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Item * getNextItem(const Item *prev) const
void EquipActorRobot(Inventory *const inv, const objDef_t *weapon)
Equip robot actor with default weapon. (defined in ugv_t->weapon)
const Container & getContainer(const containerIndex_t idx) const
bool isLoadableInWeapon(const objDef_s *weapon) const
Checks if an item can be used to reload a weapon.
bool isFloorDef() const
Checks whether the inventory definition is the floor.
Item * addToInventory(Inventory *const inv, const Item *const item, const invDef_t *container, int x, int y, int amount) __attribute__((warn_unused_result))
Add an item to a specified container in a given inventory.
#define GET_ENCUMBRANCE_PENALTY(weight, max)
void EquipActorMelee(Inventory *const inv, const teamDef_t *td)
Equip melee actor with item defined per teamDefs.
float frand(void)
Return random values between 0 and 1.
equipPrimaryWeaponType_t
Types of weapon that can be selected.
const Container * getNextCont(const Container *prev, bool inclTemp=false) const
int numItems[MAX_OBJDEFS]
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void setAmmoDef(const objDef_t *od)
Item * getItemAtPos(const invDef_t *container, const int x, const int y) const
Searches if there is an item at location (x,y) in a container.
bool isArmourDef() const
Checks whether a given inventory definition is of special type.
const objDef_t * ammoDef(void) const
inventory definition for our menus
void setAmount(int value)
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
float GetInventoryState(const Inventory *inventory, int &slowestFd)
Get the state of the given inventory: the items weight and the min TU needed to make full use of all ...
objDef_t ods[MAX_OBJDEFS]
bool isEquipDef() const
Checks whether a given inventory definition is of special type.
const fireDef_t * getSlowestFireDef() const
Get the firedef that uses the most TU for this item.
void emptyContainer(Inventory *const inv, const containerIndex_t container)
Clears the linked list of a container - removes all items from this container.
void destroyInventoryInterface(void)
int skills[SKILL_NUM_TYPES]
void setContainer(const containerIndex_t idx, Item *cont)
bool removeFromInventory(Inventory *const inv, const invDef_t *container, Item *fItem) __attribute__((warn_unused_result))
void removeInvList(Item *invList)
int GetUsedSlots()
Calculate the number of used inventory slots.
Describes a character with all its attributes.