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