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(self.classname != "droppedweapon")
20 weapon_defaultspawnfunc(WEP_UZI);
23 weapon_defaultspawnfunc(WEP_SHOCKWAVE);
26 .entity swing_alreadyhit;
27 .float shockwave_pelletstime;
28 entity shockwave_hit[32];
29 float shockwave_hit_damage[32];
30 vector shockwave_hit_force[32];
32 // LEGACY ATTACK MODE: Scattered bullets
33 void W_Shockwave_Pellets(void)
45 ammoamount = autocvar_g_balance_shockwave_pellets_ammo;
46 bullets = autocvar_g_balance_shockwave_pellets_bullets;
47 d = autocvar_g_balance_shockwave_pellets_damage;
48 f = autocvar_g_balance_shockwave_pellets_force;
49 spread = autocvar_g_balance_shockwave_pellets_spread;
50 bulletspeed = autocvar_g_balance_shockwave_pellets_speed;
51 bulletconstant = autocvar_g_balance_shockwave_pellets_bulletconstant;
53 W_DecreaseAmmo(ammo_shells, ammoamount, autocvar_g_balance_shockwave_reload_ammo);
55 W_SetupShot (self, autocvar_g_antilag_bullets && bulletspeed >= autocvar_g_antilag_bullets, 5, "weapons/shockwave_fire.wav", CH_WEAPON_A, d * bullets);
56 for (sc = 0;sc < bullets;sc = sc + 1)
57 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, f, WEP_SHOCKWAVE, 0, 1, bulletconstant);
58 endFireBallisticBullet();
60 pointparticles(particleeffectnum("shockwave_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shockwave_pellets_ammo);
63 if (autocvar_g_casings >= 1)
64 for (sc = 0;sc < ammoamount;sc = sc + 1)
65 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);
67 // muzzle flash for 1st person view
69 setmodel(flash, "models/uziflash.md3"); // precision set below
70 flash.think = SUB_Remove;
71 flash.nextthink = time + 0.06;
72 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
73 W_AttachToShotorg(flash, '5 0 0');
77 void W_Shockwave_Melee_Think()
80 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
84 if(!self.cnt) // set start time of melee
87 W_PlayStrengthSound(self.realowner);
90 makevectors(self.realowner.v_angle); // update values for v_* vectors
92 // calculate swing percentage based on time
93 meleetime = autocvar_g_balance_laser_melee_time * W_WeaponRateFactor();
94 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
95 f = ((1 - swing) * autocvar_g_balance_laser_melee_traces);
97 // check to see if we can still continue, otherwise give up now
98 if((self.realowner.deadflag != DEAD_NO) && autocvar_g_balance_laser_melee_no_doubleslap)
104 // if okay, perform the traces needed for this frame
105 for(i=self.swing_prev; i < f; ++i)
107 swing_factor = ((1 - (i / autocvar_g_balance_laser_melee_traces)) * 2 - 1);
109 targpos = (self.realowner.origin + self.realowner.view_ofs
110 + (v_forward * autocvar_g_balance_laser_melee_range)
111 + (v_up * swing_factor * autocvar_g_balance_laser_melee_swing_up)
112 + (v_right * swing_factor * autocvar_g_balance_laser_melee_swing_side));
114 WarpZone_traceline_antilag(self.realowner, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self.realowner, ANTILAG_LATENCY(self.realowner));
116 // draw lightning beams for debugging
117 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
118 te_customflash(targpos, 40, 2, '1 1 1');
120 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
122 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
123 && (trace_ent.takedamage == DAMAGE_AIM)
124 && (trace_ent != self.swing_alreadyhit)
125 && (is_player || autocvar_g_balance_laser_melee_nonplayerdamage))
127 target_victim = trace_ent; // so it persists through other calls
129 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
130 swing_damage = (autocvar_g_balance_laser_melee_damage * min(1, swing_factor + 1));
132 swing_damage = (autocvar_g_balance_laser_melee_nonplayerdamage * min(1, swing_factor + 1));
134 //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
136 Damage(target_victim, self.realowner, self.realowner,
137 swing_damage, WEP_SHOCKWAVE | HITTYPE_SECONDARY,
138 self.realowner.origin + self.realowner.view_ofs,
139 v_forward * autocvar_g_balance_laser_melee_force);
141 if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
143 if(autocvar_g_balance_laser_melee_multihit) // allow multiple hits with one swing, but not against the same player twice.
145 self.swing_alreadyhit = target_victim;
146 continue; // move along to next trace
156 if(time >= self.cnt + meleetime)
166 self.nextthink = time;
170 void W_Shockwave_Melee()
172 sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
173 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_laser_melee_animtime, w_ready);
177 meleetemp.owner = meleetemp.realowner = self;
178 meleetemp.think = W_Shockwave_Melee_Think;
179 meleetemp.nextthink = time + autocvar_g_balance_shockwave_melee_delay * W_WeaponRateFactor();
180 W_SetupShot_Range(self, TRUE, 0, "", 0, autocvar_g_balance_shockwave_melee_damage, autocvar_g_balance_shockwave_melee_range);
183 // SHOCKWAVE ATTACK MODE
184 float W_Shockwave_Attack_CheckSpread(
186 vector nearest_on_line,
188 vector attack_endpos)
191 float distance_of_attack = vlen(sw_shotorg - attack_endpos);
192 float distance_from_line = vlen(targetorg - nearest_on_line);
194 spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
195 spreadlimit = (autocvar_g_balance_laser_shockwave_spread_min * (1 - spreadlimit) + autocvar_g_balance_laser_shockwave_spread_max * spreadlimit);
198 (spreadlimit && (distance_from_line <= spreadlimit))
200 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
202 { return bound(0, (distance_from_line / spreadlimit), 1); }
207 float W_Shockwave_Attack_IsVisible(
209 vector nearest_on_line,
211 vector attack_endpos)
213 vector nearest_to_attacker = head.WarpZone_findradius_nearest;
214 vector center = (head.origin + (head.mins + head.maxs) * 0.5);
218 // STEP ONE: Check if the nearest point is clear
219 if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
221 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
222 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
225 // STEP TWO: Check if shotorg to center point is clear
226 if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
228 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
229 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
232 // STEP THREE: Check each corner to see if they are clear
235 corner = get_corner_position(head, i);
236 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
238 WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
239 if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
246 float W_Shockwave_Attack_CheckHit(
252 if not(head) { return FALSE; }
257 for(i = 1; i <= queue; ++i)
259 if(shockwave_hit[i] == head)
261 if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
262 if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
267 shockwave_hit[queue] = head;
268 shockwave_hit_force[queue] = final_force;
269 shockwave_hit_damage[queue] = final_damage;
273 void W_Shockwave_Attack()
276 float multiplier, multiplier_from_accuracy, multiplier_from_distance;
277 float final_damage; //, final_spread;
278 vector final_force, center, vel;
283 // set up the shot direction
284 W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, autocvar_g_balance_laser_shockwave_damage);
285 vector attack_endpos = (w_shotorg + (w_shotdir * autocvar_g_balance_laser_shockwave_distance));
286 WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
287 vector attack_hitpos = trace_endpos;
288 float distance_to_end = vlen(w_shotorg - attack_endpos);
289 float distance_to_hit = vlen(w_shotorg - attack_hitpos);
290 //entity transform = WarpZone_trace_transform;
292 // do the firing effect now
293 SendCSQCShockwaveParticle(attack_endpos);
294 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);
296 // splash damage/jumping trace
297 head = WarpZone_FindRadius(attack_hitpos, max(autocvar_g_balance_laser_shockwave_splash_radius, autocvar_g_balance_laser_shockwave_jump_radius), FALSE);
304 center = PLAYER_CENTER(head);
306 float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
308 if((head == self) && (distance_to_head <= autocvar_g_balance_laser_shockwave_jump_radius))
310 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / autocvar_g_balance_laser_shockwave_jump_radius)) : 0));
311 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
312 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)));
314 final_force = ((normalize(center - attack_hitpos) * autocvar_g_balance_laser_shockwave_jump_force) * multiplier);
315 vel = head.velocity; vel_z = 0;
316 vel = normalize(vel) * bound(0, vlen(vel) / autocvar_sv_maxspeed, 1) * autocvar_g_balance_laser_shockwave_jump_force_velocitybias;
317 final_force = (vlen(final_force) * normalize(normalize(final_force) + vel));
318 final_force_z *= autocvar_g_balance_laser_shockwave_jump_force_zscale;
319 final_damage = (autocvar_g_balance_laser_shockwave_jump_damage * multiplier + autocvar_g_balance_laser_shockwave_jump_edgedamage * (1 - multiplier));
321 Damage(head, self, self, final_damage, WEP_SHOCKWAVE, head.origin, final_force);
322 //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");
324 else if (distance_to_head <= autocvar_g_balance_laser_shockwave_splash_radius)
326 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / autocvar_g_balance_laser_shockwave_splash_radius)) : 0));
327 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
328 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)));
330 final_force = normalize(center - (attack_hitpos - (w_shotdir * autocvar_g_balance_laser_shockwave_splash_force_forwardbias)));
331 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
332 final_force = ((final_force * autocvar_g_balance_laser_shockwave_splash_force) * multiplier);
333 final_force_z *= autocvar_g_balance_laser_shockwave_force_zscale;
334 final_damage = (autocvar_g_balance_laser_shockwave_splash_damage * multiplier + autocvar_g_balance_laser_shockwave_splash_edgedamage * (1 - multiplier));
336 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
337 //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");
344 head = WarpZone_FindRadius(w_shotorg, autocvar_g_balance_laser_shockwave_distance, FALSE);
349 if((head != self) && head.takedamage)
351 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
352 center = CENTER_OR_VIEWOFS(head);
354 // find the closest point on the enemy to the center of the attack
355 float ang; // angle between shotdir and h
356 float h; // hypotenuse, which is the distance between attacker to head
357 float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
359 h = vlen(center - self.origin);
360 ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
363 vector nearest_on_line = (w_shotorg + a * w_shotdir);
364 vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
365 float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // todo: use the findradius function for this
367 if((distance_to_target <= autocvar_g_balance_laser_shockwave_distance)
368 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
370 multiplier_from_accuracy = (1 - W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, w_shotorg, attack_endpos));
371 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_target / distance_to_end)) : 0));
372 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)));
374 final_force = normalize(center - (nearest_on_line - (w_shotdir * autocvar_g_balance_laser_shockwave_force_forwardbias)));
375 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
376 final_force = ((final_force * autocvar_g_balance_laser_shockwave_force) * multiplier);
377 final_force_z *= autocvar_g_balance_laser_shockwave_force_zscale;
378 final_damage = (autocvar_g_balance_laser_shockwave_damage * multiplier + autocvar_g_balance_laser_shockwave_edgedamage * (1 - multiplier));
380 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
381 //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");
387 for(i = 1; i <= queue; ++i)
389 head = shockwave_hit[i];
390 final_force = shockwave_hit_force[i];
391 final_damage = shockwave_hit_damage[i];
393 Damage(head, self, self, final_damage, WEP_SHOCKWAVE, head.origin, final_force);
394 print("SHOCKWAVE by ", self.netname, ": damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force)), ".\n");
396 shockwave_hit[i] = world;
397 shockwave_hit_force[i] = '0 0 0';
398 shockwave_hit_damage[i] = 0;
400 //print("queue was ", ftos(queue), ".\n\n");
403 float W_Shockwave(float req)
411 if(vlen(self.origin-self.enemy.origin) <= autocvar_g_balance_shockwave_secondary_melee_range)
412 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
415 if(autocvar_g_antilag_bullets)
416 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
418 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_shockwave_pellets_speed, 0, 0.001, FALSE);
425 if(autocvar_g_balance_shockwave_reload_ammo && self.clip_load < autocvar_g_balance_shockwave_pellets_ammo) // forced reload
427 // don't force reload an empty shockwave if its melee attack is active
428 if not(autocvar_g_balance_shockwave_secondary && self.ammo_shells < autocvar_g_balance_shockwave_pellets_ammo)
429 WEP_ACTION(self.weapon, WR_RELOAD);
433 if (self.BUTTON_ATCK)
435 if (time >= self.shockwave_pelletstime) // handle refire separately so the secondary can be fired straight after a primary
437 if(weapon_prepareattack(0, autocvar_g_balance_shockwave_pellets_animtime))
439 W_Shockwave_Attack();
440 self.shockwave_pelletstime = time + autocvar_g_balance_shockwave_pellets_refire * W_WeaponRateFactor();
441 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shockwave_pellets_animtime, w_ready);
446 if (self.clip_load >= 0) // we are not currently reloading
447 if (!self.crouch) // no crouchmelee please
448 if (self.BUTTON_ATCK2 && autocvar_g_balance_shockwave_secondary)
449 if (weapon_prepareattack(1, autocvar_g_balance_shockwave_secondary_refire))
451 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
452 weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
459 precache_model ("models/uziflash.md3");
460 precache_model ("models/weapons/g_shockwave.md3");
461 precache_model ("models/weapons/v_shockwave.md3");
462 precache_model ("models/weapons/h_shockwave.iqm");
463 precache_sound ("misc/itempickup.wav");
464 precache_sound ("weapons/shockwave_fire.wav");
465 precache_sound ("weapons/shockwave_melee.wav");
470 self.current_ammo = ammo_shells;
475 ammo_amount = self.ammo_shells >= autocvar_g_balance_shockwave_pellets_ammo;
476 ammo_amount += self.(weapon_load[WEP_SHOCKWAVE]) >= autocvar_g_balance_shockwave_pellets_ammo;
481 // melee attack is always available
486 W_Reload(autocvar_g_balance_shockwave_pellets_ammo, "weapons/reload.wav");
489 case WR_SUICIDEMESSAGE:
491 return WEAPON_THINKING_WITH_PORTALS;
495 if(w_deathtype & HITTYPE_SECONDARY)
496 return WEAPON_SHOCKWAVE_MURDER_SLAP;
498 return WEAPON_SHOCKWAVE_MURDER;
506 float W_Shockwave(float req)
510 case WR_IMPACTEFFECT:
513 org2 = w_org + w_backoff * 2;
514 pointparticles(particleeffectnum("shockwave_impact"), org2, w_backoff * 1000, 1);
515 if(!w_issilent && time - self.prevric > 0.25)
517 if(w_random < 0.0165)
518 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
519 else if(w_random < 0.033)
520 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
521 else if(w_random < 0.05)
522 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
529 precache_sound("weapons/ric1.wav");
530 precache_sound("weapons/ric2.wav");
531 precache_sound("weapons/ric3.wav");