/** * @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; } }
/** * @brief Read the inventory from the clients team data * @param ent The actor's entity that should receive the items. */ static void G_ClientReadInventory (edict_t *ent) { /* inventory */ int nr = gi.ReadShort(); for (; nr-- > 0;) { const invDef_t *container; item_t item; int x, y; G_ReadItem(&item, &container, &x, &y); if (container->temp) gi.Error("G_ClientReadInventory failed, tried to add '%s' to a temp container %i", item.item->id, container->id); /* ignore the overload for now */ if (!INVSH_CheckAddingItemToInventory(&ent->chr.i, gi.csi->idEquip, container->id, item, ent->chr.score.skills[ABILITY_POWER])) Com_Printf("G_ClientReadInventory: Item %s exceeds ent %i weight capacity\n", item.item->id, ent->number); if (!level.noEquipment && game.i.AddToInventory(&game.i, &ent->chr.i, &item, container, x, y, 1) == NULL) gi.Error("G_ClientReadInventory failed, could not add item '%s' to container %i (x:%i,y:%i)", item.item->id, container->id, x, y); } }