e_event_invadd.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "../../../../client.h"
00026 #include "../../../cl_localentity.h"
00027 #include "../../../../cl_inventory.h"
00028 #include "e_event_invadd.h"
00029
00036 static void CL_NetReceiveItem (struct dbuffer *buf, item_t *item, containerIndex_t *container, int *x, int *y)
00037 {
00038 const eventRegister_t *eventData = CL_GetEvent(EV_INV_TRANSFER);
00039
00040
00041 int t, m;
00042 item->t = item->m = NULL;
00043 item->a = NONE_AMMO;
00044 NET_ReadFormat(buf, eventData->formatString, &t, &item->a, &m, container, x, y, &item->rotated, &item->amount);
00045
00046 item->t = INVSH_GetItemByIDX(t);
00047 item->m = INVSH_GetItemByIDX(m);
00048
00049 if (!item->t)
00050 Com_Error(ERR_DROP, "no weapon given for item");
00051 }
00052
00058 void CL_InvAdd (const eventRegister_t *self, struct dbuffer *msg)
00059 {
00060 const int number = NET_ReadShort(msg);
00061 le_t *le = LE_Get(number);
00062 int nr = NET_ReadShort(msg) / INV_INVENTORY_BYTES;
00063
00064 if (!le)
00065 Com_Error(ERR_DROP, "InvAdd message ignored... LE not found\n");
00066
00067 le->removeNextFrame = qfalse;
00068
00069 for (; nr-- > 0;) {
00070 item_t item;
00071 containerIndex_t container;
00072 int x, y;
00073 CL_NetReceiveItem(msg, &item, &container, &x, &y);
00074
00075 if (LE_IsItem(le) && container != csi.idFloor)
00076 Com_Error(ERR_DROP, "InvAdd for ET_ITEM but target container is not the floor but %i", container);
00077
00078 if (cls.i.AddToInventory(&cls.i, &le->i, item, INVDEF(container), x, y, item.amount) == NULL)
00079 Com_Error(ERR_DROP, "InvAdd failed - could not add %i item(s) of %s to container %i",
00080 item.amount, item.t->id, container);
00081
00082 if (container == csi.idRight)
00083 le->right = item.t->idx;
00084 else if (container == csi.idLeft)
00085 le->left = item.t->idx;
00086 else if (container == csi.idExtension)
00087 le->extension = item.t->idx;
00088 else if (container == csi.idHeadgear)
00089 le->headgear = item.t->idx;
00090 }
00091
00092 switch (le->type) {
00093 case ET_ACTOR:
00094 case ET_ACTOR2x2:
00095 LE_SetThink(le, LET_StartIdle);
00096 break;
00097 case ET_ITEM:
00098 LE_PlaceItem(le);
00099 break;
00100 default:
00101 break;
00102 }
00103 }
00104