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