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