3 /* WEP_##id */ SHOCKWAVE,
4 /* function */ W_Shockwave,
5 /* ammotype */ IT_SHELLS,
7 /* flags */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_LOW,
10 /* netname */ "shockwave",
11 /* fullname */ _("Shockwave")
15 void spawnfunc_weapon_shockwave()
17 //if(autocvar_sv_q3acompat_machineshockwaveswap)
18 if(autocvar_sv_q3acompat_machineshotgunswap)
19 if(self.classname != "droppedweapon")
21 weapon_defaultspawnfunc(WEP_UZI);
24 weapon_defaultspawnfunc(WEP_SHOCKWAVE);
28 .entity swing_alreadyhit;
29 .float shockwave_pelletstime;
30 entity shockwave_hit[32];
31 float shockwave_hit_damage[32];
32 vector shockwave_hit_force[32];
34 // LEGACY ATTACK MODE: Scattered bullets
35 void W_Shockwave_Pellets(void)
47 ammoamount = autocvar_g_balance_shockwave_pellets_ammo;
48 bullets = autocvar_g_balance_shockwave_pellets_bullets;
49 d = autocvar_g_balance_shockwave_pellets_damage;
50 f = autocvar_g_balance_shockwave_pellets_force;
51 spread = autocvar_g_balance_shockwave_pellets_spread;
52 bulletspeed = autocvar_g_balance_shockwave_pellets_speed;
53 bulletconstant = autocvar_g_balance_shockwave_pellets_bulletconstant;
55 W_DecreaseAmmo(ammo_shells, ammoamount, autocvar_g_balance_shockwave_reload_ammo);
57 W_SetupShot (self, TRUE, 5, "weapons/shockwave_fire.wav", CH_WEAPON_A, d * bullets);
58 for (sc = 0;sc < bullets;sc = sc + 1)
59 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, f, WEP_SHOCKWAVE, 0, bulletconstant);
60 endFireBallisticBullet();
62 pointparticles(particleeffectnum("shockwave_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shockwave_pellets_ammo);
65 if (autocvar_g_casings >= 1)
66 for (sc = 0;sc < ammoamount;sc = sc + 1)
67 SpawnCasing (((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);
69 // muzzle flash for 1st person view
71 setmodel(flash, "models/uziflash.md3"); // precision set below
72 flash.think = SUB_Remove;
73 flash.nextthink = time + 0.06;
74 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
75 W_AttachToShotorg(flash, '5 0 0');
79 void W_Shockwave_Melee_Think()
82 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
86 if(!self.cnt) // set start time of melee
89 W_PlayStrengthSound(self.realowner);
92 makevectors(self.realowner.v_angle); // update values for v_* vectors
94 // calculate swing percentage based on time
95 meleetime = autocvar_g_balance_laser_melee_time * W_WeaponRateFactor();
96 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
97 f = ((1 - swing) * autocvar_g_balance_laser_melee_traces);
99 // check to see if we can still continue, otherwise give up now
100 if((self.realowner.deadflag != DEAD_NO) && autocvar_g_balance_laser_melee_no_doubleslap)
106 // if okay, perform the traces needed for this frame
107 for(i=self.swing_prev; i < f; ++i)
109 swing_factor = ((1 - (i / autocvar_g_balance_laser_melee_traces)) * 2 - 1);
111 targpos = (self.realowner.origin + self.realowner.view_ofs
112 + (v_forward * autocvar_g_balance_laser_melee_range)
113 + (v_up * swing_factor * autocvar_g_balance_laser_melee_swing_up)
114 + (v_right * swing_factor * autocvar_g_balance_laser_melee_swing_side));
116 WarpZone_traceline_antilag(self.realowner, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self.realowner, ANTILAG_LATENCY(self.realowner));
118 // draw lightning beams for debugging
119 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
120 te_customflash(targpos, 40, 2, '1 1 1');
122 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
124 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
125 && (trace_ent.takedamage == DAMAGE_AIM)
126 && (trace_ent != self.swing_alreadyhit)
127 && (is_player || autocvar_g_balance_laser_melee_nonplayerdamage))
129 target_victim = trace_ent; // so it persists through other calls
131 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
132 swing_damage = (autocvar_g_balance_laser_melee_damage * min(1, swing_factor + 1));
134 swing_damage = (autocvar_g_balance_laser_melee_nonplayerdamage * min(1, swing_factor + 1));
136 //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
138 Damage(target_victim, self.realowner, self.realowner,
139 swing_damage, WEP_SHOCKWAVE | HITTYPE_SECONDARY,
140 self.realowner.origin + self.realowner.view_ofs,
141 v_forward * autocvar_g_balance_laser_melee_force);
143 if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
145 if(autocvar_g_balance_laser_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
147 self.swing_alreadyhit = target_victim;
148 continue; // move along to next trace
158 if(time >= self.cnt + meleetime)
168 self.nextthink = time;
172 void W_Shockwave_Melee()
174 sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
175 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_melee_animtime, w_ready);
179 meleetemp.owner = meleetemp.realowner = self;
180 meleetemp.think = W_Shockwave_Melee_Think;
181 meleetemp.nextthink = time + autocvar_g_balance_shockwave_melee_delay * W_WeaponRateFactor();
182 W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shockwave_melee_damage, autocvar_g_balance_shockwave_melee_range);
185 // SHOCKWAVE ATTACK MODE
186 float W_Shockwave_Attack_CheckSpread(
188 vector nearest_on_line,
190 vector attack_endpos)
193 float distance_of_attack = vlen(sw_shotorg - attack_endpos);
194 float distance_from_line = vlen(targetorg - nearest_on_line);
196 spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
197 spreadlimit = (autocvar_g_balance_laser_shockwave_spread_min * (1 - spreadlimit) + autocvar_g_balance_laser_shockwave_spread_max * spreadlimit);
200 (spreadlimit && (distance_from_line <= spreadlimit))
202 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
204 { return bound(0, (distance_from_line / spreadlimit), 1); }
209 float W_Shockwave_Attack_IsVisible(
211 vector nearest_on_line,
213 vector attack_endpos)
215 vector nearest_to_attacker = head.WarpZone_findradius_nearest;
216 vector center = (head.origin + (head.mins + head.maxs) * 0.5);
220 // STEP ONE: Check if the nearest point is clear
221 if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
223 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
224 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
227 // STEP TWO: Check if shotorg to center point is clear
228 if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
230 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
231 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
234 // STEP THREE: Check each corner to see if they are clear
237 corner = get_corner_position(head, i);
238 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
240 WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
241 if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
248 float W_Shockwave_Attack_CheckHit(
254 if not(head) { return FALSE; }
259 for(i = 1; i <= queue; ++i)
261 if(shockwave_hit[i] == head)
263 if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
264 if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
269 shockwave_hit[queue] = head;
270 shockwave_hit_force[queue] = final_force;
271 shockwave_hit_damage[queue] = final_damage;
275 void W_Shockwave_Attack()
278 float multiplier, multiplier_from_accuracy, multiplier_from_distance;
279 float final_damage; //, final_spread;
280 vector final_force, center, vel;
285 // set up the shot direction
286 W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_shockwave_damage);
287 vector attack_endpos = (w_shotorg + (w_shotdir * autocvar_g_balance_laser_shockwave_distance));
288 WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
289 vector attack_hitpos = trace_endpos;
290 float distance_to_end = vlen(w_shotorg - attack_endpos);
291 float distance_to_hit = vlen(w_shotorg - attack_hitpos);
292 //entity transform = WarpZone_trace_transform;
294 // do the firing effect now
295 SendCSQCShockwaveParticle(attack_endpos);
296 Damage_DamageInfo(attack_hitpos, autocvar_g_balance_laser_shockwave_splash_damage, autocvar_g_balance_laser_shockwave_splash_edgedamage, autocvar_g_balance_laser_shockwave_splash_radius, w_shotdir * autocvar_g_balance_laser_shockwave_splash_force, WEP_SHOCKWAVE, 0, self);
298 // splash damage/jumping trace
299 head = WarpZone_FindRadius(attack_hitpos, max(autocvar_g_balance_laser_shockwave_splash_radius, autocvar_g_balance_laser_shockwave_jump_radius), FALSE);
306 center = PLAYER_CENTER(head);
308 float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
310 if((head == self) && (distance_to_head <= autocvar_g_balance_laser_shockwave_jump_radius))
312 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / autocvar_g_balance_laser_shockwave_jump_radius)) : 0));
313 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
314 multiplier = max(autocvar_g_balance_laser_shockwave_jump_multiplier_min, ((multiplier_from_accuracy * autocvar_g_balance_laser_shockwave_jump_multiplier_accuracy) + (multiplier_from_distance * autocvar_g_balance_laser_shockwave_jump_multiplier_distance)));
316 final_force = ((normalize(center - attack_hitpos) * autocvar_g_balance_laser_shockwave_jump_force) * multiplier);
317 vel = head.velocity; vel_z = 0;
318 vel = normalize(vel) * bound(0, vlen(vel) / autocvar_sv_maxspeed, 1) * autocvar_g_balance_laser_shockwave_jump_force_velocitybias;
319 final_force = (vlen(final_force) * normalize(normalize(final_force) + vel));
320 final_force_z *= autocvar_g_balance_laser_shockwave_jump_force_zscale;
321 final_damage = (autocvar_g_balance_laser_shockwave_jump_damage * multiplier + autocvar_g_balance_laser_shockwave_jump_edgedamage * (1 - multiplier));
323 Damage(head, self, self, final_damage, WEP_SHOCKWAVE, head.origin, final_force);
324 //print("SELF HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
326 else if (distance_to_head <= autocvar_g_balance_laser_shockwave_splash_radius)
328 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / autocvar_g_balance_laser_shockwave_splash_radius)) : 0));
329 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
330 multiplier = max(autocvar_g_balance_laser_shockwave_splash_multiplier_min, ((multiplier_from_accuracy * autocvar_g_balance_laser_shockwave_splash_multiplier_accuracy) + (multiplier_from_distance * autocvar_g_balance_laser_shockwave_splash_multiplier_distance)));
332 final_force = normalize(center - (attack_hitpos - (w_shotdir * autocvar_g_balance_laser_shockwave_splash_force_forwardbias)));
333 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
334 final_force = ((final_force * autocvar_g_balance_laser_shockwave_splash_force) * multiplier);
335 final_force_z *= autocvar_g_balance_laser_shockwave_force_zscale;
336 final_damage = (autocvar_g_balance_laser_shockwave_splash_damage * multiplier + autocvar_g_balance_laser_shockwave_splash_edgedamage * (1 - multiplier));
338 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
339 //print("SPLASH HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
346 head = WarpZone_FindRadius(w_shotorg, autocvar_g_balance_laser_shockwave_distance, FALSE);
351 if((head != self) && head.takedamage)
353 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
354 center = CENTER_OR_VIEWOFS(head);
356 // find the closest point on the enemy to the center of the attack
357 float ang; // angle between shotdir and h
358 float h; // hypotenuse, which is the distance between attacker to head
359 float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
361 h = vlen(center - self.origin);
362 ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
365 vector nearest_on_line = (w_shotorg + a * w_shotdir);
366 vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
367 float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // todo: use the findradius function for this
369 if((distance_to_target <= autocvar_g_balance_laser_shockwave_distance)
370 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
372 multiplier_from_accuracy = (1 - W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, w_shotorg, attack_endpos));
373 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_target / distance_to_end)) : 0));
374 multiplier = max(autocvar_g_balance_laser_shockwave_multiplier_min, ((multiplier_from_accuracy * autocvar_g_balance_laser_shockwave_multiplier_accuracy) + (multiplier_from_distance * autocvar_g_balance_laser_shockwave_multiplier_distance)));
376 final_force = normalize(center - (nearest_on_line - (w_shotdir * autocvar_g_balance_laser_shockwave_force_forwardbias)));
377 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
378 final_force = ((final_force * autocvar_g_balance_laser_shockwave_force) * multiplier);
379 final_force_z *= autocvar_g_balance_laser_shockwave_force_zscale;
380 final_damage = (autocvar_g_balance_laser_shockwave_damage * multiplier + autocvar_g_balance_laser_shockwave_edgedamage * (1 - multiplier));
382 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
383 //print("CONE HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
389 for(i = 1; i <= queue; ++i)
391 head = shockwave_hit[i];
392 final_force = shockwave_hit_force[i];
393 final_damage = shockwave_hit_damage[i];
395 Damage(head, self, self, final_damage, WEP_SHOCKWAVE, head.origin, final_force);
396 print("SHOCKWAVE by ", self.netname, ": damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force)), ".\n");
398 shockwave_hit[i] = world;
399 shockwave_hit_force[i] = '0 0 0';
400 shockwave_hit_damage[i] = 0;
402 //print("queue was ", ftos(queue), ".\n\n");
405 float W_Shockwave(float req)
407 float ammo_amount = 0;
414 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shockwave_secondary_melee_range)
415 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
417 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
419 if(autocvar_g_antilag_bullets)
420 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
422 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_shockwave_pellets_speed, 0, 0.001, FALSE);
429 if(autocvar_g_balance_shockwave_reload_ammo && self.clip_load < autocvar_g_balance_shockwave_pellets_ammo) // forced reload
431 // don't force reload an empty shockwave if its melee attack is active
432 if not(autocvar_g_balance_shockwave_secondary && self.ammo_shells < autocvar_g_balance_shockwave_pellets_ammo)
433 WEP_ACTION(self.weapon, WR_RELOAD);
437 if (self.BUTTON_ATCK)
439 if (time >= self.shockwave_pelletstime) // handle refire separately so the secondary can be fired straight after a primary
441 if(weapon_prepareattack(0, autocvar_g_balance_shockwave_pellets_animtime))
443 W_Shockwave_Attack();
444 self.shockwave_pelletstime = time + autocvar_g_balance_shockwave_pellets_refire * W_WeaponRateFactor();
445 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shockwave_pellets_animtime, w_ready);
450 if (self.clip_load >= 0) // we are not currently reloading
451 if (!self.crouch) // no crouchmelee please
452 if (self.BUTTON_ATCK2 && autocvar_g_balance_shockwave_secondary)
453 if (weapon_prepareattack(1, autocvar_g_balance_shockwave_secondary_refire))
455 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
456 weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
464 precache_model ("models/uziflash.md3");
465 precache_model ("models/weapons/g_shockwave.md3");
466 precache_model ("models/weapons/v_shockwave.md3");
467 precache_model ("models/weapons/h_shockwave.iqm");
468 precache_sound ("misc/itempickup.wav");
469 precache_sound ("weapons/shockwave_fire.wav");
470 precache_sound ("weapons/shockwave_melee.wav");
475 self.current_ammo = ammo_shells;
481 ammo_amount = self.ammo_shells >= autocvar_g_balance_shockwave_pellets_ammo;
482 ammo_amount += self.(weapon_load[WEP_SHOCKWAVE]) >= autocvar_g_balance_shockwave_pellets_ammo;*/
487 // melee attack is always available
492 //W_Reload(autocvar_g_balance_shockwave_pellets_ammo, "weapons/reload.wav");
495 case WR_SUICIDEMESSAGE:
497 return WEAPON_THINKING_WITH_PORTALS;
501 if(w_deathtype & HITTYPE_SECONDARY)
502 return WEAPON_SHOCKWAVE_MURDER_SLAP;
504 return WEAPON_SHOCKWAVE_MURDER;
512 float W_Shockwave(float req)
516 case WR_IMPACTEFFECT:
519 org2 = w_org + w_backoff * 2;
520 pointparticles(particleeffectnum("shockwave_impact"), org2, w_backoff * 1000, 1);
521 if(!w_issilent && time - self.prevric > 0.25)
523 if(w_random < 0.0165)
524 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
525 else if(w_random < 0.033)
526 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
527 else if(w_random < 0.05)
528 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
535 precache_sound("weapons/ric1.wav");
536 precache_sound("weapons/ric2.wav");
537 precache_sound("weapons/ric3.wav");