]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_shockwave.qc
Fix spacing of register_weapon lists
[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 /* crosshair */ "gfx/crosshairshotgun 0.7",
12 /* netname   */ "shockwave",
13 /* fullname  */ _("Shockwave")
14 );
15
16 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
17 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
18         w_cvar(id, sn, NONE, blast_animtime) \
19         w_cvar(id, sn, NONE, blast_damage) \
20         w_cvar(id, sn, NONE, blast_distance) \
21         w_cvar(id, sn, NONE, blast_edgedamage) \
22         w_cvar(id, sn, NONE, blast_force) \
23         w_cvar(id, sn, NONE, blast_force_forwardbias) \
24         w_cvar(id, sn, NONE, blast_force_zscale) \
25         w_cvar(id, sn, NONE, blast_jump_damage) \
26         w_cvar(id, sn, NONE, blast_jump_edgedamage) \
27         w_cvar(id, sn, NONE, blast_jump_force) \
28         w_cvar(id, sn, NONE, blast_jump_force_velocitybias) \
29         w_cvar(id, sn, NONE, blast_jump_force_zscale) \
30         w_cvar(id, sn, NONE, blast_jump_multiplier_accuracy) \
31         w_cvar(id, sn, NONE, blast_jump_multiplier_distance) \
32         w_cvar(id, sn, NONE, blast_jump_multiplier_min) \
33         w_cvar(id, sn, NONE, blast_jump_radius) \
34         w_cvar(id, sn, NONE, blast_multiplier_accuracy) \
35         w_cvar(id, sn, NONE, blast_multiplier_distance) \
36         w_cvar(id, sn, NONE, blast_multiplier_min) \
37         w_cvar(id, sn, NONE, blast_refire) \
38         w_cvar(id, sn, NONE, blast_splash_damage) \
39         w_cvar(id, sn, NONE, blast_splash_edgedamage) \
40         w_cvar(id, sn, NONE, blast_splash_force) \
41         w_cvar(id, sn, NONE, blast_splash_force_forwardbias) \
42         w_cvar(id, sn, NONE, blast_splash_multiplier_accuracy) \
43         w_cvar(id, sn, NONE, blast_splash_multiplier_distance) \
44         w_cvar(id, sn, NONE, blast_splash_multiplier_min) \
45         w_cvar(id, sn, NONE, blast_splash_radius) \
46         w_cvar(id, sn, NONE, blast_spread_max) \
47         w_cvar(id, sn, NONE, blast_spread_min) \
48         w_cvar(id, sn, NONE, melee_animtime) \
49         w_cvar(id, sn, NONE, melee_damage) \
50         w_cvar(id, sn, NONE, melee_delay) \
51         w_cvar(id, sn, NONE, melee_force) \
52         w_cvar(id, sn, NONE, melee_multihit) \
53         w_cvar(id, sn, NONE, melee_no_doubleslap) \
54         w_cvar(id, sn, NONE, melee_nonplayerdamage) \
55         w_cvar(id, sn, NONE, melee_range) \
56         w_cvar(id, sn, NONE, melee_refire) \
57         w_cvar(id, sn, NONE, melee_swing_side) \
58         w_cvar(id, sn, NONE, melee_swing_up) \
59         w_cvar(id, sn, NONE, melee_time) \
60         w_cvar(id, sn, NONE, melee_traces) \
61         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
62         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
63         w_prop(id, sn, string, weaponreplace, weaponreplace) \
64         w_prop(id, sn, float,  weaponstart, weaponstart) \
65         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
66
67 #ifdef SVQC
68 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
69 #endif
70 #else
71 #ifdef SVQC
72 void spawnfunc_weapon_shockwave()
73 {
74         //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
75         if(autocvar_sv_q3acompat_machineshotgunswap)
76         if(self.classname != "droppedweapon")
77         {
78                 weapon_defaultspawnfunc(WEP_MACHINEGUN);
79                 return;
80         }
81         weapon_defaultspawnfunc(WEP_SHOCKWAVE);
82 }
83
84 #define MAX_SHOCKWAVE_HITS 10
85
86 .float swing_prev;
87 .entity swing_alreadyhit;
88 .float shockwave_blasttime;
89 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
90 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
91 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
92
93 // MELEE ATTACK MODE
94 void W_Shockwave_Melee_Think()
95 {
96         // declarations
97         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
98         entity target_victim;
99         vector targpos;
100
101         // check to see if we can still continue, otherwise give up now
102         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
103         {
104                 remove(self);
105                 return;
106         }
107
108         // set start time of melee
109         if(!self.cnt)
110         {
111                 self.cnt = time; 
112                 W_PlayStrengthSound(self.realowner);
113         }
114
115         // update values for v_* vectors
116         makevectors(self.realowner.v_angle);
117         
118         // calculate swing percentage based on time
119         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
120         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
121         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
122         
123         // perform the traces needed for this frame 
124         for(i=self.swing_prev; i < f; ++i)
125         {
126                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
127                 
128                 targpos = (self.realowner.origin + self.realowner.view_ofs 
129                         + (v_forward * WEP_CVAR(shockwave, melee_range))
130                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
131                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
132
133                 WarpZone_traceline_antilag(
134                         self.realowner,
135                         (self.realowner.origin + self.realowner.view_ofs),
136                         targpos,
137                         FALSE,
138                         self.realowner,
139                         ANTILAG_LATENCY(self.realowner)
140                 );
141                 
142                 // draw lightning beams for debugging
143                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); 
144                 te_customflash(targpos, 40,  2, '1 1 1');
145                 
146                 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
147
148                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
149                         && (trace_ent.takedamage == DAMAGE_AIM)  
150                         && (trace_ent != self.swing_alreadyhit)
151                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
152                 {
153                         target_victim = trace_ent; // so it persists through other calls
154                         
155                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
156                                 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
157                         else
158                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
159
160                         // trigger damage with this calculated info
161                         Damage(
162                                 target_victim,
163                                 self.realowner,
164                                 self.realowner, 
165                                 swing_damage,
166                                 (WEP_SHOCKWAVE | HITTYPE_SECONDARY), 
167                                 (self.realowner.origin + self.realowner.view_ofs), 
168                                 (v_forward * WEP_CVAR(shockwave, melee_force))
169                         );
170
171                         // handle accuracy
172                         if(accuracy_isgooddamage(self.realowner, target_victim))
173                                 { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
174
175                         #ifdef DEBUG_SHOCKWAVE
176                         print(sprintf(
177                                 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
178                                 self.realowner.netname,
179                                 target_victim.netname,
180                                 swing_damage,
181                                 swing_factor,
182                                 time
183                         ));
184                         #endif
185
186                         // allow multiple hits with one swing, but not against the same player twice
187                         if(WEP_CVAR(shockwave, melee_multihit))
188                         {
189                                 self.swing_alreadyhit = target_victim;
190                                 continue; // move along to next trace
191                         }
192                         else
193                         {
194                                 remove(self);
195                                 return;
196                         }
197                 }
198         }
199         
200         if(time >= self.cnt + meleetime)
201         {
202                 // melee is finished
203                 remove(self);
204                 return;
205         }
206         else
207         {
208                 // set up next frame 
209                 self.swing_prev = i;
210                 self.nextthink = time;
211         }
212 }
213
214 void W_Shockwave_Melee()
215 {
216         sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
217         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
218
219         entity meleetemp;
220         meleetemp = spawn();
221         meleetemp.owner = meleetemp.realowner = self;
222         meleetemp.think = W_Shockwave_Melee_Think;
223         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
224         W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
225 }
226
227 // SHOCKWAVE ATTACK MODE
228 float W_Shockwave_Attack_CheckSpread(
229         vector targetorg,
230         vector nearest_on_line,
231         vector sw_shotorg,
232         vector attack_endpos)
233 {
234         float spreadlimit;
235         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
236         float distance_from_line = vlen(targetorg - nearest_on_line);
237         
238         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
239         spreadlimit =
240                 (
241                         (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
242                         +
243                         (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
244                 );
245
246         if(
247                 (spreadlimit && (distance_from_line <= spreadlimit))
248                 &&
249                 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
250         )
251                 { return bound(0, (distance_from_line / spreadlimit), 1); }
252         else
253                 { return FALSE; }
254 }
255
256 float W_Shockwave_Attack_IsVisible(
257         entity head,
258         vector nearest_on_line,
259         vector sw_shotorg,
260         vector attack_endpos)
261 {
262         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
263         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
264         vector corner;
265         float i;
266
267         // STEP ONE: Check if the nearest point is clear
268         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
269         {
270                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
271                 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
272         }
273
274         // STEP TWO: Check if shotorg to center point is clear
275         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
276         {
277                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
278                 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
279         }
280
281         // STEP THREE: Check each corner to see if they are clear
282         for(i=1; i<=8; ++i)
283         {
284                 corner = get_corner_position(head, i);
285                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
286                 {
287                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
288                         if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
289                 }
290         }
291
292         return FALSE;
293 }
294
295 float W_Shockwave_Attack_CheckHit(
296         float queue,
297         entity head,
298         vector final_force,
299         float final_damage)
300 {
301         if(!head) { return FALSE; }
302         float i;
303         
304         for(i = 0; i <= queue; ++i)
305         {
306                 if(shockwave_hit[i] == head)
307                 {
308                         if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
309                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
310                         return FALSE;
311                 }
312         }
313
314         shockwave_hit[queue] = head;
315         shockwave_hit_force[queue] = final_force;
316         shockwave_hit_damage[queue] = final_damage;
317         return TRUE;
318 }
319
320 void W_Shockwave_Attack()
321 {
322         // declarations
323         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
324         float final_damage;
325         vector final_force, center, vel;
326         entity head;
327
328         float i, queue = 0;
329         
330         // set up the shot direction
331         W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
332         vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
333         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
334         vector attack_hitpos = trace_endpos;
335         float distance_to_end = vlen(w_shotorg - attack_endpos);
336         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
337         //entity transform = WarpZone_trace_transform;
338
339         // do the firing effect now
340         //SendCSQCShockwaveParticle(attack_endpos); // WEAPONTODO
341         Damage_DamageInfo(
342                 attack_hitpos,
343                 WEP_CVAR(shockwave, blast_splash_damage),
344                 WEP_CVAR(shockwave, blast_splash_edgedamage),
345                 WEP_CVAR(shockwave, blast_splash_radius),
346                 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
347                 WEP_SHOCKWAVE,
348                 0,
349                 self
350         );
351
352         // splash damage/jumping trace
353         head = WarpZone_FindRadius(
354                 attack_hitpos,
355                 max(
356                         WEP_CVAR(shockwave, blast_splash_radius),
357                         WEP_CVAR(shockwave, blast_jump_radius)
358                 ),
359                 FALSE
360         );
361         
362         while(head)
363         {
364                 if(head.takedamage)
365                 {
366                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
367                         
368                         if((head == self) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
369                         {
370                                 // ========================
371                                 //  BLAST JUMP CALCULATION
372                                 // ========================
373                                 
374                                 // calculate importance of distance and accuracy for this attack
375                                 multiplier_from_accuracy = (1 -
376                                         (distance_to_head ?
377                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
378                                                 :
379                                                 0
380                                         )
381                                 );
382                                 multiplier_from_distance = (1 -
383                                         (distance_to_hit ?
384                                                 min(1, (distance_to_hit / distance_to_end))
385                                                 :
386                                                 0
387                                         )
388                                 );
389                                 multiplier =
390                                         max(
391                                                 WEP_CVAR(shockwave, blast_jump_multiplier_min),
392                                                 (
393                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
394                                                         +
395                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
396                                                 )
397                                         );
398
399                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
400                                 final_damage =
401                                         (
402                                                 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
403                                                 +
404                                                 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
405                                         );
406
407                                 // figure out the direction of force
408                                 vel = normalize(combine_to_vector(head.velocity_x, head.velocity_y, 0));
409                                 vel *=
410                                         (
411                                                 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
412                                                 *
413                                                 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
414                                         );
415                                 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
416
417                                 // now multiply the direction by force units
418                                 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
419                                 final_force_z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
420
421                                 // trigger damage with this calculated info
422                                 Damage(
423                                         head,
424                                         self,
425                                         self,
426                                         final_damage,
427                                         WEP_SHOCKWAVE,
428                                         head.origin,
429                                         final_force
430                                 );
431
432                                 #ifdef DEBUG_SHOCKWAVE
433                                 print(sprintf(
434                                         "SELF HIT: multiplier = %f, damage = %f, force = %f... "
435                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
436                                         multiplier,
437                                         final_damage,
438                                         vlen(final_force),
439                                         multiplier_from_accuracy,
440                                         multiplier_from_distance
441                                 ));
442                                 #endif
443                         }
444                         else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
445                         {
446                                 // ==========================
447                                 //  BLAST SPLASH CALCULATION
448                                 // ==========================
449                                 
450                                 // calculate importance of distance and accuracy for this attack
451                                 multiplier_from_accuracy = (1 -
452                                         (distance_to_head ?
453                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
454                                                 :
455                                                 0
456                                         )
457                                 );
458                                 multiplier_from_distance = (1 -
459                                         (distance_to_hit ?
460                                                 min(1, (distance_to_hit / distance_to_end))
461                                                 :
462                                                 0
463                                         )
464                                 );
465                                 multiplier =
466                                         max(
467                                                 WEP_CVAR(shockwave, blast_splash_multiplier_min),
468                                                 (
469                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
470                                                         +
471                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
472                                                 )
473                                         );
474
475                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
476                                 final_damage =
477                                         (
478                                                 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
479                                                 +
480                                                 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
481                                         );
482
483                                 // figure out the direction of force
484                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
485                                 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
486                                 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
487
488                                 // now multiply the direction by force units
489                                 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
490                                 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
491
492                                 // queue damage with this calculated info
493                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
494
495                                 #ifdef DEBUG_SHOCKWAVE
496                                 print(sprintf(
497                                         "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
498                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
499                                         multiplier,
500                                         final_damage,
501                                         vlen(final_force),
502                                         multiplier_from_accuracy,
503                                         multiplier_from_distance
504                                 ));
505                                 #endif
506                         }
507                 }
508                 head = head.chain;
509         }
510
511         // cone damage trace
512         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), FALSE);
513         while(head)
514         {
515                 if((head != self) && head.takedamage)
516                 {
517                         // ========================
518                         //  BLAST CONE CALCULATION
519                         // ========================
520
521                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc) 
522                         center = CENTER_OR_VIEWOFS(head);
523
524                         // find the closest point on the enemy to the center of the attack
525                         float ang; // angle between shotdir and h
526                         float h; // hypotenuse, which is the distance between attacker to head
527                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
528                         
529                         h = vlen(center - self.origin);
530                         ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
531                         a = h * cos(ang);
532                         // WEAPONTODO: replace with simpler method
533
534                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
535                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
536
537                         if((vlen(head.WarpZone_findradius_dist) <= 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, (vlen(head.WarpZone_findradius_dist) / 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 = min(queue + 1, MAX_SHOCKWAVE_HITS); }
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 = 0; 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