2 ===========================================================================
\r
4 CLIENT WEAPONSYSTEM CODE
\r
5 Bring back W_Weaponframe
\r
7 ===========================================================================
\r
10 .float weapon_frametime;
\r
12 float W_WeaponRateFactor()
\r
15 t = 1.0 / g_weaponratefactor;
\r
20 void W_SwitchWeapon_Force(entity e, float w)
\r
22 e.cnt = e.switchweapon;
\r
26 .float antilag_debug;
\r
28 // VorteX: static frame globals
\r
29 float WFRAME_DONTCHANGE = -1;
\r
30 float WFRAME_FIRE1 = 0;
\r
31 float WFRAME_FIRE2 = 1;
\r
32 float WFRAME_IDLE = 2;
\r
33 float WFRAME_RELOAD = 3;
\r
36 void(float fr, float t, void() func) weapon_thinkf;
\r
38 vector W_HitPlotUnnormalizedUntransform(vector screenforward, vector screenright, vector screenup, vector v)
\r
41 ret_x = screenright * v;
\r
42 ret_y = screenup * v;
\r
43 ret_z = screenforward * v;
\r
47 vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforward, vector screenright, vector screenup, vector v)
\r
50 vector mi, ma, thisv, myv, ret;
\r
52 myv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, org);
\r
54 // x = 0..1 relative to hitbox; y = 0..1 relative to hitbox; z = distance
\r
56 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k)
\r
58 thisv = targ.origin;
\r
59 if(i) thisv_x += targ.maxs_x; else thisv_x += targ.mins_x;
\r
60 if(j) thisv_y += targ.maxs_y; else thisv_y += targ.mins_y;
\r
61 if(k) thisv_z += targ.maxs_z; else thisv_z += targ.mins_z;
\r
62 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, thisv);
\r
65 if(mi_x > thisv_x) mi_x = thisv_x; if(ma_x < thisv_x) ma_x = thisv_x;
\r
66 if(mi_y > thisv_y) mi_y = thisv_y; if(ma_y < thisv_y) ma_y = thisv_y;
\r
67 //if(mi_z > thisv_z) mi_z = thisv_z; if(ma_z < thisv_z) ma_y = thisv_z;
\r
76 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, v);
\r
77 ret_x = (thisv_x - mi_x) / (ma_x - mi_x);
\r
78 ret_y = (thisv_y - mi_y) / (ma_y - mi_y);
\r
79 ret_z = thisv_z - myv_z;
\r
83 void W_HitPlotAnalysis(entity player, vector screenforward, vector screenright, vector screenup)
\r
89 if(player.hitplotfh >= 0)
\r
91 lag = ANTILAG_LATENCY(player);
\r
94 if(clienttype(player) != CLIENTTYPE_REAL)
\r
95 lag = 0; // only antilag for clients
\r
97 org = player.origin + player.view_ofs;
\r
98 traceline_antilag_force(player, org, org + screenforward * MAX_SHOT_DISTANCE, MOVE_NORMAL, player, lag);
\r
99 if(trace_ent.flags & FL_CLIENT)
\r
101 antilag_takeback(trace_ent, time - lag);
\r
102 hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);
\r
103 antilag_restore(trace_ent);
\r
104 fputs(player.hitplotfh, strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), " ", ftos(player.switchweapon), "\n"));
\r
105 //print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n"));
\r
113 // this function calculates w_shotorg and w_shotdir based on the weapon model
\r
114 // offset, trueaim and antilag, and won't put w_shotorg inside a wall.
\r
115 // make sure you call makevectors first (FIXME?)
\r
116 void W_SetupShot_Dir_ProjectileSize(entity ent, vector s_forward, vector mi, vector ma, float antilag, float recoil, string snd, float maxdamage)
\r
118 float nudge = 1; // added to traceline target and subtracted from result
\r
119 local vector trueaimpoint;
\r
120 local float oldsolid;
\r
122 oldsolid = ent.dphitcontentsmask;
\r
123 ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
\r
125 WarpZone_traceline_antilag(world, ent.origin + ent.view_ofs, ent.origin + ent.view_ofs + s_forward * MAX_SHOT_DISTANCE, MOVE_NORMAL, ent, ANTILAG_LATENCY(ent));
\r
126 // passing world, because we do NOT want it to touch dphitcontentsmask
\r
128 WarpZone_TraceLine(ent.origin + ent.view_ofs, ent.origin + ent.view_ofs + s_forward * MAX_SHOT_DISTANCE, MOVE_NOMONSTERS, ent);
\r
129 ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
\r
135 trueaimpoint = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); // warpzone support
\r
140 // track max damage
\r
141 if not(inWarmupStage) {
\r
143 w = get_weaponinfo(ent.weapon);
\r
144 if(w.spawnflags & WEP_TYPE_SPLASH) { // splash damage
\r
145 ent.stats_fired[ent.weapon - 1] += maxdamage;
\r
146 ent.stat_fired = ent.weapon + 64 * floor(ent.stats_fired[ent.weapon - 1]);
\r
150 W_HitPlotAnalysis(ent, v_forward, v_right, v_up);
\r
152 if(ent.weaponentity.movedir_x > 0)
\r
154 vecs = ent.weaponentity.movedir;
\r
160 if(debug_shotorg != '0 0 0')
\r
161 vecs = debug_shotorg;
\r
163 dv = v_right * vecs_y + v_up * vecs_z;
\r
164 w_shotorg = ent.origin + ent.view_ofs + dv;
\r
166 // now move the shotorg forward as much as requested if possible
\r
169 if(ent.antilag_debug)
\r
170 tracebox_antilag(ent, w_shotorg, mi, ma, w_shotorg + v_forward * (vecs_x + nudge), MOVE_NORMAL, ent, ent.antilag_debug);
\r
172 tracebox_antilag(ent, w_shotorg, mi, ma, w_shotorg + v_forward * (vecs_x + nudge), MOVE_NORMAL, ent, ANTILAG_LATENCY(ent));
\r
175 tracebox(w_shotorg, mi, ma, w_shotorg + v_forward * (vecs_x + nudge), MOVE_NORMAL, ent);
\r
176 w_shotorg = trace_endpos - v_forward * nudge;
\r
177 // calculate the shotdir from the chosen shotorg
\r
178 w_shotdir = normalize(trueaimpoint - w_shotorg);
\r
181 if (!ent.cvar_cl_noantilag)
\r
183 if (cvar("g_antilag") == 1) // switch to "ghost" if not hitting original
\r
185 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, ent);
\r
186 if (!trace_ent.takedamage)
\r
188 traceline_antilag_force (ent, w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, ent, ANTILAG_LATENCY(ent));
\r
189 if (trace_ent.takedamage && trace_ent.classname == "player")
\r
193 traceline(w_shotorg, e.origin, MOVE_NORMAL, ent);
\r
195 w_shotdir = normalize(trace_ent.origin - w_shotorg);
\r
199 else if(cvar("g_antilag") == 3) // client side hitscan
\r
201 // this part MUST use prydon cursor
\r
202 if (ent.cursor_trace_ent) // client was aiming at someone
\r
203 if (ent.cursor_trace_ent != ent) // just to make sure
\r
204 if (ent.cursor_trace_ent.takedamage) // and that person is killable
\r
205 if (ent.cursor_trace_ent.classname == "player") // and actually a player
\r
207 // verify that the shot would miss without antilag
\r
208 // (avoids an issue where guns would always shoot at their origin)
\r
209 traceline(w_shotorg, w_shotorg + w_shotdir * MAX_SHOT_DISTANCE, MOVE_NORMAL, ent);
\r
210 if (!trace_ent.takedamage)
\r
212 // verify that the shot would hit if altered
\r
213 traceline(w_shotorg, ent.cursor_trace_ent.origin, MOVE_NORMAL, ent);
\r
214 if (trace_ent == ent.cursor_trace_ent)
\r
215 w_shotdir = normalize(ent.cursor_trace_ent.origin - w_shotorg);
\r
217 print("antilag fail\n");
\r
223 ent.dphitcontentsmask = oldsolid; // restore solid type (generally SOLID_SLIDEBOX)
\r
226 ent.punchangle_x -= recoil;
\r
230 sound (ent, CHAN_WEAPON, snd, VOL_BASE, ATTN_NORM);
\r
233 if (ent.items & IT_STRENGTH && maxdamage)
\r
234 sound (ent, CHAN_AUTO, "weapons/strength_fire.wav", VOL_BASE, ATTN_NORM);
\r
237 #define W_SetupShot_ProjectileSize(ent,mi,ma,antilag,recoil,snd,maxdamage) W_SetupShot_Dir_ProjectileSize(ent, v_forward, mi, ma, antilag, recoil, snd, maxdamage)
\r
238 #define W_SetupShot_Dir(ent,s_forward,antilag,recoil,snd,maxdamage) W_SetupShot_Dir_ProjectileSize(ent, s_forward, '0 0 0', '0 0 0', antilag, recoil, snd, maxdamage)
\r
239 #define W_SetupShot(ent,antilag,recoil,snd,maxdamage) W_SetupShot_ProjectileSize(ent, '0 0 0', '0 0 0', antilag, recoil, snd, maxdamage)
\r
241 .string weaponname;
\r
243 float CL_Weaponentity_CustomizeEntityForClient()
\r
245 self.viewmodelforclient = self.owner;
\r
246 if(other.classname == "spectator")
\r
247 if(other.enemy == self.owner)
\r
248 self.viewmodelforclient = other;
\r
252 float CL_ExteriorWeaponentity_CustomizeEntityForClient()
\r
254 // hide the exterior weapon entity of a predator from their prey
\r
255 // otherwise, the stomach model the predator is transformed in (see Client_customizeentityforclient) will have a weapon model attached to it
\r
256 if(self.owner.weaponname == "" || self.owner.deadflag != DEAD_NO)
\r
260 chase = other.cvar_chase_active;
\r
262 if(other.spectatee_status && other.spectatee_status == num_for_edict(other.enemy))
\r
263 other = other.enemy; // also do this for the player we are spectating
\r
265 if not(chase || other.classname == "observer") // the observer check prevents a bug
\r
266 if(other.predator == self.owner)
\r
268 setmodel(self, "");
\r
272 self.effects &~= EF_NODEPTHTEST;
\r
273 if not(self.owner.stat_eaten)
\r
274 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3"));
\r
275 else if(cvar("g_vore_neighborprey_distance") && other.predator == self.owner.predator && !(chase || other.classname == "observer"))
\r
277 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // allow seeing neighboring prey's weapon model
\r
278 self.effects |= EF_NODEPTHTEST; // don't hide behind the stomach's own EF_NODEPTHTEST
\r
281 setmodel(self, ""); // hide prey's weapon model
\r
285 float qcweaponanimation;
\r
286 vector weapon_offset = '0 -10 0';
\r
287 vector weapon_adjust = '10 0 -15';
\r
288 .vector weapon_morph0origin;
\r
289 .vector weapon_morph0angles;
\r
290 .float weapon_morph0time;
\r
291 .vector weapon_morph1origin;
\r
292 .vector weapon_morph1angles;
\r
293 .float weapon_morph1time;
\r
294 .vector weapon_morph2origin;
\r
295 .vector weapon_morph2angles;
\r
296 .float weapon_morph2time;
\r
297 .vector weapon_morph3origin;
\r
298 .vector weapon_morph3angles;
\r
299 .float weapon_morph3time;
\r
300 .vector weapon_morph4origin;
\r
301 .vector weapon_morph4angles;
\r
302 .float weapon_morph4time;
\r
303 #define QCWEAPONANIMATION_ORIGIN(e) ((weapon_offset_x + e.view_ofs_x) * v_forward - (weapon_offset_y + e.view_ofs_y) * v_right + (weapon_offset_z + e.view_ofs_z) * v_up + weapon_adjust)
\r
306 * supported formats:
\r
308 * 1. simple animated model, muzzle flash handling on h_ model:
\r
309 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
\r
311 * shot = muzzle end (shot origin, also used for muzzle flashes)
\r
312 * shell = casings ejection point (must be on the right hand side of the gun)
\r
313 * weapon = attachment for v_tuba.md3
\r
314 * v_tuba.md3 - first and third person model
\r
315 * g_tuba.md3 - pickup model
\r
317 * 2. simple animated model, muzzle flash handling on v_ model:
\r
318 * h_tuba.dpm, h_tuba.dpm.framegroups - invisible model controlling the animation
\r
320 * weapon = attachment for v_tuba.md3
\r
321 * v_tuba.md3 - first and third person model
\r
323 * shot = muzzle end (shot origin, also used for muzzle flashes)
\r
324 * shell = casings ejection point (must be on the right hand side of the gun)
\r
325 * g_tuba.md3 - pickup model
\r
327 * 3. fully animated model, muzzle flash handling on h_ model:
\r
328 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
\r
330 * shot = muzzle end (shot origin, also used for muzzle flashes)
\r
331 * shell = casings ejection point (must be on the right hand side of the gun)
\r
332 * handle = corresponding to the origin of v_tuba.md3 (used for muzzle flashes)
\r
333 * v_tuba.md3 - third person model
\r
334 * g_tuba.md3 - pickup model
\r
336 * 4. fully animated model, muzzle flash handling on v_ model:
\r
337 * h_tuba.dpm, h_tuba.dpm.framegroups - animated first person model
\r
339 * shot = muzzle end (shot origin)
\r
340 * shell = casings ejection point (must be on the right hand side of the gun)
\r
341 * v_tuba.md3 - third person model
\r
343 * shot = muzzle end (for muzzle flashes)
\r
344 * g_tuba.md3 - pickup model
\r
347 void CL_Weaponentity_Think()
\r
349 float tb, v_shot_idx;
\r
350 self.nextthink = time;
\r
351 if (intermission_running)
\r
352 self.frame = self.anim_idle_x;
\r
353 if (self.owner.weaponentity != self)
\r
355 if (self.weaponentity)
\r
356 remove(self.weaponentity);
\r
360 if (self.owner.deadflag != DEAD_NO)
\r
363 if (self.weaponentity)
\r
364 self.weaponentity.model = "";
\r
367 if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
\r
368 if (substring(self.owner.model, -4, 4) != ".md3") // not a stomach model
\r
370 self.cnt = self.owner.weapon;
\r
371 self.dmg = self.owner.modelindex;
\r
372 self.deadflag = self.owner.deadflag;
\r
374 string animfilename;
\r
376 if (self.owner.weaponname != "")
\r
378 // if there is a child entity, hide it until we're sure we use it
\r
379 if (self.weaponentity)
\r
380 self.weaponentity.model = "";
\r
381 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
\r
382 v_shot_idx = gettagindex(self, "shot"); // used later
\r
384 v_shot_idx = gettagindex(self, "tag_shot");
\r
386 if(qcweaponanimation)
\r
388 self.angles = '0 0 0';
\r
389 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0' + self.angles_z * '0 0 1');
\r
390 self.movedir = weapon_offset_x * v_forward - weapon_offset_y * v_right + weapon_offset_z * v_up + weapon_adjust;
\r
391 self.movedir_x += 32;
\r
392 self.spawnorigin = self.movedir;
\r
393 // oldorigin - not calculated here
\r
397 setmodel(self, strcat("models/weapons/h_", self.owner.weaponname, ".iqm")); // precision set below
\r
398 animfilename = strcat("models/weapons/h_", self.owner.weaponname, ".iqm.animinfo");
\r
399 animfile = fopen(animfilename, FILE_READ);
\r
400 // preset some defaults that work great for renamed zym files (which don't need an animinfo)
\r
401 self.anim_fire1 = '0 1 0.01';
\r
402 self.anim_fire2 = '1 1 0.01';
\r
403 self.anim_idle = '2 1 0.01';
\r
404 self.anim_reload = '3 1 0.01';
\r
407 animparseerror = FALSE;
\r
408 self.anim_fire1 = animparseline(animfile);
\r
409 self.anim_fire2 = animparseline(animfile);
\r
410 self.anim_idle = animparseline(animfile);
\r
411 self.anim_reload = animparseline(animfile);
\r
413 if (animparseerror)
\r
414 print("Parse error in ", animfilename, ", some player animations are broken\n");
\r
417 // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
\r
418 // if we don't, this is a "real" animated model
\r
419 if(gettagindex(self, "weapon"))
\r
421 if (!self.weaponentity)
\r
422 self.weaponentity = spawn();
\r
423 setmodel(self.weaponentity, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision does not matter
\r
424 setattachment(self.weaponentity, self, "weapon");
\r
426 else if(gettagindex(self, "tag_weapon"))
\r
428 if (!self.weaponentity)
\r
429 self.weaponentity = spawn();
\r
430 setmodel(self.weaponentity, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision does not matter
\r
431 setattachment(self.weaponentity, self, "tag_weapon");
\r
435 if(self.weaponentity)
\r
436 remove(self.weaponentity);
\r
437 self.weaponentity = world;
\r
440 setorigin(self,'0 0 0');
\r
441 self.angles = '0 0 0';
\r
443 self.viewmodelforclient = world;
\r
447 if(v_shot_idx) // v_ model attached to invisible h_ model
\r
449 self.movedir = gettaginfo(self.weaponentity, v_shot_idx);
\r
453 idx = gettagindex(self, "shot");
\r
455 idx = gettagindex(self, "tag_shot");
\r
457 self.movedir = gettaginfo(self, idx);
\r
460 print("WARNING: weapon model ", self.model, " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
\r
461 self.movedir = '0 0 0';
\r
465 if(self.weaponentity) // v_ model attached to invisible h_ model
\r
467 idx = gettagindex(self.weaponentity, "shell");
\r
469 idx = gettagindex(self.weaponentity, "tag_shell");
\r
471 self.spawnorigin = gettaginfo(self.weaponentity, idx);
\r
477 idx = gettagindex(self, "shell");
\r
479 idx = gettagindex(self, "tag_shell");
\r
481 self.spawnorigin = gettaginfo(self, idx);
\r
484 print("WARNING: weapon model ", self.model, " does not support the 'shell' tag, will display casings wrong\n");
\r
485 self.spawnorigin = self.movedir;
\r
491 self.oldorigin = '0 0 0'; // use regular attachment
\r
495 if(self.weaponentity)
\r
497 idx = gettagindex(self, "weapon");
\r
499 idx = gettagindex(self, "tag_weapon");
\r
503 idx = gettagindex(self, "handle");
\r
505 idx = gettagindex(self, "tag_handle");
\r
509 self.oldorigin = self.movedir - gettaginfo(self, idx);
\r
513 print("WARNING: weapon model ", self.model, " does not support the 'handle' tag and neither does the v_ model support the 'shot' tag, will display muzzle flashes TOTALLY wrong\n");
\r
514 self.oldorigin = '0 0 0'; // there is no way to recover from this
\r
518 self.viewmodelforclient = self.owner;
\r
524 if(self.weaponentity)
\r
525 remove(self.weaponentity);
\r
526 self.weaponentity = world;
\r
527 self.movedir = '0 0 0';
\r
528 self.spawnorigin = '0 0 0';
\r
529 self.oldorigin = '0 0 0';
\r
530 self.anim_fire1 = '0 1 0.01';
\r
531 self.anim_fire2 = '0 1 0.01';
\r
532 self.anim_idle = '0 1 0.01';
\r
533 self.anim_reload = '0 1 0.01';
\r
536 self.view_ofs = '0 0 0';
\r
538 if(self.movedir_x >= 0)
\r
542 self.movedir = shotorg_adjust(v0, FALSE, FALSE);
\r
543 self.view_ofs = shotorg_adjust(v0, FALSE, TRUE) - v0;
\r
545 self.owner.stat_shotorg = compressShotOrigin(self.movedir);
\r
546 self.movedir = decompressShotOrigin(self.owner.stat_shotorg); // make them match perfectly
\r
548 self.spawnorigin += self.view_ofs; // offset the casings origin by the same amount
\r
550 // check if an instant weapon switch occurred
\r
551 if (qcweaponanimation)
\r
553 if (self.state == WS_READY)
\r
555 self.angles = '0 0 0';
\r
556 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0' + self.angles_z * '0 0 1');
\r
557 setorigin(self, QCWEAPONANIMATION_ORIGIN(self));
\r
561 setorigin(self, self.view_ofs);
\r
562 // reset animstate now
\r
563 self.wframe = WFRAME_IDLE;
\r
564 self.weapon_morph0time = 0;
\r
565 self.weapon_morph1time = 0;
\r
566 self.weapon_morph2time = 0;
\r
567 self.weapon_morph3time = 0;
\r
568 self.weapon_morph4time = 0;
\r
569 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
\r
572 tb = (self.effects & (EF_TELEPORT_BIT | EF_RESTARTANIM_BIT));
\r
573 self.effects = self.owner.effects & EFMASK_CHEAP;
\r
574 self.effects &~= EF_LOWPRECISION;
\r
575 self.effects &~= EF_FULLBRIGHT; // can mask team color, so get rid of it
\r
576 self.effects &~= EF_TELEPORT_BIT;
\r
577 self.effects &~= EF_RESTARTANIM_BIT;
\r
578 self.effects |= tb;
\r
580 if(self.owner.alpha == default_player_alpha)
\r
581 self.alpha = default_weapon_alpha;
\r
582 else if(self.owner.alpha != 0 && !self.owner.stat_eaten)
\r
583 self.alpha = self.owner.alpha;
\r
587 self.colormap = self.owner.colormap;
\r
588 self.colormod = self.owner.colormod;
\r
589 self.glowmod = self.owner.weaponentity_glowmod;
\r
590 if (self.weaponentity)
\r
592 self.weaponentity.effects = self.effects;
\r
593 self.weaponentity.alpha = self.alpha;
\r
594 self.weaponentity.colormap = self.colormap;
\r
595 self.weaponentity.colormod = self.owner.colormod; // used by the regurgitating colors
\r
596 self.weaponentity.glowmod = self.glowmod;
\r
599 self.angles = '0 0 0';
\r
602 if (self.state == WS_RAISE && !intermission_running)
\r
604 f = (self.owner.weapon_nextthink - time) * g_weaponratefactor / cvar("g_balance_weaponswitchdelay");
\r
605 self.angles_x = -90 * f * f;
\r
606 if (qcweaponanimation)
\r
608 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0' + self.angles_z * '0 0 1');
\r
609 setorigin(self, QCWEAPONANIMATION_ORIGIN(self));
\r
612 else if (self.state == WS_DROP && !intermission_running)
\r
614 f = 1 - (self.owner.weapon_nextthink - time) * g_weaponratefactor / cvar("g_balance_weaponswitchdelay");
\r
615 self.angles_x = -90 * f * f;
\r
616 if (qcweaponanimation)
\r
618 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0' + self.angles_z * '0 0 1');
\r
619 setorigin(self, QCWEAPONANIMATION_ORIGIN(self));
\r
622 else if (self.state == WS_CLEAR)
\r
625 self.angles_x = -90 * f * f;
\r
626 if (qcweaponanimation)
\r
628 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0' + self.angles_z * '0 0 1');
\r
629 setorigin(self, QCWEAPONANIMATION_ORIGIN(self));
\r
632 else if (qcweaponanimation && time < self.owner.weapon_morph1time)
\r
634 f = (time - self.owner.weapon_morph0time) / (self.owner.weapon_morph1time - self.owner.weapon_morph0time);
\r
635 f = 1 - pow(1 - f, 3);
\r
636 self.angles = self.owner.weapon_morph0angles * (1 - f) + self.owner.weapon_morph1angles * f;
\r
637 setorigin(self, self.owner.weapon_morph0origin * (1 - f) + self.owner.weapon_morph1origin * f);
\r
639 else if (qcweaponanimation && time < self.owner.weapon_morph2time)
\r
641 f = (time - self.owner.weapon_morph1time) / (self.owner.weapon_morph2time - self.owner.weapon_morph1time);
\r
642 f = 1 - pow(1 - f, 3);
\r
643 self.angles = self.owner.weapon_morph1angles * (1 - f) + self.owner.weapon_morph2angles * f;
\r
644 setorigin(self, self.owner.weapon_morph1origin * (1 - f) + self.owner.weapon_morph2origin * f);
\r
646 else if (qcweaponanimation && time < self.owner.weapon_morph3time)
\r
648 f = (time - self.owner.weapon_morph2time) / (self.owner.weapon_morph3time - self.owner.weapon_morph2time);
\r
649 f = 1 - pow(1 - f, 3);
\r
650 self.angles = self.owner.weapon_morph2angles * (1 - f) + self.owner.weapon_morph3angles * f;
\r
651 setorigin(self, self.owner.weapon_morph2origin * (1 - f) + self.owner.weapon_morph3origin * f);
\r
653 else if (qcweaponanimation && time < self.owner.weapon_morph4time)
\r
655 f = (time - self.owner.weapon_morph3time) / (self.owner.weapon_morph4time - self.owner.weapon_morph3time);
\r
656 f = 1 - pow(1 - f, 3);
\r
657 self.angles = self.owner.weapon_morph3angles * (1 - f) + self.owner.weapon_morph4angles * f;
\r
658 setorigin(self, self.owner.weapon_morph3origin * (1 - f) + self.owner.weapon_morph4origin * f);
\r
660 else if (qcweaponanimation)
\r
662 // begin a new idle morph
\r
663 self.owner.weapon_morph0time = time;
\r
664 self.owner.weapon_morph0angles = self.angles;
\r
665 self.owner.weapon_morph0origin = self.origin;
\r
673 // turn gun to the left to look at it
\r
675 self.owner.weapon_morph1time = time + t * 0.2;
\r
676 self.owner.weapon_morph1angles = randomvec() * 3 + '-5 30 0';
\r
677 makevectors(self.owner.weapon_morph1angles_x * '-1 0 0' + self.owner.weapon_morph1angles_y * '0 1 0' + self.owner.weapon_morph1angles_z * '0 0 1');
\r
678 self.owner.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self);
\r
680 self.owner.weapon_morph2time = time + t * 0.6;
\r
681 self.owner.weapon_morph2angles = randomvec() * 3 + '-5 30 0';
\r
682 makevectors(self.owner.weapon_morph2angles_x * '-1 0 0' + self.owner.weapon_morph2angles_y * '0 1 0' + self.owner.weapon_morph2angles_z * '0 0 1');
\r
683 self.owner.weapon_morph2origin = QCWEAPONANIMATION_ORIGIN(self);
\r
685 self.owner.weapon_morph3time = time + t;
\r
686 self.owner.weapon_morph3angles = '0 0 0';
\r
687 makevectors(self.owner.weapon_morph3angles_x * '-1 0 0' + self.owner.weapon_morph3angles_y * '0 1 0' + self.owner.weapon_morph3angles_z * '0 0 1');
\r
688 self.owner.weapon_morph3origin = QCWEAPONANIMATION_ORIGIN(self);
\r
692 // raise the gun a bit
\r
694 self.owner.weapon_morph1time = time + t * 0.2;
\r
695 self.owner.weapon_morph1angles = randomvec() * 3 + '30 -10 0';
\r
696 makevectors(self.owner.weapon_morph1angles_x * '-1 0 0' + self.owner.weapon_morph1angles_y * '0 1 0' + self.owner.weapon_morph1angles_z * '0 0 1');
\r
697 self.owner.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self);
\r
699 self.owner.weapon_morph2time = time + t * 0.5;
\r
700 self.owner.weapon_morph2angles = randomvec() * 3 + '30 -10 5';
\r
701 makevectors(self.owner.weapon_morph2angles_x * '-1 0 0' + self.owner.weapon_morph2angles_y * '0 1 0' + self.owner.weapon_morph2angles_z * '0 0 1');
\r
702 self.owner.weapon_morph2origin = QCWEAPONANIMATION_ORIGIN(self);
\r
704 self.owner.weapon_morph3time = time + t;
\r
705 self.owner.weapon_morph3angles = '0 0 0';
\r
706 makevectors(self.owner.weapon_morph3angles_x * '-1 0 0' + self.owner.weapon_morph3angles_y * '0 1 0' + self.owner.weapon_morph3angles_z * '0 0 1');
\r
707 self.owner.weapon_morph3origin = QCWEAPONANIMATION_ORIGIN(self);
\r
713 self.owner.weapon_morph1time = time + t * 0.3;
\r
714 self.owner.weapon_morph1angles = randomvec() * 6;
\r
715 makevectors(self.owner.weapon_morph1angles_x * '-1 0 0' + self.owner.weapon_morph1angles_y * '0 1 0' + self.owner.weapon_morph1angles_z * '0 0 1');
\r
716 self.owner.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self);
\r
718 self.owner.weapon_morph2time = time + t * 0.7;
\r
719 self.owner.weapon_morph2angles = randomvec() * 6;
\r
720 makevectors(self.owner.weapon_morph2angles_x * '-1 0 0' + self.owner.weapon_morph2angles_y * '0 1 0' + self.owner.weapon_morph2angles_z * '0 0 1');
\r
721 self.owner.weapon_morph2origin = QCWEAPONANIMATION_ORIGIN(self);
\r
723 self.owner.weapon_morph3time = time + t;
\r
724 self.owner.weapon_morph3angles = '0 0 0';
\r
725 makevectors(self.owner.weapon_morph3angles_x * '-1 0 0' + self.owner.weapon_morph3angles_y * '0 1 0' + self.owner.weapon_morph3angles_z * '0 0 1');
\r
726 self.owner.weapon_morph3origin = QCWEAPONANIMATION_ORIGIN(self);
\r
730 // hold it mostly steady
\r
731 t = random() * 6 + 4;
\r
732 self.owner.weapon_morph1time = time + t * 0.2;
\r
733 self.owner.weapon_morph1angles = randomvec() * 1;
\r
734 makevectors(self.owner.weapon_morph1angles_x * '-1 0 0' + self.owner.weapon_morph1angles_y * '0 1 0' + self.owner.weapon_morph1angles_z * '0 0 1');
\r
735 self.owner.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self);
\r
737 self.owner.weapon_morph2time = time + t * 0.5;
\r
738 self.owner.weapon_morph2angles = randomvec() * 1;
\r
739 makevectors(self.owner.weapon_morph2angles_x * '-1 0 0' + self.owner.weapon_morph2angles_y * '0 1 0' + self.owner.weapon_morph2angles_z * '0 0 1');
\r
740 self.owner.weapon_morph2origin = QCWEAPONANIMATION_ORIGIN(self);
\r
742 self.owner.weapon_morph3time = time + t * 0.7;
\r
743 self.owner.weapon_morph3angles = randomvec() * 1;
\r
744 makevectors(self.owner.weapon_morph3angles_x * '-1 0 0' + self.owner.weapon_morph3angles_y * '0 1 0' + self.owner.weapon_morph3angles_z * '0 0 1');
\r
745 self.owner.weapon_morph3origin = QCWEAPONANIMATION_ORIGIN(self);
\r
748 self.owner.weapon_morph4time = time + t;
\r
749 self.owner.weapon_morph4angles = '0 0 0';
\r
750 makevectors(self.owner.weapon_morph4angles_x * '-1 0 0' + self.owner.weapon_morph4angles_y * '0 1 0' + self.owner.weapon_morph4angles_z * '0 0 1');
\r
751 self.owner.weapon_morph4origin = QCWEAPONANIMATION_ORIGIN(self);
\r
755 // if we are a micro or macro, size the weapon model accordingly
\r
756 if(cvar("g_healthsize") && cvar("g_healthsize_weapon_scalefactor"))
\r
757 if(self.model != "")
\r
759 self.weaponentity.scale = (1 + cvar("g_healthsize_weapon_scalefactor")) - cvar("g_healthsize_weapon_scalefactor") * self.owner.scale;
\r
760 if(self.weaponentity.scale < 0.1)
\r
761 self.weaponentity.scale = 0.1; // stuff breaks if scale is smaller than this
\r
762 self.weaponentity.origin_z = (1 - self.weaponentity.scale) * cvar("g_healthsize_weapon_scalefactor_pos");
\r
766 void CL_ExteriorWeaponentity_Think()
\r
770 self.nextthink = time;
\r
771 if (self.owner.exteriorweaponentity != self)
\r
776 if (self.owner.deadflag != DEAD_NO)
\r
781 if (self.cnt != self.owner.weapon || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
\r
782 if (substring(self.owner.model, -4, 4) != ".md3") // not a stomach model
\r
784 self.cnt = self.owner.weapon;
\r
785 self.dmg = self.owner.modelindex;
\r
786 self.deadflag = self.owner.deadflag;
\r
787 if (self.owner.weaponname != "")
\r
788 setmodel(self, strcat("models/weapons/v_", self.owner.weaponname, ".md3")); // precision set below
\r
792 if((tag_found = gettagindex(self.owner, "tag_weapon")))
\r
794 self.tag_index = tag_found;
\r
795 self.tag_entity = self.owner;
\r
798 setattachment(self, self.owner, "bip01 r hand");
\r
800 // if that didn't find a tag, hide the exterior weapon model
\r
801 if (!self.tag_index)
\r
804 self.effects = self.owner.effects;
\r
805 if(sv_pitch_min == sv_pitch_max)
\r
806 self.effects |= EF_LOWPRECISION;
\r
808 self.effects &~= EF_LOWPRECISION;
\r
809 self.effects = self.effects & EFMASK_CHEAP; // eat performance
\r
810 if(self.owner.alpha == default_player_alpha)
\r
811 self.alpha = default_weapon_alpha;
\r
812 else if(self.owner.alpha != 0)
\r
813 self.alpha = self.owner.alpha;
\r
816 self.colormod = self.owner.colormod; // used by the regurgitating colors
\r
818 ang_x = bound(sv_pitch_min, self.owner.v_angle_x, sv_pitch_max);
\r
822 if(sv_pitch_fixyaw) // workaround for stupid player models that don't aim forward
\r
824 ang_y = self.owner.v_angle_y;
\r
826 var vector v = v_forward;
\r
827 var float t = self.tag_entity.frame1time;
\r
828 var float f = self.tag_entity.frame;
\r
829 self.tag_entity.frame1time = time;
\r
830 self.tag_entity.frame = self.tag_entity.anim_idle_x;
\r
831 gettaginfo(self.tag_entity, self.tag_index);
\r
832 self.tag_entity.frame1time = t;
\r
833 self.tag_entity.frame = f;
\r
834 // untransform v according to this coordinate space
\r
836 w_x = v_forward * v;
\r
837 w_y = -v_right * v;
\r
839 self.angles = vectoangles(w);
\r
843 ang_x = -/* don't ask */ang_x;
\r
847 // if we are a micro or macro, size the weapon model accordingly
\r
848 if(self.owner.scale && cvar("g_healthsize_exteriorweapon_scalefactor"))
\r
849 if(self.model != "")
\r
851 self.scale = 1 / self.owner.scale; // for some reason, the exterior weapon entity copies the player's scale somewhere else, so undo that first
\r
852 self.scale = (1 - cvar("g_healthsize_exteriorweapon_scalefactor")) + cvar("g_healthsize_exteriorweapon_scalefactor") * self.scale;
\r
855 self.colormap = self.owner.colormap;
\r
856 self.glowmod = self.owner.weaponentity_glowmod;
\r
857 self.customizeentityforclient = CL_ExteriorWeaponentity_CustomizeEntityForClient;
\r
860 // spawning weaponentity for client
\r
861 void CL_SpawnWeaponentity()
\r
863 self.weaponentity = spawn();
\r
864 self.weaponentity.classname = "weaponentity";
\r
865 self.weaponentity.solid = SOLID_NOT;
\r
866 self.weaponentity.owner = self;
\r
867 setmodel(self.weaponentity, ""); // precision set when changed
\r
868 setorigin(self.weaponentity, '0 0 0');
\r
869 self.weaponentity.angles = '0 0 0';
\r
870 self.weaponentity.viewmodelforclient = self;
\r
871 self.weaponentity.flags = 0;
\r
872 self.weaponentity.think = CL_Weaponentity_Think;
\r
873 self.weaponentity.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
\r
874 self.weaponentity.nextthink = time;
\r
876 self.exteriorweaponentity = spawn();
\r
877 self.exteriorweaponentity.classname = "exteriorweaponentity";
\r
878 self.exteriorweaponentity.solid = SOLID_NOT;
\r
879 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
\r
880 self.exteriorweaponentity.owner = self;
\r
881 setorigin(self.exteriorweaponentity, '0 0 0');
\r
882 self.exteriorweaponentity.angles = '0 0 0';
\r
883 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
\r
884 self.exteriorweaponentity.nextthink = time;
\r
887 .float hasweapon_complain_spam;
\r
889 float client_hasweapon(entity cl, float wpn, float andammo, float complain)
\r
891 local float weaponbit;
\r
892 //local float weaponbit, f;
\r
893 //local entity oldself;
\r
895 if(time < self.hasweapon_complain_spam)
\r
898 self.hasweapon_complain_spam = time + 0.2;
\r
900 if (wpn < WEP_FIRST || wpn > WEP_LAST)
\r
903 sprint(self, "Invalid weapon\n");
\r
906 weaponbit = W_WeaponBit(wpn);
\r
907 if (cl.weapons & weaponbit)
\r
909 // since we don't have an infinite ammo weapon in vore tournament, allow switching to the grabber even when it has no ammo
\r
912 if(cl.items & IT_UNLIMITED_WEAPON_AMMO)
\r
920 f = weapon_action(wpn, WR_CHECKAMMO1);
\r
921 f = f + weapon_action(wpn, WR_CHECKAMMO2);
\r
927 if(clienttype(cl) == CLIENTTYPE_REAL)
\r
929 play2(cl, "misc/unavailable.wav");
\r
930 sprint(cl, strcat("You don't have any ammo for the ^2", W_Name(wpn), "\n"));
\r
940 // Report Proper Weapon Status / Modified Weapon Ownership Message
\r
941 if(weaponsInMap & weaponbit)
\r
943 sprint(cl, strcat("You do not have the ^2", W_Name(wpn), "\n") );
\r
945 if(cvar("g_showweaponspawns"))
\r
950 e = get_weaponinfo(wpn);
\r
953 for(e = world; (e = findfloat(e, weapons, weaponbit)); )
\r
955 if(e.classname == "droppedweapon")
\r
957 if not(e.flags & FL_ITEM)
\r
959 WaypointSprite_Spawn(
\r
971 sprint(cl, strcat("The ^2", W_Name(wpn), "^7 is ^1NOT AVAILABLE^7 in this map\n") );
\r
973 play2(cl, "misc/unavailable.wav");
\r
981 if (self.weapon != -1)
\r
983 if (self.weaponentity)
\r
985 self.weaponentity.state = WS_CLEAR;
\r
986 self.weaponentity.effects = 0;
\r
992 if (self.weaponentity)
\r
993 self.weaponentity.state = WS_READY;
\r
994 weapon_thinkf(WFRAME_IDLE, 1000000, w_ready);
\r
997 // Setup weapon for client (after this raise frame will be launched)
\r
998 void weapon_setup(float windex)
\r
1001 qcweaponanimation = cvar("sv_qcweaponanimation");
\r
1002 e = get_weaponinfo(windex);
\r
1003 self.items &~= IT_AMMO;
\r
1004 self.items = self.items | e.items;
\r
1006 // the two weapon entities will notice this has changed and update their models
\r
1007 self.weapon = windex;
\r
1008 self.weaponname = e.mdl;
\r
1011 // perform weapon to attack (weaponstate and attack_finished check is here)
\r
1012 void W_SwitchToOtherWeapon(entity pl)
\r
1014 // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
\r
1016 w = W_WeaponBit(pl.weapon);
\r
1018 ww = w_getbestweapon(pl);
\r
1021 W_SwitchWeapon_Force(pl, ww);
\r
1024 .float prevdryfire;
\r
1025 float weapon_prepareattack_checkammo(float secondary)
\r
1027 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
\r
1028 if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
\r
1030 if(self.weapon == self.switchweapon && time - self.prevdryfire > 1) // only play once BEFORE starting to switch weapons
\r
1032 sound (self, CHAN_AUTO, "misc/unavailable.wav", VOL_BASE, ATTN_NORM);
\r
1033 self.prevdryfire = time;
\r
1036 // since we don't have an infinite ammo weapon in vore tournament, allow switching to the grabber even when it has no ammo
\r
1037 //W_SwitchToOtherWeapon(self);
\r
1042 .float race_penalty;
\r
1043 float weapon_prepareattack_check(float secondary, float attacktime)
\r
1045 if(!weapon_prepareattack_checkammo(secondary))
\r
1048 //if sv_ready_restart_after_countdown is set, don't allow the player to shoot
\r
1049 //if all players readied up and the countdown is running
\r
1050 if(time < game_starttime || time < self.race_penalty) {
\r
1054 if (timeoutStatus == 2) //don't allow the player to shoot while game is paused
\r
1057 // do not even think about shooting if switching
\r
1058 if(self.switchweapon != self.weapon)
\r
1061 if(attacktime >= 0)
\r
1063 // don't fire if previous attack is not finished
\r
1064 if (ATTACK_FINISHED(self) > time + self.weapon_frametime * 0.5)
\r
1066 // don't fire while changing weapon
\r
1067 if (self.weaponentity.state != WS_READY)
\r
1073 float weapon_prepareattack_do(float secondary, float attacktime)
\r
1075 self.weaponentity.state = WS_INUSE;
\r
1077 self.spawnshieldtime = min(self.spawnshieldtime, time); // kill spawn shield when you fire
\r
1079 // if the weapon hasn't been firing continuously, reset the timer
\r
1080 if(attacktime >= 0)
\r
1082 if (ATTACK_FINISHED(self) < time - self.weapon_frametime * 1.5)
\r
1084 ATTACK_FINISHED(self) = time;
\r
1085 //dprint("resetting attack finished to ", ftos(time), "\n");
\r
1087 ATTACK_FINISHED(self) = ATTACK_FINISHED(self) + attacktime * W_WeaponRateFactor();
\r
1089 //dprint("attack finished ", ftos(ATTACK_FINISHED(self)), "\n");
\r
1092 float weapon_prepareattack(float secondary, float attacktime)
\r
1094 if(weapon_prepareattack_check(secondary, attacktime))
\r
1096 weapon_prepareattack_do(secondary, attacktime);
\r
1103 void weapon_thinkf(float fr, float t, void() func)
\r
1106 vector of, or, ou;
\r
1107 float restartanim;
\r
1109 if(fr == WFRAME_DONTCHANGE)
\r
1111 fr = self.weaponentity.wframe;
\r
1112 restartanim = FALSE;
\r
1114 else if (fr == WFRAME_IDLE)
\r
1115 restartanim = FALSE;
\r
1117 restartanim = TRUE;
\r
1123 if (self.weaponentity)
\r
1125 self.weaponentity.wframe = fr;
\r
1126 if (qcweaponanimation)
\r
1128 if (fr != WFRAME_IDLE)
\r
1130 self.weapon_morph0time = time;
\r
1131 self.weapon_morph0angles = self.weaponentity.angles;
\r
1132 self.weapon_morph0origin = self.weaponentity.origin;
\r
1134 self.weapon_morph1angles = '0 0 0';
\r
1135 self.weapon_morph1time = time + t;
\r
1136 makevectors(self.weapon_morph1angles_x * '-1 0 0' + self.weapon_morph1angles_y * '0 1 0' + self.weapon_morph1angles_z * '0 0 1');
\r
1137 self.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1139 self.weapon_morph2angles = '0 0 0';
\r
1140 self.weapon_morph2time = time + t;
\r
1141 makevectors(self.weapon_morph2angles_x * '-1 0 0' + self.weapon_morph2angles_y * '0 1 0' + self.weapon_morph2angles_z * '0 0 1');
\r
1142 self.weapon_morph2origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1144 self.weapon_morph3angles = '0 0 0';
\r
1145 self.weapon_morph3time = time + t;
\r
1146 makevectors(self.weapon_morph3angles_x * '-1 0 0' + self.weapon_morph3angles_y * '0 1 0' + self.weapon_morph3angles_z * '0 0 1');
\r
1147 self.weapon_morph3origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1149 self.weapon_morph4angles = '0 0 0';
\r
1150 self.weapon_morph4time = time + t;
\r
1151 makevectors(self.weapon_morph4angles_x * '-1 0 0' + self.weapon_morph4angles_y * '0 1 0' + self.weapon_morph4angles_z * '0 0 1');
\r
1152 self.weapon_morph4origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1154 if (fr == WFRAME_FIRE1)
\r
1156 self.weapon_morph1angles = '5 0 0';
\r
1157 self.weapon_morph1time = time + t * 0.1;
\r
1158 makevectors(self.weapon_morph1angles_x * '-1 0 0' + self.weapon_morph1angles_y * '0 1 0' + self.weapon_morph1angles_z * '0 0 1');
\r
1159 self.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1160 self.weapon_morph4time = time + t + 1; // delay idle effect
\r
1162 else if (fr == WFRAME_FIRE2)
\r
1164 self.weapon_morph1angles = '10 0 0';
\r
1165 self.weapon_morph1time = time + t * 0.1;
\r
1166 makevectors(self.weapon_morph1angles_x * '-1 0 0' + self.weapon_morph1angles_y * '0 1 0' + self.weapon_morph1angles_z * '0 0 1');
\r
1167 self.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1168 self.weapon_morph4time = time + t + 1; // delay idle effect
\r
1170 else if (fr == WFRAME_RELOAD)
\r
1172 self.weapon_morph1time = time + t * 0.05;
\r
1173 self.weapon_morph1angles = '-10 40 0';
\r
1174 makevectors(self.weapon_morph1angles_x * '-1 0 0' + self.weapon_morph1angles_y * '0 1 0' + self.weapon_morph1angles_z * '0 0 1');
\r
1175 self.weapon_morph1origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1177 self.weapon_morph2time = time + t * 0.15;
\r
1178 self.weapon_morph2angles = '-10 40 5';
\r
1179 makevectors(self.weapon_morph2angles_x * '-1 0 0' + self.weapon_morph2angles_y * '0 1 0' + self.weapon_morph2angles_z * '0 0 1');
\r
1180 self.weapon_morph2origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1182 self.weapon_morph3time = time + t * 0.25;
\r
1183 self.weapon_morph3angles = '-10 40 0';
\r
1184 makevectors(self.weapon_morph3angles_x * '-1 0 0' + self.weapon_morph3angles_y * '0 1 0' + self.weapon_morph3angles_z * '0 0 1');
\r
1185 self.weapon_morph3origin = QCWEAPONANIMATION_ORIGIN(self.weaponentity);
\r
1191 if (fr == WFRAME_IDLE)
\r
1192 a = self.weaponentity.anim_idle;
\r
1193 else if (fr == WFRAME_FIRE1)
\r
1194 a = self.weaponentity.anim_fire1;
\r
1195 else if (fr == WFRAME_FIRE2)
\r
1196 a = self.weaponentity.anim_fire2;
\r
1197 else if (fr == WFRAME_RELOAD)
\r
1198 a = self.weaponentity.anim_reload;
\r
1199 a_z *= g_weaponratefactor;
\r
1200 setanim(self.weaponentity, a, restartanim == FALSE, restartanim, restartanim);
\r
1208 if(self.weapon_think == w_ready && func != w_ready && self.weaponentity.state == WS_RAISE)
\r
1210 backtrace("Tried to override initial weapon think function - should this really happen?");
\r
1213 t *= W_WeaponRateFactor();
\r
1215 // VorteX: haste can be added here
\r
1216 if (self.weapon_think == w_ready)
\r
1218 self.weapon_nextthink = time;
\r
1219 //dprint("started firing at ", ftos(time), "\n");
\r
1221 if (self.weapon_nextthink < time - self.weapon_frametime * 1.5 || self.weapon_nextthink > time + self.weapon_frametime * 1.5)
\r
1223 self.weapon_nextthink = time;
\r
1224 //dprint("reset weapon animation timer at ", ftos(time), "\n");
\r
1226 self.weapon_nextthink = self.weapon_nextthink + t;
\r
1227 self.weapon_think = func;
\r
1228 //dprint("next ", ftos(self.weapon_nextthink), "\n");
\r
1232 if (!self.crouch) // shoot anim stands up, this looks bad
\r
1234 local vector anim;
\r
1235 anim = self.anim_shoot;
\r
1236 anim_z = anim_y / (t + sys_frametime);
\r
1237 setanim(self, anim, FALSE, TRUE, TRUE);
\r
1241 void weapon_boblayer1(float spd, vector org)
\r
1243 // VorteX: haste can be added here
\r
1246 vector W_CalculateProjectileVelocity(vector pvelocity, vector mvelocity)
\r
1248 vector mdirection;
\r
1252 vector outvelocity;
\r
1254 mvelocity = mvelocity * g_weaponspeedfactor;
\r
1256 mdirection = normalize(mvelocity);
\r
1257 mspeed = vlen(mvelocity);
\r
1259 nstyle = cvar("g_projectiles_newton_style");
\r
1262 // absolute velocity
\r
1263 outvelocity = mvelocity;
\r
1265 else if(nstyle == 1)
\r
1267 // true Newtonian projectiles
\r
1268 outvelocity = pvelocity + mvelocity;
\r
1270 else if(nstyle == 2)
\r
1272 // true Newtonian projectiles with automatic aim adjustment
\r
1274 // solve: |outspeed * mdirection - pvelocity| = mspeed
\r
1275 // outspeed^2 - 2 * outspeed * (mdirection * pvelocity) + pvelocity^2 - mspeed^2 = 0
\r
1276 // outspeed = (mdirection * pvelocity) +- sqrt((mdirection * pvelocity)^2 - pvelocity^2 + mspeed^2)
\r
1280 // pvelocity^2 - (mdirection * pvelocity)^2 > mspeed^2
\r
1281 // velocity without mdirection component > mspeed
\r
1282 // fire at smallest possible mspeed that works?
\r
1283 // |(mdirection * pvelocity) * pvelocity - pvelocity| = mspeed
\r
1286 solution = solve_quadratic(1, -2 * (mdirection * pvelocity), pvelocity * pvelocity - mspeed * mspeed);
\r
1288 outspeed = solution_y; // the larger one
\r
1291 //outspeed = 0; // slowest possible shot
\r
1292 outspeed = solution_x; // the real part (that is, the average!)
\r
1293 //dprint("impossible shot, adjusting\n");
\r
1296 outspeed = bound(mspeed * cvar("g_projectiles_newton_style_2_minfactor"), outspeed, mspeed * cvar("g_projectiles_newton_style_2_maxfactor"));
\r
1297 outvelocity = mdirection * outspeed;
\r
1299 else if(nstyle == 3)
\r
1301 // pseudo-Newtonian:
\r
1302 outspeed = mspeed + mdirection * pvelocity;
\r
1303 outspeed = bound(mspeed * 0.7, outspeed, mspeed * 5.0);
\r
1304 outvelocity = mdirection * outspeed;
\r
1306 else if(nstyle == 4)
\r
1309 outspeed = mspeed + vlen(pvelocity);
\r
1310 outvelocity = mdirection * outspeed;
\r
1313 error("g_projectiles_newton_style must be 0 (absolute), 1 (Newtonian), 2 (Newtonian + aimfix), 3 (pseudo Newtonian) or 4 (tZorkian)!");
\r
1315 return outvelocity;
\r
1318 void W_AttachToShotorg(entity flash, vector offset)
\r
1321 flash.owner = self;
\r
1322 flash.angles_z = random() * 360;
\r
1323 if(qcweaponanimation)
\r
1325 setorigin(flash, w_shotorg + w_shotdir * 50);
\r
1326 flash.angles = vectoangles(w_shotdir);
\r
1327 flash.angles_z = random() * 360;
\r
1331 setattachment(flash, self.weaponentity, "shot");
\r
1332 setorigin(flash, offset);
\r
1335 copyentity(flash, xflash);
\r
1337 flash.viewmodelforclient = self;
\r
1339 if(self.weaponentity.oldorigin_x > 0)
\r
1341 setattachment(xflash, self.exteriorweaponentity, "");
\r
1342 setorigin(xflash, self.weaponentity.oldorigin + offset);
\r
1346 setattachment(xflash, self.exteriorweaponentity, "shot");
\r
1351 vector cliptoplane(vector v, vector p)
\r
1353 return v - (v * p) * p;
\r
1356 vector solve_cubic_pq(float p, float q)
\r
1359 D = q*q/4.0 + p*p*p/27.0;
\r
1363 a = 1.0/3.0 * acos(-q/2.0 * sqrt(-27.0/(p*p*p)));
\r
1364 u = sqrt(-4.0/3.0 * p);
\r
1365 // a in range 0..pi/3
\r
1372 '1 0 0' * cos(a + 2.0/3.0*M_PI)
\r
1374 '0 1 0' * cos(a + 4.0/3.0*M_PI)
\r
1387 return '1 1 0' * v + '0 0 1' * u;
\r
1389 return '0 1 1' * v + '1 0 0' * u;
\r
1394 u = cbrt(-q/2.0 + sqrt(D));
\r
1395 v = cbrt(-q/2.0 - sqrt(D));
\r
1396 return '1 1 1' * (u + v);
\r
1399 vector solve_cubic_abcd(float a, float b, float c, float d)
\r
1402 // x = (y - b) / 3a
\r
1405 p = (9*a*c - 3*b*b);
\r
1406 q = (27*a*a*d - 9*a*b*c + 2*b*b*b);
\r
1407 v = solve_cubic_pq(p, q);
\r
1408 v = (v - b * '1 1 1') * (1.0 / (3.0 * a));
\r
1410 v += '1 0 -1' * (v_z - v_x); // swap x, z
\r
1414 vector findperpendicular(vector v)
\r
1420 return normalize(cliptoplane(p, v));
\r
1423 vector W_CalculateProjectileSpread(vector forward, float spread)
\r
1429 spread *= g_weaponspreadfactor;
\r
1432 sstyle = cvar("g_projectiles_spread_style");
\r
1436 // this is the baseline for the spread value!
\r
1437 // standard deviation: sqrt(2/5)
\r
1438 // density function: sqrt(1-r^2)
\r
1439 return forward + randomvec() * spread;
\r
1441 else if(sstyle == 1)
\r
1443 // same thing, basically
\r
1444 return normalize(forward + cliptoplane(randomvec() * spread, forward));
\r
1446 else if(sstyle == 2)
\r
1448 // circle spread... has at sigma=1 a standard deviation of sqrt(1/2)
\r
1449 sigma = spread * 0.89442719099991587855; // match baseline stddev
\r
1450 v1 = findperpendicular(forward);
\r
1451 v2 = cross(forward, v1);
\r
1452 // random point on unit circle
\r
1453 dx = random() * 2 * M_PI;
\r
1456 // radius in our dist function
\r
1459 return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
\r
1461 else if(sstyle == 3) // gauss 3d
\r
1463 sigma = spread * 0.44721359549996; // match baseline stddev
\r
1464 // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
\r
1466 v1_x += gsl_ran_gaussian(sigma);
\r
1467 v1_y += gsl_ran_gaussian(sigma);
\r
1468 v1_z += gsl_ran_gaussian(sigma);
\r
1471 else if(sstyle == 4) // gauss 2d
\r
1473 sigma = spread * 0.44721359549996; // match baseline stddev
\r
1474 // note: 2D gaussian has sqrt(2) times the stddev of 1D, so this factor is right
\r
1475 v1_x = gsl_ran_gaussian(sigma);
\r
1476 v1_y = gsl_ran_gaussian(sigma);
\r
1477 v1_z = gsl_ran_gaussian(sigma);
\r
1478 return normalize(forward + cliptoplane(v1, forward));
\r
1480 else if(sstyle == 5) // 1-r
\r
1482 sigma = spread * 1.154700538379252; // match baseline stddev
\r
1483 v1 = findperpendicular(forward);
\r
1484 v2 = cross(forward, v1);
\r
1485 // random point on unit circle
\r
1486 dx = random() * 2 * M_PI;
\r
1489 // radius in our dist function
\r
1491 r = solve_cubic_abcd(-2, 3, 0, -r) * '0 1 0';
\r
1492 return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
\r
1494 else if(sstyle == 6) // 1-r^2
\r
1496 sigma = spread * 1.095445115010332; // match baseline stddev
\r
1497 v1 = findperpendicular(forward);
\r
1498 v2 = cross(forward, v1);
\r
1499 // random point on unit circle
\r
1500 dx = random() * 2 * M_PI;
\r
1503 // radius in our dist function
\r
1507 return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
\r
1509 else if(sstyle == 7) // (1-r) (2-r)
\r
1511 sigma = spread * 1.224744871391589; // match baseline stddev
\r
1512 v1 = findperpendicular(forward);
\r
1513 v2 = cross(forward, v1);
\r
1514 // random point on unit circle
\r
1515 dx = random() * 2 * M_PI;
\r
1518 // radius in our dist function
\r
1522 return normalize(forward + (v1 * dx + v2 * dy) * r * sigma);
\r
1525 error("g_projectiles_spread_style must be 0 (sphere), 1 (flattened sphere), 2 (circle), 3 (gauss 3D), 4 (gauss plane), 5 (linear falloff), 6 (quadratic falloff), 7 (stronger falloff)!");
\r
1528 * how to derive falloff functions:
\r
1529 * rho(r) := (2-r) * (1-r);
\r
1532 * rhor(r) := r * rho(r);
\r
1533 * cr(t) := integrate(rhor(r), r, a, t);
\r
1534 * scr(t) := integrate(rhor(r) * r^2, r, a, t);
\r
1535 * variance : scr(b) / cr(b);
\r
1536 * solve(cr(r) = rand * cr(b), r), programmmode:false;
\r
1537 * sqrt(0.4 / variance), numer;
\r
1542 float mspercallsum;
\r
1543 float mspercallsstyle;
\r
1544 float mspercallcount;
\r
1546 void W_SetupProjectileVelocityEx(entity missile, vector dir, vector upDir, float pSpeed, float pUpSpeed, float pZSpeed, float spread)
\r
1548 if(missile.owner == world)
\r
1549 error("Unowned missile");
\r
1551 dir = dir + upDir * (pUpSpeed / pSpeed);
\r
1552 dir_z += pZSpeed / pSpeed;
\r
1553 pSpeed *= vlen(dir);
\r
1554 dir = normalize(dir);
\r
1557 if(cvar("g_projectiles_spread_style") != mspercallsstyle)
\r
1559 mspercallsum = mspercallcount = 0;
\r
1560 mspercallsstyle = cvar("g_projectiles_spread_style");
\r
1562 mspercallsum -= gettime(GETTIME_HIRES);
\r
1564 dir = W_CalculateProjectileSpread(dir, spread);
\r
1566 mspercallsum += gettime(GETTIME_HIRES);
\r
1567 mspercallcount += 1;
\r
1568 print("avg: ", ftos(mspercallcount / mspercallsum), " per sec\n");
\r
1571 missile.velocity = W_CalculateProjectileVelocity(missile.owner.velocity, pSpeed * dir);
\r
1574 void W_SetupProjectileVelocity(entity missile, float pSpeed, float spread)
\r
1576 W_SetupProjectileVelocityEx(missile, w_shotdir, v_up, pSpeed, 0, 0, spread);
\r
1579 #define W_SETUPPROJECTILEVELOCITY_UP(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), cvar(#s "_speed_up"), cvar(#s "_speed_z"), cvar(#s "_spread"))
\r
1580 #define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"))
\r
1582 void W_DisplayDigitThink()
\r
1584 self.nextthink = time;
\r
1586 // the owner has switched to another weapon, remove the digits
\r
1587 if(self.weapon != self.owner.weapon)
\r
1589 self.nextthink = 0;
\r
1596 if(self.dmg) // exterior weapon
\r
1598 // keep the digit attached to the same bone as the gun
\r
1599 setattachment(self, self.owner, "bip01 r hand");
\r
1600 gun = self.owner.exteriorweaponentity;
\r
1602 else // view weapon
\r
1604 // keep the digit attached to the same bone as the gun
\r
1605 // TODO: Does this work with self-animated weapons too?
\r
1606 if(gettagindex(self.owner.weaponentity, "weapon"))
\r
1607 setattachment(self, self.owner.weaponentity, "weapon");
\r
1608 else if(gettagindex(self.owner.weaponentity, "tag_weapon"))
\r
1609 setattachment(self, self.owner.weaponentity, "tag_weapon");
\r
1610 gun = self.owner.weaponentity.weaponentity;
\r
1613 // copy all properties of the weapon to the digit
\r
1614 self.origin = gun.origin;
\r
1615 self.angles = gun.angles;
\r
1616 self.scale = gun.scale;
\r
1617 self.effects = gun.effects;
\r
1618 self.alpha = gun.alpha;
\r
1619 self.colormap = gun.colormap;
\r
1620 self.colormod = gun.colormod; // used by the regurgitating colors
\r
1621 self.glowmod = gun.glowmod;
\r
1624 if(self.team) // weapon load display
\r
1626 if(self.owner.weapon_load[self.owner.weapon] <= 0)
\r
1628 self.skin = 11; // unavailable digit
\r
1633 txt = ftos(floor(self.owner.weapon_load[self.owner.weapon]));
\r
1634 txt = substring(txt, self.cnt - 1, 1);
\r
1637 else // ammo display
\r
1639 txt = ftos(floor(self.owner.(self.owner.current_ammo)));
\r
1640 txt = substring(txt, self.cnt - 1, 1);
\r
1643 if((!txt || txt == ""))
\r
1644 self.skin = 10; // empty digit
\r
1646 self.skin = stof(txt);
\r
1649 void W_DisplayDigitSetup(entity own, float num, float load, float exterior)
\r
1653 digit.owner = own;
\r
1654 digit.weapon = own.weapon;
\r
1655 digit.dmg = exterior;
\r
1656 digit.team = load;
\r
1658 e = get_weaponinfo(digit.weapon);
\r
1662 // weapon load digit
\r
1663 setmodel(digit, strcat("models/weapons/v_", e.netname, "_digit1-", ftos(num) , ".md3"));
\r
1667 // ammo count digit
\r
1668 setmodel(digit, strcat("models/weapons/v_", e.netname, "_digit2-", ftos(num) , ".md3"));
\r
1670 digit.think = W_DisplayDigitThink;
\r
1671 digit.nextthink = time;
\r
1674 void W_Display(entity own, float load_num, float ammo_num)
\r
1677 for(i = 1; i <= load_num; i++)
\r
1679 W_DisplayDigitSetup(own, i, TRUE, FALSE); // weapon load digit, view model
\r
1680 W_DisplayDigitSetup(own, i, TRUE, TRUE); // weapon load digit, exterior model
\r
1682 for(i = 1; i <= ammo_num; i++)
\r
1684 W_DisplayDigitSetup(own, i, FALSE, FALSE); // ammo count digit, view model
\r
1685 W_DisplayDigitSetup(own, i, FALSE, TRUE); // ammo count digit, exterior model
\r
1689 void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload)
\r
1691 if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !ammo_reload)
\r
1694 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
\r
1697 self.clip_load -= ammo_use;
\r
1698 self.(weapon_load[self.weapon]) = self.clip_load;
\r
1701 self.(self.current_ammo) -= ammo_use;
\r
1704 // weapon reloading code
\r
1706 .float reload_ammo_amount, reload_ammo_min, reload_time;
\r
1707 .float reload_complain;
\r
1708 .string reload_sound;
\r
1710 void W_ReloadedAndReady()
\r
1712 // if we are inside the stomach, don't allow reloading, and schedule the weapon to reload once when we're out
\r
1713 if(self.stat_eaten)
\r
1715 self.clip_load = self.(weapon_load[self.weapon]) = -1;
\r
1716 w_ready(); // don't keep executing each frame
\r
1720 // finish the reloading process, and do the ammo transfer
\r
1722 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
\r
1724 // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
\r
1725 if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO)
\r
1726 self.clip_load = self.reload_ammo_amount;
\r
1729 while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo) >= 1) // make sure we don't add more ammo than we have
\r
1731 self.clip_load += 1;
\r
1732 self.(self.current_ammo) -= 1;
\r
1735 self.(weapon_load[self.weapon]) = self.clip_load;
\r
1737 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
\r
1738 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
\r
1739 // so your weapon is disabled for a few seconds without reason
\r
1741 //ATTACK_FINISHED(self) -= self.reload_time - 1;
\r
1746 void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound)
\r
1748 // if we are inside the stomach, don't allow reloading
\r
1749 if(self.stat_eaten)
\r
1752 // set global values to work with
\r
1753 self.reload_ammo_min = sent_ammo_min;
\r
1754 self.reload_ammo_amount = sent_ammo_amount;
\r
1755 self.reload_time = sent_time;
\r
1756 self.reload_sound = sent_sound;
\r
1758 // check if we meet the necessary conditions to reload
\r
1761 e = get_weaponinfo(self.weapon);
\r
1763 // don't reload weapons that don't have the RELOADABLE flag
\r
1764 if not(e.spawnflags & WEP_FLAG_RELOADABLE)
\r
1766 dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
\r
1769 // return if reloading is disabled for this weapon
\r
1770 if(!self.reload_ammo_amount)
\r
1772 // our weapon is fully loaded, no need to reload
\r
1773 if (self.clip_load >= self.reload_ammo_amount)
\r
1775 // no ammo, so nothing to load
\r
1776 if(self.(self.current_ammo) < 1 && self.reload_ammo_min)
\r
1777 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
\r
1779 if(clienttype(self) == CLIENTTYPE_REAL && self.reload_complain < time)
\r
1781 play2(self, "misc/unavailable.wav");
\r
1782 sprint(self, strcat("You don't have enough ammo to reload the ^2", W_Name(self.weapon), "\n"));
\r
1783 self.reload_complain = time + 1;
\r
1785 // switch away if the amount of ammo is not enough to keep using this weapon
\r
1786 // disabled since we only have one weapon in VT, so nothing else to switch to if we're out of ammo
\r
1787 /*if not(weapon_action(self.weapon, WR_CHECKAMMO1) + weapon_action(self.weapon, WR_CHECKAMMO2))
\r
1789 self.clip_load = -1; // reload later
\r
1790 W_SwitchToOtherWeapon(self);
\r
1795 if (self.weaponentity)
\r
1797 if (self.weaponentity.wframe == WFRAME_RELOAD)
\r
1800 // allow switching away while reloading, but this will cause a new reload!
\r
1801 self.weaponentity.state = WS_READY;
\r
1804 // now begin the reloading process
\r
1806 // weapon reload effects
\r
1807 if(self.weapon == WEP_GRABBER && self.clip_load >= 0) // only when we first begin reloading
\r
1810 org = self.origin + self.view_ofs + self.weaponentity.spawnorigin_x * v_forward - self.weaponentity.spawnorigin_y * v_right + self.weaponentity.spawnorigin_z * v_up;
\r
1811 SpawnCasing (org, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self);
\r
1812 pointparticles(particleeffectnum("grabber_reload"), org, '0 0 0', 1);
\r
1814 sound (self, CHAN_WEAPON2, self.reload_sound, VOL_BASE, ATTN_NORM);
\r
1816 // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
\r
1817 // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
\r
1818 // so your weapon is disabled for a few seconds without reason
\r
1820 //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
\r
1822 weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
\r
1824 if(self.clip_load < 0)
\r
1825 self.clip_load = 0;
\r
1826 self.old_clip_load = self.clip_load;
\r
1827 self.clip_load = self.(weapon_load[self.weapon]) = -1;
\r