From: TimePath Date: Wed, 13 May 2015 00:34:15 +0000 (+1000) Subject: Cleanup X-Git-Tag: xonotic-v0.8.1~53^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3f19aed0da1ef3afb5eca7bfa53db63d0b98bcc7;p=xonotic%2Fxonotic-data.pk3dir.git Cleanup --- diff --git a/qcsrc/common/items/all.inc b/qcsrc/common/items/all.inc index 5776b7ef2..f009bbe00 100644 --- a/qcsrc/common/items/all.inc +++ b/qcsrc/common/items/all.inc @@ -1,5 +1,3 @@ -#include "item.qc" - #include "item/ammo.qc" #include "item/armor.qc" #include "item/buff.qc" diff --git a/qcsrc/common/items/all.qc b/qcsrc/common/items/all.qc index 460f77fcb..37cd93b3f 100644 --- a/qcsrc/common/items/all.qc +++ b/qcsrc/common/items/all.qc @@ -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 index a8cf566d7..000000000 --- a/qcsrc/common/items/item.qc +++ /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; - } -} diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 0434a4629..6ca131418 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -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 \ diff --git a/qcsrc/common/items/item/buff.qc b/qcsrc/common/items/item/buff.qc index 479df881f..d9420d1c3 100644 --- a/qcsrc/common/items/item/buff.qc +++ b/qcsrc/common/items/item/buff.qc @@ -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()) diff --git a/qcsrc/common/items/item/buff.qh b/qcsrc/common/items/item/buff.qh index 6b48b1fba..458b35e3c 100644 --- a/qcsrc/common/items/item/buff.qh +++ b/qcsrc/common/items/item/buff.qh @@ -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 diff --git a/qcsrc/common/items/item/pickup.qh b/qcsrc/common/items/item/pickup.qh index 1bcbc3899..a391d6861 100644 --- a/qcsrc/common/items/item/pickup.qh +++ b/qcsrc/common/items/item/pickup.qh @@ -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 diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 4a87edd0e..009f7c263 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -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); }