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