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