UFO: Alien Invasion
e_event_invdel.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2022 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #include "../../../../client.h"
26 #include "../../../cl_actor.h"
27 #include "../../../cl_localentity.h"
28 #include "e_event_invdel.h"
29 
33 int 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 
48 void 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 }
Inventory inv
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.
Definition: inv_shared.cpp:844
int shootTime
Definition: e_main.h:32
#define LE_IsItem(le)
void CL_InvDel(const eventRegister_t *self, dbuffer *msg)
CL_ParseEvent timers and vars.
Definition: e_main.h:30
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
InventoryInterface i
Definition: client.h:101
bool parsedDeath
Definition: e_main.h:35
void LE_PlaceItem(le_t *le)
int right
void Com_Error(int code, const char *fmt,...)
Definition: common.cpp:417
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition: cmd.cpp:1007
#define CID_LEFT
Definition: inv_shared.h:48
Struct that defines one particular event with all its callbacks and data.
Definition: e_main.h:42
client_static_t cls
Definition: cl_main.cpp:83
item instance data, with linked list capability
Definition: inv_shared.h:402
#define CID_HEADGEAR
Definition: inv_shared.h:50
#define ERR_DROP
Definition: common.h:211
a local entity
int headgear
#define CID_RIGHT
Definition: inv_shared.h:47
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
int nextTime
Definition: e_main.h:31
int left
clientBattleScape_t cl
#define INVDEF(containerID)
Definition: cl_shared.h:48
bool parsedShot
Definition: e_main.h:36
int32_t containerIndex_t
Definition: inv_shared.h:46
le_t * selActor
Definition: cl_actor.cpp:49
int CL_InvDelTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
int impactTime
Definition: e_main.h:33
entity_type_t type
#define NONE
Definition: defines.h:68
void LE_SetThink(le_t *le, localEntityThinkFunc_t think)
void LET_StartIdle(le_t *le)
Change the animation of an actor to the idle animation (which can be panic, dead or stand) ...
bool removeFromInventory(Inventory *const inv, const invDef_t *container, Item *fItem) __attribute__((warn_unused_result))
Definition: inventory.cpp:152