]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/shockwave.qc
Added an inactive gameplay cvar for using the own shot origin or centers of other...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / shockwave.qc
1 #include "shockwave.qh"
2
3 REGISTER_NET_TEMP(TE_CSQC_SHOCKWAVEPARTICLE)
4
5 #ifdef SVQC
6
7 const float MAX_SHOCKWAVE_HITS = 10;
8 //#define DEBUG_SHOCKWAVE
9
10 .float swing_prev;
11 .entity swing_alreadyhit;
12 .float shockwave_blasttime;
13 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
14 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
15 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
16
17 // MELEE ATTACK MODE
18 void W_Shockwave_Melee_Think(entity this)
19 {
20         // declarations
21         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
22         entity target_victim;
23         vector targpos;
24
25         // check to see if we can still continue, otherwise give up now
26         if(IS_DEAD(this.realowner) && WEP_CVAR(shockwave, melee_no_doubleslap))
27         {
28                 delete(this);
29                 return;
30         }
31
32         // set start time of melee
33         if(!this.cnt)
34         {
35                 this.cnt = time;
36                 W_PlayStrengthSound(this.realowner);
37         }
38
39         // update values for v_* vectors
40         makevectors(this.realowner.v_angle);
41
42         // calculate swing percentage based on time
43         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor(this.realowner);
44         swing = bound(0, (this.cnt + meleetime - time) / meleetime, 10);
45         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
46
47         // perform the traces needed for this frame
48         for(i=this.swing_prev; i < f; ++i)
49         {
50                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
51
52                 targpos = (this.realowner.origin + this.realowner.view_ofs
53                         + (v_forward * WEP_CVAR(shockwave, melee_range))
54                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
55                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
56
57                 WarpZone_traceline_antilag(
58                         this.realowner,
59                         (this.realowner.origin + this.realowner.view_ofs),
60                         targpos,
61                         false,
62                         this.realowner,
63                         ANTILAG_LATENCY(this.realowner)
64                 );
65
66                 // draw lightning beams for debugging
67 #ifdef DEBUG_SHOCKWAVE
68                 te_lightning2(NULL, targpos, this.realowner.origin + this.realowner.view_ofs + v_forward * 5 - v_up * 5);
69                 te_customflash(targpos, 40,  2, '1 1 1');
70 #endif
71
72                 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
73
74                 if((trace_fraction < 1) // if trace is good, apply the damage and remove this if necessary
75                         && (trace_ent.takedamage == DAMAGE_AIM)
76                         && (trace_ent != this.swing_alreadyhit)
77                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
78                 {
79                         target_victim = trace_ent; // so it persists through other calls
80
81                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
82                                 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
83                         else
84                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
85
86                         // trigger damage with this calculated info
87                         Damage(
88                                 target_victim,
89                                 this.realowner,
90                                 this.realowner,
91                                 swing_damage,
92                                 (WEP_SHOCKWAVE.m_id | HITTYPE_SECONDARY),
93                                 this.weaponentity_fld,
94                                 (this.realowner.origin + this.realowner.view_ofs),
95                                 (v_forward * WEP_CVAR(shockwave, melee_force))
96                         );
97
98                         // handle accuracy
99                         if(accuracy_isgooddamage(this.realowner, target_victim))
100                                 { accuracy_add(this.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
101
102                         #ifdef DEBUG_SHOCKWAVE
103                         LOG_INFOF(
104                                 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.",
105                                 this.realowner.netname,
106                                 target_victim.netname,
107                                 swing_damage,
108                                 swing_factor,
109                                 time
110                         );
111                         #endif
112
113                         // allow multiple hits with one swing, but not against the same player twice
114                         if(WEP_CVAR(shockwave, melee_multihit))
115                         {
116                                 this.swing_alreadyhit = target_victim;
117                                 continue; // move along to next trace
118                         }
119                         else
120                         {
121                                 delete(this);
122                                 return;
123                         }
124                 }
125         }
126
127         if(time >= this.cnt + meleetime)
128         {
129                 // melee is finished
130                 delete(this);
131                 return;
132         }
133         else
134         {
135                 // set up next frame
136                 this.swing_prev = i;
137                 this.nextthink = time;
138         }
139 }
140
141 void W_Shockwave_Melee(Weapon thiswep, entity actor, .entity weaponentity, int fire)
142 {
143         sound(actor, CH_WEAPON_A, SND_SHOTGUN_MELEE, VOL_BASE, ATTN_NORM);
144         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
145
146         entity meleetemp = new_pure(meleetemp);
147         meleetemp.owner = meleetemp.realowner = actor;
148         setthink(meleetemp, W_Shockwave_Melee_Think);
149         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor(actor);
150         meleetemp.weaponentity_fld = weaponentity;
151         W_SetupShot_Range(actor, weaponentity, true, 0, SND_Null, 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range), thiswep.m_id | HITTYPE_SECONDARY);
152 }
153
154 // SHOCKWAVE ATTACK MODE
155 float W_Shockwave_Attack_CheckSpread(
156         vector targetorg,
157         vector nearest_on_line,
158         vector sw_shotorg,
159         vector attack_endpos)
160 {
161         float spreadlimit;
162         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
163         float distance_from_line = vlen(targetorg - nearest_on_line);
164
165         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
166         spreadlimit =
167                 (
168                         (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
169                         +
170                         (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
171                 );
172
173         if(
174                 (spreadlimit && (distance_from_line <= spreadlimit))
175                 &&
176                 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
177         )
178                 { return bound(0, (distance_from_line / spreadlimit), 1); }
179         else
180                 { return false; }
181 }
182
183 float W_Shockwave_Attack_IsVisible(
184         entity actor,
185         entity head,
186         vector nearest_on_line,
187         vector sw_shotorg,
188         vector attack_endpos)
189 {
190         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
191         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
192         vector corner;
193         float i;
194
195         // STEP ONE: Check if the nearest point is clear
196         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
197         {
198                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, actor);
199                 if(trace_fraction == 1) { return true; } // yes, the nearest point is clear and we can allow the damage
200         }
201
202         // STEP TWO: Check if shotorg to center point is clear
203         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
204         {
205                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, actor);
206                 if(trace_fraction == 1) { return true; } // yes, the center point is clear and we can allow the damage
207         }
208
209         // STEP THREE: Check each corner to see if they are clear
210         for(i=1; i<=8; ++i)
211         {
212                 corner = get_corner_position(head, i);
213                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
214                 {
215                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, actor);
216                         if(trace_fraction == 1) { return true; } // yes, this corner is clear and we can allow the damage
217                 }
218         }
219
220         return false;
221 }
222
223 float W_Shockwave_Attack_CheckHit(
224         float queue,
225         entity head,
226         vector final_force,
227         float final_damage)
228 {
229         if(!head) { return false; }
230         float i;
231
232         for(i = 0; i <= queue; ++i)
233         {
234                 if(shockwave_hit[i] == head)
235                 {
236                         if(vlen2(final_force) > vlen2(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
237                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
238                         return false;
239                 }
240         }
241
242         shockwave_hit[queue] = head;
243         shockwave_hit_force[queue] = final_force;
244         shockwave_hit_damage[queue] = final_damage;
245         return true;
246 }
247
248 void W_Shockwave_Send(entity actor)
249 {
250         WriteHeader(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
251         WriteVector(MSG_BROADCAST, w_shotorg);
252         WriteVector(MSG_BROADCAST, w_shotdir);
253         WriteShort(MSG_BROADCAST, WEP_CVAR(shockwave, blast_distance));
254         WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_max), 255));
255         WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_min), 255));
256         WriteByte(MSG_BROADCAST, etof(actor));
257 }
258
259 void W_Shockwave_Attack(Weapon thiswep, entity actor, .entity weaponentity)
260 {
261         // declarations
262         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
263         float final_damage;
264         vector final_force, center, vel;
265         entity head;
266
267         float i, queue = 0;
268
269         // set up the shot direction
270         W_SetupShot(actor, weaponentity, true, 3, SND_LASERGUN_FIRE, CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage), thiswep.m_id);
271         vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
272         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, actor);
273         vector attack_hitpos = trace_endpos;
274         float distance_to_end = vlen(w_shotorg - attack_endpos);
275         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
276         //entity transform = WarpZone_trace_transform;
277
278         // do the firing effect now
279         W_Shockwave_Send(actor);
280         Damage_DamageInfo(
281                 attack_hitpos,
282                 WEP_CVAR(shockwave, blast_splash_damage),
283                 WEP_CVAR(shockwave, blast_splash_edgedamage),
284                 WEP_CVAR(shockwave, blast_splash_radius),
285                 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
286                 thiswep.m_id,
287                 0,
288                 actor
289         );
290
291         // splash damage/jumping trace
292         head = WarpZone_FindRadius(
293                 attack_hitpos,
294                 max(
295                         WEP_CVAR(shockwave, blast_splash_radius),
296                         WEP_CVAR(shockwave, blast_jump_radius)
297                 ),
298                 false
299         );
300
301         float lag = ((IS_REAL_CLIENT(actor)) ? ANTILAG_LATENCY(actor) : 0);
302         bool noantilag = ((IS_CLIENT(actor)) ? CS_CVAR(actor).cvar_cl_noantilag : false);
303         if(lag < 0.001)
304                 lag = 0;
305         if(autocvar_g_antilag == 0 || noantilag)
306                 lag = 0; // only do hitscan, but no antilag
307         if(lag)
308                 antilag_takeback_all(actor, lag);
309
310         while(head)
311         {
312                 if(head.takedamage)
313                 {
314                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
315
316                         if((head == actor) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
317                         {
318                                 // ========================
319                                 //  BLAST JUMP CALCULATION
320                                 // ========================
321
322                                 // calculate importance of distance and accuracy for this attack
323                                 multiplier_from_accuracy = (1 -
324                                         (distance_to_head ?
325                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
326                                                 :
327                                                 0
328                                         )
329                                 );
330                                 multiplier_from_distance = (1 -
331                                         (distance_to_hit ?
332                                                 min(1, (distance_to_hit / distance_to_end))
333                                                 :
334                                                 0
335                                         )
336                                 );
337                                 multiplier =
338                                         max(
339                                                 WEP_CVAR(shockwave, blast_jump_multiplier_min),
340                                                 (
341                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
342                                                         +
343                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
344                                                 )
345                                         );
346
347                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
348                                 final_damage =
349                                         (
350                                                 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
351                                                 +
352                                                 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
353                                         );
354
355                                 // figure out the direction of force
356                                 vel = normalize(vec2(head.velocity));
357                                 vel *=
358                                         (
359                                                 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
360                                                 *
361                                                 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
362                                         );
363
364                                 if (autocvar_g_player_damageplayercenter)
365                                 {
366                                         vector shot_origin = CENTER_OR_VIEWOFS(actor);
367                                         shot_origin.z += actor.(weaponentity).movedir.z;
368                                         //if (head == actor) // was checked for already, is true
369                                                 final_force = normalize((shot_origin - attack_hitpos) + vel);
370                                         //else // use target's bbox centerpoint
371                                                 //final_force = normalize(((head.origin + ((head.mins + head.maxs) * 0.5)) - attack_hitpos) + vel);
372                                 }
373                                 else
374                                 {
375                                         // if it's a player, use the view origin as reference
376                                         final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
377                                 }
378
379                                 // now multiply the direction by force units
380                                 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
381                                 final_force.z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
382
383                                 // trigger damage with this calculated info
384                                 Damage(
385                                         head,
386                                         actor,
387                                         actor,
388                                         final_damage,
389                                         thiswep.m_id,
390                                         weaponentity,
391                                         head.origin,
392                                         final_force
393                                 );
394
395                                 #ifdef DEBUG_SHOCKWAVE
396                                 LOG_INFOF(
397                                         "SELF HIT: multiplier = %f, damage = %f, force = %f... "
398                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.",
399                                         multiplier,
400                                         final_damage,
401                                         vlen(final_force),
402                                         multiplier_from_accuracy,
403                                         multiplier_from_distance
404                                 );
405                                 #endif
406                         }
407                         else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
408                         {
409                                 // ==========================
410                                 //  BLAST SPLASH CALCULATION
411                                 // ==========================
412
413                                 // calculate importance of distance and accuracy for this attack
414                                 multiplier_from_accuracy = (1 -
415                                         (distance_to_head ?
416                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
417                                                 :
418                                                 0
419                                         )
420                                 );
421                                 multiplier_from_distance = (1 -
422                                         (distance_to_hit ?
423                                                 min(1, (distance_to_hit / distance_to_end))
424                                                 :
425                                                 0
426                                         )
427                                 );
428                                 multiplier =
429                                         max(
430                                                 WEP_CVAR(shockwave, blast_splash_multiplier_min),
431                                                 (
432                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
433                                                         +
434                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
435                                                 )
436                                         );
437
438                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
439                                 final_damage =
440                                         (
441                                                 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
442                                                 +
443                                                 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
444                                         );
445
446                                 // figure out the direction of force
447                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
448                                 if (autocvar_g_player_damageplayercenter)
449                                 {
450                                         //if (head == actor) // was checked for already, is false
451                                                 //final_force = normalize(CENTER_OR_VIEWOFS(actor) + '0 0 actor.(weaponentity).movedir.z' - (attack_hitpos - final_force));
452                                         //else // use target's bbox centerpoint
453                                                 final_force = normalize((head.origin + ((head.mins + head.maxs) * 0.5)) - (attack_hitpos - final_force));
454                                 }
455                                 else
456                                 {
457                                         // if it's a player, use the view origin as reference
458                                         final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
459                                 }
460                                 //te_lightning2(NULL, attack_hitpos, (attack_hitpos + (final_force * 200)));
461
462                                 // now multiply the direction by force units
463                                 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
464                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
465
466                                 // queue damage with this calculated info
467                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
468
469                                 #ifdef DEBUG_SHOCKWAVE
470                                 LOG_INFOF(
471                                         "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
472                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.",
473                                         multiplier,
474                                         final_damage,
475                                         vlen(final_force),
476                                         multiplier_from_accuracy,
477                                         multiplier_from_distance
478                                 );
479                                 #endif
480                         }
481                 }
482                 head = head.chain;
483         }
484
485         // cone damage trace
486         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), false);
487         while(head)
488         {
489                 if((head != actor) && head.takedamage)
490                 {
491                         // ========================
492                         //  BLAST CONE CALCULATION
493                         // ========================
494
495                         if (autocvar_g_player_damageplayercenter)
496                         {
497                                 //if (head == actor) // was checked for already, is false
498                                         //center = CENTER_OR_VIEWOFS(actor) + '0 0 actor.(weaponentity).movedir.z';
499                                 //else // use target's bbox centerpoint
500                                         center = head.origin + ((head.mins + head.maxs) * 0.5);
501                         }
502                         else
503                         {
504                                 // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in damage.qc)
505                                 center = CENTER_OR_VIEWOFS(head);
506                         }
507
508                         // find the closest point on the enemy to the center of the attack
509                         float h; // hypotenuse, which is the distance between attacker to head
510                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
511
512                         h = vlen(center - actor.origin);
513                         a = h * (normalize(center - actor.origin) * w_shotdir);
514                         // WEAPONTODO: replace with simpler method
515
516                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
517                         vector nearest_to_attacker = NearestPointOnBoundingBox(center + head.mins, center + head.maxs, nearest_on_line);
518
519                         if((vdist(head.WarpZone_findradius_dist, <=, WEP_CVAR(shockwave, blast_distance)))
520                                 && (W_Shockwave_Attack_IsVisible(actor, head, nearest_on_line, w_shotorg, attack_endpos)))
521                         {
522                                 // calculate importance of distance and accuracy for this attack
523                                 multiplier_from_accuracy = (1 -
524                                         W_Shockwave_Attack_CheckSpread(
525                                                 nearest_to_attacker,
526                                                 nearest_on_line,
527                                                 w_shotorg,
528                                                 attack_endpos
529                                         )
530                                 );
531                                 multiplier_from_distance = (1 -
532                                         (distance_to_hit ?
533                                                 min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
534                                                 :
535                                                 0
536                                         )
537                                 );
538                                 multiplier =
539                                         max(
540                                                 WEP_CVAR(shockwave, blast_multiplier_min),
541                                                 (
542                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
543                                                         +
544                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
545                                                 )
546                                         );
547
548                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
549                                 final_damage =
550                                         (
551                                                 (WEP_CVAR(shockwave, blast_damage) * multiplier)
552                                                 +
553                                                 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
554                                         );
555
556                                 // figure out the direction of force
557                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
558                                 final_force = normalize(center - (nearest_on_line - final_force));
559                                 //te_lightning2(NULL, nearest_on_line, (attack_hitpos + (final_force * 200)));
560
561                                 // now multiply the direction by force units
562                                 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
563                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
564
565                                 // queue damage with this calculated info
566                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
567
568                                 #ifdef DEBUG_SHOCKWAVE
569                                 LOG_INFOF(
570                                         "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
571                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.",
572                                         multiplier,
573                                         final_damage,
574                                         vlen(final_force),
575                                         multiplier_from_accuracy,
576                                         multiplier_from_distance
577                                 );
578                                 #endif
579                         }
580                 }
581                 head = head.chain;
582         }
583
584         for(i = 1; i <= queue; ++i)
585         {
586                 head = shockwave_hit[i-1];
587                 final_force = shockwave_hit_force[i-1];
588                 final_damage = shockwave_hit_damage[i-1];
589
590                 Damage(
591                         head,
592                         actor,
593                         actor,
594                         final_damage,
595                         thiswep.m_id,
596                         weaponentity,
597                         head.origin,
598                         final_force
599                 );
600
601                 if(accuracy_isgooddamage(actor, head))
602                         accuracy_add(actor, thiswep, 0, final_damage);
603
604                 #ifdef DEBUG_SHOCKWAVE
605                 LOG_INFOF(
606                         "SHOCKWAVE by %s: damage = %f, force = %f.",
607                         actor.netname,
608                         final_damage,
609                         vlen(final_force)
610                 );
611                 #endif
612
613                 shockwave_hit[i-1] = NULL;
614                 shockwave_hit_force[i-1] = '0 0 0';
615                 shockwave_hit_damage[i-1] = 0;
616         }
617
618         if(lag)
619                 antilag_restore_all(actor);
620 }
621
622 METHOD(Shockwave, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
623 {
624     if(vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR(shockwave, melee_range)))
625         { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, false); }
626     else
627         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, false); }
628 }
629 METHOD(Shockwave, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
630 {
631     if(fire & 1)
632     {
633         if(time >= actor.(weaponentity).shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
634         {
635             if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime)))
636             {
637                 W_Shockwave_Attack(thiswep, actor, weaponentity);
638                 actor.(weaponentity).shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor(actor);
639                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
640             }
641         }
642     }
643     else if(fire & 2)
644     {
645         //if(actor.clip_load >= 0) // we are not currently reloading
646         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire)))
647         {
648             // attempt forcing playback of the anim by switching to another anim (that we never play) here...
649             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee);
650         }
651     }
652 }
653 METHOD(Shockwave, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
654 {
655     return true; // infinite ammo
656 }
657 METHOD(Shockwave, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
658 {
659     // shockwave has infinite ammo
660     return true;
661 }
662 METHOD(Shockwave, wr_suicidemessage, Notification(entity thiswep))
663 {
664     return WEAPON_THINKING_WITH_PORTALS;
665 }
666 METHOD(Shockwave, wr_killmessage, Notification(entity thiswep))
667 {
668     if(w_deathtype & HITTYPE_SECONDARY)
669         return WEAPON_SHOCKWAVE_MURDER_SLAP;
670     else
671         return WEAPON_SHOCKWAVE_MURDER;
672 }
673
674 #endif
675 #ifdef CSQC
676 // WEAPONTODO: add client side settings for these
677 const float SW_MAXALPHA = 0.5;
678 const float SW_FADETIME = 0.4;
679 const float SW_DISTTOMIN = 200;
680 void Draw_Shockwave(entity this)
681 {
682         // fading/removal control
683         float a = bound(0, (SW_MAXALPHA - ((time - this.sw_time) / SW_FADETIME)), SW_MAXALPHA);
684         if(a < ALPHA_MIN_VISIBLE) { delete(this); }
685
686         // WEAPONTODO: save this only once when creating the entity
687         vector sw_color = entcs_GetColor(this.sv_entnum - 1); // Team_ColorRGB(entcs_GetTeam(this.sv_entnum));
688
689         // WEAPONTODO: trace to find what we actually hit
690         vector endpos = (this.sw_shotorg + (this.sw_shotdir * this.sw_distance));
691
692         vector _forward, right, up;
693         VECTOR_VECTORS(this.sw_shotdir, _forward, right, up);
694
695         // WEAPONTODO: combine and simplify these calculations
696         vector min_end = ((this.sw_shotorg + (this.sw_shotdir * SW_DISTTOMIN)) + (up * this.sw_spread_min));
697         vector max_end = (endpos + (up * this.sw_spread_max));
698         float spread_to_min = vlen(normalize(min_end - this.sw_shotorg) - this.sw_shotdir);
699         float spread_to_max = vlen(normalize(max_end - min_end) - this.sw_shotdir);
700
701         vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
702         vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
703         float new_max_dist, new_min_dist;
704
705         vector deviation, angle = '0 0 0';
706         float counter, divisions = 20;
707         for(counter = 0; counter < divisions; ++counter)
708         {
709                 // perfect circle effect lines
710                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
711                 angle.y = v_forward.x;
712                 angle.z = v_forward.y;
713
714                 // first do the spread_to_min effect
715                 deviation = angle * spread_to_min;
716                 deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
717                 new_min_dist = SW_DISTTOMIN;
718                 new_min_end = (this.sw_shotorg + (deviation * new_min_dist));
719                 //te_lightning2(NULL, new_min_end, this.sw_shotorg);
720
721                 // then calculate spread_to_max effect
722                 deviation = angle * spread_to_max;
723                 deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
724                 new_max_dist = vlen(new_min_end - endpos);
725                 new_max_end = (new_min_end + (deviation * new_max_dist));
726                 //te_lightning2(NULL, new_end, prev_min_end);
727
728
729                 if(counter == 0)
730                 {
731                         first_min_end = new_min_end;
732                         first_max_end = new_max_end;
733                 }
734
735                 if(counter >= 1)
736                 {
737                         // draw from shot origin to min spread radius
738                         R_BeginPolygon("", DRAWFLAG_NORMAL, false);
739                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
740                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
741                         R_PolygonVertex(this.sw_shotorg, '0 0 0', sw_color, a);
742                         R_EndPolygon();
743
744                         // draw from min spread radius to max spread radius
745                         R_BeginPolygon("", DRAWFLAG_NORMAL, false);
746                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
747                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
748                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
749                         R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
750                         R_EndPolygon();
751                 }
752
753                 prev_min_end = new_min_end;
754                 prev_max_end = new_max_end;
755
756                 // last division only
757                 if((counter + 1) == divisions)
758                 {
759                         // draw from shot origin to min spread radius
760                         R_BeginPolygon("", DRAWFLAG_NORMAL, false);
761                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
762                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
763                         R_PolygonVertex(this.sw_shotorg, '0 0 0', sw_color, a);
764                         R_EndPolygon();
765
766                         // draw from min spread radius to max spread radius
767                         R_BeginPolygon("", DRAWFLAG_NORMAL, false);
768                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
769                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
770                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
771                         R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
772                         R_EndPolygon();
773                 }
774         }
775 }
776
777 NET_HANDLE(TE_CSQC_SHOCKWAVEPARTICLE, bool isNew)
778 {
779         Net_ReadShockwaveParticle();
780         return true;
781 }
782
783 void Net_ReadShockwaveParticle()
784 {
785         entity shockwave = new(shockwave_cone);
786         shockwave.draw = Draw_Shockwave;
787         IL_PUSH(g_drawables, shockwave);
788
789         shockwave.sw_shotorg = ReadVector();
790         shockwave.sw_shotdir = ReadVector();
791
792         shockwave.sw_distance = ReadShort();
793         shockwave.sw_spread_max = ReadByte();
794         shockwave.sw_spread_min = ReadByte();
795
796         shockwave.sv_entnum = ReadByte();
797
798         shockwave.sw_time = time;
799 }
800
801 METHOD(Shockwave, wr_impacteffect, void(entity thiswep, entity actor))
802 {
803     // handled by Net_ReadShockwaveParticle
804     //vector org2 = w_org + w_backoff * 2;
805     //pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
806 }
807
808 #endif