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