]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Globalsound: assert source is a player
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 3 Dec 2015 07:05:00 +0000 (18:05 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 3 Dec 2015 07:05:00 +0000 (18:05 +1100)
qcsrc/common/effects/qc/globalsound.qc
qcsrc/common/effects/qc/globalsound.qh
qcsrc/common/monsters/sv_monsters.qc
qcsrc/common/mutators/mutator/dodging/dodging.qc
qcsrc/common/physics.qc
qcsrc/lib/log.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/command/cmd.qc
qcsrc/server/playerdemo.qc
qcsrc/server/sv_main.qc

index c474f3b7ece34c657d955d697d6d795575b957f2..4f942ef0cbf2fc85417f12f151c2b6b534d9398e 100644 (file)
@@ -20,6 +20,7 @@
                 */
                void globalsound(int channel, entity from, entity gs, float r, int chan, float vol, float atten)
                {
+                       assert(IS_PLAYER(from));
                        if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
                        WriteHeader(channel, globalsound);
                        WriteByte(channel, gs.m_id);
@@ -42,6 +43,7 @@
                */
                void playersound(int channel, entity from, entity ps, float r, int chan, float vol, float atten)
                {
+                       assert(IS_PLAYER(from));
                        if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return;
                        WriteHeader(channel, playersound);
                        WriteByte(channel, ps.m_id);
 
        #ifdef SVQC
 
-               void _GlobalSound(entity gs, entity ps, string sample, int chan, int voicetype, bool fake)
+               void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, int voicetype, bool fake)
                {
-                       SELFPARAM();
                        if (gs == NULL && ps == NULL && sample == "") return;
                        float r = random();
                        if (sample != "") sample = GlobalSound_sample(sample, r);
index 4b86da5c8f6fda1cb51c139cf76ef1e7ad08bbd3..892d3d078b3dfb523f41c6bb59ea44d4eb8c0ec6 100644 (file)
@@ -121,11 +121,11 @@ void PrecachePlayerSounds(string f);
 
 #ifdef SVQC
 
-       void _GlobalSound(entity gs, entity ps, string sample, float chan, float voicetype, bool fake);
-       #define GlobalSound(def, chan, voicetype) _GlobalSound(def, NULL, string_null, chan, voicetype, false)
-       #define GlobalSound_string(def, chan, voicetype) _GlobalSound(NULL, NULL, def, chan, voicetype, false)
-       #define PlayerSound(def, chan, voicetype) _GlobalSound(NULL, def, string_null, chan, voicetype, false)
-       #define VoiceMessage(def, msg) \
+       void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float voicetype, bool fake);
+       #define GlobalSound(this, def, chan, voicetype) _GlobalSound(this, def, NULL, string_null, chan, voicetype, false)
+       #define GlobalSound_string(this, def, chan, voicetype) _GlobalSound(this, NULL, NULL, def, chan, voicetype, false)
+       #define PlayerSound(thise, def, chan, voicetype) _GlobalSound(this, NULL, def, string_null, chan, voicetype, false)
+       #define VoiceMessage(this, def, msg) \
                do \
                { \
                        entity VM = def; \
@@ -136,7 +136,7 @@ void PrecachePlayerSounds(string f);
                        if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \
                        else if (flood > 0) fake = false; \
                        else break; \
-                       _GlobalSound(NULL, VM, string_null, CH_VOICE, voicetype, fake); \
+                       _GlobalSound(this, NULL, VM, string_null, CH_VOICE, voicetype, fake); \
                } \
                while (0)
 
index 45fc349275768074459f11407fd5ccc94269b27f..e949e3a0d4969ac49d1c0d78c32e420390c8fe4d 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_string(self.(samplefield), chan, VOICETYPE_PLAYERSOUND);
+       GlobalSound_string(self, self.(samplefield), chan, VOICETYPE_PLAYERSOUND);
 
        self.msound_delay = time + sound_delay;
 }
index b25de6125e289f919606522652e0ec1723828f7b..3521ca77f7c838c05efa5094a9b4215f2f087c13 100644 (file)
@@ -226,7 +226,7 @@ void PM_dodging(entity this)
 
 #ifdef SVQC
                if (autocvar_sv_dodging_sound)
-                       PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+                       PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
 
                animdecide_setaction(this, ANIMACTION_JUMP, true);
 #endif
index 7a22ae1e53bb73521c690fc05a8c80f08f6aaed2..2fd3dbaa7a08e14b0dfa4e601648226929049213 100644 (file)
@@ -520,7 +520,7 @@ bool PlayerJump(entity this)
        animdecide_setaction(this, ANIMACTION_JUMP, true);
 
        if (autocvar_g_jump_grunt)
-               WITH(entity, self, this, PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND));
+               PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
 #endif
        return true;
 }
@@ -754,7 +754,7 @@ void PM_check_hitground(entity this)
     tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
     if ((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) return;
     entity fall = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) ? GS_FALL_METAL : GS_FALL;
-    WITH(entity, self, this, GlobalSound(fall, CH_PLAYER, VOICETYPE_PLAYERSOUND));
+    GlobalSound(this, fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
 #endif
 }
 
index 3e512a180658862f7aab518b50a96b64003f60ea..2a35e8e9a205a36570c88728a793f590eb879ba5 100644 (file)
        } \
        while (0)
 
