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