UFO: Alien Invasion
e_event_sound.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_localentity.h"
27 #include "../../../cl_actor.h"
28 #include "e_event_sound.h"
29 
30 int CL_SoundEventTime (const struct eventRegister_s* self, dbuffer* msg, eventTiming_t* eventTiming)
31 {
32  char sound[MAX_QPATH];
33  vec3_t origin;
34  int number;
35  int step;
36 
37  /* read data */
38  NET_ReadFormat(msg, self->formatString, &number, &origin, &step, &sound, sizeof(sound));
39 
40  const le_t* le = LE_Get(number);
41  if (!le)
42  LE_NotFoundError(number);
43  if (step >= MAX_ROUTE)
44  return eventTiming->nextTime;
45  const int stepTime = CL_GetStepTime(eventTiming, le, step);
46  if (eventTiming->shootTime > stepTime)
47  return eventTiming->impactTime;
48  return stepTime;
49 }
50 
60 void CL_SoundEvent (const eventRegister_t* self, dbuffer* msg)
61 {
62  char sound[MAX_QPATH];
63  vec3_t origin;
64  int number;
65  int step;
66 
67  /* read data */
68  NET_ReadFormat(msg, self->formatString, &number, &origin, &step, &sound, sizeof(sound));
69 
70  le_t* le = LE_Get(number);
71  if (le) {
72  if (LE_IsLivingActor(le) && le->team != cls.team) {
74  } else if (LE_IsDoor(le) || LE_IsBreakable(le)) {
76  }
77  }
78 
79  const char* file = CL_ConvertSoundFromEvent(sound, sizeof(sound));
80  Com_DPrintf(DEBUG_SOUND, "Play network sample %s at (%f:%f:%f)\n", file, origin[0], origin[1], origin[2]);
81  if (step >= 0 && step < MAX_ROUTE) {
82  le_t* closest = CL_ActorGetClosest(origin, cls.team);
83  if (closest != nullptr) {
84  vec3_t tmp;
85  VectorCopy(cl.cam.camorg, tmp);
86  VectorCopy(closest->origin, cl.cam.camorg);
88  VectorCopy(tmp, cl.cam.camorg);
89  }
90  return;
91  }
93 }
#define VectorCopy(src, dest)
Definition: vector.h:51
int shootTime
Definition: e_main.h:32
CL_ParseEvent timers and vars.
Definition: e_main.h:30
voidpf uLong int origin
Definition: ioapi.h:45
le_t * CL_ActorGetClosest(const vec3_t origin, int team)
Returns the actor that is closest to the given origin.
Definition: cl_actor.cpp:694
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
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
a local entity
const char * CL_ConvertSoundFromEvent(char *sound, size_t size)
Some sound strings may end on a &#39;+&#39; to indicate to use a random sound which can be identified by repl...
Definition: e_main.cpp:219
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
int nextTime
Definition: e_main.h:31
#define LE_IsBreakable(le)
#define MAX_ROUTE
Definition: defines.h:84
vec3_t camorg
Definition: cl_camera.h:32
clientBattleScape_t cl
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
int team
int CL_GetStepTime(const eventTiming_t *eventTiming, const le_t *le, int step)
Calculates the time when the given step was executed in the event chain.
Definition: e_main.cpp:177
#define MAX_QPATH
Definition: filesys.h:40
vec_t vec3_t[3]
Definition: ufotypes.h:39
#define SOUND_ATTN_NORM
Definition: common.h:186
int impactTime
Definition: e_main.h:33
#define DEBUG_SOUND
Definition: defines.h:63
bool LE_IsLivingActor(const le_t *le)
Checks whether the given le is a living actor (but might be hidden)
int CL_SoundEventTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
#define LE_IsDoor(le)
void CL_SoundEvent(const eventRegister_t *self, dbuffer *msg)
Play a sound on the client side.
#define SND_VOLUME_DEFAULT
Definition: s_main.h:42
#define LE_NotFoundError(entnum)