-#define assert(expr, ...) \
+#define assert(expr, ...) _assert(LOG_WARNING, expr, __VA_ARGS__)
+#define ASSERT(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__)
+#define _assert(f, expr, then) \
        do \
        { \
-               if (!(expr)) LOG_WARNINGF(__VA_ARGS__); \
+               if (!(expr)) \
+               { \
+                       f("assertion failed: `" #expr "`\n"); \
+                       then; \
+               } \
        } \
        while (0)
 
+#define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)];
+
 #define _LOG(f, level, s) f("[::"level "] ["__FILE__ ":%s:%.0f] %s", __FUNC__, __LINE__, s)
 
 #define  LOG_FATAL(...) _LOG_FATAL(strcat("", __VA_ARGS__))
@@ -84,13 +92,4 @@ noref bool autocvar_prvm_backtraceforwarnings;
        } \
        while (0)
 
-#define ASSERT(expr) \
-       do \
-       { \
-               if (!(expr)) LOG_FATAL("assertion failed: " #expr "\n"); \
-       } \
-       while (0)
-
-#define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)];
-
 #endif
index e1b34a9bb9c91e3ad26a08937a10b31974bb2778..f68cff0a4a7aaa55c4652849ff053afe6534adf5 100644 (file)
@@ -2498,21 +2498,18 @@ void PlayerPreThink ()
        {
                self.teamkill_soundtime = 0;
 
-               setself(self.teamkill_soundsource);
-               entity oldpusher = self.pusher;
-               self.pusher = this;
-
-               PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
-
-               self.pusher = oldpusher;
-               setself(this);
+               entity e = self.teamkill_soundsource;
+               entity oldpusher = e.pusher;
+               e.pusher = this;
+               PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
+               e.pusher = oldpusher;
        }
 
        if(self.taunt_soundtime)
        if(time > self.taunt_soundtime)
        {
                self.taunt_soundtime = 0;
-               PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
+               PlayerSound(self, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
        }
 
        target_voicescript_next(self);
index 22ef4bdffa5d2283d8170677850ee443ad731bff..1b0e46038acf1c0696c124dd6afca95569c49b4a 100644 (file)
@@ -430,15 +430,15 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp
                                        // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
                                        {
                                                if(deathtype == DEATH_FALL.m_id)
-                                                       PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(self, playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 75) // TODO make a "gentle" version?
-                                                       PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(self, playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 50)
-                                                       PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(self, playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 25)
-                                                       PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(self, playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                                else
-                                                       PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                                                       PlayerSound(self, playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
                                        }
                                }
                        }
@@ -514,9 +514,9 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp
                if(sound_allowed(MSG_BROADCAST, attacker))
                {
                        if(deathtype == DEATH_DROWN.m_id)
-                               PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                               PlayerSound(self, playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
                        else
-                               PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
+                               PlayerSound(self, playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
                }
 
                // get rid of kill indicator
index 6cac1c4f0620fb5a224e6d8dd2c0a5a39a865873..573b9417f99f887859b34243b515c8c5ced79224 100644 (file)
@@ -607,8 +607,8 @@ void ClientCommand_voice(float request, float argc, string command)
                                        sprint(this, sprintf("Invalid voice. Use one of: %s\n", allvoicesamples));
                                        return;
                                }
-                               if (argc >= 3) VoiceMessage(e, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
-                               else VoiceMessage(e, "");
+                               if (argc >= 3) VoiceMessage(this, e, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)));
+                               else VoiceMessage(this, e, "");
 
                                return;
                        }
index f3e03424b18eb4f5f4e7c2eb2b7228aea92784da..5ca2c1ca99d4450c11ad86b526f23cfaa869ec74 100644 (file)
@@ -146,9 +146,9 @@ float playerdemo_read(entity this)
                PLAYERDEMO_FIELDS(playerdemo_read_)
                {
                        time = this.playerdemo_time;
-                       WITH(entity, this, this, PlayerPreThink());
+                       WITH(entity, self, this, PlayerPreThink());
                        // not running physics though... this is just so we can run weapon stuff
-                       WITH(entity, this, this, PlayerPostThink());
+                       WITH(entity, self, this, PlayerPostThink());
                }
                this.playerdemo_time = stof(fgets(this.playerdemo_fh));
                if(this.playerdemo_time == 0)
index a7dfb96775d8d272b13a1acf6e4f104b75a3f936..dd6ad7260f19eb41232ab4a31987ac264d42cca9 100644 (file)
@@ -54,7 +54,7 @@ void CreatureFrame ()
                                if (self.waterlevel != WATERLEVEL_SUBMERGED)
                                {
                                        if(self.air_finished < time)
-                                               PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+                                               PlayerSound(self, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
                                        self.air_finished = time + autocvar_g_balance_contents_drowndelay;
                                        self.dmg = 2;
                                }
@@ -161,9 +161,9 @@ void CreatureFrame ()
                                        if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
                                        {
                                                if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
-                                                       GlobalSound(GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+                                                       GlobalSound(self, GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND);
                                                else
-                                                       GlobalSound(GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+                                                       GlobalSound(self, GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND);
                                        }
                                }
                        }