UFO: Alien Invasion
Loading...
Searching...
No Matches
e_event_sound.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"
28#include "e_event_sound.h"
29
30int CL_SoundEventTime (const struct eventRegister_s* self, dbuffer* msg, eventTiming_t* eventTiming)
31{
32 char sound[MAX_QPATH];
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
60void CL_SoundEvent (const eventRegister_t* self, dbuffer* msg)
61{
62 char sound[MAX_QPATH];
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}
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
clientBattleScape_t cl
bool LE_IsLivingActor(const le_t *le)
Checks whether the given le is a living actor (but might be hidden).
le_t * LE_Get(int entnum)
Searches all local entities for the one with the searched entnum.
#define LE_IsDoor(le)
#define LE_IsBreakable(le)
#define LE_NotFoundError(entnum)
client_static_t cls
Definition cl_main.cpp:83
Primary header for client.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
Definition common.cpp:440
#define SOUND_ATTN_NORM
Definition common.h:186
#define MAX_ROUTE
Definition defines.h:84
#define DEBUG_SOUND
Definition defines.h:63
void CL_SoundEvent(const eventRegister_t *self, dbuffer *msg)
Play a sound on the client side.
int CL_SoundEventTime(const struct eventRegister_s *self, dbuffer *msg, eventTiming_t *eventTiming)
const char * CL_ConvertSoundFromEvent(char *sound, size_t size)
Some sound strings may end on a '+' to indicate to use a random sound which can be identified by repl...
Definition e_main.cpp:219
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
voidpf uLong int origin
Definition ioapi.h:45
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:307
#define SND_VOLUME_DEFAULT
Definition s_main.h:42
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
a local entity
vec3_t origin
vec_t vec3_t[3]
Definition ufotypes.h:39
#define VectorCopy(src, dest)
Definition vector.h:51