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