]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/cl_weaponsystem.qc
hopefully switch weapon switching reallyt
[divverent/nexuiz.git] / data / qcsrc / server / cl_weaponsystem.qc
1 /*
2 ===========================================================================
3
4   CLIENT WEAPONSYSTEM CODE
5   Bring back W_Weaponframe
6
7 ===========================================================================
8 */
9
10 void W_SwitchWeapon_Force(entity e, float w)
11 {
12         e.cnt = e.switchweapon;
13         e.switchweapon = w;
14 }
15
16 .float antilag_debug;
17
18 // VorteX: static frame globals
19 float WFRAME_FIRE1 = 0;
20 float WFRAME_FIRE2 = 1;
21 float WFRAME_IDLE = 2;
22
23 void(float fr, float t, void() func) weapon_thinkf;
24
25 vector w_shotorg;
26 vector w_shotdir;
27
28 // this function calculates w_shotorg and w_shotdir based on the weapon model
29 // offset, trueaim and antilag, and won't put w_shotorg inside a wall.
30 // make sure you call makevectors first (FIXME?)
31 void W_SetupShot(entity ent, vector vecs, float antilag, float recoil, string snd)
32 {
33         float nudge = 1; // added to traceline target and subtracted from result
34         local vector trueaimpoint;
35         local float oldsolid;
36         oldsolid = self.dphitcontentsmask;
37         self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
38         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NOMONSTERS, self);
39         trueaimpoint = trace_endpos;
40
41         if (cvar("g_shootfromeye"))
42                 w_shotorg = ent.origin + ent.view_ofs;
43         else if (cvar("g_shootfromcenter"))
44                 w_shotorg = ent.origin + ent.view_ofs + '0 0 1' * vecs_z;
45         else
46                 w_shotorg = ent.origin + ent.view_ofs + v_right * vecs_y + v_up * vecs_z;
47         // now move the shotorg forward as much as requested if possible
48         traceline(w_shotorg, w_shotorg + v_forward * (vecs_x + nudge), MOVE_NORMAL, self);
49         w_shotorg = trace_endpos - v_forward * nudge;
50         // calculate the shotdir from the chosen shotorg
51         w_shotdir = normalize(trueaimpoint - w_shotorg);
52
53 #if 0
54         // explanation of g_antilag:
55         // if client reports it was aiming at a player, and the serverside trace
56         // says it would miss, change the aim point to the player's new origin,
57         // but only if the shot at the player's new origin would hit of course
58         //
59         // FIXME: a much better method for bullet weapons would be to leave a
60         // trail of lagged 'ghosts' behind players, and see if the bullet hits the
61         // ghost corresponding to this player's ping time, and if so it would do
62         // damage to the real player
63         if (antilag)
64         if (self.cursor_trace_ent)                 // client was aiming at someone
65         if (self.cursor_trace_ent != self)         // just to make sure
66         if (self.cursor_trace_ent.takedamage)      // and that person is killable
67         if (self.cursor_trace_ent.classname == "player") // and actually a player
68         if (cvar("g_antilag") == 1)
69         {
70                 // verify that the shot would miss without antilag
71                 // (avoids an issue where guns would always shoot at their origin)
72                 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
73                 if (!trace_ent.takedamage)
74                 {
75                         // verify that the shot would hit if altered
76                         traceline(w_shotorg, self.cursor_trace_ent.origin, MOVE_NORMAL, self);
77                         if (trace_ent == self.cursor_trace_ent)
78                         {
79                                 // verify that the shot would hit in the past
80                                 if(self.antilag_debug)
81                                         antilag_takeback(self.cursor_trace_ent, time - self.antilag_debug);
82                                 else
83                                         antilag_takeback(self.cursor_trace_ent, time - ANTILAG_LATENCY(self));
84
85                                 traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
86                                 antilag_restore(self.cursor_trace_ent);
87
88                                 if(trace_ent == self.cursor_trace_ent)
89                                 {
90                                         // HIT!
91                                         w_shotdir = normalize(self.cursor_trace_ent.origin - w_shotorg);
92                                         dprint("ANTILAG HIT for ", self.netname, "\n");
93                                 }
94                                 else
95                                 {
96                                         // prydon cursor aimbot or odd network conditions
97                                         dprint("WARNING: antilag ghost trace for ", self.netname, " failed!\n");
98                                 }
99
100                                 if(cvar("developer") >= 2)
101                                 {
102                                         vector v, vplus, vel;
103                                         float X;
104                                         v     = antilag_takebackorigin(self.cursor_trace_ent, time - (ANTILAG_LATENCY(self)       ));
105                                         vplus = antilag_takebackorigin(self.cursor_trace_ent, time - (ANTILAG_LATENCY(self) + 0.01));
106                                         vel = (vplus - v) * (1 / 0.01);
107                                         // solve: v + X * vel = closest to self.origin + self.view_ofs, v_forward axis
108                                         v     -= (self.origin + self.view_ofs);
109                                         // solve: v + X * vel = closest to v_forward axis
110                                         // project into 2D by subtracting v_forward components:
111                                         v   -= (v   * v_forward) * v_forward;
112                                         vel -= (vel * v_forward) * v_forward;
113                                         // solve: v + X * vel = closest to origin
114                                         // (v + X * vel)^2 closest to 0
115                                         // v^2 + 2 * X * (v * vel) + X^2 * vel^2 closest to 0
116                                         X = -(v * vel) / (vel * vel);
117                                         dprint("dead center needs adjustment of ", ftos(X), " (that is, ", ftos(ANTILAG_LATENCY(self) + X), " instead of ", ftos(ANTILAG_LATENCY(self)), "\n");
118                                 }
119                         }
120                 }
121         }
122 #else
123         if (antilag)
124         {
125                 if (cvar("g_antilag") == 1) // switch to "ghost" if not hitting original
126                 {
127                         traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
128                         if (!trace_ent.takedamage)
129                         {
130                                 traceline_antilag_force (self, w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self, ANTILAG_LATENCY(self));
131                                 if (trace_ent.takedamage && trace_ent.classname == "player")
132                                 {
133                                         entity e;
134                                         e = trace_ent;
135                                         traceline(w_shotorg, e.origin, MOVE_NORMAL, self);
136                                         if(trace_ent == e)
137                                                 w_shotdir = normalize(trace_ent.origin - w_shotorg);
138                                 }
139                         }
140                 }
141                 else if(cvar("g_antilag") == 3) // client side hitscan
142                 {
143                         if (self.cursor_trace_ent)                 // client was aiming at someone
144                         if (self.cursor_trace_ent != self)         // just to make sure
145                         if (self.cursor_trace_ent.takedamage)      // and that person is killable
146                         if (self.cursor_trace_ent.classname == "player") // and actually a player
147                         {
148                                 // verify that the shot would miss without antilag
149                                 // (avoids an issue where guns would always shoot at their origin)
150                                 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, self);
151                                 if (!trace_ent.takedamage)
152                                 {
153                                         // verify that the shot would hit if altered
154                                         traceline(w_shotorg, self.cursor_trace_ent.origin, MOVE_NORMAL, self);
155                                         if (trace_ent == self.cursor_trace_ent)
156                                                 w_shotdir = normalize(self.cursor_trace_ent.origin - w_shotorg);
157                                         else
158                                                 print("antilag fail\n");
159                                 }
160                         }
161                 }
162         }
163 #endif
164
165         self.dphitcontentsmask = oldsolid; // restore solid type (generally SOLID_SLIDEBOX)
166
167         if (!g_norecoil)
168                 self.punchangle_x = recoil * -1;
169
170         if (snd != "")
171         {
172                 sound (self, CHAN_WEAPON, snd, VOL_BASE, ATTN_NORM);
173         }
174
175         if (self.items & IT_STRENGTH)
176         if (!g_minstagib)
177                 sound (self, CHAN_AUTO, "weapons/strength_fire.wav", VOL_BASE, ATTN_NORM);
178 };
179
180 void LaserTarget_Think()
181 {
182         entity e;
183         vector offset;
184         float uselaser;
185         uselaser = 0;
186
187         // list of weapons that will use the laser, and the options that enable it
188         if(self.owner.laser_on && self.owner.weapon == WEP_ROCKET_LAUNCHER && g_laserguided_missile)
189                 uselaser = 1;
190         // example
191         //if(self.owner.weapon == WEP_ELECTRO && cvar("g_laserguided_electro"))
192         //      uselaser = 1;
193
194
195
196         // if a laser-enabled weapon isn't selected, delete any existing laser and quit
197         if(!uselaser)
198         {
199                 // rocket launcher isn't selected, so no laser target.
200                 if(self.lasertarget != world)
201                 {
202                         remove(self.lasertarget);
203                         self.lasertarget = world;
204                 }
205                 return;
206         }
207
208         if(!self.lasertarget)
209         {
210                 // we don't have a lasertarget entity, so spawn one
211                 //bprint("create laser target\n");
212                 e = self.lasertarget = spawn();
213                 e.owner = self.owner;                   // Its owner is my owner
214                 e.classname = "laser_target";
215                 e.movetype = MOVETYPE_NOCLIP;   // don't touch things
216                 setmodel(e, "models/laser_dot.mdl");    // what it looks like, precision set below
217                 e.scale = 1.25;                         // make it larger
218                 e.alpha = 0.25;                         // transparency
219                 e.colormod = '255 0 0' * (1/255) * 8;   // change colors
220                 e.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
221                 // make it dynamically glow
222                 // you should avoid over-using this, as it can slow down the player's computer.
223                 e.glow_color = 251; // red color
224                 e.glow_size = 12;
225         }
226         else
227                 e = self.lasertarget;
228
229         // move the laser dot to where the player is looking
230
231         makevectors(self.owner.v_angle); // set v_forward etc to the direction the player is looking
232         offset = '0 0 26' + v_right*3;
233         traceline(self.owner.origin + offset, self.owner.origin + offset + v_forward * MAX_SHOT_DISTANCE, FALSE, self); // trace forward until you hit something, like a player or wall
234         setorigin(e, trace_endpos + v_forward*8); // move me to where the traceline ended
235         if(trace_plane_normal != '0 0 0')
236                 e.angles = vectoangles(trace_plane_normal);
237         else
238                 e.angles = vectoangles(v_forward);
239 }
240
241 float CL_Weaponentity_CustomizeEntityForClient()
242 {
243         self.viewmodelforclient = self.owner;
244         if(other.classname == "spectator")
245                 if(other.enemy == self.owner)
246                         self.viewmodelforclient = other;
247         return TRUE;
248 }
249
250 .string weaponname;
251 void CL_Weaponentity_Think()
252 {
253         self.nextthink = time;
254         if (intermission_running)
255                 self.frame = WFRAME_IDLE;
256         if (self.owner.weaponentity != self)
257         {
258                 remove(self);
259                 return;
260         }
261         if (self.owner.deadflag != DEAD_NO)
262         {
263                 self.model = "";
264                 return;
265         }
266         if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
267         {
268                 self.cnt = self.owner.weapon;
269                 self.dmg = self.owner.modelindex;
270                 self.deadflag = self.owner.deadflag;
271                 if (self.owner.weaponname != "")
272                         setmodel(self, strcat("models/weapons/w_", self.owner.weaponname, ".zym")); // precision set below
273                 else
274                         self.model = "";
275         }
276         self.effects = self.owner.effects | EF_LOWPRECISION;
277         self.effects = self.effects - (self.effects & (EF_FULLBRIGHT)); // can mask team color, so get rid of it
278
279         if (self.flags & FL_FLY)
280                 // owner is currently being teleported, so don't apply EF_NODRAW otherwise the viewmodel would "blink"
281                 self.effects = self.effects - (self.effects & EF_NODRAW);
282
283         if(self.owner.alpha >= 0)
284                 self.alpha = self.owner.alpha;
285         else
286                 self.alpha = 1;
287         self.colormap = self.owner.colormap;
288
289         self.angles = '0 0 0';
290         local float f;
291         f = 0;
292         if (self.state == WS_RAISE)
293                 f = (self.owner.weapon_nextthink - time) / cvar("g_balance_weaponswitchdelay");
294         else if (self.state == WS_DROP)
295                 f = 1 - (self.owner.weapon_nextthink - time) / cvar("g_balance_weaponswitchdelay");
296         else if (self.state == WS_CLEAR)
297                 f = 1;
298         self.angles_x = -90 * f * f;
299
300         // create or update the lasertarget entity
301         LaserTarget_Think();
302 };
303
304 void CL_ExteriorWeaponentity_Think()
305 {
306         float tag_found;
307         self.nextthink = time;
308         if (self.owner.exteriorweaponentity != self)
309         {
310                 remove(self);
311                 return;
312         }
313         if (self.owner.deadflag != DEAD_NO)
314         {
315                 self.model = "";
316                 return;
317         }
318         if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
319         {
320                 self.cnt = self.owner.weapon;
321                 self.dmg = self.owner.modelindex;
322                 self.deadflag = self.owner.deadflag;
323                 if (self.owner.weaponname != "")
324                         setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
325                 else
326                         self.model = "";
327
328                 if((tag_found = gettagindex(self.owner, "tag_weapon")))
329                 {
330                         self.tag_index = tag_found;
331                         self.tag_entity = self.owner;
332                 }
333                 else
334                         setattachment(self, self.owner, "bip01 r hand");
335
336                 // if that didn't find a tag, hide the exterior weapon model
337                 if (!self.tag_index)
338                         self.model = "";
339         }
340         self.effects = self.owner.effects | EF_LOWPRECISION;
341         self.effects = self.effects - (self.effects & (EF_BLUE | EF_RED)); // eat performance
342         if(self.owner.alpha >= 0)
343                 self.alpha = self.owner.alpha;
344         else
345                 self.alpha = 1;
346         self.colormap = self.owner.colormap;
347 };
348
349 // spawning weaponentity for client
350 void CL_SpawnWeaponentity()
351 {
352         self.weaponentity = spawn();
353         self.weaponentity.solid = SOLID_NOT;
354         self.weaponentity.owner = self;
355         self.weaponentity.weaponentity = self.weaponentity;
356         setmodel(self.weaponentity, ""); // precision set when changed
357         self.weaponentity.origin = '0 0 0';
358         self.weaponentity.angles = '0 0 0';
359         self.weaponentity.viewmodelforclient = self;
360         self.weaponentity.flags = 0;
361         self.weaponentity.think = CL_Weaponentity_Think;
362         self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
363         self.weaponentity.nextthink = time;
364         self.weaponentity.scale = 0.61;
365
366         self.exteriorweaponentity = spawn();
367         self.exteriorweaponentity.solid = SOLID_NOT;
368         self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
369         self.exteriorweaponentity.owner = self;
370         self.exteriorweaponentity.origin = '0 0 0';
371         self.exteriorweaponentity.angles = '0 0 0';
372         self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
373         self.exteriorweaponentity.nextthink = time;
374 };
375
376 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
377 {
378         local float weaponbit, f;
379         local entity oldself;
380
381         if (wpn < WEP_FIRST || wpn > WEP_LAST)
382         {
383                 if (complain)
384                         sprint(self, "Invalid weapon\n");
385                 return FALSE;
386         }
387         weaponbit = W_WeaponBit(wpn);
388         if (cl.weapons & weaponbit)
389         {
390                 if (andammo)
391                 {
392                         if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
393                         {
394                                 f = 1;
395                         }
396                         else
397                         {
398                                 oldself = self;
399                                 self = cl;
400                                 f = weapon_action(wpn, WR_CHECKAMMO1);
401                                 f = f + weapon_action(wpn, WR_CHECKAMMO2);
402                                 self = oldself;
403                         }
404                         if (!f)
405                         {
406                                 if (complain)
407                                         sprint(cl, strcat("You don't have any ammo for the ^2", W_Name(wpn), "\n"));
408                                 return FALSE;
409                         }
410                 }
411                 return TRUE;
412         }
413         if (complain)
414         {
415                 // DRESK - 3/16/07
416                 // Report Proper Weapon Status / Modified Weapon Ownership Message
417                 if(weaponsInMap & weaponbit)
418                         sprint(cl, strcat("You do not have the ^2", W_Name(wpn), "\n") );
419                 else
420                         sprint(cl, strcat("The ^2", W_Name(wpn), "^7 is ^1NOT AVAILABLE^7 in this map\n") );
421         }
422         return FALSE;
423 };
424
425 // Weapon subs
426 void w_clear()
427 {
428         if (self.weapon != -1)
429                 self.weapon = 0;
430         if (self.weaponentity)
431         {
432                 self.weaponentity.state = WS_CLEAR;
433                 // self.weaponname = ""; // next frame will setmodel it to "" when needed anyway
434                 self.weaponentity.effects = 0;
435         }
436 };
437
438 void w_ready()
439 {
440         if (self.weaponentity)
441                 self.weaponentity.state = WS_READY;
442         weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
443 };
444
445 // Setup weapon for client (after this raise frame will be launched)
446 void weapon_setup(float windex)
447 {
448         entity e;
449         e = get_weaponinfo(windex);
450         self.items = self.items - (self.items & IT_AMMO);
451         self.items = self.items | e.items;
452
453         // the two weapon entities will notice this has changed and update their models
454         self.weapon = windex;
455         self.weaponname = e.mdl;
456         self.bulletcounter = 0;
457 };
458
459 // perform weapon to attack (weaponstate and attack_finished check is here)
460 .float race_penalty;
461 float weapon_prepareattack(float secondary, float attacktime)
462 {
463         //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
464         //if all players readied up and the countdown is running
465         if (cvar("sv_ready_restart_after_countdown"))
466                 if(time < game_starttime || time < self.race_penalty) {
467                         return FALSE;
468                 }
469         
470         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
471         if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
472         {
473                 W_SwitchWeapon_Force(self, w_getbestweapon(self));
474                 return FALSE;
475         }
476
477         if (timeoutStatus == 2) //don't allow the player to shoot while game is paused
478                 return FALSE;
479
480         // do not even think about shooting if switching
481         if(self.switchweapon != self.weapon)
482                 return FALSE;
483
484         // don't fire if previous attack is not finished
485         if (ATTACK_FINISHED(self) > time + frametime * 0.5)
486                 return FALSE;
487         // don't fire while changing weapon
488         if (self.weaponentity.state != WS_READY)
489                 return FALSE;
490         self.weaponentity.state = WS_INUSE;
491         // if the weapon hasn't been firing continuously, reset the timer
492         if (ATTACK_FINISHED(self) < time - frametime * 1.5)
493         {
494                 ATTACK_FINISHED(self) = time;
495                 //dprint("resetting attack finished to ", ftos(time), "\n");
496         }
497         ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime;
498         self.bulletcounter += 1;
499         //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
500         return TRUE;
501 };
502
503 void weapon_thinkf(float fr, float t, void() func)
504 {
505         if (fr >= 0)
506         {
507                 if (self.weaponentity != world)
508                         self.weaponentity.frame = fr;
509         }
510
511         if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
512         {
513                 backtrace("Tried to override initial weapon think function - should this really happen?");
514         }
515
516         if(g_runematch)
517         {
518                 if(self.runes & RUNE_SPEED)
519                 {
520                         if(self.runes & CURSE_SLOW)
521                                 t = t * cvar("g_balance_rune_speed_combo_atkrate");
522                         else
523                                 t = t * cvar("g_balance_rune_speed_atkrate");
524                 }
525                 else if(self.runes & CURSE_SLOW)
526                 {
527                         t = t * cvar("g_balance_curse_slow_atkrate");
528                 }
529         }
530
531         // VorteX: haste can be added here
532         if (self.weapon_think == w_ready)
533         {
534                 self.weapon_nextthink = time;
535                 //dprint("started firing at ", ftos(time), "\n");
536         }
537         if (self.weapon_nextthink < time - frametime * 1.5 || self.weapon_nextthink > time + frametime * 1.5)
538         {
539                 self.weapon_nextthink = time;
540                 //dprint("reset weapon animation timer at ", ftos(time), "\n");
541         }
542         self.weapon_nextthink = self.weapon_nextthink + t;
543         self.weapon_think = func;
544         //dprint("next ", ftos(self.weapon_nextthink), "\n");
545
546         if (fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2)
547         if (t)
548         if (!self.crouch) // shoot anim stands up, this looks bad
549         {
550                 local vector anim;
551                 anim = self.anim_shoot;
552                 anim_z = anim_y / t;
553                 player_setanim(anim, FALSE, TRUE, TRUE);
554         }
555 };
556
557 void weapon_boblayer1(float spd, vector org)
558 {
559         // VorteX: haste can be added here
560 };
561
562 vector W_CalculateProjectileVelocity(vector pvelocity, vector mvelocity)
563 {
564         vector mdirection;
565         float mspeed;
566         float outspeed;
567         float nstyle;
568         vector outvelocity;
569
570         mdirection = normalize(mvelocity);
571         mspeed = vlen(mvelocity);
572
573         nstyle = cvar("g_projectiles_newton_style");
574         if(nstyle == 0)
575         {
576                 // absolute velocity
577                 outvelocity = mvelocity;
578         }
579         else if(nstyle == 1)
580         {
581                 // true Newtonian projectiles
582                 outvelocity = pvelocity + mvelocity;
583         }
584         else if(nstyle == 2)
585         {
586                 // true Newtonian projectiles with automatic aim adjustment
587                 //
588                 // solve: |outspeed * mdirection - pvelocity| = mspeed
589                 // outspeed^2 - 2 * outspeed * (mdirection * pvelocity) + pvelocity^2 - mspeed^2 = 0
590                 // outspeed = (mdirection * pvelocity) +- sqrt((mdirection * pvelocity)^2 - pvelocity^2 + mspeed^2)
591                 // PLUS SIGN!
592                 // not defined?
593                 // then...
594                 // pvelocity^2 - (mdirection * pvelocity)^2 > mspeed^2
595                 // velocity without mdirection component > mspeed
596                 // fire at smallest possible mspeed that works?
597                 // |(mdirection * pvelocity) * pvelocity - pvelocity| = mspeed
598
599                 float D;
600                 float p;
601                 float q;
602                 p = mdirection * pvelocity;
603                 q = pvelocity * pvelocity - mspeed * mspeed;
604                 D = p * p - q;
605                 if(D < 0)
606                 {
607                         //dprint("impossible shot, adjusting\n");
608                         D = 0;
609                 }
610                 outspeed = p + sqrt(D);
611                 outspeed = bound(mspeed * 0.7, outspeed, mspeed * 5.0);
612                 outvelocity = mdirection * outspeed;
613         }
614         else if(nstyle == 3)
615         {
616                 // pseudo-Newtonian:
617                 outspeed = mspeed + mdirection * pvelocity;
618                 outspeed = bound(mspeed * 0.7, outspeed, mspeed * 5.0);
619                 outvelocity = mdirection * outspeed;
620         }
621         else if(nstyle == 4)
622         {
623                 // tZorkian:
624                 outspeed = mspeed + vlen(pvelocity);
625                 outvelocity = mdirection * outspeed;
626         }
627         else
628                 error("g_projectiles_newton_style must be 0 (absolute), 1 (Newtonian), 2 (Newtonian + aimfix), 3 (pseudo Newtonian) or 4 (tZorkian)!");
629
630         return outvelocity;
631 }
632
633 void W_SetupProjectileVelocity(entity missile)
634 {
635         if(missile.owner == world)
636                 error("Unowned missile");
637
638         missile.velocity = W_CalculateProjectileVelocity(missile.owner.velocity, missile.velocity);
639 }
640
641
642 // WEAPON PLUGIN SYSTEM
643 entity weapon_info[24];
644 entity dummy_weapon_info;
645 .float(float) weapon_func;
646 string weaponpriority_hudselector_0;
647 string weaponpriority_hudselector_1;
648
649 void register_weapon(float id, float(float) func, float ammotype, float i, float normalweapon, float pickupbasevalue, string modelname, string shortname, string name)
650 {
651         entity e;
652         weapon_info[id - 1] = e = spawn();
653         e.classname = "weapon_info";
654         e.weapon = id;
655         e.weapons = power2of(id - 1);
656         e.netname = shortname;
657         e.message = name;
658         e.items = ammotype;
659         e.weapon_func = func;
660         e.mdl = modelname;
661         e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
662         e.spawnflags = normalweapon;
663         e.impulse = i;
664         e.bot_pickupbasevalue = pickupbasevalue;
665 }
666 float w_null(float dummy)
667 {
668         return 0;
669 }
670 void register_weapons_done()
671 {
672         entity wi;
673
674         dummy_weapon_info = spawn();
675         dummy_weapon_info.classname = "weapon_info";
676         dummy_weapon_info.weapon = 0;
677         dummy_weapon_info.weapons = 0;
678         dummy_weapon_info.netname = "@!#%'n Tuba";
679         dummy_weapon_info.items = 0;
680         dummy_weapon_info.weapon_func = w_null;
681         dummy_weapon_info.mdl = "";
682         dummy_weapon_info.model = "";
683         dummy_weapon_info.spawnflags = 0;
684         dummy_weapon_info.impulse = -1;
685         dummy_weapon_info.bot_pickupbasevalue = 0;
686
687         float i;
688         weaponpriority_hudselector_0 = "";
689         for(i = 24; i >= 1; --i)
690                 if(weapon_info[i-1])
691                         weaponpriority_hudselector_0 = strcat(weaponpriority_hudselector_0, " ", ftos(i));
692
693         float imp;
694         weaponpriority_hudselector_1 = "";
695         for(i = 1; i <= 24; ++i)
696         {
697                 wi = weapon_info[i-1];
698                 if(wi && wi.impulse == 0)
699                         weaponpriority_hudselector_1 = strcat(weaponpriority_hudselector_1, " ", ftos(i));
700         }
701         for(imp = 9; imp > 0; --imp)
702                 for(i = 1; i <= 24; ++i)
703                 {
704                         wi = weapon_info[i-1];
705                         if(wi && wi.impulse == imp)
706                                 weaponpriority_hudselector_1 = strcat(weaponpriority_hudselector_1, " ", ftos(i));
707                 }
708
709         weaponpriority_hudselector_0 = strzone(substring(weaponpriority_hudselector_0, 1, strlen(weaponpriority_hudselector_0) - 1));
710         weaponpriority_hudselector_1 = strzone(substring(weaponpriority_hudselector_1, 1, strlen(weaponpriority_hudselector_1) - 1));
711 }
712 entity get_weaponinfo(float id)
713 {
714         entity w;
715         if(id < WEP_FIRST || id > WEP_LAST)
716                 return dummy_weapon_info;
717         w = weapon_info[id - 1];
718         if(w)
719                 return w;
720         return dummy_weapon_info;
721 }