2 CLASS(Shockwave, Weapon)
3 /* ammotype */ //ATTRIB(Shockwave, ammo_field, .int, ammo_none)
4 /* impulse */ ATTRIB(Shockwave, impulse, int, 2)
5 /* flags */ ATTRIB(Shockwave, spawnflags, int, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN | WEP_FLAG_CANCLIMB | WEP_FLAG_MUTATORBLOCKED);
6 /* rating */ ATTRIB(Shockwave, bot_pickupbasevalue, float, BOT_PICKUP_RATING_LOW);
7 /* color */ ATTRIB(Shockwave, wpcolor, vector, '0.5 0.25 0');
8 /* modelname */ ATTRIB(Shockwave, mdl, string, "shotgun");
10 /* model */ ATTRIB(Shockwave, m_model, Model, MDL_SHOCKWAVE_ITEM);
12 /* crosshair */ ATTRIB(Shockwave, w_crosshair, string, "gfx/crosshairshotgun");
13 /* crosshair */ ATTRIB(Shockwave, w_crosshair_size, float, 0.7);
14 /* wepimg */ ATTRIB(Shockwave, model2, string, "weaponshotgun");
15 /* refname */ ATTRIB(Shockwave, netname, string, "shockwave");
16 /* wepname */ ATTRIB(Shockwave, m_name, string, _("Shockwave"));
18 REGISTER_WEAPON(SHOCKWAVE, NEW(Shockwave));
20 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
21 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, NONE, blast_animtime) \
23 w_cvar(id, sn, NONE, blast_damage) \
24 w_cvar(id, sn, NONE, blast_distance) \
25 w_cvar(id, sn, NONE, blast_edgedamage) \
26 w_cvar(id, sn, NONE, blast_force) \
27 w_cvar(id, sn, NONE, blast_force_forwardbias) \
28 w_cvar(id, sn, NONE, blast_force_zscale) \
29 w_cvar(id, sn, NONE, blast_jump_damage) \
30 w_cvar(id, sn, NONE, blast_jump_edgedamage) \
31 w_cvar(id, sn, NONE, blast_jump_force) \
32 w_cvar(id, sn, NONE, blast_jump_force_velocitybias) \
33 w_cvar(id, sn, NONE, blast_jump_force_zscale) \
34 w_cvar(id, sn, NONE, blast_jump_multiplier_accuracy) \
35 w_cvar(id, sn, NONE, blast_jump_multiplier_distance) \
36 w_cvar(id, sn, NONE, blast_jump_multiplier_min) \
37 w_cvar(id, sn, NONE, blast_jump_radius) \
38 w_cvar(id, sn, NONE, blast_multiplier_accuracy) \
39 w_cvar(id, sn, NONE, blast_multiplier_distance) \
40 w_cvar(id, sn, NONE, blast_multiplier_min) \
41 w_cvar(id, sn, NONE, blast_refire) \
42 w_cvar(id, sn, NONE, blast_splash_damage) \
43 w_cvar(id, sn, NONE, blast_splash_edgedamage) \
44 w_cvar(id, sn, NONE, blast_splash_force) \
45 w_cvar(id, sn, NONE, blast_splash_force_forwardbias) \
46 w_cvar(id, sn, NONE, blast_splash_multiplier_accuracy) \
47 w_cvar(id, sn, NONE, blast_splash_multiplier_distance) \
48 w_cvar(id, sn, NONE, blast_splash_multiplier_min) \
49 w_cvar(id, sn, NONE, blast_splash_radius) \
50 w_cvar(id, sn, NONE, blast_spread_max) \
51 w_cvar(id, sn, NONE, blast_spread_min) \
52 w_cvar(id, sn, NONE, melee_animtime) \
53 w_cvar(id, sn, NONE, melee_damage) \
54 w_cvar(id, sn, NONE, melee_delay) \
55 w_cvar(id, sn, NONE, melee_force) \
56 w_cvar(id, sn, NONE, melee_multihit) \
57 w_cvar(id, sn, NONE, melee_no_doubleslap) \
58 w_cvar(id, sn, NONE, melee_nonplayerdamage) \
59 w_cvar(id, sn, NONE, melee_range) \
60 w_cvar(id, sn, NONE, melee_refire) \
61 w_cvar(id, sn, NONE, melee_swing_side) \
62 w_cvar(id, sn, NONE, melee_swing_up) \
63 w_cvar(id, sn, NONE, melee_time) \
64 w_cvar(id, sn, NONE, melee_traces) \
65 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
66 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
67 w_prop(id, sn, string, weaponreplace, weaponreplace) \
68 w_prop(id, sn, float, weaponstart, weaponstart) \
69 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
70 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
73 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
76 void Net_ReadShockwaveParticle();
87 REGISTER_NET_TEMP(TE_CSQC_SHOCKWAVEPARTICLE)
90 spawnfunc(weapon_shockwave)
92 //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
93 if(autocvar_sv_q3acompat_machineshotgunswap)
94 if(self.classname != "droppedweapon")
96 weapon_defaultspawnfunc(this, WEP_MACHINEGUN);
99 weapon_defaultspawnfunc(this, WEP_SHOCKWAVE);
102 const float MAX_SHOCKWAVE_HITS = 10;
103 //#define DEBUG_SHOCKWAVE
106 .entity swing_alreadyhit;
107 .float shockwave_blasttime;
108 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
109 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
110 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
113 void W_Shockwave_Melee_Think()
116 float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
117 entity target_victim;
120 // check to see if we can still continue, otherwise give up now
121 if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
127 // set start time of melee
131 W_PlayStrengthSound(self.realowner);
134 // update values for v_* vectors
135 makevectors(self.realowner.v_angle);
137 // calculate swing percentage based on time
138 meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
139 swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
140 f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
142 // perform the traces needed for this frame
143 for(i=self.swing_prev; i < f; ++i)
145 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
147 targpos = (self.realowner.origin + self.realowner.view_ofs
148 + (v_forward * WEP_CVAR(shockwave, melee_range))
149 + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
150 + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
152 WarpZone_traceline_antilag(
154 (self.realowner.origin + self.realowner.view_ofs),
158 ANTILAG_LATENCY(self.realowner)
161 // draw lightning beams for debugging
162 #ifdef DEBUG_SHOCKWAVE
163 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
164 te_customflash(targpos, 40, 2, '1 1 1');
167 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
169 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
170 && (trace_ent.takedamage == DAMAGE_AIM)
171 && (trace_ent != self.swing_alreadyhit)
172 && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
174 target_victim = trace_ent; // so it persists through other calls
176 if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
177 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
179 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
181 // trigger damage with this calculated info
187 (WEP_SHOCKWAVE.m_id | HITTYPE_SECONDARY),
188 (self.realowner.origin + self.realowner.view_ofs),
189 (v_forward * WEP_CVAR(shockwave, melee_force))
193 if(accuracy_isgooddamage(self.realowner, target_victim))
194 { accuracy_add(self.realowner, WEP_SHOCKWAVE.m_id, 0, swing_damage); }
196 #ifdef DEBUG_SHOCKWAVE
198 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
199 self.realowner.netname,
200 target_victim.netname,
207 // allow multiple hits with one swing, but not against the same player twice
208 if(WEP_CVAR(shockwave, melee_multihit))
210 self.swing_alreadyhit = target_victim;
211 continue; // move along to next trace
221 if(time >= self.cnt + meleetime)
231 self.nextthink = time;
235 void W_Shockwave_Melee(Weapon thiswep, entity actor, .entity weaponentity, int fire)
237 sound(actor, CH_WEAPON_A, SND_SHOTGUN_MELEE, VOL_BASE, ATTN_NORM);
238 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
240 entity meleetemp = new(meleetemp);
241 make_pure(meleetemp);
242 meleetemp.owner = meleetemp.realowner = actor;
243 meleetemp.think = W_Shockwave_Melee_Think;
244 meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
245 W_SetupShot_Range(actor, true, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
248 // SHOCKWAVE ATTACK MODE
249 float W_Shockwave_Attack_CheckSpread(
251 vector nearest_on_line,
253 vector attack_endpos)
256 float distance_of_attack = vlen(sw_shotorg - attack_endpos);
257 float distance_from_line = vlen(targetorg - nearest_on_line);
259 spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
262 (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
264 (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
268 (spreadlimit && (distance_from_line <= spreadlimit))
270 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
272 { return bound(0, (distance_from_line / spreadlimit), 1); }
277 float W_Shockwave_Attack_IsVisible(
279 vector nearest_on_line,
281 vector attack_endpos)
283 vector nearest_to_attacker = head.WarpZone_findradius_nearest;
284 vector center = (head.origin + (head.mins + head.maxs) * 0.5);
288 // STEP ONE: Check if the nearest point is clear
289 if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
291 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
292 if(trace_fraction == 1) { return true; } // yes, the nearest point is clear and we can allow the damage
295 // STEP TWO: Check if shotorg to center point is clear
296 if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
298 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
299 if(trace_fraction == 1) { return true; } // yes, the center point is clear and we can allow the damage
302 // STEP THREE: Check each corner to see if they are clear
305 corner = get_corner_position(head, i);
306 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
308 WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
309 if(trace_fraction == 1) { return true; } // yes, this corner is clear and we can allow the damage
316 float W_Shockwave_Attack_CheckHit(
322 if(!head) { return false; }
325 for(i = 0; i <= queue; ++i)
327 if(shockwave_hit[i] == head)
329 if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
330 if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
335 shockwave_hit[queue] = head;
336 shockwave_hit_force[queue] = final_force;
337 shockwave_hit_damage[queue] = final_damage;
341 void W_Shockwave_Send()
343 WriteHeader(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
344 WriteCoord(MSG_BROADCAST, w_shotorg.x);
345 WriteCoord(MSG_BROADCAST, w_shotorg.y);
346 WriteCoord(MSG_BROADCAST, w_shotorg.z);
347 WriteCoord(MSG_BROADCAST, w_shotdir.x);
348 WriteCoord(MSG_BROADCAST, w_shotdir.y);
349 WriteCoord(MSG_BROADCAST, w_shotdir.z);
350 WriteShort(MSG_BROADCAST, WEP_CVAR(shockwave, blast_distance));
351 WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_max), 255));
352 WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_min), 255));
353 WriteByte(MSG_BROADCAST, num_for_edict(self));
356 void W_Shockwave_Attack()
359 float multiplier, multiplier_from_accuracy, multiplier_from_distance;
361 vector final_force, center, vel;
366 // set up the shot direction
367 W_SetupShot(self, false, 3, SND(LASERGUN_FIRE), CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
368 vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
369 WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
370 vector attack_hitpos = trace_endpos;
371 float distance_to_end = vlen(w_shotorg - attack_endpos);
372 float distance_to_hit = vlen(w_shotorg - attack_hitpos);
373 //entity transform = WarpZone_trace_transform;
375 // do the firing effect now
379 WEP_CVAR(shockwave, blast_splash_damage),
380 WEP_CVAR(shockwave, blast_splash_edgedamage),
381 WEP_CVAR(shockwave, blast_splash_radius),
382 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
388 // splash damage/jumping trace
389 head = WarpZone_FindRadius(
392 WEP_CVAR(shockwave, blast_splash_radius),
393 WEP_CVAR(shockwave, blast_jump_radius)
402 float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
404 if((head == self) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
406 // ========================
407 // BLAST JUMP CALCULATION
408 // ========================
410 // calculate importance of distance and accuracy for this attack
411 multiplier_from_accuracy = (1 -
413 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
418 multiplier_from_distance = (1 -
420 min(1, (distance_to_hit / distance_to_end))
427 WEP_CVAR(shockwave, blast_jump_multiplier_min),
429 (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
431 (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
435 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
438 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
440 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
443 // figure out the direction of force
444 vel = normalize(vec3(head.velocity.x, head.velocity.y, 0));
447 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
449 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
451 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
453 // now multiply the direction by force units
454 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
455 final_force.z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
457 // trigger damage with this calculated info
468 #ifdef DEBUG_SHOCKWAVE
470 "SELF HIT: multiplier = %f, damage = %f, force = %f... "
471 "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
475 multiplier_from_accuracy,
476 multiplier_from_distance
480 else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
482 // ==========================
483 // BLAST SPLASH CALCULATION
484 // ==========================
486 // calculate importance of distance and accuracy for this attack
487 multiplier_from_accuracy = (1 -
489 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
494 multiplier_from_distance = (1 -
496 min(1, (distance_to_hit / distance_to_end))
503 WEP_CVAR(shockwave, blast_splash_multiplier_min),
505 (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
507 (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
511 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
514 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
516 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
519 // figure out the direction of force
520 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
521 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
522 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
524 // now multiply the direction by force units
525 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
526 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
528 // queue damage with this calculated info
529 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
531 #ifdef DEBUG_SHOCKWAVE
533 "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
534 "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
538 multiplier_from_accuracy,
539 multiplier_from_distance
548 head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), false);
551 if((head != self) && head.takedamage)
553 // ========================
554 // BLAST CONE CALCULATION
555 // ========================
557 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
558 center = CENTER_OR_VIEWOFS(head);
560 // find the closest point on the enemy to the center of the attack
561 float h; // hypotenuse, which is the distance between attacker to head
562 float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
564 h = vlen(center - self.origin);
565 a = h * (normalize(center - self.origin) * w_shotdir);
566 // WEAPONTODO: replace with simpler method
568 vector nearest_on_line = (w_shotorg + a * w_shotdir);
569 vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
571 if((vlen(head.WarpZone_findradius_dist) <= WEP_CVAR(shockwave, blast_distance))
572 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
574 // calculate importance of distance and accuracy for this attack
575 multiplier_from_accuracy = (1 -
576 W_Shockwave_Attack_CheckSpread(
583 multiplier_from_distance = (1 -
585 min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
592 WEP_CVAR(shockwave, blast_multiplier_min),
594 (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
596 (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
600 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
603 (WEP_CVAR(shockwave, blast_damage) * multiplier)
605 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
608 // figure out the direction of force
609 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
610 final_force = normalize(center - (nearest_on_line - final_force));
611 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
613 // now multiply the direction by force units
614 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
615 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
617 // queue damage with this calculated info
618 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
620 #ifdef DEBUG_SHOCKWAVE
622 "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
623 "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
627 multiplier_from_accuracy,
628 multiplier_from_distance
636 for(i = 1; i <= queue; ++i)
638 head = shockwave_hit[i-1];
639 final_force = shockwave_hit_force[i-1];
640 final_damage = shockwave_hit_damage[i-1];
652 if(accuracy_isgooddamage(self.realowner, head))
655 accuracy_add(self.realowner, WEP_SHOCKWAVE.m_id, 0, final_damage);
658 #ifdef DEBUG_SHOCKWAVE
660 "SHOCKWAVE by %s: damage = %f, force = %f.\n",
667 shockwave_hit[i-1] = world;
668 shockwave_hit_force[i-1] = '0 0 0';
669 shockwave_hit_damage[i-1] = 0;
673 METHOD(Shockwave, wr_aim, void(entity thiswep))
675 if(vlen(self.origin - self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
676 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false); }
678 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false); }
680 METHOD(Shockwave, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
684 if(time >= actor.shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
686 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime)))
688 W_Shockwave_Attack();
689 actor.shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor();
690 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
696 //if(actor.clip_load >= 0) // we are not currently reloading
697 if(!actor.crouch) // no crouchmelee please
698 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire)))
700 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
701 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee);
705 METHOD(Shockwave, wr_init, void(entity thiswep))
707 SHOCKWAVE_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
709 METHOD(Shockwave, wr_checkammo1, bool(entity thiswep))
711 return true; // infinite ammo
713 METHOD(Shockwave, wr_checkammo2, bool(entity thiswep))
715 // shockwave has infinite ammo
718 METHOD(Shockwave, wr_config, void(entity thiswep))
720 SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
722 METHOD(Shockwave, wr_suicidemessage, int(entity thiswep))
724 return WEAPON_THINKING_WITH_PORTALS;
726 METHOD(Shockwave, wr_killmessage, int(entity thiswep))
728 if(w_deathtype & HITTYPE_SECONDARY)
729 return WEAPON_SHOCKWAVE_MURDER_SLAP;
731 return WEAPON_SHOCKWAVE_MURDER;
736 // WEAPONTODO: add client side settings for these
737 const float SW_MAXALPHA = 0.5;
738 const float SW_FADETIME = 0.4;
739 const float SW_DISTTOMIN = 200;
740 void Draw_Shockwave(entity this)
742 // fading/removal control
743 float a = bound(0, (SW_MAXALPHA - ((time - self.sw_time) / SW_FADETIME)), SW_MAXALPHA);
744 if(a < ALPHA_MIN_VISIBLE) { remove(self); }
746 // WEAPONTODO: save this only once when creating the entity
747 vector sw_color = getcsqcplayercolor(self.sv_entnum - 1); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
749 // WEAPONTODO: trace to find what we actually hit
750 vector endpos = (self.sw_shotorg + (self.sw_shotdir * self.sw_distance));
752 vectorvectors(self.sw_shotdir);
753 vector right = v_right; // save this for when we do makevectors later
754 vector up = v_up; // save this for when we do makevectors later
756 // WEAPONTODO: combine and simplify these calculations
757 vector min_end = ((self.sw_shotorg + (self.sw_shotdir * SW_DISTTOMIN)) + (up * self.sw_spread_min));
758 vector max_end = (endpos + (up * self.sw_spread_max));
759 float spread_to_min = vlen(normalize(min_end - self.sw_shotorg) - self.sw_shotdir);
760 float spread_to_max = vlen(normalize(max_end - min_end) - self.sw_shotdir);
762 vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
763 vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
764 float new_max_dist, new_min_dist;
766 vector deviation, angle = '0 0 0';
767 float counter, divisions = 20;
768 for(counter = 0; counter < divisions; ++counter)
770 // perfect circle effect lines
771 makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
772 angle.y = v_forward.x;
773 angle.z = v_forward.y;
775 // first do the spread_to_min effect
776 deviation = angle * spread_to_min;
777 deviation = ((self.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
778 new_min_dist = SW_DISTTOMIN;
779 new_min_end = (self.sw_shotorg + (deviation * new_min_dist));
780 //te_lightning2(world, new_min_end, self.sw_shotorg);
782 // then calculate spread_to_max effect
783 deviation = angle * spread_to_max;
784 deviation = ((self.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
785 new_max_dist = vlen(new_min_end - endpos);
786 new_max_end = (new_min_end + (deviation * new_max_dist));
787 //te_lightning2(world, new_end, prev_min_end);
792 first_min_end = new_min_end;
793 first_max_end = new_max_end;
798 // draw from shot origin to min spread radius
799 R_BeginPolygon("", DRAWFLAG_NORMAL);
800 R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
801 R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
802 R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
805 // draw from min spread radius to max spread radius
806 R_BeginPolygon("", DRAWFLAG_NORMAL);
807 R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
808 R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
809 R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
810 R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
814 prev_min_end = new_min_end;
815 prev_max_end = new_max_end;
817 // last division only
818 if((counter + 1) == divisions)
820 // draw from shot origin to min spread radius
821 R_BeginPolygon("", DRAWFLAG_NORMAL);
822 R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
823 R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
824 R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
827 // draw from min spread radius to max spread radius
828 R_BeginPolygon("", DRAWFLAG_NORMAL);
829 R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
830 R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
831 R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
832 R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
838 NET_HANDLE(TE_CSQC_SHOCKWAVEPARTICLE, bool isNew)
840 Net_ReadShockwaveParticle();
844 void Net_ReadShockwaveParticle()
848 shockwave.draw = Draw_Shockwave;
850 shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
851 shockwave.sw_shotdir_x = ReadCoord(); shockwave.sw_shotdir_y = ReadCoord(); shockwave.sw_shotdir_z = ReadCoord();
853 shockwave.sw_distance = ReadShort();
854 shockwave.sw_spread_max = ReadByte();
855 shockwave.sw_spread_min = ReadByte();
857 shockwave.sv_entnum = ReadByte();
859 shockwave.sw_time = time;
862 METHOD(Shockwave, wr_impacteffect, void(entity thiswep))
864 // handled by Net_ReadShockwaveParticle
866 //org2 = w_org + w_backoff * 2;
867 //pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);