]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
FakeGlobalSound: merge with GlobalSound
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Nov 2015 12:00:10 +0000 (23:00 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 7 Nov 2015 12:00:10 +0000 (23:00 +1100)
qcsrc/common/monsters/sv_monsters.qc
qcsrc/server/cl_player.qc
qcsrc/server/cl_player.qh

index 31e5d2784f5b2a460df6512412d214595d2873ad..a3610e17f7e76b27db8f694a1414d4603797ddca 100644 (file)
@@ -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;
 }
index cd1ce6901584266f0f8f52c1e5864fb19ef1a94e..b49488b0553701cb528de71fd1261c0326c38e65 100644 (file)
@@ -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);
 }
index ef27f6a636ec6ecccbe102ba405cb842e90f8aaa..b74b6f01c5ca89e71c9b76d9265aa32bd7cd2f9b 100644 (file)
@@ -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);