3 #include <common/command/_mod.qh>
4 #include <common/stats.qh>
10 void WriteWepSet(float dest, WepSet w);
14 WepSet WepSet_GetFromStat();
15 WepSet WepSet_GetFromStat_InMap();
22 #include "calculations.qh"
23 #include "projectiles.qh"
24 #include <common/models/all.qh>
27 #include <common/util.qh>
29 REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72.
30 #define Weapons_from(i) _Weapons_from(i, WEP_Null)
31 REGISTER_REGISTRY(Weapons)
32 STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, it.m_pickup = NEW(WeaponPickup, it)); }
35 #include <server/bot/api.qh>
39 #define WEPSET(id) (WEP_##id.m_wepset)
40 #define WepSet_FromWeapon(it) ((it).m_wepset)
41 WepSet _WepSet_FromWeapon(int i);
43 GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPONTODO: make this work with other progs than just server
47 case CMD_REQUEST_COMMAND:
51 wep_config_alsoprint = -1;
52 string filename = argv(1);
56 filename = "weapons_dump.cfg";
57 wep_config_alsoprint = false;
59 else if(filename == "-")
61 filename = "weapons_dump.cfg";
62 wep_config_alsoprint = true;
64 wep_config_file = fopen(filename, FILE_WRITE);
66 if(wep_config_file >= 0)
68 Dump_Weapon_Settings();
69 LOG_INFO(sprintf("Dumping weapons... File located in ^2data/data/%s^7.\n", filename));
70 fclose(wep_config_file);
72 wep_config_alsoprint = -1;
76 LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
79 LOG_INFO(_("Weapons dump command only works with sv_cmd.\n"));
85 case CMD_REQUEST_USAGE:
87 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]"));
88 LOG_INFO(" Where 'filename' is the file to write (default is weapons_dump.cfg),\n");
89 LOG_INFO(" if supplied with '-' output to console as well as default,\n");
90 LOG_INFO(" if left blank, it will only write to default.\n");
97 entity W_PROP_reloader;
98 float autocvar_w_prop_interval = 5;
99 .void(Weapon this, int) wr_net;
100 void W_PROP_reload(int chan, entity to)
102 W_PROP_reloader.nextthink = time + autocvar_w_prop_interval;
104 FOREACH(Weapons, true, {
106 void(Weapon, int) f = it.wr_net;
110 void W_PROP_think(entity this)
112 W_PROP_reload(MSG_ALL, NULL);
114 STATIC_INIT_LATE(W_PROP_reloader)
116 entity e = W_PROP_reloader = new_pure(W_PROP_reloader);
117 setthink(e, W_PROP_think);
122 #define REGISTER_WEAPON(...) EVAL_REGISTER_WEAPON(OVERLOAD(REGISTER_WEAPON, __VA_ARGS__))
123 #define EVAL_REGISTER_WEAPON(...) __VA_ARGS__
124 #define REGISTER_WEAPON_2(id, inst) REGISTER(Weapons, WEP, id, m_id, inst)
125 /** TODO: deprecated - remove */
126 #define REGISTER_WEAPON_3(id, sname, inst) \
127 REGISTER_WEAPON_2(id, inst); \
128 [[alias("WEP_" #id)]] Weapon _wep_##sname
130 REGISTER_WEAPON(Null, NEW(Weapon));
132 Weapon Weapons_fromstr(string s)
134 FOREACH(Weapons, it != WEP_Null && it.netname == s, return it);
139 // legacy w_prop mappings
140 #define X(fld, T) .T fld; .T wepvar_##fld = fld;
141 X(switchdelay_drop, float)
142 X(switchdelay_raise, float)
143 X(weaponreplace, string)
144 X(weaponstartoverride, float)
145 X(weaponstart, float)
146 X(weaponthrowable, float)
148 X(reload_ammo, float)
149 .float reloading_ammo = reload_ammo;
150 X(reload_time, float)
151 .float reloading_time = reload_time;
157 #define W_PROPS(L, class, prefix) \
158 L(W_PROP_BEGIN, W_PROP, W_PROP_END, class, prefix) \
159 L(W_CONFIG_BEGIN, W_CONFIG, W_CONFIG_END, class, prefix) \
160 L(W_UPDATE_BEGIN, W_UPDATE, W_UPDATE_END, class, prefix) \
161 L(W_NET_BEGIN, W_NET, W_NET_END, class, prefix) \
165 #define W_PROP(class, wepname, fld, T, m) W_PROP_##m(class, fld, T, wepname)
166 #define W_PROP_NONE(class, fld, T, wepname) _W_PROP(class, fld, T, wepname)
167 #define W_PROP_PRI(class, fld, T, wepname) _W_PROP(class, primary_##fld, T, wepname)
168 #define W_PROP_SEC(class, fld, T, wepname) _W_PROP(class, secondary_##fld, T, wepname)
169 #define W_PROP_BOTH(class, fld, T, wepname) \
170 W_PROP_PRI(class, fld, T, wepname) \
171 W_PROP_SEC(class, fld, T, wepname)
172 #define W_PROP_BEGIN(class)
173 #define _W_PROP(class, fld, T, wepname) \
174 /* static */ T _W_PROP_CVAR(wepname, fld); \
175 ATTRIB(class, wepvar_##fld, T, _W_PROP_CVAR(wepname, fld));
176 #define _W_PROP_CVAR(wepname, fld) autocvar_g_balance_##wepname##_##fld
181 #define W_CONFIG(class, wepname, fld, T, m) W_CONFIG_##m(class, fld, T, wepname)
182 #define W_CONFIG_NONE(class, fld, T, wepname) _W_CONFIG(class, fld, T, wepname)
183 #define W_CONFIG_PRI(class, fld, T, wepname) _W_CONFIG(class, primary_##fld, T, wepname)
184 #define W_CONFIG_SEC(class, fld, T, wepname) _W_CONFIG(class, secondary_##fld, T, wepname)
185 #define W_CONFIG_BOTH(class, fld, T, wepname) \
186 W_CONFIG_PRI(class, fld, T, wepname) \
187 W_CONFIG_SEC(class, fld, T, wepname)
188 #define W_CONFIG_BEGIN(class) METHOD(class, wr_config, void(class this)) {
190 #define _W_CONFIG(class, fld, T, wepname) if (#wepname == this.netname) WEP_CONFIG_WRITE_CVARS(wepname, fld, T);
192 #define _W_CONFIG(class, fld, T, wepname)
194 #define W_CONFIG_END() }
197 #define W_UPDATE(class, wepname, fld, T, m) W_UPDATE_##m(class, fld, T, wepname)
198 #define W_UPDATE_NONE(class, fld, T, wepname) _W_UPDATE(class, fld, T, wepname)
199 #define W_UPDATE_PRI(class, fld, T, wepname) _W_UPDATE(class, primary_##fld, T, wepname)
200 #define W_UPDATE_SEC(class, fld, T, wepname) _W_UPDATE(class, secondary_##fld, T, wepname)
201 #define W_UPDATE_BOTH(class, fld, T, wepname) \
202 W_UPDATE_PRI(class, fld, T, wepname) \
203 W_UPDATE_SEC(class, fld, T, wepname)
204 .entity baseline, baseline_target;
205 #define W_UPDATE_BEGIN(class) \
206 METHOD(class, wr_update, void(class this)) \
208 noref entity b = this.baseline; \
211 b = this.baseline = new_pure(baseline); \
212 b.baseline_target = this; \
215 #define _W_UPDATE(class, fld, T, wepname) \
217 T it = _W_PROP_CVAR(wepname, fld); \
218 b.wepvar_##fld = this.wepvar_##fld; \
219 this.wepvar_##fld = it; \
222 #define _W_UPDATE(class, fld, T, wepname)
224 #define W_UPDATE_END() }
227 #define W_NET(class, wepname, fld, T, m) W_NET_##m(class, fld, T, wepname)
228 #define W_NET_NONE(class, fld, T, wepname) _W_NET(class, fld, T, wepname)
229 #define W_NET_PRI(class, fld, T, wepname) _W_NET(class, primary_##fld, T, wepname)
230 #define W_NET_SEC(class, fld, T, wepname) _W_NET(class, secondary_##fld, T, wepname)
231 #define W_NET_BOTH(class, fld, T, wepname) \
232 W_NET_PRI(class, fld, T, wepname) \
233 W_NET_SEC(class, fld, T, wepname)
234 REGISTER_NET_TEMP(WeaponUpdate)
236 #define W_NET_BEGIN(class) METHOD(class, wr_net, void(class this, int i)) { int n = 0;
237 #define _W_NET(class, fld, T, wepname) \
239 if (++n == i) this.wepvar_##fld = Read_##T(); \
241 .void(Weapon this, int i) wr_net;
242 NET_HANDLE(WeaponUpdate, bool isnew)
244 Weapon w = Weapons_from(ReadByte());
245 for (int i; (i = ReadByte()); )
251 #define W_NET_END() }
253 #define W_NET_BEGIN(class) \
254 METHOD(class, wr_net, void(class this, int chan)) \
256 bool commit = false; \
258 #define _W_NET(class, fld, T, wepname) \
261 T it = this.wepvar_##fld; \
262 if (chan == MSG_ONE || it != this.baseline.wepvar_##fld) \
264 if (!commit) { commit = true; WriteHeader(chan, WeaponUpdate); WriteByte(chan, this.m_id); } \
265 WriteByte(chan, i); Write_##T(chan, it); \
268 #define W_NET_END() \
269 if (commit) WriteByte(chan, 0); \
272 #define W_NET_BEGIN(class)
273 #define _W_NET(class, fld, T, wepname)
279 // read cvars from weapon settings
280 #define WEP_CVAR(wepname, name) (_wep_##wepname.wepvar_##name)
281 #define WEP_CVAR_PRI(wepname, name) WEP_CVAR(wepname, primary_##name)
282 #define WEP_CVAR_SEC(wepname, name) WEP_CVAR(wepname, secondary_##name)
283 #define WEP_CVAR_BOTH(wepname, isprimary, name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
285 const int WEP_FIRST = 1;
286 #define WEP_LAST (Weapons_COUNT - 1)
288 WepSet WEPSET_SUPERWEAPONS;
292 // TODO: remove after 0.8.2. Retains impulse number compatibility because 0.8.1 clients don't reload the weapons.cfg
293 #define WEP_HARDCODED_IMPULSES 20
295 // TODO: invert after 0.8.2. Will require moving 'best weapon' impulses
296 #define WEP_IMPULSE_BEGIN 230
297 #define WEP_IMPULSE_END bound(WEP_IMPULSE_BEGIN, WEP_IMPULSE_BEGIN + (Weapons_COUNT - 1) - 1, 253)
299 REGISTRY_SORT(Weapons, WEP_HARDCODED_IMPULSES + 1)
300 REGISTRY_CHECK(Weapons)
302 STATIC_INIT(register_weapons_done)
304 string inaccessible = "";
305 FOREACH(Weapons, true, {
306 WepSet set = it.m_wepset = _WepSet_FromWeapon(it.m_id = i);
308 if ((it.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set;
310 if (it == WEP_Null) continue;
311 int imp = WEP_IMPULSE_BEGIN + it.m_id - 1;
312 if (imp <= WEP_IMPULSE_END)
313 localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", it.netname, imp));
315 inaccessible = strcat(inaccessible, "\n", it.netname);
317 if (inaccessible) LOG_TRACEF("Impulse limit exceeded, weapon(s) will not be directly accessible: %s", inaccessible);
319 FOREACH(Weapons, true, it.wr_init(it));
321 weaponorder_byid = "";
322 for (int i = Weapons_MAX - 1; i >= 1; --i)
324 weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
325 weaponorder_byid = strzone(substring(weaponorder_byid, 1, -1));
331 .entity exteriorweaponentity;
332 vector weaponentity_glowmod(Weapon wep, entity actor, int c, entity wepent)
335 if (!(g = wep.wr_glow(wep, actor, wepent))) g = colormapPaletteColor(c & 0x0F, true) * 2;
341 //.int weapon; // current weapon
342 .string weaponname; // name of .weapon
344 .vector spawnorigin; // for casings
346 // weapon animation vectors:
352 // static frame globals
355 CASE(WFRAME, DONTCHANGE)
360 ENUMCLASS_END(WFRAME)
364 vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn);
365 void CL_WeaponEntity_SetModel(entity this, string name, bool _anim);