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;
84 .float beam_teleporttime;
87 void Ent_ReadArcBeam(float isnew);
91 .float beam_thickness;
92 .float beam_traileffect;
93 .float beam_hiteffect;
94 .float beam_hitlight[4]; // 0: radius, 123: rgb
95 .float beam_muzzleeffect;
96 .float beam_muzzlelight[4]; // 0: radius, 123: rgb
99 .entity beam_muzzleentity;
101 .float beam_degreespersegment;
102 .float beam_distancepersegment;
103 .float beam_usevieworigin;
104 .float beam_initialized;
105 .float beam_maxangle;
107 .float beam_returnspeed;
108 .float beam_tightness;
109 .vector beam_shotorigin;
111 entity Draw_ArcBeam_callback_entity;
112 float Draw_ArcBeam_callback_last_thickness;
113 vector Draw_ArcBeam_callback_last_top; // NOTE: in same coordinate system as player.
114 vector Draw_ArcBeam_callback_last_bottom; // NOTE: in same coordinate system as player.
118 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
120 float W_Arc_Beam_Send(entity to, float sf)
122 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
124 // Truncate information when this beam is displayed to the owner client
125 // - The owner client has no use for beam start position or directions,
126 // it always figures this information out for itself with csqc code.
127 // - Spectating the owner also truncates this information.
128 float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
129 if(drawlocal) { sf &= ~ARC_SF_LOCALMASK; }
131 WriteByte(MSG_ENTITY, sf);
133 if(sf & ARC_SF_SETTINGS) // settings information
135 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_degreespersegment));
136 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_distancepersegment));
137 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
138 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
139 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
140 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
142 WriteByte(MSG_ENTITY, drawlocal);
144 if(sf & ARC_SF_START) // starting location
146 WriteCoord(MSG_ENTITY, self.beam_start_x);
147 WriteCoord(MSG_ENTITY, self.beam_start_y);
148 WriteCoord(MSG_ENTITY, self.beam_start_z);
150 if(sf & ARC_SF_WANTDIR) // want/aim direction
152 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
153 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
154 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
156 if(sf & ARC_SF_BEAMDIR) // beam direction
158 WriteCoord(MSG_ENTITY, self.beam_dir_x);
159 WriteCoord(MSG_ENTITY, self.beam_dir_y);
160 WriteCoord(MSG_ENTITY, self.beam_dir_z);
162 if(sf & ARC_SF_BEAMTYPE) // beam type
164 WriteByte(MSG_ENTITY, self.beam_type);
170 void Reset_ArcBeam(entity player, vector forward)
172 if (!player.arc_beam) {
175 player.arc_beam.beam_dir = forward;
176 player.arc_beam.beam_teleporttime = time;
179 void W_Arc_Beam_Think(void)
181 if(self != self.owner.arc_beam)
188 (self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
190 self.owner.deadflag != DEAD_NO
192 (!self.owner.BUTTON_ATCK /* FIXME(Samual): && !self.beam_bursting */)
194 self.owner.freezetag_frozen
197 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
198 entity oldself = self;
200 if(!WEP_ACTION(WEP_ARC, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC, WR_CHECKAMMO2))
202 // note: this doesn't force the switch
203 W_SwitchToOtherWeapon(self);
211 if(self.owner.BUTTON_ATCK2 || self.beam_bursting)
213 if(!self.beam_bursting)
214 self.beam_bursting = TRUE;
215 burst = ARC_BT_BURSTMASK;
219 float coefficient = frametime;
220 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
224 { rootammo = WEP_CVAR(arc, burst_ammo); }
226 { rootammo = WEP_CVAR(arc, beam_ammo); }
230 coefficient = min(coefficient, self.owner.WEP_AMMO(ARC) / rootammo);
231 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - (rootammo * frametime));
235 makevectors(self.owner.v_angle);
243 WEP_CVAR(arc, beam_damage) * coefficient,
244 WEP_CVAR(arc, beam_range)
247 // After teleport, "lock" the beam until the teleport is confirmed.
248 if (time < self.beam_teleporttime + ANTILAG_LATENCY(self.owner)) {
249 w_shotdir = self.beam_dir;
252 // network information: shot origin and want/aim direction
253 if(self.beam_start != w_shotorg)
255 self.SendFlags |= ARC_SF_START;
256 self.beam_start = w_shotorg;
258 if(self.beam_wantdir != w_shotdir)
260 self.SendFlags |= ARC_SF_WANTDIR;
261 self.beam_wantdir = w_shotdir;
264 if(!self.beam_initialized)
266 self.beam_dir = w_shotdir;
267 self.beam_initialized = TRUE;
270 // WEAPONTODO: Detect player velocity so that the beam curves when moving too
271 // idea: blend together self.beam_dir with the inverted direction the player is moving in
272 // might have to make some special accomodation so that it only uses view_right and view_up
274 // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
277 if(self.beam_dir != w_shotdir)
279 // calculate how much we're going to move the end of the beam to the want position
280 // WEAPONTODO (server and client):
281 // blendfactor never actually becomes 0 in this situation, which is a problem
282 // regarding precision... this means that self.beam_dir and w_shotdir approach
283 // eachother, however they never actually become the same value with this method.
284 // Perhaps we should do some form of rounding/snapping?
285 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
286 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
288 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
289 float blendfactor = bound(
291 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
292 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
294 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
298 // the radius is not too far yet, no worries :D
299 float blendfactor = bound(
301 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
304 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
307 // network information: beam direction
308 self.SendFlags |= ARC_SF_BEAMDIR;
310 // calculate how many segments are needed
311 float max_allowed_segments;
313 if(WEP_CVAR(arc, beam_distancepersegment))
315 max_allowed_segments = min(
317 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
320 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
322 if(WEP_CVAR(arc, beam_degreespersegment))
329 WEP_CVAR(arc, beam_maxangle)
332 WEP_CVAR(arc, beam_degreespersegment)
337 else { segments = 1; }
339 else { segments = 1; }
341 vector beam_endpos = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
342 vector beam_controlpoint = w_shotorg + w_shotdir * (WEP_CVAR(arc, beam_range) * (1 - WEP_CVAR(arc, beam_tightness)));
345 float new_beam_type = 0;
346 vector last_origin = w_shotorg;
347 for(i = 1; i <= segments; ++i)
349 // WEAPONTODO (client):
350 // In order to do nice fading and pointing on the starting segment, we must always
351 // have that drawn as a separate triangle... However, that is difficult to do when
352 // keeping in mind the above problems and also optimizing the amount of segments
353 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
355 vector new_origin = bezier_quadratic_getpoint(
360 vector new_dir = normalize(new_origin - last_origin);
362 WarpZone_traceline_antilag(
368 ANTILAG_LATENCY(self.owner)
371 // Do all the transforms for warpzones right now, as we already
372 // "are" in the post-trace system (if we hit a player, that's
373 // always BEHIND the last passed wz).
374 last_origin = trace_endpos;
375 w_shotorg = WarpZone_TransformOrigin(WarpZone_trace_transform, w_shotorg);
376 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
377 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
378 new_dir = WarpZone_TransformVelocity(WarpZone_trace_transform, new_dir);
381 trace_ent.classname == "player"
383 trace_ent.classname == "body"
385 (trace_ent.flags & FL_MONSTER)
388 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
390 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
391 // NO. trace_endpos should be just fine. If not,
392 // that's an engine bug that needs proper debugging.
393 vector hitorigin = trace_endpos;
395 float falloff = ExponentialFalloff(
396 WEP_CVAR(arc, beam_falloff_mindist),
397 WEP_CVAR(arc, beam_falloff_maxdist),
398 WEP_CVAR(arc, beam_falloff_halflifedist),
399 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
402 if(is_player && SAME_TEAM(self.owner, trace_ent))
404 float roothealth, rootarmor;
407 roothealth = WEP_CVAR(arc, burst_healing_hps);
408 rootarmor = WEP_CVAR(arc, burst_healing_aps);
412 roothealth = WEP_CVAR(arc, beam_healing_hps);
413 rootarmor = WEP_CVAR(arc, beam_healing_aps);
416 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
418 trace_ent.health = min(
419 trace_ent.health + (roothealth * coefficient),
420 WEP_CVAR(arc, beam_healing_hmax)
423 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
425 trace_ent.armorvalue = min(
426 trace_ent.armorvalue + (rootarmor * coefficient),
427 WEP_CVAR(arc, beam_healing_amax)
431 // stop rot, set visual effect
432 if(roothealth || rootarmor)
434 trace_ent.pauserothealth_finished = max(
435 trace_ent.pauserothealth_finished,
436 time + autocvar_g_balance_pause_health_rot
438 trace_ent.pauserotarmor_finished = max(
439 trace_ent.pauserotarmor_finished,
440 time + autocvar_g_balance_pause_armor_rot
442 new_beam_type = ARC_BT_HEAL;
451 { rootdamage = WEP_CVAR(arc, burst_damage); }
453 { rootdamage = WEP_CVAR(arc, beam_damage); }
456 { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
458 if(accuracy_isgooddamage(self.owner, trace_ent))
464 rootdamage * coefficient * falloff
472 rootdamage * coefficient * falloff,
475 WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
478 new_beam_type = ARC_BT_HIT;
482 else if(trace_fraction != 1)
484 // we collided with geometry
485 new_beam_type = ARC_BT_WALL;
490 // te_explosion(trace_endpos);
492 // if we're bursting, use burst visual effects
493 new_beam_type += burst;
495 // network information: beam type
496 if(new_beam_type != self.beam_type)
498 self.SendFlags |= ARC_SF_BEAMTYPE;
499 self.beam_type = new_beam_type;
502 self.owner.beam_prev = time;
503 self.nextthink = time;
506 void W_Arc_Beam(float burst)
508 // FIXME(Samual): remove this when overheat and burst work.
511 centerprint(self, "^4NOTE:^7 Arc burst (secondary) is not implemented yet.");
514 // only play fire sound if 1 sec has passed since player let go the fire button
515 if(time - self.beam_prev > 1)
517 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
520 entity beam = self.arc_beam = spawn();
521 beam.classname = "W_Arc_Beam";
522 beam.solid = SOLID_NOT;
523 beam.think = W_Arc_Beam_Think;
525 beam.movetype = MOVETYPE_NONE;
526 beam.bot_dodge = TRUE;
527 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
528 beam.beam_bursting = burst;
529 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
531 entity oldself = self;
537 float W_Arc(float req)
543 if(WEP_CVAR(arc, beam_botaimspeed))
545 self.BUTTON_ATCK = bot_aim(
546 WEP_CVAR(arc, beam_botaimspeed),
548 WEP_CVAR(arc, beam_botaimlifetime),
554 self.BUTTON_ATCK = bot_aim(
566 if(self.arc_beam.beam_heat > threshold)
568 stop the beam somehow
569 play overheat animation
573 if(self.BUTTON_ATCK || self.BUTTON_ATCK2 /* FIXME(Samual): || self.arc_beam.beam_bursting */)
575 if(self.BUTTON_ATCK_prev)
578 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
579 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
582 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
585 if((!self.arc_beam) || wasfreed(self.arc_beam))
587 if(weapon_prepareattack(!!self.BUTTON_ATCK2, 0))
589 W_Arc_Beam(!!self.BUTTON_ATCK2);
591 if(!self.BUTTON_ATCK_prev)
593 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
594 self.BUTTON_ATCK_prev = 1;
601 if(self.BUTTON_ATCK_prev != 0)
603 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
604 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
606 self.BUTTON_ATCK_prev = 0;
610 if(self.BUTTON_ATCK2)
611 if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
614 self.arc_count = autocvar_g_balance_arc_secondary_count;
615 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
616 self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
624 precache_model("models/weapons/g_arc.md3");
625 precache_model("models/weapons/v_arc.md3");
626 precache_model("models/weapons/h_arc.iqm");
627 precache_sound("weapons/lgbeam_fire.wav");
628 if(!arc_shotorigin[0])
630 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
631 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
632 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
633 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
635 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
640 return ((!WEP_CVAR(arc, beam_ammo)) || (self.WEP_AMMO(ARC) > 0));
644 // arc currently has no secondary attack
646 //return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
650 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
655 if(w_deathtype & HITTYPE_SECONDARY)
657 return WEAPON_ELECTRO_MURDER_ORBS;
661 if(w_deathtype & HITTYPE_BOUNCE)
662 return WEAPON_ELECTRO_MURDER_COMBO;
664 return WEAPON_ELECTRO_MURDER_BOLT;
672 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
674 entity beam = Draw_ArcBeam_callback_entity;
675 vector transformed_view_org;
676 transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
678 // Thickdir shall be perpendicular to the beam and to the view-to-beam direction (WEAPONTODO: WHY)
679 // WEAPONTODO: Wouldn't it be better to be perpendicular to the beam and to the view FORWARD direction?
680 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
686 if(trace_fraction != 1)
688 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
689 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
690 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
700 // decide upon thickness
701 float thickness = beam.beam_thickness;
703 // draw primary beam render
704 vector top = hitorigin + (thickdir * thickness);
705 vector bottom = hitorigin - (thickdir * thickness);
707 vector last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
708 vector last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
710 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
713 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
719 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
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 = WarpZone_UnTransformOrigin(WarpZone_trace_transform, top);
749 Draw_ArcBeam_callback_last_bottom = WarpZone_UnTransformOrigin(WarpZone_trace_transform, bottom);
752 void Reset_ArcBeam(void)
755 for (e = world; (e = findfloat(e, beam_usevieworigin, 1)); ) {
756 e.beam_initialized = FALSE;
758 for (e = world; (e = findfloat(e, beam_usevieworigin, 2)); ) {
759 e.beam_initialized = FALSE;
763 void Draw_ArcBeam(void)
765 if(!self.beam_usevieworigin)
767 InterpolateOrigin_Do();
770 // origin = beam starting origin
771 // v_angle = wanted/aim direction
772 // angles = current direction of beam
775 vector wantdir; //= view_forward;
776 vector beamdir; //= self.beam_dir;
779 if(self.beam_usevieworigin)
782 // Currently we have to replicate nearly the same method of figuring
783 // out the shotdir that the server does... Ideally in the future we
784 // should be able to acquire this from a generalized function built
785 // into a weapon system for client code.
787 // find where we are aiming
788 makevectors(warpzone_save_view_angles);
789 vector forward = v_forward;
790 vector right = v_right;
793 // decide upon start position
794 if(self.beam_usevieworigin == 2)
795 { start_pos = warpzone_save_view_origin; }
797 { start_pos = self.origin; }
799 // trace forward with an estimation
802 start_pos + forward * self.beam_range,
807 // untransform in case our trace went through a warpzone
808 vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
810 // un-adjust trueaim if shotend is too close
811 if(vlen(end_pos - start_pos) < g_trueaim_minrange)
812 end_pos = start_pos + (forward * g_trueaim_minrange);
814 // move shot origin to the actual gun muzzle origin
815 vector origin_offset =
816 right * -self.beam_shotorigin_y
817 + up * self.beam_shotorigin_z;
819 start_pos = start_pos + origin_offset;
821 // Move it also forward, but only as far as possible without hitting anything. Don't poke into walls!
822 traceline(start_pos, start_pos + forward * self.beam_shotorigin_x, MOVE_NORMAL, self);
823 start_pos = trace_endpos;
825 // calculate the aim direction now
826 wantdir = normalize(end_pos - start_pos);
828 if(!self.beam_initialized)
830 self.beam_dir = wantdir;
831 self.beam_initialized = TRUE;
834 if(self.beam_dir != wantdir)
836 // calculate how much we're going to move the end of the beam to the want position
837 // WEAPONTODO (server and client):
838 // blendfactor never actually becomes 0 in this situation, which is a problem
839 // regarding precision... this means that self.beam_dir and w_shotdir approach
840 // eachother, however they never actually become the same value with this method.
841 // Perhaps we should do some form of rounding/snapping?
842 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
843 if(angle && (angle > self.beam_maxangle))
845 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
846 float blendfactor = bound(
848 (1 - (self.beam_returnspeed * frametime)),
849 min(self.beam_maxangle / angle, 1)
851 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
855 // the radius is not too far yet, no worries :D
856 float blendfactor = bound(
858 (1 - (self.beam_returnspeed * frametime)),
861 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
864 // calculate how many segments are needed
865 float max_allowed_segments;
867 if(self.beam_distancepersegment)
869 max_allowed_segments = min(
871 1 + (vlen(wantdir / self.beam_distancepersegment))
874 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
876 if(self.beam_degreespersegment)
886 self.beam_degreespersegment
891 else { segments = 1; }
893 else { segments = 1; }
895 // set the beam direction which the rest of the code will refer to
896 beamdir = self.beam_dir;
898 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
899 self.angles = fixedvectoangles2(forward, up); // TODO(Samual): is this == warpzone_save_view_angles?
903 // set the values from the provided info from the networked entity
904 start_pos = self.origin;
905 wantdir = self.v_angle;
906 beamdir = self.angles;
908 if(beamdir != wantdir)
910 float angle = vlen(wantdir - beamdir) * RAD2DEG;
912 // calculate how many segments are needed
913 float max_allowed_segments;
915 if(self.beam_distancepersegment)
917 max_allowed_segments = min(
919 1 + (vlen(wantdir / self.beam_distancepersegment))
922 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
924 if(self.beam_degreespersegment)
934 self.beam_degreespersegment
939 else { segments = 1; }
941 else { segments = 1; }
944 setorigin(self, start_pos);
945 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
947 vector beam_endpos = (start_pos + (beamdir * self.beam_range));
948 vector beam_controlpoint = start_pos + wantdir * (self.beam_range * (1 - self.beam_tightness));
950 Draw_ArcBeam_callback_entity = self;
951 Draw_ArcBeam_callback_last_thickness = 0;
952 Draw_ArcBeam_callback_last_top = start_pos;
953 Draw_ArcBeam_callback_last_bottom = start_pos;
955 vector last_origin = start_pos;
956 vector original_start_pos = start_pos;
959 for(i = 1; i <= segments; ++i)
961 // WEAPONTODO (client):
962 // In order to do nice fading and pointing on the starting segment, we must always
963 // have that drawn as a separate triangle... However, that is difficult to do when
964 // keeping in mind the above problems and also optimizing the amount of segments
965 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
967 vector new_origin = bezier_quadratic_getpoint(
973 WarpZone_TraceBox_ThroughZone(
981 Draw_ArcBeam_callback
984 // Do all the transforms for warpzones right now, as we already "are" in the post-trace
985 // system (if we hit a player, that's always BEHIND the last passed wz).
986 last_origin = trace_endpos;
987 start_pos = WarpZone_TransformOrigin(WarpZone_trace_transform, start_pos);
988 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
989 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
990 beamdir = WarpZone_TransformVelocity(WarpZone_trace_transform, beamdir);
991 Draw_ArcBeam_callback_last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
992 Draw_ArcBeam_callback_last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
994 if(trace_fraction < 1) { break; }
997 // visual effects for startpoint and endpoint
998 if(self.beam_hiteffect)
1000 // FIXME we really should do this on the server so it actually
1001 // matches gameplay. What this client side stuff is doing is no
1002 // more than guesswork.
1004 self.beam_hiteffect,
1010 if(self.beam_hitlight[0])
1014 self.beam_hitlight[0],
1016 self.beam_hitlight[1],
1017 self.beam_hitlight[2],
1018 self.beam_hitlight[3]
1022 if(self.beam_muzzleeffect)
1025 self.beam_muzzleeffect,
1026 original_start_pos + wantdir * 20,
1031 if(self.beam_muzzlelight[0])
1034 original_start_pos + wantdir * 20,
1035 self.beam_muzzlelight[0],
1037 self.beam_muzzlelight[1],
1038 self.beam_muzzlelight[2],
1039 self.beam_muzzlelight[3]
1045 Draw_ArcBeam_callback_entity = world;
1046 Draw_ArcBeam_callback_last_thickness = 0;
1047 Draw_ArcBeam_callback_last_top = '0 0 0';
1048 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1051 void Remove_ArcBeam(void)
1053 remove(self.beam_muzzleentity);
1054 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1057 void Ent_ReadArcBeam(float isnew)
1059 float sf = ReadByte();
1064 // calculate shot origin offset from gun alignment
1065 float gunalign = autocvar_cl_gunalign;
1066 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1067 gunalign = 3; // default value
1070 self.beam_shotorigin = arc_shotorigin[gunalign];
1072 // set other main attributes of the beam
1073 self.draw = Draw_ArcBeam;
1074 self.entremove = Remove_ArcBeam;
1075 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1079 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1080 flash.drawmask = MASK_NORMAL;
1081 flash.solid = SOLID_NOT;
1082 flash.avelocity_z = 5000;
1083 setattachment(flash, self, "");
1084 setorigin(flash, '0 0 0');
1086 self.beam_muzzleentity = flash;
1090 flash = self.beam_muzzleentity;
1093 if(sf & ARC_SF_SETTINGS) // settings information
1095 self.beam_degreespersegment = ReadShort();
1096 self.beam_distancepersegment = ReadShort();
1097 self.beam_maxangle = ReadShort();
1098 self.beam_range = ReadCoord();
1099 self.beam_returnspeed = ReadShort();
1100 self.beam_tightness = (ReadByte() / 10);
1104 if(autocvar_chase_active)
1105 { self.beam_usevieworigin = 1; }
1106 else // use view origin
1107 { self.beam_usevieworigin = 2; }
1111 self.beam_usevieworigin = 0;
1115 if(!self.beam_usevieworigin)
1117 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1118 self.iflags = IFLAG_ORIGIN;
1120 InterpolateOrigin_Undo();
1123 if(sf & ARC_SF_START) // starting location
1125 self.origin_x = ReadCoord();
1126 self.origin_y = ReadCoord();
1127 self.origin_z = ReadCoord();
1129 else if(self.beam_usevieworigin) // infer the location from player location
1131 if(self.beam_usevieworigin == 2)
1134 self.origin = view_origin;
1138 // use player origin so that third person display still works
1139 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1143 setorigin(self, self.origin);
1145 if(sf & ARC_SF_WANTDIR) // want/aim direction
1147 self.v_angle_x = ReadCoord();
1148 self.v_angle_y = ReadCoord();
1149 self.v_angle_z = ReadCoord();
1152 if(sf & ARC_SF_BEAMDIR) // beam direction
1154 self.angles_x = ReadCoord();
1155 self.angles_y = ReadCoord();
1156 self.angles_z = ReadCoord();
1159 if(sf & ARC_SF_BEAMTYPE) // beam type
1161 self.beam_type = ReadByte();
1162 switch(self.beam_type)
1166 self.beam_color = '-1 -1 1';
1167 self.beam_alpha = 0.5;
1168 self.beam_thickness = 8;
1169 self.beam_traileffect = FALSE;
1170 self.beam_hiteffect = particleeffectnum("electro_lightning");
1171 self.beam_hitlight[0] = 0;
1172 self.beam_hitlight[1] = 1;
1173 self.beam_hitlight[2] = 1;
1174 self.beam_hitlight[3] = 1;
1175 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1176 self.beam_muzzlelight[0] = 0;
1177 self.beam_muzzlelight[1] = 1;
1178 self.beam_muzzlelight[2] = 1;
1179 self.beam_muzzlelight[3] = 1;
1180 self.beam_image = "particles/lgbeam";
1181 setmodel(flash, "models/flash.md3");
1182 flash.alpha = self.beam_alpha;
1183 flash.colormod = self.beam_color;
1187 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1189 self.beam_color = '0.5 0.5 1';
1190 self.beam_alpha = 0.5;
1191 self.beam_thickness = 8;
1192 self.beam_traileffect = FALSE;
1193 self.beam_hiteffect = particleeffectnum("electro_lightning");
1194 self.beam_hitlight[0] = 0;
1195 self.beam_hitlight[1] = 1;
1196 self.beam_hitlight[2] = 1;
1197 self.beam_hitlight[3] = 1;
1198 self.beam_muzzleeffect = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
1199 self.beam_muzzlelight[0] = 0;
1200 self.beam_muzzlelight[1] = 1;
1201 self.beam_muzzlelight[2] = 1;
1202 self.beam_muzzlelight[3] = 1;
1203 self.beam_image = "particles/lgbeam";
1204 setmodel(flash, "models/flash.md3");
1205 flash.alpha = self.beam_alpha;
1206 flash.colormod = self.beam_color;
1212 self.beam_color = '0 1 0';
1213 self.beam_alpha = 0.5;
1214 self.beam_thickness = 8;
1215 self.beam_traileffect = FALSE;
1216 self.beam_hiteffect = particleeffectnum("healray_impact");
1217 self.beam_hitlight[0] = 0;
1218 self.beam_hitlight[1] = 1;
1219 self.beam_hitlight[2] = 1;
1220 self.beam_hitlight[3] = 1;
1221 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1222 self.beam_muzzlelight[0] = 0;
1223 self.beam_muzzlelight[1] = 1;
1224 self.beam_muzzlelight[2] = 1;
1225 self.beam_muzzlelight[3] = 1;
1226 self.beam_image = "particles/lgbeam";
1227 setmodel(flash, "models/flash.md3");
1228 flash.alpha = self.beam_alpha;
1229 flash.colormod = self.beam_color;
1235 self.beam_color = '1 0 1';
1236 self.beam_alpha = 0.5;
1237 self.beam_thickness = 8;
1238 self.beam_traileffect = particleeffectnum("nex_beam");
1239 self.beam_hiteffect = particleeffectnum("electro_lightning");
1240 self.beam_hitlight[0] = 20;
1241 self.beam_hitlight[1] = 1;
1242 self.beam_hitlight[2] = 0;
1243 self.beam_hitlight[3] = 0;
1244 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1245 self.beam_muzzlelight[0] = 50;
1246 self.beam_muzzlelight[1] = 1;
1247 self.beam_muzzlelight[2] = 0;
1248 self.beam_muzzlelight[3] = 0;
1249 self.beam_image = "particles/lgbeam";
1250 setmodel(flash, "models/flash.md3");
1251 flash.alpha = self.beam_alpha;
1252 flash.colormod = self.beam_color;
1256 case ARC_BT_BURST_MISS:
1258 self.beam_color = '-1 -1 1';
1259 self.beam_alpha = 0.5;
1260 self.beam_thickness = 14;
1261 self.beam_traileffect = FALSE;
1262 self.beam_hiteffect = particleeffectnum("electro_lightning");
1263 self.beam_hitlight[0] = 0;
1264 self.beam_hitlight[1] = 1;
1265 self.beam_hitlight[2] = 1;
1266 self.beam_hitlight[3] = 1;
1267 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1268 self.beam_muzzlelight[0] = 0;
1269 self.beam_muzzlelight[1] = 1;
1270 self.beam_muzzlelight[2] = 1;
1271 self.beam_muzzlelight[3] = 1;
1272 self.beam_image = "particles/lgbeam";
1273 setmodel(flash, "models/flash.md3");
1274 flash.alpha = self.beam_alpha;
1275 flash.colormod = self.beam_color;
1279 case ARC_BT_BURST_WALL:
1281 self.beam_color = '0.5 0.5 1';
1282 self.beam_alpha = 0.5;
1283 self.beam_thickness = 14;
1284 self.beam_traileffect = FALSE;
1285 self.beam_hiteffect = particleeffectnum("electro_lightning");
1286 self.beam_hitlight[0] = 0;
1287 self.beam_hitlight[1] = 1;
1288 self.beam_hitlight[2] = 1;
1289 self.beam_hitlight[3] = 1;
1290 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1291 self.beam_muzzlelight[0] = 0;
1292 self.beam_muzzlelight[1] = 1;
1293 self.beam_muzzlelight[2] = 1;
1294 self.beam_muzzlelight[3] = 1;
1295 self.beam_image = "particles/lgbeam";
1296 setmodel(flash, "models/flash.md3");
1297 flash.alpha = self.beam_alpha;
1298 flash.colormod = self.beam_color;
1302 case ARC_BT_BURST_HEAL:
1304 self.beam_color = '0 1 0';
1305 self.beam_alpha = 0.5;
1306 self.beam_thickness = 14;
1307 self.beam_traileffect = FALSE;
1308 self.beam_hiteffect = particleeffectnum("electro_lightning");
1309 self.beam_hitlight[0] = 0;
1310 self.beam_hitlight[1] = 1;
1311 self.beam_hitlight[2] = 1;
1312 self.beam_hitlight[3] = 1;
1313 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1314 self.beam_muzzlelight[0] = 0;
1315 self.beam_muzzlelight[1] = 1;
1316 self.beam_muzzlelight[2] = 1;
1317 self.beam_muzzlelight[3] = 1;
1318 self.beam_image = "particles/lgbeam";
1319 setmodel(flash, "models/flash.md3");
1320 flash.alpha = self.beam_alpha;
1321 flash.colormod = self.beam_color;
1325 case ARC_BT_BURST_HIT:
1327 self.beam_color = '1 0 1';
1328 self.beam_alpha = 0.5;
1329 self.beam_thickness = 14;
1330 self.beam_traileffect = FALSE;
1331 self.beam_hiteffect = particleeffectnum("electro_lightning");
1332 self.beam_hitlight[0] = 0;
1333 self.beam_hitlight[1] = 1;
1334 self.beam_hitlight[2] = 1;
1335 self.beam_hitlight[3] = 1;
1336 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1337 self.beam_muzzlelight[0] = 0;
1338 self.beam_muzzlelight[1] = 1;
1339 self.beam_muzzlelight[2] = 1;
1340 self.beam_muzzlelight[3] = 1;
1341 self.beam_image = "particles/lgbeam";
1342 setmodel(flash, "models/flash.md3");
1343 flash.alpha = self.beam_alpha;
1344 flash.colormod = self.beam_color;
1349 // shouldn't be possible, but lets make it colorful if it does :D
1352 self.beam_color = randomvec();
1353 self.beam_alpha = 1;
1354 self.beam_thickness = 8;
1355 self.beam_traileffect = FALSE;
1356 self.beam_hiteffect = FALSE;
1357 self.beam_hitlight[0] = 0;
1358 self.beam_hitlight[1] = 1;
1359 self.beam_hitlight[2] = 1;
1360 self.beam_hitlight[3] = 1;
1361 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1362 self.beam_muzzlelight[0] = 0;
1363 self.beam_muzzlelight[1] = 1;
1364 self.beam_muzzlelight[2] = 1;
1365 self.beam_muzzlelight[3] = 1;
1366 self.beam_image = "particles/lgbeam";
1367 setmodel(flash, "models/flash.md3");
1368 flash.alpha = self.beam_alpha;
1369 flash.colormod = self.beam_color;
1376 if(!self.beam_usevieworigin)
1378 InterpolateOrigin_Note();
1382 float W_Arc(float req)
1386 case WR_IMPACTEFFECT:
1393 precache_sound("weapons/lgbeam_fly.wav");
1396 case WR_ZOOMRETICLE:
1398 // no weapon specific image for this weapon