UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_actorshoothidden.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
32int CL_ActorShootHiddenTime (const eventRegister_t* self, dbuffer* msg, eventTiming_t* eventTiming)
33{
34 int dummy;
35 int first;
36 int objIdx;
37 weaponFireDefIndex_t weapFdsIdx;
38 fireDefIndex_t fireDefIndex;
39 vec3_t impact;
40
41 NET_ReadFormat(msg, self->formatString, &dummy, &first, &objIdx, &weapFdsIdx, &fireDefIndex, &impact, &dummy);
42
43 const int eventTime = first ? eventTiming->nextTime : eventTiming->shootTime;
44 const objDef_t* obj = INVSH_GetItemByIDX(objIdx);
45 if (first) {
46 eventTiming->nextTime = CL_GetNextTime(self, eventTiming, eventTiming->nextTime + 900);
47 eventTiming->impactTime = eventTiming->shootTime = eventTiming->nextTime;
48 } else {
49 const fireDef_t* fd = FIRESH_GetFiredef(obj, weapFdsIdx, fireDefIndex);
50 /* impact right away - we don't see it at all
51 * bouncing is not needed here, too (we still don't see it) */
52 eventTiming->impactTime = eventTiming->shootTime + 500;
53 eventTiming->nextTime = CL_GetNextTime(self, eventTiming, eventTiming->shootTime + 1400);
54 if (fd->delayBetweenShots > 0.0f)
55 eventTiming->shootTime += 1000 / fd->delayBetweenShots;
56 }
57 eventTiming->parsedDeath = false;
58
59 return eventTime;
60}
61
67{
68 int targetEntNo;
69 int first;
70 int objIdx;
71 weaponFireDefIndex_t weapFdsIdx;
72 fireDefIndex_t fdIdx;
73 vec3_t impact;
74 int flags;
75
76 NET_ReadFormat(msg, self->formatString, &targetEntNo, &first, &objIdx, &weapFdsIdx, &fdIdx, &impact, &flags);
77
78 /* target le */
79 const le_t* leTarget;
80 if (targetEntNo != SKIP_LOCAL_ENTITY) {
81 leTarget = LE_Get(targetEntNo);
82 if (!leTarget)
83 LE_NotFoundError(targetEntNo);
84 } else {
85 leTarget = nullptr;
86 }
87
88 /* get the fire def */
89 const objDef_t* obj = INVSH_GetItemByIDX(objIdx);
90 const fireDef_t* fd = FIRESH_GetFiredef(obj, weapFdsIdx, fdIdx);
91
92 /* start the sound */
93 if ((first || !fd->soundOnce) && fd->fireSound != nullptr)
95 if (!first) {
96 const char* sound = nullptr;
97 if (flags & SF_BODY)
98 sound = fd->hitBodySound;
99 else if ((flags & SF_IMPACT) || (fd->splrad && !fd->bounce))
100 sound = fd->impactSound;
101 else if (flags & SF_BOUNCING)
102 sound = fd->bounceSound;
103
104 if (Q_strvalid(sound) && !CL_OutsideMap(impact, 0.0f))
106 if (leTarget)
107 CL_ActorPlaySound(leTarget, SND_HURT);
108 }
109}
@ SND_HURT
Definition chr_shared.h:220
void CL_ActorPlaySound(const le_t *le, actorSound_t soundType)
Plays various sounds on actor action.
bool CL_OutsideMap(const vec3_t position, const float delta)
Checks whether give position is still inside the map borders.
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
#define LE_NotFoundError(entnum)
Primary header for client.
int CL_ActorShootHiddenTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
void CL_ActorShootHidden(const eventRegister_t *self, dbuffer *msg)
Shoot with weapon but don't bother with animations - actor is hidden.
int CL_GetNextTime(const eventRegister_t *event, eventTiming_t *eventTiming, int nextTime)
Definition e_main.cpp:203
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
const fireDef_t * FIRESH_GetFiredef(const objDef_t *obj, const weaponFireDefIndex_t weapFdsIdx, const fireDefIndex_t fdIdx)
Get the fire definitions for a given object.
int32_t weaponFireDefIndex_t
Definition inv_shared.h:77
int32_t fireDefIndex_t
Definition inv_shared.h:78
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 SKIP_LOCAL_ENTITY
Definition q_shared.h:255
#define SF_BODY
Definition q_shared.h:249
#define SF_IMPACT
Definition q_shared.h:248
#define SF_BOUNCING
Definition q_shared.h:250
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
#define Q_strvalid(string)
Definition shared.h:141
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
this is a fire definition for our weapons/ammo
Definition inv_shared.h:110
float fireAttenuation
Definition inv_shared.h:120
const char * fireSound
Definition inv_shared.h:117
float splrad
Definition inv_shared.h:161
float delayBetweenShots
Definition inv_shared.h:155
const char * hitBodySound
Definition inv_shared.h:116
const char * bounceSound
Definition inv_shared.h:118
bool soundOnce
Definition inv_shared.h:135
const char * impactSound
Definition inv_shared.h:114
float impactAttenuation
Definition inv_shared.h:121
a local entity
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
vec_t vec3_t[3]
Definition ufotypes.h:39