Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
speaker.qc File Reference
#include "speaker.qh"
Include dependency graph for speaker.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 spawnfunc (target_speaker)
void target_speaker_reset (entity this)
void target_speaker_use_activator (entity this, entity actor, entity trigger)
void target_speaker_use_off (entity this, entity actor, entity trigger)
void target_speaker_use_on (entity this, entity actor, entity trigger)

Function Documentation

◆ spawnfunc()

spawnfunc ( target_speaker )

Definition at line 79 of file speaker.qc.

80{
81 // TODO: "*" prefix to sound file name
82 // TODO: wait and random (just, HOW? random is not a field)
83 if(this.noise)
84 precache_sound (this.noise);
85
86 if(!this.atten && (this.spawnflags & SPEAKER_GLOBAL) && !(this.spawnflags & 3)) // special check for quake 3: looped sounds are never global
87 {
88 if (!Q3COMPAT_COMMON)
89 LOG_WARN("target_speaker uses legacy spawnflag GLOBAL (BIT(2)), please set atten to -1 instead");
90 this.atten = -1;
91 }
92
93 if(!this.atten)
94 {
95 if(this.targetname && this.targetname != "")
96 this.atten = ATTEN_NORM;
97 else
98 this.atten = ATTEN_STATIC;
99 }
100 else if(this.atten < 0)
101 this.atten = 0;
102
103 if(!this.volume)
104 this.volume = 1;
105
106 if(this.targetname && this.targetname != "")
107 {
110 else if(this.spawnflags & SPEAKER_LOOPED_ON)
111 {
113 this.reset = target_speaker_reset;
114 }
115 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
116 {
118 this.reset = target_speaker_reset;
119 }
120 else
122 }
123 else if(this.spawnflags & SPEAKER_LOOPED_ON)
124 {
125 ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten);
126 delete(this);
127 }
128 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
129 {
130 objerror(this, "This sound entity can never be activated");
131 }
132 else
133 {
134 // Quake/Nexuiz fallback
135 ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten);
136 delete(this);
137 }
138}
int spawnflags
Definition ammo.qh:15
#define Q3COMPAT_COMMON
Definition stats.qh:368
vector origin
#define use
#define LOG_WARN(...)
Definition log.qh:61
string precache_sound(string sample)
#define NULL
Definition post.qh:14
#define objerror
Definition pre.qh:8
const float VOL_BASE
Definition sound.qh:36
const float ATTEN_NORM
Definition sound.qh:30
const float ATTEN_STATIC
Definition sound.qh:33
void target_speaker_reset(entity this)
Definition speaker.qc:65
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:33
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

References atten, ATTEN_NORM, ATTEN_STATIC, LOG_WARN, noise, NULL, objerror, origin, precache_sound(), Q3COMPAT_COMMON, spawnflags, SPEAKER_ACTIVATOR, SPEAKER_GLOBAL, SPEAKER_LOOPED_OFF, SPEAKER_LOOPED_ON, target_speaker_reset(), target_speaker_use_activator(), target_speaker_use_on(), targetname, use, VOL_BASE, and volume.

◆ target_speaker_reset()

void target_speaker_reset ( entity this)

Definition at line 65 of file speaker.qc.

66{
68 {
69 if(this.use == target_speaker_use_on)
71 }
72 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
73 {
74 if(this.use == target_speaker_use_off)
76 }
77}
void target_speaker_use_off(entity this, entity actor, entity trigger)
Definition speaker.qc:60

References entity(), NULL, spawnflags, SPEAKER_LOOPED_OFF, SPEAKER_LOOPED_ON, target_speaker_use_off(), target_speaker_use_on(), and use.

Referenced by spawnfunc().

◆ target_speaker_use_activator()

void target_speaker_use_activator ( entity this,
entity actor,
entity trigger )

Definition at line 5 of file speaker.qc.

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;
21 n = stof(argv(1));
22 if(n > 0)
23 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
24 else
25 snd = strcat(argv(0), ".wav"); // randomization
26 }
27 }
28 else
29 snd = this.noise;
30 msg_entity = actor;
31 soundto(MSG_ONE, this, CH_TRIGGER, snd, VOL_BASE * this.volume, this.atten, 0);
32}
#define tokenize_console
string GetVoiceMessageSampleField(string type)
bool GetPlayerSoundSampleField_notFound
float MSG_ONE
Definition menudefs.qc:56
float stof(string val,...)
string substring(string s, float start, float length)
float random(void)
string ftos(float f)
float floor(float f)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
entity msg_entity
Definition progsdefs.qc:63
const int CH_TRIGGER
Definition sound.qh:12
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 IS_REAL_CLIENT(v)
Definition utils.qh:17

References argv(), atten, CH_TRIGGER, entity(), floor(), ftos(), GetPlayerSoundSampleField_notFound, GetVoiceMessageSampleField(), IS_REAL_CLIENT, msg_entity, MSG_ONE, noise, random(), SND, soundto(), stof(), strcat(), substring(), tokenize_console, VOL_BASE, and volume.

Referenced by spawnfunc().

◆ target_speaker_use_off()

void target_speaker_use_off ( entity this,
entity actor,
entity trigger )

Definition at line 60 of file speaker.qc.

61{
62 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASE * this.volume, this.atten);
64}
const int CH_TRIGGER_SINGLE
Definition sound.qh:13
#define sound(e, c, s, v, a)
Definition sound.qh:52

References atten, CH_TRIGGER_SINGLE, entity(), sound, target_speaker_use_on(), use, VOL_BASE, and volume.

Referenced by target_speaker_reset(), and target_speaker_use_on().

◆ target_speaker_use_on()

void target_speaker_use_on ( entity this,
entity actor,
entity trigger )

Definition at line 33 of file speaker.qc.

34{
35 string snd;
36 if(substring(this.noise, 0, 1) == "*")
37 {
38 var .string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1));
40 snd = SND(Null);
41 else if(actor.(sample) == "")
42 snd = SND(Null);
43 else
44 {
45 tokenize_console(actor.(sample));
46 float n;
47 n = stof(argv(1));
48 if(n > 0)
49 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
50 else
51 snd = strcat(argv(0), ".wav"); // randomization
52 }
53 }
54 else
55 snd = this.noise;
56 _sound(this, CH_TRIGGER_SINGLE, snd, VOL_BASE * this.volume, this.atten);
59}
#define _sound(e, c, s, v, a)
Definition sound.qh:43

References _sound, argv(), atten, CH_TRIGGER_SINGLE, entity(), floor(), ftos(), GetPlayerSoundSampleField_notFound, GetVoiceMessageSampleField(), noise, random(), SND, spawnflags, SPEAKER_LOOPED_OFF, SPEAKER_LOOPED_ON, stof(), strcat(), substring(), target_speaker_use_off(), tokenize_console, use, VOL_BASE, and volume.

Referenced by spawnfunc(), target_speaker_reset(), and target_speaker_use_off().