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