]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_shockwave.qc
Add define for MAX_SHOCKWAVE_HITS
[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 /* model    */ "shotgun",
11 /* netname  */ "shockwave",
12 /* fullname */ _("Shockwave")
13 );
14
15 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
16 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
17         w_cvar(id, sn, NONE, blast_animtime) \
18         w_cvar(id, sn, NONE, blast_damage) \
19         w_cvar(id, sn, NONE, blast_distance) \
20         w_cvar(id, sn, NONE, blast_edgedamage) \
21         w_cvar(id, sn, NONE, blast_force) \
22         w_cvar(id, sn, NONE, blast_force_forwardbias) \
23         w_cvar(id, sn, NONE, blast_force_zscale) \
24         w_cvar(id, sn, NONE, blast_jump_damage) \
25         w_cvar(id, sn, NONE, blast_jump_edgedamage) \
26         w_cvar(id, sn, NONE, blast_jump_force) \
27         w_cvar(id, sn, NONE, blast_jump_force_velocitybias) \
28         w_cvar(id, sn, NONE, blast_jump_force_zscale) \
29         w_cvar(id, sn, NONE, blast_jump_multiplier_accuracy) \
30         w_cvar(id, sn, NONE, blast_jump_multiplier_distance) \
31         w_cvar(id, sn, NONE, blast_jump_multiplier_min) \
32         w_cvar(id, sn, NONE, blast_jump_radius) \
33         w_cvar(id, sn, NONE, blast_multiplier_accuracy) \
34         w_cvar(id, sn, NONE, blast_multiplier_distance) \
35         w_cvar(id, sn, NONE, blast_multiplier_min) \
36         w_cvar(id, sn, NONE, blast_refire) \
37         w_cvar(id, sn, NONE, blast_splash_damage) \
38         w_cvar(id, sn, NONE, blast_splash_edgedamage) \
39         w_cvar(id, sn, NONE, blast_splash_force) \
40         w_cvar(id, sn, NONE, blast_splash_force_forwardbias) \
41         w_cvar(id, sn, NONE, blast_splash_multiplier_accuracy) \
42         w_cvar(id, sn, NONE, blast_splash_multiplier_distance) \
43         w_cvar(id, sn, NONE, blast_splash_multiplier_min) \
44         w_cvar(id, sn, NONE, blast_splash_radius) \
45         w_cvar(id, sn, NONE, blast_spread_max) \
46         w_cvar(id, sn, NONE, blast_spread_min) \
47         w_cvar(id, sn, NONE, melee_animtime) \
48         w_cvar(id, sn, NONE, melee_damage) \
49         w_cvar(id, sn, NONE, melee_delay) \
50         w_cvar(id, sn, NONE, melee_force) \
51         w_cvar(id, sn, NONE, melee_multihit) \
52         w_cvar(id, sn, NONE, melee_no_doubleslap) \
53         w_cvar(id, sn, NONE, melee_nonplayerdamage) \
54         w_cvar(id, sn, NONE, melee_range) \
55         w_cvar(id, sn, NONE, melee_refire) \
56         w_cvar(id, sn, NONE, melee_swing_side) \
57         w_cvar(id, sn, NONE, melee_swing_up) \
58         w_cvar(id, sn, NONE, melee_time) \
59         w_cvar(id, sn, NONE, melee_traces) \
60         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
61         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
62         w_prop(id, sn, string, weaponreplace, weaponreplace) \
63         w_prop(id, sn, float,  weaponstart, weaponstart) \
64         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
65
66 #ifdef SVQC
67 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
68 #endif
69 #else
70 #ifdef SVQC
71 void spawnfunc_weapon_shockwave()
72 {
73         //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
74         if(autocvar_sv_q3acompat_machineshotgunswap)
75         if(self.classname != "droppedweapon")
76         {
77                 weapon_defaultspawnfunc(WEP_MACHINEGUN);
78                 return;
79         }
80         weapon_defaultspawnfunc(WEP_SHOCKWAVE);
81 }
82
83 #define MAX_SHOCKWAVE_HITS 5
84
85 .float swing_prev;
86 .entity swing_alreadyhit;
87 .float shockwave_blasttime;
88 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
89 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
90 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
91
92 // MELEE ATTACK MODE
93 void W_Shockwave_Melee_Think()
94 {
95         // declarations
96         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
97         entity target_victim;
98         vector targpos;
99
100         // check to see if we can still continue, otherwise give up now
101         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
102         {
103                 remove(self);
104                 return;
105         }
106
107         // set start time of melee
108         if(!self.cnt)
109         {
110                 self.cnt = time; 
111                 W_PlayStrengthSound(self.realowner);
112         }
113
114         // update values for v_* vectors
115         makevectors(self.realowner.v_angle);
116         
117         // calculate swing percentage based on time
118         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
119         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
120         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
121         
122         // perform the traces needed for this frame 
123         for(i=self.swing_prev; i < f; ++i)
124         {
125                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
126                 
127                 targpos = (self.realowner.origin + self.realowner.view_ofs 
128                         + (v_forward * WEP_CVAR(shockwave, melee_range))
129                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
130                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
131
132                 WarpZone_traceline_antilag(
133                         self.realowner,
134                         (self.realowner.origin + self.realowner.view_ofs),
135                         targpos,
136                         FALSE,
137                         self.realowner,
138                         ANTILAG_LATENCY(self.realowner)
139                 );
140                 
141                 // draw lightning beams for debugging
142                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); 
143                 te_customflash(targpos, 40,  2, '1 1 1');
144                 
145                 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
146
147                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
148                         && (trace_ent.takedamage == DAMAGE_AIM)  
149                         && (trace_ent != self.swing_alreadyhit)
150                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
151                 {
152                         target_victim = trace_ent; // so it persists through other calls
153                         
154                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
155                                 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
156                         else
157                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
158
159                         // trigger damage with this calculated info
160                         Damage(
161                                 target_victim,
162                                 self.realowner,
163                                 self.realowner, 
164                                 swing_damage,
165                                 (WEP_SHOCKWAVE | HITTYPE_SECONDARY), 
166                                 (self.realowner.origin + self.realowner.view_ofs), 
167                                 (v_forward * WEP_CVAR(shockwave, melee_force))
168                         );
169
170                         // handle accuracy
171                         if(accuracy_isgooddamage(self.realowner, target_victim))
172                                 { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
173
174                         #ifdef DEBUG_SHOCKWAVE
175                         print(sprintf(
176                                 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
177                                 self.realowner.netname,
178                                 target_victim.netname,
179                                 swing_damage,
180                                 swing_factor,
181                                 time
182                         ));
183                         #endif
184
185                         // allow multiple hits with one swing, but not against the same player twice
186                         if(WEP_CVAR(shockwave, melee_multihit))
187                         {
188                                 self.swing_alreadyhit = target_victim;
189                                 continue; // move along to next trace
190                         }
191                         else
192                         {
193                                 remove(self);
194                                 return;
195                         }
196                 }
197         }
198         
199         if(time >= self.cnt + meleetime)
200         {
201                 // melee is finished
202                 remove(self);
203                 return;
204         }
205         else
206         {
207                 // set up next frame 
208                 self.swing_prev = i;
209                 self.nextthink = time;
210         }
211 }
212
213 void W_Shockwave_Melee()
214 {
215         sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
216         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
217
218         entity meleetemp;
219         meleetemp = spawn();
220         meleetemp.owner = meleetemp.realowner = self;
221         meleetemp.think = W_Shockwave_Melee_Think;
222         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
223         W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
224 }
225
226 // SHOCKWAVE ATTACK MODE
227 float W_Shockwave_Attack_CheckSpread(
228         vector targetorg,
229         vector nearest_on_line,
230         vector sw_shotorg,
231         vector attack_endpos)
232 {
233         float spreadlimit;
234         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
235         float distance_from_line = vlen(targetorg - nearest_on_line);
236         
237         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
238         spreadlimit =
239                 (
240                         (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
241                         +
242                         (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
243                 );
244
245         if(
246                 (spreadlimit && (distance_from_line <= spreadlimit))
247                 &&
248                 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
249         )
250                 { return bound(0, (distance_from_line / spreadlimit), 1); }
251         else
252                 { return FALSE; }
253 }
254
255 float W_Shockwave_Attack_IsVisible(
256         entity head,
257         vector nearest_on_line,
258         vector sw_shotorg,
259         vector attack_endpos)
260 {
261         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
262         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
263         vector corner;
264         float i;
265
266         // STEP ONE: Check if the nearest point is clear
267         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
268         {
269                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
270                 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
271         }
272
273         // STEP TWO: Check if shotorg to center point is clear
274         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
275         {
276                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
277                 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
278         }
279
280         // STEP THREE: Check each corner to see if they are clear
281         for(i=1; i<=8; ++i)
282         {
283                 corner = get_corner_position(head, i);
284                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
285                 {
286                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
287                         if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
288                 }
289         }
290
291         return FALSE;
292 }
293
294 float W_Shockwave_Attack_CheckHit(
295         float queue,
296         entity head,
297         vector final_force,
298         float final_damage)
299 {
300         if(!head) { return FALSE; }
301         float i;
302
303         ++queue;
304         
305         for(i = 1; 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; }
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                         float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // WEAPONTODO: use the findradius function for this
538
539                         if((distance_to_target <= WEP_CVAR(shockwave, blast_distance)) 
540                                 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
541                         {
542                                 // calculate importance of distance and accuracy for this attack
543                                 multiplier_from_accuracy = (1 -
544                                         W_Shockwave_Attack_CheckSpread(
545                                                 nearest_to_attacker,
546                                                 nearest_on_line,
547                                                 w_shotorg,
548                                                 attack_endpos
549                                         )
550                                 );
551                                 multiplier_from_distance = (1 -
552                                         (distance_to_hit ?
553                                                 min(1, (distance_to_target / distance_to_end))
554                                                 :
555                                                 0
556                                         )
557                                 );
558                                 multiplier =
559                                         max(
560                                                 WEP_CVAR(shockwave, blast_multiplier_min),
561                                                 (
562                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
563                                                         +
564                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
565                                                 )
566                                         );
567
568                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
569                                 final_damage =
570                                         (
571                                                 (WEP_CVAR(shockwave, blast_damage) * multiplier)
572                                                 +
573                                                 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
574                                         );
575
576                                 // figure out the direction of force
577                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
578                                 final_force = normalize(center - (nearest_on_line - final_force));
579                                 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
580
581                                 // now multiply the direction by force units
582                                 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
583                                 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
584
585                                 // queue damage with this calculated info
586                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
587
588                                 #ifdef DEBUG_SHOCKWAVE
589                                 print(sprintf(
590                                         "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
591                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
592                                         multiplier,
593                                         final_damage,
594                                         vlen(final_force),
595                                         multiplier_from_accuracy,
596                                         multiplier_from_distance
597                                 ));
598                                 #endif
599                         }
600                 }
601                 head = head.chain;
602         }
603
604         for(i = 1; i <= queue; ++i)
605         {
606                 head = shockwave_hit[i];
607                 final_force = shockwave_hit_force[i];
608                 final_damage = shockwave_hit_damage[i];
609                 
610                 Damage(
611                         head,
612                         self,
613                         self,
614                         final_damage,
615                         WEP_SHOCKWAVE,
616                         head.origin,
617                         final_force
618                 );
619                 
620                 #ifdef DEBUG_SHOCKWAVE
621                 print(sprintf(
622                         "SHOCKWAVE by %s: damage = %f, force = %f.\n",
623                         self.netname,
624                         final_damage,
625                         vlen(final_force)
626                 ));
627                 #endif
628                 
629                 shockwave_hit[i] = world;
630                 shockwave_hit_force[i] = '0 0 0';
631                 shockwave_hit_damage[i] = 0;
632         }
633 }
634
635 float W_Shockwave(float req)
636 {
637         switch(req)
638         {
639                 case WR_AIM:
640                 {
641                         if(vlen(self.origin - self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
642                                 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE); }
643                         else
644                                 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE); }
645                         
646                         return TRUE;
647                 }
648                 case WR_THINK:
649                 {
650                         if(self.BUTTON_ATCK)
651                         {
652                                 if(time >= self.shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
653                                 {
654                                         if(weapon_prepareattack(0, WEP_CVAR(shockwave, blast_animtime)))
655                                         {
656                                                 W_Shockwave_Attack();
657                                                 self.shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor();
658                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
659                                         }
660                                 }
661                         }
662                         else if(self.BUTTON_ATCK2)
663                         {
664                                 //if(self.clip_load >= 0) // we are not currently reloading
665                                 if(!self.crouch) // no crouchmelee please
666                                 if(weapon_prepareattack(1, WEP_CVAR(shockwave, melee_refire)))
667                                 {
668                                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
669                                         weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
670                                 }
671                         }
672                         
673                         return TRUE;
674                 }
675                 case WR_INIT:
676                 {
677                         precache_model("models/uziflash.md3");
678                         precache_model("models/weapons/g_shockwave.md3");
679                         precache_model("models/weapons/v_shockwave.md3");
680                         precache_model("models/weapons/h_shockwave.iqm");
681                         precache_sound("misc/itempickup.wav");
682                         precache_sound("weapons/shockwave_fire.wav");
683                         precache_sound("weapons/shockwave_melee.wav");
684                         SHOCKWAVE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
685                         return TRUE;
686                 }
687                 case WR_CHECKAMMO1:
688                 case WR_CHECKAMMO2:
689                 {
690                         // shockwave has infinite ammo
691                         return TRUE;
692                 }
693                 case WR_CONFIG:
694                 {
695                         SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
696                         return TRUE;
697                 }
698                 case WR_SUICIDEMESSAGE:
699                 {
700                         return WEAPON_THINKING_WITH_PORTALS;
701                 }
702                 case WR_KILLMESSAGE:
703                 {
704                         if(w_deathtype & HITTYPE_SECONDARY)
705                                 return WEAPON_SHOCKWAVE_MURDER_SLAP;
706                         else
707                                 return WEAPON_SHOCKWAVE_MURDER;
708                 }
709         }
710         return TRUE;
711 }
712 #endif
713 #ifdef CSQC
714 float W_Shockwave(float req)
715 {
716         switch(req)
717         {
718                 case WR_IMPACTEFFECT:
719                 {
720                         vector org2;
721                         org2 = w_org + w_backoff * 2;
722                         pointparticles(particleeffectnum("shockwave_impact"), org2, w_backoff * 1000, 1);
723                         return TRUE;
724                 }
725                 case WR_INIT:
726                 {
727                         //precache_sound("weapons/ric1.wav");
728                         //precache_sound("weapons/ric2.wav");
729                         //precache_sound("weapons/ric3.wav");
730                         return FALSE;
731                 }
732                 case WR_ZOOMRETICLE:
733                 {
734                         // no weapon specific image for this weapon
735                         return FALSE;
736                 }
737         }
738         return TRUE;
739 }
740 #endif
741 #endif