]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Partial support for buffs in target_items entities
authorMario <mario@smbclan.net>
Thu, 9 Feb 2017 15:32:42 +0000 (01:32 +1000)
committerMario <mario@smbclan.net>
Thu, 9 Feb 2017 15:32:42 +0000 (01:32 +1000)
qcsrc/common/mutators/mutator/buffs/all.inc
qcsrc/common/mutators/mutator/buffs/buffs.qh
qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
qcsrc/common/t_items.qc

index 915f95329dbda327f6d3f752221892346a4bb114..943c75594eb7d7f5987a64e9e71ea6ad1b7eda38 100644 (file)
@@ -1,3 +1,15 @@
+string Buff_UndeprecateName(string buffname)
+{
+    switch(buffname)
+    {
+        case "ammoregen": return "ammo";
+        case "haste": case "scout": return "speed";
+        case "doubler": return "medic";
+        case "invis": return "invisible";
+        default: return buffname;
+    }
+}
+
 REGISTER_BUFF(AMMO) {
     this.m_prettyName = _("Ammo");
     this.m_name = "ammo";
index ae76d9f59ef6f9dc9e910389508d9f81a8417c21..81a638ea7c300f07edffdeadfadd3dd980388d68 100644 (file)
@@ -64,6 +64,8 @@ STATIC_INIT(REGISTER_BUFFS) {
        #define BUFF_SPAWNFUNC_Q3TA_COMPAT(o, r)
 #endif
 
+string Buff_UndeprecateName(string buffname);
+
 REGISTER_BUFF(Null);
 BUFF_SPAWNFUNCS(random, BUFF_Null)
 
index c02ac5687ea5664ec4a1b0498b067d3b9d3cbdc4..b63349e86a34b1965896b9e30955b20443226706 100644 (file)
@@ -970,7 +970,8 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
                }
                else
                {
-                       delete(player.buff_model);
+                       if(player.buff_model)
+                               delete(player.buff_model);
                        player.buff_model = NULL;
 
                        player.effects &= ~(EF_NOSHADOW);
index 9aab742d0198560e651cccc71c8bae12beadd517..79fa97801ed45c615b631b214ede506fcbff6c5d 100644 (file)
@@ -22,6 +22,8 @@
 
     #include <common/weapons/_all.qh>
 
+    #include <common/mutators/mutator/buffs/buffs.qh>
+
     #include "../lib/warpzone/util_server.qh"
 #elif defined(CSQC)
        #include "physics/movetypes/movetypes.qh"
@@ -1493,6 +1495,15 @@ spawnfunc(target_items)
                        else if(argv(j) == "fuel_regen")             this.items |= ITEM_JetpackRegen.m_itemid;
                        else
                        {
+                               FOREACH(Buffs, it != BUFF_Null,
+                               {
+                                       s = Buff_UndeprecateName(argv(j));
+                                       if(s == it.m_name)
+                                       {
+                                               this.buffs |= (it.m_itemid);
+                                               break;
+                                       }
+                               });
                                FOREACH(Weapons, it != WEP_Null, {
                                        s = W_UndeprecateName(argv(j));
                                        if(s == it.netname)
@@ -1549,6 +1560,7 @@ spawnfunc(target_items)
                if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel");
                if(this.health != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.health), "health");
                if(this.armorvalue != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.armorvalue), "armor");
+               FOREACH(Buffs, it != BUFF_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.buffs & (it.m_itemid)), it.m_name));
                FOREACH(Weapons, it != WEP_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.weapons & (it.m_wepset)), it.netname));
        }
        this.netname = strzone(this.netname);
@@ -1624,6 +1636,35 @@ float GiveWeapon(entity e, float wpn, float op, float val)
        return (v0 != v1);
 }
 
+bool GiveBuff(entity e, Buff thebuff, int op, int val)
+{
+       bool had_buff = (e.buffs & thebuff.m_itemid);
+       switch(op)
+       {
+               case OP_SET:
+                       if(val > 0)
+                               e.buffs |= thebuff.m_itemid;
+                       else
+                               e.buffs &= ~thebuff.m_itemid;
+                       break;
+               case OP_MIN:
+               case OP_PLUS:
+                       if(val > 0)
+                               e.buffs |= thebuff.m_itemid;
+                       break;
+               case OP_MAX:
+                       if(val <= 0)
+                               e.buffs &= ~thebuff.m_itemid;
+                       break;
+               case OP_MINUS:
+                       if(val > 0)
+                               e.buffs &= ~thebuff.m_itemid;
+                       break;
+       }
+       bool have_buff = (e.buffs & thebuff.m_itemid);
+       return (had_buff != have_buff);
+}
+
 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
 {
        if(v1 == v0)
@@ -1727,6 +1768,8 @@ float GiveItems(entity e, float beginarg, float endarg)
                                got += GiveValue(e, armorvalue, op, val);
                        case "allweapons":
                                FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED), got += GiveWeapon(e, it.m_id, op, val));
+                       //case "allbuffs": // all buffs makes a player god, do not want!
+                               //FOREACH(Buffs, it != BUFF_Null, got += GiveBuff(e, it.m_itemid, op, val));
                        case "allammo":
                                got += GiveValue(e, ammo_cells, op, val);
                                got += GiveValue(e, ammo_plasma, op, val);
@@ -1785,6 +1828,11 @@ float GiveItems(entity e, float beginarg, float endarg)
                                got += GiveValue(e, ammo_fuel, op, val);
                                break;
                        default:
+                               FOREACH(Buffs, it != BUFF_Null && Buff_UndeprecateName(cmd) == it.m_name,
+                               {
+                                       got += GiveBuff(e, it, op, val);
+                                       break;
+                               });
                                FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
                     got += GiveWeapon(e, it.m_id, op, val);
                     break;