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