]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Cleanup
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 13 May 2015 00:34:15 +0000 (10:34 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 13 May 2015 00:34:15 +0000 (10:34 +1000)
qcsrc/common/items/all.inc
qcsrc/common/items/all.qc
qcsrc/common/items/item.qc [deleted file]
qcsrc/common/items/item.qh
qcsrc/common/items/item/buff.qc
qcsrc/common/items/item/buff.qh
qcsrc/common/items/item/pickup.qh
qcsrc/server/t_items.qc

index 5776b7ef264a07e28a8a21c27f63193ccb7b2c6b..f009bbe00c506000fa5e886d9a5c1f8e65475fa3 100644 (file)
@@ -1,5 +1,3 @@
-#include "item.qc"
-
 #include "item/ammo.qc"
 #include "item/armor.qc"
 #include "item/buff.qc"
index 460f77fcbffd9127e567c679f83d31141ff2b57b..37cd93b3fc62df7b702dc6b497c754972c1112cc 100644 (file)
@@ -8,7 +8,7 @@ void ItemTest()
 {
     ITEMS_FOREACH(it != NULL, LAMBDA({
         print(strcat(etos(it), "\n"));
-        ITEM_SEND(Default, it);
+        ITEM_HANDLE(Show, it);
     }));
 }
 
diff --git a/qcsrc/common/items/item.qc b/qcsrc/common/items/item.qc
deleted file mode 100644 (file)
index a8cf566..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "item.qh"
-
-bool GameItem_respondTo(entity this, int request)
-{
-    switch (request) {
-        default: return false;
-        case ITEM_SIGNAL(Default):
-            print("Item responding\n");
-            return true;
-    }
-}
index 0434a46296ea808d2071e550f5f8508cb9da7f79..6ca1314185bb19f61b58a8d867c904fb504f0695 100644 (file)
@@ -1,34 +1,19 @@
 #ifndef GAMEITEM_H
 #define GAMEITEM_H
 #include "../oo.qh"
+#define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__)
 CLASS(GameItem, Object)
-    METHOD(GameItem, respondTo, bool(entity, int))
+    METHOD(GameItem, show, void(entity this))
+    void GameItem_show(entity this) { print("A game item\n"); }
+    void ITEM_HANDLE(Show, entity this) { this.show(this); }
 ENDCLASS(GameItem)
 
 
-
-#define ITEM_SIGNALS(_) \
-    _(Default, void, (entity it), LAMBDA({ it.respondTo(it, SIGNAL); })) \
-    /* Common item signals */
-
-#define ITEM_SIGNAL(id) __Item_Signal_##id
-
-#define ITEM_ENUM(id, ret, params, body) ITEM_SIGNAL(id) ,
-enum { ITEM_SIGNALS(ITEM_ENUM) };
-#undef ITEM_ENUM
-
-#define ITEM_SEND(id, ret, params, body) ret __Item_Send_##id params { const noref int SIGNAL = ITEM_SIGNAL(id); body }
-ITEM_SIGNALS(ITEM_SEND)
-#undef ITEM_SEND
-#define ITEM_SEND(id, ...) __Item_Send_##id(__VA_ARGS__)
-
-
-
 int ITEM_COUNT;
 #define REGISTER_ITEM(id, class, body)          \
     entity ITEM_##id;                           \
     void RegisterItems_##id() {                 \
-        const noref entity this = NEW(class);   \
+        const entity this = NEW(class);         \
         ITEM_##id = this;                       \
         ITEMS[ITEM_COUNT++] = this;             \
         body                                    \
index 479df881fa511f74080438d6a37d765dde1bbac9..d9420d1c3ce44ea69d055e285c7e82e23a8a3945 100644 (file)
@@ -1,13 +1,3 @@
 #include "buff.qh"
 
-REGISTER_ITEM(strength, Buff, LAMBDA())
-
-bool Buff_respondTo(entity this, int request)
-{
-    switch (request) {
-        default: return false;
-        case ITEM_SIGNAL(Default):
-            print("Buff responding\n");
-            return true;
-    }
-}
+REGISTER_ITEM(DefaultBuff, Buff, LAMBDA())
index 6b48b1fbad366cce3356a327ad8a680148fcf9f2..458b35e3c2b97f7a403b0146ac2c40878caec7b1 100644 (file)
@@ -2,6 +2,7 @@
 #define BUFF_H
 #include "../item.qh"
 CLASS(Buff, GameItem)
-    METHOD(Buff, respondTo, bool(entity, int))
+    METHOD(Buff, show, void(entity this))
+    void Buff_show(entity this) { print("%s\n", "Buff"); }
 ENDCLASS(Buff)
 #endif
index 1bcbc389950ace48d927602879138988beca896c..a391d6861d5f49a8d8f06c5d3f2661fdc2772519 100644 (file)
@@ -2,10 +2,11 @@
 #define PICKUP_H
 #include "../item.qh"
 CLASS(Pickup, GameItem)
-    METHOD(Pickup, respondTo, bool(entity, int))
     ATTRIB(Pickup, m_model, string, string_null)
     ATTRIB(Pickup, m_sound, string, "misc/itempickup.wav")
     ATTRIB(Pickup, m_name, string, string_null)
+    METHOD(Pickup, show, void(entity this))
+    void Pickup_show(entity this) { printf("%s\n", this.m_name); }
 #ifdef SVQC
     ATTRIB(Pickup, m_botvalue, int, 0)
     ATTRIB(Pickup, m_itemflags, int, 0)
@@ -13,13 +14,16 @@ CLASS(Pickup, GameItem)
     ATTRIB(Pickup, m_pickupevalfunc, float(entity player, entity item), generic_pickupevalfunc)
     ATTRIB(Pickup, m_respawntime, float(), func_null)
     ATTRIB(Pickup, m_respawntimejitter, float(), func_null)
+    METHOD(Pickup, giveTo, bool(entity this, entity item, entity player))
+    bool Pickup_giveTo(entity this, entity item, entity player) { return Item_GiveTo(item, player); }
+    bool ITEM_HANDLE(Pickup, entity this, entity item, entity player) { printf("%s picked up %s\n", etos(player), this.m_name); return this.giveTo(this, item, player); }
 #endif
 ENDCLASS(Pickup)
 
 #ifdef SVQC
 // For g_pickup_respawntime
 #include "../../../server/defs.qh"
-// Getters to dynamically retrieve the values of g_pickup_respawntime* as they aren't autocvars
+// Getters to dynamically retrieve the values of g_pickup_respawntime*
 GETTER(float, g_pickup_respawntime_weapon)
 GETTER(float, g_pickup_respawntime_superweapon)
 GETTER(float, g_pickup_respawntime_ammo)
@@ -34,16 +38,7 @@ GETTER(float, g_pickup_respawntimejitter_short)
 GETTER(float, g_pickup_respawntimejitter_medium)
 GETTER(float, g_pickup_respawntimejitter_long)
 GETTER(float, g_pickup_respawntimejitter_powerup)
-#endif
 
-bool Pickup_respondTo(entity this, int request)
-{
-    switch (request) {
-        default: return false;
-        case ITEM_SIGNAL(Default):
-            print(strcat(this.m_name, " responding\n"));
-            return true;
-    }
-}
+#endif
 
 #endif
index 4a87edd0e9e410275c57ca6c214e8607e1c527a4..009f7c26340e92a3456bd6a568ce437e220d492c 100644 (file)
@@ -665,6 +665,8 @@ float Item_GiveTo(entity item, entity player)
        return 1;
 }
 
+.entity itemdef;
+
 void Item_Touch (void)
 {
        entity e, head;
@@ -704,8 +706,9 @@ void Item_Touch (void)
                self.invincible_finished = max(0, self.invincible_finished - time);
                self.superweapons_finished = max(0, self.superweapons_finished - time);
        }
-
-       if(!Item_GiveTo(self, other))
+       entity it = self.itemdef;
+       bool gave = (it && it.instanceOfPickup) ? ITEM_HANDLE(Pickup, it, self, other) : Item_GiveTo(self, other);
+       if (!gave)
        {
                if (self.classname == "droppedweapon")
                {
@@ -726,9 +729,7 @@ void Item_Touch (void)
 
        if (self.classname == "droppedweapon")
                remove (self);
-       else if (!self.spawnshieldtime)
-               return;
-       else
+       else if (self.spawnshieldtime)
        {
                if(self.team)
                {
@@ -1156,6 +1157,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
 
 void StartItemA (entity a)
 {
+    self.itemdef = a;
     StartItem(a.m_model, a.m_sound, a.m_respawntime(), a.m_respawntimejitter(), a.m_name, a.m_itemid, 0, a.m_itemflags, a.m_pickupevalfunc, a.m_botvalue);
 }