]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/shockwave.qc
s/(void)/()
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / shockwave.qc
1 #ifndef IMPLEMENTATION
2 CLASS(Shockwave, Weapon)
3 /* ammotype  */ //ATTRIB(Shockwave, ammo_field, .int, ammo_none)
4 /* impulse   */ ATTRIB(Shockwave, impulse, int, 2)
5 /* flags     */ ATTRIB(Shockwave, spawnflags, int, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN | WEP_FLAG_CANCLIMB | WEP_FLAG_MUTATORBLOCKED);
6 /* rating    */ ATTRIB(Shockwave, bot_pickupbasevalue, float, BOT_PICKUP_RATING_LOW);
7 /* color     */ ATTRIB(Shockwave, wpcolor, vector, '0.5 0.25 0');
8 /* modelname */ ATTRIB(Shockwave, mdl, string, "shotgun");
9 #ifndef MENUQC
10 /* model     */ ATTRIB(Shockwave, m_model, Model, MDL_SHOCKWAVE_ITEM);
11 #endif
12 /* crosshair */ ATTRIB(Shockwave, w_crosshair, string, "gfx/crosshairshotgun");
13 /* crosshair */ ATTRIB(Shockwave, w_crosshair_size, float, 0.7);
14 /* wepimg    */ ATTRIB(Shockwave, model2, string, "weaponshotgun");
15 /* refname   */ ATTRIB(Shockwave, netname, string, "shockwave");
16 /* wepname   */ ATTRIB(Shockwave, m_name, string, _("Shockwave"));
17 ENDCLASS(Shockwave)
18 REGISTER_WEAPON(SHOCKWAVE, NEW(Shockwave));
19
20 #define SHOCKWAVE_SETTINGS(w_cvar,w_prop) SHOCKWAVE_SETTINGS_LIST(w_cvar, w_prop, SHOCKWAVE, shockwave)
21 #define SHOCKWAVE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22         w_cvar(id, sn, NONE, blast_animtime) \
23         w_cvar(id, sn, NONE, blast_damage) \
24         w_cvar(id, sn, NONE, blast_distance) \
25         w_cvar(id, sn, NONE, blast_edgedamage) \
26         w_cvar(id, sn, NONE, blast_force) \
27         w_cvar(id, sn, NONE, blast_force_forwardbias) \
28         w_cvar(id, sn, NONE, blast_force_zscale) \
29         w_cvar(id, sn, NONE, blast_jump_damage) \
30         w_cvar(id, sn, NONE, blast_jump_edgedamage) \
31         w_cvar(id, sn, NONE, blast_jump_force) \
32         w_cvar(id, sn, NONE, blast_jump_force_velocitybias) \
33         w_cvar(id, sn, NONE, blast_jump_force_zscale) \
34         w_cvar(id, sn, NONE, blast_jump_multiplier_accuracy) \
35         w_cvar(id, sn, NONE, blast_jump_multiplier_distance) \
36         w_cvar(id, sn, NONE, blast_jump_multiplier_min) \
37         w_cvar(id, sn, NONE, blast_jump_radius) \
38         w_cvar(id, sn, NONE, blast_multiplier_accuracy) \
39         w_cvar(id, sn, NONE, blast_multiplier_distance) \
40         w_cvar(id, sn, NONE, blast_multiplier_min) \
41         w_cvar(id, sn, NONE, blast_refire) \
42         w_cvar(id, sn, NONE, blast_splash_damage) \
43         w_cvar(id, sn, NONE, blast_splash_edgedamage) \
44         w_cvar(id, sn, NONE, blast_splash_force) \
45         w_cvar(id, sn, NONE, blast_splash_force_forwardbias) \
46         w_cvar(id, sn, NONE, blast_splash_multiplier_accuracy) \
47         w_cvar(id, sn, NONE, blast_splash_multiplier_distance) \
48         w_cvar(id, sn, NONE, blast_splash_multiplier_min) \
49         w_cvar(id, sn, NONE, blast_splash_radius) \
50         w_cvar(id, sn, NONE, blast_spread_max) \
51         w_cvar(id, sn, NONE, blast_spread_min) \
52         w_cvar(id, sn, NONE, melee_animtime) \
53         w_cvar(id, sn, NONE, melee_damage) \
54         w_cvar(id, sn, NONE, melee_delay) \
55         w_cvar(id, sn, NONE, melee_force) \
56         w_cvar(id, sn, NONE, melee_multihit) \
57         w_cvar(id, sn, NONE, melee_no_doubleslap) \
58         w_cvar(id, sn, NONE, melee_nonplayerdamage) \
59         w_cvar(id, sn, NONE, melee_range) \
60         w_cvar(id, sn, NONE, melee_refire) \
61         w_cvar(id, sn, NONE, melee_swing_side) \
62         w_cvar(id, sn, NONE, melee_swing_up) \
63         w_cvar(id, sn, NONE, melee_time) \
64         w_cvar(id, sn, NONE, melee_traces) \
65         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
66         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
67         w_prop(id, sn, string, weaponreplace, weaponreplace) \
68         w_prop(id, sn, float,  weaponstart, weaponstart) \
69         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
70         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
71
72 #ifdef SVQC
73 SHOCKWAVE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
74 #endif
75 #ifdef CSQC
76 void Net_ReadShockwaveParticle();
77 .vector sw_shotorg;
78 .vector sw_shotdir;
79 .float sw_distance;
80 .float sw_spread_max;
81 .float sw_spread_min;
82 .float sw_time;
83 #endif
84 #endif
85 #ifdef IMPLEMENTATION
86 #ifdef SVQC
87 spawnfunc(weapon_shockwave)
88 {
89         //if(autocvar_sv_q3acompat_machineshockwaveswap) // WEAPONTODO
90         if(autocvar_sv_q3acompat_machineshotgunswap)
91         if(self.classname != "droppedweapon")
92         {
93                 weapon_defaultspawnfunc(this, WEP_MACHINEGUN);
94                 return;
95         }
96         weapon_defaultspawnfunc(this, WEP_SHOCKWAVE);
97 }
98
99 const float MAX_SHOCKWAVE_HITS = 10;
100 //#define DEBUG_SHOCKWAVE
101
102 .float swing_prev;
103 .entity swing_alreadyhit;
104 .float shockwave_blasttime;
105 entity shockwave_hit[MAX_SHOCKWAVE_HITS];
106 float shockwave_hit_damage[MAX_SHOCKWAVE_HITS];
107 vector shockwave_hit_force[MAX_SHOCKWAVE_HITS];
108
109 // MELEE ATTACK MODE
110 void W_Shockwave_Melee_Think()
111 {SELFPARAM();
112         // declarations
113         float i, f, swing, swing_factor, swing_damage, meleetime, is_player;
114         entity target_victim;
115         vector targpos;
116
117         // check to see if we can still continue, otherwise give up now
118         if((self.realowner.deadflag != DEAD_NO) && WEP_CVAR(shockwave, melee_no_doubleslap))
119         {
120                 remove(self);
121                 return;
122         }
123
124         // set start time of melee
125         if(!self.cnt)
126         {
127                 self.cnt = time;
128                 W_PlayStrengthSound(self.realowner);
129         }
130
131         // update values for v_* vectors
132         makevectors(self.realowner.v_angle);
133
134         // calculate swing percentage based on time
135         meleetime = WEP_CVAR(shockwave, melee_time) * W_WeaponRateFactor();
136         swing = bound(0, (self.cnt + meleetime - time) / meleetime, 10);
137         f = ((1 - swing) * WEP_CVAR(shockwave, melee_traces));
138
139         // perform the traces needed for this frame
140         for(i=self.swing_prev; i < f; ++i)
141         {
142                 swing_factor = ((1 - (i / WEP_CVAR(shockwave, melee_traces))) * 2 - 1);
143
144                 targpos = (self.realowner.origin + self.realowner.view_ofs
145                         + (v_forward * WEP_CVAR(shockwave, melee_range))
146                         + (v_up * swing_factor * WEP_CVAR(shockwave, melee_swing_up))
147                         + (v_right * swing_factor * WEP_CVAR(shockwave, melee_swing_side)));
148
149                 WarpZone_traceline_antilag(
150                         self.realowner,
151                         (self.realowner.origin + self.realowner.view_ofs),
152                         targpos,
153                         false,
154                         self.realowner,
155                         ANTILAG_LATENCY(self.realowner)
156                 );
157
158                 // draw lightning beams for debugging
159 #ifdef DEBUG_SHOCKWAVE
160                 te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5);
161                 te_customflash(targpos, 40,  2, '1 1 1');
162 #endif
163
164                 is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent));
165
166                 if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary
167                         && (trace_ent.takedamage == DAMAGE_AIM)
168                         && (trace_ent != self.swing_alreadyhit)
169                         && (is_player || WEP_CVAR(shockwave, melee_nonplayerdamage)))
170                 {
171                         target_victim = trace_ent; // so it persists through other calls
172
173                         if(is_player) // this allows us to be able to nerf the non-player damage done in e.g. assault or onslaught
174                                 swing_damage = (WEP_CVAR(shockwave, melee_damage) * min(1, swing_factor + 1));
175                         else
176                                 swing_damage = (WEP_CVAR(shockwave, melee_nonplayerdamage) * min(1, swing_factor + 1));
177
178                         // trigger damage with this calculated info
179                         Damage(
180                                 target_victim,
181                                 self.realowner,
182                                 self.realowner,
183                                 swing_damage,
184                                 (WEP_SHOCKWAVE.m_id | HITTYPE_SECONDARY),
185                                 (self.realowner.origin + self.realowner.view_ofs),
186                                 (v_forward * WEP_CVAR(shockwave, melee_force))
187                         );
188
189                         // handle accuracy
190                         if(accuracy_isgooddamage(self.realowner, target_victim))
191                                 { accuracy_add(self.realowner, WEP_SHOCKWAVE.m_id, 0, swing_damage); }
192
193                         #ifdef DEBUG_SHOCKWAVE
194                         LOG_INFO(sprintf(
195                                 "MELEE: %s hitting %s with %f damage (factor: %f) at %f time.\n",
196                                 self.realowner.netname,
197                                 target_victim.netname,
198                                 swing_damage,
199                                 swing_factor,
200                                 time
201                         ));
202                         #endif
203
204                         // allow multiple hits with one swing, but not against the same player twice
205                         if(WEP_CVAR(shockwave, melee_multihit))
206                         {
207                                 self.swing_alreadyhit = target_victim;
208                                 continue; // move along to next trace
209                         }
210                         else
211                         {
212                                 remove(self);
213                                 return;
214                         }
215                 }
216         }
217
218         if(time >= self.cnt + meleetime)
219         {
220                 // melee is finished
221                 remove(self);
222                 return;
223         }
224         else
225         {
226                 // set up next frame
227                 self.swing_prev = i;
228                 self.nextthink = time;
229         }
230 }
231
232 void W_Shockwave_Melee(Weapon thiswep, entity actor, .entity weaponentity, int fire)
233 {
234         sound(actor, CH_WEAPON_A, SND_SHOTGUN_MELEE, VOL_BASE, ATTN_NORM);
235         weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(shockwave, melee_animtime), w_ready);
236
237         entity meleetemp = new(meleetemp);
238         make_pure(meleetemp);
239         meleetemp.owner = meleetemp.realowner = actor;
240         meleetemp.think = W_Shockwave_Melee_Think;
241         meleetemp.nextthink = time + WEP_CVAR(shockwave, melee_delay) * W_WeaponRateFactor();
242         W_SetupShot_Range(actor, true, 0, "", 0, WEP_CVAR(shockwave, melee_damage), WEP_CVAR(shockwave, melee_range));
243 }
244
245 // SHOCKWAVE ATTACK MODE
246 float W_Shockwave_Attack_CheckSpread(
247         vector targetorg,
248         vector nearest_on_line,
249         vector sw_shotorg,
250         vector attack_endpos)
251 {
252         float spreadlimit;
253         float distance_of_attack = vlen(sw_shotorg - attack_endpos);
254         float distance_from_line = vlen(targetorg - nearest_on_line);
255
256         spreadlimit = (distance_of_attack ? min(1, (vlen(sw_shotorg - nearest_on_line) / distance_of_attack)) : 1);
257         spreadlimit =
258                 (
259                         (WEP_CVAR(shockwave, blast_spread_min) * (1 - spreadlimit))
260                         +
261                         (WEP_CVAR(shockwave, blast_spread_max) * spreadlimit)
262                 );
263
264         if(
265                 (spreadlimit && (distance_from_line <= spreadlimit))
266                 &&
267                 ((vlen(normalize(targetorg - sw_shotorg) - normalize(attack_endpos - sw_shotorg)) * RAD2DEG) <= 90)
268         )
269                 { return bound(0, (distance_from_line / spreadlimit), 1); }
270         else
271                 { return false; }
272 }
273
274 float W_Shockwave_Attack_IsVisible(
275         entity head,
276         vector nearest_on_line,
277         vector sw_shotorg,
278         vector attack_endpos)
279 {SELFPARAM();
280         vector nearest_to_attacker = head.WarpZone_findradius_nearest;
281         vector center = (head.origin + (head.mins + head.maxs) * 0.5);
282         vector corner;
283         float i;
284
285         // STEP ONE: Check if the nearest point is clear
286         if(W_Shockwave_Attack_CheckSpread(nearest_to_attacker, nearest_on_line, sw_shotorg, attack_endpos))
287         {
288                 WarpZone_TraceLine(sw_shotorg, nearest_to_attacker, MOVE_NOMONSTERS, self);
289                 if(trace_fraction == 1) { return true; } // yes, the nearest point is clear and we can allow the damage
290         }
291
292         // STEP TWO: Check if shotorg to center point is clear
293         if(W_Shockwave_Attack_CheckSpread(center, nearest_on_line, sw_shotorg, attack_endpos))
294         {
295                 WarpZone_TraceLine(sw_shotorg, center, MOVE_NOMONSTERS, self);
296                 if(trace_fraction == 1) { return true; } // yes, the center point is clear and we can allow the damage
297         }
298
299         // STEP THREE: Check each corner to see if they are clear
300         for(i=1; i<=8; ++i)
301         {
302                 corner = get_corner_position(head, i);
303                 if(W_Shockwave_Attack_CheckSpread(corner, nearest_on_line, sw_shotorg, attack_endpos))
304                 {
305                         WarpZone_TraceLine(sw_shotorg, corner, MOVE_NOMONSTERS, self);
306                         if(trace_fraction == 1) { return true; } // yes, this corner is clear and we can allow the damage
307                 }
308         }
309
310         return false;
311 }
312
313 float W_Shockwave_Attack_CheckHit(
314         float queue,
315         entity head,
316         vector final_force,
317         float final_damage)
318 {
319         if(!head) { return false; }
320         float i;
321
322         for(i = 0; i <= queue; ++i)
323         {
324                 if(shockwave_hit[i] == head)
325                 {
326                         if(vlen(final_force) > vlen(shockwave_hit_force[i])) { shockwave_hit_force[i] = final_force; }
327                         if(final_damage > shockwave_hit_damage[i]) { shockwave_hit_damage[i] = final_damage; }
328                         return false;
329                 }
330         }
331
332         shockwave_hit[queue] = head;
333         shockwave_hit_force[queue] = final_force;
334         shockwave_hit_damage[queue] = final_damage;
335         return true;
336 }
337
338 void W_Shockwave_Send()
339 {SELFPARAM();
340         WriteHeader(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()
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(vec3(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                 METHOD(Shockwave, wr_aim, void(entity thiswep))
671                 {
672                         if(vlen(self.origin - self.enemy.origin) <= WEP_CVAR(shockwave, melee_range))
673                                 { self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, false); }
674                         else
675                                 { self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, false); }
676                 }
677                 METHOD(Shockwave, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
678                 {
679                         if(fire & 1)
680                         {
681                                 if(time >= actor.shockwave_blasttime) // handle refire separately so the secondary can be fired straight after a primary
682                                 {
683                                         if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(shockwave, blast_animtime)))
684                                         {
685                                                 W_Shockwave_Attack();
686                                                 actor.shockwave_blasttime = time + WEP_CVAR(shockwave, blast_refire) * W_WeaponRateFactor();
687                                                 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(shockwave, blast_animtime), w_ready);
688                                         }
689                                 }
690                         }
691                         else if(fire & 2)
692                         {
693                                 //if(actor.clip_load >= 0) // we are not currently reloading
694                                 if(!actor.crouch) // no crouchmelee please
695                                 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR(shockwave, melee_refire)))
696                                 {
697                                         // attempt forcing playback of the anim by switching to another anim (that we never play) here...
698                                         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, W_Shockwave_Melee);
699                                 }
700                         }
701                 }
702                 METHOD(Shockwave, wr_init, void(entity thiswep))
703                 {
704                         SHOCKWAVE_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
705                 }
706                 METHOD(Shockwave, wr_checkammo1, bool(entity thiswep))
707                 {
708                         return true; // infinite ammo
709                 }
710                 METHOD(Shockwave, wr_checkammo2, bool(entity thiswep))
711                 {
712                         // shockwave has infinite ammo
713                         return true;
714                 }
715                 METHOD(Shockwave, wr_config, void(entity thiswep))
716                 {
717                         SHOCKWAVE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
718                 }
719                 METHOD(Shockwave, wr_suicidemessage, int(entity thiswep))
720                 {
721                         return WEAPON_THINKING_WITH_PORTALS;
722                 }
723                 METHOD(Shockwave, wr_killmessage, int(entity thiswep))
724                 {
725                         if(w_deathtype & HITTYPE_SECONDARY)
726                                 return WEAPON_SHOCKWAVE_MURDER_SLAP;
727                         else
728                                 return WEAPON_SHOCKWAVE_MURDER;
729                 }
730
731 #endif
732 #ifdef CSQC
733 // WEAPONTODO: add client side settings for these
734 const float SW_MAXALPHA = 0.5;
735 const float SW_FADETIME = 0.4;
736 const float SW_DISTTOMIN = 200;
737 void Draw_Shockwave(entity this)
738 {
739         // fading/removal control
740         float a = bound(0, (SW_MAXALPHA - ((time - self.sw_time) / SW_FADETIME)), SW_MAXALPHA);
741         if(a < ALPHA_MIN_VISIBLE) { remove(self); }
742
743         // WEAPONTODO: save this only once when creating the entity
744         vector sw_color = getcsqcplayercolor(self.sv_entnum); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
745
746         // WEAPONTODO: trace to find what we actually hit
747         vector endpos = (self.sw_shotorg + (self.sw_shotdir * self.sw_distance));
748
749         vectorvectors(self.sw_shotdir);
750         vector right = v_right; // save this for when we do makevectors later
751         vector up = v_up; // save this for when we do makevectors later
752
753         // WEAPONTODO: combine and simplify these calculations
754         vector min_end = ((self.sw_shotorg + (self.sw_shotdir * SW_DISTTOMIN)) + (up * self.sw_spread_min));
755         vector max_end = (endpos + (up * self.sw_spread_max));
756         float spread_to_min = vlen(normalize(min_end - self.sw_shotorg) - self.sw_shotdir);
757         float spread_to_max = vlen(normalize(max_end - min_end) - self.sw_shotdir);
758
759         vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
760         vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
761         float new_max_dist, new_min_dist;
762
763         vector deviation, angle = '0 0 0';
764         float counter, divisions = 20;
765         for(counter = 0; counter < divisions; ++counter)
766         {
767                 // perfect circle effect lines
768                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / divisions));
769                 angle.y = v_forward.x;
770                 angle.z = v_forward.y;
771
772                 // first do the spread_to_min effect
773                 deviation = angle * spread_to_min;
774                 deviation = ((self.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
775                 new_min_dist = SW_DISTTOMIN;
776                 new_min_end = (self.sw_shotorg + (deviation * new_min_dist));
777                 //te_lightning2(world, new_min_end, self.sw_shotorg);
778
779                 // then calculate spread_to_max effect
780                 deviation = angle * spread_to_max;
781                 deviation = ((self.sw_shotdir + (right * deviation.y) + (up * deviation.z)));
782                 new_max_dist = vlen(new_min_end - endpos);
783                 new_max_end = (new_min_end + (deviation * new_max_dist));
784                 //te_lightning2(world, new_end, prev_min_end);
785
786
787                 if(counter == 0)
788                 {
789                         first_min_end = new_min_end;
790                         first_max_end = new_max_end;
791                 }
792
793                 if(counter >= 1)
794                 {
795                         // draw from shot origin to min spread radius
796                         R_BeginPolygon("", DRAWFLAG_NORMAL);
797                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
798                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
799                         R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
800                         R_EndPolygon();
801
802                         // draw from min spread radius to max spread radius
803                         R_BeginPolygon("", DRAWFLAG_NORMAL);
804                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
805                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
806                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
807                         R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
808                         R_EndPolygon();
809                 }
810
811                 prev_min_end = new_min_end;
812                 prev_max_end = new_max_end;
813
814                 // last division only
815                 if((counter + 1) == divisions)
816                 {
817                         // draw from shot origin to min spread radius
818                         R_BeginPolygon("", DRAWFLAG_NORMAL);
819                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
820                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
821                         R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
822                         R_EndPolygon();
823
824                         // draw from min spread radius to max spread radius
825                         R_BeginPolygon("", DRAWFLAG_NORMAL);
826                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
827                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
828                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
829                         R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
830                         R_EndPolygon();
831                 }
832         }
833 }
834
835 NET_HANDLE(TE_CSQC_SHOCKWAVEPARTICLE, bool isNew)
836 {
837         Net_ReadShockwaveParticle();
838         return true;
839 }
840
841 void Net_ReadShockwaveParticle()
842 {
843         entity shockwave;
844         shockwave = spawn();
845         shockwave.draw = Draw_Shockwave;
846
847         shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
848         shockwave.sw_shotdir_x = ReadCoord(); shockwave.sw_shotdir_y = ReadCoord(); shockwave.sw_shotdir_z = ReadCoord();
849
850         shockwave.sw_distance = ReadShort();
851         shockwave.sw_spread_max = ReadByte();
852         shockwave.sw_spread_min = ReadByte();
853
854         shockwave.sv_entnum = ReadByte();
855
856         shockwave.sw_time = time;
857 }
858
859                 METHOD(Shockwave, wr_impacteffect, void(entity thiswep))
860                 {
861                         // handled by Net_ReadShockwaveParticle
862                         //vector org2;
863                         //org2 = w_org + w_backoff * 2;
864                         //pointparticles(EFFECT_BLASTER_IMPACT, org2, w_backoff * 1000, 1);
865                 }
866
867 #endif
868 #endif