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
583 int totalAvailableAmmo = 0;
584 for (
int i = 0;
i <
csi->numODs;
i++) {
587 totalAvailableAmmo++;
590 if (totalAvailableAmmo) {
591 int randNumber = rand() % totalAvailableAmmo;
592 for (
int i = 0;
i <
csi->numODs;
i++) {
596 if (randNumber < 0) {
605 Com_DPrintf(
DEBUG_SHARED,
"PackAmmoAndWeapon: no ammo for sidearm or primary weapon '%s' in equipment '%s' (%s).\n",
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))
775 if (ammo < this->
csi->numODs) {
777 !(this->
csi->ods[ammo].dmgtype == this->csi->damParticle)
779 && !(this->csi->ods[ammo].dmgtype == this->csi->damNormal)) {
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;
798 for (
int i = 0;
i < this->
csi->numODs;
i++) {
802 if (randNumber < 0) {
803 secondaryWeapon = obj;
809 if (secondaryWeapon) {
810 hasWeapon +=
PackAmmoAndWeapon(chr, secondaryWeapon, missedPrimary, ed, maxWeight);
812 }
while (!hasWeapon && repeat--);
822 for (
int i = 0;
i < this->
csi->numODs;
i++) {
834 int randNumber = rand() % sum;
835 const objDef_t* secondaryWeapon =
nullptr;
836 for (
int i = 0;
i < this->
csi->numODs;
i++) {
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",
863 for (
int i = 0;
i < this->
csi->numODs;
i++) {
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;
891 for (
int i = 0;
i < this->
csi->numODs;
i++) {
895 if (randNumber < 0) {
896 const Item item(armour);
909 }
while (repeat-- > 0);
916 int randNumber = rand() % 10;
917 for (
int i = 0;
i < this->
csi->numODs;
i++) {
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");
990 this->
import = import;
999 if (this->
import ==
nullptr)
1001 this->
import->FreeAll();
Item * getNextItem(const Item *prev) const
inventory definition with all its containers
int canHoldItem(const invDef_t *container, const objDef_t *od, const int x, const int y, const Item *ignoredItem) const
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.
int getWeight() const
Get the weight of the items in the given inventory (excluding those in temp containers).
void setContainer(const containerIndex_t idx, Item *cont)
void resetContainer(const containerIndex_t idx)
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.
const Container & getContainer(const containerIndex_t idx) const
Item * getContainer2(const containerIndex_t idx) const
const Container * getNextCont(const Container *prev, bool inclTemp=false) const
void destroyInventory(Inventory *const inv)
Destroys inventory.
void removeInvList(Item *invList)
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).
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.
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.
int GetUsedSlots()
Calculate the number of used inventory slots.
void EquipActorMelee(Inventory *const inv, const teamDef_t *td)
Equip melee actor with item defined per teamDefs.
const inventoryImport_t * import
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 ...
bool removeFromInventory(Inventory *const inv, const invDef_t *container, Item *fItem) __attribute__((warn_unused_result))
void EquipActor(character_t *const chr, const equipDef_t *ed, const objDef_t *weapon, int maxWeight)
void emptyContainer(Inventory *const inv, const containerIndex_t container)
Clears the linked list of a container - removes all items from this container.
void EquipActorRobot(Inventory *const inv, const objDef_t *weapon)
Equip robot actor with default weapon. (defined in ugv_t->weapon).
void destroyInventoryInterface(void)
void * alloc(size_t size)
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.
Item * addInvList(Inventory *const inv, const invDef_t *container)
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 ...
item instance data, with linked list capability
const objDef_t * ammoDef(void) const
void setAmount(int value)
void setAmmoDef(const objDef_t *od)
void addAmount(int value)
const objDef_t * def(void) const
const fireDef_t * getSlowestFireDef() const
Get the firedef that uses the most TU for this item.
int getWeight() const
Return the weight of an item.
bool isSameAs(const Item *const other) const
Check if the (physical) information of 2 items is exactly the same.
void setAmmoLeft(int value)
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
void Com_Printf(const char *const fmt,...)
void Sys_Error(const char *error,...)
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
#define SHAPE_BIG_MAX_WIDTH
32 bit mask
#define SHAPE_BIG_MAX_HEIGHT
defines the max height of an inventory container
inventory_action_t
Possible inventory actions for moving items between containers.
equipPrimaryWeaponType_t
Types of weapon that can be selected.
@ WEAPON_PARTICLE_OR_NORMAL
float frand(void)
Return random values between 0 and 1.
#define GET_ENCUMBRANCE_PENALTY(weight, max)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Describes a character with all its attributes.
const teamDef_t * teamDef
int skills[SKILL_NUM_TYPES]
The csi structure is the client-server-information structure which contains all the static data neede...
int numItems[MAX_OBJDEFS]
this is a fire definition for our weapons/ammo
inventory definition for our menus
bool isFloorDef() const
Checks whether the inventory definition is the floor.
bool isArmourDef() const
Checks whether a given inventory definition is of special type.
bool isLeftDef() const
Checks whether a given inventory definition is of special type.
bool isEquipDef() const
Checks whether a given inventory definition is of special type.
bool isRightDef() const
Checks whether the inventory definition is the right Hand.
Defines all attributes of objects used in the inventory.
const struct objDef_s * ammos[MAX_AMMOS_PER_OBJDEF]
int getReloadTime() const
bool isLoadableInWeapon(const objDef_s *weapon) const
Checks if an item can be used to reload a weapon.
bool isReloadable() const
const objDef_t * onlyWeapon