]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_shockwave.qc
Merge branch 'samual/weapons' of http://nl.git.xonotic.org/xonotic/xonotic-data.pk3di...
[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 */ IT_SHELLS,
6 /* impulse  */ 2,
7 /* flags    */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating   */ BOT_PICKUP_RATING_LOW,
9 /* model    */ "shotgun",
10 /* netname  */ "shockwave",
11 /* fullname */ _("Shockwave")
12 );
13
14 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) \
15         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_damage) \
16         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_distance) \
17         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_edgedamage) \
18         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_force) \
19         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_force_forwardbias) \
20         /*w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_force_velocitybias)*/ \
21         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_force_zscale) \
22         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_damage) \
23         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_edgedamage) \
24         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_force) \
25         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_force_velocitybias) \
26         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_force_zscale) \
27         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_multiplier_accuracy) \
28         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_multiplier_distance) \
29         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_multiplier_min) \
30         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_jump_radius) \
31         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_multiplier_accuracy) \
32         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_multiplier_distance) \
33         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_multiplier_min) \
34         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_damage) \
35         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_edgedamage) \
36         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_force) \
37         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_force_forwardbias) \
38         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_multiplier_accuracy) \
39         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_multiplier_distance) \
40         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_multiplier_min) \
41         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_splash_radius) \
42         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_spread_max) \
43         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, blast_spread_min) \
44         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_animtime) \
45         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_damage) \
46         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_delay) \
47         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_force) \
48         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_multihit) \
49         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_no_doubleslap) \
50         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_nonplayerdamage) \
51         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_range) \
52         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_refire) \
53         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_swing_side) \
54         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_swing_up) \
55         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_time) \
56         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, melee_traces) \
57         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_ammo) \
58         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_animtime) \
59         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_bulletconstant) \
60         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_bullets) \
61         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_damage) \
62         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_force) \
63         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_refire) \
64         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_speed) \
65         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, pellets_spread) \
66         w_cvar(WEP_SHOCKWAVE, shockwave, MO_NONE, secondary) \
67         w_prop(WEP_SHOCKWAVE, shockwave, reloading_ammo, reload_ammo) \
68         w_prop(WEP_SHOCKWAVE, shockwave, reloading_time, reload_time) \
69         w_prop(WEP_SHOCKWAVE, shockwave, switchdelay_raise, switchdelay_raise) \
70         w_prop(WEP_SHOCKWAVE, shockwave, switchdelay_drop, switchdelay_drop)
71
72 #ifdef SVQC
73 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
74 #endif
75 #else
76 #ifdef SVQC
77 void spawnfunc_weapon_shockwave()
78 {
79         //if(autocvar_sv_q3acompat_machineshockwaveswap)
80         if(autocvar_sv_q3acompat_machineshotgunswap)
81         if(self.classname != "droppedweapon")
82         {
83                 weapon_defaultspawnfunc(WEP_UZI);
84                 return;
85         }
86         weapon_defaultspawnfunc(WEP_SHOCKWAVE);
87 }
88
89 .float swing_prev;
90 .entity swing_alreadyhit;
91 .float shockwave_pelletstime;
92 entity shockwave_hit[32];
93 float shockwave_hit_damage[32];
94 vector shockwave_hit_force[32];
95
96 // LEGACY ATTACK MODE: Scattered bullets
97 void W_Shockwave_Pellets(void)
98 {
99         float sc;
100         float ammoamount;
101         float bullets;
102         float d;
103         float f;
104         float spread;
105         float bulletspeed;
106         float bulletconstant;
107         entity flash;
108
109         ammoamount = autocvar_g_balance_shockwave_pellets_ammo;
110         bullets = autocvar_g_balance_shockwave_pellets_bullets;
111         d = autocvar_g_balance_shockwave_pellets_damage;
112         f = autocvar_g_balance_shockwave_pellets_force;
113         spread = autocvar_g_balance_shockwave_pellets_spread;
114         bulletspeed = autocvar_g_balance_shockwave_pellets_speed;
115         bulletconstant = autocvar_g_balance_shockwave_pellets_bulletconstant;
116
117         W_DecreaseAmmo(ammo_shells, ammoamount, autocvar_g_balance_shockwave_reload_ammo);
118
119         W_SetupShot(self, TRUE, 5, "weapons/shockwave_fire.wav", CH_WEAPON_A, d * bullets);
120         for(sc = 0;sc < bullets;sc = sc + 1)
121                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, f, WEP_SHOCKWAVE, 0, bulletconstant);
122         endFireBallisticBullet();
123
124         pointparticles(particleeffectnum("shockwave_muzzleflash"), w_shotorg, w_shotdir * 1000, autocvar_g_balance_shockwave_pellets_ammo);
125
126         // casing code
127         if(autocvar_g_casings >= 1)
128                 for(sc = 0;sc < ammoamount;sc = sc + 1)
129                         SpawnCasing(((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, self);
130
131         // muzzle flash for 1st person view
132         flash = spawn();
133         setmodel(flash, "models/uziflash.md3"); // precision set below
134         flash.think = SUB_Remove;
135         flash.nextthink = time + 0.06;
136         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
137         W_AttachToShotorg(flash, '5 0 0');
138 }
139
140 // MELEE ATTACK MODE
141 void W_Shockwave_Melee_Think()
142 {
143         // declarations
144         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
145         entity target_victim;
146         vector targpos;
147
148         if(!self.cnt) // set start time of melee
149         {
150                 self.cnt = time; 
151                 W_PlayStrengthSound(self.realowner);
152         }
153
154         makevectors(self.realowner.v_angle); // update values for v_* vectors
155         
156         // calculate swing percentage based on time
157         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
158         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
159         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
160         
161         // check to see if we can still continue, otherwise give up now
162         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
163         {
164                 remove(self);
165                 return;
166         }
167         
168         // if okay, perform the traces needed for this frame 
169         for(i=self.swing_prev; i < f; ++i)
170         {
171                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
172                 
173                 targpos = (self.realowner.origin + self.realowner.view_ofs 
174                         + (v_forward * WEP_CVAR(shockwave, melee_range))
175                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
176                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
177
178                 WarpZone_traceline_antilag(self.realowner, self.realowner.origin + self.realowner.view_ofs, targpos, FALSE, self.realowner, ANTILAG_LATENCY(self.realowner));
179                 
180                 // draw lightning beams for debugging
181                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); 
182                 te_customflash(targpos, 40,  2, '1 1 1');
183                 
184                 is_player = (trace_ent.classname == "player" || trace_ent.classname == "body");
185
186                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self
187                         && (trace_ent.takedamage == DAMAGE_AIM)  
188                         && (trace_ent != self.swing_alreadyhit)
189                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
190                 {
191                         target_victim = trace_ent; // so it persists through other calls
192                         
193                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught.
194                                 swing_damage = (WEP_CVAR(shockwave, melee_damage * min(1, swing_factor + 1)));
195                         else
196                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage * min(1, swing_factor + 1)));
197                         
198                         //print(strcat(self.realowner.netname, " hitting ", target_victim.netname, " with ", strcat(ftos(swing_damage), " damage (factor: ", ftos(swing_factor), ") at "), ftos(time), " seconds.\n"));
199                         
200                         Damage(target_victim, self.realowner, self.realowner, 
201                                 swing_damage, WEP_SHOCKWAVE | HITTYPE_SECONDARY, 
202                                 self.realowner.origin + self.realowner.view_ofs, 
203                                 v_forward * WEP_CVAR(shockwave, melee_force));
204                                 
205                         if(accuracy_isgooddamage(self.realowner, target_victim)) { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
206                         
207                         if(WEP_CVAR(shockwave, melee_multihit)) // allow multiple hits with one swing, but not against the same player twice.
208                         {
209                                 self.swing_alreadyhit = target_victim;
210                                 continue; // move along to next trace
211                         }
212                         else
213                         {
214                                 remove(self);
215                                 return;
216                         }
217                 }
218         }
219         
220         if(time >= self.cnt + meleetime)
221         {
222                 // melee is finished
223                 remove(self);
224                 return;
225         }
226         else
227         {
228                 // set up next frame 
229                 self.swing_prev = i;
230                 self.nextthink = time;
231         }
232 }
233
234 void W_Shockwave_Melee()
235 {
236         sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
237         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
238
239         entity meleetemp;
240         meleetemp = spawn();
241         meleetemp.owner = meleetemp.realowner = self;
242         meleetemp.think = W_Shockwave_Melee_Think;
243         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
244         W_SetupShot_Range(self, TRUE, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
245 }
246
247 // SHOCKWAVE ATTACK MODE
248 float W_Shockwave_Attack_CheckSpread(
249         vector targetorg,
250         vector nearest_on_line,
251         vector sw_shotorg,
252         vector attack_endpos)
253 {
254         float spreadlimit;
255         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
256         float distance_from_line = vlen(targetorg - nearest_on_line);
257         
258         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
259         spreadlimit = (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit) + WEP_CVAR(shockwave, blast_spread_max) * spreadlimit);
260         
261         if(
262                 (spreadlimit && (distance_from_line <= spreadlimit))
263                 &&
264                 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
265         )
266                 { return bound(0, (distance_from_line / spreadlimit), 1); }
267         else
268                 { return FALSE; }
269 }
270
271 float W_Shockwave_Attack_IsVisible(
272         entity head,
273         vector nearest_on_line,
274         vector sw_shotorg,
275         vector attack_endpos)
276 {
277         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
278         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
279         vector corner;
280         float i;
281
282         // STEP ONE: Check if the nearest point is clear
283         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
284         {
285                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
286                 if(trace_fraction == 1) { return TRUE; } // yes, the nearest point is clear and we can allow the damage
287         }
288
289         // STEP TWO: Check if shotorg to center point is clear
290         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
291         {
292                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
293                 if(trace_fraction == 1) { return TRUE; } // yes, the center point is clear and we can allow the damage
294         }
295
296         // STEP THREE: Check each corner to see if they are clear
297         for(i=1; i<=8; ++i)
298         {
299                 corner = get_corner_position(head, i);
300                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
301                 {
302                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
303                         if(trace_fraction == 1) { return TRUE; } // yes, this corner is clear and we can allow the damage
304                 }
305         }
306
307         return FALSE;
308 }
309
310 float W_Shockwave_Attack_CheckHit(
311         float queue,
312         entity head,
313         vector final_force,
314         float final_damage)
315 {
316         if not(head) { return FALSE; }
317         float i;
318
319         ++queue;
320         
321         for(i = 1; i <= queue; ++i)
322         {
323                 if(shockwave_hit[i] == head)
324                 {
325                         if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
326                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
327                         return FALSE;
328                 }
329         }
330
331         shockwave_hit[queue] = head;
332         shockwave_hit_force[queue] = final_force;
333         shockwave_hit_damage[queue] = final_damage;
334         return TRUE;
335 }
336
337 void W_Shockwave_Attack()
338 {
339         // declarations
340         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
341         float final_damage; //, final_spread;
342         vector final_force, center, vel;
343         entity head, next;
344
345         float i, queue = 0;
346         
347         // set up the shot direction
348         W_SetupShot(self, FALSE, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
349         vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
350         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
351         vector attack_hitpos = trace_endpos;
352         float distance_to_end = vlen(w_shotorg - attack_endpos);
353         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
354         //entity transform = WarpZone_trace_transform;
355
356         // do the firing effect now
357         //SendCSQCShockwaveParticle(attack_endpos);
358         Damage_DamageInfo(attack_hitpos, WEP_CVAR(shockwave, blast_splash_damage), WEP_CVAR(shockwave, blast_splash_edgedamage), WEP_CVAR(shockwave, blast_splash_radius), w_shotdir * WEP_CVAR(shockwave, blast_splash_force), WEP_SHOCKWAVE, 0, self);
359
360         // splash damage/jumping trace
361         head = WarpZone_FindRadius(attack_hitpos, max(WEP_CVAR(shockwave, blast_splash_radius), WEP_CVAR(shockwave, blast_jump_radius)), FALSE);
362         while(head)
363         {
364                 next = head.chain;
365
366                 if(head.takedamage)
367                 {
368                         center = CENTER_OR_VIEWOFS(head);
369
370                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
371                         
372                         if((head == self) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
373                         {
374                                 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius))) : 0));
375                                 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
376                                 multiplier = max(WEP_CVAR(shockwave, blast_jump_multiplier_min), ((multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy)) + (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))));
377
378                                 final_force = ((normalize(center - attack_hitpos) * WEP_CVAR(shockwave, blast_jump_force)) * multiplier);
379                                 vel = head.velocity; vel_z = 0;
380                                 vel = normalize(vel) * bound(0, vlen(vel) / autocvar_sv_maxspeed, 1) * WEP_CVAR(shockwave, blast_jump_force_velocitybias);
381                                 final_force = (vlen(final_force) * normalize(normalize(final_force) + vel));
382                                 final_force_z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
383                                 final_damage = (WEP_CVAR(shockwave, blast_jump_damage) * multiplier + WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier));
384
385                                 Damage(head, self, self, final_damage, WEP_SHOCKWAVE, head.origin, final_force);
386                                 //print("SELF HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
387                         }
388                         else if (distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
389                         {       
390                                 multiplier_from_accuracy = (1 - (distance_to_head ? min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius))) : 0));
391                                 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_hit / distance_to_end)) : 0));
392                                 multiplier = max(WEP_CVAR(shockwave, blast_splash_multiplier_min), ((multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy)) + (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))));
393
394                                 final_force = normalize(center - (attack_hitpos - (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias))));
395                                 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
396                                 final_force = ((final_force * WEP_CVAR(shockwave, blast_splash_force)) * multiplier);
397                                 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
398                                 final_damage = (WEP_CVAR(shockwave, blast_splash_damage) * multiplier + WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier));
399
400                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
401                                 //print("SPLASH HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
402                         }
403                 }
404                 head = next;
405         }
406
407         // cone damage trace
408         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), FALSE);
409         while(head)
410         {
411                 next = head.chain;
412                 
413                 if((head != self) && head.takedamage)
414                 {
415                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc) 
416                         center = CENTER_OR_VIEWOFS(head);
417
418                         // find the closest point on the enemy to the center of the attack
419                         float ang; // angle between shotdir and h
420                         float h; // hypotenuse, which is the distance between attacker to head
421                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
422                         
423                         h = vlen(center - self.origin);
424                         ang = acos(dotproduct(normalize(center - self.origin), w_shotdir));
425                         a = h * cos(ang);
426
427                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
428                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
429                         float distance_to_target = vlen(w_shotorg - nearest_to_attacker); // todo: use the findradius function for this
430
431                         if((distance_to_target <= WEP_CVAR(shockwave, blast_distance)) 
432                                 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
433                         {
434                                 multiplier_from_accuracy = (1 - W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, w_shotorg, attack_endpos));
435                                 multiplier_from_distance = (1 - (distance_to_hit ? min(1, (distance_to_target / distance_to_end)) : 0));
436                                 multiplier = max(WEP_CVAR(shockwave, blast_multiplier_min), ((multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy)) + (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))));
437
438                                 final_force = normalize(center - (nearest_on_line - (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias))));
439                                 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
440                                 final_force = ((final_force * WEP_CVAR(shockwave, blast_force)) * multiplier);
441                                 final_force_z *= WEP_CVAR(shockwave, blast_force_zscale);
442                                 final_damage = (WEP_CVAR(shockwave, blast_damage) * multiplier + WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier));
443
444                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { ++queue; }
445                                 //print("CONE HIT: multiplier = ", ftos(multiplier), strcat(", damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force))),"... multiplier_from_accuracy = ", ftos(multiplier_from_accuracy), ", multiplier_from_distance = ", ftos(multiplier_from_distance), ".\n");
446                         }
447                 }
448                 head = next;
449         }
450
451         for(i = 1; i <= queue; ++i)
452         {
453                 head = shockwave_hit[i];
454                 final_force = shockwave_hit_force[i];
455                 final_damage = shockwave_hit_damage[i];
456                 
457                 Damage(head, self, self, final_damage, WEP_SHOCKWAVE, head.origin, final_force);
458                 print("SHOCKWAVE by ", self.netname, ": damage = ", ftos(final_damage), ", force = ", ftos(vlen(final_force)), ".\n");
459                 
460                 shockwave_hit[i] = world;
461                 shockwave_hit_force[i] = '0 0 0';
462                 shockwave_hit_damage[i] = 0;
463         }
464         //print("queue was ", ftos(queue), ".\n\n");
465 }
466
467 float W_Shockwave(float req)
468 {
469         float ammo_amount;
470         switch(req)
471         {
472                 case WR_AIM:
473                 {
474                         if(vlen(self.origin-self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
475                                 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE); }
476                         else
477                                 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE); }
478                         
479                         return TRUE;
480                 }
481                 case WR_THINK:
482                 {
483                         if(autocvar_g_balance_shockwave_reload_ammo && self.clip_load < autocvar_g_balance_shockwave_pellets_ammo) // forced reload
484                         {
485                                 // don't force reload an empty shockwave if its melee attack is active
486                                 if(!(autocvar_g_balance_shockwave_secondary && self.ammo_shells < autocvar_g_balance_shockwave_pellets_ammo))
487                                         WEP_ACTION(self.weapon, WR_RELOAD);
488                         }
489                         else
490                         {
491                                 if (self.BUTTON_ATCK)
492                                 {
493                                         if (time >= self.shockwave_pelletstime) // handle refire separately so the secondary can be fired straight after a primary
494                                         {
495                                                 if(weapon_prepareattack(0, autocvar_g_balance_shockwave_pellets_animtime))
496                                                 {
497                                                         W_Shockwave_Attack();
498                                                         self.shockwave_pelletstime = time + autocvar_g_balance_shockwave_pellets_refire * W_WeaponRateFactor();
499                                                         weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_shockwave_pellets_animtime, w_ready);
500                                                 }
501                                         }
502                                 }
503                         }
504                         if (self.clip_load >= 0) // we are not currently reloading
505                         if (!self.crouch) // no crouchmelee please
506                         if (self.BUTTON_ATCK2 && autocvar_g_balance_shockwave_secondary)
507                         if (weapon_prepareattack(1, WEP_CVAR(shockwave, melee_refire)))
508                         {
509                                 // attempt forcing playback of the anim by switching to another anim (that we never play) here...
510                                 weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
511                         }
512                         
513                         return TRUE;
514                 }
515                 case WR_INIT:
516                 {
517                         precache_model("models/uziflash.md3");
518                         precache_model("models/weapons/g_shockwave.md3");
519                         precache_model("models/weapons/v_shockwave.md3");
520                         precache_model("models/weapons/h_shockwave.iqm");
521                         precache_sound("misc/itempickup.wav");
522                         precache_sound("weapons/shockwave_fire.wav");
523                         precache_sound("weapons/shockwave_melee.wav");
524                         SHOCKWAVE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
525                         return TRUE;
526                 }
527                 case WR_SETUP:
528                 {
529                         self.current_ammo = ammo_shells;
530                         return TRUE;
531                 }
532                 case WR_CHECKAMMO1:
533                 {
534                         ammo_amount = self.ammo_shells >= autocvar_g_balance_shockwave_pellets_ammo;
535                         ammo_amount += self.(weapon_load[WEP_SHOCKWAVE]) >= autocvar_g_balance_shockwave_pellets_ammo;
536                         return ammo_amount;
537                 }
538                 case WR_CHECKAMMO2:
539                 {
540                         // melee attack is always available
541                         return TRUE;
542                 }
543                 case WR_CONFIG:
544                 {
545                         SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
546                         return TRUE;
547                 }
548                 case WR_RELOAD:
549                 {
550                         W_Reload(autocvar_g_balance_shockwave_pellets_ammo, "weapons/reload.wav");
551                         return TRUE;
552                 }
553                 case WR_SUICIDEMESSAGE:
554                 {
555                         return WEAPON_THINKING_WITH_PORTALS;
556                 }
557                 case WR_KILLMESSAGE:
558                 {
559                         if(w_deathtype & HITTYPE_SECONDARY)
560                                 return WEAPON_SHOCKWAVE_MURDER_SLAP;
561                         else
562                                 return WEAPON_SHOCKWAVE_MURDER;
563                 }
564         }
565         return TRUE;
566 }
567 #endif
568 #ifdef CSQC
569 float W_Shockwave(float req)
570 {
571         switch(req)
572         {
573                 case WR_IMPACTEFFECT:
574                 {
575                         vector org2;
576                         org2 = w_org + w_backoff * 2;
577                         pointparticles(particleeffectnum("shockwave_impact"), org2, w_backoff * 1000, 1);
578                         return TRUE;
579                 }
580                 case WR_INIT:
581                 {
582                         //precache_sound("weapons/ric1.wav");
583                         //precache_sound("weapons/ric2.wav");
584                         //precache_sound("weapons/ric3.wav");
585                         return FALSE;
586                 }
587         }
588         return TRUE;
589 }
590 #endif
591 #endif