]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_shockwave.qc
Remove shell ammo from Shockwave
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_shockwave.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ SHOCKWAVE,
4 /* function */ W_Shockwave,
5 /* ammotype */ ammo_none,
6 /* impulse  */ 2,
7 /* flags    */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating   */ BOT_PICKUP_RATING_LOW,
9 /* model    */ "shotgun",
10 /* netname  */ "shockwave",
11 /* fullname */ _("Shockwave")
12 );
13
14 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
15 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
16         w_cvar(id, sn, MO_NONE, blast_damage) \
17         w_cvar(id, sn, MO_NONE, blast_distance) \
18         w_cvar(id, sn, MO_NONE, blast_edgedamage) \
19         w_cvar(id, sn, MO_NONE, blast_force) \
20         w_cvar(id, sn, MO_NONE, blast_force_forwardbias) \
21         w_cvar(id, sn, MO_NONE, blast_force_zscale) \
22         w_cvar(id, sn, MO_NONE, blast_jump_damage) \
23         w_cvar(id, sn, MO_NONE, blast_jump_edgedamage) \
24         w_cvar(id, sn, MO_NONE, blast_jump_force) \
25         w_cvar(id, sn, MO_NONE, blast_jump_force_velocitybias) \
26         w_cvar(id, sn, MO_NONE, blast_jump_force_zscale) \
27         w_cvar(id, sn, MO_NONE, blast_jump_multiplier_accuracy) \
28         w_cvar(id, sn, MO_NONE, blast_jump_multiplier_distance) \
29         w_cvar(id, sn, MO_NONE, blast_jump_multiplier_min) \
30         w_cvar(id, sn, MO_NONE, blast_jump_radius) \
31         w_cvar(id, sn, MO_NONE, blast_multiplier_accuracy) \
32         w_cvar(id, sn, MO_NONE, blast_multiplier_distance) \
33         w_cvar(id, sn, MO_NONE, blast_multiplier_min) \
34         w_cvar(id, sn, MO_NONE, blast_splash_damage) \
35         w_cvar(id, sn, MO_NONE, blast_splash_edgedamage) \
36         w_cvar(id, sn, MO_NONE, blast_splash_force) \
37         w_cvar(id, sn, MO_NONE, blast_splash_force_forwardbias) \
38         w_cvar(id, sn, MO_NONE, blast_splash_multiplier_accuracy) \
39         w_cvar(id, sn, MO_NONE, blast_splash_multiplier_distance) \
40         w_cvar(id, sn, MO_NONE, blast_splash_multiplier_min) \
41         w_cvar(id, sn, MO_NONE, blast_splash_radius) \
42         w_cvar(id, sn, MO_NONE, blast_spread_max) \
43         w_cvar(id, sn, MO_NONE, blast_spread_min) \
44         w_cvar(id, sn, MO_NONE, melee_animtime) \
45         w_cvar(id, sn, MO_NONE, melee_damage) \
46         w_cvar(id, sn, MO_NONE, melee_delay) \
47         w_cvar(id, sn, MO_NONE, melee_force) \
48         w_cvar(id, sn, MO_NONE, melee_multihit) \
49         w_cvar(id, sn, MO_NONE, melee_no_doubleslap) \
50         w_cvar(id, sn, MO_NONE, melee_nonplayerdamage) \
51         w_cvar(id, sn, MO_NONE, melee_range) \
52         w_cvar(id, sn, MO_NONE, melee_refire) \
53         w_cvar(id, sn, MO_NONE, melee_swing_side) \
54         w_cvar(id, sn, MO_NONE, melee_swing_up) \
55         w_cvar(id, sn, MO_NONE, melee_time) \
56         w_cvar(id, sn, MO_NONE, melee_traces) \
57         w_cvar(id, sn, MO_NONE, pellets_animtime) \
58         w_cvar(id, sn, MO_NONE, pellets_bulletconstant) \
59         w_cvar(id, sn, MO_NONE, pellets_bullets) \
60         w_cvar(id, sn, MO_NONE, pellets_damage) \
61         w_cvar(id, sn, MO_NONE, pellets_force) \
62         w_cvar(id, sn, MO_NONE, pellets_refire) \
63         w_cvar(id, sn, MO_NONE, pellets_speed) \
64         w_cvar(id, sn, MO_NONE, pellets_spread) \
65         w_cvar(id, sn, MO_NONE, primary) \
66         w_cvar(id, sn, MO_NONE, secondary) \
67         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
68         w_prop(id, sn, float,  reloading_time, reload_time) \
69         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
70         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
71         w_prop(id, sn, string, weaponreplace, weaponreplace) \
72         w_prop(id, sn, float,  weaponstart, weaponstart) \
73         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
74
75 #ifdef SVQC
76 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
77 #endif
78 #else
79 #ifdef SVQC
80 void spawnfunc_weapon_shockwave()
81 {
82         //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
83         if(autocvar_sv_q3acompat_machineshotgunswap)
84         if(self.classname != "droppedweapon")
85         {
86                 weapon_defaultspawnfunc(WEP_UZI);
87                 return;
88         }
89         weapon_defaultspawnfunc(WEP_SHOCKWAVE);
90 }
91
92 .float swing_prev;
93 .entity swing_alreadyhit;
94 .float shockwave_pelletstime;
95 entity shockwave_hit[32];
96 float shockwave_hit_damage[32];
97 vector shockwave_hit_force[32];
98
99 // LEGACY ATTACK MODE: Scattered bullets
100 void W_Shockwave_Pellets(void)
101 {
102         float sc;
103         entity flash;
104
105         //W_DecreaseAmmo(ammo_shells, WEP_CVAR(shockwave, pellets_ammo), WEP_CVAR(shockwave, reload_ammo));
106
107         W_SetupShot(self, TRUE, 5, "weapons/shotgun_fire.wav", CH_WEAPON_A, WEP_CVAR(shockwave, pellets_damage) * WEP_CVAR(shockwave, pellets_bullets));
108         
109         for(sc = 0; sc < WEP_CVAR(shockwave, pellets_bullets); ++sc)
110         {
111                 fireBallisticBullet(
112                         w_shotorg,
113                         w_shotdir,
114                         WEP_CVAR(shockwave, pellets_spread),
115                         WEP_CVAR(shockwave, pellets_speed),
116                         5,
117                         WEP_CVAR(shockwave, pellets_damage),
118                         WEP_CVAR(shockwave, pellets_force),
119                         WEP_SHOCKWAVE,
120                         0,
121                         WEP_CVAR(shockwave, pellets_bulletconstant)
122                 );
123         }
124         endFireBallisticBullet();
125
126         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, 5); // WEAPONTODO: why 5? this was pellets_ammo before
127
128         // casing code
129         if(autocvar_g_casings >= 1)
130         {
131                 for(sc = 0;sc < 5; ++sc)
132                 {
133                         SpawnCasing(
134                                 (
135                                         ((random () * 50 + 50) * v_right)
136                                         -
137                                         (v_forward * (random () * 25 + 25))
138                                         -
139                                         ((random () * 5 - 30) * v_up)
140                                 ),
141                                 2,
142                                 vectoangles(v_forward),
143                                 '0 250 0',
144                                 100,
145                                 1,
146                                 self
147                         );
148                 }
149         }
150
151         // muzzle flash for 1st person view
152         flash = spawn();
153         setmodel(flash, "models/uziflash.md3"); // precision set below
154         flash.think = SUB_Remove;
155         flash.nextthink = time + 0.06;
156         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
157         W_AttachToShotorg(flash, '5 0 0');
158 }
159
160 // MELEE ATTACK MODE
161 void W_Shockwave_Melee_Think()
162 {
163         // declarations
164         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
165         entity target_victim;
166         vector targpos;
167
168         // check to see if we can still continue, otherwise give up now
169         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
170         {
171                 remove(self);
172                 return;
173         }
174
175         // set start time of melee
176         if(!self.cnt)
177         {
178                 self.cnt = time; 
179                 W_PlayStrengthSound(self.realowner);
180         }
181
182         // update values for v_* vectors
183         makevectors(self.realowner.v_angle);
184         
185         // calculate swing percentage based on time
186         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
187         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
188         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
189         
190         // perform the traces needed for this frame 
191         for(i=self.swing_prev; i < f; ++i)
192         {
193                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
194                 
195                 targpos = (self.realowner.origin + self.realowner.view_ofs 
196                         + (v_forward * WEP_CVAR(shockwave, melee_range))
197                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
198                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
199
200                 WarpZone_traceline_antilag(
201                         self.realowner,
202                         (self.realowner.origin + self.realowner.view_ofs),
203                         targpos,
204                         FALSE,
205                         self.realowner,
206                         ANTILAG_LATENCY(self.realowner)
207                 );
208                 
209                 // draw lightning beams for debugging
210                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); 
211                 te_customflash(targpos, 40,  2, '1 1 1');
212                 
213                 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
214
215                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
216                         && (trace_ent.takedamage == DAMAGE_AIM)  
217                         && (trace_ent != self.swing_alreadyhit)
218                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
219                 {
220                         target_victim = trace_ent; // so it persists through other calls
221                         
222                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
223                                 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
224                         else
225                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
226
227                         // trigger damage with this calculated info
228                         Damage(
229                                 target_victim,
230                                 self.realowner,
231                                 self.realowner, 
232                                 swing_damage,
233                                 (WEP_SHOCKWAVE | HITTYPE_SECONDARY), 
234                                 (self.realowner.origin + self.realowner.view_ofs), 
235                                 (v_forward * WEP_CVAR(shockwave, melee_force))
236                         );
237
238                         // handle accuracy
239                         if(accuracy_isgooddamage(self.realowner, target_victim))
240                                 { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
241
242                         #ifdef DEBUG_SHOCKWAVE
243                         print(sprintf(
244                                 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
245                                 self.realowner.netname,
246                                 target_victim.netname,
247                                 swing_damage,
248                                 swing_factor,
249                                 time
250                         ));
251                         #endif
252
253                         // allow multiple hits with one swing, but not against the same player twice
254                         if(WEP_CVAR(shockwave, melee_multihit))
255                         {
256                                 self.swing_alreadyhit = target_victim;
257                                 continue; // move along to next trace
258                         }
259                         else
260                         {
261                                 remove(self);
262                                 return;
263                         }
264                 }
265         }
266         
267         if(time >= self.cnt + meleetime)
268         {
269                 // melee is finished
270                 remove(self);
271                 return;
272         }
273         else
274         {
275                 // set up next frame 
276                 self.swing_prev = i;
277                 self.nextthink = time;
278         }
279 }
280
281 void W_Shockwave_Melee()
282 {
283         sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
284         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
285
286         entity meleetemp;
287         meleetemp = spawn();
288         meleetemp.owner = meleetemp.realowner = self;
289         meleetemp.think = W_Shockwave_Melee_Think;
290         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
291         W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
292 }
293
294 // SHOCKWAVE ATTACK MODE
295 float W_Shockwave_Attack_CheckSpread(
296         vector targetorg,
297         vector nearest_on_line,
298         vector sw_shotorg,
299         vector attack_endpos)
300 {
301         float spreadlimit;
302         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
303         float distance_from_line = vlen(targetorg - nearest_on_line);
304         
305         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
306         spreadlimit =
307                 (
308                         (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
309                         +
310                         (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
311                 );
312
313         if(
314                 (spreadlimit && (distance_from_line <= spreadlimit))
315                 &&
316                 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
317         )
318                 { return bound(0, (distance_from_line / spreadlimit), 1); }
319         else
320                 { return FALSE; }
321 }
322
323 float W_Shockwave_Attack_IsVisible(
324         entity head,
325         vector nearest_on_line,
326         vector sw_shotorg,
327         vector attack_endpos)
328 {
329         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
330         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
331         vector corner;
332         float i;
333
334         // STEP ONE: Check if the nearest point is clear
335         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
336         {
337                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
338                 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
339         }
340
341         // STEP TWO: Check if shotorg to center point is clear
342         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
343         {
344                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
345                 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
346         }
347
348         // STEP THREE: Check each corner to see if they are clear
349         for(i=1; i<=8; ++i)
350         {
351                 corner = get_corner_position(head, i);
352                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
353                 {
354                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
355                         if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
356                 }
357         }
358
359         return FALSE;
360 }
361
362 float W_Shockwave_Attack_CheckHit(
363         float queue,
364         entity head,
365         vector final_force,
366         float final_damage)
367 {
368         if(!head) { return FALSE; }
369         float i;
370
371         ++queue;
372         
373         for(i = 1; i <= queue; ++i)
374         {
375                 if(shockwave_hit[i] == head)
376                 {
377                         if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
378                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
379                         return FALSE;
380                 }
381         }
382
383         shockwave_hit[queue] = head;
384         shockwave_hit_force[queue] = final_force;
385         shockwave_hit_damage[queue] = final_damage;
386         return TRUE;
387 }
388
389 void W_Shockwave_Attack()
390 {
391         // declarations
392         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
393         float final_damage;
394         vector final_force, center, vel;
395         entity head;
396
397         float i, queue = 0;
398         
399         // set up the shot direction
400         W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
401         vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
402         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
403         vector attack_hitpos = trace_endpos;
404         float distance_to_end = vlen(w_shotorg - attack_endpos);
405         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
406         //entity transform = WarpZone_trace_transform;
407
408         // do the firing effect now
409         //SendCSQCShockwaveParticle(attack_endpos); // WEAPONTODO
410         Damage_DamageInfo(
411                 attack_hitpos,
412                 WEP_CVAR(shockwave, blast_splash_damage),
413                 WEP_CVAR(shockwave, blast_splash_edgedamage),
414                 WEP_CVAR(shockwave, blast_splash_radius),
415                 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
416                 WEP_SHOCKWAVE,
417                 0,
418                 self
419         );
420
421         // splash damage/jumping trace
422         head = WarpZone_FindRadius(
423                 attack_hitpos,
424                 max(
425                         WEP_CVAR(shockwave, blast_splash_radius),
426                         WEP_CVAR(shockwave, blast_jump_radius)
427                 ),
428                 FALSE
429         );
430         
431         while(head)
432         {
433                 if(head.takedamage)
434                 {
435                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
436                         
437                         if((head == self) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
438                         {
439                                 // ========================
440                                 //  BLAST JUMP CALCULATION
441                                 // ========================
442                                 
443                                 // calculate importance of distance and accuracy for this attack
444                                 multiplier_from_accuracy = (1 -
445                                         (distance_to_head ?
446                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
447                                                 :
448                                                 0
449                                         )
450                                 );
451                                 multiplier_from_distance = (1 -
452                                         (distance_to_hit ?
453                                                 min(1, (distance_to_hit / distance_to_end))
454                                                 :
455                                                 0
456                                         )
457                                 );
458                                 multiplier =
459                                         max(
460                                                 WEP_CVAR(shockwave, blast_jump_multiplier_min),
461                                                 (
462                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
463                                                         +
464                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
465                                                 )
466                                         );
467
468                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
469                                 final_damage =
470                                         (
471                                                 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
472                                                 +
473                                                 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
474                                         );
475
476                                 // figure out the direction of force
477                                 vel = normalize(combine_to_vector(head.velocity_x, head.velocity_y, 0));
478                                 vel *=
479                                         (
480                                                 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
481                                                 *
482                                                 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
483                                         );
484                                 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
485
486                                 // now multiply the direction by force units
487                                 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
488                                 final_force_z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
489
490                                 // trigger damage with this calculated info
491                                 Damage(
492                                         head,
493                                         self,
494                                         self,
495                                         final_damage,
496                                         WEP_SHOCKWAVE,
497                                         head.origin,
498                                         final_force
499                                 );
500
501                                 #ifdef DEBUG_SHOCKWAVE
502                                 print(sprintf(
503                                         "SELF HIT: multiplier = %f, damage = %f, force = %f... "
504                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
505                                         multiplier,
506                                         final_damage,
507                                         vlen(final_force),
508                                         multiplier_from_accuracy,
509                                         multiplier_from_distance
510                                 ));
511                                 #endif
512                         }
513                         else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
514                         {
515                                 // ==========================
516                                 //  BLAST SPLASH CALCULATION
517                                 // ==========================
518                                 
519                                 // calculate importance of distance and accuracy for this attack
520                                 multiplier_from_accuracy = (1 -
521                                         (distance_to_head ?
522                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
523                                                 :
524                                                 0
525                                         )
526                                 );
527                                 multiplier_from_distance = (1 -
528                                         (distance_to_hit ?
529                                                 min(1, (distance_to_hit / distance_to_end))
530                                                 :
531                                                 0
532                                         )
533                                 );
534                                 multiplier =
535                                         max(
536                                                 WEP_CVAR(shockwave, blast_splash_multiplier_min),
537                                                 (
538                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
539                                                         +
540                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
541                                                 )
542                                         );
543
544                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
545                                 final_damage =
546                                         (
547                                                 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
548                                                 +
549                                                 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
550                                         );
551
552                                 // figure out the direction of force
553                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
554                                 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
555                                 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
556
557                                 // now multiply the direction by force units
558                                 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
559                                 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
560
561                                 // queue damage with this calculated info
562                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
563
564                                 #ifdef DEBUG_SHOCKWAVE
565                                 print(sprintf(
566                                         "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
567                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
568                                         multiplier,
569                                         final_damage,
570                                         vlen(final_force),
571                                         multiplier_from_accuracy,
572                                         multiplier_from_distance
573                                 ));
574                                 #endif
575                         }
576                 }
577                 head = head.chain;
578         }
579
580         // cone damage trace
581         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), FALSE);
582         while(head)
583         {
584                 if((head != self) && head.takedamage)
585                 {
586                         // ========================
587                         //  BLAST CONE CALCULATION
588                         // ========================
589
590                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc) 
591                         center = CENTER_OR_VIEWOFS(head);
592
593                         // find the closest point on the enemy to the center of the attack
594                         float ang; // angle between shotdir and h
595                         float h; // hypotenuse, which is the distance between attacker to head
596                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
597                         
598                         h = vlen(center - self.origin);
599                         ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
600                         a = h * cos(ang);
601                         // WEAPONTODO: replace with simpler method
602
603                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
604                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
605                         float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // WEAPONTODO: use the findradius function for this
606
607                         if((distance_to_target <= WEP_CVAR(shockwave, blast_distance)) 
608                                 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
609                         {
610                                 // calculate importance of distance and accuracy for this attack
611                                 multiplier_from_accuracy = (1 -
612                                         W_Shockwave_Attack_CheckSpread(
613                                                 nearest_to_attacker,
614                                                 nearest_on_line,
615                                                 w_shotorg,
616                                                 attack_endpos
617                                         )
618                                 );
619                                 multiplier_from_distance = (1 -
620                                         (distance_to_hit ?
621                                                 min(1, (distance_to_target / distance_to_end))
622                                                 :
623                                                 0
624                                         )
625                                 );
626                                 multiplier =
627                                         max(
628                                                 WEP_CVAR(shockwave, blast_multiplier_min),
629                                                 (
630                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
631                                                         +
632                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
633                                                 )
634                                         );
635
636                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
637                                 final_damage =
638                                         (
639                                                 (WEP_CVAR(shockwave, blast_damage) * multiplier)
640                                                 +
641                                                 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
642                                         );
643
644                                 // figure out the direction of force
645                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
646                                 final_force = normalize(center - (nearest_on_line - final_force));
647                                 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
648
649                                 // now multiply the direction by force units
650                                 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
651                                 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
652
653                                 // queue damage with this calculated info
654                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
655
656                                 #ifdef DEBUG_SHOCKWAVE
657                                 print(sprintf(
658                                         "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
659                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
660                                         multiplier,
661                                         final_damage,
662                                         vlen(final_force),
663                                         multiplier_from_accuracy,
664                                         multiplier_from_distance
665                                 ));
666                                 #endif
667                         }
668                 }
669                 head = head.chain;
670         }
671
672         for(i = 1; i <= queue; ++i)
673         {
674                 head = shockwave_hit[i];
675                 final_force = shockwave_hit_force[i];
676                 final_damage = shockwave_hit_damage[i];
677                 
678                 Damage(
679                         head,
680                         self,
681                         self,
682                         final_damage,
683                         WEP_SHOCKWAVE,
684                         head.origin,
685                         final_force
686                 );
687                 
688                 #ifdef DEBUG_SHOCKWAVE
689                 print(sprintf(
690                         "SHOCKWAVE by %s: damage = %f, force = %f.\n",
691                         self.netname,
692                         final_damage,
693                         vlen(final_force)
694                 ));
695                 #endif
696                 
697                 shockwave_hit[i] = world;
698                 shockwave_hit_force[i] = '0 0 0';
699                 shockwave_hit_damage[i] = 0;
700         }
701 }
702
703 float W_Shockwave(float req)
704 {
705         switch(req)
706         {
707                 case WR_AIM:
708                 {
709                         if(vlen(self.origin - self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
710                                 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE); }
711                         else
712                                 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE); }
713                         
714                         return TRUE;
715                 }
716                 case WR_THINK:
717                 {
718                         if(self.BUTTON_ATCK)
719                         {
720                                 switch(WEP_CVAR(shockwave, primary))
721                                 {
722                                         case 1:
723                                         {
724                                                 if(time >= self.shockwave_pelletstime) // handle refire separately so the secondary can be fired straight after a primary
725                                                 {
726                                                         if(weapon_prepareattack(0, WEP_CVAR(shockwave, pellets_animtime)))
727                                                         {
728                                                                 W_Shockwave_Attack();
729                                                                 self.shockwave_pelletstime = time + WEP_CVAR(shockwave, pellets_refire) * W_WeaponRateFactor();
730                                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(shockwave, pellets_animtime), w_ready);
731                                                         }
732                                                 }
733                                                 break;
734                                         }
735                                         case 2:
736                                         {
737                                                 if(time >= self.shockwave_pelletstime) // handle refire separately so the secondary can be fired straight after a primary
738                                                 {
739                                                         if(weapon_prepareattack(0, WEP_CVAR(shockwave, pellets_animtime)))
740                                                         {
741                                                                 W_Shockwave_Pellets();
742                                                                 self.shockwave_pelletstime = time + WEP_CVAR(shockwave, pellets_refire) * W_WeaponRateFactor();
743                                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(shockwave, pellets_animtime), w_ready);
744                                                         }
745                                                 }
746                                                 break;
747                                         }
748                                 }
749                         }
750                         
751                         if(self.clip_load >= 0) // we are not currently reloading
752                         if(!self.crouch) // no crouchmelee please
753                         if(self.BUTTON_ATCK2 && WEP_CVAR(shockwave, secondary))
754                         if(weapon_prepareattack(1, WEP_CVAR(shockwave, melee_refire)))
755                         {
756                                 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
757                                 weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
758                         }
759
760                         return TRUE;
761                 }
762                 case WR_INIT:
763                 {
764                         precache_model("models/uziflash.md3");
765                         precache_model("models/weapons/g_shockwave.md3");
766                         precache_model("models/weapons/v_shockwave.md3");
767                         precache_model("models/weapons/h_shockwave.iqm");
768                         precache_sound("misc/itempickup.wav");
769                         precache_sound("weapons/shockwave_fire.wav");
770                         precache_sound("weapons/shockwave_melee.wav");
771                         SHOCKWAVE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
772                         return TRUE;
773                 }
774                 case WR_CHECKAMMO1:
775                 case WR_CHECKAMMO2:
776                 {
777                         // shockwave has infinite ammo
778                         return TRUE;
779                 }
780                 case WR_CONFIG:
781                 {
782                         SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
783                         return TRUE;
784                 }
785                 case WR_RELOAD:
786                 {
787                         W_Reload(0, "weapons/reload.wav");
788                         return TRUE;
789                 }
790                 case WR_SUICIDEMESSAGE:
791                 {
792                         return WEAPON_THINKING_WITH_PORTALS;
793                 }
794                 case WR_KILLMESSAGE:
795                 {
796                         if(w_deathtype & HITTYPE_SECONDARY)
797                                 return WEAPON_SHOCKWAVE_MURDER_SLAP;
798                         else
799                                 return WEAPON_SHOCKWAVE_MURDER;
800                 }
801         }
802         return TRUE;
803 }
804 #endif
805 #ifdef CSQC
806 float W_Shockwave(float req)
807 {
808         switch(req)
809         {
810                 case WR_IMPACTEFFECT:
811                 {
812                         vector org2;
813                         org2 = w_org + w_backoff * 2;
814                         pointparticles(particleeffectnum("shockwave_impact"), org2, w_backoff * 1000, 1);
815                         return TRUE;
816                 }
817                 case WR_INIT:
818                 {
819                         //precache_sound("weapons/ric1.wav");
820                         //precache_sound("weapons/ric2.wav");
821                         //precache_sound("weapons/ric3.wav");
822                         return FALSE;
823                 }
824         }
825         return TRUE;
826 }
827 #endif
828 #endif