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