]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qc
b0262d4330e11686bde23085fd36be6eb4fcc460
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qc
1 #ifndef WEAPONS_ALL_C
2 #define WEAPONS_ALL_C
3
4 #include "all.qh"
5
6 #if defined(CSQC)
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"
15         #include "../util.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"
23 #elif defined(MENUQC)
24 #elif defined(SVQC)
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"
35     #include "../util.qh"
36     #include "../buffs.qh"
37     #include "../monsters/all.qh"
38     #include "config.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"
53 #endif
54 #ifndef MENUQC
55 #include "calculations.qc"
56 #endif
57 #define IMPLEMENTATION
58 #include "all.inc"
59 #undef IMPLEMENTATION
60
61 // WEAPON PLUGIN SYSTEM
62
63 #if WEP_MAXCOUNT > 72
64 # error Kein Weltraum links auf dem Gerät
65 #endif
66
67 WepSet WepSet_FromWeapon(int a) {
68         a -= WEP_FIRST;
69 #if WEP_MAXCOUNT > 24
70         if(a >= 24) {
71                 a -= 24;
72 #if WEP_MAXCOUNT > 48
73                 if(a >= 24) {
74                         a -= 24;
75                         return '0 0 1' * power2of(a);
76                 }
77 #endif
78                 return '0 1 0' * power2of(a);
79         }
80 #endif
81         return '1 0 0' * power2of(a);
82 }
83 #ifdef SVQC
84 void WepSet_AddStat()
85 {
86         addstat(STAT_WEAPONS, AS_INT, weapons_x);
87 #if WEP_MAXCOUNT > 24
88         addstat(STAT_WEAPONS2, AS_INT, weapons_y);
89 #if WEP_MAXCOUNT > 48
90         addstat(STAT_WEAPONS3, AS_INT, weapons_z);
91 #endif
92 #endif
93 }
94 void WepSet_AddStat_InMap()
95 {
96         addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
97 #if WEP_MAXCOUNT > 24
98         addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
99 #if WEP_MAXCOUNT > 48
100         addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
101 #endif
102 #endif
103 }
104 void WriteWepSet(float dst, WepSet w)
105 {
106 #if WEP_MAXCOUNT > 48
107         WriteInt72_t(dst, w);
108 #elif WEP_MAXCOUNT > 24
109         WriteInt48_t(dst, w);
110 #else
111         WriteInt24_t(dst, w.x);
112 #endif
113 }
114 #endif
115 #ifdef CSQC
116 WepSet WepSet_GetFromStat()
117 {
118         WepSet w = '0 0 0';
119         w.x = getstati(STAT_WEAPONS);
120 #if WEP_MAXCOUNT > 24
121         w.y = getstati(STAT_WEAPONS2);
122 #if WEP_MAXCOUNT > 48
123         w.z = getstati(STAT_WEAPONS3);
124 #endif
125 #endif
126         return w;
127 }
128 WepSet WepSet_GetFromStat_InMap()
129 {
130         WepSet w = '0 0 0';
131         w_x = getstati(STAT_WEAPONSINMAP);
132 #if WEP_MAXCOUNT > 24
133         w_y = getstati(STAT_WEAPONSINMAP2);
134 #if WEP_MAXCOUNT > 48
135         w_z = getstati(STAT_WEAPONSINMAP3);
136 #endif
137 #endif
138         return w;
139 }
140 WepSet ReadWepSet()
141 {
142 #if WEP_MAXCOUNT > 48
143         return ReadInt72_t();
144 #elif WEP_MAXCOUNT > 24
145         return ReadInt48_t();
146 #else
147         return ReadInt24_t() * '1 0 0';
148 #endif
149 }
150 #endif
151
152 void register_weapons_done()
153 {
154         dummy_weapon_info = spawn();
155         dummy_weapon_info.classname = "weapon_info";
156         dummy_weapon_info.weapon = 0; // you can recognize dummies by this
157         dummy_weapon_info.weapons = '0 0 0';
158         dummy_weapon_info.netname = "";
159         dummy_weapon_info.message = "AOL CD Thrower";
160         dummy_weapon_info.weapon_func = w_null;
161         dummy_weapon_info.wpmodel = "";
162         dummy_weapon_info.mdl = "";
163         dummy_weapon_info.model = "";
164         dummy_weapon_info.spawnflags = 0;
165         dummy_weapon_info.impulse = -1;
166         dummy_weapon_info.bot_pickupbasevalue = 0;
167         dummy_weapon_info.ammo_field = ammo_none;
168
169         dummy_weapon_info.w_crosshair = "gfx/crosshair1";
170         dummy_weapon_info.w_crosshair_size = 1;
171         dummy_weapon_info.model2 = "";
172
173         weaponorder_byid = "";
174         for (int i = WEP_MAXCOUNT - 1; i >= 0; --i)
175                 if (weapon_info[i])
176                         weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
177         weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
178 }
179 entity get_weaponinfo(int id)
180 {
181         entity w;
182         if(id < WEP_FIRST || id > WEP_LAST)
183                 return dummy_weapon_info;
184         w = weapon_info[id - 1];
185         if(w)
186                 return w;
187         return dummy_weapon_info;
188 }
189 string W_FixWeaponOrder(string order, float complete)
190 {
191         return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
192 }
193 string W_NameWeaponOrder_MapFunc(string s)
194 {
195         entity wi;
196         if(s == "0" || stof(s))
197         {
198                 wi = get_weaponinfo(stof(s));
199                 if(wi != dummy_weapon_info)
200                         return wi.netname;
201         }
202         return s;
203 }
204
205 string W_UndeprecateName(string s)
206 {
207         switch ( s )
208         {
209                 case "nex"            : return "vortex";
210                 case "rocketlauncher" : return "devastator";
211                 case "laser"          : return "blaster";
212                 case "minstanex"      : return "vaporizer";
213                 case "grenadelauncher": return "mortar";
214                 case "uzi"            : return "machinegun";
215                 default               : return s;
216         }
217 }
218 string W_NameWeaponOrder(string order)
219 {
220         return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
221 }
222 string W_NumberWeaponOrder_MapFunc(string s)
223 {
224         int i;
225         if(s == "0" || stof(s))
226                 return s;
227         s = W_UndeprecateName(s);
228         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
229                 if(s == get_weaponinfo(i).netname)
230                         return ftos(i);
231         return s;
232 }
233 string W_NumberWeaponOrder(string order)
234 {
235         return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
236 }
237
238 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
239 string W_FixWeaponOrder_BuildImpulseList_order;
240 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
241 {
242         float h;
243         h = W_FixWeaponOrder_BuildImpulseList_buf[i];
244         W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
245         W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
246 }
247 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
248 {
249         entity e1, e2;
250         float d;
251         e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
252         e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
253         d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
254         if(d != 0)
255                 return -d; // high impulse first!
256         return
257                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
258                 -
259                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
260                 ; // low char index first!
261 }
262 string W_FixWeaponOrder_BuildImpulseList(string o)
263 {
264         int i;
265         W_FixWeaponOrder_BuildImpulseList_order = o;
266         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
267                 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
268         heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
269         o = "";
270         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
271                 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
272         W_FixWeaponOrder_BuildImpulseList_order = string_null;
273         return substring(o, 1, -1);
274 }
275
276 string W_FixWeaponOrder_AllowIncomplete(string order)
277 {
278         return W_FixWeaponOrder(order, 0);
279 }
280
281 string W_FixWeaponOrder_ForceComplete(string order)
282 {
283         if(order == "")
284                 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
285         return W_FixWeaponOrder(order, 1);
286 }
287
288 void W_RandomWeapons(entity e, float n)
289 {
290         int i, j;
291         WepSet remaining;
292         WepSet result;
293         remaining = e.weapons;
294         result = '0 0 0';
295         for(i = 0; i < n; ++i)
296         {
297                 RandomSelection_Init();
298                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
299                         if(remaining & WepSet_FromWeapon(j))
300                                 RandomSelection_Add(world, j, string_null, 1, 1);
301                 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
302                 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
303         }
304         e.weapons = result;
305 }
306
307 string GetAmmoPicture(.int ammotype)
308 {
309         switch(ammotype)
310         {
311                 case ammo_shells:  return "ammo_shells";
312                 case ammo_nails:   return "ammo_bullets";
313                 case ammo_rockets: return "ammo_rockets";
314                 case ammo_cells:   return "ammo_cells";
315                 case ammo_plasma:  return "ammo_cells";
316                 case ammo_fuel:    return "ammo_fuel";
317                 default: return ""; // wtf, no ammo type?
318         }
319 }
320
321 #ifdef CSQC
322 .int GetAmmoFieldFromNum(int i)
323 {
324         switch(i)
325         {
326                 case 0: return ammo_shells;
327                 case 1: return ammo_nails;
328                 case 2: return ammo_rockets;
329                 case 3: return ammo_cells;
330                 case 4: return ammo_plasma;
331                 case 5: return ammo_fuel;
332                 default: return ammo_none;
333         }
334 }
335
336 int GetAmmoStat(.int ammotype)
337 {
338         switch(ammotype)
339         {
340                 case ammo_shells: return STAT_SHELLS;
341                 case ammo_nails: return STAT_NAILS;
342                 case ammo_rockets: return STAT_ROCKETS;
343                 case ammo_cells: return STAT_CELLS;
344                 case ammo_plasma: return STAT_PLASMA;
345                 case ammo_fuel: return STAT_FUEL;
346                 default: return -1;
347         }
348 }
349 #endif
350 #endif