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