UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
e_event_actorshoothidden.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_actor.h"
28 
32 int 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 }
const char * bounceSound
Definition: inv_shared.h:118
#define SF_BODY
Definition: q_shared.h:249
this is a fire definition for our weapons/ammo
Definition: inv_shared.h:110
bool soundOnce
Definition: inv_shared.h:135
int CL_ActorShootHiddenTime(const eventRegister_t *self, dbuffer *msg, eventTiming_t *eventTiming)
Decides if following events should be delayed.
int CL_GetNextTime(const eventRegister_t *event, eventTiming_t *eventTiming, int nextTime)
Definition: e_main.cpp:203
void CL_ActorShootHidden(const eventRegister_t *self, dbuffer *msg)
Shoot with weapon but don't bother with animations - actor is hidden.
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
bool CL_OutsideMap(const vec3_t position, const float delta)
Checks whether give position is still inside the map borders.
float fireAttenuation
Definition: inv_shared.h:120
int shootTime
Definition: e_main.h:32
const char * hitBodySound
Definition: inv_shared.h:116
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
#define SF_BOUNCING
Definition: q_shared.h:250
const char * impactSound
Definition: inv_shared.h:114
#define Q_strvalid(string)
Definition: shared.h:141
CL_ParseEvent timers and vars.
Definition: e_main.h:30
#define SKIP_LOCAL_ENTITY
Definition: q_shared.h:255
float delayBetweenShots
Definition: inv_shared.h:155
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.
Definition: inv_shared.cpp:385
void CL_ActorPlaySound(const le_t *le, actorSound_t soundType)
Plays various sounds on actor action.
Definition: cl_actor.cpp:2134
float impactAttenuation
Definition: inv_shared.h:121
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
int32_t fireDefIndex_t
Definition: inv_shared.h:78
const char * fireSound
Definition: inv_shared.h:117
#define SF_IMPACT
Definition: q_shared.h:248
Struct that defines one particular event with all its callbacks and data.
Definition: e_main.h:42
int32_t weaponFireDefIndex_t
Definition: inv_shared.h:77
a local entity
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
#define SND_VOLUME_WEAPONS
Definition: s_main.h:43
bool parsedDeath
Definition: e_main.h:35
int impactTime
Definition: e_main.h:33
vec_t vec3_t[3]
Definition: ufotypes.h:39
float splrad
Definition: inv_shared.h:161
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 bounce
Definition: inv_shared.h:149
int nextTime
Definition: e_main.h:31
#define LE_NotFoundError(entnum)