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