]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/shockwave.qc
Apply a minimal line spacing
[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, "weaponshockwave");
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(this.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(entity this)
116 {
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(this.realowner) && WEP_CVAR(shockwave, melee_no_doubleslap))
124         {
125                 remove(this);
126                 return;
127         }
128
129         // set start time of melee
130         if(!this.cnt)
131         {
132                 this.cnt = time;
133                 W_PlayStrengthSound(this.realowner);
134         }
135
136         // update values for v_* vectors
137         makevectors(this.realowner.v_angle);
138
139         // calculate swing percentage based on time
140         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor(this.realowner);
141         swing = bound(0, (this.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=this.swing_prev; i < f; ++i)
146         {
147                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
148
149                 targpos = (this.realowner.origin + this.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                         this.realowner,
156                         (this.realowner.origin + this.realowner.view_ofs),
157                         targpos,
158                         false,
159                         this.realowner,
160                         ANTILAG_LATENCY(this.realowner)
161                 );
162
163                 // draw lightning beams for debugging
164 #ifdef DEBUG_SHOCKWAVE
165                 te_lightning2(NULL, targpos, this.realowner.origin + this.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 this if necessary
172                         && (trace_ent.takedamage == DAMAGE_AIM)
173                         && (trace_ent != this.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                                 this.realowner,
187                                 this.realowner,
188                                 swing_damage,
189                                 (WEP_SHOCKWAVE.m_id | HITTYPE_SECONDARY),
190                                 (this.realowner.origin + this.realowner.view_ofs),
191                                 (v_forward * WEP_CVAR(shockwave, melee_force))
192                         );
193
194                         // handle accuracy
195                         if(accuracy_isgooddamage(this.realowner, target_victim))
196                                 { accuracy_add(this.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                                 this.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                                 this.swing_alreadyhit = target_victim;
213                                 continue; // move along to next trace
214                         }
215                         else
216                         {
217                                 remove(this);
218                                 return;
219                         }
220                 }
221         }
222
223         if(time >= this.cnt + meleetime)
224         {
225                 // melee is finished
226                 remove(this);
227                 return;
228         }
229         else
230         {
231                 // set up next frame
232                 this.swing_prev = i;
233                 this.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         setthink(meleetemp, W_Shockwave_Melee_Think);
245         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor(actor);
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 actor,
280         entity head,
281         vector nearest_on_line,
282         vector sw_shotorg,
283         vector attack_endpos)
284 {
285         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
286         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
287         vector corner;
288         float i;
289
290         // STEP ONE: Check if the nearest point is clear
291         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
292         {
293                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, actor);
294                 if(trace_fraction == 1) { return true; } // yes, the nearest point is clear and we can allow the damage
295         }
296
297         // STEP TWO: Check if shotorg to center point is clear
298         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
299         {
300                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, actor);
301                 if(trace_fraction == 1) { return true; } // yes, the center point is clear and we can allow the damage
302         }
303
304         // STEP THREE: Check each corner to see if they are clear
305         for(i=1; i<=8; ++i)
306         {
307                 corner = get_corner_position(head, i);
308                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
309                 {
310                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, actor);
311                         if(trace_fraction == 1) { return true; } // yes, this corner is clear and we can allow the damage
312                 }
313         }
314
315         return false;
316 }
317
318 float W_Shockwave_Attack_CheckHit(
319         float queue,
320         entity head,
321         vector final_force,
322         float final_damage)
323 {
324         if(!head) { return false; }
325         float i;
326
327         for(i = 0; i <= queue; ++i)
328         {
329                 if(shockwave_hit[i] == head)
330                 {
331                         if(vlen2(final_force) > vlen2(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
332                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
333                         return false;
334                 }
335         }
336
337         shockwave_hit[queue] = head;
338         shockwave_hit_force[queue] = final_force;
339         shockwave_hit_damage[queue] = final_damage;
340         return true;
341 }
342
343 void W_Shockwave_Send(entity actor)
344 {
345         WriteHeader(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
346         WriteCoord(MSG_BROADCAST, w_shotorg.x);
347         WriteCoord(MSG_BROADCAST, w_shotorg.y);
348         WriteCoord(MSG_BROADCAST, w_shotorg.z);
349         WriteCoord(MSG_BROADCAST, w_shotdir.x);
350         WriteCoord(MSG_BROADCAST, w_shotdir.y);
351         WriteCoord(MSG_BROADCAST, w_shotdir.z);
352         WriteShort(MSG_BROADCAST, WEP_CVAR(shockwave, blast_distance));
353         WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_max), 255));
354         WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_min), 255));
355         WriteByte(MSG_BROADCAST, etof(actor));
356 }
357
358 void W_Shockwave_Attack(entity actor)
359 {
360         // declarations
361         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
362         float final_damage;
363         vector final_force, center, vel;
364         entity head;
365
366         float i, queue = 0;
367
368         // set up the shot direction
369         W_SetupShot(actor, true, 3, SND_LASERGUN_FIRE, CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
370         vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
371         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, actor);
372         vector attack_hitpos = trace_endpos;
373         float distance_to_end = vlen(w_shotorg - attack_endpos);
374         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
375         //entity transform = WarpZone_trace_transform;
376
377         // do the firing effect now
378         W_Shockwave_Send(actor);
379         Damage_DamageInfo(
380                 attack_hitpos,
381                 WEP_CVAR(shockwave, blast_splash_damage),
382                 WEP_CVAR(shockwave, blast_splash_edgedamage),
383                 WEP_CVAR(shockwave, blast_splash_radius),
384                 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
385                 WEP_SHOCKWAVE.m_id,
386                 0,
387                 actor
388         );
389
390         // splash damage/jumping trace
391         head = WarpZone_FindRadius(
392                 attack_hitpos,
393                 max(
394                         WEP_CVAR(shockwave, blast_splash_radius),
395                         WEP_CVAR(shockwave, blast_jump_radius)
396                 ),
397                 false
398         );
399
400         float lag = ANTILAG_LATENCY(actor);
401         if(lag < 0.001)
402                 lag = 0;
403         if (!IS_REAL_CLIENT(actor))
404                 lag = 0;
405         if(autocvar_g_antilag == 0 || actor.cvar_cl_noantilag)
406                 lag = 0; // only do hitscan, but no antilag
407         if(lag)
408         {
409                 FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_takeback(it, CS(it), time - lag));
410                 FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
411                         if (it != actor)
412                                 antilag_takeback(it, it, time - lag);
413                 });
414         }
415
416         while(head)
417         {
418                 if(head.takedamage)
419                 {
420                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
421
422                         if((head == actor) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
423                         {
424                                 // ========================
425                                 //  BLAST JUMP CALCULATION
426                                 // ========================
427
428                                 // calculate importance of distance and accuracy for this attack
429                                 multiplier_from_accuracy = (1 -
430                                         (distance_to_head ?
431                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
432                                                 :
433                                                 0
434                                         )
435                                 );
436                                 multiplier_from_distance = (1 -
437                                         (distance_to_hit ?
438                                                 min(1, (distance_to_hit / distance_to_end))
439                                                 :
440                                                 0
441                                         )
442                                 );
443                                 multiplier =
444                                         max(
445                                                 WEP_CVAR(shockwave, blast_jump_multiplier_min),
446                                                 (
447                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
448                                                         +
449                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
450                                                 )
451                                         );
452
453                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
454                                 final_damage =
455                                         (
456                                                 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
457                                                 +
458                                                 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
459                                         );
460
461                                 // figure out the direction of force
462                                 vel = normalize(vec3(head.velocity.x, head.velocity.y, 0));
463                                 vel *=
464                                         (
465                                                 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
466                                                 *
467                                                 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
468                                         );
469                                 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
470
471                                 // now multiply the direction by force units
472                                 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
473                                 final_force.z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
474
475                                 // trigger damage with this calculated info
476                                 Damage(
477                                         head,
478                                         actor,
479                                         actor,
480                                         final_damage,
481                                         WEP_SHOCKWAVE.m_id,
482                                         head.origin,
483                                         final_force
484                                 );
485
486                                 #ifdef DEBUG_SHOCKWAVE
487                                 LOG_INFO(sprintf(
488                                         "SELF HIT: multiplier = %f, damage = %f, force = %f... "
489                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
490                                         multiplier,
491                                         final_damage,
492                                         vlen(final_force),
493                                         multiplier_from_accuracy,
494                                         multiplier_from_distance
495                                 ));
496                                 #endif
497                         }
498                         else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
499                         {
500                                 // ==========================
501                                 //  BLAST SPLASH CALCULATION
502                                 // ==========================
503
504                                 // calculate importance of distance and accuracy for this attack
505                                 multiplier_from_accuracy = (1 -
506                                         (distance_to_head ?
507                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
508                                                 :
509                                                 0
510                                         )
511                                 );
512                                 multiplier_from_distance = (1 -
513                                         (distance_to_hit ?
514                                                 min(1, (distance_to_hit / distance_to_end))
515                                                 :
516                                                 0
517                                         )
518                                 );
519                                 multiplier =
520                                         max(
521                                                 WEP_CVAR(shockwave, blast_splash_multiplier_min),
522                                                 (
523                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
524                                                         +
525                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
526                                                 )
527                                         );
528
529                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
530                                 final_damage =
531                                         (
532                                                 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
533                                                 +
534                                                 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
535                                         );
536
537                                 // figure out the direction of force
538                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
539                                 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
540                                 //te_lightning2(NULL, attack_hitpos, (attack_hitpos + (final_force * 200)));
541
542                                 // now multiply the direction by force units
543                                 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
544                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
545
546                                 // queue damage with this calculated info
547                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
548
549                                 #ifdef DEBUG_SHOCKWAVE
550                                 LOG_INFO(sprintf(
551                                         "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
552                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
553                                         multiplier,
554                                         final_damage,
555                                         vlen(final_force),
556                                         multiplier_from_accuracy,
557                                         multiplier_from_distance
558                                 ));
559                                 #endif
560                         }
561                 }
562                 head = head.chain;
563         }
564
565         // cone damage trace
566         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), false);
567         while(head)
568         {
569                 if((head != actor) && head.takedamage)
570                 {
571                         // ========================
572                         //  BLAST CONE CALCULATION
573                         // ========================
574
575                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
576                         center = CENTER_OR_VIEWOFS(head);
577
578                         // find the closest point on the enemy to the center of the attack
579                         float h; // hypotenuse, which is the distance between attacker to head
580                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
581
582                         h = vlen(center - actor.origin);
583                         a = h * (normalize(center - actor.origin) * w_shotdir);
584                         // WEAPONTODO: replace with simpler method
585
586                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
587                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
588
589                         if((vdist(head.WarpZone_findradius_dist, <=, WEP_CVAR(shockwave, blast_distance)))
590                                 && (W_Shockwave_Attack_IsVisible(actor, head, nearest_on_line, w_shotorg, attack_endpos)))
591                         {
592                                 // calculate importance of distance and accuracy for this attack
593                                 multiplier_from_accuracy = (1 -
594                                         W_Shockwave_Attack_CheckSpread(
595                                                 nearest_to_attacker,
596                                                 nearest_on_line,
597                                                 w_shotorg,
598                                                 attack_endpos
599                                         )
600                                 );
601                                 multiplier_from_distance = (1 -
602                                         (distance_to_hit ?
603                                                 min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
604                                                 :
605                                                 0
606                                         )
607                                 );
608                                 multiplier =
609                                         max(
610                                                 WEP_CVAR(shockwave, blast_multiplier_min),
611                                                 (
612                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
613                                                         +
614                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
615                                                 )
616                                         );
617
618                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
619                                 final_damage =
620                                         (
621                                                 (WEP_CVAR(shockwave, blast_damage) * multiplier)
622                                                 +
623                                                 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
624                                         );
625
626                                 // figure out the direction of force
627                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
628                                 final_force = normalize(center - (nearest_on_line - final_force));
629                                 //te_lightning2(NULL, nearest_on_line, (attack_hitpos + (final_force * 200)));
630
631                                 // now multiply the direction by force units
632                                 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
633                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
634
635                                 // queue damage with this calculated info
636                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
637
638                                 #ifdef DEBUG_SHOCKWAVE
639                                 LOG_INFO(sprintf(
640                                         "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
641                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
642                                         multiplier,
643                                         final_damage,
644                                         vlen(final_force),
645                                         multiplier_from_accuracy,
646                                         multiplier_from_distance
647                                 ));
648                                 #endif
649                         }
650                 }
651                 head = head.chain;
652         }
653
654         for(i = 1; i <= queue; ++i)
655         {
656                 head = shockwave_hit[i-1];
657                 final_force = shockwave_hit_force[i-1];
658                 final_damage = shockwave_hit_damage[i-1];
659
660                 Damage(
661                         head,
662                         actor,
663                         actor,
664                         final_damage,
665                         WEP_SHOCKWAVE.m_id,
666                         head.origin,
667                         final_force
668                 );
669
670                 if(accuracy_isgooddamage(actor, head))
671                         accuracy_add(actor, WEP_SHOCKWAVE.m_id, 0, final_damage);
672
673                 #ifdef DEBUG_SHOCKWAVE
674                 LOG_INFO(sprintf(
675                         "SHOCKWAVE by %s: damage = %f, force = %f.\n",
676                         actor.netname,
677                         final_damage,
678                         vlen(final_force)
679                 ));
680                 #endif
681
682                 shockwave_hit[i-1] = NULL;
683                 shockwave_hit_force[i-1] = '0 0 0';
684                 shockwave_hit_damage[i-1] = 0;
685         }
686
687         if(lag)
688         {
689                 FOREACH_CLIENT(IS_PLAYER(it) && it != actor, antilag_restore(it, CS(it)));
690                 FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, {
691                         if (it != actor)
692                                 antilag_restore(it, it);
693                 });
694         }
695 }
696
697 METHOD(Shockwave, wr_aim, void(entity thiswep, entity actor))
698 {
699     if(vdist(actor.origin - actor.enemy.origin, <=, WEP_CVAR(shockwave, melee_range)))
700         { PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, 1000000, 0, 0.001, false); }
701     else
702         { PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, 1000000, 0, 0.001, false); }
703 }
704 METHOD(Shockwave, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
705 {
706     if(fire & 1)
707     {
708         if(time >= actor.shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
709         {
710             if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime)))
711             {
712                 W_Shockwave_Attack(actor);
713                 actor.shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor(actor);
714                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
715             }
716         }
717     }
718     else if(fire & 2)
719     {
720         //if(actor.clip_load >= 0) // we are not currently reloading
721         if(!actor.crouch) // no crouchmelee please
722         if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire)))
723         {
724             // attempt forcing playback of the anim by switching to another anim (that we never play) here...
725             weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee);
726         }
727     }
728 }
729 METHOD(Shockwave, wr_checkammo1, bool(entity thiswep, entity actor))
730 {
731     return true; // infinite ammo
732 }
733 METHOD(Shockwave, wr_checkammo2, bool(entity thiswep, entity actor))
734 {
735     // shockwave has infinite ammo
736     return true;
737 }
738 METHOD(Shockwave, wr_suicidemessage, Notification(entity thiswep))
739 {
740     return WEAPON_THINKING_WITH_PORTALS;
741 }
742 METHOD(Shockwave, wr_killmessage, Notification(entity thiswep))
743 {
744     if(w_deathtype & HITTYPE_SECONDARY)
745         return WEAPON_SHOCKWAVE_MURDER_SLAP;
746     else
747         return WEAPON_SHOCKWAVE_MURDER;
748 }
749
750 #endif
751 #ifdef CSQC
752 // WEAPONTODO: add client side settings for these
753 const float SW_MAXALPHA = 0.5;
754 const float SW_FADETIME = 0.4;
755 const float SW_DISTTOMIN = 200;
756 void Draw_Shockwave(entity this)
757 {
758         // fading/removal control
759         float a = bound(0, (SW_MAXALPHA - ((time - this.sw_time) / SW_FADETIME)), SW_MAXALPHA);
760         if(a < ALPHA_MIN_VISIBLE) { remove(this); }
761
762         // WEAPONTODO: save this only once when creating the entity
763         vector sw_color = entcs_GetColor(this.sv_entnum - 1); // GetTeamRGB(entcs_GetTeam(this.sv_entnum));
764
765         // WEAPONTODO: trace to find what we actually hit
766         vector endpos = (this.sw_shotorg + (this.sw_shotdir * this.sw_distance));
767
768         vectorvectors(this.sw_shotdir);
769         vector right = v_right; // save this for when we do makevectors later
770         vector up = v_up; // save this for when we do makevectors later
771
772         // WEAPONTODO: combine and simplify these calculations
773         vector min_end = ((this.sw_shotorg + (this.sw_shotdir * SW_DISTTOMIN)) + (up * this.sw_spread_min));
774         vector max_end = (endpos + (up * this.sw_spread_max));
775         float spread_to_min = vlen(normalize(min_end - this.sw_shotorg) - this.sw_shotdir);
776         float spread_to_max = vlen(normalize(max_end - min_end) - this.sw_shotdir);
777
778         vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
779         vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
780         float new_max_dist, new_min_dist;
781
782         vector deviation, angle = '0 0 0';
783         float counter, divisions = 20;
784         for(counter = 0; counter < divisions; ++counter)
785         {
786                 // perfect circle effect lines
787                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
788                 angle.y = v_forward.x;
789                 angle.z = v_forward.y;
790
791                 // first do the spread_to_min effect
792                 deviation = angle * spread_to_min;
793                 deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
794                 new_min_dist = SW_DISTTOMIN;
795                 new_min_end = (this.sw_shotorg + (deviation * new_min_dist));
796                 //te_lightning2(NULL, new_min_end, this.sw_shotorg);
797
798                 // then calculate spread_to_max effect
799                 deviation = angle * spread_to_max;
800                 deviation = ((this.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
801                 new_max_dist = vlen(new_min_end - endpos);
802                 new_max_end = (new_min_end + (deviation * new_max_dist));
803                 //te_lightning2(NULL, new_end, prev_min_end);
804
805
806                 if(counter == 0)
807                 {
808                         first_min_end = new_min_end;
809                         first_max_end = new_max_end;
810                 }
811
812                 if(counter >= 1)
813                 {
814                         // draw from shot origin to min spread radius
815                         R_BeginPolygon("", DRAWFLAG_NORMAL);
816                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
817                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
818                         R_PolygonVertex(this.sw_shotorg, '0 0 0', sw_color, a);
819                         R_EndPolygon();
820
821                         // draw from min spread radius to max spread radius
822                         R_BeginPolygon("", DRAWFLAG_NORMAL);
823                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
824                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
825                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
826                         R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
827                         R_EndPolygon();
828                 }
829
830                 prev_min_end = new_min_end;
831                 prev_max_end = new_max_end;
832
833                 // last division only
834                 if((counter + 1) == divisions)
835                 {
836                         // draw from shot origin to min spread radius
837                         R_BeginPolygon("", DRAWFLAG_NORMAL);
838                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
839                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
840                         R_PolygonVertex(this.sw_shotorg, '0 0 0', sw_color, a);
841                         R_EndPolygon();
842
843                         // draw from min spread radius to max spread radius
844                         R_BeginPolygon("", DRAWFLAG_NORMAL);
845                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
846                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
847                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
848                         R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
849                         R_EndPolygon();
850                 }
851         }
852 }
853
854 NET_HANDLE(TE_CSQC_SHOCKWAVEPARTICLE, bool isNew)
855 {
856         Net_ReadShockwaveParticle();
857         return true;
858 }
859
860 void Net_ReadShockwaveParticle()
861 {
862         entity shockwave;
863         shockwave = spawn();
864         shockwave.draw = Draw_Shockwave;
865
866         shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
867         shockwave.sw_shotdir_x = ReadCoord(); shockwave.sw_shotdir_y = ReadCoord(); shockwave.sw_shotdir_z = ReadCoord();
868
869         shockwave.sw_distance = ReadShort();
870         shockwave.sw_spread_max = ReadByte();
871         shockwave.sw_spread_min = ReadByte();
872
873         shockwave.sv_entnum = ReadByte();
874
875         shockwave.sw_time = time;
876 }
877
878 METHOD(Shockwave, wr_impacteffect, void(entity thiswep, entity actor))
879 {
880     // handled by Net_ReadShockwaveParticle
881     //vector org2;
882     //org2 = w_org + w_backoff * 2;
883     //pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
884 }
885
886 #endif
887 #endif