7 #include "../../dpdefs/csprogsdefs.qh"
8 #include "../../client/defs.qh"
9 #include "../constants.qh"
10 #include "../stats.qh"
11 #include "../../warpzonelib/anglestransform.qh"
12 #include "../../warpzonelib/mathlib.qh"
13 #include "../../warpzonelib/common.qh"
14 #include "../../warpzonelib/client.qh"
16 #include "../buffs.qh"
17 #include "../../client/autocvars.qh"
18 #include "../deathtypes.qh"
19 #include "../../csqcmodellib/interpolate.qh"
20 #include "../movetypes/movetypes.qh"
21 #include "../../client/main.qh"
22 #include "../../csqcmodellib/cl_model.qh"
25 #include "../../dpdefs/progsdefs.qh"
26 #include "../../dpdefs/dpextensions.qh"
27 #include "../../warpzonelib/anglestransform.qh"
28 #include "../../warpzonelib/mathlib.qh"
29 #include "../../warpzonelib/common.qh"
30 #include "../../warpzonelib/util_server.qh"
31 #include "../../warpzonelib/server.qh"
32 #include "../constants.qh"
33 #include "../stats.qh"
34 #include "../teams.qh"
36 #include "../buffs.qh"
37 #include "../monsters/all.qh"
39 #include "../../server/weapons/csqcprojectile.qh"
40 #include "../../server/weapons/tracing.qh"
41 #include "../../server/t_items.qh"
42 #include "../../server/autocvars.qh"
43 #include "../../server/constants.qh"
44 #include "../../server/defs.qh"
45 #include "../notifications.qh"
46 #include "../deathtypes.qh"
47 #include "../../server/mutators/mutators_include.qh"
48 #include "../mapinfo.qh"
49 #include "../../server/command/common.qh"
50 #include "../../csqcmodellib/sv_model.qh"
51 #include "../../server/portals.qh"
52 #include "../../server/g_hook.qh"
55 #include "calculations.qc"
57 #define IMPLEMENTATION
61 // WEAPON PLUGIN SYSTEM
62 entity weapon_info[WEP_MAXCOUNT];
63 entity dummy_weapon_info;
66 # error Kein Weltraum links auf dem Gerät
69 WepSet WepSet_FromWeapon(int a) {
77 return '0 0 1' * power2of(a);
80 return '0 1 0' * power2of(a);
83 return '1 0 0' * power2of(a);
88 addstat(STAT_WEAPONS, AS_INT, weapons_x);
90 addstat(STAT_WEAPONS2, AS_INT, weapons_y);
92 addstat(STAT_WEAPONS3, AS_INT, weapons_z);
96 void WepSet_AddStat_InMap()
98 addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
100 addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
101 #if WEP_MAXCOUNT > 48
102 addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
106 void WriteWepSet(float dst, WepSet w)
108 #if WEP_MAXCOUNT > 48
109 WriteInt72_t(dst, w);
110 #elif WEP_MAXCOUNT > 24
111 WriteInt48_t(dst, w);
113 WriteInt24_t(dst, w.x);
118 WepSet WepSet_GetFromStat()
121 w.x = getstati(STAT_WEAPONS);
122 #if WEP_MAXCOUNT > 24
123 w.y = getstati(STAT_WEAPONS2);
124 #if WEP_MAXCOUNT > 48
125 w.z = getstati(STAT_WEAPONS3);
130 WepSet WepSet_GetFromStat_InMap()
133 w_x = getstati(STAT_WEAPONSINMAP);
134 #if WEP_MAXCOUNT > 24
135 w_y = getstati(STAT_WEAPONSINMAP2);
136 #if WEP_MAXCOUNT > 48
137 w_z = getstati(STAT_WEAPONSINMAP3);
144 #if WEP_MAXCOUNT > 48
145 return ReadInt72_t();
146 #elif WEP_MAXCOUNT > 24
147 return ReadInt48_t();
149 return ReadInt24_t() * '1 0 0';
154 void register_weapon(
161 float pickupbasevalue,
171 weapon_info[id - 1] = e = spawn();
172 e.classname = "weapon_info";
175 e.weapon_func = func;
176 e.ammo_field = ammotype;
178 e.spawnflags = weapontype;
179 e.bot_pickupbasevalue = pickupbasevalue;
181 e.wpmodel = strzone(strcat("wpn-", ftos(id)));
183 e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
184 e.w_simplemdl = strzone(simplemdl); // simpleitems weapon model/image
185 e.w_crosshair = strzone(car(crosshair));
186 string s = cdr(crosshair);
187 e.w_crosshair_size = ((s != "") ? stof(s) : 1); // so that we can scale the crosshair from code (for compat)
188 e.model2 = strzone(wepimg);
196 bool w_null(int dummy)
200 void register_weapons_done()
202 dummy_weapon_info = spawn();
203 dummy_weapon_info.classname = "weapon_info";
204 dummy_weapon_info.weapon = 0; // you can recognize dummies by this
205 dummy_weapon_info.weapons = '0 0 0';
206 dummy_weapon_info.netname = "";
207 dummy_weapon_info.message = "AOL CD Thrower";
208 dummy_weapon_info.weapon_func = w_null;
209 dummy_weapon_info.wpmodel = "";
210 dummy_weapon_info.mdl = "";
211 dummy_weapon_info.model = "";
212 dummy_weapon_info.spawnflags = 0;
213 dummy_weapon_info.impulse = -1;
214 dummy_weapon_info.bot_pickupbasevalue = 0;
215 dummy_weapon_info.ammo_field = ammo_none;
217 dummy_weapon_info.w_crosshair = "gfx/crosshair1";
218 dummy_weapon_info.w_crosshair_size = 1;
219 dummy_weapon_info.model2 = "";
222 weaponorder_byid = "";
223 for(i = WEP_MAXCOUNT; i >= 1; --i)
225 weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
226 weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
228 entity get_weaponinfo(int id)
231 if(id < WEP_FIRST || id > WEP_LAST)
232 return dummy_weapon_info;
233 w = weapon_info[id - 1];
236 return dummy_weapon_info;
238 string W_FixWeaponOrder(string order, float complete)
240 return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
242 string W_NameWeaponOrder_MapFunc(string s)
245 if(s == "0" || stof(s))
247 wi = get_weaponinfo(stof(s));
248 if(wi != dummy_weapon_info)
254 string W_UndeprecateName(string s)
258 case "nex" : return "vortex";
259 case "rocketlauncher" : return "devastator";
260 case "laser" : return "blaster";
261 case "minstanex" : return "vaporizer";
262 case "grenadelauncher": return "mortar";
263 case "uzi" : return "machinegun";
267 string W_NameWeaponOrder(string order)
269 return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
271 string W_NumberWeaponOrder_MapFunc(string s)
274 if(s == "0" || stof(s))
276 s = W_UndeprecateName(s);
277 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
278 if(s == get_weaponinfo(i).netname)
282 string W_NumberWeaponOrder(string order)
284 return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
287 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
288 string W_FixWeaponOrder_BuildImpulseList_order;
289 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
292 h = W_FixWeaponOrder_BuildImpulseList_buf[i];
293 W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
294 W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
296 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
300 e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
301 e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
302 d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
304 return -d; // high impulse first!
306 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
308 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
309 ; // low char index first!
311 string W_FixWeaponOrder_BuildImpulseList(string o)
314 W_FixWeaponOrder_BuildImpulseList_order = o;
315 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
316 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
317 heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
319 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
320 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
321 W_FixWeaponOrder_BuildImpulseList_order = string_null;
322 return substring(o, 1, -1);
325 string W_FixWeaponOrder_AllowIncomplete(string order)
327 return W_FixWeaponOrder(order, 0);
330 string W_FixWeaponOrder_ForceComplete(string order)
333 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
334 return W_FixWeaponOrder(order, 1);
337 void W_RandomWeapons(entity e, float n)
342 remaining = e.weapons;
344 for(i = 0; i < n; ++i)
346 RandomSelection_Init();
347 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
348 if(remaining & WepSet_FromWeapon(j))
349 RandomSelection_Add(world, j, string_null, 1, 1);
350 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
351 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
356 string GetAmmoPicture(.int ammotype)
360 case ammo_shells: return "ammo_shells";
361 case ammo_nails: return "ammo_bullets";
362 case ammo_rockets: return "ammo_rockets";
363 case ammo_cells: return "ammo_cells";
364 case ammo_plasma: return "ammo_cells";
365 case ammo_fuel: return "ammo_fuel";
366 default: return ""; // wtf, no ammo type?
371 .int GetAmmoFieldFromNum(int i)
375 case 0: return ammo_shells;
376 case 1: return ammo_nails;
377 case 2: return ammo_rockets;
378 case 3: return ammo_cells;
379 case 4: return ammo_plasma;
380 case 5: return ammo_fuel;
381 default: return ammo_none;
385 int GetAmmoStat(.int ammotype)
389 case ammo_shells: return STAT_SHELLS;
390 case ammo_nails: return STAT_NAILS;
391 case ammo_rockets: return STAT_ROCKETS;
392 case ammo_cells: return STAT_CELLS;
393 case ammo_plasma: return STAT_PLASMA;
394 case ammo_fuel: return STAT_FUEL;