5 /* ammotype */ ammo_cells,
7 /* flags */ WEP_FLAG_NORMAL,
8 /* rating */ BOT_PICKUP_RATING_HIGH,
10 /* modelname */ "arc",
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 !IS_PLAYER(self.owner)
190 (self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
192 self.owner.deadflag != DEAD_NO
194 (!self.owner.BUTTON_ATCK /* FIXME(Samual): && !self.beam_bursting */)
196 self.owner.freezetag_frozen
199 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
200 entity oldself = self;
202 if(!WEP_ACTION(WEP_ARC, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC, WR_CHECKAMMO2))
204 // note: this doesn't force the switch
205 W_SwitchToOtherWeapon(self);
213 if(/*self.owner.BUTTON_ATCK2 || */self.beam_bursting)
215 if(!self.beam_bursting)
216 self.beam_bursting = TRUE;
217 burst = ARC_BT_BURSTMASK;
221 float coefficient = frametime;
222 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
226 { rootammo = WEP_CVAR(arc, burst_ammo); }
228 { rootammo = WEP_CVAR(arc, beam_ammo); }
232 coefficient = min(coefficient, self.owner.WEP_AMMO(ARC) / rootammo);
233 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - (rootammo * frametime));
237 makevectors(self.owner.v_angle);
245 WEP_CVAR(arc, beam_damage) * coefficient,
246 WEP_CVAR(arc, beam_range)
249 // After teleport, "lock" the beam until the teleport is confirmed.
250 if (time < self.beam_teleporttime + ANTILAG_LATENCY(self.owner)) {
251 w_shotdir = self.beam_dir;
254 // network information: shot origin and want/aim direction
255 if(self.beam_start != w_shotorg)
257 self.SendFlags |= ARC_SF_START;
258 self.beam_start = w_shotorg;
260 if(self.beam_wantdir != w_shotdir)
262 self.SendFlags |= ARC_SF_WANTDIR;
263 self.beam_wantdir = w_shotdir;
266 if(!self.beam_initialized)
268 self.beam_dir = w_shotdir;
269 self.beam_initialized = TRUE;
272 // WEAPONTODO: Detect player velocity so that the beam curves when moving too
273 // idea: blend together self.beam_dir with the inverted direction the player is moving in
274 // might have to make some special accomodation so that it only uses view_right and view_up
276 // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
279 if(self.beam_dir != w_shotdir)
281 // calculate how much we're going to move the end of the beam to the want position
282 // WEAPONTODO (server and client):
283 // blendfactor never actually becomes 0 in this situation, which is a problem
284 // regarding precision... this means that self.beam_dir and w_shotdir approach
285 // eachother, however they never actually become the same value with this method.
286 // Perhaps we should do some form of rounding/snapping?
287 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
288 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
290 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
291 float blendfactor = bound(
293 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
294 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
296 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
300 // the radius is not too far yet, no worries :D
301 float blendfactor = bound(
303 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
306 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
309 // network information: beam direction
310 self.SendFlags |= ARC_SF_BEAMDIR;
312 // calculate how many segments are needed
313 float max_allowed_segments;
315 if(WEP_CVAR(arc, beam_distancepersegment))
317 max_allowed_segments = min(
319 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
322 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
324 if(WEP_CVAR(arc, beam_degreespersegment))
331 WEP_CVAR(arc, beam_maxangle)
334 WEP_CVAR(arc, beam_degreespersegment)
339 else { segments = 1; }
341 else { segments = 1; }
343 vector beam_endpos = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
344 vector beam_controlpoint = w_shotorg + w_shotdir * (WEP_CVAR(arc, beam_range) * (1 - WEP_CVAR(arc, beam_tightness)));
347 float new_beam_type = 0;
348 vector last_origin = w_shotorg;
349 for(i = 1; i <= segments; ++i)
351 // WEAPONTODO (client):
352 // In order to do nice fading and pointing on the starting segment, we must always
353 // have that drawn as a separate triangle... However, that is difficult to do when
354 // keeping in mind the above problems and also optimizing the amount of segments
355 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
357 vector new_origin = bezier_quadratic_getpoint(
362 vector new_dir = normalize(new_origin - last_origin);
364 WarpZone_traceline_antilag(
370 ANTILAG_LATENCY(self.owner)
373 // Do all the transforms for warpzones right now, as we already
374 // "are" in the post-trace system (if we hit a player, that's
375 // always BEHIND the last passed wz).
376 last_origin = trace_endpos;
377 w_shotorg = WarpZone_TransformOrigin(WarpZone_trace_transform, w_shotorg);
378 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
379 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
380 new_dir = WarpZone_TransformVelocity(WarpZone_trace_transform, new_dir);
383 trace_ent.classname == "player"
385 trace_ent.classname == "body"
387 (trace_ent.flags & FL_MONSTER)
390 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
392 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
393 // NO. trace_endpos should be just fine. If not,
394 // that's an engine bug that needs proper debugging.
395 vector hitorigin = trace_endpos;
397 float falloff = ExponentialFalloff(
398 WEP_CVAR(arc, beam_falloff_mindist),
399 WEP_CVAR(arc, beam_falloff_maxdist),
400 WEP_CVAR(arc, beam_falloff_halflifedist),
401 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
404 if(is_player && SAME_TEAM(self.owner, trace_ent))
406 float roothealth, rootarmor;
409 roothealth = WEP_CVAR(arc, burst_healing_hps);
410 rootarmor = WEP_CVAR(arc, burst_healing_aps);
414 roothealth = WEP_CVAR(arc, beam_healing_hps);
415 rootarmor = WEP_CVAR(arc, beam_healing_aps);
418 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
420 trace_ent.health = min(
421 trace_ent.health + (roothealth * coefficient),
422 WEP_CVAR(arc, beam_healing_hmax)
425 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
427 trace_ent.armorvalue = min(
428 trace_ent.armorvalue + (rootarmor * coefficient),
429 WEP_CVAR(arc, beam_healing_amax)
433 // stop rot, set visual effect
434 if(roothealth || rootarmor)
436 trace_ent.pauserothealth_finished = max(
437 trace_ent.pauserothealth_finished,
438 time + autocvar_g_balance_pause_health_rot
440 trace_ent.pauserotarmor_finished = max(
441 trace_ent.pauserotarmor_finished,
442 time + autocvar_g_balance_pause_armor_rot
444 new_beam_type = ARC_BT_HEAL;
453 { rootdamage = WEP_CVAR(arc, burst_damage); }
455 { rootdamage = WEP_CVAR(arc, beam_damage); }
458 { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
460 if(accuracy_isgooddamage(self.owner, trace_ent))
466 rootdamage * coefficient * falloff
474 rootdamage * coefficient * falloff,
477 WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
480 new_beam_type = ARC_BT_HIT;
484 else if(trace_fraction != 1)
486 // we collided with geometry
487 new_beam_type = ARC_BT_WALL;
492 // te_explosion(trace_endpos);
494 // if we're bursting, use burst visual effects
495 new_beam_type += burst;
497 // network information: beam type
498 if(new_beam_type != self.beam_type)
500 self.SendFlags |= ARC_SF_BEAMTYPE;
501 self.beam_type = new_beam_type;
504 self.owner.beam_prev = time;
505 self.nextthink = time;
508 void W_Arc_Beam(float burst)
510 // FIXME(Samual): remove this when overheat and burst work.
513 centerprint(self, "^4NOTE:^7 Arc burst (secondary) is not implemented yet.");
516 // only play fire sound if 1 sec has passed since player let go the fire button
517 if(time - self.beam_prev > 1)
519 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
522 entity beam = self.arc_beam = spawn();
523 beam.classname = "W_Arc_Beam";
524 beam.solid = SOLID_NOT;
525 beam.think = W_Arc_Beam_Think;
527 beam.movetype = MOVETYPE_NONE;
528 beam.bot_dodge = TRUE;
529 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
530 beam.beam_bursting = burst;
531 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
533 entity oldself = self;
539 float W_Arc(float req)
545 if(WEP_CVAR(arc, beam_botaimspeed))
547 self.BUTTON_ATCK = bot_aim(
548 WEP_CVAR(arc, beam_botaimspeed),
550 WEP_CVAR(arc, beam_botaimlifetime),
556 self.BUTTON_ATCK = bot_aim(
568 if(self.arc_beam.beam_heat > threshold)
570 stop the beam somehow
571 play overheat animation
575 if(self.BUTTON_ATCK || self.BUTTON_ATCK2 /* FIXME(Samual): || self.arc_beam.beam_bursting */)
577 if(self.BUTTON_ATCK_prev)
580 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
581 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
584 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
587 if((!self.arc_beam) || wasfreed(self.arc_beam))
589 if(weapon_prepareattack(!!self.BUTTON_ATCK2, 0))
591 W_Arc_Beam(!!self.BUTTON_ATCK2);
593 if(!self.BUTTON_ATCK_prev)
595 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
596 self.BUTTON_ATCK_prev = 1;
603 if(self.BUTTON_ATCK_prev != 0)
605 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
606 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
608 self.BUTTON_ATCK_prev = 0;
612 if(self.BUTTON_ATCK2)
613 if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
616 self.arc_count = autocvar_g_balance_arc_secondary_count;
617 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
618 self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
626 precache_model("models/weapons/g_arc.md3");
627 precache_model("models/weapons/v_arc.md3");
628 precache_model("models/weapons/h_arc.iqm");
629 precache_sound("weapons/lgbeam_fire.wav");
630 if(!arc_shotorigin[0])
632 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
633 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
634 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
635 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
637 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
642 return ((!WEP_CVAR(arc, beam_ammo)) || (self.WEP_AMMO(ARC) > 0));
646 // arc currently has no secondary attack
648 //return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
652 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
657 return WEAPON_ARC_MURDER;
664 void Draw_ArcBeam_callback(vector start, vector hit, vector end)
666 entity beam = Draw_ArcBeam_callback_entity;
667 vector transformed_view_org;
668 transformed_view_org = WarpZone_TransformOrigin(WarpZone_trace_transform, view_origin);
670 // Thickdir shall be perpendicular to the beam and to the view-to-beam direction (WEAPONTODO: WHY)
671 // WEAPONTODO: Wouldn't it be better to be perpendicular to the beam and to the view FORWARD direction?
672 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
678 if(trace_fraction != 1)
680 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
681 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
682 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
692 // decide upon thickness
693 float thickness = beam.beam_thickness;
695 // draw primary beam render
696 vector top = hitorigin + (thickdir * thickness);
697 vector bottom = hitorigin - (thickdir * thickness);
699 vector last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
700 vector last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
702 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
705 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
711 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
717 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
723 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
729 // draw trailing particles
731 // - Don't use spammy particle counts here, use a FEW small particles around the beam
732 // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
733 if(beam.beam_traileffect)
735 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
738 // set up for the next
739 Draw_ArcBeam_callback_last_thickness = thickness;
740 Draw_ArcBeam_callback_last_top = WarpZone_UnTransformOrigin(WarpZone_trace_transform, top);
741 Draw_ArcBeam_callback_last_bottom = WarpZone_UnTransformOrigin(WarpZone_trace_transform, bottom);
744 void Reset_ArcBeam(void)
747 for (e = world; (e = findfloat(e, beam_usevieworigin, 1)); ) {
748 e.beam_initialized = FALSE;
750 for (e = world; (e = findfloat(e, beam_usevieworigin, 2)); ) {
751 e.beam_initialized = FALSE;
755 void Draw_ArcBeam(void)
757 if(!self.beam_usevieworigin)
759 InterpolateOrigin_Do();
762 // origin = beam starting origin
763 // v_angle = wanted/aim direction
764 // angles = current direction of beam
767 vector wantdir; //= view_forward;
768 vector beamdir; //= self.beam_dir;
771 if(self.beam_usevieworigin)
774 // Currently we have to replicate nearly the same method of figuring
775 // out the shotdir that the server does... Ideally in the future we
776 // should be able to acquire this from a generalized function built
777 // into a weapon system for client code.
779 // find where we are aiming
780 makevectors(warpzone_save_view_angles);
781 vector forward = v_forward;
782 vector right = v_right;
785 // decide upon start position
786 if(self.beam_usevieworigin == 2)
787 { start_pos = warpzone_save_view_origin; }
789 { start_pos = self.origin; }
791 // trace forward with an estimation
794 start_pos + forward * self.beam_range,
799 // untransform in case our trace went through a warpzone
800 vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
802 // un-adjust trueaim if shotend is too close
803 if(vlen(end_pos - start_pos) < g_trueaim_minrange)
804 end_pos = start_pos + (forward * g_trueaim_minrange);
806 // move shot origin to the actual gun muzzle origin
807 vector origin_offset =
808 right * -self.beam_shotorigin_y
809 + up * self.beam_shotorigin_z;
811 start_pos = start_pos + origin_offset;
813 // Move it also forward, but only as far as possible without hitting anything. Don't poke into walls!
814 traceline(start_pos, start_pos + forward * self.beam_shotorigin_x, MOVE_NORMAL, self);
815 start_pos = trace_endpos;
817 // calculate the aim direction now
818 wantdir = normalize(end_pos - start_pos);
820 if(!self.beam_initialized)
822 self.beam_dir = wantdir;
823 self.beam_initialized = TRUE;
826 if(self.beam_dir != wantdir)
828 // calculate how much we're going to move the end of the beam to the want position
829 // WEAPONTODO (server and client):
830 // blendfactor never actually becomes 0 in this situation, which is a problem
831 // regarding precision... this means that self.beam_dir and w_shotdir approach
832 // eachother, however they never actually become the same value with this method.
833 // Perhaps we should do some form of rounding/snapping?
834 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
835 if(angle && (angle > self.beam_maxangle))
837 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
838 float blendfactor = bound(
840 (1 - (self.beam_returnspeed * frametime)),
841 min(self.beam_maxangle / angle, 1)
843 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
847 // the radius is not too far yet, no worries :D
848 float blendfactor = bound(
850 (1 - (self.beam_returnspeed * frametime)),
853 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
856 // calculate how many segments are needed
857 float max_allowed_segments;
859 if(self.beam_distancepersegment)
861 max_allowed_segments = min(
863 1 + (vlen(wantdir / self.beam_distancepersegment))
866 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
868 if(self.beam_degreespersegment)
878 self.beam_degreespersegment
883 else { segments = 1; }
885 else { segments = 1; }
887 // set the beam direction which the rest of the code will refer to
888 beamdir = self.beam_dir;
890 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
891 self.angles = fixedvectoangles2(forward, up); // TODO(Samual): is this == warpzone_save_view_angles?
895 // set the values from the provided info from the networked entity
896 start_pos = self.origin;
897 wantdir = self.v_angle;
898 beamdir = self.angles;
900 if(beamdir != wantdir)
902 float angle = vlen(wantdir - beamdir) * RAD2DEG;
904 // calculate how many segments are needed
905 float max_allowed_segments;
907 if(self.beam_distancepersegment)
909 max_allowed_segments = min(
911 1 + (vlen(wantdir / self.beam_distancepersegment))
914 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
916 if(self.beam_degreespersegment)
926 self.beam_degreespersegment
931 else { segments = 1; }
933 else { segments = 1; }
936 setorigin(self, start_pos);
937 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
939 vector beam_endpos = (start_pos + (beamdir * self.beam_range));
940 vector beam_controlpoint = start_pos + wantdir * (self.beam_range * (1 - self.beam_tightness));
942 Draw_ArcBeam_callback_entity = self;
943 Draw_ArcBeam_callback_last_thickness = 0;
944 Draw_ArcBeam_callback_last_top = start_pos;
945 Draw_ArcBeam_callback_last_bottom = start_pos;
947 vector last_origin = start_pos;
948 vector original_start_pos = start_pos;
951 for(i = 1; i <= segments; ++i)
953 // WEAPONTODO (client):
954 // In order to do nice fading and pointing on the starting segment, we must always
955 // have that drawn as a separate triangle... However, that is difficult to do when
956 // keeping in mind the above problems and also optimizing the amount of segments
957 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
959 vector new_origin = bezier_quadratic_getpoint(
965 WarpZone_TraceBox_ThroughZone(
973 Draw_ArcBeam_callback
976 // Do all the transforms for warpzones right now, as we already "are" in the post-trace
977 // system (if we hit a player, that's always BEHIND the last passed wz).
978 last_origin = trace_endpos;
979 start_pos = WarpZone_TransformOrigin(WarpZone_trace_transform, start_pos);
980 beam_controlpoint = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_controlpoint);
981 beam_endpos = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos);
982 beamdir = WarpZone_TransformVelocity(WarpZone_trace_transform, beamdir);
983 Draw_ArcBeam_callback_last_top = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_top);
984 Draw_ArcBeam_callback_last_bottom = WarpZone_TransformOrigin(WarpZone_trace_transform, Draw_ArcBeam_callback_last_bottom);
986 if(trace_fraction < 1) { break; }
989 // visual effects for startpoint and endpoint
990 if(self.beam_hiteffect)
992 // FIXME we really should do this on the server so it actually
993 // matches gameplay. What this client side stuff is doing is no
994 // more than guesswork.
1002 if(self.beam_hitlight[0])
1006 self.beam_hitlight[0],
1008 self.beam_hitlight[1],
1009 self.beam_hitlight[2],
1010 self.beam_hitlight[3]
1014 if(self.beam_muzzleeffect)
1017 self.beam_muzzleeffect,
1018 original_start_pos + wantdir * 20,
1023 if(self.beam_muzzlelight[0])
1026 original_start_pos + wantdir * 20,
1027 self.beam_muzzlelight[0],
1029 self.beam_muzzlelight[1],
1030 self.beam_muzzlelight[2],
1031 self.beam_muzzlelight[3]
1037 Draw_ArcBeam_callback_entity = world;
1038 Draw_ArcBeam_callback_last_thickness = 0;
1039 Draw_ArcBeam_callback_last_top = '0 0 0';
1040 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1043 void Remove_ArcBeam(void)
1045 remove(self.beam_muzzleentity);
1046 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1049 void Ent_ReadArcBeam(float isnew)
1051 float sf = ReadByte();
1056 // calculate shot origin offset from gun alignment
1057 float gunalign = autocvar_cl_gunalign;
1058 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1059 gunalign = 3; // default value
1062 self.beam_shotorigin = arc_shotorigin[gunalign];
1064 // set other main attributes of the beam
1065 self.draw = Draw_ArcBeam;
1066 self.entremove = Remove_ArcBeam;
1067 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1071 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1072 flash.drawmask = MASK_NORMAL;
1073 flash.solid = SOLID_NOT;
1074 flash.avelocity_z = 5000;
1075 setattachment(flash, self, "");
1076 setorigin(flash, '0 0 0');
1078 self.beam_muzzleentity = flash;
1082 flash = self.beam_muzzleentity;
1085 if(sf & ARC_SF_SETTINGS) // settings information
1087 self.beam_degreespersegment = ReadShort();
1088 self.beam_distancepersegment = ReadShort();
1089 self.beam_maxangle = ReadShort();
1090 self.beam_range = ReadCoord();
1091 self.beam_returnspeed = ReadShort();
1092 self.beam_tightness = (ReadByte() / 10);
1096 if(autocvar_chase_active)
1097 { self.beam_usevieworigin = 1; }
1098 else // use view origin
1099 { self.beam_usevieworigin = 2; }
1103 self.beam_usevieworigin = 0;
1107 if(!self.beam_usevieworigin)
1109 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1110 self.iflags = IFLAG_ORIGIN;
1112 InterpolateOrigin_Undo();
1115 if(sf & ARC_SF_START) // starting location
1117 self.origin_x = ReadCoord();
1118 self.origin_y = ReadCoord();
1119 self.origin_z = ReadCoord();
1121 else if(self.beam_usevieworigin) // infer the location from player location
1123 if(self.beam_usevieworigin == 2)
1126 self.origin = view_origin;
1130 // use player origin so that third person display still works
1131 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1135 setorigin(self, self.origin);
1137 if(sf & ARC_SF_WANTDIR) // want/aim direction
1139 self.v_angle_x = ReadCoord();
1140 self.v_angle_y = ReadCoord();
1141 self.v_angle_z = ReadCoord();
1144 if(sf & ARC_SF_BEAMDIR) // beam direction
1146 self.angles_x = ReadCoord();
1147 self.angles_y = ReadCoord();
1148 self.angles_z = ReadCoord();
1151 if(sf & ARC_SF_BEAMTYPE) // beam type
1153 self.beam_type = ReadByte();
1154 switch(self.beam_type)
1158 self.beam_color = '-1 -1 1';
1159 self.beam_alpha = 0.5;
1160 self.beam_thickness = 8;
1161 self.beam_traileffect = FALSE;
1162 self.beam_hiteffect = particleeffectnum("electro_lightning");
1163 self.beam_hitlight[0] = 0;
1164 self.beam_hitlight[1] = 1;
1165 self.beam_hitlight[2] = 1;
1166 self.beam_hitlight[3] = 1;
1167 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1168 self.beam_muzzlelight[0] = 0;
1169 self.beam_muzzlelight[1] = 1;
1170 self.beam_muzzlelight[2] = 1;
1171 self.beam_muzzlelight[3] = 1;
1172 if(self.beam_muzzleeffect >= 0)
1174 self.beam_image = "particles/lgbeam";
1175 setmodel(flash, "models/flash.md3");
1176 flash.alpha = self.beam_alpha;
1177 flash.colormod = self.beam_color;
1182 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1184 self.beam_color = '0.5 0.5 1';
1185 self.beam_alpha = 0.5;
1186 self.beam_thickness = 8;
1187 self.beam_traileffect = FALSE;
1188 self.beam_hiteffect = particleeffectnum("electro_lightning");
1189 self.beam_hitlight[0] = 0;
1190 self.beam_hitlight[1] = 1;
1191 self.beam_hitlight[2] = 1;
1192 self.beam_hitlight[3] = 1;
1193 self.beam_muzzleeffect = -1; // particleeffectnum("grenadelauncher_muzzleflash");
1194 self.beam_muzzlelight[0] = 0;
1195 self.beam_muzzlelight[1] = 1;
1196 self.beam_muzzlelight[2] = 1;
1197 self.beam_muzzlelight[3] = 1;
1198 self.beam_image = "particles/lgbeam";
1199 if(self.beam_muzzleeffect >= 0)
1201 setmodel(flash, "models/flash.md3");
1202 flash.alpha = self.beam_alpha;
1203 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 = -1; //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 if(self.beam_muzzleeffect >= 0)
1227 self.beam_image = "particles/lgbeam";
1228 setmodel(flash, "models/flash.md3");
1229 flash.alpha = self.beam_alpha;
1230 flash.colormod = self.beam_color;
1237 self.beam_color = '1 0 1';
1238 self.beam_alpha = 0.5;
1239 self.beam_thickness = 8;
1240 self.beam_traileffect = FALSE;
1241 self.beam_hiteffect = particleeffectnum("electro_lightning");
1242 self.beam_hitlight[0] = 20;
1243 self.beam_hitlight[1] = 1;
1244 self.beam_hitlight[2] = 0;
1245 self.beam_hitlight[3] = 0;
1246 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1247 self.beam_muzzlelight[0] = 50;
1248 self.beam_muzzlelight[1] = 1;
1249 self.beam_muzzlelight[2] = 0;
1250 self.beam_muzzlelight[3] = 0;
1251 self.beam_image = "particles/lgbeam";
1252 if(self.beam_muzzleeffect >= 0)
1254 self.beam_image = "particles/lgbeam";
1255 setmodel(flash, "models/flash.md3");
1256 flash.alpha = self.beam_alpha;
1257 flash.colormod = self.beam_color;
1262 case ARC_BT_BURST_MISS:
1264 self.beam_color = '-1 -1 1';
1265 self.beam_alpha = 0.5;
1266 self.beam_thickness = 14;
1267 self.beam_traileffect = FALSE;
1268 self.beam_hiteffect = particleeffectnum("electro_lightning");
1269 self.beam_hitlight[0] = 0;
1270 self.beam_hitlight[1] = 1;
1271 self.beam_hitlight[2] = 1;
1272 self.beam_hitlight[3] = 1;
1273 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1274 self.beam_muzzlelight[0] = 0;
1275 self.beam_muzzlelight[1] = 1;
1276 self.beam_muzzlelight[2] = 1;
1277 self.beam_muzzlelight[3] = 1;
1278 self.beam_image = "particles/lgbeam";
1279 setmodel(flash, "models/flash.md3");
1280 flash.alpha = self.beam_alpha;
1281 flash.colormod = self.beam_color;
1285 case ARC_BT_BURST_WALL:
1287 self.beam_color = '0.5 0.5 1';
1288 self.beam_alpha = 0.5;
1289 self.beam_thickness = 14;
1290 self.beam_traileffect = FALSE;
1291 self.beam_hiteffect = particleeffectnum("electro_lightning");
1292 self.beam_hitlight[0] = 0;
1293 self.beam_hitlight[1] = 1;
1294 self.beam_hitlight[2] = 1;
1295 self.beam_hitlight[3] = 1;
1296 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1297 self.beam_muzzlelight[0] = 0;
1298 self.beam_muzzlelight[1] = 1;
1299 self.beam_muzzlelight[2] = 1;
1300 self.beam_muzzlelight[3] = 1;
1301 self.beam_image = "particles/lgbeam";
1302 if(self.beam_muzzleeffect >= 0)
1304 self.beam_image = "particles/lgbeam";
1305 setmodel(flash, "models/flash.md3");
1306 flash.alpha = self.beam_alpha;
1307 flash.colormod = self.beam_color;
1312 case ARC_BT_BURST_HEAL:
1314 self.beam_color = '0 1 0';
1315 self.beam_alpha = 0.5;
1316 self.beam_thickness = 14;
1317 self.beam_traileffect = FALSE;
1318 self.beam_hiteffect = particleeffectnum("electro_lightning");
1319 self.beam_hitlight[0] = 0;
1320 self.beam_hitlight[1] = 1;
1321 self.beam_hitlight[2] = 1;
1322 self.beam_hitlight[3] = 1;
1323 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1324 self.beam_muzzlelight[0] = 0;
1325 self.beam_muzzlelight[1] = 1;
1326 self.beam_muzzlelight[2] = 1;
1327 self.beam_muzzlelight[3] = 1;
1328 self.beam_image = "particles/lgbeam";
1329 if(self.beam_muzzleeffect >= 0)
1331 self.beam_image = "particles/lgbeam";
1332 setmodel(flash, "models/flash.md3");
1333 flash.alpha = self.beam_alpha;
1334 flash.colormod = self.beam_color;
1339 case ARC_BT_BURST_HIT:
1341 self.beam_color = '1 0 1';
1342 self.beam_alpha = 0.5;
1343 self.beam_thickness = 14;
1344 self.beam_traileffect = FALSE;
1345 self.beam_hiteffect = particleeffectnum("electro_lightning");
1346 self.beam_hitlight[0] = 0;
1347 self.beam_hitlight[1] = 1;
1348 self.beam_hitlight[2] = 1;
1349 self.beam_hitlight[3] = 1;
1350 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1351 self.beam_muzzlelight[0] = 0;
1352 self.beam_muzzlelight[1] = 1;
1353 self.beam_muzzlelight[2] = 1;
1354 self.beam_muzzlelight[3] = 1;
1355 self.beam_image = "particles/lgbeam";
1356 if(self.beam_muzzleeffect >= 0)
1358 self.beam_image = "particles/lgbeam";
1359 setmodel(flash, "models/flash.md3");
1360 flash.alpha = self.beam_alpha;
1361 flash.colormod = self.beam_color;
1367 // shouldn't be possible, but lets make it colorful if it does :D
1370 self.beam_color = randomvec();
1371 self.beam_alpha = 1;
1372 self.beam_thickness = 8;
1373 self.beam_traileffect = FALSE;
1374 self.beam_hiteffect = FALSE;
1375 self.beam_hitlight[0] = 0;
1376 self.beam_hitlight[1] = 1;
1377 self.beam_hitlight[2] = 1;
1378 self.beam_hitlight[3] = 1;
1379 self.beam_muzzleeffect = -1; //particleeffectnum("nex_muzzleflash");
1380 self.beam_muzzlelight[0] = 0;
1381 self.beam_muzzlelight[1] = 1;
1382 self.beam_muzzlelight[2] = 1;
1383 self.beam_muzzlelight[3] = 1;
1384 self.beam_image = "particles/lgbeam";
1385 if(self.beam_muzzleeffect >= 0)
1387 self.beam_image = "particles/lgbeam";
1388 setmodel(flash, "models/flash.md3");
1389 flash.alpha = self.beam_alpha;
1390 flash.colormod = self.beam_color;
1398 if(!self.beam_usevieworigin)
1400 InterpolateOrigin_Note();
1404 float W_Arc(float req)
1408 case WR_IMPACTEFFECT:
1415 precache_sound("weapons/lgbeam_fly.wav");
1418 case WR_ZOOMRETICLE:
1420 // no weapon specific image for this weapon