Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
speaker.qc
Go to the documentation of this file.
1#include "speaker.qh"
2#ifdef SVQC
3// TODO add a way to do looped sounds with sound(); then complete this entity
4void target_speaker_use_off(entity this, entity actor, entity trigger);
6{
7 if (!IS_REAL_CLIENT(actor))
8 return;
9 string snd;
10 if(substring(this.noise, 0, 1) == "*")
11 {
12 var .string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1));
14 snd = SND(Null);
15 else if(actor.(sample) == "")
16 snd = SND(Null);
17 else
18 {
19 tokenize_console(actor.(sample));
20 float n = stof(argv(1));
21 if(n > 0)
22 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
23 else
24 snd = strcat(argv(0), ".wav"); // randomization
25 }
26 }
27 else
28 snd = this.noise;
29 msg_entity = actor;
30 soundto(MSG_ONE, this, CH_TRIGGER, snd, VOL_BASE * this.volume, this.atten, 0);
31}
32void target_speaker_use_on(entity this, entity actor, entity trigger)
33{
34 string snd;
35 if(substring(this.noise, 0, 1) == "*")
36 {
37 var .string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1));
39 snd = SND(Null);
40 else if(actor.(sample) == "")
41 snd = SND(Null);
42 else
43 {
44 tokenize_console(actor.(sample));
45 float n = stof(argv(1));
46 if(n > 0)
47 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
48 else
49 snd = strcat(argv(0), ".wav"); // randomization
50 }
51 }
52 else
53 snd = this.noise;
54 _sound(this, CH_TRIGGER_SINGLE, snd, VOL_BASE * this.volume, this.atten);
57}
58void target_speaker_use_off(entity this, entity actor, entity trigger)
59{
60 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASE * this.volume, this.atten);
62}
64{
66 {
67 if(this.use == target_speaker_use_on)
69 }
70 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
71 {
72 if(this.use == target_speaker_use_off)
74 }
75}
76
77spawnfunc(target_speaker)
78{
79 // TODO: "*" prefix to sound file name
80 // TODO: wait and random (just, HOW? random is not a field)
81 if(this.noise)
82 precache_sound (this.noise);
83
84 if(!this.atten && (this.spawnflags & SPEAKER_GLOBAL) && !(this.spawnflags & 3)) // special check for quake 3: looped sounds are never global
85 {
86 if (!Q3COMPAT_COMMON)
87 LOG_WARN("target_speaker uses legacy spawnflag GLOBAL (BIT(2)), please set atten to -1 instead");
88 this.atten = -1;
89 }
90
91 if(!this.atten)
92 {
93 if(this.targetname && this.targetname != "")
94 this.atten = ATTEN_NORM;
95 else
96 this.atten = ATTEN_STATIC;
97 }
98 else if(this.atten < 0)
99 this.atten = 0;
100
101 if(!this.volume)
102 this.volume = 1;
103
104 if(this.targetname && this.targetname != "")
105 {
108 else if(this.spawnflags & SPEAKER_LOOPED_ON)
109 {
111 this.reset = target_speaker_reset;
112 }
113 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
114 {
116 this.reset = target_speaker_reset;
117 }
118 else
120 }
121 else if(this.spawnflags & SPEAKER_LOOPED_ON)
122 {
123 ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten);
124 delete(this);
125 }
126 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
127 {
128 objerror(this, "This sound entity can never be activated");
129 }
130 else
131 {
132 // Quake/Nexuiz fallback
133 ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten);
134 delete(this);
135 }
136}
137#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
int spawnflags
Definition ammo.qh:15
#define Q3COMPAT_COMMON
Definition stats.qh:370
vector origin
#define use
#define tokenize_console
string GetVoiceMessageSampleField(string type)
bool GetPlayerSoundSampleField_notFound
#define LOG_WARN(...)
Definition log.qh:61
float MSG_ONE
Definition menudefs.qc:56
float stof(string val,...)
string substring(string s, float start, float length)
float random(void)
string precache_sound(string sample)
string ftos(float f)
float floor(float f)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
#define objerror
Definition pre.qh:8
entity msg_entity
Definition progsdefs.qc:63
const int CH_TRIGGER
Definition sound.qh:12
const int CH_TRIGGER_SINGLE
Definition sound.qh:13
const float VOL_BASE
Definition sound.qh:36
#define _sound(e, c, s, v, a)
Definition sound.qh:43
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
const float ATTEN_STATIC
Definition sound.qh:33
void soundto(int _dest, entity e, int chan, string samp, float vol, float _atten, float _pitch)
Definition all.qc:74
#define SND(id)
Definition all.qh:35
#define spawnfunc(id)
Definition spawnfunc.qh:96
void target_speaker_use_off(entity this, entity actor, entity trigger)
Definition speaker.qc:58
void target_speaker_reset(entity this)
Definition speaker.qc:63
void target_speaker_use_activator(entity this, entity actor, entity trigger)
Definition speaker.qc:5
void target_speaker_use_on(entity this, entity actor, entity trigger)
Definition speaker.qc:32
const int SPEAKER_ACTIVATOR
Definition speaker.qh:7
const int SPEAKER_GLOBAL
Definition speaker.qh:6
const int SPEAKER_LOOPED_ON
Definition speaker.qh:4
const int SPEAKER_LOOPED_OFF
Definition speaker.qh:5
string noise
Definition subs.qh:83
float volume
Definition triggers.qh:47
float atten
Definition triggers.qh:47
string targetname
Definition triggers.qh:56
#define IS_REAL_CLIENT(v)
Definition utils.qh:17