]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/globalsound.qh
Purge autocvars.qh from the codebase, cvars are defined in the headers of the feature...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / globalsound.qh
1 #pragma once
2
3 #if defined(SVQC)
4         #include <server/chat.qh>
5 #endif
6
7 #ifdef SVQC
8         /** Use new sound handling. TODO: use when sounds play correctly on clients */
9         bool autocvar_g_debug_globalsounds = false;
10         bool autocvar_sv_taunt;
11         bool autocvar_sv_autotaunt;
12 #endif
13
14 // player sounds, voice messages
15
16 .string m_playersoundstr;
17 ..string m_playersoundfld;
18
19 REGISTRY(PlayerSounds, BITS(8) - 1)
20 #define REGISTER_PLAYERSOUND(id) \
21         .string _playersound_##id; \
22         REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \
23         { \
24                 this.m_playersoundstr = #id; \
25                 this.m_playersoundfld = _playersound_##id; \
26         }
27 REGISTER_REGISTRY(PlayerSounds)
28 REGISTRY_SORT(PlayerSounds)
29
30 REGISTRY_DEFINE_GET(PlayerSounds, NULL)
31 STATIC_INIT(PlayerSounds_renumber)
32 {
33         FOREACH(PlayerSounds, true, it.m_id = i);
34 }
35 REGISTRY_CHECK(PlayerSounds)
36
37 REGISTER_PLAYERSOUND(death)
38 REGISTER_PLAYERSOUND(drown)
39 REGISTER_PLAYERSOUND(fall)
40 REGISTER_PLAYERSOUND(falling)
41 REGISTER_PLAYERSOUND(gasp)
42 REGISTER_PLAYERSOUND(jump)
43 REGISTER_PLAYERSOUND(pain100)
44 REGISTER_PLAYERSOUND(pain25)
45 REGISTER_PLAYERSOUND(pain50)
46 REGISTER_PLAYERSOUND(pain75)
47
48 .bool instanceOfVoiceMessage;
49 .int m_playersoundvt;
50 #define REGISTER_VOICEMSG(id, vt, listed) \
51         .string _playersound_##id; \
52         REGISTER(PlayerSounds, playersound, id, m_id, new_pure(VoiceMessage)) \
53         { \
54                 this.instanceOfVoiceMessage = listed; \
55                 this.m_playersoundstr = #id; \
56                 this.m_playersoundfld = _playersound_##id; \
57                 this.m_playersoundvt = vt; \
58         }
59
60 const int VOICETYPE_PLAYERSOUND = 10;
61 const int VOICETYPE_TEAMRADIO = 11;
62 const int VOICETYPE_LASTATTACKER = 12;
63 const int VOICETYPE_LASTATTACKER_ONLY = 13;
64 const int VOICETYPE_AUTOTAUNT = 14;
65 const int VOICETYPE_TAUNT = 15;
66
67 REGISTER_VOICEMSG(attack, VOICETYPE_TEAMRADIO, true)
68 REGISTER_VOICEMSG(attackinfive, VOICETYPE_TEAMRADIO, true)
69 REGISTER_VOICEMSG(coverme, VOICETYPE_TEAMRADIO, true)
70 REGISTER_VOICEMSG(defend, VOICETYPE_TEAMRADIO, true)
71 REGISTER_VOICEMSG(freelance, VOICETYPE_TEAMRADIO, true)
72 REGISTER_VOICEMSG(incoming, VOICETYPE_TEAMRADIO, true)
73 REGISTER_VOICEMSG(meet, VOICETYPE_TEAMRADIO, true)
74 REGISTER_VOICEMSG(needhelp, VOICETYPE_TEAMRADIO, true)
75 REGISTER_VOICEMSG(seenflag, VOICETYPE_TEAMRADIO, true)
76 REGISTER_VOICEMSG(taunt, VOICETYPE_TAUNT, true)
77 REGISTER_VOICEMSG(teamshoot, VOICETYPE_LASTATTACKER, true)
78
79 //NOTE: some models lack sounds for these:
80 REGISTER_VOICEMSG(flagcarriertakingdamage, VOICETYPE_TEAMRADIO, false)
81 REGISTER_VOICEMSG(getflag, VOICETYPE_TEAMRADIO, false)
82 //NOTE: ALL models lack sounds for these (only available in default sounds currently):
83 REGISTER_VOICEMSG(affirmative, VOICETYPE_TEAMRADIO, false)
84 REGISTER_VOICEMSG(attacking, VOICETYPE_TEAMRADIO, false)
85 REGISTER_VOICEMSG(defending, VOICETYPE_TEAMRADIO, false)
86 REGISTER_VOICEMSG(roaming, VOICETYPE_TEAMRADIO, false)
87 REGISTER_VOICEMSG(onmyway, VOICETYPE_TEAMRADIO, false)
88 REGISTER_VOICEMSG(droppedflag, VOICETYPE_TEAMRADIO, false)
89 REGISTER_VOICEMSG(negative, VOICETYPE_TEAMRADIO, false)
90 REGISTER_VOICEMSG(seenenemy, VOICETYPE_TEAMRADIO, false)
91
92 .string m_globalsoundstr;
93 REGISTRY(GlobalSounds, BITS(8) - 1)
94 #define REGISTER_GLOBALSOUND(id, str) \
95         REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \
96         { \
97                 this.m_globalsoundstr = str; \
98         }
99 REGISTER_REGISTRY(GlobalSounds)
100 REGISTRY_SORT(GlobalSounds)
101
102 REGISTRY_DEFINE_GET(GlobalSounds, NULL)
103 STATIC_INIT(GlobalSounds_renumber)
104 {
105         FOREACH(GlobalSounds, true, it.m_id = i);
106 }
107 REGISTRY_CHECK(GlobalSounds)
108 void PrecacheGlobalSound(string samplestring);
109 PRECACHE(GlobalSounds)
110 {
111         FOREACH(GlobalSounds, true, PrecacheGlobalSound(it.m_globalsoundstr));
112 }
113
114 REGISTER_GLOBALSOUND(STEP, "misc/footstep0 6")
115 REGISTER_GLOBALSOUND(STEP_METAL, "misc/metalfootstep0 6")
116 REGISTER_GLOBALSOUND(FALL, "misc/hitground 4")
117 REGISTER_GLOBALSOUND(FALL_METAL, "misc/metalhitground 4")
118
119 bool GetPlayerSoundSampleField_notFound;
120 void PrecachePlayerSounds(string f);
121 //#ifdef CSQC
122         .string GetVoiceMessageSampleField(string type);
123         .string GetPlayerSoundSampleField(string type);
124         void ClearPlayerSounds(entity this);
125         float LoadPlayerSounds(entity this, string f, bool strict);
126         void UpdatePlayerSounds(entity this);
127 //#endif
128 entity GetVoiceMessage(string type);
129
130 string GlobalSound_sample(string pair, float r);
131
132 float GlobalSound_pitch(float _pitch);
133
134 #ifdef SVQC
135
136         void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float vol, float voicetype, bool fake);
137         #define GlobalSound(this, def, chan, vol, voicetype) _GlobalSound(this, def, NULL, string_null, chan, vol, voicetype, false)
138         #define GlobalSound_string(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, NULL, def, chan, vol, voicetype, false)
139         #define PlayerSound(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, def, string_null, chan, vol, voicetype, false)
140         #define VoiceMessage(this, def, msg) \
141                 MACRO_BEGIN \
142                         entity VM = def; \
143                         int voicetype = VM.m_playersoundvt; \
144                         bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \
145                         int flood = Say(this, ownteam, NULL, msg, true); \
146                         bool fake; \
147                         if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \
148                         else if (flood > 0) fake = false; \
149                         else break; \
150                         _GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake); \
151                 MACRO_END
152
153 #endif
154
155 string allvoicesamples;
156 STATIC_INIT(allvoicesamples)
157 {
158     FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr));
159     allvoicesamples = strzone(substring(allvoicesamples, 1, -1));
160 }