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