-#include "item.qc"
-
#include "item/ammo.qc"
#include "item/armor.qc"
#include "item/buff.qc"
{
ITEMS_FOREACH(it != NULL, LAMBDA({
print(strcat(etos(it), "\n"));
- ITEM_SEND(Default, it);
+ ITEM_HANDLE(Show, it);
}));
}
+++ /dev/null
-#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;
- }
-}
#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 \
#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())
#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
#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)
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)
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
return 1;
}
+.entity itemdef;
+
void Item_Touch (void)
{
entity e, head;
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")
{
if (self.classname == "droppedweapon")
remove (self);
- else if (!self.spawnshieldtime)
- return;
- else
+ else if (self.spawnshieldtime)
{
if(self.team)
{
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);
}