]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_shockwave.qc
Merge branch 'TimePath/issues/1490'
[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 | WEP_FLAG_CANCLIMB | WEP_FLAG_MUTATORBLOCKED,
8 /* rating    */ BOT_PICKUP_RATING_LOW,
9 /* color     */ '0.5 0.25 0',
10 /* modelname */ "shotgun",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairshotgun 0.7",
13 /* wepimg    */ "weaponshotgun",
14 /* refname   */ "shockwave",
15 /* wepname   */ _("Shockwave")
16 );
17
18 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
19 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, NONE, blast_animtime) \
21         w_cvar(id, sn, NONE, blast_damage) \
22         w_cvar(id, sn, NONE, blast_distance) \
23         w_cvar(id, sn, NONE, blast_edgedamage) \
24         w_cvar(id, sn, NONE, blast_force) \
25         w_cvar(id, sn, NONE, blast_force_forwardbias) \
26         w_cvar(id, sn, NONE, blast_force_zscale) \
27         w_cvar(id, sn, NONE, blast_jump_damage) \
28         w_cvar(id, sn, NONE, blast_jump_edgedamage) \
29         w_cvar(id, sn, NONE, blast_jump_force) \
30         w_cvar(id, sn, NONE, blast_jump_force_velocitybias) \
31         w_cvar(id, sn, NONE, blast_jump_force_zscale) \
32         w_cvar(id, sn, NONE, blast_jump_multiplier_accuracy) \
33         w_cvar(id, sn, NONE, blast_jump_multiplier_distance) \
34         w_cvar(id, sn, NONE, blast_jump_multiplier_min) \
35         w_cvar(id, sn, NONE, blast_jump_radius) \
36         w_cvar(id, sn, NONE, blast_multiplier_accuracy) \
37         w_cvar(id, sn, NONE, blast_multiplier_distance) \
38         w_cvar(id, sn, NONE, blast_multiplier_min) \
39         w_cvar(id, sn, NONE, blast_refire) \
40         w_cvar(id, sn, NONE, blast_splash_damage) \
41         w_cvar(id, sn, NONE, blast_splash_edgedamage) \
42         w_cvar(id, sn, NONE, blast_splash_force) \
43         w_cvar(id, sn, NONE, blast_splash_force_forwardbias) \
44         w_cvar(id, sn, NONE, blast_splash_multiplier_accuracy) \
45         w_cvar(id, sn, NONE, blast_splash_multiplier_distance) \
46         w_cvar(id, sn, NONE, blast_splash_multiplier_min) \
47         w_cvar(id, sn, NONE, blast_splash_radius) \
48         w_cvar(id, sn, NONE, blast_spread_max) \
49         w_cvar(id, sn, NONE, blast_spread_min) \
50         w_cvar(id, sn, NONE, melee_animtime) \
51         w_cvar(id, sn, NONE, melee_damage) \
52         w_cvar(id, sn, NONE, melee_delay) \
53         w_cvar(id, sn, NONE, melee_force) \
54         w_cvar(id, sn, NONE, melee_multihit) \
55         w_cvar(id, sn, NONE, melee_no_doubleslap) \
56         w_cvar(id, sn, NONE, melee_nonplayerdamage) \
57         w_cvar(id, sn, NONE, melee_range) \
58         w_cvar(id, sn, NONE, melee_refire) \
59         w_cvar(id, sn, NONE, melee_swing_side) \
60         w_cvar(id, sn, NONE, melee_swing_up) \
61         w_cvar(id, sn, NONE, melee_time) \
62         w_cvar(id, sn, NONE, melee_traces) \
63         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
64         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
65         w_prop(id, sn, string, weaponreplace, weaponreplace) \
66         w_prop(id, sn, float,  weaponstart, weaponstart) \
67         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
68         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
69
70 #ifdef SVQC
71 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
72 #endif
73 #ifdef CSQC
74 void Net_ReadShockwaveParticle(void);
75 .vector sw_shotorg;
76 .vector sw_shotdir;
77 .float sw_distance;
78 .float sw_spread_max;
79 .float sw_spread_min;
80 .float sw_time;
81 #endif
82 #else
83 #ifdef SVQC
84 void spawnfunc_weapon_shockwave(void)
85 {
86         //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
87         if(autocvar_sv_q3acompat_machineshotgunswap)
88         if(self.classname != "droppedweapon")
89         {
90                 weapon_defaultspawnfunc(WEP_MACHINEGUN);
91                 return;
92         }
93         weapon_defaultspawnfunc(WEP_SHOCKWAVE);
94 }
95
96 const float MAX_SHOCKWAVE_HITS = 10;
97 //#define DEBUG_SHOCKWAVE
98
99 .float swing_prev;
100 .entity swing_alreadyhit;
101 .float shockwave_blasttime;
102 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
103 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
104 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
105
106 // MELEE ATTACK MODE
107 void W_Shockwave_Melee_Think(void)
108 {
109         // declarations
110         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
111         entity target_victim;
112         vector targpos;
113
114         // check to see if we can still continue, otherwise give up now
115         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
116         {
117                 remove(self);
118                 return;
119         }
120
121         // set start time of melee
122         if(!self.cnt)
123         {
124                 self.cnt = time;
125                 W_PlayStrengthSound(self.realowner);
126         }
127
128         // update values for v_* vectors
129         makevectors(self.realowner.v_angle);
130
131         // calculate swing percentage based on time
132         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
133         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
134         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
135
136         // perform the traces needed for this frame
137         for(i=self.swing_prev; i < f; ++i)
138         {
139                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
140
141                 targpos = (self.realowner.origin + self.realowner.view_ofs
142                         + (v_forward * WEP_CVAR(shockwave, melee_range))
143                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
144                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
145
146                 WarpZone_traceline_antilag(
147                         self.realowner,
148                         (self.realowner.origin + self.realowner.view_ofs),
149                         targpos,
150                         false,
151                         self.realowner,
152                         ANTILAG_LATENCY(self.realowner)
153                 );
154
155                 // draw lightning beams for debugging
156 #ifdef DEBUG_SHOCKWAVE
157                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
158                 te_customflash(targpos, 40,  2, '1 1 1');
159 #endif
160
161                 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
162
163                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
164                         && (trace_ent.takedamage == DAMAGE_AIM)
165                         && (trace_ent != self.swing_alreadyhit)
166                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
167                 {
168                         target_victim = trace_ent; // so it persists through other calls
169
170                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
171                                 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
172                         else
173                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
174
175                         // trigger damage with this calculated info
176                         Damage(
177                                 target_victim,
178                                 self.realowner,
179                                 self.realowner,
180                                 swing_damage,
181                                 (WEP_SHOCKWAVE | HITTYPE_SECONDARY),
182                                 (self.realowner.origin + self.realowner.view_ofs),
183                                 (v_forward * WEP_CVAR(shockwave, melee_force))
184                         );
185
186                         // handle accuracy
187                         if(accuracy_isgooddamage(self.realowner, target_victim))
188                                 { accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, swing_damage); }
189
190                         #ifdef DEBUG_SHOCKWAVE
191                         print(sprintf(
192                                 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
193                                 self.realowner.netname,
194                                 target_victim.netname,
195                                 swing_damage,
196                                 swing_factor,
197                                 time
198                         ));
199                         #endif
200
201                         // allow multiple hits with one swing, but not against the same player twice
202                         if(WEP_CVAR(shockwave, melee_multihit))
203                         {
204                                 self.swing_alreadyhit = target_victim;
205                                 continue; // move along to next trace
206                         }
207                         else
208                         {
209                                 remove(self);
210                                 return;
211                         }
212                 }
213         }
214
215         if(time >= self.cnt + meleetime)
216         {
217                 // melee is finished
218                 remove(self);
219                 return;
220         }
221         else
222         {
223                 // set up next frame
224                 self.swing_prev = i;
225                 self.nextthink = time;
226         }
227 }
228
229 void W_Shockwave_Melee(void)
230 {
231         sound(self, CH_WEAPON_A, "weapons/shotgun_melee.wav", VOL_BASE, ATTN_NORM);
232         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
233
234         entity meleetemp;
235         meleetemp = spawn();
236         meleetemp.owner = meleetemp.realowner = self;
237         meleetemp.think = W_Shockwave_Melee_Think;
238         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
239         W_SetupShot_Range(self, true, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
240 }
241
242 // SHOCKWAVE ATTACK MODE
243 float W_Shockwave_Attack_CheckSpread(
244         vector targetorg,
245         vector nearest_on_line,
246         vector sw_shotorg,
247         vector attack_endpos)
248 {
249         float spreadlimit;
250         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
251         float distance_from_line = vlen(targetorg - nearest_on_line);
252
253         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
254         spreadlimit =
255                 (
256                         (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
257                         +
258                         (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
259                 );
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(!head) { return false; }
317         float i;
318
319         for(i = 0; i <= queue; ++i)
320         {
321                 if(shockwave_hit[i] == head)
322                 {
323                         if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
324                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
325                         return false;
326                 }
327         }
328
329         shockwave_hit[queue] = head;
330         shockwave_hit_force[queue] = final_force;
331         shockwave_hit_damage[queue] = final_damage;
332         return true;
333 }
334
335 void W_Shockwave_Send(void)
336 {
337         WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
338         WriteByte(MSG_BROADCAST, TE_CSQC_SHOCKWAVEPARTICLE);
339         WriteCoord(MSG_BROADCAST, w_shotorg.x);
340         WriteCoord(MSG_BROADCAST, w_shotorg.y);
341         WriteCoord(MSG_BROADCAST, w_shotorg.z);
342         WriteCoord(MSG_BROADCAST, w_shotdir.x);
343         WriteCoord(MSG_BROADCAST, w_shotdir.y);
344         WriteCoord(MSG_BROADCAST, w_shotdir.z);
345         WriteShort(MSG_BROADCAST, WEP_CVAR(shockwave, blast_distance));
346         WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_max), 255));
347         WriteByte(MSG_BROADCAST, bound(0, WEP_CVAR(shockwave, blast_spread_min), 255));
348         WriteByte(MSG_BROADCAST, num_for_edict(self));
349 }
350
351 void W_Shockwave_Attack(void)
352 {
353         // declarations
354         float multiplier, multiplier_from_accuracy, multiplier_from_distance;
355         float final_damage;
356         vector final_force, center, vel;
357         entity head;
358
359         float i, queue = 0;
360
361         // set up the shot direction
362         W_SetupShot(self, false, 3, "weapons/lasergun_fire.wav", CH_WEAPON_B, WEP_CVAR(shockwave, blast_damage));
363         vector attack_endpos = (w_shotorg + (w_shotdir * WEP_CVAR(shockwave, blast_distance)));
364         WarpZone_TraceLine(w_shotorg, attack_endpos, MOVE_NOMONSTERS, self);
365         vector attack_hitpos = trace_endpos;
366         float distance_to_end = vlen(w_shotorg - attack_endpos);
367         float distance_to_hit = vlen(w_shotorg - attack_hitpos);
368         //entity transform = WarpZone_trace_transform;
369
370         // do the firing effect now
371         W_Shockwave_Send();
372         Damage_DamageInfo(
373                 attack_hitpos,
374                 WEP_CVAR(shockwave, blast_splash_damage),
375                 WEP_CVAR(shockwave, blast_splash_edgedamage),
376                 WEP_CVAR(shockwave, blast_splash_radius),
377                 w_shotdir * WEP_CVAR(shockwave, blast_splash_force),
378                 WEP_SHOCKWAVE,
379                 0,
380                 self
381         );
382
383         // splash damage/jumping trace
384         head = WarpZone_FindRadius(
385                 attack_hitpos,
386                 max(
387                         WEP_CVAR(shockwave, blast_splash_radius),
388                         WEP_CVAR(shockwave, blast_jump_radius)
389                 ),
390                 false
391         );
392
393         while(head)
394         {
395                 if(head.takedamage)
396                 {
397                         float distance_to_head = vlen(attack_hitpos - head.WarpZone_findradius_nearest);
398
399                         if((head == self) && (distance_to_head <= WEP_CVAR(shockwave, blast_jump_radius)))
400                         {
401                                 // ========================
402                                 //  BLAST JUMP CALCULATION
403                                 // ========================
404
405                                 // calculate importance of distance and accuracy for this attack
406                                 multiplier_from_accuracy = (1 -
407                                         (distance_to_head ?
408                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_jump_radius)))
409                                                 :
410                                                 0
411                                         )
412                                 );
413                                 multiplier_from_distance = (1 -
414                                         (distance_to_hit ?
415                                                 min(1, (distance_to_hit / distance_to_end))
416                                                 :
417                                                 0
418                                         )
419                                 );
420                                 multiplier =
421                                         max(
422                                                 WEP_CVAR(shockwave, blast_jump_multiplier_min),
423                                                 (
424                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_jump_multiplier_accuracy))
425                                                         +
426                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_jump_multiplier_distance))
427                                                 )
428                                         );
429
430                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
431                                 final_damage =
432                                         (
433                                                 (WEP_CVAR(shockwave, blast_jump_damage) * multiplier)
434                                                 +
435                                                 (WEP_CVAR(shockwave, blast_jump_edgedamage) * (1 - multiplier))
436                                         );
437
438                                 // figure out the direction of force
439                                 vel = normalize(combine_to_vector(head.velocity.x, head.velocity.y, 0));
440                                 vel *=
441                                         (
442                                                 bound(0, (vlen(vel) / autocvar_sv_maxspeed), 1)
443                                                 *
444                                                 WEP_CVAR(shockwave, blast_jump_force_velocitybias)
445                                         );
446                                 final_force = normalize((CENTER_OR_VIEWOFS(head) - attack_hitpos) + vel);
447
448                                 // now multiply the direction by force units
449                                 final_force *= (WEP_CVAR(shockwave, blast_jump_force) * multiplier);
450                                 final_force.z *= WEP_CVAR(shockwave, blast_jump_force_zscale);
451
452                                 // trigger damage with this calculated info
453                                 Damage(
454                                         head,
455                                         self,
456                                         self,
457                                         final_damage,
458                                         WEP_SHOCKWAVE,
459                                         head.origin,
460                                         final_force
461                                 );
462
463                                 #ifdef DEBUG_SHOCKWAVE
464                                 print(sprintf(
465                                         "SELF HIT: multiplier = %f, damage = %f, force = %f... "
466                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
467                                         multiplier,
468                                         final_damage,
469                                         vlen(final_force),
470                                         multiplier_from_accuracy,
471                                         multiplier_from_distance
472                                 ));
473                                 #endif
474                         }
475                         else if(distance_to_head <= WEP_CVAR(shockwave, blast_splash_radius))
476                         {
477                                 // ==========================
478                                 //  BLAST SPLASH CALCULATION
479                                 // ==========================
480
481                                 // calculate importance of distance and accuracy for this attack
482                                 multiplier_from_accuracy = (1 -
483                                         (distance_to_head ?
484                                                 min(1, (distance_to_head / WEP_CVAR(shockwave, blast_splash_radius)))
485                                                 :
486                                                 0
487                                         )
488                                 );
489                                 multiplier_from_distance = (1 -
490                                         (distance_to_hit ?
491                                                 min(1, (distance_to_hit / distance_to_end))
492                                                 :
493                                                 0
494                                         )
495                                 );
496                                 multiplier =
497                                         max(
498                                                 WEP_CVAR(shockwave, blast_splash_multiplier_min),
499                                                 (
500                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_splash_multiplier_accuracy))
501                                                         +
502                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_splash_multiplier_distance))
503                                                 )
504                                         );
505
506                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
507                                 final_damage =
508                                         (
509                                                 (WEP_CVAR(shockwave, blast_splash_damage) * multiplier)
510                                                 +
511                                                 (WEP_CVAR(shockwave, blast_splash_edgedamage) * (1 - multiplier))
512                                         );
513
514                                 // figure out the direction of force
515                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_splash_force_forwardbias));
516                                 final_force = normalize(CENTER_OR_VIEWOFS(head) - (attack_hitpos - final_force));
517                                 //te_lightning2(world, attack_hitpos, (attack_hitpos + (final_force * 200)));
518
519                                 // now multiply the direction by force units
520                                 final_force *= (WEP_CVAR(shockwave, blast_splash_force) * multiplier);
521                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
522
523                                 // queue damage with this calculated info
524                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
525
526                                 #ifdef DEBUG_SHOCKWAVE
527                                 print(sprintf(
528                                         "SPLASH HIT: multiplier = %f, damage = %f, force = %f... "
529                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
530                                         multiplier,
531                                         final_damage,
532                                         vlen(final_force),
533                                         multiplier_from_accuracy,
534                                         multiplier_from_distance
535                                 ));
536                                 #endif
537                         }
538                 }
539                 head = head.chain;
540         }
541
542         // cone damage trace
543         head = WarpZone_FindRadius(w_shotorg, WEP_CVAR(shockwave, blast_distance), false);
544         while(head)
545         {
546                 if((head != self) && head.takedamage)
547                 {
548                         // ========================
549                         //  BLAST CONE CALCULATION
550                         // ========================
551
552                         // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
553                         center = CENTER_OR_VIEWOFS(head);
554
555                         // find the closest point on the enemy to the center of the attack
556                         float h; // hypotenuse, which is the distance between attacker to head
557                         float a; // adjacent side, which is the distance between attacker and the point on w_shotdir that is closest to head.origin
558
559                         h = vlen(center - self.origin);
560                         a = h * (normalize(center - self.origin) * w_shotdir);
561                         // WEAPONTODO: replace with simpler method
562
563                         vector nearest_on_line = (w_shotorg + a * w_shotdir);
564                         vector nearest_to_attacker = WarpZoneLib_NearestPointOnBox(center + head.mins, center + head.maxs, nearest_on_line);
565
566                         if((vlen(head.WarpZone_findradius_dist) <= WEP_CVAR(shockwave, blast_distance))
567                                 && (W_Shockwave_Attack_IsVisible(head, nearest_on_line, w_shotorg, attack_endpos)))
568                         {
569                                 // calculate importance of distance and accuracy for this attack
570                                 multiplier_from_accuracy = (1 -
571                                         W_Shockwave_Attack_CheckSpread(
572                                                 nearest_to_attacker,
573                                                 nearest_on_line,
574                                                 w_shotorg,
575                                                 attack_endpos
576                                         )
577                                 );
578                                 multiplier_from_distance = (1 -
579                                         (distance_to_hit ?
580                                                 min(1, (vlen(head.WarpZone_findradius_dist) / distance_to_end))
581                                                 :
582                                                 0
583                                         )
584                                 );
585                                 multiplier =
586                                         max(
587                                                 WEP_CVAR(shockwave, blast_multiplier_min),
588                                                 (
589                                                         (multiplier_from_accuracy * WEP_CVAR(shockwave, blast_multiplier_accuracy))
590                                                         +
591                                                         (multiplier_from_distance * WEP_CVAR(shockwave, blast_multiplier_distance))
592                                                 )
593                                         );
594
595                                 // calculate damage from multiplier: 1 = "highest" damage, 0 = "lowest" edgedamage
596                                 final_damage =
597                                         (
598                                                 (WEP_CVAR(shockwave, blast_damage) * multiplier)
599                                                 +
600                                                 (WEP_CVAR(shockwave, blast_edgedamage) * (1 - multiplier))
601                                         );
602
603                                 // figure out the direction of force
604                                 final_force = (w_shotdir * WEP_CVAR(shockwave, blast_force_forwardbias));
605                                 final_force = normalize(center - (nearest_on_line - final_force));
606                                 //te_lightning2(world, nearest_on_line, (attack_hitpos + (final_force * 200)));
607
608                                 // now multiply the direction by force units
609                                 final_force *= (WEP_CVAR(shockwave, blast_force) * multiplier);
610                                 final_force.z *= WEP_CVAR(shockwave, blast_force_zscale);
611
612                                 // queue damage with this calculated info
613                                 if(W_Shockwave_Attack_CheckHit(queue, head, final_force, final_damage)) { queue = min(queue + 1, MAX_SHOCKWAVE_HITS); }
614
615                                 #ifdef DEBUG_SHOCKWAVE
616                                 print(sprintf(
617                                         "BLAST HIT: multiplier = %f, damage = %f, force = %f... "
618                                         "multiplier_from_accuracy = %f, multiplier_from_distance = %f.\n",
619                                         multiplier,
620                                         final_damage,
621                                         vlen(final_force),
622                                         multiplier_from_accuracy,
623                                         multiplier_from_distance
624                                 ));
625                                 #endif
626                         }
627                 }
628                 head = head.chain;
629         }
630
631         for(i = 1; i <= queue; ++i)
632         {
633                 head = shockwave_hit[i-1];
634                 final_force = shockwave_hit_force[i-1];
635                 final_damage = shockwave_hit_damage[i-1];
636
637                 Damage(
638                         head,
639                         self,
640                         self,
641                         final_damage,
642                         WEP_SHOCKWAVE,
643                         head.origin,
644                         final_force
645                 );
646
647                 if(accuracy_isgooddamage(self.realowner, head))
648                 {
649                         print("wtf\n");
650                         accuracy_add(self.realowner, WEP_SHOCKWAVE, 0, final_damage);
651                 }
652
653                 #ifdef DEBUG_SHOCKWAVE
654                 print(sprintf(
655                         "SHOCKWAVE by %s: damage = %f, force = %f.\n",
656                         self.netname,
657                         final_damage,
658                         vlen(final_force)
659                 ));
660                 #endif
661
662                 shockwave_hit[i-1] = world;
663                 shockwave_hit_force[i-1] = '0 0 0';
664                 shockwave_hit_damage[i-1] = 0;
665         }
666 }
667
668 bool W_Shockwave(int req)
669 {
670         switch(req)
671         {
672                 case WR_AIM:
673                 {
674                         if(vlen(self.origin - self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
675                                 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false); }
676                         else
677                                 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false); }
678
679                         return true;
680                 }
681                 case WR_THINK:
682                 {
683                         if(self.BUTTON_ATCK)
684                         {
685                                 if(time >= self.shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
686                                 {
687                                         if(weapon_prepareattack(0, WEP_CVAR(shockwave, blast_animtime)))
688                                         {
689                                                 W_Shockwave_Attack();
690                                                 self.shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor();
691                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
692                                         }
693                                 }
694                         }
695                         else if(self.BUTTON_ATCK2)
696                         {
697                                 //if(self.clip_load >= 0) // we are not currently reloading
698                                 if(!self.crouch) // no crouchmelee please
699                                 if(weapon_prepareattack(1, WEP_CVAR(shockwave, melee_refire)))
700                                 {
701                                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
702                                         weapon_thinkf(WFRAME_FIRE1, 0, W_Shockwave_Melee);
703                                 }
704                         }
705
706                         return true;
707                 }
708                 case WR_INIT:
709                 {
710                         precache_model("models/uziflash.md3");
711                         precache_model("models/weapons/g_shotgun.md3");
712                         precache_model("models/weapons/v_shotgun.md3");
713                         precache_model("models/weapons/h_shotgun.iqm");
714                         precache_sound("misc/itempickup.wav");
715                         precache_sound("weapons/lasergun_fire.wav");
716                         precache_sound("weapons/shotgun_melee.wav");
717                         SHOCKWAVE_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
718                         return true;
719                 }
720                 case WR_CHECKAMMO1:
721                 case WR_CHECKAMMO2:
722                 {
723                         // shockwave has infinite ammo
724                         return true;
725                 }
726                 case WR_CONFIG:
727                 {
728                         SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
729                         return true;
730                 }
731                 case WR_SUICIDEMESSAGE:
732                 {
733                         return WEAPON_THINKING_WITH_PORTALS;
734                 }
735                 case WR_KILLMESSAGE:
736                 {
737                         if(w_deathtype & HITTYPE_SECONDARY)
738                                 return WEAPON_SHOCKWAVE_MURDER_SLAP;
739                         else
740                                 return WEAPON_SHOCKWAVE_MURDER;
741                 }
742         }
743         return false;
744 }
745 #endif
746 #ifdef CSQC
747 // WEAPONTODO: add client side settings for these
748 const float SW_MAXALPHA = 0.5;
749 const float SW_FADETIME = 0.4;
750 const float SW_DISTTOMIN = 200;
751 void Draw_Shockwave()
752 {
753         // fading/removal control
754         float a = bound(0, (SW_MAXALPHA - ((time - self.sw_time) / SW_FADETIME)), SW_MAXALPHA);
755         if(a < ALPHA_MIN_VISIBLE) { remove(self); }
756
757         // WEAPONTODO: save this only once when creating the entity
758         vector sw_color = getcsqcplayercolor(self.sv_entnum); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
759
760         // WEAPONTODO: trace to find what we actually hit
761         vector endpos = (self.sw_shotorg + (self.sw_shotdir * self.sw_distance));
762
763         vectorvectors(self.sw_shotdir);
764         vector right = v_right; // save this for when we do makevectors later
765         vector up = v_up; // save this for when we do makevectors later
766
767         // WEAPONTODO: combine and simplify these calculations
768         vector min_end = ((self.sw_shotorg + (self.sw_shotdir * SW_DISTTOMIN)) + (up * self.sw_spread_min));
769         vector max_end = (endpos + (up * self.sw_spread_max));
770         float spread_to_min = vlen(normalize(min_end - self.sw_shotorg) - self.sw_shotdir);
771         float spread_to_max = vlen(normalize(max_end - min_end) - self.sw_shotdir);
772
773         vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
774         vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
775         float new_max_dist, new_min_dist;
776
777         vector deviation, angle = '0 0 0';
778         float counter, divisions = 20;
779         for(counter = 0; counter < divisions; ++counter)
780         {
781                 // perfect circle effect lines
782                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
783                 angle.y = v_forward.x;
784                 angle.z = v_forward.y;
785
786                 // first do the spread_to_min effect
787                 deviation = angle * spread_to_min;
788                 deviation = ((self.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
789                 new_min_dist = SW_DISTTOMIN;
790                 new_min_end = (self.sw_shotorg + (deviation * new_min_dist));
791                 //te_lightning2(world, new_min_end, self.sw_shotorg);
792
793                 // then calculate spread_to_max effect
794                 deviation = angle * spread_to_max;
795                 deviation = ((self.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
796                 new_max_dist = vlen(new_min_end - endpos);
797                 new_max_end = (new_min_end + (deviation * new_max_dist));
798                 //te_lightning2(world, new_end, prev_min_end);
799
800
801                 if(counter == 0)
802                 {
803                         first_min_end = new_min_end;
804                         first_max_end = new_max_end;
805                 }
806
807                 if(counter >= 1)
808                 {
809                         // draw from shot origin to min spread radius
810                         R_BeginPolygon("", DRAWFLAG_NORMAL);
811                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
812                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
813                         R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
814                         R_EndPolygon();
815
816                         // draw from min spread radius to max spread radius
817                         R_BeginPolygon("", DRAWFLAG_NORMAL);
818                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
819                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
820                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
821                         R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
822                         R_EndPolygon();
823                 }
824
825                 prev_min_end = new_min_end;
826                 prev_max_end = new_max_end;
827
828                 // last division only
829                 if((counter + 1) == divisions)
830                 {
831                         // draw from shot origin to min spread radius
832                         R_BeginPolygon("", DRAWFLAG_NORMAL);
833                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
834                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
835                         R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
836                         R_EndPolygon();
837
838                         // draw from min spread radius to max spread radius
839                         R_BeginPolygon("", DRAWFLAG_NORMAL);
840                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
841                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
842                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
843                         R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
844                         R_EndPolygon();
845                 }
846         }
847 }
848
849 void Net_ReadShockwaveParticle(void)
850 {
851         entity shockwave;
852         shockwave = spawn();
853         shockwave.draw = Draw_Shockwave;
854
855         shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
856         shockwave.sw_shotdir_x = ReadCoord(); shockwave.sw_shotdir_y = ReadCoord(); shockwave.sw_shotdir_z = ReadCoord();
857
858         shockwave.sw_distance = ReadShort();
859         shockwave.sw_spread_max = ReadByte();
860         shockwave.sw_spread_min = ReadByte();
861
862         shockwave.sv_entnum = ReadByte();
863
864         shockwave.sw_time = time;
865 }
866
867 bool W_Shockwave(int req)
868 {
869         switch(req)
870         {
871                 case WR_IMPACTEFFECT:
872                 {
873                         // handled by Net_ReadShockwaveParticle
874                         //vector org2;
875                         //org2 = w_org + w_backoff * 2;
876                         //pointparticles(particleeffectnum("laser_impact"), org2, w_backoff * 1000, 1);
877                         return false;
878                 }
879                 case WR_INIT:
880                 {
881                         //precache_sound("weapons/ric1.wav");
882                         //precache_sound("weapons/ric2.wav");
883                         //precache_sound("weapons/ric3.wav");
884                         return false;
885                 }
886                 case WR_ZOOMRETICLE:
887                 {
888                         // no weapon specific image for this weapon
889                         return false;
890                 }
891         }
892         return false;
893 }
894 #endif
895 #endif