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 return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
648 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
653 if(w_deathtype & HITTYPE_SECONDARY)
655 return WEAPON_ELECTRO_MURDER_ORBS;
659 if(w_deathtype & HITTYPE_BOUNCE)
660 return WEAPON_ELECTRO_MURDER_COMBO;
662 return WEAPON_ELECTRO_MURDER_BOLT;
670 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
672 entity beam = Draw_ArcBeam_callback_entity;
673 vector transformed_view_org;
674 transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
676 // Thickdir shall be perpendicular to the beam and to the view-to-beam direction (WEAPONTODO: WHY)
677 // WEAPONTODO: Wouldn't it be better to be perpendicular to the beam and to the view FORWARD direction?
678 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
684 if(trace_fraction != 1)
686 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
687 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
688 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
698 // decide upon thickness
699 float thickness = beam.beam_thickness;
701 // draw primary beam render
702 vector top = hitorigin + (thickdir * thickness);
703 vector bottom = hitorigin - (thickdir * thickness);
705 vector last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
706 vector last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
708 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
711 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
717 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
723 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
729 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
735 // draw trailing particles
737 // - Don't use spammy particle counts here, use a FEW small particles around the beam
738 // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
739 if(beam.beam_traileffect)
741 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
744 // set up for the next
745 Draw_ArcBeam_callback_last_thickness = thickness;
746 Draw_ArcBeam_callback_last_top = WarpZone_UnTransformOrigin(WarpZone_trace_transform, top);
747 Draw_ArcBeam_callback_last_bottom = WarpZone_UnTransformOrigin(WarpZone_trace_transform, bottom);
750 void Reset_ArcBeam(void)
753 for (e = world; (e = findfloat(e, beam_usevieworigin, 1)); ) {
754 e.beam_initialized = FALSE;
756 for (e = world; (e = findfloat(e, beam_usevieworigin, 2)); ) {
757 e.beam_initialized = FALSE;
761 void Draw_ArcBeam(void)
763 if(!self.beam_usevieworigin)
765 InterpolateOrigin_Do();
768 // origin = beam starting origin
769 // v_angle = wanted/aim direction
770 // angles = current direction of beam
773 vector wantdir; //= view_forward;
774 vector beamdir; //= self.beam_dir;
777 if(self.beam_usevieworigin)
780 // Currently we have to replicate nearly the same method of figuring
781 // out the shotdir that the server does... Ideally in the future we
782 // should be able to acquire this from a generalized function built
783 // into a weapon system for client code.
785 // find where we are aiming
786 makevectors(warpzone_save_view_angles);
787 vector forward = v_forward;
788 vector right = v_right;
791 // decide upon start position
792 if(self.beam_usevieworigin == 2)
793 { start_pos = warpzone_save_view_origin; }
795 { start_pos = self.origin; }
797 // trace forward with an estimation
800 start_pos + forward * self.beam_range,
805 // untransform in case our trace went through a warpzone
806 vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
808 // un-adjust trueaim if shotend is too close
809 if(vlen(end_pos - start_pos) < g_trueaim_minrange)
810 end_pos = start_pos + (forward * g_trueaim_minrange);
812 // move shot origin to the actual gun muzzle origin
813 vector origin_offset =
814 right * -self.beam_shotorigin_y
815 + up * self.beam_shotorigin_z;
817 start_pos = start_pos + origin_offset;
819 // Move it also forward, but only as far as possible without hitting anything. Don't poke into walls!
820 traceline(start_pos, start_pos + forward * self.beam_shotorigin_x, MOVE_NORMAL, self);
821 start_pos = trace_endpos;
823 // calculate the aim direction now
824 wantdir = normalize(end_pos - start_pos);
826 if(!self.beam_initialized)
828 self.beam_dir = wantdir;
829 self.beam_initialized = TRUE;
832 if(self.beam_dir != wantdir)
834 // calculate how much we're going to move the end of the beam to the want position
835 // WEAPONTODO (server and client):
836 // blendfactor never actually becomes 0 in this situation, which is a problem
837 // regarding precision... this means that self.beam_dir and w_shotdir approach
838 // eachother, however they never actually become the same value with this method.
839 // Perhaps we should do some form of rounding/snapping?
840 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
841 if(angle && (angle > self.beam_maxangle))
843 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
844 float blendfactor = bound(
846 (1 - (self.beam_returnspeed * frametime)),
847 min(self.beam_maxangle / angle, 1)
849 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
853 // the radius is not too far yet, no worries :D
854 float blendfactor = bound(
856 (1 - (self.beam_returnspeed * frametime)),
859 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
862 // calculate how many segments are needed
863 float max_allowed_segments;
865 if(self.beam_distancepersegment)
867 max_allowed_segments = min(
869 1 + (vlen(wantdir / self.beam_distancepersegment))
872 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
874 if(self.beam_degreespersegment)
884 self.beam_degreespersegment
889 else { segments = 1; }
891 else { segments = 1; }
893 // set the beam direction which the rest of the code will refer to
894 beamdir = self.beam_dir;
896 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
897 self.angles = fixedvectoangles2(forward, up); // TODO(Samual): is this == warpzone_save_view_angles?
901 // set the values from the provided info from the networked entity
902 start_pos = self.origin;
903 wantdir = self.v_angle;
904 beamdir = self.angles;
906 if(beamdir != wantdir)
908 float angle = vlen(wantdir - beamdir) * RAD2DEG;
910 // calculate how many segments are needed
911 float max_allowed_segments;
913 if(self.beam_distancepersegment)
915 max_allowed_segments = min(
917 1 + (vlen(wantdir / self.beam_distancepersegment))
920 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
922 if(self.beam_degreespersegment)
932 self.beam_degreespersegment
937 else { segments = 1; }
939 else { segments = 1; }
942 setorigin(self, start_pos);
943 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
945 vector beam_endpos = (start_pos + (beamdir * self.beam_range));
946 vector beam_controlpoint = start_pos + wantdir * (self.beam_range * (1 - self.beam_tightness));
948 Draw_ArcBeam_callback_entity = self;
949 Draw_ArcBeam_callback_last_thickness = 0;
950 Draw_ArcBeam_callback_last_top = start_pos;
951 Draw_ArcBeam_callback_last_bottom = start_pos;
953 vector last_origin = start_pos;
954 vector original_start_pos = start_pos;
957 for(i = 1; i <= segments; ++i)
959 // WEAPONTODO (client):
960 // In order to do nice fading and pointing on the starting segment, we must always
961 // have that drawn as a separate triangle... However, that is difficult to do when
962 // keeping in mind the above problems and also optimizing the amount of segments
963 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
965 vector new_origin = bezier_quadratic_getpoint(
971 WarpZone_TraceBox_ThroughZone(
979 Draw_ArcBeam_callback
982 // Do all the transforms for warpzones right now, as we already "are" in the post-trace
983 // system (if we hit a player, that's always BEHIND the last passed wz).
984 last_origin = trace_endpos;
985 start_pos = WarpZone_TransformOrigin(WarpZone_trace_transform, start_pos);
986 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
987 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
988 beamdir = WarpZone_TransformVelocity(WarpZone_trace_transform, beamdir);
989 Draw_ArcBeam_callback_last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
990 Draw_ArcBeam_callback_last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
992 if(trace_fraction < 1) { break; }
995 // visual effects for startpoint and endpoint
996 if(self.beam_hiteffect)
998 // FIXME we really should do this on the server so it actually
999 // matches gameplay. What this client side stuff is doing is no
1000 // more than guesswork.
1002 self.beam_hiteffect,
1008 if(self.beam_hitlight[0])
1012 self.beam_hitlight[0],
1014 self.beam_hitlight[1],
1015 self.beam_hitlight[2],
1016 self.beam_hitlight[3]
1020 if(self.beam_muzzleeffect)
1023 self.beam_muzzleeffect,
1024 original_start_pos + wantdir * 20,
1029 if(self.beam_muzzlelight[0])
1032 original_start_pos + wantdir * 20,
1033 self.beam_muzzlelight[0],
1035 self.beam_muzzlelight[1],
1036 self.beam_muzzlelight[2],
1037 self.beam_muzzlelight[3]
1043 Draw_ArcBeam_callback_entity = world;
1044 Draw_ArcBeam_callback_last_thickness = 0;
1045 Draw_ArcBeam_callback_last_top = '0 0 0';
1046 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1049 void Remove_ArcBeam(void)
1051 remove(self.beam_muzzleentity);
1052 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1055 void Ent_ReadArcBeam(float isnew)
1057 float sf = ReadByte();
1062 // calculate shot origin offset from gun alignment
1063 float gunalign = autocvar_cl_gunalign;
1064 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1065 gunalign = 3; // default value
1068 self.beam_shotorigin = arc_shotorigin[gunalign];
1070 // set other main attributes of the beam
1071 self.draw = Draw_ArcBeam;
1072 self.entremove = Remove_ArcBeam;
1073 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1077 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1078 flash.drawmask = MASK_NORMAL;
1079 flash.solid = SOLID_NOT;
1080 flash.avelocity_z = 5000;
1081 setattachment(flash, self, "");
1082 setorigin(flash, '0 0 0');
1084 self.beam_muzzleentity = flash;
1088 flash = self.beam_muzzleentity;
1091 if(sf & ARC_SF_SETTINGS) // settings information
1093 self.beam_degreespersegment = ReadShort();
1094 self.beam_distancepersegment = ReadShort();
1095 self.beam_maxangle = ReadShort();
1096 self.beam_range = ReadCoord();
1097 self.beam_returnspeed = ReadShort();
1098 self.beam_tightness = (ReadByte() / 10);
1102 if(autocvar_chase_active)
1103 { self.beam_usevieworigin = 1; }
1104 else // use view origin
1105 { self.beam_usevieworigin = 2; }
1109 self.beam_usevieworigin = 0;
1113 if(!self.beam_usevieworigin)
1115 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1116 self.iflags = IFLAG_ORIGIN;
1118 InterpolateOrigin_Undo();
1121 if(sf & ARC_SF_START) // starting location
1123 self.origin_x = ReadCoord();
1124 self.origin_y = ReadCoord();
1125 self.origin_z = ReadCoord();
1127 else if(self.beam_usevieworigin) // infer the location from player location
1129 if(self.beam_usevieworigin == 2)
1132 self.origin = view_origin;
1136 // use player origin so that third person display still works
1137 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1141 setorigin(self, self.origin);
1143 if(sf & ARC_SF_WANTDIR) // want/aim direction
1145 self.v_angle_x = ReadCoord();
1146 self.v_angle_y = ReadCoord();
1147 self.v_angle_z = ReadCoord();
1150 if(sf & ARC_SF_BEAMDIR) // beam direction
1152 self.angles_x = ReadCoord();
1153 self.angles_y = ReadCoord();
1154 self.angles_z = ReadCoord();
1157 if(sf & ARC_SF_BEAMTYPE) // beam type
1159 self.beam_type = ReadByte();
1160 switch(self.beam_type)
1164 self.beam_color = '-1 -1 1';
1165 self.beam_alpha = 0.5;
1166 self.beam_thickness = 8;
1167 self.beam_traileffect = FALSE;
1168 self.beam_hiteffect = particleeffectnum("electro_lightning");
1169 self.beam_hitlight[0] = 0;
1170 self.beam_hitlight[1] = 1;
1171 self.beam_hitlight[2] = 1;
1172 self.beam_hitlight[3] = 1;
1173 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1174 self.beam_muzzlelight[0] = 0;
1175 self.beam_muzzlelight[1] = 1;
1176 self.beam_muzzlelight[2] = 1;
1177 self.beam_muzzlelight[3] = 1;
1178 self.beam_image = "particles/lgbeam";
1179 setmodel(flash, "models/flash.md3");
1180 flash.alpha = self.beam_alpha;
1181 flash.colormod = self.beam_color;
1185 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1187 self.beam_color = '0.5 0.5 1';
1188 self.beam_alpha = 0.5;
1189 self.beam_thickness = 8;
1190 self.beam_traileffect = FALSE;
1191 self.beam_hiteffect = particleeffectnum("electro_lightning");
1192 self.beam_hitlight[0] = 0;
1193 self.beam_hitlight[1] = 1;
1194 self.beam_hitlight[2] = 1;
1195 self.beam_hitlight[3] = 1;
1196 self.beam_muzzleeffect = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
1197 self.beam_muzzlelight[0] = 0;
1198 self.beam_muzzlelight[1] = 1;
1199 self.beam_muzzlelight[2] = 1;
1200 self.beam_muzzlelight[3] = 1;
1201 self.beam_image = "particles/lgbeam";
1202 setmodel(flash, "models/flash.md3");
1203 flash.alpha = self.beam_alpha;
1204 flash.colormod = self.beam_color;
1210 self.beam_color = '0 1 0';
1211 self.beam_alpha = 0.5;
1212 self.beam_thickness = 8;
1213 self.beam_traileffect = FALSE;
1214 self.beam_hiteffect = particleeffectnum("healray_impact");
1215 self.beam_hitlight[0] = 0;
1216 self.beam_hitlight[1] = 1;
1217 self.beam_hitlight[2] = 1;
1218 self.beam_hitlight[3] = 1;
1219 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1220 self.beam_muzzlelight[0] = 0;
1221 self.beam_muzzlelight[1] = 1;
1222 self.beam_muzzlelight[2] = 1;
1223 self.beam_muzzlelight[3] = 1;
1224 self.beam_image = "particles/lgbeam";
1225 setmodel(flash, "models/flash.md3");
1226 flash.alpha = self.beam_alpha;
1227 flash.colormod = self.beam_color;
1233 self.beam_color = '1 0 1';
1234 self.beam_alpha = 0.5;
1235 self.beam_thickness = 8;
1236 self.beam_traileffect = particleeffectnum("nex_beam");
1237 self.beam_hiteffect = particleeffectnum("electro_lightning");
1238 self.beam_hitlight[0] = 20;
1239 self.beam_hitlight[1] = 1;
1240 self.beam_hitlight[2] = 0;
1241 self.beam_hitlight[3] = 0;
1242 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1243 self.beam_muzzlelight[0] = 50;
1244 self.beam_muzzlelight[1] = 1;
1245 self.beam_muzzlelight[2] = 0;
1246 self.beam_muzzlelight[3] = 0;
1247 self.beam_image = "particles/lgbeam";
1248 setmodel(flash, "models/flash.md3");
1249 flash.alpha = self.beam_alpha;
1250 flash.colormod = self.beam_color;
1254 case ARC_BT_BURST_MISS:
1256 self.beam_color = '-1 -1 1';
1257 self.beam_alpha = 0.5;
1258 self.beam_thickness = 14;
1259 self.beam_traileffect = FALSE;
1260 self.beam_hiteffect = particleeffectnum("electro_lightning");
1261 self.beam_hitlight[0] = 0;
1262 self.beam_hitlight[1] = 1;
1263 self.beam_hitlight[2] = 1;
1264 self.beam_hitlight[3] = 1;
1265 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1266 self.beam_muzzlelight[0] = 0;
1267 self.beam_muzzlelight[1] = 1;
1268 self.beam_muzzlelight[2] = 1;
1269 self.beam_muzzlelight[3] = 1;
1270 self.beam_image = "particles/lgbeam";
1271 setmodel(flash, "models/flash.md3");
1272 flash.alpha = self.beam_alpha;
1273 flash.colormod = self.beam_color;
1277 case ARC_BT_BURST_WALL:
1279 self.beam_color = '0.5 0.5 1';
1280 self.beam_alpha = 0.5;
1281 self.beam_thickness = 14;
1282 self.beam_traileffect = FALSE;
1283 self.beam_hiteffect = particleeffectnum("electro_lightning");
1284 self.beam_hitlight[0] = 0;
1285 self.beam_hitlight[1] = 1;
1286 self.beam_hitlight[2] = 1;
1287 self.beam_hitlight[3] = 1;
1288 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1289 self.beam_muzzlelight[0] = 0;
1290 self.beam_muzzlelight[1] = 1;
1291 self.beam_muzzlelight[2] = 1;
1292 self.beam_muzzlelight[3] = 1;
1293 self.beam_image = "particles/lgbeam";
1294 setmodel(flash, "models/flash.md3");
1295 flash.alpha = self.beam_alpha;
1296 flash.colormod = self.beam_color;
1300 case ARC_BT_BURST_HEAL:
1302 self.beam_color = '0 1 0';
1303 self.beam_alpha = 0.5;
1304 self.beam_thickness = 14;
1305 self.beam_traileffect = FALSE;
1306 self.beam_hiteffect = particleeffectnum("electro_lightning");
1307 self.beam_hitlight[0] = 0;
1308 self.beam_hitlight[1] = 1;
1309 self.beam_hitlight[2] = 1;
1310 self.beam_hitlight[3] = 1;
1311 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1312 self.beam_muzzlelight[0] = 0;
1313 self.beam_muzzlelight[1] = 1;
1314 self.beam_muzzlelight[2] = 1;
1315 self.beam_muzzlelight[3] = 1;
1316 self.beam_image = "particles/lgbeam";
1317 setmodel(flash, "models/flash.md3");
1318 flash.alpha = self.beam_alpha;
1319 flash.colormod = self.beam_color;
1323 case ARC_BT_BURST_HIT:
1325 self.beam_color = '1 0 1';
1326 self.beam_alpha = 0.5;
1327 self.beam_thickness = 14;
1328 self.beam_traileffect = FALSE;
1329 self.beam_hiteffect = particleeffectnum("electro_lightning");
1330 self.beam_hitlight[0] = 0;
1331 self.beam_hitlight[1] = 1;
1332 self.beam_hitlight[2] = 1;
1333 self.beam_hitlight[3] = 1;
1334 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1335 self.beam_muzzlelight[0] = 0;
1336 self.beam_muzzlelight[1] = 1;
1337 self.beam_muzzlelight[2] = 1;
1338 self.beam_muzzlelight[3] = 1;
1339 self.beam_image = "particles/lgbeam";
1340 setmodel(flash, "models/flash.md3");
1341 flash.alpha = self.beam_alpha;
1342 flash.colormod = self.beam_color;
1347 // shouldn't be possible, but lets make it colorful if it does :D
1350 self.beam_color = randomvec();
1351 self.beam_alpha = 1;
1352 self.beam_thickness = 8;
1353 self.beam_traileffect = FALSE;
1354 self.beam_hiteffect = FALSE;
1355 self.beam_hitlight[0] = 0;
1356 self.beam_hitlight[1] = 1;
1357 self.beam_hitlight[2] = 1;
1358 self.beam_hitlight[3] = 1;
1359 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1360 self.beam_muzzlelight[0] = 0;
1361 self.beam_muzzlelight[1] = 1;
1362 self.beam_muzzlelight[2] = 1;
1363 self.beam_muzzlelight[3] = 1;
1364 self.beam_image = "particles/lgbeam";
1365 setmodel(flash, "models/flash.md3");
1366 flash.alpha = self.beam_alpha;
1367 flash.colormod = self.beam_color;
1374 if(!self.beam_usevieworigin)
1376 InterpolateOrigin_Note();
1380 float W_Arc(float req)
1384 case WR_IMPACTEFFECT:
1391 precache_sound("weapons/lgbeam_fly.wav");
1394 case WR_ZOOMRETICLE:
1396 // no weapon specific image for this weapon