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