]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qc
Stats: port vectors
[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 "../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"
21 #elif defined(MENUQC)
22 #elif defined(SVQC)
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"
30     #include "../util.qh"
31     #include "../buffs/all.qh"
32     #include "../monsters/all.qh"
33     #include "config.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"
48 #endif
49 #ifndef MENUQC
50 #include "calculations.qc"
51 #endif
52 #define IMPLEMENTATION
53 #include "all.inc"
54 #undef IMPLEMENTATION
55
56 // WEAPON PLUGIN SYSTEM
57
58 WepSet WepSet_FromWeapon(int a) {
59         a -= WEP_FIRST;
60         if (Weapons_MAX > 24)
61         if (a >= 24) {
62                 a -= 24;
63                 if (Weapons_MAX > 48)
64                 if (a >= 24) {
65                         a -= 24;
66                         return '0 0 1' * power2of(a);
67                 }
68                 return '0 1 0' * power2of(a);
69         }
70         return '1 0 0' * power2of(a);
71 }
72 #ifdef SVQC
73 void WriteWepSet(float dst, WepSet w)
74 {
75         if (Weapons_MAX > 48)
76         WriteInt72_t(dst, w);
77         else if (Weapons_MAX > 24)
78         WriteInt48_t(dst, w);
79         else
80         WriteInt24_t(dst, w.x);
81 }
82 #endif
83 #ifdef CSQC
84 WepSet WepSet_GetFromStat()
85 {
86         return STAT(WEAPONS);
87 }
88 WepSet WepSet_GetFromStat_InMap()
89 {
90         return STAT(WEAPONSINMAP);
91 }
92 WepSet ReadWepSet()
93 {
94         if (Weapons_MAX > 48)
95         return ReadInt72_t();
96         if (Weapons_MAX > 24)
97         return ReadInt48_t();
98         return ReadInt24_t() * '1 0 0';
99 }
100 #endif
101
102 string W_FixWeaponOrder(string order, float complete)
103 {
104         return fixPriorityList(order, WEP_FIRST, WEP_LAST, WEP_IMPULSE_BEGIN - WEP_FIRST, complete);
105 }
106 string W_NameWeaponOrder_MapFunc(string s)
107 {
108         entity wi;
109         if(s == "0" || stof(s))
110         {
111                 wi = get_weaponinfo(stof(s));
112                 if(wi != WEP_Null)
113                         return wi.netname;
114         }
115         return s;
116 }
117
118 string W_UndeprecateName(string s)
119 {
120         switch ( s )
121         {
122                 case "nex"            : return "vortex";
123                 case "rocketlauncher" : return "devastator";
124                 case "laser"          : return "blaster";
125                 case "minstanex"      : return "vaporizer";
126                 case "grenadelauncher": return "mortar";
127                 case "uzi"            : return "machinegun";
128                 default               : return s;
129         }
130 }
131 string W_NameWeaponOrder(string order)
132 {
133         return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
134 }
135 string W_NumberWeaponOrder_MapFunc(string s)
136 {
137         int i;
138         if(s == "0" || stof(s))
139                 return s;
140         s = W_UndeprecateName(s);
141         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
142                 if(s == get_weaponinfo(i).netname)
143                         return ftos(i);
144         return s;
145 }
146 string W_NumberWeaponOrder(string order)
147 {
148         return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
149 }
150
151 float W_FixWeaponOrder_BuildImpulseList_buf[Weapons_MAX];
152 string W_FixWeaponOrder_BuildImpulseList_order;
153 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
154 {
155         float h;
156         h = W_FixWeaponOrder_BuildImpulseList_buf[i];
157         W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
158         W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
159 }
160 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
161 {
162         entity e1, e2;
163         float d;
164         e1 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[i]);
165         e2 = get_weaponinfo(W_FixWeaponOrder_BuildImpulseList_buf[j]);
166         d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
167         if(d != 0)
168                 return -d; // high impulse first!
169         return
170                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[i]), 0)
171                 -
172                 strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "), sprintf(" %d ", W_FixWeaponOrder_BuildImpulseList_buf[j]), 0)
173                 ; // low char index first!
174 }
175 string W_FixWeaponOrder_BuildImpulseList(string o)
176 {
177         int i;
178         W_FixWeaponOrder_BuildImpulseList_order = o;
179         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
180                 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
181         heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp, world);
182         o = "";
183         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
184                 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
185         W_FixWeaponOrder_BuildImpulseList_order = string_null;
186         return substring(o, 1, -1);
187 }
188
189 string W_FixWeaponOrder_AllowIncomplete(string order)
190 {
191         return W_FixWeaponOrder(order, 0);
192 }
193
194 string W_FixWeaponOrder_ForceComplete(string order)
195 {
196         if(order == "")
197                 order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
198         return W_FixWeaponOrder(order, 1);
199 }
200
201 void W_RandomWeapons(entity e, float n)
202 {
203         int i, j;
204         WepSet remaining;
205         WepSet result;
206         remaining = e.weapons;
207         result = '0 0 0';
208         for(i = 0; i < n; ++i)
209         {
210                 RandomSelection_Init();
211                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
212                         if(remaining & WepSet_FromWeapon(j))
213                                 RandomSelection_Add(world, j, string_null, 1, 1);
214                 result |= WepSet_FromWeapon(RandomSelection_chosen_float);
215                 remaining &= ~WepSet_FromWeapon(RandomSelection_chosen_float);
216         }
217         e.weapons = result;
218 }
219
220 string GetAmmoPicture(.int ammotype)
221 {
222         switch (ammotype)
223         {
224                 case ammo_shells:  return ITEM_Shells.m_icon;
225                 case ammo_nails:   return ITEM_Bullets.m_icon;
226                 case ammo_rockets: return ITEM_Rockets.m_icon;
227                 case ammo_cells:   return ITEM_Cells.m_icon;
228                 case ammo_plasma:  return ITEM_Plasma.m_icon;
229                 case ammo_fuel:    return ITEM_JetpackFuel.m_icon;
230                 default: return ""; // wtf, no ammo type?
231         }
232 }
233
234 #ifdef CSQC
235 .int GetAmmoFieldFromNum(int i)
236 {
237         switch(i)
238         {
239                 case 0: return ammo_shells;
240                 case 1: return ammo_nails;
241                 case 2: return ammo_rockets;
242                 case 3: return ammo_cells;
243                 case 4: return ammo_plasma;
244                 case 5: return ammo_fuel;
245                 default: return ammo_none;
246         }
247 }
248
249 int GetAmmoStat(.int ammotype)
250 {
251         switch(ammotype)
252         {
253                 case ammo_shells: return STAT_SHELLS;
254                 case ammo_nails: return STAT_NAILS;
255                 case ammo_rockets: return STAT_ROCKETS;
256                 case ammo_cells: return STAT_CELLS;
257                 case ammo_plasma: return STAT_PLASMA.m_id;
258                 case ammo_fuel: return STAT_FUEL.m_id;
259                 default: return -1;
260         }
261 }
262 #endif
263
264 string W_Sound(string w_snd)
265 {
266         string output = strcat("weapons/", w_snd);
267 #ifdef SVQC
268         MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
269         return weapon_sound_output;
270 #else
271         return output;
272 #endif
273 }
274
275 string W_Model(string w_mdl)
276 {
277         string output = strcat("models/weapons/", w_mdl);
278 #ifdef SVQC
279         MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
280         return weapon_model_output;
281 #else
282         return output;
283 #endif
284 }
285
286 #endif