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];
64 #define ARC_BT_BURST_MISS 10
65 #define ARC_BT_BURST_WALL 11
66 #define ARC_BT_BURST_HEAL 12
67 #define ARC_BT_BURST_HIT 13
68 #define ARC_BT_BURSTMASK 10
70 #define ARC_SF_SETTINGS 1
71 #define ARC_SF_START 2
72 #define ARC_SF_WANTDIR 4
73 #define ARC_SF_BEAMDIR 8
74 #define ARC_SF_BEAMTYPE 16
75 #define ARC_SF_LOCALMASK 14
78 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
80 .float BUTTON_ATCK_prev; // for better animation control
82 .float beam_initialized;
86 void Ent_ReadArcBeam(float isnew);
90 .float beam_thickness;
91 .float beam_traileffect;
92 .float beam_hiteffect;
93 .float beam_hitlight[4]; // 0: radius, 123: rgb
94 .float beam_muzzleeffect;
95 .float beam_muzzlelight[4]; // 0: radius, 123: rgb
98 .entity beam_muzzleentity;
100 .float beam_degreespersegment;
101 .float beam_distancepersegment;
102 .float beam_usevieworigin;
103 .float beam_initialized;
104 .float beam_maxangle;
106 .float beam_returnspeed;
107 .float beam_tightness;
108 .vector beam_shotorigin;
110 entity Draw_ArcBeam_callback_entity;
111 vector Draw_ArcBeam_callback_new_dir;
112 float Draw_ArcBeam_callback_segmentdist;
113 float Draw_ArcBeam_callback_last_thickness;
114 vector Draw_ArcBeam_callback_last_top;
115 vector Draw_ArcBeam_callback_last_bottom;
119 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
121 float W_Arc_Beam_Send(entity to, float sf)
123 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
125 // Truncate information when this beam is displayed to the owner client
126 // - The owner client has no use for beam start position or directions,
127 // it always figures this information out for itself with csqc code.
128 // - Spectating the owner also truncates this information.
129 float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
130 if(drawlocal) { sf &= ~ARC_SF_LOCALMASK; }
132 WriteByte(MSG_ENTITY, sf);
134 if(sf & ARC_SF_SETTINGS) // settings information
136 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_degreespersegment));
137 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_distancepersegment));
138 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
139 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
140 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
141 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
143 WriteByte(MSG_ENTITY, drawlocal);
145 if(sf & ARC_SF_START) // starting location
147 WriteCoord(MSG_ENTITY, self.beam_start_x);
148 WriteCoord(MSG_ENTITY, self.beam_start_y);
149 WriteCoord(MSG_ENTITY, self.beam_start_z);
151 if(sf & ARC_SF_WANTDIR) // want/aim direction
153 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
154 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
155 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
157 if(sf & ARC_SF_BEAMDIR) // beam direction
159 WriteCoord(MSG_ENTITY, self.beam_dir_x);
160 WriteCoord(MSG_ENTITY, self.beam_dir_y);
161 WriteCoord(MSG_ENTITY, self.beam_dir_z);
163 if(sf & ARC_SF_BEAMTYPE) // beam type
165 WriteByte(MSG_ENTITY, self.beam_type);
171 void W_Arc_Beam_Think(void)
173 if(self != self.owner.arc_beam)
180 (self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
182 self.owner.deadflag != DEAD_NO
184 (!self.owner.BUTTON_ATCK && !self.beam_bursting)
186 self.owner.freezetag_frozen
189 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
190 entity oldself = self;
192 if(!WEP_ACTION(WEP_ARC, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC, WR_CHECKAMMO2))
194 // note: this doesn't force the switch
195 W_SwitchToOtherWeapon(self);
203 if(self.owner.BUTTON_ATCK2 || self.beam_bursting)
205 if(!self.beam_bursting)
206 self.beam_bursting = TRUE;
207 burst = ARC_BT_BURSTMASK;
211 float coefficient = frametime;
212 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
216 { rootammo = WEP_CVAR(arc, burst_ammo); }
218 { rootammo = WEP_CVAR(arc, beam_ammo); }
222 coefficient = min(coefficient, self.owner.WEP_AMMO(ARC) / rootammo);
223 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - (rootammo * frametime));
227 makevectors(self.owner.v_angle);
235 WEP_CVAR(arc, beam_damage) * coefficient,
236 WEP_CVAR(arc, beam_range)
239 // network information: shot origin and want/aim direction
240 if(self.beam_start != w_shotorg)
242 self.SendFlags |= ARC_SF_START;
243 self.beam_start = w_shotorg;
245 if(self.beam_wantdir != w_shotdir)
247 self.SendFlags |= ARC_SF_WANTDIR;
248 self.beam_wantdir = w_shotdir;
251 if(!self.beam_initialized)
253 self.beam_dir = w_shotdir;
254 self.beam_initialized = TRUE;
257 // WEAPONTODO: Detect player velocity so that the beam curves when moving too
258 // idea: blend together self.beam_dir with the inverted direction the player is moving in
259 // might have to make some special accomodation so that it only uses view_right and view_up
261 // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
264 if(self.beam_dir != w_shotdir)
266 // calculate how much we're going to move the end of the beam to the want position
267 // WEAPONTODO (server and client):
268 // blendfactor never actually becomes 0 in this situation, which is a problem
269 // regarding precision... this means that self.beam_dir and w_shotdir approach
270 // eachother, however they never actually become the same value with this method.
271 // Perhaps we should do some form of rounding/snapping?
272 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
273 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
275 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
276 float blendfactor = bound(
278 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
279 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
281 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
285 // the radius is not too far yet, no worries :D
286 float blendfactor = bound(
288 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
291 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
294 // network information: beam direction
295 self.SendFlags |= ARC_SF_BEAMDIR;
297 // calculate how many segments are needed
298 float max_allowed_segments;
300 if(WEP_CVAR(arc, beam_distancepersegment))
302 max_allowed_segments = min(
304 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
307 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
309 if(WEP_CVAR(arc, beam_degreespersegment))
316 WEP_CVAR(arc, beam_maxangle)
319 WEP_CVAR(arc, beam_degreespersegment)
324 else { segments = 1; }
326 else { segments = 1; }
328 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
331 float new_beam_type = 0;
332 vector last_origin = w_shotorg;
333 for(i = 1; i <= segments; ++i)
335 // WEAPONTODO (server and client):
336 // Segment blend and distance should probably really be calculated in a better way,
337 // however I am not sure how to do it properly. There are a few things I have tried,
338 // but most of them do not work properly due to my lack of understanding regarding
339 // the mathematics behind them.
341 // Ideally, we should calculate the positions along a perfect curve
342 // between wantdir and self.beam_dir with an option for depth of arc
344 // Another issue is that (on the client code) we must separate the
345 // curve into multiple rendered curves when handling warpzones.
347 // I can handle this by detecting it for each segment, however that
348 // is a fairly inefficient method in comparison to having a curved line
349 // drawing function similar to Draw_CylindricLine that accepts
350 // top and bottom origins as input, this way there would be no
351 // overlapping edges when connecting the curved pieces.
353 // WEAPONTODO (client):
354 // In order to do nice fading and pointing on the starting segment, we must always
355 // have that drawn as a separate triangle... However, that is difficult to do when
356 // keeping in mind the above problems and also optimizing the amount of segments
357 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
359 // calculate this on every segment to ensure that we always reach the full length of the attack
360 float segmentblend = bound(0, (i/segments) + WEP_CVAR(arc, beam_tightness), 1);
361 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
363 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
364 // Figure out how this actually should work.
365 vector new_dir = normalize(
366 (w_shotdir * (1 - segmentblend))
368 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
370 vector new_origin = last_origin + (new_dir * segmentdist);
372 WarpZone_traceline_antilag(
378 ANTILAG_LATENCY(self.owner)
382 trace_ent.classname == "player"
384 trace_ent.classname == "body"
386 (trace_ent.flags & FL_MONSTER)
389 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
391 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
392 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
394 float falloff = ExponentialFalloff(
395 WEP_CVAR(arc, beam_falloff_mindist),
396 WEP_CVAR(arc, beam_falloff_maxdist),
397 WEP_CVAR(arc, beam_falloff_halflifedist),
398 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
401 if(is_player && SAME_TEAM(self.owner, trace_ent))
403 float roothealth, rootarmor;
406 roothealth = WEP_CVAR(arc, burst_healing_hps);
407 rootarmor = WEP_CVAR(arc, burst_healing_aps);
411 roothealth = WEP_CVAR(arc, beam_healing_hps);
412 rootarmor = WEP_CVAR(arc, beam_healing_aps);
415 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
417 trace_ent.health = min(
418 trace_ent.health + (roothealth * coefficient),
419 WEP_CVAR(arc, beam_healing_hmax)
422 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
424 trace_ent.armorvalue = min(
425 trace_ent.armorvalue + (rootarmor * coefficient),
426 WEP_CVAR(arc, beam_healing_amax)
430 // stop rot, set visual effect
431 if(roothealth || rootarmor)
433 trace_ent.pauserothealth_finished = max(
434 trace_ent.pauserothealth_finished,
435 time + autocvar_g_balance_pause_health_rot
437 trace_ent.pauserotarmor_finished = max(
438 trace_ent.pauserotarmor_finished,
439 time + autocvar_g_balance_pause_armor_rot
441 new_beam_type = ARC_BT_HEAL;
450 { rootdamage = WEP_CVAR(arc, burst_damage); }
452 { rootdamage = WEP_CVAR(arc, beam_damage); }
455 { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
457 if(accuracy_isgooddamage(self.owner, trace_ent))
463 rootdamage * coefficient * falloff
471 rootdamage * coefficient * falloff,
474 WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
477 new_beam_type = ARC_BT_HIT;
481 else if(trace_fraction != 1)
483 // we collided with geometry
484 new_beam_type = ARC_BT_WALL;
489 last_origin = new_origin;
493 // if we're bursting, use burst visual effects
494 new_beam_type += burst;
496 // network information: beam type
497 if(new_beam_type != self.beam_type)
499 self.SendFlags |= ARC_SF_BEAMTYPE;
500 self.beam_type = new_beam_type;
503 self.owner.beam_prev = time;
504 self.nextthink = time;
507 void W_Arc_Beam(float burst)
509 // only play fire sound if 1 sec has passed since player let go the fire button
510 if(time - self.beam_prev > 1)
512 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
515 entity beam = self.arc_beam = spawn();
516 beam.classname = "W_Arc_Beam";
517 beam.solid = SOLID_NOT;
518 beam.think = W_Arc_Beam_Think;
520 beam.movetype = MOVETYPE_NONE;
521 beam.bot_dodge = TRUE;
522 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
523 beam.beam_bursting = burst;
524 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
526 entity oldself = self;
532 float W_Arc(float req)
538 if(WEP_CVAR(arc, beam_botaimspeed))
540 self.BUTTON_ATCK = bot_aim(
541 WEP_CVAR(arc, beam_botaimspeed),
543 WEP_CVAR(arc, beam_botaimlifetime),
549 self.BUTTON_ATCK = bot_aim(
561 if(self.arc_beam.beam_heat > threshold)
563 stop the beam somehow
564 play overheat animation
568 if(self.BUTTON_ATCK || self.BUTTON_ATCK2 || self.arc_beam.beam_bursting)
570 if(self.BUTTON_ATCK_prev)
573 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
574 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
577 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
580 if((!self.arc_beam) || wasfreed(self.arc_beam))
582 if(weapon_prepareattack(!!self.BUTTON_ATCK2, 0))
584 W_Arc_Beam(!!self.BUTTON_ATCK2);
586 if(!self.BUTTON_ATCK_prev)
588 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
589 self.BUTTON_ATCK_prev = 1;
596 if(self.BUTTON_ATCK_prev != 0)
598 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
599 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
601 self.BUTTON_ATCK_prev = 0;
605 if(self.BUTTON_ATCK2)
606 if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
609 self.arc_count = autocvar_g_balance_arc_secondary_count;
610 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
611 self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
619 precache_model("models/weapons/g_arc.md3");
620 precache_model("models/weapons/v_arc.md3");
621 precache_model("models/weapons/h_arc.iqm");
622 precache_sound("weapons/lgbeam_fire.wav");
623 if(!arc_shotorigin[0])
625 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
626 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
627 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
628 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
630 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
635 return ((!WEP_CVAR(arc, beam_ammo)) || (self.WEP_AMMO(ARC) > 0));
639 return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
643 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
648 if(w_deathtype & HITTYPE_SECONDARY)
650 return WEAPON_ELECTRO_MURDER_ORBS;
654 if(w_deathtype & HITTYPE_BOUNCE)
655 return WEAPON_ELECTRO_MURDER_COMBO;
657 return WEAPON_ELECTRO_MURDER_BOLT;
665 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
667 entity beam = Draw_ArcBeam_callback_entity;
668 vector transformed_view_org;
669 transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
671 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
677 if(trace_fraction != 1)
679 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
680 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
681 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
691 // decide upon thickness
692 float thickness = beam.beam_thickness;
694 // draw primary beam render
695 vector top = hitorigin + (thickdir * thickness);
696 vector bottom = hitorigin - (thickdir * thickness);
697 //vector last_top = start + (thickdir * Draw_ArcBeam_callback_last_thickness);
698 //vector last_bottom = start - (thickdir * Draw_ArcBeam_callback_last_thickness);
700 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
703 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
708 Draw_ArcBeam_callback_last_top,
709 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
714 Draw_ArcBeam_callback_last_bottom,
715 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
721 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
727 // draw trailing particles
729 // - Don't use spammy particle counts here, use a FEW small particles around the beam
730 // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
731 if(beam.beam_traileffect)
733 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
736 // set up for the next
737 Draw_ArcBeam_callback_last_thickness = thickness;
738 Draw_ArcBeam_callback_last_top = top;
739 Draw_ArcBeam_callback_last_bottom = bottom;
742 void Draw_ArcBeam(void)
744 if(!self.beam_usevieworigin)
746 InterpolateOrigin_Do();
749 // origin = beam starting origin
750 // v_angle = wanted/aim direction
751 // angles = current direction of beam
754 vector wantdir; //= view_forward;
755 vector beamdir; //= self.beam_dir;
758 if(self.beam_usevieworigin)
761 // Currently we have to replicate nearly the same method of figuring
762 // out the shotdir that the server does... Ideally in the future we
763 // should be able to acquire this from a generalized function built
764 // into a weapon system for client code.
766 // find where we are aiming
767 makevectors(view_angles);
769 // decide upon start position
770 if(self.beam_usevieworigin == 2)
771 { start_pos = view_origin; }
773 { start_pos = self.origin; }
775 // trace forward with an estimation
778 start_pos + view_forward * self.beam_range,
783 // untransform in case our trace went through a warpzone
788 vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
793 // un-adjust trueaim if shotend is too close
794 if(vlen(end_pos - view_origin) < g_trueaim_minrange)
795 end_pos = view_origin + (view_forward * g_trueaim_minrange);
797 // move shot origin to the actual gun muzzle origin
798 vector origin_offset =
799 view_forward * self.beam_shotorigin_x
800 + view_right * -self.beam_shotorigin_y
801 + view_up * self.beam_shotorigin_z;
803 start_pos = start_pos + origin_offset;
805 // calculate the aim direction now
806 wantdir = normalize(end_pos - start_pos);
808 if(!self.beam_initialized)
810 self.beam_dir = wantdir;
811 self.beam_initialized = TRUE;
814 if(self.beam_dir != wantdir)
816 // calculate how much we're going to move the end of the beam to the want position
817 // WEAPONTODO (server and client):
818 // blendfactor never actually becomes 0 in this situation, which is a problem
819 // regarding precision... this means that self.beam_dir and w_shotdir approach
820 // eachother, however they never actually become the same value with this method.
821 // Perhaps we should do some form of rounding/snapping?
822 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
823 if(angle && (angle > self.beam_maxangle))
825 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
826 float blendfactor = bound(
828 (1 - (self.beam_returnspeed * frametime)),
829 min(self.beam_maxangle / angle, 1)
831 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
835 // the radius is not too far yet, no worries :D
836 float blendfactor = bound(
838 (1 - (self.beam_returnspeed * frametime)),
841 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
844 // calculate how many segments are needed
845 float max_allowed_segments;
847 if(self.beam_distancepersegment)
849 max_allowed_segments = min(
851 1 + (vlen(wantdir / self.beam_distancepersegment))
854 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
856 if(self.beam_degreespersegment)
866 self.beam_degreespersegment
871 else { segments = 1; }
873 else { segments = 1; }
875 // set the beam direction which the rest of the code will refer to
876 beamdir = self.beam_dir;
878 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
879 self.angles = fixedvectoangles2(view_forward, view_up);
883 // set the values from the provided info from the networked entity
884 start_pos = self.origin;
885 wantdir = self.v_angle;
886 beamdir = self.angles;
888 if(beamdir != wantdir)
890 float angle = vlen(wantdir - beamdir) * RAD2DEG;
892 // calculate how many segments are needed
893 float max_allowed_segments;
895 if(self.beam_distancepersegment)
897 max_allowed_segments = min(
899 1 + (vlen(wantdir / self.beam_distancepersegment))
902 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
904 if(self.beam_degreespersegment)
914 self.beam_degreespersegment
919 else { segments = 1; }
921 else { segments = 1; }
924 setorigin(self, start_pos);
925 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
927 vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
929 Draw_ArcBeam_callback_entity = self;
930 Draw_ArcBeam_callback_last_thickness = 0;
931 Draw_ArcBeam_callback_last_top = start_pos;
932 Draw_ArcBeam_callback_last_bottom = start_pos;
934 vector last_origin = start_pos;
937 for(i = 1; i <= segments; ++i)
939 // WEAPONTODO (server and client):
940 // Segment blend and distance should probably really be calculated in a better way,
941 // however I am not sure how to do it properly. There are a few things I have tried,
942 // but most of them do not work properly due to my lack of understanding regarding
943 // the mathematics behind them.
945 // Ideally, we should calculate the positions along a perfect curve
946 // between wantdir and self.beam_dir with an option for depth of arc
948 // Another issue is that (on the client code) we must separate the
949 // curve into multiple rendered curves when handling warpzones.
951 // I can handle this by detecting it for each segment, however that
952 // is a fairly inefficient method in comparison to having a curved line
953 // drawing function similar to Draw_CylindricLine that accepts
954 // top and bottom origins as input, this way there would be no
955 // overlapping edges when connecting the curved pieces.
957 // WEAPONTODO (client):
958 // In order to do nice fading and pointing on the starting segment, we must always
959 // have that drawn as a separate triangle... However, that is difficult to do when
960 // keeping in mind the above problems and also optimizing the amount of segments
961 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
963 // calculate this on every segment to ensure that we always reach the full length of the attack
964 float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
965 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
967 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
968 // Figure out how this actually should work.
969 vector new_dir = normalize(
970 (wantdir * (1 - segmentblend))
972 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
974 vector new_origin = last_origin + (new_dir * segmentdist);
976 Draw_ArcBeam_callback_segmentdist = segmentdist;
977 Draw_ArcBeam_callback_new_dir = new_dir;
979 WarpZone_TraceBox_ThroughZone(
987 Draw_ArcBeam_callback
990 //printf("segment: %d, warpzone transform: %d\n", i, (WarpZone_trace_transform != world));
993 // Figure out some way to detect a collision with geometry with callback...
994 // That way we can know when we are done drawing the beam and skip
995 // the rest of the segments without breaking warpzone support.
997 last_origin = WarpZone_TransformOrigin(WarpZone_trace_transform, new_origin);
998 beam_endpos_estimate = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos_estimate);
1001 // visual effects for startpoint and endpoint
1002 if(self.beam_hiteffect)
1005 self.beam_hiteffect,
1011 if(self.beam_hitlight[0])
1015 self.beam_hitlight[0],
1017 self.beam_hitlight[1],
1018 self.beam_hitlight[2],
1019 self.beam_hitlight[3]
1023 if(self.beam_muzzleeffect)
1026 self.beam_muzzleeffect,
1027 start_pos + wantdir * 20,
1032 if(self.beam_muzzlelight[0])
1035 start_pos + wantdir * 20,
1036 self.beam_muzzlelight[0],
1038 self.beam_muzzlelight[1],
1039 self.beam_muzzlelight[2],
1040 self.beam_muzzlelight[3]
1046 Draw_ArcBeam_callback_entity = world;
1047 Draw_ArcBeam_callback_new_dir = '0 0 0';
1048 Draw_ArcBeam_callback_segmentdist = 0;
1049 Draw_ArcBeam_callback_last_thickness = 0;
1050 Draw_ArcBeam_callback_last_top = '0 0 0';
1051 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1054 void Remove_ArcBeam(void)
1056 remove(self.beam_muzzleentity);
1057 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1060 void Ent_ReadArcBeam(float isnew)
1062 float sf = ReadByte();
1067 // calculate shot origin offset from gun alignment
1068 float gunalign = autocvar_cl_gunalign;
1069 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1070 gunalign = 3; // default value
1073 self.beam_shotorigin = arc_shotorigin[gunalign];
1075 // set other main attributes of the beam
1076 self.draw = Draw_ArcBeam;
1077 self.entremove = Remove_ArcBeam;
1078 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1082 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1083 flash.drawmask = MASK_NORMAL;
1084 flash.solid = SOLID_NOT;
1085 setattachment(flash, self, "");
1086 setorigin(flash, '0 0 0');
1088 self.beam_muzzleentity = flash;
1092 flash = self.beam_muzzleentity;
1095 if(sf & ARC_SF_SETTINGS) // settings information
1097 self.beam_degreespersegment = ReadShort();
1098 self.beam_distancepersegment = ReadShort();
1099 self.beam_maxangle = ReadShort();
1100 self.beam_range = ReadCoord();
1101 self.beam_returnspeed = ReadShort();
1102 self.beam_tightness = (ReadByte() / 10);
1106 if(autocvar_chase_active)
1107 { self.beam_usevieworigin = 1; }
1108 else // use view origin
1109 { self.beam_usevieworigin = 2; }
1113 self.beam_usevieworigin = 0;
1117 if(!self.beam_usevieworigin)
1119 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1120 self.iflags = IFLAG_ORIGIN;
1122 InterpolateOrigin_Undo();
1125 if(sf & ARC_SF_START) // starting location
1127 self.origin_x = ReadCoord();
1128 self.origin_y = ReadCoord();
1129 self.origin_z = ReadCoord();
1131 else if(self.beam_usevieworigin) // infer the location from player location
1133 if(self.beam_usevieworigin == 2)
1136 self.origin = view_origin;
1140 // use player origin so that third person display still works
1141 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1145 setorigin(self, self.origin);
1147 if(sf & ARC_SF_WANTDIR) // want/aim direction
1149 self.v_angle_x = ReadCoord();
1150 self.v_angle_y = ReadCoord();
1151 self.v_angle_z = ReadCoord();
1154 if(sf & ARC_SF_BEAMDIR) // beam direction
1156 self.angles_x = ReadCoord();
1157 self.angles_y = ReadCoord();
1158 self.angles_z = ReadCoord();
1161 if(sf & ARC_SF_BEAMTYPE) // beam type
1163 self.beam_type = ReadByte();
1164 switch(self.beam_type)
1168 self.beam_color = '-1 -1 1';
1169 self.beam_alpha = 0.5;
1170 self.beam_thickness = 8;
1171 self.beam_traileffect = FALSE;
1172 self.beam_hiteffect = particleeffectnum("electro_lightning");
1173 self.beam_hitlight[0] = 0;
1174 self.beam_hitlight[1] = 1;
1175 self.beam_hitlight[2] = 1;
1176 self.beam_hitlight[3] = 1;
1177 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1178 self.beam_muzzlelight[0] = 0;
1179 self.beam_muzzlelight[1] = 1;
1180 self.beam_muzzlelight[2] = 1;
1181 self.beam_muzzlelight[3] = 1;
1182 self.beam_image = "particles/lgbeam";
1183 setmodel(flash, "models/flash.md3");
1184 flash.alpha = self.beam_alpha;
1185 flash.colormod = self.beam_color;
1189 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1191 self.beam_color = '0.5 0.5 1';
1192 self.beam_alpha = 0.5;
1193 self.beam_thickness = 8;
1194 self.beam_traileffect = FALSE;
1195 self.beam_hiteffect = particleeffectnum("electro_lightning");
1196 self.beam_hitlight[0] = 0;
1197 self.beam_hitlight[1] = 1;
1198 self.beam_hitlight[2] = 1;
1199 self.beam_hitlight[3] = 1;
1200 self.beam_muzzleeffect = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
1201 self.beam_muzzlelight[0] = 0;
1202 self.beam_muzzlelight[1] = 1;
1203 self.beam_muzzlelight[2] = 1;
1204 self.beam_muzzlelight[3] = 1;
1205 self.beam_image = "particles/lgbeam";
1206 setmodel(flash, "models/flash.md3");
1207 flash.alpha = self.beam_alpha;
1208 flash.colormod = self.beam_color;
1214 self.beam_color = '0 1 0';
1215 self.beam_alpha = 0.5;
1216 self.beam_thickness = 8;
1217 self.beam_traileffect = FALSE;
1218 self.beam_hiteffect = particleeffectnum("healray_impact");
1219 self.beam_hitlight[0] = 0;
1220 self.beam_hitlight[1] = 1;
1221 self.beam_hitlight[2] = 1;
1222 self.beam_hitlight[3] = 1;
1223 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1224 self.beam_muzzlelight[0] = 0;
1225 self.beam_muzzlelight[1] = 1;
1226 self.beam_muzzlelight[2] = 1;
1227 self.beam_muzzlelight[3] = 1;
1228 self.beam_image = "particles/lgbeam";
1229 setmodel(flash, "models/flash.md3");
1230 flash.alpha = self.beam_alpha;
1231 flash.colormod = self.beam_color;
1237 self.beam_color = '1 0 1';
1238 self.beam_alpha = 0.5;
1239 self.beam_thickness = 8;
1240 self.beam_traileffect = particleeffectnum("nex_beam");
1241 self.beam_hiteffect = particleeffectnum("electro_lightning");
1242 self.beam_hitlight[0] = 20;
1243 self.beam_hitlight[1] = 1;
1244 self.beam_hitlight[2] = 0;
1245 self.beam_hitlight[3] = 0;
1246 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1247 self.beam_muzzlelight[0] = 50;
1248 self.beam_muzzlelight[1] = 1;
1249 self.beam_muzzlelight[2] = 0;
1250 self.beam_muzzlelight[3] = 0;
1251 self.beam_image = "particles/lgbeam";
1252 setmodel(flash, "models/flash.md3");
1253 flash.alpha = self.beam_alpha;
1254 flash.colormod = self.beam_color;
1258 case ARC_BT_BURST_MISS:
1260 self.beam_color = '-1 -1 1';
1261 self.beam_alpha = 0.5;
1262 self.beam_thickness = 14;
1263 self.beam_traileffect = FALSE;
1264 self.beam_hiteffect = particleeffectnum("electro_lightning");
1265 self.beam_hitlight[0] = 0;
1266 self.beam_hitlight[1] = 1;
1267 self.beam_hitlight[2] = 1;
1268 self.beam_hitlight[3] = 1;
1269 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1270 self.beam_muzzlelight[0] = 0;
1271 self.beam_muzzlelight[1] = 1;
1272 self.beam_muzzlelight[2] = 1;
1273 self.beam_muzzlelight[3] = 1;
1274 self.beam_image = "particles/lgbeam";
1275 setmodel(flash, "models/flash.md3");
1276 flash.alpha = self.beam_alpha;
1277 flash.colormod = self.beam_color;
1281 case ARC_BT_BURST_WALL:
1283 self.beam_color = '0.5 0.5 1';
1284 self.beam_alpha = 0.5;
1285 self.beam_thickness = 14;
1286 self.beam_traileffect = FALSE;
1287 self.beam_hiteffect = particleeffectnum("electro_lightning");
1288 self.beam_hitlight[0] = 0;
1289 self.beam_hitlight[1] = 1;
1290 self.beam_hitlight[2] = 1;
1291 self.beam_hitlight[3] = 1;
1292 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1293 self.beam_muzzlelight[0] = 0;
1294 self.beam_muzzlelight[1] = 1;
1295 self.beam_muzzlelight[2] = 1;
1296 self.beam_muzzlelight[3] = 1;
1297 self.beam_image = "particles/lgbeam";
1298 setmodel(flash, "models/flash.md3");
1299 flash.alpha = self.beam_alpha;
1300 flash.colormod = self.beam_color;
1304 case ARC_BT_BURST_HEAL:
1306 self.beam_color = '0 1 0';
1307 self.beam_alpha = 0.5;
1308 self.beam_thickness = 14;
1309 self.beam_traileffect = FALSE;
1310 self.beam_hiteffect = particleeffectnum("electro_lightning");
1311 self.beam_hitlight[0] = 0;
1312 self.beam_hitlight[1] = 1;
1313 self.beam_hitlight[2] = 1;
1314 self.beam_hitlight[3] = 1;
1315 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1316 self.beam_muzzlelight[0] = 0;
1317 self.beam_muzzlelight[1] = 1;
1318 self.beam_muzzlelight[2] = 1;
1319 self.beam_muzzlelight[3] = 1;
1320 self.beam_image = "particles/lgbeam";
1321 setmodel(flash, "models/flash.md3");
1322 flash.alpha = self.beam_alpha;
1323 flash.colormod = self.beam_color;
1327 case ARC_BT_BURST_HIT:
1329 self.beam_color = '1 0 1';
1330 self.beam_alpha = 0.5;
1331 self.beam_thickness = 14;
1332 self.beam_traileffect = FALSE;
1333 self.beam_hiteffect = particleeffectnum("electro_lightning");
1334 self.beam_hitlight[0] = 0;
1335 self.beam_hitlight[1] = 1;
1336 self.beam_hitlight[2] = 1;
1337 self.beam_hitlight[3] = 1;
1338 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1339 self.beam_muzzlelight[0] = 0;
1340 self.beam_muzzlelight[1] = 1;
1341 self.beam_muzzlelight[2] = 1;
1342 self.beam_muzzlelight[3] = 1;
1343 self.beam_image = "particles/lgbeam";
1344 setmodel(flash, "models/flash.md3");
1345 flash.alpha = self.beam_alpha;
1346 flash.colormod = self.beam_color;
1351 // shouldn't be possible, but lets make it colorful if it does :D
1354 self.beam_color = randomvec();
1355 self.beam_alpha = 1;
1356 self.beam_thickness = 8;
1357 self.beam_traileffect = FALSE;
1358 self.beam_hiteffect = FALSE;
1359 self.beam_hitlight[0] = 0;
1360 self.beam_hitlight[1] = 1;
1361 self.beam_hitlight[2] = 1;
1362 self.beam_hitlight[3] = 1;
1363 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1364 self.beam_muzzlelight[0] = 0;
1365 self.beam_muzzlelight[1] = 1;
1366 self.beam_muzzlelight[2] = 1;
1367 self.beam_muzzlelight[3] = 1;
1368 self.beam_image = "particles/lgbeam";
1369 setmodel(flash, "models/flash.md3");
1370 flash.alpha = self.beam_alpha;
1371 flash.colormod = self.beam_color;
1378 if(!self.beam_usevieworigin)
1380 InterpolateOrigin_Note();
1384 float W_Arc(float req)
1388 case WR_IMPACTEFFECT:
1395 precache_sound("weapons/lgbeam_fly.wav");
1398 case WR_ZOOMRETICLE:
1400 // no weapon specific image for this weapon