UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_invadd.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "../../../../client.h"
27#include "e_event_invadd.h"
28
35static void CL_NetReceiveItem (dbuffer* buf, Item* item, containerIndex_t* container, int* x, int* y)
36{
38
39 /* reset */
40 int itemIdx, ammoIdx;
41 int ammoleft = NONE_AMMO;
42 int amount = 0;
43 item->setDef(nullptr);
44 item->setAmmoDef(nullptr);
45 NET_ReadFormat(buf, eventData->formatString, &itemIdx, &ammoleft, &ammoIdx, container, x, y, &item->rotated, &amount);
46 item->setAmmoLeft(ammoleft);
47 item->setAmount(amount);
48 item->setDef(INVSH_GetItemByIDX(itemIdx));
49 item->setAmmoDef(INVSH_GetItemByIDX(ammoIdx));
50
51 if (!item->def())
52 Com_Error(ERR_DROP, "no weapon given for item");
53}
54
58int CL_InvAddTime (const struct eventRegister_s* self, dbuffer* msg, eventTiming_t* eventTiming)
59{
60 if (eventTiming->parsedShot) {
61 if (eventTiming->parsedDeath) { /* drop items after death (caused by impact) */
62 /* EV_INV_ADD messages are the last events sent after a death */
65 eventTiming->parsedDeath = false;
66 return eventTiming->impactTime + 1400;
67 } else if (eventTiming->impactTime > cl.time) { /* item thrown on the ground */
68 return eventTiming->impactTime + 75;
69 }
70 }
71
72 return eventTiming->nextTime;
73}
74
80void CL_InvAdd (const eventRegister_t* self, dbuffer* msg)
81{
82 const int number = NET_ReadShort(msg);
83 le_t* le = LE_Get(number);
84 int nr = NET_ReadShort(msg);
85
86 if (!le)
87 LE_NotFoundError(number);
88
90
91 for (; nr-- > 0;) {
92 Item item;
93 containerIndex_t container;
94 int x, y;
95 CL_NetReceiveItem(msg, &item, &container, &x, &y);
96
97 if (LE_IsItem(le)) {
98 if (container != CID_FLOOR)
99 Com_Error(ERR_DROP, "InvAdd for ET_ITEM but target container is not the floor but %i", container);
100 } else if (INVDEF(container)->temp) {
101 Com_Error(ERR_DROP, "InvAdd for %i to temp container %i", le->type, container);
102 }
103
104 if (cls.i.addToInventory(&le->inv, &item, INVDEF(container), x, y, item.getAmount()) == nullptr)
105 Com_Error(ERR_DROP, "InvAdd failed - could not add %i item(s) of %s to container %i",
106 item.getAmount(), item.def()->id, container);
107
108 if (container == CID_RIGHT)
109 le->right = item.def()->idx;
110 else if (container == CID_LEFT)
111 le->left = item.def()->idx;
112 else if (container == CID_HEADGEAR)
113 le->headgear = item.def()->idx;
114 }
115
116 switch (le->type) {
117 case ET_ACTOR:
118 case ET_ACTOR2x2:
119 if (LE_IsSelected(le))
120 Cmd_ExecuteString("hud_updateactorload");
122 break;
123 case ET_ITEM:
124 LE_PlaceItem(le);
125 break;
126 default:
127 break;
128 }
129}
clientBattleScape_t cl
void LE_SetThink(le_t *le, localEntityThinkFunc_t think)
void LE_PlaceItem(le_t *le)
void LET_StartIdle(le_t *le)
Change the animation of an actor to the idle animation (which can be panic, dead or stand).
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
#define LE_REMOVE_NEXT_FRAME
#define LE_IsItem(le)
#define LE_IsSelected(le)
#define LE_NotFoundError(entnum)
client_static_t cls
Definition cl_main.cpp:83
#define INVDEF(containerID)
Definition cl_shared.h:48
item instance data, with linked list capability
Definition inv_shared.h:402
void setAmount(int value)
Definition inv_shared.h:438
void setAmmoDef(const objDef_t *od)
Definition inv_shared.h:435
int rotated
Definition inv_shared.h:412
int getAmount() const
Definition inv_shared.h:463
void setDef(const objDef_t *objDef)
Definition inv_shared.h:444
const objDef_t * def(void) const
Definition inv_shared.h:469
void setAmmoLeft(int value)
Definition inv_shared.h:441
Primary header for client.
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition cmd.cpp:1007
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
#define ERR_DROP
Definition common.h:211
#define NONE_AMMO
Definition defines.h:69
int CL_InvAddTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_InvAdd(const eventRegister_t *self, dbuffer *msg)
static void CL_NetReceiveItem(dbuffer *buf, Item *item, containerIndex_t *container, int *x, int *y)
const eventRegister_t * CL_GetEvent(const event_t eType)
Definition e_main.cpp:157
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
#define CID_HEADGEAR
Definition inv_shared.h:50
int32_t containerIndex_t
Definition inv_shared.h:46
#define CID_FLOOR
Definition inv_shared.h:55
#define CID_LEFT
Definition inv_shared.h:48
#define CID_RIGHT
Definition inv_shared.h:47
voidpf void * buf
Definition ioapi.h:42
void NET_ReadFormat(dbuffer *buf, const char *format,...)
The user-friendly version of NET_ReadFormat that reads variable arguments from a buffer according to ...
Definition netpack.cpp:533
int NET_ReadShort(dbuffer *buf)
Definition netpack.cpp:242
@ EV_INV_TRANSFER
Definition q_shared.h:124
@ ET_ACTOR
Definition q_shared.h:148
@ ET_ACTOR2x2
Definition q_shared.h:160
@ ET_ITEM
Definition q_shared.h:149
Struct that defines one particular event with all its callbacks and data.
Definition e_main.h:42
const char * formatString
The format string that is used to write and parse this event.
Definition e_main.h:54
CL_ParseEvent timers and vars.
Definition e_main.h:30
int nextTime
Definition e_main.h:31
int impactTime
Definition e_main.h:33
bool parsedDeath
Definition e_main.h:35
bool parsedShot
Definition e_main.h:36
a local entity
int flags
entity_type_t type
int headgear
Inventory inv
const char * id
Definition inv_shared.h:268