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