]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/effects/qc/globalsound.qc
Merge branch 'master' into TimePath/notifications
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / globalsound.qc
index 4f942ef0cbf2fc85417f12f151c2b6b534d9398e..f13b231042d41fccbd9d265611e6ca04182b38b6 100644 (file)
@@ -1,18 +1,22 @@
 #include "globalsound.qh"
 
-#include "../common/ent_cs.qh"
+#include <common/ent_cs.qh>
 
 #ifdef IMPLEMENTATION
-       #include "../../animdecide.qh"
+       #include <common/animdecide.qh>
 
        #ifdef SVQC
-               #include "../../../server/cl_player.qh"
+               #include <server/cl_player.qh>
        #endif
 
        REGISTER_NET_TEMP(globalsound)
        REGISTER_NET_TEMP(playersound)
 
+       string GlobalSound_sample(string pair, float r);
+
        #ifdef SVQC
+               /** Use new sound handling. TODO: use when sounds play correctly on clients */
+               bool autocvar_g_debug_globalsounds = false;
                /**
                 * @param from the source entity, its position is sent
                 * @param gs the global sound def
                 */
                void globalsound(int channel, entity from, entity gs, float r, int chan, float vol, float atten)
                {
-                       assert(IS_PLAYER(from));
+                       assert(IS_PLAYER(from), eprint(from));
                        if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
+                       if (!autocvar_g_debug_globalsounds) {
+                               string sample = GlobalSound_sample(gs.m_globalsoundstr, r);
+                               switch (channel) {
+                                       case MSG_ONE:
+                                               soundto(channel, from, chan, sample, vol, atten);
+                                               break;
+                                       case MSG_ALL:
+                                               _sound(from, chan, sample, vol, atten);
+                                               break;
+                               }
+                               return;
+                       }
                        WriteHeader(channel, globalsound);
                        WriteByte(channel, gs.m_id);
                        WriteByte(channel, r * 255);
                */
                void playersound(int channel, entity from, entity ps, float r, int chan, float vol, float atten)
                {
-                       assert(IS_PLAYER(from));
+                       assert(IS_PLAYER(from), eprint(from));
                        if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
+                       if (!autocvar_g_debug_globalsounds) {
+                               UpdatePlayerSounds(from);
+                               string s = from.(ps.m_playersoundfld);
+                               string sample = GlobalSound_sample(s, r);
+                               switch (channel) {
+                                       case MSG_ONE:
+                                               soundto(channel, from, chan, sample, vol, atten);
+                                               break;
+                                       case MSG_ALL:
+                                               _sound(from, chan, sample, vol, atten);
+                                               break;
+                               }
+                               return;
+                       }
                        WriteHeader(channel, playersound);
                        WriteByte(channel, ps.m_id);
                        WriteByte(channel, r * 255);
@@ -60,8 +90,6 @@
                }
        #endif
 
-       string GlobalSound_sample(string pair, float r);
-
        #ifdef CSQC
 
                NET_HANDLE(globalsound, bool isnew)
@@ -71,8 +99,7 @@
                        string sample = GlobalSound_sample(gs.m_globalsoundstr, r);
                        int who = ReadByte();
                        entity e = entcs_receiver(who - 1);
-                       int chan = ReadByte();
-                       chan = (chan & BIT(7) ? -1 : 1) * (chan & BITS(7));
+                       int chan = ReadSByte();
                        float vol = ReadByte() / 255;
                        float atten = ReadByte() / 64;
                        vector o;
                        UpdatePlayerSounds(e);
                        string s = e.(ps.m_playersoundfld);
                        string sample = GlobalSound_sample(s, r);
-                       int chan = ReadByte();
-                       chan = (chan & BIT(7) ? -1 : 1) * (chan & BITS(7));
+                       int chan = ReadSByte();
                        float vol = ReadByte() / 255;
                        float atten = ReadByte() / 64;
                        vector o;
                fclose(fh);
        }
 
-       #ifdef CSQC
+       //#ifdef CSQC
 
                .string GetPlayerSoundSampleField(string type)
                {
 
                void ClearPlayerSounds(entity this)
                {
-                       FOREACH(PlayerSounds, true, LAMBDA(
+                       FOREACH(PlayerSounds, true, {
                                .string fld = it.m_playersoundfld;
                                if (this.(fld))
-       {
-               strunzone(this.(fld));
-               this.(fld) = string_null;
-       }
-                                                             ));
+                               {
+                                       strunzone(this.(fld));
+                                       this.(fld) = string_null;
+                               }
+                       });
                }
 
                bool LoadPlayerSounds(entity this, string f, bool strict)
                        LoadPlayerSounds(this, get_model_datafilename(this.model, 0, "sounds"), true);
                }
 
-       #endif
+       //#endif
 
        #ifdef SVQC
 
                void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, int voicetype, bool fake)
                {
                        if (gs == NULL && ps == NULL && sample == "") return;
+                       if(this.classname == "body") return;
                        float r = random();
                        if (sample != "") sample = GlobalSound_sample(sample, r);
                        switch (voicetype)
                                case VOICETYPE_TEAMRADIO:
                                {
                                        #define X() \
-                                               do \
+                                               MACRO_BEGIN \
                                                { \
                                                        float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE; \
                                                        if (gs) globalsound(MSG_ONE, this, gs, r, chan, VOL_BASEVOICE, atten); \
                                                        else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASEVOICE, atten); \
                                                        else soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \
-                                               } \
-                                               while (0)
+                                               } MACRO_END
 
                                        if (fake) { msg_entity = this; X(); }
                                        else
                                        {
-                                               FOR_EACH_REALCLIENT(msg_entity)
-                                               {
-                                                       if (!teamplay || msg_entity.team == this.team) X();
-                                               }
+                                               FOREACH_CLIENT(IS_REAL_CLIENT(it) && (!teamplay || msg_entity.team == this.team), LAMBDA(
+                                                       msg_entity = it;
+                                                       X();
+                                               ));
                                        }
                #undef X
                                        break;
                                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,
+                                       else if (IS_PLAYER(this) && !IS_DEAD(this)) animdecide_setaction(this, ANIMACTION_TAUNT,
                                                        true);
                                        if (!sv_taunt) break;
                                        if (autocvar_sv_gentle) break;
                                        float tauntrand = 0;
                                        if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random();
                                        #define X() \
-                                               do \
+                                               MACRO_BEGIN \
                                                { \
                                                        if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt) \
                                                        { \
                                                                else if (ps) playersound(MSG_ONE, this, ps, r, chan, VOL_BASEVOICE, atten); \
                                                                else soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten); \
                                                        } \
-                                               } \
-                                               while (0)
+                                               } MACRO_END
                                        if (fake)
                                        {
                                                msg_entity = this;
                                        }
                                        else
                                        {
-                                               FOR_EACH_REALCLIENT(msg_entity)
-                                               {
+                                               FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+                                                       msg_entity = it;
                                                        X();
-                                               }
+                                               ));
                                        }
                #undef X
                                        break;