]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/items/item.qh
1c8939beb09800d497c9eab75f581c3bcc981075
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / item.qh
1 #ifndef GAMEITEM_H
2 #define GAMEITEM_H
3 #include "../oo.qh"
4 CLASS(GameItem, Object)
5     METHOD(GameItem, respondTo, bool(entity, int))
6 ENDCLASS(GameItem)
7
8
9
10 #define LAMBDA(...) { __VA_ARGS__ ; }
11
12 #define ITEM_SIGNALS(_) \
13     _(Default, void, (entity it), LAMBDA({ it.respondTo(it, SIGNAL); })) \
14     /* Common item signals */
15
16 #define ITEM_SIGNAL(id) __Item_Signal_##id
17
18 #define ITEM_ENUM(id, ret, params, body) ITEM_SIGNAL(id) ,
19 enum { ITEM_SIGNALS(ITEM_ENUM) };
20 #undef ITEM_ENUM
21
22 #define ITEM_SEND(id, ret, params, body) ret __Item_Send_##id params { const noref int SIGNAL = ITEM_SIGNAL(id); body }
23 ITEM_SIGNALS(ITEM_SEND)
24 #undef ITEM_SEND
25 #define ITEM_SEND(id, ...) __Item_Send_##id(__VA_ARGS__)
26
27
28
29 int ITEM_COUNT;
30 #define REGISTER_ITEM(id, class, body)          \
31     entity ITEM_##id;                           \
32     void RegisterItems_##id() {                 \
33         const noref entity this = NEW(class);   \
34         ITEM_##id = this;                       \
35         ITEMS[ITEM_COUNT++] = this;             \
36         body                                    \
37     }                                           \
38     ACCUMULATE_FUNCTION(RegisterItems, RegisterItems_##id)
39
40 #endif