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 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
92 float W_Arc_Beam_Send(entity to, float sf)
94 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
96 // Truncate information when this beam is displayed to the owner client
97 // - The owner client has no use for beam start position or directions,
98 // it always figures this information out for itself with csqc code.
99 // - Spectating the owner also truncates this information.
100 float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
103 sf &= ~ARC_SF_LOCALMASK;
106 WriteByte(MSG_ENTITY, sf);
108 if(sf & ARC_SF_SETTINGS) // settings information
110 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_degreespersegment));
111 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_distancepersegment));
112 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
113 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
114 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
115 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
117 WriteByte(MSG_ENTITY, drawlocal);
119 if(sf & ARC_SF_START) // starting location
121 WriteCoord(MSG_ENTITY, self.beam_start_x);
122 WriteCoord(MSG_ENTITY, self.beam_start_y);
123 WriteCoord(MSG_ENTITY, self.beam_start_z);
125 if(sf & ARC_SF_WANTDIR) // want/aim direction
127 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
128 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
129 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
131 if(sf & ARC_SF_BEAMDIR) // beam direction
133 WriteCoord(MSG_ENTITY, self.beam_dir_x);
134 WriteCoord(MSG_ENTITY, self.beam_dir_y);
135 WriteCoord(MSG_ENTITY, self.beam_dir_z);
137 if(sf & ARC_SF_BEAMTYPE) // beam type
139 WriteByte(MSG_ENTITY, self.beam_type);
145 void W_Arc_Beam_Think(void)
147 if(self != self.owner.arc_beam)
154 (self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
156 self.owner.deadflag != DEAD_NO
158 (!self.owner.BUTTON_ATCK && !self.beam_bursting)
160 self.owner.freezetag_frozen
164 // is this needed? I thought this is changed to world when removed ANYWAY
165 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
167 entity oldself = self;
169 if(!WEP_ACTION(WEP_ARC, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC, WR_CHECKAMMO2))
171 // note: this doesn't force the switch
172 W_SwitchToOtherWeapon(self);
180 if(self.owner.BUTTON_ATCK2 || self.beam_bursting)
182 if(!self.beam_bursting)
183 self.beam_bursting = TRUE;
184 burst = ARC_BT_BURSTMASK;
188 float coefficient = frametime;
189 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
193 { rootammo = WEP_CVAR(arc, burst_ammo); }
195 { rootammo = WEP_CVAR(arc, beam_ammo); }
199 coefficient = min(coefficient, self.owner.WEP_AMMO(ARC) / rootammo);
200 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - (rootammo * frametime));
204 makevectors(self.owner.v_angle);
212 WEP_CVAR(arc, beam_damage) * coefficient,
213 WEP_CVAR(arc, beam_range)
216 // network information: shot origin and want/aim direction
217 if(self.beam_start != w_shotorg)
219 self.SendFlags |= ARC_SF_START;
220 self.beam_start = w_shotorg;
222 if(self.beam_wantdir != w_shotdir)
224 self.SendFlags |= ARC_SF_WANTDIR;
225 self.beam_wantdir = w_shotdir;
228 if(!self.beam_initialized)
230 self.beam_dir = w_shotdir;
231 self.beam_initialized = TRUE;
234 // WEAPONTODO: Detect player velocity so that the beam curves when moving too
235 // idea: blend together self.beam_dir with the inverted direction the player is moving in
236 // might have to make some special accomodation so that it only uses view_right and view_up
238 // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
241 if(self.beam_dir != w_shotdir)
243 // calculate how much we're going to move the end of the beam to the want position
244 // WEAPONTODO (server and client):
245 // blendfactor never actually becomes 0 in this situation, which is a problem
246 // regarding precision... this means that self.beam_dir and w_shotdir approach
247 // eachother, however they never actually become the same value with this method.
248 // Perhaps we should do some form of rounding/snapping?
249 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
250 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
252 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
253 float blendfactor = bound(
255 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
256 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
258 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
262 // the radius is not too far yet, no worries :D
263 float blendfactor = bound(
265 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
268 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
271 // network information: beam direction
272 self.SendFlags |= ARC_SF_BEAMDIR;
274 // calculate how many segments are needed
275 float max_allowed_segments;
277 if(WEP_CVAR(arc, beam_distancepersegment))
279 max_allowed_segments = min(
281 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
284 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
286 if(WEP_CVAR(arc, beam_degreespersegment))
293 WEP_CVAR(arc, beam_maxangle)
296 WEP_CVAR(arc, beam_degreespersegment)
301 else { segments = 1; }
303 else { segments = 1; }
305 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
308 float new_beam_type = 0;
309 vector last_origin = w_shotorg;
310 for(i = 1; i <= segments; ++i)
312 // WEAPONTODO (server and client):
313 // Segment blend and distance should probably really be calculated in a better way,
314 // however I am not sure how to do it properly. There are a few things I have tried,
315 // but most of them do not work properly due to my lack of understanding regarding
316 // the mathematics behind them.
318 // Ideally, we should calculate the positions along a perfect curve
319 // between wantdir and self.beam_dir with an option for depth of arc
321 // Another issue is that (on the client code) we must separate the
322 // curve into multiple rendered curves when handling warpzones.
324 // I can handle this by detecting it for each segment, however that
325 // is a fairly inefficient method in comparison to having a curved line
326 // drawing function similar to Draw_CylindricLine that accepts
327 // top and bottom origins as input, this way there would be no
328 // overlapping edges when connecting the curved pieces.
330 // WEAPONTODO (client):
331 // In order to do nice fading and pointing on the starting segment, we must always
332 // have that drawn as a separate triangle... However, that is difficult to do when
333 // keeping in mind the above problems and also optimizing the amount of segments
334 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
336 // calculate this on every segment to ensure that we always reach the full length of the attack
337 float segmentblend = bound(0, (i/segments) + WEP_CVAR(arc, beam_tightness), 1);
338 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
340 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
341 // Figure out how this actually should work.
342 vector new_dir = normalize(
343 (w_shotdir * (1 - segmentblend))
345 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
347 vector new_origin = last_origin + (new_dir * segmentdist);
349 WarpZone_traceline_antilag(
355 ANTILAG_LATENCY(self.owner)
359 trace_ent.classname == "player"
361 trace_ent.classname == "body"
363 (trace_ent.flags & FL_MONSTER)
366 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
368 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
369 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
371 float falloff = ExponentialFalloff(
372 WEP_CVAR(arc, beam_falloff_mindist),
373 WEP_CVAR(arc, beam_falloff_maxdist),
374 WEP_CVAR(arc, beam_falloff_halflifedist),
375 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
378 if(is_player && SAME_TEAM(self.owner, trace_ent))
380 float roothealth, rootarmor;
383 roothealth = WEP_CVAR(arc, burst_healing_hps);
384 rootarmor = WEP_CVAR(arc, burst_healing_aps);
388 roothealth = WEP_CVAR(arc, beam_healing_hps);
389 rootarmor = WEP_CVAR(arc, beam_healing_aps);
392 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
394 trace_ent.health = min(
395 trace_ent.health + (roothealth * coefficient),
396 WEP_CVAR(arc, beam_healing_hmax)
399 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
401 trace_ent.armorvalue = min(
402 trace_ent.armorvalue + (rootarmor * coefficient),
403 WEP_CVAR(arc, beam_healing_amax)
407 // stop rot, set visual effect
408 if(roothealth || rootarmor)
410 trace_ent.pauserothealth_finished = max(
411 trace_ent.pauserothealth_finished,
412 time + autocvar_g_balance_pause_health_rot
414 trace_ent.pauserotarmor_finished = max(
415 trace_ent.pauserotarmor_finished,
416 time + autocvar_g_balance_pause_armor_rot
418 new_beam_type = ARC_BT_HEAL;
427 { rootdamage = WEP_CVAR(arc, burst_damage); }
429 { rootdamage = WEP_CVAR(arc, beam_damage); }
432 { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
434 if(accuracy_isgooddamage(self.owner, trace_ent))
440 rootdamage * coefficient * falloff
448 rootdamage * coefficient * falloff,
451 WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
454 new_beam_type = ARC_BT_HIT;
458 else if(trace_fraction != 1)
460 // we collided with geometry
461 new_beam_type = ARC_BT_WALL;
466 last_origin = new_origin;
470 // if we're bursting, use burst visual effects
471 new_beam_type += burst;
473 // network information: beam type
474 if(new_beam_type != self.beam_type)
476 self.SendFlags |= ARC_SF_BEAMTYPE;
477 self.beam_type = new_beam_type;
480 self.owner.beam_prev = time;
481 self.nextthink = time;
484 void W_Arc_Beam(float burst)
486 // only play fire sound if 1 sec has passed since player let go the fire button
487 if(time - self.beam_prev > 1)
489 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
492 entity beam = self.arc_beam = spawn();
493 beam.classname = "W_Arc_Beam";
494 beam.solid = SOLID_NOT;
495 beam.think = W_Arc_Beam_Think;
497 beam.movetype = MOVETYPE_NONE;
498 beam.bot_dodge = TRUE;
499 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
500 beam.beam_bursting = burst;
501 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
503 entity oldself = self;
509 float W_Arc(float req)
515 if(WEP_CVAR(arc, beam_botaimspeed))
517 self.BUTTON_ATCK = bot_aim(
518 WEP_CVAR(arc, beam_botaimspeed),
520 WEP_CVAR(arc, beam_botaimlifetime),
526 self.BUTTON_ATCK = bot_aim(
538 if(self.arc_beam.beam_heat > threshold)
540 stop the beam somehow
541 play overheat animation
545 if(self.BUTTON_ATCK || self.BUTTON_ATCK2 || self.arc_beam.beam_bursting)
547 if(self.BUTTON_ATCK_prev)
550 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
551 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
554 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
557 if((!self.arc_beam) || wasfreed(self.arc_beam))
559 if(weapon_prepareattack(!!self.BUTTON_ATCK2, 0))
561 W_Arc_Beam(!!self.BUTTON_ATCK2);
563 if(!self.BUTTON_ATCK_prev)
565 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
566 self.BUTTON_ATCK_prev = 1;
573 if(self.BUTTON_ATCK_prev != 0)
575 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
576 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
578 self.BUTTON_ATCK_prev = 0;
582 if(self.BUTTON_ATCK2)
583 if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
586 self.arc_count = autocvar_g_balance_arc_secondary_count;
587 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
588 self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
596 precache_model("models/weapons/g_arc.md3");
597 precache_model("models/weapons/v_arc.md3");
598 precache_model("models/weapons/h_arc.iqm");
599 //precache_sound("weapons/arc_fire.wav");
600 //precache_sound("weapons/arc_fire2.wav");
601 //precache_sound("weapons/arc_impact.wav");
602 if(!arc_shotorigin[0])
604 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
605 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
606 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
607 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
609 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
614 return ((!WEP_CVAR(arc, beam_ammo)) || (self.WEP_AMMO(ARC) > 0));
618 return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
622 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
627 if(w_deathtype & HITTYPE_SECONDARY)
629 return WEAPON_ELECTRO_MURDER_ORBS;
633 if(w_deathtype & HITTYPE_BOUNCE)
634 return WEAPON_ELECTRO_MURDER_COMBO;
636 return WEAPON_ELECTRO_MURDER_BOLT;
647 .float beam_thickness;
648 .float beam_traileffect;
649 .float beam_hiteffect;
650 .float beam_hitlight[4]; // 0: radius, 123: rgb
651 .float beam_muzzleeffect;
652 .float beam_muzzlelight[4]; // 0: radius, 123: rgb
655 .entity beam_muzzleentity;
657 .float beam_degreespersegment;
658 .float beam_distancepersegment;
659 .float beam_usevieworigin;
660 .float beam_initialized;
661 .float beam_maxangle;
663 .float beam_returnspeed;
664 .float beam_tightness;
665 .vector beam_shotorigin;
668 entity Draw_ArcBeam_callback_entity;
669 vector Draw_ArcBeam_callback_new_dir;
670 float Draw_ArcBeam_callback_segmentdist;
671 float Draw_ArcBeam_callback_last_thickness;
672 vector Draw_ArcBeam_callback_last_top;
673 vector Draw_ArcBeam_callback_last_bottom;
675 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
677 entity beam = Draw_ArcBeam_callback_entity;
678 vector transformed_view_org;
679 transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
681 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
687 if(trace_fraction != 1)
689 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
690 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
691 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
701 // decide upon thickness
702 float thickness = beam.beam_thickness;
704 // draw primary beam render
705 vector top = hitorigin + (thickdir * thickness);
706 vector bottom = hitorigin - (thickdir * thickness);
707 //vector last_top = start + (thickdir * Draw_ArcBeam_callback_last_thickness);
708 //vector last_bottom = start - (thickdir * Draw_ArcBeam_callback_last_thickness);
710 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
713 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
718 Draw_ArcBeam_callback_last_top,
719 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
724 Draw_ArcBeam_callback_last_bottom,
725 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
731 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
737 // draw trailing particles
739 // - Don't use spammy particle counts here, use a FEW small particles around the beam
740 // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
741 if(beam.beam_traileffect)
743 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
746 // set up for the next
747 Draw_ArcBeam_callback_last_thickness = thickness;
748 Draw_ArcBeam_callback_last_top = top;
749 Draw_ArcBeam_callback_last_bottom = bottom;
752 void Draw_ArcBeam(void)
754 if(!self.beam_usevieworigin)
756 InterpolateOrigin_Do();
759 // origin = beam starting origin
760 // v_angle = wanted/aim direction
761 // angles = current direction of beam
764 vector wantdir; //= view_forward;
765 vector beamdir; //= self.beam_dir;
768 if(self.beam_usevieworigin)
771 // Currently we have to replicate nearly the same method of figuring
772 // out the shotdir that the server does... Ideally in the future we
773 // should be able to acquire this from a generalized function built
774 // into a weapon system for client code.
776 // find where we are aiming
777 makevectors(view_angles);
779 // decide upon start position
780 if(self.beam_usevieworigin == 2)
781 { start_pos = view_origin; }
783 { start_pos = self.origin; }
785 // trace forward with an estimation
788 start_pos + view_forward * self.beam_range,
793 // untransform in case our trace went through a warpzone
798 vector shothitpos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); // warpzone support
803 // un-adjust trueaim if shotend is too close
804 if(vlen(shothitpos - view_origin) < g_trueaim_minrange)
805 shothitpos = view_origin + (view_forward * g_trueaim_minrange);
807 // move shot origin to the actual gun muzzle origin
808 vector origin_offset =
809 view_forward * self.beam_shotorigin_x
810 + view_right * -self.beam_shotorigin_y
811 + view_up * self.beam_shotorigin_z;
813 start_pos = start_pos + origin_offset;
815 // calculate the aim direction now
816 wantdir = normalize(shothitpos - start_pos);
818 if(!self.beam_initialized)
820 self.beam_dir = wantdir;
821 self.beam_initialized = TRUE;
824 if(self.beam_dir != wantdir)
826 // calculate how much we're going to move the end of the beam to the want position
827 // WEAPONTODO (server and client):
828 // blendfactor never actually becomes 0 in this situation, which is a problem
829 // regarding precision... this means that self.beam_dir and w_shotdir approach
830 // eachother, however they never actually become the same value with this method.
831 // Perhaps we should do some form of rounding/snapping?
832 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
833 if(angle && (angle > self.beam_maxangle))
835 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
836 float blendfactor = bound(
838 (1 - (self.beam_returnspeed * frametime)),
839 min(self.beam_maxangle / angle, 1)
841 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
845 // the radius is not too far yet, no worries :D
846 float blendfactor = bound(
848 (1 - (self.beam_returnspeed * frametime)),
851 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
854 // calculate how many segments are needed
855 float max_allowed_segments;
857 if(self.beam_distancepersegment)
859 max_allowed_segments = min(
861 1 + (vlen(wantdir / self.beam_distancepersegment))
864 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
866 if(self.beam_degreespersegment)
876 self.beam_degreespersegment
881 else { segments = 1; }
883 else { segments = 1; }
885 // set the beam direction which the rest of the code will refer to
886 beamdir = self.beam_dir;
888 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
889 self.angles = fixedvectoangles2(view_forward, view_up);
893 // set the values from the provided info from the networked entity
894 start_pos = self.origin;
895 wantdir = self.v_angle;
896 beamdir = self.angles;
898 if(beamdir != wantdir)
900 float angle = vlen(wantdir - beamdir) * RAD2DEG;
902 // calculate how many segments are needed
903 float max_allowed_segments;
905 if(self.beam_distancepersegment)
907 max_allowed_segments = min(
909 1 + (vlen(wantdir / self.beam_distancepersegment))
912 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
914 if(self.beam_degreespersegment)
924 self.beam_degreespersegment
929 else { segments = 1; }
931 else { segments = 1; }
934 setorigin(self, start_pos);
935 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
937 vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
939 Draw_ArcBeam_callback_entity = self;
940 Draw_ArcBeam_callback_last_thickness = 0;
941 Draw_ArcBeam_callback_last_top = start_pos;
942 Draw_ArcBeam_callback_last_bottom = start_pos;
944 vector last_origin = start_pos;
947 for(i = 1; i <= segments; ++i)
949 // WEAPONTODO (server and client):
950 // Segment blend and distance should probably really be calculated in a better way,
951 // however I am not sure how to do it properly. There are a few things I have tried,
952 // but most of them do not work properly due to my lack of understanding regarding
953 // the mathematics behind them.
955 // Ideally, we should calculate the positions along a perfect curve
956 // between wantdir and self.beam_dir with an option for depth of arc
958 // Another issue is that (on the client code) we must separate the
959 // curve into multiple rendered curves when handling warpzones.
961 // I can handle this by detecting it for each segment, however that
962 // is a fairly inefficient method in comparison to having a curved line
963 // drawing function similar to Draw_CylindricLine that accepts
964 // top and bottom origins as input, this way there would be no
965 // overlapping edges when connecting the curved pieces.
967 // WEAPONTODO (client):
968 // In order to do nice fading and pointing on the starting segment, we must always
969 // have that drawn as a separate triangle... However, that is difficult to do when
970 // keeping in mind the above problems and also optimizing the amount of segments
971 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
973 // calculate this on every segment to ensure that we always reach the full length of the attack
974 float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
975 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
977 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
978 // Figure out how this actually should work.
979 vector new_dir = normalize(
980 (wantdir * (1 - segmentblend))
982 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
984 vector new_origin = last_origin + (new_dir * segmentdist);
986 Draw_ArcBeam_callback_segmentdist = segmentdist;
987 Draw_ArcBeam_callback_new_dir = new_dir;
989 WarpZone_TraceBox_ThroughZone(
997 Draw_ArcBeam_callback
1000 //printf("segment: %d, warpzone transform: %d\n", i, (WarpZone_trace_transform != world));
1003 // Figure out some way to detect a collision with geometry with callback...
1004 // That way we can know when we are done drawing the beam and skip
1005 // the rest of the segments without breaking warpzone support.
1007 last_origin = WarpZone_TransformOrigin(WarpZone_trace_transform, new_origin);
1008 beam_endpos_estimate = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos_estimate);
1011 // startpoint and endpoint drawn visual effects
1012 if(self.beam_hiteffect)
1015 self.beam_hiteffect,
1021 if(self.beam_hitlight[0])
1025 self.beam_hitlight[0],
1027 self.beam_hitlight[1],
1028 self.beam_hitlight[2],
1029 self.beam_hitlight[3]
1033 if(self.beam_muzzleeffect)
1036 self.beam_muzzleeffect,
1037 start_pos + wantdir * 20,
1042 if(self.beam_muzzlelight[0])
1045 start_pos + wantdir * 20,
1046 self.beam_muzzlelight[0],
1048 self.beam_muzzlelight[1],
1049 self.beam_muzzlelight[2],
1050 self.beam_muzzlelight[3]
1056 Draw_ArcBeam_callback_entity = world;
1057 Draw_ArcBeam_callback_new_dir = '0 0 0';
1058 Draw_ArcBeam_callback_segmentdist = 0;
1059 Draw_ArcBeam_callback_last_thickness = 0;
1060 Draw_ArcBeam_callback_last_top = '0 0 0';
1061 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1064 void Remove_ArcBeam(void)
1066 remove(self.beam_muzzleentity);
1067 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1070 void Ent_ReadArcBeam(float isnew)
1072 float sf = ReadByte();
1077 // calculate shot origin offset from gun alignment
1078 float gunalign = autocvar_cl_gunalign;
1079 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1080 gunalign = 3; // default value
1083 self.beam_shotorigin = arc_shotorigin[gunalign];
1085 // set other main attributes of the beam
1086 self.draw = Draw_ArcBeam;
1087 self.entremove = Remove_ArcBeam;
1088 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1092 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1093 flash.drawmask = MASK_NORMAL;
1094 flash.solid = SOLID_NOT;
1095 setattachment(flash, self, "");
1096 setorigin(flash, '0 0 0');
1098 self.beam_muzzleentity = flash;
1102 flash = self.beam_muzzleentity;
1105 if(sf & ARC_SF_SETTINGS) // settings information
1107 self.beam_degreespersegment = ReadShort();
1108 self.beam_distancepersegment = ReadShort();
1109 self.beam_maxangle = ReadShort();
1110 self.beam_range = ReadCoord();
1111 self.beam_returnspeed = ReadShort();
1112 self.beam_tightness = (ReadByte() / 10);
1116 if(autocvar_chase_active)
1117 { self.beam_usevieworigin = 1; }
1118 else // use view origin
1119 { self.beam_usevieworigin = 2; }
1123 self.beam_usevieworigin = 0;
1127 if(!self.beam_usevieworigin)
1129 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1130 self.iflags = IFLAG_ORIGIN;
1132 InterpolateOrigin_Undo();
1135 if(sf & ARC_SF_START) // starting location
1137 self.origin_x = ReadCoord();
1138 self.origin_y = ReadCoord();
1139 self.origin_z = ReadCoord();
1141 else if(self.beam_usevieworigin) // infer the location from player location
1143 if(self.beam_usevieworigin == 2)
1146 self.origin = view_origin;
1150 // use player origin so that third person display still works
1151 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1155 setorigin(self, self.origin);
1157 if(sf & ARC_SF_WANTDIR) // want/aim direction
1159 self.v_angle_x = ReadCoord();
1160 self.v_angle_y = ReadCoord();
1161 self.v_angle_z = ReadCoord();
1164 if(sf & ARC_SF_BEAMDIR) // beam direction
1166 self.angles_x = ReadCoord();
1167 self.angles_y = ReadCoord();
1168 self.angles_z = ReadCoord();
1171 if(sf & ARC_SF_BEAMTYPE) // beam type
1173 self.beam_type = ReadByte();
1174 switch(self.beam_type)
1178 self.beam_color = '-1 -1 1';
1179 self.beam_alpha = 0.5;
1180 self.beam_thickness = 8;
1181 self.beam_traileffect = FALSE;
1182 self.beam_hiteffect = particleeffectnum("electro_lightning");
1183 self.beam_hitlight[0] = 0;
1184 self.beam_hitlight[1] = 1;
1185 self.beam_hitlight[2] = 1;
1186 self.beam_hitlight[3] = 1;
1187 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1188 self.beam_muzzlelight[0] = 0;
1189 self.beam_muzzlelight[1] = 1;
1190 self.beam_muzzlelight[2] = 1;
1191 self.beam_muzzlelight[3] = 1;
1192 self.beam_image = "particles/lgbeam";
1193 setmodel(flash, "models/flash.md3");
1194 flash.alpha = self.beam_alpha;
1195 flash.colormod = self.beam_color;
1199 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1201 self.beam_color = '0.5 0.5 1';
1202 self.beam_alpha = 0.5;
1203 self.beam_thickness = 8;
1204 self.beam_traileffect = FALSE;
1205 self.beam_hiteffect = particleeffectnum("electro_lightning");
1206 self.beam_hitlight[0] = 0;
1207 self.beam_hitlight[1] = 1;
1208 self.beam_hitlight[2] = 1;
1209 self.beam_hitlight[3] = 1;
1210 self.beam_muzzleeffect = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
1211 self.beam_muzzlelight[0] = 0;
1212 self.beam_muzzlelight[1] = 1;
1213 self.beam_muzzlelight[2] = 1;
1214 self.beam_muzzlelight[3] = 1;
1215 self.beam_image = "particles/lgbeam";
1216 setmodel(flash, "models/flash.md3");
1217 flash.alpha = self.beam_alpha;
1218 flash.colormod = self.beam_color;
1224 self.beam_color = '0 1 0';
1225 self.beam_alpha = 0.5;
1226 self.beam_thickness = 8;
1227 self.beam_traileffect = FALSE;
1228 self.beam_hiteffect = particleeffectnum("healray_impact");
1229 self.beam_hitlight[0] = 0;
1230 self.beam_hitlight[1] = 1;
1231 self.beam_hitlight[2] = 1;
1232 self.beam_hitlight[3] = 1;
1233 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1234 self.beam_muzzlelight[0] = 0;
1235 self.beam_muzzlelight[1] = 1;
1236 self.beam_muzzlelight[2] = 1;
1237 self.beam_muzzlelight[3] = 1;
1238 self.beam_image = "particles/lgbeam";
1239 setmodel(flash, "models/flash.md3");
1240 flash.alpha = self.beam_alpha;
1241 flash.colormod = self.beam_color;
1247 self.beam_color = '1 0 1';
1248 self.beam_alpha = 0.5;
1249 self.beam_thickness = 8;
1250 self.beam_traileffect = particleeffectnum("nex_beam");
1251 self.beam_hiteffect = particleeffectnum("electro_lightning");
1252 self.beam_hitlight[0] = 20;
1253 self.beam_hitlight[1] = 1;
1254 self.beam_hitlight[2] = 0;
1255 self.beam_hitlight[3] = 0;
1256 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1257 self.beam_muzzlelight[0] = 50;
1258 self.beam_muzzlelight[1] = 1;
1259 self.beam_muzzlelight[2] = 0;
1260 self.beam_muzzlelight[3] = 0;
1261 self.beam_image = "particles/lgbeam";
1262 setmodel(flash, "models/flash.md3");
1263 flash.alpha = self.beam_alpha;
1264 flash.colormod = self.beam_color;
1268 case ARC_BT_BURST_MISS:
1270 self.beam_color = '-1 -1 1';
1271 self.beam_alpha = 0.5;
1272 self.beam_thickness = 14;
1273 self.beam_traileffect = FALSE;
1274 self.beam_hiteffect = particleeffectnum("electro_lightning");
1275 self.beam_hitlight[0] = 0;
1276 self.beam_hitlight[1] = 1;
1277 self.beam_hitlight[2] = 1;
1278 self.beam_hitlight[3] = 1;
1279 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1280 self.beam_muzzlelight[0] = 0;
1281 self.beam_muzzlelight[1] = 1;
1282 self.beam_muzzlelight[2] = 1;
1283 self.beam_muzzlelight[3] = 1;
1284 self.beam_image = "particles/lgbeam";
1285 setmodel(flash, "models/flash.md3");
1286 flash.alpha = self.beam_alpha;
1287 flash.colormod = self.beam_color;
1291 case ARC_BT_BURST_WALL:
1293 self.beam_color = '0.5 0.5 1';
1294 self.beam_alpha = 0.5;
1295 self.beam_thickness = 14;
1296 self.beam_traileffect = FALSE;
1297 self.beam_hiteffect = particleeffectnum("electro_lightning");
1298 self.beam_hitlight[0] = 0;
1299 self.beam_hitlight[1] = 1;
1300 self.beam_hitlight[2] = 1;
1301 self.beam_hitlight[3] = 1;
1302 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1303 self.beam_muzzlelight[0] = 0;
1304 self.beam_muzzlelight[1] = 1;
1305 self.beam_muzzlelight[2] = 1;
1306 self.beam_muzzlelight[3] = 1;
1307 self.beam_image = "particles/lgbeam";
1308 setmodel(flash, "models/flash.md3");
1309 flash.alpha = self.beam_alpha;
1310 flash.colormod = self.beam_color;
1314 case ARC_BT_BURST_HEAL:
1316 self.beam_color = '0 1 0';
1317 self.beam_alpha = 0.5;
1318 self.beam_thickness = 14;
1319 self.beam_traileffect = FALSE;
1320 self.beam_hiteffect = particleeffectnum("electro_lightning");
1321 self.beam_hitlight[0] = 0;
1322 self.beam_hitlight[1] = 1;
1323 self.beam_hitlight[2] = 1;
1324 self.beam_hitlight[3] = 1;
1325 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1326 self.beam_muzzlelight[0] = 0;
1327 self.beam_muzzlelight[1] = 1;
1328 self.beam_muzzlelight[2] = 1;
1329 self.beam_muzzlelight[3] = 1;
1330 self.beam_image = "particles/lgbeam";
1331 setmodel(flash, "models/flash.md3");
1332 flash.alpha = self.beam_alpha;
1333 flash.colormod = self.beam_color;
1337 case ARC_BT_BURST_HIT:
1339 self.beam_color = '1 0 1';
1340 self.beam_alpha = 0.5;
1341 self.beam_thickness = 14;
1342 self.beam_traileffect = FALSE;
1343 self.beam_hiteffect = particleeffectnum("electro_lightning");
1344 self.beam_hitlight[0] = 0;
1345 self.beam_hitlight[1] = 1;
1346 self.beam_hitlight[2] = 1;
1347 self.beam_hitlight[3] = 1;
1348 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1349 self.beam_muzzlelight[0] = 0;
1350 self.beam_muzzlelight[1] = 1;
1351 self.beam_muzzlelight[2] = 1;
1352 self.beam_muzzlelight[3] = 1;
1353 self.beam_image = "particles/lgbeam";
1354 setmodel(flash, "models/flash.md3");
1355 flash.alpha = self.beam_alpha;
1356 flash.colormod = self.beam_color;
1361 // shouldn't be possible, but lets make it colorful if it does :D
1364 self.beam_color = randomvec();
1365 self.beam_alpha = 1;
1366 self.beam_thickness = 8;
1367 self.beam_traileffect = FALSE;
1368 self.beam_hiteffect = FALSE;
1369 self.beam_hitlight[0] = 0;
1370 self.beam_hitlight[1] = 1;
1371 self.beam_hitlight[2] = 1;
1372 self.beam_hitlight[3] = 1;
1373 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1374 self.beam_muzzlelight[0] = 0;
1375 self.beam_muzzlelight[1] = 1;
1376 self.beam_muzzlelight[2] = 1;
1377 self.beam_muzzlelight[3] = 1;
1378 self.beam_image = "particles/lgbeam";
1379 setmodel(flash, "models/flash.md3");
1380 flash.alpha = self.beam_alpha;
1381 flash.colormod = self.beam_color;
1388 if(!self.beam_usevieworigin)
1390 InterpolateOrigin_Note();
1394 float W_Arc(float req)
1398 case WR_IMPACTEFFECT:
1405 //precache_sound("weapons/arc_impact.wav");
1406 //precache_sound("weapons/arc_impact_combo.wav");
1409 case WR_ZOOMRETICLE:
1411 // no weapon specific image for this weapon