UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_invdel.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"
26#include "../../../cl_actor.h"
28#include "e_event_invdel.h"
29
33int CL_InvDelTime (const struct eventRegister_s* self, dbuffer* msg, eventTiming_t* eventTiming)
34{
35 if (eventTiming->parsedShot) {
36 if (eventTiming->parsedDeath) { /* drop items after death (caused by impact) */
37 return eventTiming->impactTime + 1400;
38 } else if (eventTiming->impactTime > cl.time) { /* item thrown on the ground */
39 return eventTiming->shootTime + 75;
40 }
41 }
42 return eventTiming->nextTime;
43}
44
48void CL_InvDel (const eventRegister_t* self, dbuffer* msg)
49{
50 int number;
51 int x, y;
52 containerIndex_t container;
53
54 NET_ReadFormat(msg, self->formatString, &number, &container, &x, &y);
55
56 le_t* le = LE_Get(number);
57 if (!le)
58 Com_Error(ERR_DROP, "InvDel message ignored... LE not found\n");
59
60 /* update the local entity to ensure that the correct weapon/item is rendered in the battlescape */
61 if (container == CID_RIGHT)
62 le->right = NONE;
63 else if (container == CID_LEFT)
64 le->left = NONE;
65 else if (container == CID_HEADGEAR)
66 le->headgear = NONE;
67
68 if (le->type == ET_ACTOR || le->type == ET_ACTOR2x2)
70
71 Item* item = le->inv.getItemAtPos(INVDEF(container), x, y);
72 /* ic can be null for other team actors - we don't the full inventory of them, only
73 * the object index */
74 if (!item)
75 return;
76
77 if (!cls.i.removeFromInventory(&le->inv, INVDEF(container), item))
78 Com_Error(ERR_DROP, "CL_InvDel: No item was removed from container %i", container);
79
80 if (le == selActor)
81 Cmd_ExecuteString("hud_updateactorload");
82
83 /* update the rendered item after it was removed from the floor container */
84 if (LE_IsItem(le))
85 LE_PlaceItem(le);
86}
le_t * selActor
Definition cl_actor.cpp:49
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_IsItem(le)
client_static_t cls
Definition cl_main.cpp:83
#define INVDEF(containerID)
Definition cl_shared.h:48
Item * getItemAtPos(const invDef_t *container, const int x, const int y) const
Searches if there is an item at location (x,y) in a container.
item instance data, with linked list capability
Definition inv_shared.h:402
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
Definition defines.h:68
int CL_InvDelTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_InvDel(const eventRegister_t *self, dbuffer *msg)
#define CID_HEADGEAR
Definition inv_shared.h:50
int32_t containerIndex_t
Definition inv_shared.h:46
#define CID_LEFT
Definition inv_shared.h:48
#define CID_RIGHT
Definition inv_shared.h:47
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
@ ET_ACTOR
Definition q_shared.h:148
@ ET_ACTOR2x2
Definition q_shared.h:160
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 shootTime
Definition e_main.h:32
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
entity_type_t type
int headgear
Inventory inv