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