]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Items: shift picking up weapons into WeaponPickup
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 13 Oct 2015 10:01:09 +0000 (21:01 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 13 Oct 2015 10:02:26 +0000 (21:02 +1100)
qcsrc/common/items/all.qh
qcsrc/common/items/item/pickup.qc
qcsrc/common/items/item/pickup.qh
qcsrc/common/weapons/weapon.qh
qcsrc/server/t_items.qc
qcsrc/server/t_items.qh

index a825b4ed16fbfb58a8718ce4ca5cd86d2e9c97cb..37e417a63f27f97b5f9020cec17ee2348839fee8 100644 (file)
@@ -34,5 +34,3 @@ string Item_Model(string item_mdl);
 #endif
 
 #endif
-
-#include "inventory.qh"
index ade99c543aeacb710cabd4b9194d5de7bd6fc753..fc958709e87d66af6eb50b958ce71ab8ef8f11b2 100644 (file)
@@ -2,12 +2,6 @@
 
 #ifdef SVQC
 bool ITEM_HANDLE(Pickup, entity this, entity item, entity player) {
-    bool b = this.giveTo(this, item, player);
-    if (b) {
-        LOG_TRACEF("entity %i picked up %s\n", player, this.m_name);
-        player.inventory.inv_items[this.m_id]++;
-        Inventory_update(player);
-    }
-    return b;
+    return this.giveTo(this, item, player);
 }
 #endif
index 9a25ebe9ad28bd5c1461f355983c3d07782b9cde..19963278873103d6f8e5386bc8a7b14b7d670ccc 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef PICKUP_H
 #define PICKUP_H
+#include "../inventory.qh"
 #include "../item.qh"
 CLASS(Pickup, GameItem)
 #ifndef MENUQC
@@ -21,7 +22,15 @@ CLASS(Pickup, GameItem)
     ATTRIB(Pickup, m_respawntimejitter, float(), func_null)
     float Item_GiveTo(entity item, entity player);
     METHOD(Pickup, giveTo, bool(entity this, entity item, entity player))
-    { return Item_GiveTo(item, player); }
+    {
+        bool b = Item_GiveTo(item, player);
+        if (b) {
+            LOG_TRACEF("entity %i picked up %s\n", player, this.m_name);
+            player.inventory.inv_items[this.m_id]++;
+            Inventory_update(player);
+        }
+        return b;
+    }
     bool ITEM_HANDLE(Pickup, entity this, entity item, entity player);
 #endif
 ENDCLASS(Pickup)
index 39702051b7aeda158ddce290daddc2a6456d0b27..624cb83f5226a478267018bc16f5f83146843db2 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef WEAPON_H
 #define WEAPON_H
+#include "../items/item/pickup.qh"
 
 .int ammo_shells;
 .int ammo_nails;
@@ -112,6 +113,16 @@ CLASS(WeaponPickup, Pickup)
         this.m_botvalue = w.bot_pickupbasevalue;
 #endif
     }
+#ifdef SVQC
+    METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
+    {
+        bool b = Item_GiveTo(item, player);
+        if (b) {
+            LOG_TRACEF("entity %i picked up %s\n", player, this.m_name);
+        }
+        return b;
+    }
+#endif
 ENDCLASS(WeaponPickup)
 
 CLASS(OffhandWeapon, Object)
index 15a8ec9b6000a283aa8044708358a073f36882a1..595f3c84e43e6aa8378785a0708622b10670f68c 100644 (file)
@@ -711,16 +711,16 @@ float Item_GiveTo(entity item, entity player)
        return 1;
 }
 
-void Item_Touch (void)
-{SELFPARAM();
-       entity e, head;
+void Item_Touch()
+{
+       SELFPARAM();
 
        // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
-       if(self.classname == "droppedweapon")
+       if (this.classname == "droppedweapon")
        {
                if (ITEM_TOUCH_NEEDKILL())
                {
-                       remove(self);
+                       remove(this);
                        return;
                }
        }
@@ -728,33 +728,33 @@ void Item_Touch (void)
        if(!(other.flags & FL_PICKUPITEMS)
        || other.frozen
        || other.deadflag
-       || (self.solid != SOLID_TRIGGER)
-       || (self.owner == other)
-       || (time < self.item_spawnshieldtime)
-       ) { return;}
+       || (this.solid != SOLID_TRIGGER)
+       || (this.owner == other)
+       || (time < this.item_spawnshieldtime)
+       ) { return; }
 
-       switch(MUTATOR_CALLHOOK(ItemTouch, self, other))
+       switch (MUTATOR_CALLHOOK(ItemTouch, this, other))
        {
                case MUT_ITEMTOUCH_RETURN: { return; }
                case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
        }
 
-       if (self.classname == "droppedweapon")
+       if (this.classname == "droppedweapon")
        {
-               self.strength_finished = max(0, self.strength_finished - time);
-               self.invincible_finished = max(0, self.invincible_finished - time);
-               self.superweapons_finished = max(0, self.superweapons_finished - time);
+               this.strength_finished = max(0, this.strength_finished - time);
+               this.invincible_finished = max(0, this.invincible_finished - time);
+               this.superweapons_finished = max(0, this.superweapons_finished - time);
        }
-       entity it = self.itemdef;
-       bool gave = (it && it.instanceOfPickup) ? ITEM_HANDLE(Pickup, it, self, other) : Item_GiveTo(self, other);
+       entity it = this.itemdef;
+       bool gave = ITEM_HANDLE(Pickup, it, this, other);
        if (!gave)
        {
-               if (self.classname == "droppedweapon")
+               if (this.classname == "droppedweapon")
                {
                        // undo what we did above
-                       self.strength_finished += time;
-                       self.invincible_finished += time;
-                       self.superweapons_finished += time;
+                       this.strength_finished += time;
+                       this.invincible_finished += time;
+                       this.superweapons_finished += time;
                }
                return;
        }
@@ -763,17 +763,18 @@ void Item_Touch (void)
 
        other.last_pickup = time;
 
-       Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
-       _sound (other, CH_TRIGGER, (self.item_pickupsound ? self.item_pickupsound : self.item_pickupsound_ent.sound_str()), VOL_BASE, ATTEN_NORM);
+       Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
+       _sound (other, CH_TRIGGER, (this.item_pickupsound ? this.item_pickupsound : this.item_pickupsound_ent.sound_str()), VOL_BASE, ATTEN_NORM);
 
-       if (self.classname == "droppedweapon")
-               remove (self);
-       else if (self.spawnshieldtime)
+       if (this.classname == "droppedweapon")
+               remove (this);
+       else if (this.spawnshieldtime)
        {
-               if(self.team)
+               entity e;
+               if(this.team)
                {
                        RandomSelection_Init();
-                       for(head = world; (head = findfloat(head, team, self.team)); )
+                       for(entity head = world; (head = findfloat(head, team, this.team)); )
                        {
                                if(head.flags & FL_ITEM)
                                if(head.classname != "item_flag_team" && head.classname != "item_key_team")
@@ -786,7 +787,7 @@ void Item_Touch (void)
 
                }
                else
-                       e = self;
+                       e = this;
                Item_ScheduleRespawn(e);
        }
 }
index 0e4da21ed3cfea86a4d4b6c9b8668c7110ad123b..21fb5eb71da7b32da17768955c52044b1272d64f 100644 (file)
@@ -90,7 +90,7 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
 
 float Item_GiveTo(entity item, entity player);
 
-void Item_Touch (void);
+void Item_Touch();
 
 void Item_Reset(entity this);