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