3 /* WEP_##id */ SHOCKWAVE,
4 /* function */ W_Shockwave,
5 /* ammotype */ ammo_none,
7 /* flags */ WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_LOW,
9 /* color */ '0.5 0.25 0',
10 /* modelname */ "shotgun",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairshotgun 0.7",
13 /* wepimg */ "weaponshotgun",
14 /* refname */ "shockwave",
15 /* wepname */ _("Shockwave")
18 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
19 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, NONE, blast_animtime) \
21 w_cvar(id, sn, NONE, blast_damage) \
22 w_cvar(id, sn, NONE, blast_distance) \
23 w_cvar(id, sn, NONE, blast_edgedamage) \
24 w_cvar(id, sn, NONE, blast_force) \
25 w_cvar(id, sn, NONE, blast_force_forwardbias) \
26 w_cvar(id, sn, NONE, blast_force_zscale) \
27 w_cvar(id, sn, NONE, blast_jump_damage) \
28 w_cvar(id, sn, NONE, blast_jump_edgedamage) \
29 w_cvar(id, sn, NONE, blast_jump_force) \
30 w_cvar(id, sn, NONE, blast_jump_force_velocitybias) \
31 w_cvar(id, sn, NONE, blast_jump_force_zscale) \
32 w_cvar(id, sn, NONE, blast_jump_multiplier_accuracy) \
33 w_cvar(id, sn, NONE, blast_jump_multiplier_distance) \
34 w_cvar(id, sn, NONE, blast_jump_multiplier_min) \
35 w_cvar(id, sn, NONE, blast_jump_radius) \
36 w_cvar(id, sn, NONE, blast_multiplier_accuracy) \
37 w_cvar(id, sn, NONE, blast_multiplier_distance) \
38 w_cvar(id, sn, NONE, blast_multiplier_min) \
39 w_cvar(id, sn, NONE, blast_refire) \
40 w_cvar(id, sn, NONE, blast_splash_damage) \
41 w_cvar(id, sn, NONE, blast_splash_edgedamage) \
42 w_cvar(id, sn, NONE, blast_splash_force) \
43 w_cvar(id, sn, NONE, blast_splash_force_forwardbias) \
44 w_cvar(id, sn, NONE, blast_splash_multiplier_accuracy) \
45 w_cvar(id, sn, NONE, blast_splash_multiplier_distance) \
46 w_cvar(id, sn, NONE, blast_splash_multiplier_min) \
47 w_cvar(id, sn, NONE, blast_splash_radius) \
48 w_cvar(id, sn, NONE, blast_spread_max) \
49 w_cvar(id, sn, NONE, blast_spread_min) \
50 w_cvar(id, sn, NONE, melee_animtime) \
51 w_cvar(id, sn, NONE, melee_damage) \
52 w_cvar(id, sn, NONE, melee_delay) \
53 w_cvar(id, sn, NONE, melee_force) \
54 w_cvar(id, sn, NONE, melee_multihit) \
55 w_cvar(id, sn, NONE, melee_no_doubleslap) \
56 w_cvar(id, sn, NONE, melee_nonplayerdamage) \
57 w_cvar(id, sn, NONE, melee_range) \
58 w_cvar(id, sn, NONE, melee_refire) \
59 w_cvar(id, sn, NONE, melee_swing_side) \
60 w_cvar(id, sn, NONE, melee_swing_up) \
61 w_cvar(id, sn, NONE, melee_time) \
62 w_cvar(id, sn, NONE, melee_traces) \
63 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
64 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
65 w_prop(id, sn, string, weaponreplace, weaponreplace) \
66 w_prop(id, sn, float, weaponstart, weaponstart) \
67 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
68 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
71 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
75 void spawnfunc_weapon_shockwave(void)
77 //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
78 if(autocvar_sv_q3acompat_machineshotgunswap)
79 if(self.classname != "droppedweapon")
81 weapon_defaultspawnfunc(WEP_MACHINEGUN);
84 weapon_defaultspawnfunc(WEP_SHOCKWAVE);
87 #define MAX_SHOCKWAVE_HITS 10
88 #define DEBUG_SHOCKWAVE
91 .entity swing_alreadyhit;
92 .float shockwave_blasttime;
93 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
94 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
95 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
98 void W_Shockwave_Melee_Think(void)
101 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
102 entity target_victim;
105 // check to see if we can still continue, otherwise give up now
106 if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
112 // set start time of melee
116 W_PlayStrengthSound(self.realowner);
119 // update values for v_* vectors
120 makevectors(self.realowner.v_angle);
122 // calculate swing percentage based on time
123 meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
124 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
125 f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
127 // perform the traces needed for this frame
128 for(i=self.swing_prev; i < f; ++i)
130 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
132 targpos = (self.realowner.origin + self.realowner.view_ofs
133 + (v_forward * WEP_CVAR(shockwave, melee_range))
134 + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
135 + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
137 WarpZone_traceline_antilag(
139 (self.realowner.origin + self.realowner.view_ofs),
143 ANTILAG_LATENCY(self.realowner)
146 // draw lightning beams for debugging
147 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
148 te_customflash(targpos, 40, 2, '1 1 1');
150 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER));
152 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
153 && (trace_ent.takedamage == DAMAGE_AIM)
154 && (trace_ent != self.swing_alreadyhit)
155 && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
157 target_victim = trace_ent; // so it persists through other calls
159 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
160 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
162 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
164 // trigger damage with this calculated info
170 (WEP_SHOCKWAVE | HITTYPE_SECONDARY),
171 (self.realowner.origin + self.realowner.view_ofs),
172 (v_forward * WEP_CVAR(shockwave, melee_force))
176 if(accuracy_isgooddamage(self.realowner, target_victim))
177 { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
179 #ifdef DEBUG_SHOCKWAVE
181 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
182 self.realowner.netname,
183 target_victim.netname,
190 // allow multiple hits with one swing, but not against the same player twice
191 if(WEP_CVAR(shockwave, melee_multihit))
193 self.swing_alreadyhit = target_victim;
194 continue; // move along to next trace
204 if(time >= self.cnt + meleetime)
214 self.nextthink = time;
218 void W_Shockwave_Melee(void)
220 sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
221 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
225 meleetemp.owner = meleetemp.realowner = self;
226 meleetemp.think = W_Shockwave_Melee_Think;
227 meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
228 W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
231 // SHOCKWAVE ATTACK MODE
232 float W_Shockwave_Attack_CheckSpread(
234 vector nearest_on_line,
236 vector attack_endpos)
239 float distance_of_attack = vlen(sw_shotorg - attack_endpos);
240 float distance_from_line = vlen(targetorg - nearest_on_line);
242 spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
245 (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
247 (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
251 (spreadlimit && (distance_from_line <= spreadlimit))
253 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
255 { return bound(0, (distance_from_line / spreadlimit), 1); }
260 float W_Shockwave_Attack_IsVisible(
262 vector nearest_on_line,
264 vector attack_endpos)
266 vector nearest_to_attacker = head.WarpZone_findradius_nearest;
267 vector center = (head.origin + (head.mins + head.maxs) * 0.5);
271 // STEP ONE: Check if the nearest point is clear
272 if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
274 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
275 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
278 // STEP TWO: Check if shotorg to center point is clear
279 if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
281 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
282 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
285 // STEP THREE: Check each corner to see if they are clear
288 corner = get_corner_position(head, i);
289 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
291 WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
292 if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
299 float W_Shockwave_Attack_CheckHit(
305 if(!head) { return FALSE; }
308 for(i = 0; i <= queue; ++i)
310 if(shockwave_hit[i] == head)
312 if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
313 if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
318 shockwave_hit[queue] = head;
319 shockwave_hit_force[queue] = final_force;
320 shockwave_hit_damage[queue] = final_damage;
324 void W_Shockwave_Attack(void)
327 float multiplier, multiplier_from_accuracy, multiplier_from_distance;
329 vector final_force, center, vel;
334 // set up the shot direction
335 W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
336 vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
337 WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
338 vector attack_hitpos = trace_endpos;
339 float distance_to_end = vlen(w_shotorg - attack_endpos);
340 float distance_to_hit = vlen(w_shotorg - attack_hitpos);
341 //entity transform = WarpZone_trace_transform;
343 // do the firing effect now
344 //SendCSQCShockwaveParticle(attack_endpos); // WEAPONTODO
347 WEP_CVAR(shockwave, blast_splash_damage),
348 WEP_CVAR(shockwave, blast_splash_edgedamage),
349 WEP_CVAR(shockwave, blast_splash_radius),
350 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
356 // splash damage/jumping trace
357 head = WarpZone_FindRadius(
360 WEP_CVAR(shockwave, blast_splash_radius),
361 WEP_CVAR(shockwave, blast_jump_radius)
370 float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
372 if((head == self) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
374 // ========================
375 // BLAST JUMP CALCULATION
376 // ========================
378 // calculate importance of distance and accuracy for this attack
379 multiplier_from_accuracy = (1 -
381 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
386 multiplier_from_distance = (1 -
388 min(1, (distance_to_hit / distance_to_end))
395 WEP_CVAR(shockwave, blast_jump_multiplier_min),
397 (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
399 (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
403 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
406 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
408 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
411 // figure out the direction of force
412 vel = normalize(combine_to_vector(head.velocity_x, head.velocity_y, 0));
415 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
417 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
419 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
421 // now multiply the direction by force units
422 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
423 final_force_z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
425 // trigger damage with this calculated info
436 #ifdef DEBUG_SHOCKWAVE
438 "SELF HIT: multiplier = %f, damage = %f, force = %f... "
439 "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
443 multiplier_from_accuracy,
444 multiplier_from_distance
448 else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
450 // ==========================
451 // BLAST SPLASH CALCULATION
452 // ==========================
454 // calculate importance of distance and accuracy for this attack
455 multiplier_from_accuracy = (1 -
457 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
462 multiplier_from_distance = (1 -
464 min(1, (distance_to_hit / distance_to_end))
471 WEP_CVAR(shockwave, blast_splash_multiplier_min),
473 (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
475 (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
479 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
482 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
484 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
487 // figure out the direction of force
488 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
489 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
490 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
492 // now multiply the direction by force units
493 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
494 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
496 // queue damage with this calculated info
497 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
499 #ifdef DEBUG_SHOCKWAVE
501 "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
502 "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
506 multiplier_from_accuracy,
507 multiplier_from_distance
516 head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), FALSE);
519 if((head != self) && head.takedamage)
521 // ========================
522 // BLAST CONE CALCULATION
523 // ========================
525 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
526 center = CENTER_OR_VIEWOFS(head);
528 // find the closest point on the enemy to the center of the attack
529 float ang; // angle between shotdir and h
530 float h; // hypotenuse, which is the distance between attacker to head
531 float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
533 h = vlen(center - self.origin);
534 ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
536 // WEAPONTODO: replace with simpler method
538 vector nearest_on_line = (w_shotorg + a * w_shotdir);
539 vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
541 if((vlen(head.WarpZone_findradius_dist) <= WEP_CVAR(shockwave, blast_distance))
542 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
544 // calculate importance of distance and accuracy for this attack
545 multiplier_from_accuracy = (1 -
546 W_Shockwave_Attack_CheckSpread(
553 multiplier_from_distance = (1 -
555 min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
562 WEP_CVAR(shockwave, blast_multiplier_min),
564 (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
566 (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
570 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
573 (WEP_CVAR(shockwave, blast_damage) * multiplier)
575 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
578 // figure out the direction of force
579 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
580 final_force = normalize(center - (nearest_on_line - final_force));
581 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
583 // now multiply the direction by force units
584 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
585 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
587 // queue damage with this calculated info
588 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
590 #ifdef DEBUG_SHOCKWAVE
592 "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
593 "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
597 multiplier_from_accuracy,
598 multiplier_from_distance
606 for(i = 1; i <= queue; ++i)
608 head = shockwave_hit[i-1];
609 final_force = shockwave_hit_force[i-1];
610 final_damage = shockwave_hit_damage[i-1];
622 if(accuracy_isgooddamage(self.realowner, head))
625 accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, final_damage);
628 #ifdef DEBUG_SHOCKWAVE
630 "SHOCKWAVE by %s: damage = %f, force = %f.\n",
637 shockwave_hit[i-1] = world;
638 shockwave_hit_force[i-1] = '0 0 0';
639 shockwave_hit_damage[i-1] = 0;
643 float W_Shockwave(float req)
649 if(vlen(self.origin - self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
650 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE); }
652 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE); }
660 if(time >= self.shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
662 if(weapon_prepareattack(0, WEP_CVAR(shockwave, blast_animtime)))
664 W_Shockwave_Attack();
665 self.shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor();
666 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
670 else if(self.BUTTON_ATCK2)
672 //if(self.clip_load >= 0) // we are not currently reloading
673 if(!self.crouch) // no crouchmelee please
674 if(weapon_prepareattack(1, WEP_CVAR(shockwave, melee_refire)))
676 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
677 weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
685 precache_model("models/uziflash.md3");
686 precache_model("models/weapons/g_shockwave.md3");
687 precache_model("models/weapons/v_shockwave.md3");
688 precache_model("models/weapons/h_shockwave.iqm");
689 precache_sound("misc/itempickup.wav");
690 precache_sound("weapons/shockwave_fire.wav");
691 precache_sound("weapons/shockwave_melee.wav");
692 SHOCKWAVE_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
698 // shockwave has infinite ammo
703 SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
706 case WR_SUICIDEMESSAGE:
708 return WEAPON_THINKING_WITH_PORTALS;
712 if(w_deathtype & HITTYPE_SECONDARY)
713 return WEAPON_SHOCKWAVE_MURDER_SLAP;
715 return WEAPON_SHOCKWAVE_MURDER;
722 float W_Shockwave(float req)
726 case WR_IMPACTEFFECT:
729 org2 = w_org + w_backoff * 2;
730 pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1); // WEAPONTODO: replace with proper impact effect
735 //precache_sound("weapons/ric1.wav");
736 //precache_sound("weapons/ric2.wav");
737 //precache_sound("weapons/ric3.wav");
742 // no weapon specific image for this weapon