]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/items/item.qh
Reorganise item code so that VM-specific code is in its correct directories and not...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / item.qh
1 #pragma once
2
3 #ifdef GAMEQC
4 #include <common/models/all.qh>
5 #include <common/sounds/all.qh>
6 #include <common/sounds/all.inc>
7 #include <common/stats.qh>
8 #endif
9
10 #ifdef SVQC
11 #include <server/items/spawning.qh>
12 #endif
13
14 #ifdef GAMEQC
15 const int IT_UNLIMITED_AMMO                     =  BIT(0); // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
16 const int IT_UNLIMITED_SUPERWEAPONS             =  BIT(1); // when this bit is set, superweapons don't expire. Checkpoints can give this powerup.
17
18 const int IT_JETPACK                            =  BIT(2); // actual item
19 const int IT_USING_JETPACK                      =  BIT(3); // confirmation that button is pressed
20 const int IT_FUEL_REGEN                         =  BIT(4); // fuel regeneration trigger
21
22 const int IT_RESOURCE                           =  BIT(5); // bitflag to mark this item as a resource (unused)
23
24 const int IT_KEY1                                               = BIT(6);
25 const int IT_KEY2                                               = BIT(7);
26
27 // special colorblend meaning in engine
28 const int IT_INVISIBILITY                               = BIT(9);
29 const int IT_INVINCIBLE                                 = BIT(10);
30 const int IT_SUPERWEAPON                                = BIT(11); // suit
31 const int IT_STRENGTH                                   = BIT(12);
32
33 // item masks
34 const int IT_PICKUPMASK                 = IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS | IT_JETPACK | IT_FUEL_REGEN; // strength and invincible are handled separately
35
36 // item networking
37 const int ISF_LOCATION          = BIT(1);
38 const int ISF_MODEL             = BIT(2);
39 const int ISF_STATUS            = BIT(3);
40 const int ISF_COLORMAP          = BIT(4);
41 const int ISF_DROP              = BIT(5);
42 const int ISF_ANGLES            = BIT(6);
43 const int ISF_SIZE              = BIT(7);
44
45 REGISTER_NET_LINKED(ENT_CLIENT_ITEM)
46
47 // item status
48 .int ItemStatus;
49 const int ITS_STAYWEP           = BIT(0);
50 const int ITS_ANIMATE1          = BIT(1);
51 const int ITS_ANIMATE2          = BIT(2);
52 const int ITS_AVAILABLE         = BIT(3);
53 const int ITS_ALLOWFB           = BIT(4);
54 const int ITS_ALLOWSI           = BIT(5);
55 const int ITS_GLOW              = BIT(6);
56
57 .float fade_start;
58 .float fade_end;
59 #endif
60
61 #ifdef SVQC
62 .float strength_finished; // NOTE: this field is used only by map entities, it does not directly apply the strength stat
63 .float invincible_finished; // ditto
64
65 #define spawnfunc_body(item) \
66         if (!Item_IsDefinitionAllowed(item)) \
67         { \
68                 startitem_failed = true; \
69                 delete(this); \
70                 return; \
71         } \
72         StartItem(this, item)
73
74 #define SPAWNFUNC_ITEM(name, item) \
75         spawnfunc(name) \
76         { \
77                 spawnfunc_body(item); \
78         }
79
80 #define SPAWNFUNC_ITEM_COND(name, cond, item1, item2) \
81         spawnfunc(name) \
82         { \
83                 entity item = (cond) ? item1 : item2; \
84                 spawnfunc_body(item); \
85         }
86
87 #else
88
89 #define SPAWNFUNC_ITEM(name, item)
90
91 #endif
92
93 enum
94 {
95         ITEM_FLAG_NORMAL = BIT(0), ///< Item is usable during normal gameplay.
96         ITEM_FLAG_MUTATORBLOCKED = BIT(1),
97         ITEM_FLAG_RESOURCE = BIT(2) ///< Item is is a resource, not a held item.
98 };
99
100 #define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__)
101 CLASS(GameItem, Object)
102     ATTRIB(GameItem, m_id, int, 0);
103     /** the canonical spawnfunc name */
104     ATTRIB(GameItem, m_canonical_spawnfunc, string);
105     METHOD(GameItem, m_spawnfunc_hookreplace, GameItem(GameItem this, entity e)) { return this; }
106     ATTRIB(GameItem, m_name, string);
107     ATTRIB(GameItem, m_icon, string);
108     ATTRIB(GameItem, m_color, vector, '1 1 1');
109     ATTRIB(GameItem, m_waypoint, string);
110     ATTRIB(GameItem, m_waypointblink, int, 1);
111 #ifdef GAMEQC
112     ATTRIB(GameItem, m_glow, bool, false);
113     ATTRIB(GameItem, m_respawnsound, Sound, SND_ITEMRESPAWN);
114 #endif
115     METHOD(GameItem, display, void(GameItem this, void(string name, string icon) returns))
116     {
117         TC(GameItem, this);
118         returns(this.m_name, this.m_icon ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.m_icon) : string_null);
119     }
120     METHOD(GameItem, show, void(GameItem this))
121     {
122         TC(GameItem, this);
123         LOG_INFO("A game item");
124     }
125     void ITEM_HANDLE(Show, GameItem this) { this.show(this); }
126 ENDCLASS(GameItem)