Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
all.qc
Go to the documentation of this file.
1#include "all.qh"
2
3#ifdef SVQC
4#include <server/utils.qh>
5
7
8.entity realowner;
9bool sound_allowed(int to, entity e)
10{
11 if(!e) return true; // save on a few checks
12 for ( ; ; )
13 {
14 if (e.classname == "body") e = e.enemy;
15 else if (e.realowner && e.realowner != e) e = e.realowner;
16 else if (e.owner && e.owner != e) e = e.owner;
17 else break;
18 }
19 // sounds to self may always pass
20 if (to == MSG_ONE && e == msg_entity) return true;
21 // sounds by players can be removed
22 if (autocvar_bot_sound_monopoly && IS_REAL_CLIENT(e)) return false;
23 // anything else may pass
24 return true;
25}
26
28int precache_sound_index(string s) = #19;
29
30const int SVC_SOUND = 6;
31const int SVC_STOPSOUND = 16;
32
33const int SND_VOLUME = BIT(0);
34const int SND_ATTENUATION = BIT(1);
35const int SND_LARGEENTITY = BIT(3);
36const int SND_LARGESOUND = BIT(4);
37const int SND_SPEEDUSHORT4000 = BIT(5);
38
39void soundtoat(int to, entity e, vector o, int chan, string samp, float vol, float attenu, float _pitch)
40{
41 if (!sound_allowed(to, e)) return;
42 int entno = etof(e);
43 int idx = precache_sound_index(samp);
44 attenu = floor(attenu * 64);
45 vol = floor(vol * 255);
46 int sflags = 0;
47 int speed4000 = floor((_pitch * 0.01) * 4000 + 0.5);
48 if (vol != 255) sflags |= SND_VOLUME;
49 if (attenu != 64) sflags |= SND_ATTENUATION;
50 if (entno >= 8192 || chan < 0 || chan > 7) sflags |= SND_LARGEENTITY;
51 if (idx >= 256) sflags |= SND_LARGESOUND;
52 if (speed4000 && speed4000 != 4000) sflags |= SND_SPEEDUSHORT4000;
54 WriteByte(to, sflags);
55 if (sflags & SND_VOLUME) WriteByte(to, vol);
56 if (sflags & SND_ATTENUATION) WriteByte(to, attenu);
57 if (sflags & SND_SPEEDUSHORT4000) WriteShort(to, speed4000);
58 if (sflags & SND_LARGEENTITY)
59 {
60 WriteShort(to, entno);
61 WriteByte(to, chan);
62 }
63 else
64 {
65 WriteShort(to, (entno << 3) | chan);
66 }
67 if (sflags & SND_LARGESOUND) WriteShort(to, idx);
68 else WriteByte(to, idx);
69 WriteCoord(to, o.x);
70 WriteCoord(to, o.y);
71 WriteCoord(to, o.z);
72}
73
74void soundto(int _dest, entity e, int chan, string samp, float vol, float _atten, float _pitch)
75{
76 if (!sound_allowed(_dest, e)) return;
77 vector o = e.origin + 0.5 * (e.mins + e.maxs);
78 soundtoat(_dest, e, o, chan, samp, vol, _atten, _pitch);
79}
80void soundat(entity e, vector o, int chan, string samp, float vol, float _atten)
81{
82 soundtoat(((chan & 8) ? MSG_ALL : MSG_BROADCAST), e, o, chan, samp, vol, _atten, 0);
83}
84void stopsoundto(int _dest, entity e, int chan)
85{
86 if (!sound_allowed(_dest, e)) return;
87 int entno = etof(e);
88 if (entno >= 8192 || chan < 0 || chan > 7)
89 {
90 int idx = precache_sound_index(SND(Null));
91 int sflags = SND_LARGEENTITY;
92 if (idx >= 256) sflags |= SND_LARGESOUND;
93 WriteByte(_dest, SVC_SOUND);
94 WriteByte(_dest, sflags);
95 WriteShort(_dest, entno);
96 WriteByte(_dest, chan);
97 if (sflags & SND_LARGESOUND) WriteShort(_dest, idx);
98 else WriteByte(_dest, idx);
99 WriteCoord(_dest, e.origin.x);
100 WriteCoord(_dest, e.origin.y);
101 WriteCoord(_dest, e.origin.z);
102 }
103 else
104 {
105 WriteByte(_dest, SVC_STOPSOUND);
106 WriteShort(_dest, entno * 8 + chan);
107 }
108}
109void stopsound(entity e, int chan)
110{
111 if (!sound_allowed(MSG_BROADCAST, e)) return;
112 stopsoundto(MSG_BROADCAST, e, chan); // unreliable, gets there fast
113 stopsoundto(MSG_ALL, e, chan); // in case of packet loss
114}
115
116void play2(entity e, string filename)
117{
118 msg_entity = e;
119 soundtoat(MSG_ONE, NULL, '0 0 0', CH_INFO, filename, VOL_BASE, ATTEN_NONE, 0);
120}
121
122.float spamtime;
124float spamsound(entity e, int chan, Sound samp, float vol, float _atten)
125{
126 if (!sound_allowed(MSG_BROADCAST, e)) return false;
127 if (time > e.spamtime)
128 {
129 e.spamtime = time;
130 sound(e, chan, samp, vol, _atten);
131 return true;
132 }
133 return false;
134}
135
136void play2team(float t, string filename)
137{
138 if (autocvar_bot_sound_monopoly) return;
139 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.team == t, play2(it, filename));
140}
141
142void play2all(string samp)
143{
144 if (autocvar_bot_sound_monopoly) return;
146}
147
148#endif
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_PLAYER(s)
Definition player.qh:243
float time
float MSG_ONE
Definition menudefs.qc:56
void WriteShort(float data, float dest, float desto)
void WriteCoord(float data, float dest, float desto)
void WriteByte(float data, float dest, float desto)
float floor(float f)
float MSG_BROADCAST
Definition menudefs.qc:55
float MSG_ALL
Definition menudefs.qc:57
#define etof(e)
Definition misc.qh:25
#define NULL
Definition post.qh:14
entity msg_entity
Definition progsdefs.qc:63
vector
Definition self.qh:92
const float VOL_BASE
Definition sound.qh:36
const int CH_INFO
Definition sound.qh:6
const float ATTEN_NONE
Definition sound.qh:27
#define _sound(e, c, s, v, a)
Definition sound.qh:43
#define sound(e, c, s, v, a)
Definition sound.qh:52
bool autocvar_bot_sound_monopoly
Definition all.qc:6
const int SND_VOLUME
Definition all.qc:33
const int SVC_STOPSOUND
Definition all.qc:31
const int SND_ATTENUATION
Definition all.qc:34
const int SND_SPEEDUSHORT4000
Definition all.qc:37
void play2(entity e, string filename)
Definition all.qc:116
float spamtime
Definition all.qc:122
void play2team(float t, string filename)
Definition all.qc:136
const int SVC_SOUND
Definition all.qc:30
void stopsound(entity e, int chan)
Definition all.qc:109
const int SND_LARGEENTITY
Definition all.qc:35
int precache_sound_index(string s)
hack: string precache_sound(string s) = #19;
void play2all(string samp)
Definition all.qc:142
void stopsoundto(int _dest, entity e, int chan)
Definition all.qc:84
void soundtoat(int to, entity e, vector o, int chan, string samp, float vol, float attenu, float _pitch)
Definition all.qc:39
void soundto(int _dest, entity e, int chan, string samp, float vol, float _atten, float _pitch)
Definition all.qc:74
float spamsound(entity e, int chan, Sound samp, float vol, float _atten)
use this one if you might be causing spam (e.g.
Definition all.qc:124
void soundat(entity e, vector o, int chan, string samp, float vol, float _atten)
Definition all.qc:80
bool sound_allowed(int to, entity e)
Definition all.qc:9
const int SND_LARGESOUND
Definition all.qc:36
#define SND(id)
Definition all.qh:35
entity realowner
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50