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