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