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