5 /* ammotype */ ammo_cells,
7 /* flags */ WEP_FLAG_NORMAL,
8 /* rating */ BOT_PICKUP_RATING_HIGH,
10 /* modelname */ "hlac",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairhlac 0.7",
13 /* wepimg */ "weaponhlac",
15 /* wepname */ _("Arc")
18 #define ARC_SETTINGS(w_cvar,w_prop) ARC_SETTINGS_LIST(w_cvar, w_prop, ARC, arc)
19 #define ARC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, NONE, beam_ammo) \
21 w_cvar(id, sn, NONE, beam_animtime) \
22 w_cvar(id, sn, NONE, beam_botaimspeed) \
23 w_cvar(id, sn, NONE, beam_botaimlifetime) \
24 w_cvar(id, sn, NONE, beam_damage) \
25 w_cvar(id, sn, NONE, beam_degreespersegment) \
26 w_cvar(id, sn, NONE, beam_distancepersegment) \
27 w_cvar(id, sn, NONE, beam_falloff_halflifedist) \
28 w_cvar(id, sn, NONE, beam_falloff_maxdist) \
29 w_cvar(id, sn, NONE, beam_falloff_mindist) \
30 w_cvar(id, sn, NONE, beam_force) \
31 w_cvar(id, sn, NONE, beam_healing_amax) \
32 w_cvar(id, sn, NONE, beam_healing_aps) \
33 w_cvar(id, sn, NONE, beam_healing_hmax) \
34 w_cvar(id, sn, NONE, beam_healing_hps) \
35 w_cvar(id, sn, NONE, beam_maxangle) \
36 w_cvar(id, sn, NONE, beam_nonplayerdamage) \
37 w_cvar(id, sn, NONE, beam_range) \
38 w_cvar(id, sn, NONE, beam_refire) \
39 w_cvar(id, sn, NONE, beam_returnspeed) \
40 w_cvar(id, sn, NONE, beam_tightness) \
41 w_cvar(id, sn, NONE, burst_ammo) \
42 w_cvar(id, sn, NONE, burst_damage) \
43 w_cvar(id, sn, NONE, burst_healing_aps) \
44 w_cvar(id, sn, NONE, burst_healing_hps) \
45 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
46 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
47 w_prop(id, sn, string, weaponreplace, weaponreplace) \
48 w_prop(id, sn, float, weaponstart, weaponstart) \
49 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
50 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
53 #define ARC_MAX_SEGMENTS 20
54 vector arc_shotorigin[4];
63 #define ARC_BT_BURST_MISS 10
64 #define ARC_BT_BURST_WALL 11
65 #define ARC_BT_BURST_HEAL 12
66 #define ARC_BT_BURST_HIT 13
67 #define ARC_BT_BURSTMASK 10
70 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
72 .float BUTTON_ATCK_prev; // for better animation control
74 .float beam_initialized;
78 void Ent_ReadArcBeam(float isnew);
82 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
84 float W_Arc_Beam_Send(entity to, float sf)
86 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
88 // Truncate information when this beam is displayed to the owner client
89 // - The owner client has no use for beam start position or directions,
90 // it always figures this information out for itself with csqc code.
91 // - Spectating the owner also truncates this information.
92 float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
104 WriteByte(MSG_ENTITY, sf);
106 if(sf & 1) // settings information
108 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_degreespersegment));
109 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_distancepersegment));
110 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
111 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
112 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
113 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
115 WriteByte(MSG_ENTITY, drawlocal);
117 if(sf & 2) // starting location
119 WriteCoord(MSG_ENTITY, self.beam_start_x);
120 WriteCoord(MSG_ENTITY, self.beam_start_y);
121 WriteCoord(MSG_ENTITY, self.beam_start_z);
123 if(sf & 4) // want/aim direction
125 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
126 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
127 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
129 if(sf & 8) // beam direction
131 WriteCoord(MSG_ENTITY, self.beam_dir_x);
132 WriteCoord(MSG_ENTITY, self.beam_dir_y);
133 WriteCoord(MSG_ENTITY, self.beam_dir_z);
135 if(sf & 16) // beam type
137 WriteByte(MSG_ENTITY, self.beam_type);
143 void W_Arc_Beam_Think(void)
145 if(self != self.owner.arc_beam)
152 (self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
154 self.owner.deadflag != DEAD_NO
156 (!self.owner.BUTTON_ATCK && !self.beam_bursting)
158 self.owner.freezetag_frozen
162 // is this needed? I thought this is changed to world when removed ANYWAY
163 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
165 entity oldself = self;
167 if(!WEP_ACTION(WEP_ARC, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC, WR_CHECKAMMO2))
169 // note: this doesn't force the switch
170 W_SwitchToOtherWeapon(self);
178 if(self.owner.BUTTON_ATCK2 || self.beam_bursting)
180 if(!self.beam_bursting)
181 self.beam_bursting = TRUE;
182 burst = ARC_BT_BURSTMASK;
186 float coefficient = frametime;
187 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
191 { rootammo = WEP_CVAR(arc, burst_ammo); }
193 { rootammo = WEP_CVAR(arc, beam_ammo); }
197 coefficient = min(coefficient, self.owner.WEP_AMMO(ARC) / rootammo);
198 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - (rootammo * frametime));
202 makevectors(self.owner.v_angle);
210 WEP_CVAR(arc, beam_damage) * coefficient,
211 WEP_CVAR(arc, beam_range)
214 // network information: shot origin and want/aim direction
215 if(self.beam_start != w_shotorg)
218 self.beam_start = w_shotorg;
220 if(self.beam_wantdir != w_shotdir)
223 self.beam_wantdir = w_shotdir;
226 if(!self.beam_initialized)
229 for(i = 0; i < ARC_MAX_SEGMENTS; ++i)
230 self.lg_ents[i] = spawn();
233 self.beam_dir = w_shotdir;
234 self.beam_initialized = TRUE;
237 // WEAPONTODO: Detect player velocity so that the beam curves when moving too
238 // idea: blend together self.beam_dir with the inverted direction the player is moving in
239 // might have to make some special accomodation so that it only uses view_right and view_up
241 // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
244 if(self.beam_dir != w_shotdir)
246 // calculate how much we're going to move the end of the beam to the want position
247 // WEAPONTODO (server and client):
248 // blendfactor never actually becomes 0 in this situation, which is a problem
249 // regarding precision... this means that self.beam_dir and w_shotdir approach
250 // eachother, however they never actually become the same value with this method.
251 // Perhaps we should do some form of rounding/snapping?
252 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
253 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
255 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
256 float blendfactor = bound(
258 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
259 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
261 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
265 // the radius is not too far yet, no worries :D
266 float blendfactor = bound(
268 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
271 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
274 // network information: beam direction
277 // calculate how many segments are needed
278 float max_allowed_segments;
280 if(WEP_CVAR(arc, beam_distancepersegment))
282 max_allowed_segments = min(
284 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
287 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
289 if(WEP_CVAR(arc, beam_degreespersegment))
296 WEP_CVAR(arc, beam_maxangle)
299 WEP_CVAR(arc, beam_degreespersegment)
304 else { segments = 1; }
306 else { segments = 1; }
308 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
311 float new_beam_type = 0;
312 vector last_origin = w_shotorg;
313 for(i = 1; i <= segments; ++i)
315 // WEAPONTODO (server and client):
316 // Segment blend and distance should probably really be calculated in a better way,
317 // however I am not sure how to do it properly. There are a few things I have tried,
318 // but most of them do not work properly due to my lack of understanding regarding
319 // the mathematics behind them.
321 // Ideally, we should calculate the positions along a perfect curve
322 // between wantdir and self.beam_dir with an option for depth of arc
324 // Another issue is that (on the client code) we must separate the
325 // curve into multiple rendered curves when handling warpzones.
327 // I can handle this by detecting it for each segment, however that
328 // is a fairly inefficient method in comparison to having a curved line
329 // drawing function similar to Draw_CylindricLine that accepts
330 // top and bottom origins as input, this way there would be no
331 // overlapping edges when connecting the curved pieces.
333 // WEAPONTODO (client):
334 // In order to do nice fading and pointing on the starting segment, we must always
335 // have that drawn as a separate triangle... However, that is difficult to do when
336 // keeping in mind the above problems and also optimizing the amount of segments
337 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
339 // calculate this on every segment to ensure that we always reach the full length of the attack
340 float segmentblend = bound(0, (i/segments) + WEP_CVAR(arc, beam_tightness), 1);
341 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
343 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
344 // Figure out how this actually should work.
345 vector new_dir = normalize(
346 (w_shotdir * (1 - segmentblend))
348 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
350 vector new_origin = last_origin + (new_dir * segmentdist);
352 WarpZone_traceline_antilag(
358 ANTILAG_LATENCY(self.owner)
362 trace_ent.classname == "player"
364 trace_ent.classname == "body"
366 (trace_ent.flags & FL_MONSTER)
369 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
371 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
372 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
374 float falloff = ExponentialFalloff(
375 WEP_CVAR(arc, beam_falloff_mindist),
376 WEP_CVAR(arc, beam_falloff_maxdist),
377 WEP_CVAR(arc, beam_falloff_halflifedist),
378 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
381 if(is_player && SAME_TEAM(self.owner, trace_ent))
383 float roothealth, rootarmor;
386 roothealth = WEP_CVAR(arc, burst_healing_hps);
387 rootarmor = WEP_CVAR(arc, burst_healing_aps);
391 roothealth = WEP_CVAR(arc, beam_healing_hps);
392 rootarmor = WEP_CVAR(arc, beam_healing_aps);
395 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
397 trace_ent.health = min(
398 trace_ent.health + (roothealth * coefficient),
399 WEP_CVAR(arc, beam_healing_hmax)
402 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
404 trace_ent.armorvalue = min(
405 trace_ent.armorvalue + (rootarmor * coefficient),
406 WEP_CVAR(arc, beam_healing_amax)
410 // stop rot, set visual effect
411 if(roothealth || rootarmor)
413 trace_ent.pauserothealth_finished = max(
414 trace_ent.pauserothealth_finished,
415 time + autocvar_g_balance_pause_health_rot
417 trace_ent.pauserotarmor_finished = max(
418 trace_ent.pauserotarmor_finished,
419 time + autocvar_g_balance_pause_armor_rot
421 new_beam_type = ARC_BT_HEAL;
430 { rootdamage = WEP_CVAR(arc, burst_damage); }
432 { rootdamage = WEP_CVAR(arc, beam_damage); }
435 { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
437 if(accuracy_isgooddamage(self.owner, trace_ent))
443 rootdamage * coefficient * falloff
451 rootdamage * coefficient * falloff,
454 WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
457 new_beam_type = ARC_BT_HIT;
461 else if(trace_fraction != 1)
463 // we collided with geometry
464 new_beam_type = ARC_BT_WALL;
469 last_origin = new_origin;
473 // if we're bursting, use burst visual effects
474 new_beam_type += burst;
476 // network information: beam type
477 if(new_beam_type != self.beam_type)
479 self.SendFlags |= 16;
480 self.beam_type = new_beam_type;
483 self.owner.beam_prev = time;
484 self.nextthink = time;
487 void W_Arc_Beam(float burst)
489 // only play fire sound if 1 sec has passed since player let go the fire button
490 if(time - self.beam_prev > 1)
492 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
495 entity beam = self.arc_beam = spawn();
496 beam.classname = "W_Arc_Beam";
497 beam.solid = SOLID_NOT;
498 beam.think = W_Arc_Beam_Think;
500 beam.movetype = MOVETYPE_NONE;
501 beam.bot_dodge = TRUE;
502 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
503 beam.beam_bursting = burst;
504 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
506 entity oldself = self;
512 float W_Arc(float req)
518 if(WEP_CVAR(arc, beam_botaimspeed))
520 self.BUTTON_ATCK = bot_aim(
521 WEP_CVAR(arc, beam_botaimspeed),
523 WEP_CVAR(arc, beam_botaimlifetime),
529 self.BUTTON_ATCK = bot_aim(
541 if(self.arc_beam.beam_heat > threshold)
543 stop the beam somehow
544 play overheat animation
548 if(self.BUTTON_ATCK || self.BUTTON_ATCK2 || self.arc_beam.beam_bursting)
550 if(self.BUTTON_ATCK_prev)
553 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
554 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
557 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
560 if((!self.arc_beam) || wasfreed(self.arc_beam))
562 if(weapon_prepareattack(!!self.BUTTON_ATCK2, 0))
564 W_Arc_Beam(!!self.BUTTON_ATCK2);
566 if(!self.BUTTON_ATCK_prev)
568 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
569 self.BUTTON_ATCK_prev = 1;
576 if(self.BUTTON_ATCK_prev != 0)
578 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
579 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
581 self.BUTTON_ATCK_prev = 0;
585 if(self.BUTTON_ATCK2)
586 if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
589 self.arc_count = autocvar_g_balance_arc_secondary_count;
590 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
591 self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
599 precache_model("models/weapons/g_arc.md3");
600 precache_model("models/weapons/v_arc.md3");
601 precache_model("models/weapons/h_arc.iqm");
602 //precache_sound("weapons/arc_fire.wav");
603 //precache_sound("weapons/arc_fire2.wav");
604 //precache_sound("weapons/arc_impact.wav");
605 if(!arc_shotorigin[0])
607 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
608 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
609 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
610 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
612 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
617 return ((!WEP_CVAR(arc, beam_ammo)) || (self.WEP_AMMO(ARC) > 0));
621 return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
625 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
630 if(w_deathtype & HITTYPE_SECONDARY)
632 return WEAPON_ELECTRO_MURDER_ORBS;
636 if(w_deathtype & HITTYPE_BOUNCE)
637 return WEAPON_ELECTRO_MURDER_COMBO;
639 return WEAPON_ELECTRO_MURDER_BOLT;
650 .float beam_thickness;
651 .float beam_traileffect;
652 .float beam_hiteffect;
653 .float beam_hitlight[4]; // 0: radius, 123: rgb
654 .float beam_muzzleeffect;
655 .float beam_muzzlelight[4]; // 0: radius, 123: rgb
658 .entity beam_muzzleentity;
660 .float beam_degreespersegment;
661 .float beam_distancepersegment;
662 .float beam_usevieworigin;
663 .float beam_initialized;
664 .float beam_maxangle;
666 .float beam_returnspeed;
667 .float beam_tightness;
668 .vector beam_shotorigin;
671 entity Draw_ArcBeam_callback_entity;
672 vector Draw_ArcBeam_callback_new_dir;
673 float Draw_ArcBeam_callback_segmentdist;
674 float Draw_ArcBeam_callback_last_thickness;
675 vector Draw_ArcBeam_callback_last_top;
676 vector Draw_ArcBeam_callback_last_bottom;
678 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
680 entity beam = Draw_ArcBeam_callback_entity;
681 vector transformed_view_org;
682 transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
684 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
690 if(trace_fraction != 1)
692 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
693 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
694 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
704 // decide upon thickness
705 float thickness = beam.beam_thickness;
707 // draw primary beam render
708 vector top = hitorigin + (thickdir * thickness);
709 vector bottom = hitorigin - (thickdir * thickness);
710 //vector last_top = start + (thickdir * Draw_ArcBeam_callback_last_thickness);
711 //vector last_bottom = start - (thickdir * Draw_ArcBeam_callback_last_thickness);
713 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
716 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
721 Draw_ArcBeam_callback_last_top,
722 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
727 Draw_ArcBeam_callback_last_bottom,
728 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
734 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
740 // draw trailing particles
742 // - Don't use spammy particle counts here, use a FEW small particles around the beam
743 // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
744 if(beam.beam_traileffect)
746 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
749 // set up for the next
750 Draw_ArcBeam_callback_last_thickness = thickness;
751 Draw_ArcBeam_callback_last_top = top;
752 Draw_ArcBeam_callback_last_bottom = bottom;
755 void Draw_ArcBeam(void)
757 if(!self.beam_usevieworigin)
759 InterpolateOrigin_Do();
762 // origin = beam starting origin
763 // v_angle = wanted/aim direction
764 // angles = current direction of beam
767 vector wantdir; //= view_forward;
768 vector beamdir; //= self.beam_dir;
771 if(self.beam_usevieworigin)
774 // Currently we have to replicate nearly the same method of figuring
775 // out the shotdir that the server does... Ideally in the future we
776 // should be able to acquire this from a generalized function built
777 // into a weapon system for client code.
779 // find where we are aiming
780 makevectors(view_angles);
782 // decide upon start position
783 if(self.beam_usevieworigin == 2)
784 { start_pos = view_origin; }
786 { start_pos = self.origin; }
788 // trace forward with an estimation
791 start_pos + view_forward * self.beam_range,
796 // untransform in case our trace went through a warpzone
801 vector shothitpos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); // warpzone support
806 // un-adjust trueaim if shotend is too close
807 if(vlen(shothitpos - view_origin) < g_trueaim_minrange)
808 shothitpos = view_origin + (view_forward * g_trueaim_minrange);
810 // move shot origin to the actual gun muzzle origin
811 vector origin_offset =
812 view_forward * self.beam_shotorigin_x
813 + view_right * -self.beam_shotorigin_y
814 + view_up * self.beam_shotorigin_z;
816 start_pos = start_pos + origin_offset;
818 // calculate the aim direction now
819 wantdir = normalize(shothitpos - start_pos);
821 if(!self.beam_initialized)
823 self.beam_dir = wantdir;
824 self.beam_initialized = TRUE;
827 if(self.beam_dir != wantdir)
829 // calculate how much we're going to move the end of the beam to the want position
830 // WEAPONTODO (server and client):
831 // blendfactor never actually becomes 0 in this situation, which is a problem
832 // regarding precision... this means that self.beam_dir and w_shotdir approach
833 // eachother, however they never actually become the same value with this method.
834 // Perhaps we should do some form of rounding/snapping?
835 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
836 if(angle && (angle > self.beam_maxangle))
838 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
839 float blendfactor = bound(
841 (1 - (self.beam_returnspeed * frametime)),
842 min(self.beam_maxangle / angle, 1)
844 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
848 // the radius is not too far yet, no worries :D
849 float blendfactor = bound(
851 (1 - (self.beam_returnspeed * frametime)),
854 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
857 // calculate how many segments are needed
858 float max_allowed_segments;
860 if(self.beam_distancepersegment)
862 max_allowed_segments = min(
864 1 + (vlen(wantdir / self.beam_distancepersegment))
867 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
869 if(self.beam_degreespersegment)
879 self.beam_degreespersegment
884 else { segments = 1; }
886 else { segments = 1; }
888 // set the beam direction which the rest of the code will refer to
889 beamdir = self.beam_dir;
891 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
892 self.angles = fixedvectoangles2(view_forward, view_up);
896 // set the values from the provided info from the networked entity
897 start_pos = self.origin;
898 wantdir = self.v_angle;
899 beamdir = self.angles;
901 if(beamdir != wantdir)
903 float angle = vlen(wantdir - beamdir) * RAD2DEG;
905 // calculate how many segments are needed
906 float max_allowed_segments;
908 if(self.beam_distancepersegment)
910 max_allowed_segments = min(
912 1 + (vlen(wantdir / self.beam_distancepersegment))
915 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
917 if(self.beam_degreespersegment)
927 self.beam_degreespersegment
932 else { segments = 1; }
934 else { segments = 1; }
937 setorigin(self, start_pos);
938 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
940 vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
942 Draw_ArcBeam_callback_entity = self;
943 Draw_ArcBeam_callback_last_thickness = 0;
944 Draw_ArcBeam_callback_last_top = start_pos;
945 Draw_ArcBeam_callback_last_bottom = start_pos;
947 vector last_origin = start_pos;
950 for(i = 1; i <= segments; ++i)
952 // WEAPONTODO (server and client):
953 // Segment blend and distance should probably really be calculated in a better way,
954 // however I am not sure how to do it properly. There are a few things I have tried,
955 // but most of them do not work properly due to my lack of understanding regarding
956 // the mathematics behind them.
958 // Ideally, we should calculate the positions along a perfect curve
959 // between wantdir and self.beam_dir with an option for depth of arc
961 // Another issue is that (on the client code) we must separate the
962 // curve into multiple rendered curves when handling warpzones.
964 // I can handle this by detecting it for each segment, however that
965 // is a fairly inefficient method in comparison to having a curved line
966 // drawing function similar to Draw_CylindricLine that accepts
967 // top and bottom origins as input, this way there would be no
968 // overlapping edges when connecting the curved pieces.
970 // WEAPONTODO (client):
971 // In order to do nice fading and pointing on the starting segment, we must always
972 // have that drawn as a separate triangle... However, that is difficult to do when
973 // keeping in mind the above problems and also optimizing the amount of segments
974 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
976 // calculate this on every segment to ensure that we always reach the full length of the attack
977 float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
978 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
980 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
981 // Figure out how this actually should work.
982 vector new_dir = normalize(
983 (wantdir * (1 - segmentblend))
985 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
987 vector new_origin = last_origin + (new_dir * segmentdist);
989 Draw_ArcBeam_callback_segmentdist = segmentdist;
990 Draw_ArcBeam_callback_new_dir = new_dir;
992 WarpZone_TraceBox_ThroughZone(
1000 Draw_ArcBeam_callback
1003 //printf("segment: %d, warpzone transform: %d\n", i, (WarpZone_trace_transform != world));
1006 // Figure out some way to detect a collision with geometry with callback...
1007 // That way we can know when we are done drawing the beam and skip
1008 // the rest of the segments without breaking warpzone support.
1010 last_origin = WarpZone_TransformOrigin(WarpZone_trace_transform, new_origin);
1011 beam_endpos_estimate = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos_estimate);
1014 // startpoint and endpoint drawn visual effects
1015 if(self.beam_hiteffect)
1018 self.beam_hiteffect,
1024 if(self.beam_hitlight[0])
1028 self.beam_hitlight[0],
1030 self.beam_hitlight[1],
1031 self.beam_hitlight[2],
1032 self.beam_hitlight[3]
1036 if(self.beam_muzzleeffect)
1039 self.beam_muzzleeffect,
1040 start_pos + wantdir * 20,
1045 if(self.beam_muzzlelight[0])
1048 start_pos + wantdir * 20,
1049 self.beam_muzzlelight[0],
1051 self.beam_muzzlelight[1],
1052 self.beam_muzzlelight[2],
1053 self.beam_muzzlelight[3]
1059 Draw_ArcBeam_callback_entity = world;
1060 Draw_ArcBeam_callback_new_dir = '0 0 0';
1061 Draw_ArcBeam_callback_segmentdist = 0;
1062 Draw_ArcBeam_callback_last_thickness = 0;
1063 Draw_ArcBeam_callback_last_top = '0 0 0';
1064 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1067 void Remove_ArcBeam(void)
1069 remove(self.beam_muzzleentity);
1070 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1073 void Ent_ReadArcBeam(float isnew)
1075 float sf = ReadByte();
1080 // calculate shot origin offset from gun alignment
1081 float gunalign = autocvar_cl_gunalign;
1082 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1083 gunalign = 3; // default value
1086 self.beam_shotorigin = arc_shotorigin[gunalign];
1088 // set other main attributes of the beam
1089 self.draw = Draw_ArcBeam;
1090 self.entremove = Remove_ArcBeam;
1091 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1095 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1096 flash.drawmask = MASK_NORMAL;
1097 flash.solid = SOLID_NOT;
1098 setattachment(flash, self, "");
1099 setorigin(flash, '0 0 0');
1101 self.beam_muzzleentity = flash;
1105 flash = self.beam_muzzleentity;
1108 if(sf & 1) // settings information
1110 self.beam_degreespersegment = ReadShort();
1111 self.beam_distancepersegment = ReadShort();
1112 self.beam_maxangle = ReadShort();
1113 self.beam_range = ReadCoord();
1114 self.beam_returnspeed = ReadShort();
1115 self.beam_tightness = (ReadByte() / 10);
1119 if(autocvar_chase_active)
1120 { self.beam_usevieworigin = 1; }
1121 else // use view origin
1122 { self.beam_usevieworigin = 2; }
1126 self.beam_usevieworigin = 0;
1130 if(!self.beam_usevieworigin)
1132 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1133 self.iflags = IFLAG_ORIGIN;
1135 InterpolateOrigin_Undo();
1138 if(sf & 2) // starting location
1140 self.origin_x = ReadCoord();
1141 self.origin_y = ReadCoord();
1142 self.origin_z = ReadCoord();
1144 else if(self.beam_usevieworigin) // infer the location from player location
1146 if(self.beam_usevieworigin == 2)
1149 self.origin = view_origin;
1153 // use player origin so that third person display still works
1154 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1158 setorigin(self, self.origin);
1160 if(sf & 4) // want/aim direction
1162 self.v_angle_x = ReadCoord();
1163 self.v_angle_y = ReadCoord();
1164 self.v_angle_z = ReadCoord();
1167 if(sf & 8) // beam direction
1169 self.angles_x = ReadCoord();
1170 self.angles_y = ReadCoord();
1171 self.angles_z = ReadCoord();
1174 if(sf & 16) // beam type
1176 self.beam_type = ReadByte();
1177 switch(self.beam_type)
1181 self.beam_color = '-1 -1 1';
1182 self.beam_alpha = 0.5;
1183 self.beam_thickness = 8;
1184 self.beam_traileffect = FALSE;
1185 self.beam_hiteffect = particleeffectnum("electro_lightning");
1186 self.beam_hitlight[0] = 0;
1187 self.beam_hitlight[1] = 1;
1188 self.beam_hitlight[2] = 1;
1189 self.beam_hitlight[3] = 1;
1190 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1191 self.beam_muzzlelight[0] = 0;
1192 self.beam_muzzlelight[1] = 1;
1193 self.beam_muzzlelight[2] = 1;
1194 self.beam_muzzlelight[3] = 1;
1195 self.beam_image = "particles/lgbeam";
1196 setmodel(flash, "models/flash.md3");
1197 flash.alpha = self.beam_alpha;
1198 flash.colormod = self.beam_color;
1202 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1204 self.beam_color = '0.5 0.5 1';
1205 self.beam_alpha = 0.5;
1206 self.beam_thickness = 8;
1207 self.beam_traileffect = FALSE;
1208 self.beam_hiteffect = particleeffectnum("electro_lightning");
1209 self.beam_hitlight[0] = 0;
1210 self.beam_hitlight[1] = 1;
1211 self.beam_hitlight[2] = 1;
1212 self.beam_hitlight[3] = 1;
1213 self.beam_muzzleeffect = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
1214 self.beam_muzzlelight[0] = 0;
1215 self.beam_muzzlelight[1] = 1;
1216 self.beam_muzzlelight[2] = 1;
1217 self.beam_muzzlelight[3] = 1;
1218 self.beam_image = "particles/lgbeam";
1219 setmodel(flash, "models/flash.md3");
1220 flash.alpha = self.beam_alpha;
1221 flash.colormod = self.beam_color;
1227 self.beam_color = '0 1 0';
1228 self.beam_alpha = 0.5;
1229 self.beam_thickness = 8;
1230 self.beam_traileffect = FALSE;
1231 self.beam_hiteffect = particleeffectnum("healray_impact");
1232 self.beam_hitlight[0] = 0;
1233 self.beam_hitlight[1] = 1;
1234 self.beam_hitlight[2] = 1;
1235 self.beam_hitlight[3] = 1;
1236 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1237 self.beam_muzzlelight[0] = 0;
1238 self.beam_muzzlelight[1] = 1;
1239 self.beam_muzzlelight[2] = 1;
1240 self.beam_muzzlelight[3] = 1;
1241 self.beam_image = "particles/lgbeam";
1242 setmodel(flash, "models/flash.md3");
1243 flash.alpha = self.beam_alpha;
1244 flash.colormod = self.beam_color;
1250 self.beam_color = '1 0 1';
1251 self.beam_alpha = 0.5;
1252 self.beam_thickness = 8;
1253 self.beam_traileffect = particleeffectnum("nex_beam");
1254 self.beam_hiteffect = particleeffectnum("electro_lightning");
1255 self.beam_hitlight[0] = 20;
1256 self.beam_hitlight[1] = 1;
1257 self.beam_hitlight[2] = 0;
1258 self.beam_hitlight[3] = 0;
1259 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1260 self.beam_muzzlelight[0] = 50;
1261 self.beam_muzzlelight[1] = 1;
1262 self.beam_muzzlelight[2] = 0;
1263 self.beam_muzzlelight[3] = 0;
1264 self.beam_image = "particles/lgbeam";
1265 setmodel(flash, "models/flash.md3");
1266 flash.alpha = self.beam_alpha;
1267 flash.colormod = self.beam_color;
1271 case ARC_BT_BURST_MISS:
1273 self.beam_color = '-1 -1 1';
1274 self.beam_alpha = 0.5;
1275 self.beam_thickness = 14;
1276 self.beam_traileffect = FALSE;
1277 self.beam_hiteffect = particleeffectnum("electro_lightning");
1278 self.beam_hitlight[0] = 0;
1279 self.beam_hitlight[1] = 1;
1280 self.beam_hitlight[2] = 1;
1281 self.beam_hitlight[3] = 1;
1282 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1283 self.beam_muzzlelight[0] = 0;
1284 self.beam_muzzlelight[1] = 1;
1285 self.beam_muzzlelight[2] = 1;
1286 self.beam_muzzlelight[3] = 1;
1287 self.beam_image = "particles/lgbeam";
1288 setmodel(flash, "models/flash.md3");
1289 flash.alpha = self.beam_alpha;
1290 flash.colormod = self.beam_color;
1294 case ARC_BT_BURST_WALL:
1296 self.beam_color = '0.5 0.5 1';
1297 self.beam_alpha = 0.5;
1298 self.beam_thickness = 14;
1299 self.beam_traileffect = FALSE;
1300 self.beam_hiteffect = particleeffectnum("electro_lightning");
1301 self.beam_hitlight[0] = 0;
1302 self.beam_hitlight[1] = 1;
1303 self.beam_hitlight[2] = 1;
1304 self.beam_hitlight[3] = 1;
1305 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1306 self.beam_muzzlelight[0] = 0;
1307 self.beam_muzzlelight[1] = 1;
1308 self.beam_muzzlelight[2] = 1;
1309 self.beam_muzzlelight[3] = 1;
1310 self.beam_image = "particles/lgbeam";
1311 setmodel(flash, "models/flash.md3");
1312 flash.alpha = self.beam_alpha;
1313 flash.colormod = self.beam_color;
1317 case ARC_BT_BURST_HEAL:
1319 self.beam_color = '0 1 0';
1320 self.beam_alpha = 0.5;
1321 self.beam_thickness = 14;
1322 self.beam_traileffect = FALSE;
1323 self.beam_hiteffect = particleeffectnum("electro_lightning");
1324 self.beam_hitlight[0] = 0;
1325 self.beam_hitlight[1] = 1;
1326 self.beam_hitlight[2] = 1;
1327 self.beam_hitlight[3] = 1;
1328 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1329 self.beam_muzzlelight[0] = 0;
1330 self.beam_muzzlelight[1] = 1;
1331 self.beam_muzzlelight[2] = 1;
1332 self.beam_muzzlelight[3] = 1;
1333 self.beam_image = "particles/lgbeam";
1334 setmodel(flash, "models/flash.md3");
1335 flash.alpha = self.beam_alpha;
1336 flash.colormod = self.beam_color;
1340 case ARC_BT_BURST_HIT:
1342 self.beam_color = '1 0 1';
1343 self.beam_alpha = 0.5;
1344 self.beam_thickness = 14;
1345 self.beam_traileffect = FALSE;
1346 self.beam_hiteffect = particleeffectnum("electro_lightning");
1347 self.beam_hitlight[0] = 0;
1348 self.beam_hitlight[1] = 1;
1349 self.beam_hitlight[2] = 1;
1350 self.beam_hitlight[3] = 1;
1351 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1352 self.beam_muzzlelight[0] = 0;
1353 self.beam_muzzlelight[1] = 1;
1354 self.beam_muzzlelight[2] = 1;
1355 self.beam_muzzlelight[3] = 1;
1356 self.beam_image = "particles/lgbeam";
1357 setmodel(flash, "models/flash.md3");
1358 flash.alpha = self.beam_alpha;
1359 flash.colormod = self.beam_color;
1364 // shouldn't be possible, but lets make it colorful if it does :D
1367 self.beam_color = randomvec();
1368 self.beam_alpha = 1;
1369 self.beam_thickness = 8;
1370 self.beam_traileffect = FALSE;
1371 self.beam_hiteffect = FALSE;
1372 self.beam_hitlight[0] = 0;
1373 self.beam_hitlight[1] = 1;
1374 self.beam_hitlight[2] = 1;
1375 self.beam_hitlight[3] = 1;
1376 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1377 self.beam_muzzlelight[0] = 0;
1378 self.beam_muzzlelight[1] = 1;
1379 self.beam_muzzlelight[2] = 1;
1380 self.beam_muzzlelight[3] = 1;
1381 self.beam_image = "particles/lgbeam";
1382 setmodel(flash, "models/flash.md3");
1383 flash.alpha = self.beam_alpha;
1384 flash.colormod = self.beam_color;
1391 if(!self.beam_usevieworigin)
1393 InterpolateOrigin_Note();
1397 float W_Arc(float req)
1401 case WR_IMPACTEFFECT:
1408 //precache_sound("weapons/arc_impact.wav");
1409 //precache_sound("weapons/arc_impact_combo.wav");
1412 case WR_ZOOMRETICLE:
1414 // no weapon specific image for this weapon