UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_invreload.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 "../../../cl_actor.h"
29#include "e_event_invreload.h"
30
31int 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
38void 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);
73
74 if (le == selActor)
75 Cmd_ExecuteString("hud_updateactorload");
76}
le_t * selActor
Definition cl_actor.cpp:49
equipDef_t * GAME_GetEquipmentDefinition(void)
Definition cl_game.cpp:1423
Shared game type headers.
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
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
int getAmmoLeft() const
Definition inv_shared.h:466
void setAmmoDef(const objDef_t *od)
Definition inv_shared.h:435
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
int CL_InvReloadTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
void CL_InvReload(const eventRegister_t *self, dbuffer *msg)
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
int32_t containerIndex_t
Definition inv_shared.h:46
#define MAX_INVDEFS
Definition inv_shared.h:368
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
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
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:307
#define SND_VOLUME_WEAPONS
Definition s_main.h:43
void addClip(const Item *item)
Combine the rounds of partially used clips.
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
a local entity
vec3_t origin
Inventory inv
float reloadAttenuation
Definition inv_shared.h:298
const char * reloadSound
Definition inv_shared.h:297