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