]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qc
Merge branch 'master' into Mario/bulldozer
[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 "../../client/defs.qh"
8         #include "../constants.qh"
9         #include "../stats.qh"
10         #include "../../lib/warpzone/anglestransform.qh"
11         #include "../../lib/warpzone/common.qh"
12         #include "../../lib/warpzone/client.qh"
13         #include "../util.qh"
14         #include "../../client/autocvars.qh"
15         #include "../deathtypes/all.qh"
16         #include "../../lib/csqcmodel/interpolate.qh"
17         #include "../movetypes/movetypes.qh"
18         #include "../../client/main.qh"
19         #include "../../lib/csqcmodel/cl_model.qh"
20 #elif defined(MENUQC)
21 #elif defined(SVQC)
22     #include "../../lib/warpzone/anglestransform.qh"
23     #include "../../lib/warpzone/common.qh"
24     #include "../../lib/warpzone/util_server.qh"
25     #include "../../lib/warpzone/server.qh"
26     #include "../constants.qh"
27     #include "../stats.qh"
28     #include "../teams.qh"
29     #include "../util.qh"
30     #include "../monsters/all.qh"
31     #include "config.qh"
32     #include "../../server/weapons/csqcprojectile.qh"
33     #include "../../server/weapons/tracing.qh"
34     #include "../../server/t_items.qh"
35     #include "../../server/autocvars.qh"
36     #include "../../server/constants.qh"
37     #include "../../server/defs.qh"
38     #include "../notifications.qh"
39     #include "../deathtypes/all.qh"
40     #include "../../server/mutators/all.qh"
41     #include "../mapinfo.qh"
42     #include "../../server/command/common.qh"
43     #include "../../lib/csqcmodel/sv_model.qh"
44     #include "../../server/portals.qh"
45     #include "../../server/g_hook.qh"
46 #endif
47 #ifndef MENUQC
48 #include "calculations.qc"
49 #endif
50 #define IMPLEMENTATION
51 #include "all.inc"
52 #undef IMPLEMENTATION
53
54 // WEAPON PLUGIN SYSTEM
55
56 WepSet WepSet_FromWeapon(int a) {
57         a -= WEP_FIRST;
58         if (Weapons_MAX > 24)
59         if (a >= 24) {
60                 a -= 24;
61                 if (Weapons_MAX > 48)
62                 if (a >= 24) {
63                         a -= 24;
64                         return '0 0 1' * power2of(a);
65                 }
66                 return '0 1 0' * power2of(a);
67         }
68         return '1 0 0' * power2of(a);
69 }
70 #ifdef SVQC
71 void WepSet_AddStat()
72 {
73         addstat(STAT_WEAPONS, AS_INT, weapons_x);
74         if (Weapons_MAX > 24)
75         addstat(STAT_WEAPONS2, AS_INT, weapons_y);
76         if (Weapons_MAX > 48)
77         addstat(STAT_WEAPONS3, AS_INT, weapons_z);
78 }
79 void WepSet_AddStat_InMap()
80 {
81         addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
82         if (Weapons_MAX > 24)
83         addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
84         if (Weapons_MAX > 48)
85         addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
86 }
87 void WriteWepSet(float dst, WepSet w)
88 {
89         if (Weapons_MAX > 48)
90         WriteInt72_t(dst, w);
91         else if (Weapons_MAX > 24)
92         WriteInt48_t(dst, w);
93         else
94         WriteInt24_t(dst, w.x);
95 }
96 #endif
97 #ifdef CSQC
98 WepSet WepSet_GetFromStat()
99 {
100         WepSet w = '0 0 0';
101         w.x = getstati(STAT_WEAPONS);
102         if (Weapons_MAX > 24)
103         w.y = getstati(STAT_WEAPONS2);
104         if (Weapons_MAX > 48)
105         w.z = getstati(STAT_WEAPONS3);
106         return w;
107 }
108 WepSet WepSet_GetFromStat_InMap()
109 {
110         WepSet w = '0 0 0';
111         w_x = getstati(STAT_WEAPONSINMAP);
112         if (Weapons_MAX > 24)
113         w_y = getstati(STAT_WEAPONSINMAP2);
114         if (Weapons_MAX > 48)
115         w_z = getstati(STAT_WEAPONSINMAP3);
116         return w;
117 }
118 WepSet ReadWepSet()
119 {
120         if (Weapons_MAX > 48)
121         return ReadInt72_t();
122         if (Weapons_MAX > 24)
123         return ReadInt48_t();
124         return ReadInt24_t() * '1 0 0';
125 }
126 #endif
127
128 string W_FixWeaponOrder(string order, float complete)
129 {
130         return fixPriorityList(order, WEP_FIRST, WEP_LAST, WEP_IMPULSE_BEGIN - WEP_FIRST, complete);
131 }
132 string W_NameWeaponOrder_MapFunc(string s)
133 {
134         entity wi;
135         if(s == "0" || stof(s))
136         {
137                 wi = get_weaponinfo(stof(s));
138                 if(wi != WEP_Null)
139                         return wi.netname;
140         }
141         return s;
142 }
143
144 string W_UndeprecateName(string s)
145 {
146         switch ( s )
147         {
148                 case "nex"            : return "vortex";
149                 case "rocketlauncher" : return "devastator";
150                 case "laser"          : return "blaster";
151                 case "minstanex"      : return "vaporizer";
152                 case "grenadelauncher": return "mortar";
153                 case "uzi"            : return "machinegun";
154                 default               : return s;
155         }
156 }
157 string W_NameWeaponOrder(string order)
158 {
159         return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
160 }
161 string W_NumberWeaponOrder_MapFunc(string s)
162 {
163         int i;
164         if(s == "0" || stof(s))
165                 return s;
166         s = W_UndeprecateName(s);
167         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
168                 if(s == get_weaponinfo(i).netname)
169                         return ftos(i);
170         return s;
171 }
172 string W_NumberWeaponOrder(string order)
173 {
174         return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
175 }
176
177 float W_FixWeaponOrder_BuildImpulseList_buf[Weapons_MAX];
178 string W_FixWeaponOrder_BuildImpulseList_order;
179 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
180 {
181         float h;
182         h = W_FixWeaponOrder_BuildImpulseList_buf[i];
183         W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
184         W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
185 }
186 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
187 {
188         entity e1, e2;
189         float d;
190         e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
191         e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
192         d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
193         if(d != 0)
194                 return -d; // high impulse first!
195         return
196                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
197                 -
198                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
199                 ; // low char index first!
200 }
201 string W_FixWeaponOrder_BuildImpulseList(string o)
202 {
203         int i;
204         W_FixWeaponOrder_BuildImpulseList_order = o;
205         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
206                 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
207         heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
208         o = "";
209         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
210                 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
211         W_FixWeaponOrder_BuildImpulseList_order = string_null;
212         return substring(o, 1, -1);
213 }
214
215 string W_FixWeaponOrder_AllowIncomplete(string order)
216 {
217         return W_FixWeaponOrder(order, 0);
218 }
219
220 string W_FixWeaponOrder_ForceComplete(string order)
221 {
222         if(order == "")
223                 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
224         return W_FixWeaponOrder(order, 1);
225 }
226
227 void W_RandomWeapons(entity e, float n)
228 {
229         int i, j;
230         WepSet remaining;
231         WepSet result;
232         remaining = e.weapons;
233         result = '0 0 0';
234         for(i = 0; i < n; ++i)
235         {
236                 RandomSelection_Init();
237                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
238                         if(remaining & WepSet_FromWeapon(j))
239                                 RandomSelection_Add(world, j, string_null, 1, 1);
240                 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
241                 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
242         }
243         e.weapons = result;
244 }
245
246 string GetAmmoPicture(.int ammotype)
247 {
248         switch (ammotype)
249         {
250                 case ammo_shells:  return ITEM_Shells.m_icon;
251                 case ammo_nails:   return ITEM_Bullets.m_icon;
252                 case ammo_rockets: return ITEM_Rockets.m_icon;
253                 case ammo_cells:   return ITEM_Cells.m_icon;
254                 case ammo_plasma:  return ITEM_Plasma.m_icon;
255                 case ammo_fuel:    return ITEM_JetpackFuel.m_icon;
256                 default: return ""; // wtf, no ammo type?
257         }
258 }
259
260 #ifdef CSQC
261 .int GetAmmoFieldFromNum(int i)
262 {
263         switch(i)
264         {
265                 case 0: return ammo_shells;
266                 case 1: return ammo_nails;
267                 case 2: return ammo_rockets;
268                 case 3: return ammo_cells;
269                 case 4: return ammo_plasma;
270                 case 5: return ammo_fuel;
271                 default: return ammo_none;
272         }
273 }
274
275 int GetAmmoStat(.int ammotype)
276 {
277         switch(ammotype)
278         {
279                 case ammo_shells: return STAT_SHELLS;
280                 case ammo_nails: return STAT_NAILS;
281                 case ammo_rockets: return STAT_ROCKETS;
282                 case ammo_cells: return STAT_CELLS;
283                 case ammo_plasma: return STAT_PLASMA;
284                 case ammo_fuel: return STAT_FUEL;
285                 default: return -1;
286         }
287 }
288 #endif
289
290 string W_Sound(string w_snd)
291 {
292         string output = strcat("weapons/", w_snd);
293 #ifdef SVQC
294         MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
295         return weapon_sound_output;
296 #else
297         return output;
298 #endif
299 }
300
301 string W_Model(string w_mdl)
302 {
303         string output = strcat("models/weapons/", w_mdl);
304 #ifdef SVQC
305         MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
306         return weapon_model_output;
307 #else
308         return output;
309 #endif
310 }
311
312 #endif