]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/items.qh
0bf8fd8efff5e08a1a534022c82401de61c37eab
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items.qh
1 float BOT_PICKUP_RATING_LOW     = 2500;
2 float BOT_PICKUP_RATING_MID     = 5000;
3 float BOT_PICKUP_RATING_HIGH    = 10000;
4
5 float WEP_TYPE_OTHER          =  0x00; // not for damaging people
6 float WEP_TYPE_SPLASH         =  0x01; // splash damage
7 float WEP_TYPE_HITSCAN        =  0x02; // hitscan
8 float WEP_TYPEMASK            =  0x0F;
9 float WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
10 float WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
11 float WEP_FLAG_HIDDEN         =  0x40; // hides from menu
12 float WEP_FLAG_RELOADABLE     =  0x80; // can has reload
13 float WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
14 float WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
15
16 float   IT_UNLIMITED_WEAPON_AMMO     = 1;
17 // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
18 float   IT_UNLIMITED_SUPERWEAPONS    = 2;
19 // when this bit is set, superweapons don't expire. Checkpoints can give this powerup.
20 float   IT_CTF_SHIELDED              = 4; // set for the flag shield
21 float   IT_USING_JETPACK             = 8; // confirmation that button is pressed
22 float   IT_JETPACK                   = 16; // actual item
23 float   IT_FUEL_REGEN                = 32; // fuel regeneration trigger
24 float   IT_SHELLS                    = 256;
25 float   IT_NAILS                     = 512;
26 float   IT_ROCKETS                   = 1024;
27 float   IT_CELLS                     = 2048;
28 float   IT_SUPERWEAPON               = 4096;
29 float   IT_FUEL                      = 128;
30 float   IT_STRENGTH                  = 8192;
31 float   IT_INVINCIBLE                = 16384;
32 float   IT_HEALTH                    = 32768;
33 // union:
34         // for items:
35         float   IT_KEY1                                 = 131072;
36         float   IT_KEY2                                 = 262144;
37         // for players:
38         float   IT_RED_FLAG_TAKEN               = 32768;
39         float   IT_RED_FLAG_LOST                = 65536;
40         float   IT_RED_FLAG_CARRYING            = 98304;
41         float   IT_BLUE_FLAG_TAKEN              = 131072;
42         float   IT_BLUE_FLAG_LOST               = 262144;
43         float   IT_BLUE_FLAG_CARRYING   = 393216;
44 // end
45 float   IT_5HP                       = 524288;
46 float   IT_25HP                      = 1048576;
47 float   IT_ARMOR_SHARD               = 2097152;
48 float   IT_ARMOR                     = 4194304;
49
50 float   IT_AMMO                      = 3968; // IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS | IT_FUEL;
51 float   IT_PICKUPMASK                = 51; // IT_FUEL_REGEN | IT_JETPACK | IT_UNLIMITED_AMMO; // strength and invincible are handled separately
52 float   IT_UNLIMITED_AMMO            = 3; // IT_UNLIMITED_SUPERWEAPONS | IT_UNLIMITED_WEAPON_AMMO;
53
54 // variables:
55 string weaponorder_byid;
56
57 // functions:
58 entity get_weaponinfo(float id);
59 string W_FixWeaponOrder(string order, float complete);
60 string W_NameWeaponOrder(string order);
61 string W_NumberWeaponOrder(string order);
62
63 // ammo types
64 .float ammo_shells;
65 .float ammo_nails;
66 .float ammo_rockets;
67 .float ammo_cells;
68 .float ammo_fuel;
69 .float ammo_batteries; // dummy
70
71 // entity properties of weaponinfo:
72 .float weapon; // WEP_...
73 .string netname; // short name
74 .string message; // human readable name
75 .float items; // IT_...
76 .float(float) weapon_func; // w_...
77 .string mdl; // modelname without g_, v_, w_
78 .string model; // full name of g_ model
79 .float spawnflags; // WEPSPAWNFLAG_... combined
80 .float impulse; // weapon impulse
81 .float bot_pickupbasevalue; // bot weapon priority
82 .string model2; // wpn- sprite name
83 ..float ammo_field; // main ammo field
84 // also, weaponinfo ents can act as a WEPSET
85
86 // dynamic weapon adding
87 float w_null(float dummy);
88 void register_weapon(float id, float(float) func, float ammotype, float i, float weapontype, float pickupbasevalue, string modelname, string shortname, string wname);
89 void register_weapons_done();
90
91 #define WEP_FIRST 1
92 float WEP_COUNT;
93 float WEP_LAST;
94
95 #if 1
96 # define WEP_MAXCOUNT 24
97 // default storage
98 .float _WS_weapons;
99 # define WEPSET_BIT(a)                  power2of((a) - WEP_FIRST)
100 # define WEPSET_DECLARE_A(a)            float _WS_##a
101 # define WEPSET_CLEAR_E(e)              ((e)._WS_weapons = 0)
102 # define WEPSET_CLEAR_A(a)              (_WS_##a = 0)
103 # define WEPSET_EMPTY_E(e)              ((e)._WS_weapons == 0)
104 # define WEPSET_EMPTY_A(a)              (_WS_##a == 0)
105 # define WEPSET_COPY_AS(a)              (_WS_##a = getstati(STAT_WEAPONS))
106 # define WEPSET_ADDSTAT()               addstat(STAT_WEAPONS, AS_INT, _WS_weapons)
107 # define WEPSET_WRITE_E(dest,a)         WriteInt24_t(dest, (a)._WS_weapons)
108 # define WEPSET_WRITE_A(dest,a)         WriteInt24_t(dest, _WS_##a)
109 # define WEPSET_WRITE_W(dest,a)         WriteInt24_t(dest, WEPSET_BIT(a))
110 # define WEPSET_READ_E(a)               (a)._WS_weapons = ReadInt24_t()
111 # define WEPSET_READ_A(a)               (_WS_##a) = ReadInt24_t()
112 # define WEPSET_OP1_EE(a,b,mergeop,x)   ((a)._WS_weapons x (b)._WS_weapons)
113 # define WEPSET_OP2_EE(a,b,mergeop,x,y) ((a)._WS_weapons x (b)._WS_weapons y (a)._WS_weapons)
114 # define WEPSET_OP1_EA(a,b,mergeop,x)   ((a)._WS_weapons x _WS_##b)
115 # define WEPSET_OP2_EA(a,b,mergeop,x,y) ((a)._WS_weapons x _WS_##b y (a)._WS_weapons)
116 # define WEPSET_OP1_EW(a,b,mergeop,x)   ((a)._WS_weapons x WEPSET_BIT(b))
117 # define WEPSET_OP2_EW(a,b,mergeop,x,y) ((a)._WS_weapons x WEPSET_BIT(b) y (a)._WS_weapons)
118 # define WEPSET_OP1_AE(a,b,mergeop,x)   (_WS_##a x (b)._WS_weapons)
119 # define WEPSET_OP2_AE(a,b,mergeop,x,y) (_WS_##a x (b)._WS_weapons y _WS_##a)
120 # define WEPSET_OP1_AA(a,b,mergeop,x)   (_WS_##a x _WS_##b)
121 # define WEPSET_OP2_AA(a,b,mergeop,x,y) (_WS_##a x _WS_##b y _WS_##a)
122 # define WEPSET_OP1_AW(a,b,mergeop,x)   (_WS_##a x WEPSET_BIT(b))
123 # define WEPSET_OP2_AW(a,b,mergeop,x,y) (_WS_##a x WEPSET_BIT(b) y _WS_##a)
124 #else
125 # define WEP_MAXCOUNT 48
126 # define WEP_FIRST2 25
127 .float _WS1_weapons;
128 .float _WS2_weapons;
129 # define WEPSET_BIT1(a)                 (((a) < WEP_FIRST2) ? power2of((a) - WEP_FIRST) : 0)
130 # define WEPSET_BIT2(a)                 (((a) >= WEP_FIRST2) ? power2of((a) - WEP_FIRST2) : 0)
131 # define WEPSET_DECLARE_A(a)            float _WS1_##a, _WS2_##a
132 # define WEPSET_CLEAR_E(e)              ((e)._WS1_weapons = (e)._WS2_weapons = 0)
133 # define WEPSET_CLEAR_A(a)              ((_WS1_##a) = (_WS2_##a) = 0)
134 # define WEPSET_EMPTY_E(e)              ((e)._WS1_weapons == 0 && (e)._WS2_weapons == 0)
135 # define WEPSET_EMPTY_A(a)              ((_WS1_##a) == 0 && (_WS2_##a) == 0)
136 # define WEPSET_COPY_AS(a)              ((_WS1_##a) = getstati(STAT_WEAPONS), (_WS2_##a) = getstati(STAT_WEAPONS2))
137 # define WEPSET_ADDSTAT()               addstat(STAT_WEAPONS, AS_INT, _WS1_weapons); addstat(STAT_WEAPONS2, AS_INT, _WS2_weapons)
138 # define WEPSET_WRITE_E(dest,a)         WriteInt24_t(dest, (a)._WS1_weapons); WriteInt24_t(dest, (a)._WS2_weapons)
139 # define WEPSET_WRITE_A(dest,a)         WriteInt24_t(dest, _WS1_##a); WriteInt24_t(dest, _WS2_##a)
140 # define WEPSET_WRITE_W(dest,a)         WriteInt24_t(dest, WEPSET_BIT1(a)); WriteInt24_t(dest, WEPSET_BIT2(a))
141 # define WEPSET_READ_E(a)               (a)._WS1_weapons = ReadInt24_t(); (a)._WS2_weapons = ReadInt24_t()
142 # define WEPSET_READ_A(a)               (_WS1_##a) = ReadInt24_t(); (_WS2_##a) = ReadInt24_t()
143 # define WEPSET_OP1_EE(a,b,mergeop,x)   (((a)._WS1_weapons x (b)._WS1_weapons) mergeop ((a)._WS2_weapons x (b)._WS2_weapons))
144 # define WEPSET_OP2_EE(a,b,mergeop,x,y) (((a)._WS1_weapons x (b)._WS1_weapons y (a)._WS1_weapons) mergeop ((a)._WS2_weapons x (b)._WS2_weapons y (a)._WS2_weapons))
145 # define WEPSET_OP1_EA(a,b,mergeop,x)   (((a)._WS1_weapons x _WS1_##b) mergeop ((a)._WS2_weapons x _WS2_##b))
146 # define WEPSET_OP2_EA(a,b,mergeop,x,y) (((a)._WS1_weapons x _WS1_##b y (a)._WS1_weapons) mergeop ((a)._WS2_weapons x _WS2_##b y (a)._WS2_weapons))
147 # define WEPSET_OP1_EW(a,b,mergeop,x)   (((a)._WS1_weapons x WEPSET_BIT1(b)) mergeop ((a)._WS2_weapons x WEPSET_BIT2(b)))
148 # define WEPSET_OP2_EW(a,b,mergeop,x,y) (((a)._WS1_weapons x WEPSET_BIT1(b) y (a)._WS1_weapons) mergeop ((a)._WS2_weapons x WEPSET_BIT2(b) y (a)._WS2_weapons))
149 # define WEPSET_OP1_AE(a,b,mergeop,x)   ((_WS1_##a x (b)._WS1_weapons) mergeop (_WS2_##a x (b)._WS2_weapons))
150 # define WEPSET_OP2_AE(a,b,mergeop,x,y) ((_WS1_##a x (b)._WS1_weapons y _WS1_##a) mergeop (_WS2_##a x (b)._WS2_weapons y _WS2_##a))
151 # define WEPSET_OP1_AA(a,b,mergeop,x)   ((_WS1_##a x _WS1_##b) mergeop (_WS2_##a x _WS2_##b))
152 # define WEPSET_OP2_AA(a,b,mergeop,x,y) ((_WS1_##a x _WS1_##b y _WS1_##a) mergeop (_WS2_##a x _WS2_##b y _WS2_##a))
153 # define WEPSET_OP1_AW(a,b,mergeop,x)   ((_WS1_##a x WEPSET_BIT1(b)) mergeop (_WS2_##a x WEPSET_BIT2(b)))
154 # define WEPSET_OP2_AW(a,b,mergeop,x,y) ((_WS1_##a x WEPSET_BIT1(b) y _WS1_##a) mergeop (_WS2_##a x WEPSET_BIT2(b) y _WS2_##a))
155 #endif
156
157 #define XX ,
158
159 #define WEPSET_COPY_EE(a,b)            WEPSET_OP1_EE(a,b,XX,=)
160 #define WEPSET_EQ_EE(a,b)              WEPSET_OP1_EE(a,b,&&,==)
161 #define WEPSET_OR_EE(a,b)              WEPSET_OP1_EE(a,b,XX,|=)
162 #define WEPSET_AND_EE(a,b)             WEPSET_OP2_EE(a,b,XX,=,&)
163 #define WEPSET_ANDNOT_EE(a,b)          WEPSET_OP1_EE(a,b,XX,&~=)
164 #define WEPSET_CONTAINS_ANY_EE(a,b) !!(WEPSET_OP1_EE(a,b,||,&))
165 #define WEPSET_CONTAINS_ALL_EE(a,b)    WEPSET_OP2_EE(b,a,&&,==,&)
166
167 #define WEPSET_COPY_EA(a,b)            WEPSET_OP1_EA(a,b,XX,=)
168 #define WEPSET_EQ_EA(a,b)              WEPSET_OP1_EA(a,b,&&,==)
169 #define WEPSET_OR_EA(a,b)              WEPSET_OP1_EA(a,b,XX,|=)
170 #define WEPSET_AND_EA(a,b)             WEPSET_OP2_EA(a,b,XX,=,&)
171 #define WEPSET_ANDNOT_EA(a,b)          WEPSET_OP1_EA(a,b,XX,&~=)
172 #define WEPSET_CONTAINS_ANY_EA(a,b) !!(WEPSET_OP1_EA(a,b,||,&))
173 #define WEPSET_CONTAINS_ALL_EA(a,b)    WEPSET_OP2_EA(b,a,&&,==,&)
174
175 #define WEPSET_COPY_EW(a,b)            WEPSET_OP1_EW(a,b,XX,=)
176 #define WEPSET_EQ_EW(a,b)              WEPSET_OP1_EW(a,b,&&,==)
177 #define WEPSET_OR_EW(a,b)              WEPSET_OP1_EW(a,b,XX,|=)
178 #define WEPSET_AND_EW(a,b)             WEPSET_OP2_EW(a,b,XX,=,&)
179 #define WEPSET_ANDNOT_EW(a,b)          WEPSET_OP1_EW(a,b,XX,&~=)
180 #define WEPSET_CONTAINS_EW(a,b)     !!(WEPSET_OP1_EW(a,b,||,&))
181
182 #define WEPSET_COPY_AE(a,b)            WEPSET_OP1_AE(a,b,XX,=)
183 #define WEPSET_EQ_AE(a,b)              WEPSET_OP1_AE(a,b,&&,==)
184 #define WEPSET_OR_AE(a,b)              WEPSET_OP1_AE(a,b,XX,|=)
185 #define WEPSET_AND_AE(a,b)             WEPSET_OP2_AE(a,b,XX,=,&)
186 #define WEPSET_ANDNOT_AE(a,b)          WEPSET_OP1_AE(a,b,XX,&~=)
187 #define WEPSET_CONTAINS_ANY_AE(a,b) !!(WEPSET_OP1_AE(a,b,||,&))
188 #define WEPSET_CONTAINS_ALL_AE(a,b)    WEPSET_OP2_AE(b,a,&&,==,&)
189
190 #define WEPSET_COPY_AA(a,b)            WEPSET_OP1_AA(a,b,XX,=)
191 #define WEPSET_EQ_AA(a,b)              WEPSET_OP1_AA(a,b,&&,==)
192 #define WEPSET_OR_AA(a,b)              WEPSET_OP1_AA(a,b,XX,|=)
193 #define WEPSET_AND_AA(a,b)             WEPSET_OP2_AA(a,b,XX,=,&)
194 #define WEPSET_ANDNOT_AA(a,b)          WEPSET_OP1_AA(a,b,XX,&~=)
195 #define WEPSET_CONTAINS_ANY_AA(a,b) !!(WEPSET_OP1_AA(a,b,||,&))
196 #define WEPSET_CONTAINS_ALL_AA(a,b)    WEPSET_OP2_AA(b,a,&&,==,&)
197
198 #define WEPSET_COPY_AW(a,b)            WEPSET_OP1_AW(a,b,XX,=)
199 #define WEPSET_EQ_AW(a,b)              WEPSET_OP1_AW(a,b,&&,==)
200 #define WEPSET_OR_AW(a,b)              WEPSET_OP1_AW(a,b,XX,|=)
201 #define WEPSET_AND_AW(a,b)             WEPSET_OP2_AW(a,b,XX,=,&)
202 #define WEPSET_ANDNOT_AW(a,b)          WEPSET_OP1_AW(a,b,XX,&~=)
203 #define WEPSET_CONTAINS_AW(a,b)     !!(WEPSET_OP1_AW(a,b,||,&))
204
205 WEPSET_DECLARE_A(WEPBIT_ALL);
206 WEPSET_DECLARE_A(WEPBIT_SUPERWEAPONS);
207 // note: the fabs call is just there to hide "if result is constant" warning
208 #define REGISTER_WEAPON_2(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
209         float id; \
210         float func(float); \
211         void RegisterWeapons_##id() \
212         { \
213                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
214                 WEPSET_OR_AW(WEPBIT_ALL, id); \
215                 if(fabs(weapontype & WEP_FLAG_SUPERWEAPON)) \
216                         WEPSET_OR_AW(WEPBIT_SUPERWEAPONS, id); \
217                 ++WEP_COUNT; \
218                 register_weapon(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname); \
219         } \
220         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
221 #ifdef MENUQC
222 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
223         REGISTER_WEAPON_2(WEP_##id,w_null,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname)
224 #else
225 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
226         REGISTER_WEAPON_2(WEP_##id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname)
227 #endif
228
229 #include "../server/w_all.qc"
230
231 #undef REGISTER_WEAPON
232 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done)
233
234
235 string W_FixWeaponOrder(string order, float complete);
236 string W_NumberWeaponOrder(string order);
237 string W_NameWeaponOrder(string order);
238 string W_FixWeaponOrder_BuildImpulseList(string o);
239 string W_FixWeaponOrder_AllowIncomplete(string order);
240 string W_FixWeaponOrder_ForceComplete(string order);
241
242 void W_RandomWeapons(entity e, float n);
243
244 string W_Name(float weaponid);
245
246 float W_AmmoItemCode(float wpn);