7 #include "../../client/defs.qh"
8 #include "../constants.qh"
10 #include "../../lib/warpzone/anglestransform.qh"
11 #include "../../lib/warpzone/common.qh"
12 #include "../../lib/warpzone/client.qh"
14 #include "../buffs/all.qh"
15 #include "../../client/autocvars.qh"
16 #include "../deathtypes/all.qh"
17 #include "../../lib/csqcmodel/interpolate.qh"
18 #include "../movetypes/movetypes.qh"
19 #include "../../client/main.qh"
20 #include "../../lib/csqcmodel/cl_model.qh"
23 #include "../../lib/warpzone/anglestransform.qh"
24 #include "../../lib/warpzone/common.qh"
25 #include "../../lib/warpzone/util_server.qh"
26 #include "../../lib/warpzone/server.qh"
27 #include "../constants.qh"
28 #include "../stats.qh"
29 #include "../teams.qh"
31 #include "../buffs/all.qh"
32 #include "../monsters/all.qh"
34 #include "../../server/weapons/csqcprojectile.qh"
35 #include "../../server/weapons/tracing.qh"
36 #include "../../server/t_items.qh"
37 #include "../../server/autocvars.qh"
38 #include "../../server/constants.qh"
39 #include "../../server/defs.qh"
40 #include "../notifications.qh"
41 #include "../deathtypes/all.qh"
42 #include "../../server/mutators/all.qh"
43 #include "../mapinfo.qh"
44 #include "../../server/command/common.qh"
45 #include "../../lib/csqcmodel/sv_model.qh"
46 #include "../../server/portals.qh"
47 #include "../../server/g_hook.qh"
50 #include "calculations.qc"
52 #define IMPLEMENTATION
56 // WEAPON PLUGIN SYSTEM
58 WepSet WepSet_FromWeapon(int a) {
66 return '0 0 1' * power2of(a);
68 return '0 1 0' * power2of(a);
70 return '1 0 0' * power2of(a);
75 addstat(STAT_WEAPONS, AS_INT, weapons_x);
77 addstat(STAT_WEAPONS2, AS_INT, weapons_y);
79 addstat(STAT_WEAPONS3, AS_INT, weapons_z);
81 void WepSet_AddStat_InMap()
83 addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
85 addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
87 addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
89 void WriteWepSet(float dst, WepSet w)
93 else if (Weapons_MAX > 24)
96 WriteInt24_t(dst, w.x);
100 WepSet WepSet_GetFromStat()
103 w.x = getstati(STAT_WEAPONS);
104 if (Weapons_MAX > 24)
105 w.y = getstati(STAT_WEAPONS2);
106 if (Weapons_MAX > 48)
107 w.z = getstati(STAT_WEAPONS3);
110 WepSet WepSet_GetFromStat_InMap()
113 w_x = getstati(STAT_WEAPONSINMAP);
114 if (Weapons_MAX > 24)
115 w_y = getstati(STAT_WEAPONSINMAP2);
116 if (Weapons_MAX > 48)
117 w_z = getstati(STAT_WEAPONSINMAP3);
122 if (Weapons_MAX > 48)
123 return ReadInt72_t();
124 if (Weapons_MAX > 24)
125 return ReadInt48_t();
126 return ReadInt24_t() * '1 0 0';
130 string W_FixWeaponOrder(string order, float complete)
132 return fixPriorityList(order, WEP_FIRST, WEP_LAST, WEP_IMPULSE_BEGIN - WEP_FIRST, complete);
134 string W_NameWeaponOrder_MapFunc(string s)
137 if(s == "0" || stof(s))
139 wi = get_weaponinfo(stof(s));
146 string W_UndeprecateName(string s)
150 case "nex" : return "vortex";
151 case "rocketlauncher" : return "devastator";
152 case "laser" : return "blaster";
153 case "minstanex" : return "vaporizer";
154 case "grenadelauncher": return "mortar";
155 case "uzi" : return "machinegun";
159 string W_NameWeaponOrder(string order)
161 return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
163 string W_NumberWeaponOrder_MapFunc(string s)
166 if(s == "0" || stof(s))
168 s = W_UndeprecateName(s);
169 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
170 if(s == get_weaponinfo(i).netname)
174 string W_NumberWeaponOrder(string order)
176 return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
179 float W_FixWeaponOrder_BuildImpulseList_buf[Weapons_MAX];
180 string W_FixWeaponOrder_BuildImpulseList_order;
181 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
184 h = W_FixWeaponOrder_BuildImpulseList_buf[i];
185 W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
186 W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
188 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
192 e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
193 e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
194 d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
196 return -d; // high impulse first!
198 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
200 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
201 ; // low char index first!
203 string W_FixWeaponOrder_BuildImpulseList(string o)
206 W_FixWeaponOrder_BuildImpulseList_order = o;
207 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
208 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
209 heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
211 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
212 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
213 W_FixWeaponOrder_BuildImpulseList_order = string_null;
214 return substring(o, 1, -1);
217 string W_FixWeaponOrder_AllowIncomplete(string order)
219 return W_FixWeaponOrder(order, 0);
222 string W_FixWeaponOrder_ForceComplete(string order)
225 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
226 return W_FixWeaponOrder(order, 1);
229 void W_RandomWeapons(entity e, float n)
234 remaining = e.weapons;
236 for(i = 0; i < n; ++i)
238 RandomSelection_Init();
239 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
240 if(remaining & WepSet_FromWeapon(j))
241 RandomSelection_Add(world, j, string_null, 1, 1);
242 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
243 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
248 string GetAmmoPicture(.int ammotype)
252 case ammo_shells: return ITEM_Shells.m_icon;
253 case ammo_nails: return ITEM_Bullets.m_icon;
254 case ammo_rockets: return ITEM_Rockets.m_icon;
255 case ammo_cells: return ITEM_Cells.m_icon;
256 case ammo_plasma: return ITEM_Plasma.m_icon;
257 case ammo_fuel: return ITEM_JetpackFuel.m_icon;
258 default: return ""; // wtf, no ammo type?
263 .int GetAmmoFieldFromNum(int i)
267 case 0: return ammo_shells;
268 case 1: return ammo_nails;
269 case 2: return ammo_rockets;
270 case 3: return ammo_cells;
271 case 4: return ammo_plasma;
272 case 5: return ammo_fuel;
273 default: return ammo_none;
277 int GetAmmoStat(.int ammotype)
281 case ammo_shells: return STAT_SHELLS;
282 case ammo_nails: return STAT_NAILS;
283 case ammo_rockets: return STAT_ROCKETS;
284 case ammo_cells: return STAT_CELLS;
285 case ammo_plasma: return STAT_PLASMA;
286 case ammo_fuel: return STAT_FUEL;
292 string W_Sound(string w_snd)
294 #define extensions(X) X(wav) X(ogg)
295 #define tryext(ext) { if (fexists(strcat("sound/", output = strcat("weapons/", w_snd, "."#ext)))) break; }
301 output = strcat("weapons/", w_snd);
305 MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
306 return weapon_sound_output;
312 string W_Model(string w_mdl)
314 string output = strcat("models/weapons/", w_mdl);
316 MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
317 return weapon_model_output;