-#ifndef GLOBALSOUND_H
-#define GLOBALSOUND_H
+#pragma once
+
+#ifdef SVQC
+ /** Use new sound handling. TODO: use when sounds play correctly on clients */
+ bool autocvar_g_debug_globalsounds = false;
+#endif
// player sounds, voice messages
-// TODO implemented fall and falling
-#define ALLPLAYERSOUNDS(X) \
- X(death) \
- X(drown) \
- X(fall) \
- X(falling) \
- X(gasp) \
- X(jump) \
- X(pain100) \
- X(pain25) \
- X(pain50) \
- X(pain75)
-
-#define ALLVOICEMSGS(X) \
- X(attack) \
- X(attackinfive) \
- X(coverme) \
- X(defend) \
- X(freelance) \
- X(incoming) \
- X(meet) \
- X(needhelp) \
- X(seenflag) \
- X(taunt) \
- X(teamshoot)
+
+.string m_playersoundstr;
+..string m_playersoundfld;
+
+REGISTRY(PlayerSounds, BITS(8) - 1)
+#define PlayerSounds_from(i) _PlayerSounds_from(i, NULL)
+#define REGISTER_PLAYERSOUND(id) \
+ .string _playersound_##id; \
+ REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \
+ { \
+ this.m_playersoundstr = #id; \
+ this.m_playersoundfld = _playersound_##id; \
+ }
+REGISTER_REGISTRY(PlayerSounds)
+REGISTRY_SORT(PlayerSounds)
+STATIC_INIT(PlayerSounds_renumber)
+{
+ FOREACH(PlayerSounds, true, it.m_id = i);
+}
+REGISTRY_CHECK(PlayerSounds)
+
+REGISTER_PLAYERSOUND(death)
+REGISTER_PLAYERSOUND(drown)
+REGISTER_PLAYERSOUND(fall)
+REGISTER_PLAYERSOUND(falling)
+REGISTER_PLAYERSOUND(gasp)
+REGISTER_PLAYERSOUND(jump)
+REGISTER_PLAYERSOUND(pain100)
+REGISTER_PLAYERSOUND(pain25)
+REGISTER_PLAYERSOUND(pain50)
+REGISTER_PLAYERSOUND(pain75)
+
+.bool instanceOfVoiceMessage;
+.int m_playersoundvt;
+#define REGISTER_VOICEMSG(id, vt) \
+ .string _playersound_##id; \
+ REGISTER(PlayerSounds, playersound, id, m_id, new_pure(VoiceMessage)) \
+ { \
+ this.instanceOfVoiceMessage = true; \
+ this.m_playersoundstr = #id; \
+ this.m_playersoundfld = _playersound_##id; \
+ this.m_playersoundvt = vt; \
+ }
+
+const int VOICETYPE_PLAYERSOUND = 10;
+const int VOICETYPE_TEAMRADIO = 11;
+const int VOICETYPE_LASTATTACKER = 12;
+const int VOICETYPE_LASTATTACKER_ONLY = 13;
+const int VOICETYPE_AUTOTAUNT = 14;
+const int VOICETYPE_TAUNT = 15;
+
+REGISTER_VOICEMSG(attack, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(attackinfive, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(coverme, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(defend, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(freelance, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(incoming, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(meet, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(needhelp, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(seenflag, VOICETYPE_TEAMRADIO)
+REGISTER_VOICEMSG(taunt, VOICETYPE_TAUNT)
+REGISTER_VOICEMSG(teamshoot, VOICETYPE_LASTATTACKER)
// reserved sound names for the future (some models lack sounds for them):
// _VOICEMSG(flagcarriertakingdamage)
REGISTRY(GlobalSounds, BITS(8) - 1)
#define GlobalSounds_from(i) _GlobalSounds_from(i, NULL)
#define REGISTER_GLOBALSOUND(id, str) \
- REGISTER(RegisterGlobalSounds, GS, GlobalSounds, id, m_id, new(GlobalSound)) \
+ REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \
{ \
- make_pure(this); \
this.m_globalsoundstr = str; \
}
-REGISTER_REGISTRY(RegisterGlobalSounds)
-REGISTRY_SORT(GlobalSounds, 0)
-STATIC_INIT(GlobalSounds_renumber) { FOREACH(GlobalSounds, true, LAMBDA(it.m_id = i)); }
+REGISTER_REGISTRY(GlobalSounds)
+REGISTRY_SORT(GlobalSounds)
+STATIC_INIT(GlobalSounds_renumber)
+{
+ FOREACH(GlobalSounds, true, it.m_id = i);
+}
REGISTRY_CHECK(GlobalSounds)
void PrecacheGlobalSound(string samplestring);
PRECACHE(GlobalSounds)
{
- FOREACH(GlobalSounds, true, LAMBDA(PrecacheGlobalSound(it.m_globalsoundstr)));
+ FOREACH(GlobalSounds, true, PrecacheGlobalSound(it.m_globalsoundstr));
}
REGISTER_GLOBALSOUND(STEP, "misc/footstep0 6")
REGISTER_GLOBALSOUND(FALL, "misc/hitground 4")
REGISTER_GLOBALSOUND(FALL_METAL, "misc/metalhitground 4")
-#ifdef SVQC
-
- #define X(m) .string playersound_##m;
- ALLPLAYERSOUNDS(X)
- ALLVOICEMSGS(X)
- #undef X
-
- bool GetPlayerSoundSampleField_notFound;
- float GetVoiceMessageVoiceType(string type);
+bool GetPlayerSoundSampleField_notFound;
+void PrecachePlayerSounds(string f);
+//#ifdef CSQC
.string GetVoiceMessageSampleField(string type);
.string GetPlayerSoundSampleField(string type);
- void PrecachePlayerSounds(string f);
void ClearPlayerSounds(entity this);
- float LoadPlayerSounds(string f, bool strict);
+ float LoadPlayerSounds(entity this, string f, bool strict);
void UpdatePlayerSounds(entity this);
- #define FakeGlobalSound(sample, chan, voicetype) _GlobalSound(NULL, sample, chan, voicetype, true)
- void _GlobalSound(entity gs, string sample, float chan, float voicetype, bool fake);
- #define GlobalSound(def, chan, voicetype) _GlobalSound(def, string_null, chan, voicetype, false)
- void PlayerSound(.string samplefield, float chan, float voicetype);
- void VoiceMessage(string type, string msg);
+//#endif
+entity GetVoiceMessage(string type);
-#endif
+#ifdef SVQC
+
+ void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float vol, float voicetype, bool fake);
+ #define GlobalSound(this, def, chan, vol, voicetype) _GlobalSound(this, def, NULL, string_null, chan, vol, voicetype, false)
+ #define GlobalSound_string(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, NULL, def, chan, vol, voicetype, false)
+ #define PlayerSound(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, def, string_null, chan, vol, voicetype, false)
+ #define VoiceMessage(this, def, msg) \
+ MACRO_BEGIN \
+ { \
+ entity VM = def; \
+ int voicetype = VM.m_playersoundvt; \
+ bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \
+ int flood = Say(this, ownteam, NULL, msg, true); \
+ bool fake; \
+ if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \
+ else if (flood > 0) fake = false; \
+ else break; \
+ _GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake); \
+ } MACRO_END
#endif
+
+string allvoicesamples;
+STATIC_INIT(allvoicesamples)
+{
+ FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr));
+ allvoicesamples = strzone(substring(allvoicesamples, 1, -1));
+}