]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qc
Merge branch 'terencehill/itemstime_readyrestart_fix' into 'master'
[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 = NEW(Weapon);
155
156         weaponorder_byid = "";
157         for (int i = WEP_MAXCOUNT - 1; i >= 0; --i)
158                 if (weapon_info[i])
159                         weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
160         weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
161 }
162 entity get_weaponinfo(int id)
163 {
164         entity w;
165         if(id < WEP_FIRST || id > WEP_LAST)
166                 return dummy_weapon_info;
167         w = weapon_info[id - 1];
168         if(w)
169                 return w;
170         return dummy_weapon_info;
171 }
172 string W_FixWeaponOrder(string order, float complete)
173 {
174         return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
175 }
176 string W_NameWeaponOrder_MapFunc(string s)
177 {
178         entity wi;
179         if(s == "0" || stof(s))
180         {
181                 wi = get_weaponinfo(stof(s));
182                 if(wi != dummy_weapon_info)
183                         return wi.netname;
184         }
185         return s;
186 }
187
188 string W_UndeprecateName(string s)
189 {
190         switch ( s )
191         {
192                 case "nex"            : return "vortex";
193                 case "rocketlauncher" : return "devastator";
194                 case "laser"          : return "blaster";
195                 case "minstanex"      : return "vaporizer";
196                 case "grenadelauncher": return "mortar";
197                 case "uzi"            : return "machinegun";
198                 default               : return s;
199         }
200 }
201 string W_NameWeaponOrder(string order)
202 {
203         return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
204 }
205 string W_NumberWeaponOrder_MapFunc(string s)
206 {
207         int i;
208         if(s == "0" || stof(s))
209                 return s;
210         s = W_UndeprecateName(s);
211         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
212                 if(s == get_weaponinfo(i).netname)
213                         return ftos(i);
214         return s;
215 }
216 string W_NumberWeaponOrder(string order)
217 {
218         return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
219 }
220
221 float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
222 string W_FixWeaponOrder_BuildImpulseList_order;
223 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
224 {
225         float h;
226         h = W_FixWeaponOrder_BuildImpulseList_buf[i];
227         W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
228         W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
229 }
230 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
231 {
232         entity e1, e2;
233         float d;
234         e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
235         e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
236         d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
237         if(d != 0)
238                 return -d; // high impulse first!
239         return
240                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
241                 -
242                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
243                 ; // low char index first!
244 }
245 string W_FixWeaponOrder_BuildImpulseList(string o)
246 {
247         int i;
248         W_FixWeaponOrder_BuildImpulseList_order = o;
249         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
250                 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
251         heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
252         o = "";
253         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
254                 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
255         W_FixWeaponOrder_BuildImpulseList_order = string_null;
256         return substring(o, 1, -1);
257 }
258
259 string W_FixWeaponOrder_AllowIncomplete(string order)
260 {
261         return W_FixWeaponOrder(order, 0);
262 }
263
264 string W_FixWeaponOrder_ForceComplete(string order)
265 {
266         if(order == "")
267                 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
268         return W_FixWeaponOrder(order, 1);
269 }
270
271 void W_RandomWeapons(entity e, float n)
272 {
273         int i, j;
274         WepSet remaining;
275         WepSet result;
276         remaining = e.weapons;
277         result = '0 0 0';
278         for(i = 0; i < n; ++i)
279         {
280                 RandomSelection_Init();
281                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
282                         if(remaining & WepSet_FromWeapon(j))
283                                 RandomSelection_Add(world, j, string_null, 1, 1);
284                 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
285                 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
286         }
287         e.weapons = result;
288 }
289
290 string GetAmmoPicture(.int ammotype)
291 {
292         switch (ammotype)
293         {
294                 case ammo_shells:  return ITEM_Shells.m_icon;
295                 case ammo_nails:   return ITEM_Bullets.m_icon;
296                 case ammo_rockets: return ITEM_Rockets.m_icon;
297                 case ammo_cells:   return ITEM_Cells.m_icon;
298                 case ammo_plasma:  return ITEM_Plasma.m_icon;
299                 case ammo_fuel:    return ITEM_JetpackFuel.m_icon;
300                 default: return ""; // wtf, no ammo type?
301         }
302 }
303
304 #ifdef CSQC
305 .int GetAmmoFieldFromNum(int i)
306 {
307         switch(i)
308         {
309                 case 0: return ammo_shells;
310                 case 1: return ammo_nails;
311                 case 2: return ammo_rockets;
312                 case 3: return ammo_cells;
313                 case 4: return ammo_plasma;
314                 case 5: return ammo_fuel;
315                 default: return ammo_none;
316         }
317 }
318
319 int GetAmmoStat(.int ammotype)
320 {
321         switch(ammotype)
322         {
323                 case ammo_shells: return STAT_SHELLS;
324                 case ammo_nails: return STAT_NAILS;
325                 case ammo_rockets: return STAT_ROCKETS;
326                 case ammo_cells: return STAT_CELLS;
327                 case ammo_plasma: return STAT_PLASMA;
328                 case ammo_fuel: return STAT_FUEL;
329                 default: return -1;
330         }
331 }
332 #endif
333
334 string W_Sound(string w_snd)
335 {
336         string output = strcat("weapons/", w_snd, ".wav");
337 #ifdef SVQC
338         MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
339         return weapon_sound_output;
340 #else
341         return output;
342 #endif
343 }
344
345 string W_Model(string w_mdl)
346 {
347         string output = strcat("models/weapons/", w_mdl);
348 #ifdef SVQC
349         MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
350         return weapon_model_output;
351 #else
352         return output;
353 #endif
354 }
355
356 #endif