]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/shockwave.qc
af158c7df6111618b5ebc5677c333c1282d668fe
[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.weaponentity_fld,
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         meleetemp.weaponentity_fld = weaponentity;
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                 antilag_takeback_all(actor, lag);
322
323         while(head)
324         {
325                 if(head.takedamage)
326                 {
327                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
328
329                         if((head == actor) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
330                         {
331                                 // ========================
332                                 //  BLAST JUMP CALCULATION
333                                 // ========================
334
335                                 // calculate importance of distance and accuracy for this attack
336                                 multiplier_from_accuracy = (1 -
337                                         (distance_to_head ?
338                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
339                                                 :
340                                                 0
341                                         )
342                                 );
343                                 multiplier_from_distance = (1 -
344                                         (distance_to_hit ?
345                                                 min(1, (distance_to_hit / distance_to_end))
346                                                 :
347                                                 0
348                                         )
349                                 );
350                                 multiplier =
351                                         max(
352                                                 WEP_CVAR(shockwave, blast_jump_multiplier_min),
353                                                 (
354                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
355                                                         +
356                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
357                                                 )
358                                         );
359
360                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
361                                 final_damage =
362                                         (
363                                                 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
364                                                 +
365                                                 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
366                                         );
367
368                                 // figure out the direction of force
369                                 vel = normalize(vec2(head.velocity));
370                                 vel *=
371                                         (
372                                                 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
373                                                 *
374                                                 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
375                                         );
376                                 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
377
378                                 // now multiply the direction by force units
379                                 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
380                                 final_force.z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
381
382                                 // trigger damage with this calculated info
383                                 Damage(
384                                         head,
385                                         actor,
386                                         actor,
387                                         final_damage,
388                                         WEP_SHOCKWAVE.m_id,
389                                         weaponentity,
390                                         head.origin,
391                                         final_force
392                                 );
393
394                                 #ifdef DEBUG_SHOCKWAVE
395                                 LOG_INFOF(
396                                         "SELF HIT: multiplier = %f, damage = %f, force = %f... "
397                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.",
398                                         multiplier,
399                                         final_damage,
400                                         vlen(final_force),
401                                         multiplier_from_accuracy,
402                                         multiplier_from_distance
403                                 );
404                                 #endif
405                         }
406                         else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
407                         {
408                                 // ==========================
409                                 //  BLAST SPLASH CALCULATION
410                                 // ==========================
411
412                                 // calculate importance of distance and accuracy for this attack
413                                 multiplier_from_accuracy = (1 -
414                                         (distance_to_head ?
415                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
416                                                 :
417                                                 0
418                                         )
419                                 );
420                                 multiplier_from_distance = (1 -
421                                         (distance_to_hit ?
422                                                 min(1, (distance_to_hit / distance_to_end))
423                                                 :
424                                                 0
425                                         )
426                                 );
427                                 multiplier =
428                                         max(
429                                                 WEP_CVAR(shockwave, blast_splash_multiplier_min),
430                                                 (
431                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
432                                                         +
433                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
434                                                 )
435                                         );
436
437                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
438                                 final_damage =
439                                         (
440                                                 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
441                                                 +
442                                                 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
443                                         );
444
445                                 // figure out the direction of force
446                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
447                                 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
448                                 //te_lightning2(NULL, attack_hitpos, (attack_hitpos + (final_force * 200)));
449
450                                 // now multiply the direction by force units
451                                 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
452                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
453
454                                 // queue damage with this calculated info
455                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
456
457                                 #ifdef DEBUG_SHOCKWAVE
458                                 LOG_INFOF(
459                                         "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
460                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.",
461                                         multiplier,
462                                         final_damage,
463                                         vlen(final_force),
464                                         multiplier_from_accuracy,
465                                         multiplier_from_distance
466                                 );
467                                 #endif
468                         }
469                 }
470                 head = head.chain;
471         }
472
473         // cone damage trace
474         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), false);
475         while(head)
476         {
477                 if((head != actor) && head.takedamage)
478                 {
479                         // ========================
480                         //  BLAST CONE CALCULATION
481                         // ========================
482
483                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
484                         center = CENTER_OR_VIEWOFS(head);
485
486                         // find the closest point on the enemy to the center of the attack
487                         float h; // hypotenuse, which is the distance between attacker to head
488                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
489
490                         h = vlen(center - actor.origin);
491                         a = h * (normalize(center - actor.origin) * w_shotdir);
492                         // WEAPONTODO: replace with simpler method
493
494                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
495                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
496
497                         if((vdist(head.WarpZone_findradius_dist, <=, WEP_CVAR(shockwave, blast_distance)))
498                                 && (W_Shockwave_Attack_IsVisible(actor, head, nearest_on_line, w_shotorg, attack_endpos)))
499                         {
500                                 // calculate importance of distance and accuracy for this attack
501                                 multiplier_from_accuracy = (1 -
502                                         W_Shockwave_Attack_CheckSpread(
503                                                 nearest_to_attacker,
504                                                 nearest_on_line,
505                                                 w_shotorg,
506                                                 attack_endpos
507                                         )
508                                 );
509                                 multiplier_from_distance = (1 -
510                                         (distance_to_hit ?
511                                                 min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
512                                                 :
513                                                 0
514                                         )
515                                 );
516                                 multiplier =
517                                         max(
518                                                 WEP_CVAR(shockwave, blast_multiplier_min),
519                                                 (
520                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
521                                                         +
522                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
523                                                 )
524                                         );
525
526                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
527                                 final_damage =
528                                         (
529                                                 (WEP_CVAR(shockwave, blast_damage) * multiplier)
530                                                 +
531                                                 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
532                                         );
533
534                                 // figure out the direction of force
535                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
536                                 final_force = normalize(center - (nearest_on_line - final_force));
537                                 //te_lightning2(NULL, nearest_on_line, (attack_hitpos + (final_force * 200)));
538
539                                 // now multiply the direction by force units
540                                 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
541                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
542
543                                 // queue damage with this calculated info
544                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
545
546                                 #ifdef DEBUG_SHOCKWAVE
547                                 LOG_INFOF(
548                                         "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
549                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.",
550                                         multiplier,
551                                         final_damage,
552                                         vlen(final_force),
553                                         multiplier_from_accuracy,
554                                         multiplier_from_distance
555                                 );
556                                 #endif
557                         }
558                 }
559                 head = head.chain;
560         }
561
562         for(i = 1; i <= queue; ++i)
563         {
564                 head = shockwave_hit[i-1];
565                 final_force = shockwave_hit_force[i-1];
566                 final_damage = shockwave_hit_damage[i-1];
567
568                 Damage(
569                         head,
570                         actor,
571                         actor,
572                         final_damage,
573                         WEP_SHOCKWAVE.m_id,
574                         weaponentity,
575                         head.origin,
576                         final_force
577                 );
578
579                 if(accuracy_isgooddamage(actor, head))
580                         accuracy_add(actor, WEP_SHOCKWAVE.m_id, 0, final_damage);
581
582                 #ifdef DEBUG_SHOCKWAVE
583                 LOG_INFOF(
584                         "SHOCKWAVE by %s: damage = %f, force = %f.",
585                         actor.netname,
586                         final_damage,
587                         vlen(final_force)
588                 );
589                 #endif
590
591                 shockwave_hit[i-1] = NULL;
592                 shockwave_hit_force[i-1] = '0 0 0';
593                 shockwave_hit_damage[i-1] = 0;
594         }
595
596         if(lag)
597                 antilag_restore_all(actor);
598 }
599
600 METHOD(Shockwave, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
601 {
602     if(vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR(shockwave, melee_range)))
603         { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); }
604     else
605         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false); }
606 }
607 METHOD(Shockwave, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
608 {
609     if(fire & 1)
610     {
611         if(time >= actor.(weaponentity).shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
612         {
613             if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime)))
614             {
615                 W_Shockwave_Attack(actor, weaponentity);
616                 actor.(weaponentity).shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor(actor);
617                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
618             }
619         }
620     }
621     else if(fire & 2)
622     {
623         //if(actor.clip_load >= 0) // we are not currently reloading
624         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire)))
625         {
626             // attempt forcing playback of the anim by switching to another anim (that we never play) here...
627             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee);
628         }
629     }
630 }
631 METHOD(Shockwave, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
632 {
633     return true; // infinite ammo
634 }
635 METHOD(Shockwave, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
636 {
637     // shockwave has infinite ammo
638     return true;
639 }
640 METHOD(Shockwave, wr_suicidemessage, Notification(entity thiswep))
641 {
642     return WEAPON_THINKING_WITH_PORTALS;
643 }
644 METHOD(Shockwave, wr_killmessage, Notification(entity thiswep))
645 {
646     if(w_deathtype & HITTYPE_SECONDARY)
647         return WEAPON_SHOCKWAVE_MURDER_SLAP;
648     else
649         return WEAPON_SHOCKWAVE_MURDER;
650 }
651
652 #endif
653 #ifdef CSQC
654 // WEAPONTODO: add client side settings for these
655 const float SW_MAXALPHA = 0.5;
656 const float SW_FADETIME = 0.4;
657 const float SW_DISTTOMIN = 200;
658 void Draw_Shockwave(entity this)
659 {
660         // fading/removal control
661         float a = bound(0, (SW_MAXALPHA - ((time - this.sw_time) / SW_FADETIME)), SW_MAXALPHA);
662         if(a < ALPHA_MIN_VISIBLE) { delete(this); }
663
664         // WEAPONTODO: save this only once when creating the entity
665         vector sw_color = entcs_GetColor(this.sv_entnum - 1); // GetTeamRGB(entcs_GetTeam(this.sv_entnum));
666
667         // WEAPONTODO: trace to find what we actually hit
668         vector endpos = (this.sw_shotorg + (this.sw_shotdir * this.sw_distance));
669
670         vectorvectors(this.sw_shotdir);
671         vector right = v_right; // save this for when we do makevectors later
672         vector up = v_up; // save this for when we do makevectors later
673
674         // WEAPONTODO: combine and simplify these calculations
675         vector min_end = ((this.sw_shotorg + (this.sw_shotdir * SW_DISTTOMIN)) + (up * this.sw_spread_min));
676         vector max_end = (endpos + (up * this.sw_spread_max));
677         float spread_to_min = vlen(normalize(min_end - this.sw_shotorg) - this.sw_shotdir);
678         float spread_to_max = vlen(normalize(max_end - min_end) - this.sw_shotdir);
679
680         vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
681         vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
682         float new_max_dist, new_min_dist;
683
684         vector deviation, angle = '0 0 0';
685         float counter, divisions = 20;
686         for(counter = 0; counter < divisions; ++counter)
687         {
688                 // perfect circle effect lines
689                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
690                 angle.y = v_forward.x;
691                 angle.z = v_forward.y;
692
693                 // first do the spread_to_min effect
694                 deviation = angle * spread_to_min;
695                 deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
696                 new_min_dist = SW_DISTTOMIN;
697                 new_min_end = (this.sw_shotorg + (deviation * new_min_dist));
698                 //te_lightning2(NULL, new_min_end, this.sw_shotorg);
699
700                 // then calculate spread_to_max effect
701                 deviation = angle * spread_to_max;
702                 deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
703                 new_max_dist = vlen(new_min_end - endpos);
704                 new_max_end = (new_min_end + (deviation * new_max_dist));
705                 //te_lightning2(NULL, new_end, prev_min_end);
706
707
708                 if(counter == 0)
709                 {
710                         first_min_end = new_min_end;
711                         first_max_end = new_max_end;
712                 }
713
714                 if(counter >= 1)
715                 {
716                         // draw from shot origin to min spread radius
717                         R_BeginPolygon("", DRAWFLAG_NORMAL);
718                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
719                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
720                         R_PolygonVertex(this.sw_shotorg, '0 0 0', sw_color, a);
721                         R_EndPolygon();
722
723                         // draw from min spread radius to max spread radius
724                         R_BeginPolygon("", DRAWFLAG_NORMAL);
725                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
726                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
727                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
728                         R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
729                         R_EndPolygon();
730                 }
731
732                 prev_min_end = new_min_end;
733                 prev_max_end = new_max_end;
734
735                 // last division only
736                 if((counter + 1) == divisions)
737                 {
738                         // draw from shot origin to min spread radius
739                         R_BeginPolygon("", DRAWFLAG_NORMAL);
740                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
741                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
742                         R_PolygonVertex(this.sw_shotorg, '0 0 0', sw_color, a);
743                         R_EndPolygon();
744
745                         // draw from min spread radius to max spread radius
746                         R_BeginPolygon("", DRAWFLAG_NORMAL);
747                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
748                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
749                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
750                         R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
751                         R_EndPolygon();
752                 }
753         }
754 }
755
756 NET_HANDLE(TE_CSQC_SHOCKWAVEPARTICLE, bool isNew)
757 {
758         Net_ReadShockwaveParticle();
759         return true;
760 }
761
762 void Net_ReadShockwaveParticle()
763 {
764         entity shockwave;
765         shockwave = spawn();
766         shockwave.draw = Draw_Shockwave;
767         IL_PUSH(g_drawables, shockwave);
768
769         shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
770         shockwave.sw_shotdir_x = ReadCoord(); shockwave.sw_shotdir_y = ReadCoord(); shockwave.sw_shotdir_z = ReadCoord();
771
772         shockwave.sw_distance = ReadShort();
773         shockwave.sw_spread_max = ReadByte();
774         shockwave.sw_spread_min = ReadByte();
775
776         shockwave.sv_entnum = ReadByte();
777
778         shockwave.sw_time = time;
779 }
780
781 METHOD(Shockwave, wr_impacteffect, void(entity thiswep, entity actor))
782 {
783     // handled by Net_ReadShockwaveParticle
784     //vector org2;
785     //org2 = w_org + w_backoff * 2;
786     //pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
787 }
788
789 #endif