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