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