]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/superspec/superspec.qc
Merge branch 'terencehill/v_deathtilt_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / superspec / superspec.qc
index 887b1842345098eb42b9d70d2468feb04a0be58c..142f9d9ba54dce3d379993b0cbfc794336435896 100644 (file)
@@ -26,7 +26,7 @@ const float SSF_ITEMMSG = 4;
 bool superspec_Spectate(entity _player)
 {SELFPARAM();
        if(Spectate(_player) == 1)
-               self.classname = STR_SPECTATOR;
+           TRANSMUTE(Spectator, self);
 
        return true;
 }
@@ -101,52 +101,47 @@ MUTATOR_HOOKFUNCTION(superspec, ItemTouch)
 {SELFPARAM();
        entity _item = self;
 
-       entity e;
-       FOR_EACH_CLIENT(e) if (IS_SPEC(e) || IS_OBSERVER(e))
-       {
-               setself(e);
-               if(self.superspec_flags & SSF_ITEMMSG)
-                       if(superspec_filteritem(self, _item))
+       FOREACH_CLIENT(true, LAMBDA(
+               if(!IS_SPEC(it) && !IS_OBSERVER(it))
+                       continue;
+               if(it.superspec_flags & SSF_ITEMMSG)
+                       if(superspec_filteritem(it, _item))
                        {
-                               if(self.superspec_flags & SSF_VERBOSE)
-                                       superspec_msg("", "", self, sprintf("Player %s^7 just picked up ^3%s\n", other.netname, _item.netname), 1);
+                               if(it.superspec_flags & SSF_VERBOSE)
+                                       superspec_msg("", "", it, sprintf("Player %s^7 just picked up ^3%s\n", other.netname, _item.netname), 1);
                                else
-                                       superspec_msg("", "", self, sprintf("Player %s^7 just picked up ^3%s\n^8(%s^8)\n", other.netname, _item.netname, _item.classname), 1);
-                               if((self.autospec_flags & ASF_SSIM) && self.enemy != other)
+                                       superspec_msg("", "", it, sprintf("Player %s^7 just picked up ^3%s\n^8(%s^8)\n", other.netname, _item.netname, _item.classname), 1);
+                               if((it.autospec_flags & ASF_SSIM) && it.enemy != other)
                                {
-                                       superspec_Spectate(other);
-
-                                       setself(this);
+                                       WITHSELF(it, superspec_Spectate(other));
                                        return MUT_ITEMTOUCH_CONTINUE;
                                }
                        }
 
-               if((self.autospec_flags & ASF_SHIELD && _item.invincible_finished) ||
-                       (self.autospec_flags & ASF_STRENGTH && _item.strength_finished) ||
-                       (self.autospec_flags & ASF_MEGA_AR && _item.itemdef == ITEM_ArmorMega) ||
-                       (self.autospec_flags & ASF_MEGA_HP && _item.itemdef == ITEM_HealthMega) ||
-                       (self.autospec_flags & ASF_FLAG_GRAB && _item.classname == "item_flag_team"))
+               if((it.autospec_flags & ASF_SHIELD && _item.invincible_finished) ||
+                       (it.autospec_flags & ASF_STRENGTH && _item.strength_finished) ||
+                       (it.autospec_flags & ASF_MEGA_AR && _item.itemdef == ITEM_ArmorMega) ||
+                       (it.autospec_flags & ASF_MEGA_HP && _item.itemdef == ITEM_HealthMega) ||
+                       (it.autospec_flags & ASF_FLAG_GRAB && _item.classname == "item_flag_team"))
                {
 
-                       if((self.enemy != other) || IS_OBSERVER(self))
+                       if((it.enemy != other) || IS_OBSERVER(it))
                        {
-                               if(self.autospec_flags & ASF_OBSERVER_ONLY && !IS_OBSERVER(self))
+                               if(it.autospec_flags & ASF_OBSERVER_ONLY && !IS_OBSERVER(it))
                                {
-                                       if(self.superspec_flags & SSF_VERBOSE)
-                                               superspec_msg("", "", self, sprintf("^8Ignored that ^7%s^8 grabbed %s^8 since the observer_only option is ON\n", other.netname, _item.netname), 2);
+                                       if(it.superspec_flags & SSF_VERBOSE)
+                                               superspec_msg("", "", it, sprintf("^8Ignored that ^7%s^8 grabbed %s^8 since the observer_only option is ON\n", other.netname, _item.netname), 2);
                                }
                                else
                                {
-                                       if(self.autospec_flags & ASF_SHOWWHAT)
-                                               superspec_msg("", "", self, sprintf("^7Following %s^7 due to picking up %s\n", other.netname, _item.netname), 2);
+                                       if(it.autospec_flags & ASF_SHOWWHAT)
+                                               superspec_msg("", "", it, sprintf("^7Following %s^7 due to picking up %s\n", other.netname, _item.netname), 2);
 
-                                       superspec_Spectate(other);
+                                       WITHSELF(it, superspec_Spectate(other));
                                }
                        }
                }
-       }
-
-       setself(this);
+       ));
 
        return MUT_ITEMTOUCH_CONTINUE;
 }
