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