/** * @brief Move item between containers. * @param[in] inv Pointer to the inventory we are working on. * @param[in] toContainer Pointer to target container, to place the item in. * @param[in] toX target x position in the toContainer container. * @param[in] toY target y position in the toContainer container. * @param[in] fromContainer Pointer to source container, the item is in. * @param[in] fItem Pointer to item being moved. * @param[out] uponItem The item the moving item is eventually dropped upon. * @note If you set toX or toY to -1/NONE the item is automatically placed on * @note a free spot in the targetContainer * @return true if the move was successful. */ bool INV_MoveItem (inventory_t* inv, const invDef_t *toContainer, int toX, int toY, const invDef_t *fromContainer, invList_t *fItem, invList_t **uponItem) { int moved; if (toX >= SHAPE_BIG_MAX_WIDTH || toY >= SHAPE_BIG_MAX_HEIGHT) return false; if (!fItem) return false; if (!inv->canHoldItemWeight(fromContainer->id, toContainer->id, *fItem, GAME_GetChrMaxLoad(GAME_GetSelectedChr()))) { UI_Popup(_("Warning"), _("This soldier can not carry anything else.")); return false; } /* move the item */ moved = cls.i.moveInInventory(inv, fromContainer, fItem, toContainer, toX, toY, nullptr, uponItem); switch (moved) { case IA_MOVE: case IA_ARMOUR: case IA_RELOAD: case IA_RELOAD_SWAP: return true; default: return false; } }
/** * @brief Update the equipment weight for the selected actor. */ static void INV_UpdateActorLoad_f (void) { if (Cmd_Argc() < 2) { Com_Printf("Usage: %s <callback>\n", Cmd_Argv(0)); return; } const character_t* chr = GAME_GetSelectedChr(); if (chr == nullptr) return; const float invWeight = chr->inv.getWeight(); const int maxWeight = GAME_GetChrMaxLoad(chr); const float penalty = GET_ENCUMBRANCE_PENALTY(invWeight, maxWeight); const int normalTU = GET_TU(chr->score.skills[ABILITY_SPEED], 1.0f - WEIGHT_NORMAL_PENALTY); const int tus = GET_TU(chr->score.skills[ABILITY_SPEED], penalty); const int tuPenalty = tus - normalTU; int count = 0; const Container* cont = nullptr; while ((cont = chr->inv.getNextCont(cont))) { if (cont->def()->temp) continue; for (Item* invList = cont->_invList, *next; invList; invList = next) { next = invList->getNext(); const fireDef_t* fireDef = invList->getFiredefs(); if (fireDef == nullptr) continue; for (int i = 0; i < MAX_FIREDEFS_PER_WEAPON; i++) { if (fireDef[i].time <= 0) continue; if (fireDef[i].time <= tus) continue; if (count <= 0) Com_sprintf(popupText, sizeof(popupText), _("This soldier no longer has enough TUs to use the following items:\n\n")); Q_strcat(popupText, sizeof(popupText), "%s: %s (%i)\n", _(invList->def()->name), _(fireDef[i].name), fireDef[i].time); ++count; } } } if ((Cmd_Argc() < 3 || atoi(Cmd_Argv(2)) == 0) && count > 0) UI_Popup(_("Warning"), popupText); char label[MAX_VAR]; char tooltip[MAX_VAR]; Com_sprintf(label, sizeof(label), "%g/%i %s %s", invWeight / WEIGHT_FACTOR, maxWeight, _("Kg"), (count > 0 ? _("Warning!") : "")); Com_sprintf(tooltip, sizeof(tooltip), "%s %i (%+i)", _("TU:"), tus, tuPenalty); UI_ExecuteConfunc("%s \"%s\" \"%s\" %f %i", Cmd_Argv(1), label, tooltip, WEIGHT_NORMAL_PENALTY - (1.0f - penalty), count); }
/** * @brief Move item between containers. * @param[in] inv Pointer to the list where the item is currently in. * @param[in] toContainer Pointer to target container, to place the item in. * @param[in] px target x position in the toContainer container. * @param[in] py target y position in the toContainer container. * @param[in] fromContainer Pointer to source container, the item is in. * @param[in] fItem Pointer to item being moved. * @note If you set px or py to -1/NONE the item is automatically placed on * @note a free spot in the targetContainer * @return true if the move was successful. */ bool INV_MoveItem (inventory_t* inv, const invDef_t * toContainer, int px, int py, const invDef_t * fromContainer, invList_t *fItem, invList_t **tItem) { int moved; if (px >= SHAPE_BIG_MAX_WIDTH || py >= SHAPE_BIG_MAX_HEIGHT) return false; if (!fItem) return false; if (!INVSH_CheckAddingItemToInventory(inv, fromContainer->id, toContainer->id, fItem->item, GAME_GetChrMaxLoad(GAME_GetSelectedChr()))) { UI_Popup(_("Warning"), _("This soldier can not carry anything else.")); return false; } /* move the item */ moved = cls.i.MoveInInventory(&cls.i, inv, fromContainer, fItem, toContainer, px, py, NULL, tItem); switch (moved) { case IA_MOVE: case IA_ARMOUR: case IA_RELOAD: case IA_RELOAD_SWAP: return true; default: return false; } }