/** * @sa CL_InvDel * @sa G_SendInventory * @sa EV_INV_ADD */ void CL_InvAdd (const eventRegister_t *self, dbuffer *msg) { const int number = NET_ReadShort(msg); le_t *le = LE_Get(number); int nr = NET_ReadShort(msg); if (!le) LE_NotFoundError(number); le->removeNextFrame = false; for (; nr-- > 0;) { item_t item; containerIndex_t container; int x, y; CL_NetReceiveItem(msg, &item, &container, &x, &y); if (LE_IsItem(le)) { if (container != csi.idFloor) Com_Error(ERR_DROP, "InvAdd for ET_ITEM but target container is not the floor but %i", container); } else if (INVDEF(container)->temp) { Com_Error(ERR_DROP, "InvAdd for %i to temp container %i", le->type, container); } if (cls.i.AddToInventory(&cls.i, &le->i, &item, INVDEF(container), x, y, item.amount) == NULL) Com_Error(ERR_DROP, "InvAdd failed - could not add %i item(s) of %s to container %i", item.amount, item.item->id, container); if (container == csi.idRight) le->right = item.item->idx; else if (container == csi.idLeft) le->left = item.item->idx; else if (container == csi.idExtension) le->extension = item.item->idx; else if (container == csi.idHeadgear) le->headgear = item.item->idx; } switch (le->type) { case ET_ACTOR: case ET_ACTOR2x2: LE_SetThink(le, LET_StartIdle); break; case ET_ITEM: LE_PlaceItem(le); break; default: break; } }
/** * @sa CL_InvDel * @sa G_SendInventory * @sa EV_INV_ADD */ void CL_InvAdd (const eventRegister_t* self, dbuffer* msg) { const int number = NET_ReadShort(msg); le_t* le = LE_Get(number); int nr = NET_ReadShort(msg); if (!le) LE_NotFoundError(number); le->flags &= ~LE_REMOVE_NEXT_FRAME; for (; nr-- > 0;) { Item item; containerIndex_t container; int x, y; CL_NetReceiveItem(msg, &item, &container, &x, &y); if (LE_IsItem(le)) { if (container != CID_FLOOR) Com_Error(ERR_DROP, "InvAdd for ET_ITEM but target container is not the floor but %i", container); } else if (INVDEF(container)->temp) { Com_Error(ERR_DROP, "InvAdd for %i to temp container %i", le->type, container); } if (cls.i.addToInventory(&le->inv, &item, INVDEF(container), x, y, item.getAmount()) == nullptr) Com_Error(ERR_DROP, "InvAdd failed - could not add %i item(s) of %s to container %i", item.getAmount(), item.def()->id, container); if (container == CID_RIGHT) le->right = item.def()->idx; else if (container == CID_LEFT) le->left = item.def()->idx; else if (container == CID_HEADGEAR) le->headgear = item.def()->idx; } switch (le->type) { case ET_ACTOR: case ET_ACTOR2x2: if (LE_IsSelected(le)) Cmd_ExecuteString("hud_updateactorload"); LE_SetThink(le, LET_StartIdle); break; case ET_ITEM: LE_PlaceItem(le); break; default: break; } }
/** * @sa CL_InvAdd */ void CL_InvDel (const eventRegister_t *self, dbuffer *msg) { le_t *le; int number; int x, y; containerIndex_t container; invList_t *ic; NET_ReadFormat(msg, self->formatString, &number, &container, &x, &y); le = LE_Get(number); if (!le) Com_Error(ERR_DROP, "InvDel message ignored... LE not found\n"); /* update the local entity to ensure that the correct weapon/item is rendered in the battlescape */ if (container == csi.idRight) le->right = NONE; else if (container == csi.idLeft) le->left = NONE; else if (container == csi.idExtension) le->extension = NONE; else if (container == csi.idHeadgear) le->headgear = NONE; if (le->type == ET_ACTOR || le->type == ET_ACTOR2x2) LE_SetThink(le, LET_StartIdle); ic = INVSH_SearchInInventory(&le->i, INVDEF(container), x, y); /* ic can be null for other team actors - we don't the full inventory of them, only * the object index */ if (!ic) return; if (!cls.i.RemoveFromInventory(&cls.i, &le->i, INVDEF(container), ic)) Com_Error(ERR_DROP, "CL_InvDel: No item was removed from container %i", container); if (le == selActor) Cmd_ExecuteString("hud_updateactorload"); /* update the rendered item after it was removed from the floor container */ if (LE_IsItem(le)) LE_PlaceItem(le); }