]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qc
Further cleanup of defs.qh
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qc
1 #include "all.qh"
2 #ifndef WEAPONS_ALL_C
3 #define WEAPONS_ALL_C
4
5 #if defined(CSQC)
6         #include <client/defs.qh>
7         #include "../constants.qh"
8         #include "../stats.qh"
9         #include <lib/warpzone/anglestransform.qh>
10         #include <lib/warpzone/common.qh>
11         #include <lib/warpzone/client.qh>
12         #include "../util.qh"
13         #include <client/autocvars.qh>
14         #include "../deathtypes/all.qh"
15         #include <lib/csqcmodel/interpolate.qh>
16         #include "../physics/movetypes/movetypes.qh"
17         #include <client/main.qh>
18         #include <lib/csqcmodel/cl_model.qh>
19 #elif defined(MENUQC)
20 #elif defined(SVQC)
21         #include <common/items/_mod.qh>
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 <common/util.qh>
30     #include "../monsters/_mod.qh"
31     #include "config.qh"
32     #include <server/weapons/common.qh>
33     #include <server/weapons/csqcprojectile.qh>
34     #include <server/weapons/tracing.qh>
35     #include <server/items/spawning.qh>
36     #include <server/autocvars.qh>
37     #include <server/constants.qh>
38     #include <server/defs.qh>
39     #include "../notifications/all.qh"
40     #include "../deathtypes/all.qh"
41     #include <server/mutators/_mod.qh>
42     #include "../mapinfo.qh"
43     #include <server/command/_mod.qh>
44     #include <lib/csqcmodel/sv_model.qh>
45     #include <server/portals.qh>
46     #include <server/g_hook.qh>
47 #endif
48 #ifdef GAMEQC
49         #include "calculations.qc"
50 #endif
51 #ifdef SVQC
52         #include "config.qc"
53 #endif
54
55 #include "weapon/_mod.inc"
56
57
58 // WEAPON PLUGIN SYSTEM
59
60 WepSet _WepSet_FromWeapon(int a)
61 {
62         a -= WEP_FIRST;
63         if (REGISTRY_MAX(Weapons) > 24)
64                 if (a >= 24)
65                 {
66                         a -= 24;
67                         if (REGISTRY_MAX(Weapons) > 48)
68                                 if (a >= 24)
69                                 {
70                                         a -= 24;
71                                         return '0 0 1' * (2 ** a);
72                                 }
73                         return '0 1 0' * (2 ** a);
74                 }
75         return '1 0 0' * (2 ** a);
76 }
77 #ifdef SVQC
78         void WriteWepSet(float dst, WepSet w)
79         {
80                 if (REGISTRY_MAX(Weapons) > 48) WriteInt72_t(dst, w);
81                 else if (REGISTRY_MAX(Weapons) > 24) WriteInt48_t(dst, w);
82                 else WriteInt24_t(dst, w.x);
83         }
84 #endif
85 #ifdef CSQC
86         WepSet WepSet_GetFromStat()
87         {
88                 return STAT(WEAPONS);
89         }
90         WepSet WepSet_GetFromStat_InMap()
91         {
92                 return STAT(WEAPONSINMAP);
93         }
94         WepSet ReadWepSet()
95         {
96                 if (REGISTRY_MAX(Weapons) > 48) return ReadInt72_t();
97                 if (REGISTRY_MAX(Weapons) > 24) 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         int i = stof(s);
109         if (s == "0" || i)
110         {
111                 entity wi = REGISTRY_GET(Weapons, i);
112                 if (wi != WEP_Null) return wi.netname;
113         }
114         return s;
115 }
116
117 string W_UndeprecateName(string s)
118 {
119         switch (s)
120         {
121                 case "nex": return "vortex";
122                 case "rocketlauncher": return "devastator";
123                 case "laser": return "blaster";
124                 case "minstanex": return "vaporizer";
125                 case "grenadelauncher": return "mortar";
126                 case "uzi": return "machinegun";
127                 case "hmg": return "okhmg";
128                 case "rpc": return "okrpc";
129                 default: return s;
130         }
131 }
132 string W_NameWeaponOrder(string order)
133 {
134         return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
135 }
136 string W_NumberWeaponOrder_MapFunc(string s)
137 {
138         if (s == "0" || stof(s)) return s;
139         s = W_UndeprecateName(s);
140         FOREACH(Weapons, it != WEP_Null && it.netname == s, return ftos(i));
141         return s;
142 }
143 string W_NumberWeaponOrder(string order)
144 {
145         return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
146 }
147
148 float W_FixWeaponOrder_BuildImpulseList_buf[REGISTRY_MAX(Weapons)];
149 string W_FixWeaponOrder_BuildImpulseList_order;
150 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
151 {
152         float h;
153         h = W_FixWeaponOrder_BuildImpulseList_buf[i];
154         W_FixWeaponOrder_BuildImpulseList_buf[i] = W_FixWeaponOrder_BuildImpulseList_buf[j];
155         W_FixWeaponOrder_BuildImpulseList_buf[j] = h;
156 }
157 float W_FixWeaponOrder_BuildImpulseList_cmp(int i, int j, entity pass)
158 {
159         int si = W_FixWeaponOrder_BuildImpulseList_buf[i];
160         Weapon e1 = REGISTRY_GET(Weapons, si);
161         int sj = W_FixWeaponOrder_BuildImpulseList_buf[j];
162         Weapon e2 = REGISTRY_GET(Weapons, sj);
163         int d = (e1.impulse + 9) % 10 - (e2.impulse + 9) % 10;
164         if (d != 0) return -d;  // high impulse first!
165         return strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "),
166                 sprintf(" %d ", si), 0)
167                -
168                strstrofs(strcat(" ", W_FixWeaponOrder_BuildImpulseList_order, " "),
169                 sprintf(" %d ", sj), 0)
170         ;  // low char index first!
171 }
172 string W_FixWeaponOrder_BuildImpulseList(string o)
173 {
174         int i;
175         W_FixWeaponOrder_BuildImpulseList_order = o;
176         for (i = WEP_FIRST; i <= WEP_LAST; ++i)
177                 W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST] = i;
178         heapsort(WEP_LAST - WEP_FIRST + 1, W_FixWeaponOrder_BuildImpulseList_swap, W_FixWeaponOrder_BuildImpulseList_cmp,
179                 NULL);
180         o = "";
181         for (i = WEP_FIRST; i <= WEP_LAST; ++i)
182                 o = strcat(o, " ", ftos(W_FixWeaponOrder_BuildImpulseList_buf[i - WEP_FIRST]));
183         W_FixWeaponOrder_BuildImpulseList_order = string_null;
184         return substring(o, 1, -1);
185 }
186
187 string W_FixWeaponOrder_AllowIncomplete(entity this, string order)
188 {
189         return W_FixWeaponOrder(order, 0);
190 }
191
192 string W_FixWeaponOrder_ForceComplete(string order)
193 {
194         if (order == "") order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
195         return W_FixWeaponOrder(order, 1);
196 }
197
198 WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
199 {
200         WepSet result = '0 0 0';
201         for (int j = 0; j < n; ++j)
202         {
203                 RandomSelection_Init();
204                 FOREACH(Weapons, it != WEP_Null, {
205                         if (remaining & (it.m_wepset))
206                                 RandomSelection_AddEnt(it, 1, 1);
207                 });
208                 Weapon w = RandomSelection_chosen_ent;
209                 result |= WepSet_FromWeapon(w);
210                 remaining &= ~WepSet_FromWeapon(w);
211         }
212         return result;
213 }
214
215 string GetAmmoPicture(int ammotype)
216 {
217         switch (ammotype)
218         {
219                 case RES_SHELLS:  return ITEM_Shells.m_icon;
220                 case RES_BULLETS: return ITEM_Bullets.m_icon;
221                 case RES_ROCKETS: return ITEM_Rockets.m_icon;
222                 case RES_CELLS:   return ITEM_Cells.m_icon;
223                 case RES_PLASMA:  return ITEM_Plasma.m_icon;
224                 case RES_FUEL:    return ITEM_JetpackFuel.m_icon;
225                 default: return "";  // wtf, no ammo type?
226         }
227 }
228
229 string GetAmmoName(int ammotype)
230 {
231         switch (ammotype)
232         {
233                 case RES_SHELLS:  return ITEM_Shells.m_name;
234                 case RES_BULLETS: return ITEM_Bullets.m_name;
235                 case RES_ROCKETS: return ITEM_Rockets.m_name;
236                 case RES_CELLS:   return ITEM_Cells.m_name;
237                 case RES_PLASMA:  return ITEM_Plasma.m_name;
238                 case RES_FUEL:    return ITEM_JetpackFuel.m_name;
239                 default:          return "batteries";
240         }
241 }
242
243 #ifdef CSQC
244 int GetAmmoTypeFromNum(int i)
245 {
246         switch (i)
247         {
248                 case 0: return RES_SHELLS;
249                 case 1: return RES_BULLETS;
250                 case 2: return RES_ROCKETS;
251                 case 3: return RES_CELLS;
252                 case 4: return RES_PLASMA;
253                 case 5: return RES_FUEL;
254                 default: return RES_NONE;
255         }
256 }
257
258 int GetAmmoStat(int ammotype)
259 {
260         switch (ammotype)
261         {
262                 case RES_SHELLS: return STAT_SHELLS;
263                 case RES_BULLETS: return STAT_NAILS;
264                 case RES_ROCKETS: return STAT_ROCKETS;
265                 case RES_CELLS: return STAT_CELLS;
266                 case RES_PLASMA: return STAT_PLASMA.m_id;
267                 case RES_FUEL: return STAT_FUEL.m_id;
268                 default: return -1;
269         }
270 }
271 #endif
272
273 string W_Sound(string w_snd)
274 {
275         string output = strcat("weapons/", w_snd);
276         MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
277         return M_ARGV(1, string);
278 }
279
280 string W_Model(string w_mdl)
281 {
282         string output = strcat("models/weapons/", w_mdl);
283         MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
284         return M_ARGV(1, string);
285 }
286
287 #ifdef GAMEQC
288 vector shotorg_adjustfromclient(vector vecs, float y_is_right, float algn)
289 {
290         switch (algn)
291         {
292                 default:
293                 case 3:
294                         // right alignment
295                         break;
296                 case 4:
297                         // left
298                         vecs.y = -vecs.y;
299                         break;
300                 case 1:
301                 case 2:
302                         // center
303                         vecs.y = 0;
304                         vecs.z -= 2;
305                         break;
306         }
307         return vecs;
308 }
309
310 vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn)
311 {
312         string s;
313         if (visual)
314         {
315                 vecs = shotorg_adjustfromclient(vecs, y_is_right, algn);
316         }
317         else if (STAT(SHOOTFROMEYE))
318         {
319                 vecs.y = vecs.z = 0;
320         }
321         else if (STAT(SHOOTFROMCENTER))
322         {
323                 vecs.y = 0;
324                 vecs.z -= 2;
325         }
326         else if ((s = G_SHOOTFROMFIXEDORIGIN) != "")
327         {
328                 vector v = stov(s);
329                 if (y_is_right) v.y = -v.y;
330                 if (v.x != 0) vecs.x = v.x;
331                 vecs.y = v.y;
332                 vecs.z = v.z;
333         }
334         else  // just do the same as top
335         {
336                 vecs = shotorg_adjustfromclient(vecs, y_is_right, algn);
337         }
338
339         return vecs;
340 }
341
342 #define shotorg_adjust shotorg_adjust_values
343
344 /**
345  * supported formats:
346  *
347  * 1. simple animated model, muzzle flash handling on h_ model:
348  *    h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
349  *      tags:
350  *        shot = muzzle end (shot origin, also used for muzzle flashes)
351  *        shell = casings ejection point (must be on the right hand side of the gun)
352  *        weapon = attachment for v_tuba.md3
353  *    v_tuba.md3 - first and third person model
354  *    g_tuba.md3 - pickup model
355  *
356  * 2. simple animated model, muzzle flash handling on v_ model:
357  *    h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
358  *      tags:
359  *        weapon = attachment for v_tuba.md3
360  *    v_tuba.md3 - first and third person model
361  *      tags:
362  *        shot = muzzle end (shot origin, also used for muzzle flashes)
363  *        shell = casings ejection point (must be on the right hand side of the gun)
364  *    g_tuba.md3 - pickup model
365  *
366  * 3. fully animated model, muzzle flash handling on h_ model:
367  *    h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
368  *      tags:
369  *        shot = muzzle end (shot origin, also used for muzzle flashes)
370  *        shell = casings ejection point (must be on the right hand side of the gun)
371  *        handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
372  *    v_tuba.md3 - third person model
373  *    g_tuba.md3 - pickup model
374  *
375  * 4. fully animated model, muzzle flash handling on v_ model:
376  *    h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
377  *      tags:
378  *        shot = muzzle end (shot origin)
379  *        shell = casings ejection point (must be on the right hand side of the gun)
380  *    v_tuba.md3 - third person model
381  *      tags:
382  *        shot = muzzle end (for muzzle flashes)
383  *    g_tuba.md3 - pickup model
384  *
385  * writes:
386  *   this.origin, this.angles
387  *   this.weaponchild
388  *   this.movedir, this.view_ofs, this.movedir_aligned
389  *   attachment stuff
390  *   anim stuff
391  * to free:
392  *   call again with ""
393  *   remove the ent
394  */
395 void CL_WeaponEntity_SetModel(entity this, string name, bool _anim)
396 {
397         if (name == "")
398         {
399                 vector oldmin = this.mins, oldmax = this.maxs;
400                 setmodel(this, MDL_Null);
401                 setsize(this, oldmin, oldmax);
402                 if (this.weaponchild) delete(this.weaponchild);
403                 this.weaponchild = NULL;
404                 this.movedir = '0 0 0';
405                 this.spawnorigin = '0 0 0';
406                 this.oldorigin = '0 0 0';
407                 this.anim_fire1  = '0 1 0.01';
408                 this.anim_fire2  = '0 1 0.01';
409                 this.anim_idle   = '0 1 0.01';
410                 this.anim_reload = '0 1 0.01';
411         }
412         else
413         {
414                 // if there is a child entity, hide it until we're sure we use it
415                 if (this.weaponchild) this.weaponchild.model = "";
416                 _setmodel(this, W_Model(strcat("v_", name, ".md3")));
417                 int v_shot_idx;  // used later
418                 (v_shot_idx = gettagindex(this, "shot")) || (v_shot_idx = gettagindex(this, "tag_shot"));
419
420                 _setmodel(this, W_Model(strcat("h_", name, ".iqm")));
421                 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
422                 this.anim_fire1  = animfixfps(this, '0 1 0.01', '0 0 0');
423                 this.anim_fire2  = animfixfps(this, '1 1 0.01', '0 0 0');
424                 this.anim_idle   = animfixfps(this, '2 1 0.01', '0 0 0');
425                 this.anim_reload = animfixfps(this, '3 1 0.01', '0 0 0');
426
427                 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
428                 // if we don't, this is a "real" animated model
429                 string t;
430                 if ((t = "weapon", gettagindex(this, t)) || (t = "tag_weapon", gettagindex(this, t)))
431                 {
432                         if (!this.weaponchild)
433                         {
434                                 this.weaponchild = new(weaponchild);
435 #ifdef CSQC
436                                 this.weaponchild.drawmask = MASK_NORMAL;
437                                 this.weaponchild.renderflags |= RF_VIEWMODEL;
438 #endif
439                         }
440                         _setmodel(this.weaponchild, W_Model(strcat("v_", name, ".md3")));
441                         setsize(this.weaponchild, '0 0 0', '0 0 0');
442                         setattachment(this.weaponchild, this, t);
443                 }
444                 else
445                 {
446                         if (this.weaponchild) delete(this.weaponchild);
447                         this.weaponchild = NULL;
448                 }
449
450                 setsize(this, '0 0 0', '0 0 0');
451                 setorigin(this, '0 0 0');
452                 this.angles = '0 0 0';
453                 this.frame = 0;
454 #ifdef SVQC
455                 this.viewmodelforclient = NULL;
456 #else
457                 this.renderflags &= ~RF_VIEWMODEL;
458 #endif
459                 if (v_shot_idx)  // v_ model attached to invisible h_ model
460                 {
461                         this.movedir = gettaginfo(this.weaponchild, v_shot_idx);
462                 }
463                 else
464                 {
465                         int idx;
466                         if ((idx = gettagindex(this, "shot")) || (idx = gettagindex(this, "tag_shot")))
467                         {
468                                 this.movedir = gettaginfo(this, idx);
469                         }
470                         else
471                         {
472                                 LOG_WARNF("weapon model %s does not support the 'shot' tag, will display shots TOTALLY wrong",
473                                         this.model);
474                                 this.movedir = '0 0 0';
475                         }
476                 }
477                 {
478                         int idx = 0;
479                         // v_ model attached to invisible h_ model
480                         if (this.weaponchild
481                             && ((idx = gettagindex(this.weaponchild, "shell")) || (idx = gettagindex(this.weaponchild, "tag_shell"))))
482                         {
483                                 this.spawnorigin = gettaginfo(this.weaponchild, idx);
484                         }
485                         else if ((idx = gettagindex(this, "shell")) || (idx = gettagindex(this, "tag_shell")))
486                         {
487                                 this.spawnorigin = gettaginfo(this, idx);
488                         }
489                         else
490                         {
491                                 LOG_WARNF("weapon model %s does not support the 'shell' tag, will display casings wrong",
492                                         this.model);
493                                 this.spawnorigin = this.movedir;
494                         }
495                 }
496                 if (v_shot_idx)
497                 {
498                         this.oldorigin = '0 0 0';  // use regular attachment
499                 }
500                 else
501                 {
502                         int idx;
503                         if (this.weaponchild)
504                                 (idx = gettagindex(this, "weapon")) || (idx = gettagindex(this, "tag_weapon"));
505                         else
506                                 (idx = gettagindex(this, "handle")) || (idx = gettagindex(this, "tag_handle"));
507                         if (idx)
508                         {
509                                 this.oldorigin = this.movedir - gettaginfo(this, idx);
510                         }
511                         else
512                         {
513                                 LOG_WARNF(
514                                         "weapon model %s does not support the 'handle' tag "
515                                         "and neither does the v_ model support the 'shot' tag, "
516                                         "will display muzzle flashes TOTALLY wrong\n",
517                                         this.model);
518                                 this.oldorigin = '0 0 0';  // there is no way to recover from this
519                         }
520                 }
521
522 #ifdef SVQC
523                 this.viewmodelforclient = this.owner;
524 #else
525                 this.renderflags |= RF_VIEWMODEL;
526 #endif
527         }
528
529         this.view_ofs = '0 0 0';
530         this.movedir_aligned = this.movedir;
531
532         if (this.movedir.x >= 0)
533         {
534                 //int algn = STAT(GUNALIGN, this.owner);
535                 int algn = W_GunAlign(this, STAT(GUNALIGN, this.owner));
536         #ifdef SVQC
537                 this.m_gunalign = algn;
538         #endif
539                 vector v = this.movedir;
540                 this.movedir = shotorg_adjust(v, false, false, algn);
541                 this.movedir_aligned = shotorg_adjust(v, false, true, algn);
542                 this.view_ofs = shotorg_adjust(v, false, true, algn) - v;
543         }
544         int compressed_shotorg = compressShotOrigin(this.movedir);
545         // make them match perfectly
546 #ifdef SVQC
547     // null during init
548     if (this.owner) STAT(SHOTORG, this.owner) = compressed_shotorg;
549         this.movedir = decompressShotOrigin(compressed_shotorg);
550 #else
551         this.movedir = decompressShotOrigin(compressed_shotorg);
552 #endif
553
554         this.spawnorigin += this.view_ofs;  // offset the casings origin by the same amount
555
556         // check if an instant weapon switch occurred
557         setorigin(this, this.view_ofs);
558         if (!_anim) return;
559         // reset animstate now
560         this.wframe = WFRAME_IDLE;
561         setanim(this, this.anim_idle, true, false, true);
562 }
563 #endif
564
565 #ifdef GAMEQC
566
567 REGISTER_NET_TEMP(wframe)
568 #ifdef CSQC
569 NET_HANDLE(wframe, bool isNew)
570 {
571         int fr = ReadByte();
572         float t = ReadFloat();
573     int slot = ReadByte();
574         bool restartanim = ReadByte();
575         entity wepent = viewmodels[slot];
576         if(fr == WFRAME_IDLE)
577                 wepent.animstate_looping = false; // we don't need to enforce idle animation
578         else
579         {
580                 vector a = '0 0 0';
581                 switch(fr)
582                 {
583                         default:
584                         case WFRAME_IDLE: a = wepent.anim_idle; break;
585                         case WFRAME_FIRE1: a = wepent.anim_fire1; break;
586                         case WFRAME_FIRE2: a = wepent.anim_fire2; break;
587                         case WFRAME_RELOAD: a = wepent.anim_reload; break;
588                 }
589                 a.z *= t;
590                 anim_set(wepent, a, !restartanim, restartanim, restartanim);
591         }
592         wepent.state = ReadByte();
593         wepent.weapon_nextthink = ReadFloat();
594         switch (wepent.state)
595         {
596                 case WS_RAISE:
597                         wepent.weapon_switchdelay = wepent.activeweapon.switchdelay_raise;
598                         break;
599                 case WS_DROP:
600                         wepent.weapon_switchdelay = wepent.activeweapon.switchdelay_drop;
601                         break;
602         default:
603             wepent.weapon_switchdelay = 0;
604             break;
605         }
606         return true;
607 }
608 #endif
609
610 #ifdef SVQC
611 void wframe_send(entity actor, entity weaponentity, int wepframe, float attackrate, bool restartanim)
612 {
613         if (!IS_REAL_CLIENT(actor)) return;
614         int channel = MSG_ONE;
615         msg_entity = actor;
616         WriteHeader(channel, wframe);
617         WriteByte(channel, wepframe);
618         WriteFloat(channel, attackrate);
619         WriteByte(channel, weaponslot(weaponentity.weaponentity_fld));
620         WriteByte(channel, restartanim);
621         WriteByte(channel, weaponentity.state);
622         WriteFloat(channel, weaponentity.weapon_nextthink);
623 }
624 #endif
625
626 REGISTER_NET_C2S(w_whereis)
627 #ifdef SVQC
628 void Weapon_whereis(Weapon this, entity cl);
629 NET_HANDLE(w_whereis, bool)
630 {
631         Weapon wpn = ReadRegistered(Weapons);
632         if (wpn != WEP_Null) Weapon_whereis(wpn, sender);
633         return true;
634 }
635 #else
636 void w_whereis(Weapon this)
637 {
638         int channel = MSG_C2S;
639         WriteHeader(channel, w_whereis);
640         WriteRegistered(Weapons, channel, this);
641 }
642 CLIENT_COMMAND(weapon_find, "Show spawn locations of a weapon")
643 {
644         switch (request)
645         {
646                 case CMD_REQUEST_COMMAND:
647                 {
648                         string s = argv(1);
649                         if (s == "all")
650                         {
651                                 FOREACH(Weapons, it != WEP_Null, w_whereis(it));
652                                 return;
653                         }
654                         if (s == "unowned")
655                         {
656                                 FOREACH(Weapons, it != WEP_Null && !(STAT(WEAPONS) & it.m_wepset), w_whereis(it));
657                                 return;
658                         }
659                         FOREACH(Weapons, it != WEP_Null && it.netname == s,
660                         {
661                                 w_whereis(it);
662                                 return;
663                         });
664                 }
665                 default:
666                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
667                 case CMD_REQUEST_USAGE:
668                 {
669                         LOG_HELP("Usage:^3 cl_cmd weapon_find weapon");
670                         LOG_HELP("  Where 'weapon' is the lowercase weapon name, 'all' or 'unowned'.");
671                         return;
672                 }
673         }
674 }
675 #endif
676
677 #ifdef SVQC
678 void W_MuzzleFlash_Model_AttachToShotorg(entity actor, .entity weaponentity, entity flash, vector offset)
679 {
680         flash.owner = actor;
681         flash.angles_z = random() * 360;
682
683         entity view = actor.(weaponentity);
684         entity exterior = actor.exteriorweaponentity;
685
686         if (view.oldorigin.x > 0)
687         {
688                 setattachment(flash, exterior, "");
689                 setorigin(flash, view.oldorigin + offset);
690         }
691         else
692         {
693                 if (gettagindex(exterior, "shot")) setattachment(flash, exterior, "shot");
694                 else setattachment(flash, exterior, "tag_shot");
695                 setorigin(flash, offset);
696         }
697 }
698 #elif defined(CSQC)
699 void W_MuzzleFlash_Model_AttachToShotorg(entity wepent, entity flash, vector offset)
700 {
701         flash.owner = wepent;
702         flash.angles_z = random() * 360;
703
704         if (gettagindex(wepent, "shot")) setattachment(flash, wepent, "shot");
705         else setattachment(flash, wepent, "tag_shot");
706         setorigin(flash, offset);
707 }
708 #endif
709
710 void W_MuzzleFlash_Model_Think(entity this)
711 {
712         this.frame += 2;
713         this.scale *= 0.5;
714         this.alpha -= 0.25;
715         this.nextthink = time + 0.05;
716
717         if(this.alpha <= 0)
718         {
719                 setthink(this, SUB_Remove);
720                 this.nextthink = time;
721                 this.realowner.muzzle_flash = NULL;
722                 return;
723         }
724 }
725
726 void W_MuzzleFlash_Model(entity wepent, entity muzzlemodel)
727 {
728         if(wepent.muzzle_flash == NULL)
729                 wepent.muzzle_flash = spawn();
730
731         entity flash = wepent.muzzle_flash;
732         setmodel(flash, muzzlemodel); // precision set below
733
734         flash.scale = 0.75;
735         setthink(flash, W_MuzzleFlash_Model_Think);
736         flash.nextthink = time + 0.02;
737         flash.frame = 2;
738         flash.alpha = 0.75;
739         flash.angles_z = random() * 180;
740         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
741         flash.owner = flash.realowner = wepent;
742
743 #ifdef CSQC
744         flash.drawmask = MASK_NORMAL;
745 #endif
746 }
747
748 REGISTER_NET_TEMP(w_muzzleflash)
749
750 #ifdef SVQC
751 void W_MuzzleFlash(Weapon thiswep, entity actor, .entity weaponentity, vector shotorg, vector shotdir)
752 {
753         // don't show an exterior muzzle effect for the off-hand
754         if(weaponslot(weaponentity) == 0)
755         {
756                 Send_Effect_Except(thiswep.m_muzzleeffect, shotorg, shotdir * 1000, 1, actor);
757
758                 if(thiswep.m_muzzlemodel != MDL_Null)
759                 {
760                         W_MuzzleFlash_Model(actor.exteriorweaponentity, thiswep.m_muzzlemodel);
761                         W_MuzzleFlash_Model_AttachToShotorg(actor, weaponentity, actor.exteriorweaponentity.muzzle_flash, '5 0 0');
762                 }
763         }
764
765         FOREACH_CLIENT(it == actor || (IS_SPEC(it) && it.enemy == actor),
766         {
767                 if(!IS_REAL_CLIENT(it))
768                         continue;
769                 int channel = MSG_ONE;
770                 msg_entity = it;
771                 WriteHeader(channel, w_muzzleflash);
772                 WriteByte(channel, thiswep.m_id);
773                 WriteByte(channel, weaponslot(weaponentity));
774                 WriteVector(channel, shotorg);
775         });
776 }
777 #elif defined(CSQC)
778 NET_HANDLE(w_muzzleflash, bool isNew)
779 {
780         return = true;
781         int weapon_id = ReadByte();
782     int slot = ReadByte();
783     vector sv_shotorg = ReadVector();
784
785         Weapon thiswep = REGISTRY_GET(Weapons, weapon_id);
786     vector viewangles = getpropertyvec(VF_CL_VIEWANGLES);
787         vector forward, right, up;
788         MAKE_VECTORS(viewangles, forward, right, up);
789
790         if(autocvar_chase_active)
791         {
792                 // in third person mode, show the muzzle flash from the server side weapon position
793                 // we don't have a view model to reference in this case
794                 pointparticles(thiswep.m_muzzleeffect, sv_shotorg, forward * 1000, 1);
795                 return;
796         }
797     if(!autocvar_r_drawviewmodel) return;
798
799         entity wepent = viewmodels[slot];
800         // get the local player entity to calculate shot origin
801         entity rlplayer = CSQCModel_server2csqc(player_localentnum - 1);
802         if(!rlplayer)
803                 rlplayer = csqcplayer; // fall back to the global
804
805         vector md = wepent.movedir_aligned;
806         vector vecs = ((md.x > 0) ? md : '0 0 0');
807         vector dv = forward * vecs.x + right * -vecs.y + up * vecs.z;
808         vector org = rlplayer.origin + rlplayer.view_ofs + dv;
809
810         pointparticles(thiswep.m_muzzleeffect, org, forward * 1000, 1);
811
812         if(thiswep.m_muzzlemodel != MDL_Null)
813         {
814                 W_MuzzleFlash_Model(wepent, thiswep.m_muzzlemodel);
815                 W_MuzzleFlash_Model_AttachToShotorg(wepent, wepent.muzzle_flash, '5 0 0');
816         }
817 }
818 #endif
819
820
821 #endif
822
823 #endif