]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator_superspec.qc
Nades: always throw with weapon drop in case offhand is occupied
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_superspec.qc
index 1fd1022e72d2131d57edacd22c8ed8e2df2f6c6e..32e81319dfe87dda5d6eeaa680aed00836bd77ae 100644 (file)
@@ -1,3 +1,7 @@
+#include "../_all.qh"
+
+#include "mutator.qh"
+
 #define _SSMAGIX "SUPERSPEC_OPTIONSFILE_V1"
 #define _ISLOCAL ((edict_num(1) == self) ? true : false)
 
@@ -21,7 +25,7 @@ const float SSF_ITEMMSG = 4;
 .string superspec_itemfilter; //"classname1 classname2 ..."
 
 float _spectate(entity _player)
-{
+{SELFPARAM();
        if(Spectate(_player) == 1)
                self.classname = "spectator";
 
@@ -29,7 +33,7 @@ float _spectate(entity _player)
 }
 
 void superspec_save_client_conf()
-{
+{SELFPARAM();
        string fn = "superspec-local.options";
        float fh;
 
@@ -44,7 +48,7 @@ void superspec_save_client_conf()
        fh = fopen(fn, FILE_WRITE);
        if(fh < 0)
        {
-               dprint("^1ERROR: ^7 superspec can not open ", fn, " for writing.\n");
+               LOG_TRACE("^1ERROR: ^7 superspec can not open ", fn, " for writing.\n");
        }
        else
        {
@@ -95,12 +99,13 @@ float superspec_filteritem(entity _for, entity _item)
 }
 
 MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
-{
-       entity _oldself = self;
+{SELFPARAM();
        entity _item = self;
 
-       FOR_EACH_SPEC(self)
+       entity e;
+       FOR_EACH_SPEC(e)
        {
+               setself(e);
                if(self.superspec_flags & SSF_ITEMMSG)
                        if(superspec_filteritem(self, _item))
                        {
@@ -112,16 +117,16 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
                                {
                                        _spectate(other);
 
-                                       self = _oldself;
+                                       setself(this);
                                        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.classname == "item_armor_large") ||
-                               (self.autospec_flags & ASF_MEGA_HP && _item.classname == "item_health_mega") ||
-                               (self.autospec_flags & ASF_FLAG_GRAB && _item.classname == "item_flag_team"))
+                       (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((self.enemy != other) || IS_OBSERVER(self))
@@ -142,13 +147,13 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
                }
        }
 
-       self = _oldself;
+       setself(this);
 
        return MUT_ITEMTOUCH_CONTINUE;
 }
 
 MUTATOR_HOOKFUNCTION(superspec_SV_ParseClientCommand)
-{
+{SELFPARAM();
 #define OPTIONINFO(flag,var,test,text,long,short) \
     var = strcat(var, ((flag & test) ? "^2[ON]  ^7" : "^1[OFF] ^7")); \
     var = strcat(var, text," ^7(^3 ", long, "^7 | ^3", short, " ^7)\n")
@@ -383,15 +388,18 @@ MUTATOR_HOOKFUNCTION(superspec_SV_ParseClientCommand)
                        return true;
 
                entity _player;
-               float _team = 0;
-               float found = false;
+               int _team = 0;
+               bool found = false;
 
                if(cmd_argc == 2)
                {
-                       if(argv(1) == "red")
-                               _team = NUM_TEAM_1;
-                       else
-                               _team = NUM_TEAM_2;
+                       switch(argv(1))
+                       {
+                               case "red": _team = NUM_TEAM_1; break;
+                               case "blue": _team = NUM_TEAM_2; break;
+                               case "yellow": if(ctf_teams >= 3) _team = NUM_TEAM_3; break;
+                               case "pink": if(ctf_teams >= 4) _team = NUM_TEAM_4; break;
+                       }
                }
 
                FOR_EACH_PLAYER(_player)
@@ -427,7 +435,7 @@ MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsPrettyString)
 }
 
 void superspec_hello()
-{
+{SELFPARAM();
        if(self.enemy.crypto_idfp == "")
                Send_Notification(NOTIF_ONE_ONLY, self.enemy, MSG_INFO, INFO_SUPERSPEC_MISSING_UID);
 
@@ -435,7 +443,7 @@ void superspec_hello()
 }
 
 MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
-{
+{SELFPARAM();
        if(!IS_REAL_CLIENT(self))
                return false;
 
@@ -461,14 +469,14 @@ MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
        fh = fopen(fn, FILE_READ);
        if(fh < 0)
        {
-               dprint("^1ERROR: ^7 superspec can not open ", fn, " for reading.\n");
+               LOG_TRACE("^1ERROR: ^7 superspec can not open ", fn, " for reading.\n");
        }
        else
        {
                string _magic = fgets(fh);
                if(_magic != _SSMAGIX)
                {
-                       dprint("^1ERROR^7 While reading superspec options file: unknown magic\n");
+                       LOG_TRACE("^1ERROR^7 While reading superspec options file: unknown magic\n");
                }
                else
                {
@@ -483,12 +491,12 @@ MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
 }
 
 MUTATOR_HOOKFUNCTION(superspec_PlayerDies)
-{
-       entity _old_self = self;
-
-       FOR_EACH_SPEC(self)
+{SELFPARAM();
+       entity e;
+       FOR_EACH_SPEC(e)
        {
-               if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == _old_self)
+               setself(e);
+               if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == this)
                {
                        if(self.autospec_flags & ASF_SHOWWHAT)
                                superspec_msg("", "", self, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2);
@@ -497,7 +505,7 @@ MUTATOR_HOOKFUNCTION(superspec_PlayerDies)
                }
        }
 
-       self = _old_self;
+       setself(this);
        return false;
 }