UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
e_event_invreload.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 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_localentity.h"
27 #include "../../../cl_actor.h"
28 #include "../../../../cgame/cl_game.h"
29 #include "e_event_invreload.h"
30 
31 int CL_InvReloadTime (const eventRegister_t* self, dbuffer* msg, eventTiming_t* eventTiming)
32 {
33  const int eventTime = eventTiming->nextTime;
34  eventTiming->nextTime += 600;
35  return eventTime;
36 }
37 
38 void CL_InvReload (const eventRegister_t* self, dbuffer* msg)
39 {
40  int number;
41  int ammo, type, x, y;
42  containerIndex_t container;
43 
44  NET_ReadFormat(msg, self->formatString, &number, &ammo, &type, &container, &x, &y);
45 
46  le_t* le = LE_Get(number);
47  if (!le)
48  return;
49 
50  if (le->team != cls.team)
51  return;
52 
53  assert(container >= 0);
54  assert(container < MAX_INVDEFS);
55  Item* ic = le->inv.getItemAtPos(INVDEF(container), x, y);
56  if (!ic)
57  return;
58 
60 
61  /* if the displaced clip had any remaining bullets
62  * store them as loose, unless the removed clip was full */
64  if (ed && ic->getAmmoLeft() > 0 && ic->getAmmoLeft() != ic->def()->ammo) {
65  assert(ammo == ic->def()->ammo);
66  /* Accumulate loose ammo into clips (only accessible post-mission) */
67  ed->addClip(ic);
68  }
69 
70  /* set new ammo */
71  ic->setAmmoLeft(ammo);
72  ic->setAmmoDef(INVSH_GetItemByIDX(type));
73 
74  if (le == selActor)
75  Cmd_ExecuteString("hud_updateactorload");
76 }
equipDef_t * GAME_GetEquipmentDefinition(void)
Definition: cl_game.cpp:1614
void setAmmoLeft(int value)
Definition: inv_shared.h:441
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
int getAmmoLeft() const
Definition: inv_shared.h:466
float reloadAttenuation
Definition: inv_shared.h:298
void CL_InvReload(const eventRegister_t *self, dbuffer *msg)
const objDef_t * def(void) const
Definition: inv_shared.h:469
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
bool S_LoadAndPlaySample(const char *s, const vec3_t origin, float attenuation, float volume)
does what the name implies in just one function to avoid exposing s_sample_t
Definition: s_main.cpp:314
vec3_t origin
CL_ParseEvent timers and vars.
Definition: e_main.h:30
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition: cmd.cpp:1007
#define MAX_INVDEFS
Definition: inv_shared.h:368
client_static_t cls
Definition: cl_main.cpp:83
item instance data, with linked list capability
Definition: inv_shared.h:402
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
#define INVDEF(containerID)
Definition: cl_shared.h:47
Struct that defines one particular event with all its callbacks and data.
Definition: e_main.h:42
a local entity
Inventory inv
int32_t containerIndex_t
Definition: inv_shared.h:46
le_t * selActor
Definition: cl_actor.cpp:49
#define SND_VOLUME_WEAPONS
Definition: s_main.h:43
void setAmmoDef(const objDef_t *od)
Definition: inv_shared.h:435
int ammo
Definition: inv_shared.h:293
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
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
int team
int nextTime
Definition: e_main.h:31
const char * reloadSound
Definition: inv_shared.h:297
int CL_InvReloadTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)