From: TimePath Date: Sat, 7 Nov 2015 12:00:10 +0000 (+1100) Subject: FakeGlobalSound: merge with GlobalSound X-Git-Tag: xonotic-v0.8.2~1689 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=71978173d05cc2283d50299e6298c3ec2a4d406c;p=xonotic%2Fxonotic-data.pk3dir.git FakeGlobalSound: merge with GlobalSound --- diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 31e5d2784..a3610e17f 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -346,7 +346,7 @@ void Monster_Sound(.string samplefield, float sound_delay, float delaytoo, float if(delaytoo) if(time < self.msound_delay) return; // too early - _GlobalSound(self.(samplefield), chan, VOICETYPE_PLAYERSOUND); + _GlobalSound(self.(samplefield), chan, VOICETYPE_PLAYERSOUND, false); self.msound_delay = time + sound_delay; } diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index cd1ce6901..b49488b05 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -478,7 +478,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp PlayerScore_Add(self, SP_DMGTAKEN, realdmg); } } - + bool abot = (IS_BOT_CLIENT(attacker)); bool vbot = (IS_BOT_CLIENT(self)); @@ -1103,7 +1103,7 @@ void UpdatePlayerSounds(entity this) LoadPlayerSounds(get_model_datafilename(this.model, 0, "sounds"), true); } -void FakeGlobalSound(string sample, int chan, int voicetype) +void _GlobalSound(string sample, int chan, int voicetype, bool fake) { SELFPARAM(); if (sample == "") return; @@ -1121,113 +1121,89 @@ void FakeGlobalSound(string sample, int chan, int voicetype) case VOICETYPE_LASTATTACKER_ONLY: case VOICETYPE_LASTATTACKER: { - if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break; - msg_entity = this; - if (IS_REAL_CLIENT(msg_entity)) soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE); - break; - } - case VOICETYPE_TEAMRADIO: - { - msg_entity = this; - float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; - soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); - break; - } - case VOICETYPE_AUTOTAUNT: - case VOICETYPE_TAUNT: - { - if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) break; else {} - else if (IS_PLAYER(this) && this.deadflag == DEAD_NO) animdecide_setaction(this, ANIMACTION_TAUNT, true); - if (!sv_taunt) break; - if (autocvar_sv_gentle) break; - float tauntrand = 0; - if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random(); - msg_entity = this; - if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) + if (!fake) { - float atten = (msg_entity.cvar_cl_voice_directional >= 1) - ? bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX) - : ATTEN_NONE; - soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); + if (!this.pusher) break; + msg_entity = this.pusher; + if (IS_REAL_CLIENT(msg_entity)) + { + float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; + soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); + } } - break; - } - case VOICETYPE_PLAYERSOUND: - { - msg_entity = this; - soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NORM); - break; - } - default: - { - backtrace("Invalid voice type!"); - break; - } - } -} - -void _GlobalSound(string sample, int chan, int voicetype) -{ - SELFPARAM(); - if (sample == "") return; - int n; - { - string s = cdr(sample); - if (s) n = stof(s); - else n = 0; - } - sample = car(sample); - if (n > 0) sample = sprintf("%s%d.wav", sample, floor(random() * n + 1)); // randomization - else sample = sprintf("%s.wav", sample); - switch (voicetype) - { - case VOICETYPE_LASTATTACKER_ONLY: - case VOICETYPE_LASTATTACKER: - { - if (!this.pusher) break; - msg_entity = this.pusher; - if (IS_REAL_CLIENT(msg_entity)) - { - float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; - soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); - } - if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break; + if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break; msg_entity = this; if (IS_REAL_CLIENT(msg_entity)) soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE); break; } case VOICETYPE_TEAMRADIO: { - FOR_EACH_REALCLIENT(msg_entity) - if (!teamplay || msg_entity.team == this.team) + #define X() \ + do \ + { \ + float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \ + soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \ + } \ + while (0) + + if (fake) { msg_entity = this; X(); } + else { - float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; - soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); + FOR_EACH_REALCLIENT(msg_entity) + { + if (!teamplay || msg_entity.team == this.team) X(); + } } + #undef X break; } case VOICETYPE_AUTOTAUNT: case VOICETYPE_TAUNT: { - if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) break; else {} + if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) { break; }else {} else if (IS_PLAYER(this) && this.deadflag == DEAD_NO) animdecide_setaction(this, ANIMACTION_TAUNT, true); if (!sv_taunt) break; if (autocvar_sv_gentle) break; float tauntrand = 0; if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random(); - FOR_EACH_REALCLIENT(msg_entity) - if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) + #define X() \ + do \ + { \ + if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) \ + { \ + float atten = (msg_entity.cvar_cl_voice_directional >= 1) \ + ? bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX) \ + : ATTEN_NONE; \ + soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \ + } \ + } \ + while (0) + if (fake) { - float atten = (msg_entity.cvar_cl_voice_directional >= 1) - ? bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX) - : ATTEN_NONE; - soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); + msg_entity = this; + X(); } + else + { + FOR_EACH_REALCLIENT(msg_entity) + { + X(); + } + } + #undef X break; } case VOICETYPE_PLAYERSOUND: { - _sound(this, chan, sample, VOL_BASE, ATTEN_NORM); + if (fake) + { + msg_entity = this; + soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NORM); + } + else + { + _sound(this, chan, sample, VOL_BASE, ATTEN_NORM); + } break; } default: @@ -1241,7 +1217,7 @@ void _GlobalSound(string sample, int chan, int voicetype) void PlayerSound(.string samplefield, int chan, float voicetype) { SELFPARAM(); - _GlobalSound(this.(samplefield), chan, voicetype); + _GlobalSound(this.(samplefield), chan, voicetype, false); } void VoiceMessage(string type, string msg) @@ -1256,9 +1232,9 @@ void VoiceMessage(string type, string msg) int voicetype = GetVoiceMessageVoiceType(type); bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); int flood = Say(this, ownteam, world, msg, true); - void(string sample, int chan, int voicetype) f; - f = (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) ? FakeGlobalSound - : (flood > 0) ? _GlobalSound - : func_null; - if (f) f(this.(sample), CH_VOICE, voicetype); + bool fake; + if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; + else if (flood > 0) fake = false; + else return; + _GlobalSound(this.(sample), CH_VOICE, voicetype, fake); } diff --git a/qcsrc/server/cl_player.qh b/qcsrc/server/cl_player.qh index ef27f6a63..b74b6f01c 100644 --- a/qcsrc/server/cl_player.qh +++ b/qcsrc/server/cl_player.qh @@ -93,9 +93,9 @@ void PrecachePlayerSounds(string f); void ClearPlayerSounds(entity this); float LoadPlayerSounds(string f, bool strict); void UpdatePlayerSounds(entity this); -void FakeGlobalSound(string sample, float chan, float voicetype); -void _GlobalSound(string sample, float chan, float voicetype); -#define GlobalSound(def, chan, voicetype) _GlobalSound((def).m_globalsoundstr, chan, voicetype) +#define FakeGlobalSound(sample, chan, voicetype) _GlobalSound(sample, chan, voicetype, true) +void _GlobalSound(string sample, float chan, float voicetype, bool fake); +#define GlobalSound(def, chan, voicetype) _GlobalSound((def).m_globalsoundstr, chan, voicetype, false) void PlayerSound(.string samplefield, float chan, float voicetype); void VoiceMessage(string type, string msg);