@@ -344,12 +339,7 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand)
 
        if(cmd_name == "followpowerup")
        {
-               entity _player;
-               FOR_EACH_PLAYER(_player)
-               {
-                       if(_player.strength_finished > time || _player.invincible_finished > time)
-                               return superspec_Spectate(_player);
-               }
+               FOREACH_CLIENT(IS_PLAYER(it) && (it.strength_finished > time || it.invincible_finished > time), LAMBDA(return superspec_Spectate(it)));
 
                superspec_msg("", "", self, "No active powerup\n", 1);
                return true;
@@ -357,12 +347,7 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand)
 
        if(cmd_name == "followstrength")
        {
-               entity _player;
-               FOR_EACH_PLAYER(_player)
-               {
-                       if(_player.strength_finished > time)
-                               return superspec_Spectate(_player);
-               }
+               FOREACH_CLIENT(IS_PLAYER(it) && it.strength_finished > time, LAMBDA(return superspec_Spectate(it)));
 
                superspec_msg("", "", self, "No active Strength\n", 1);
                return true;
@@ -370,12 +355,7 @@ MUTATOR_HOOKFUNCTION(superspec, SV_ParseClientCommand)
 
        if(cmd_name == "followshield")
        {
-               entity _player;
-               FOR_EACH_PLAYER(_player)
-               {
-                       if(_player.invincible_finished > time)
-                               return superspec_Spectate(_player);
-               }
+               FOREACH_CLIENT(IS_PLAYER(it) && it.invincible_finished > time, LAMBDA(return superspec_Spectate(it)));
 
                superspec_msg("", "", self, "No active Shield\n", 1);
                return true;
@@ -397,8 +377,8 @@ MUTATOR_HOOKFUNCTION(superspec, BuildMutatorsPrettyString)
        return 0;
 }
 
-void superspec_hello()
-{SELFPARAM();
+void superspec_hello(entity this)
+{
        if(self.enemy.crypto_idfp == "")
                Send_Notification(NOTIF_ONE_ONLY, self.enemy, MSG_INFO, INFO_SUPERSPEC_MISSING_UID);
 
@@ -418,7 +398,7 @@ MUTATOR_HOOKFUNCTION(superspec, ClientConnect)
 
        entity _hello = spawn();
        _hello.enemy = self;
-       _hello.think = superspec_hello;
+       setthink(_hello, superspec_hello);
        _hello.nextthink = time + 5;
 
        if (!_ISLOCAL)
@@ -454,21 +434,17 @@ MUTATOR_HOOKFUNCTION(superspec, ClientConnect)
 }
 
 MUTATOR_HOOKFUNCTION(superspec, PlayerDies)
-{SELFPARAM();
-       entity e;
-       FOR_EACH_SPEC(e)
-       {
-               setself(e);
-               if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == this)
+{
+       FOREACH_CLIENT(IS_SPEC(it), LAMBDA(
+               if(it.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && it.enemy == frag_target)
                {
-                       if(self.autospec_flags & ASF_SHOWWHAT)
-                               superspec_msg("", "", self, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2);
+                       if(it.autospec_flags & ASF_SHOWWHAT)
+                               superspec_msg("", "", it, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2);
 
-                       superspec_Spectate(frag_attacker);
+                       WITHSELF(it, superspec_Spectate(frag_attacker));
                }
-       }
+       ));
 
-       setself(this);
        return false;
 }