UFO: Alien Invasion
e_event_invammo.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_invammo.h"
29 
30 void CL_InvAmmo (const eventRegister_t* self, dbuffer* msg)
31 {
32  int number;
33  int ammo, type, x, y;
34  containerIndex_t container;
35 
36  NET_ReadFormat(msg, self->formatString, &number, &ammo, &type, &container, &x, &y);
37 
38  le_t* le = LE_Get(number);
39  if (!le) {
40  Com_DPrintf(DEBUG_CLIENT, "InvAmmo message ignored... LE not found\n");
41  return;
42  }
43 
44  if (le->team != cls.team)
45  return;
46 
47  assert(container >= 0);
48  assert(container < MAX_INVDEFS);
49  Item* item = le->inv.getItemAtPos(INVDEF(container), x, y);
50  if (!item)
51  return;
52 
53  /* set new ammo */
54  item->setAmmoLeft(ammo);
56 }
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
void setAmmoLeft(int value)
Definition: inv_shared.h:441
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
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
#define MAX_INVDEFS
Definition: inv_shared.h:368
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
a local entity
#define DEBUG_CLIENT
Definition: defines.h:59
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
void CL_InvAmmo(const eventRegister_t *self, dbuffer *msg)
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition: common.cpp:398
#define INVDEF(containerID)
Definition: cl_shared.h:48
int team
int32_t containerIndex_t
Definition: inv_shared.h:46
void setAmmoDef(const objDef_t *od)
Definition: inv_shared.h:435
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
Definition: inv_shared.cpp:266