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