5 /* ammotype */ ammo_cells,
7 /* flags */ WEP_FLAG_NORMAL,
8 /* rating */ BOT_PICKUP_RATING_HIGH,
10 /* modelname */ "hlac",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairhlac 0.7",
13 /* wepimg */ "weaponhlac",
15 /* wepname */ _("Arc")
18 #define ARC_SETTINGS(w_cvar,w_prop) ARC_SETTINGS_LIST(w_cvar, w_prop, ARC, arc)
19 #define ARC_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, NONE, beam_ammo) \
21 w_cvar(id, sn, NONE, beam_animtime) \
22 w_cvar(id, sn, NONE, beam_botaimspeed) \
23 w_cvar(id, sn, NONE, beam_botaimlifetime) \
24 w_cvar(id, sn, NONE, beam_damage) \
25 w_cvar(id, sn, NONE, beam_degreespersegment) \
26 w_cvar(id, sn, NONE, beam_distancepersegment) \
27 w_cvar(id, sn, NONE, beam_falloff_halflifedist) \
28 w_cvar(id, sn, NONE, beam_falloff_maxdist) \
29 w_cvar(id, sn, NONE, beam_falloff_mindist) \
30 w_cvar(id, sn, NONE, beam_force) \
31 w_cvar(id, sn, NONE, beam_healing_amax) \
32 w_cvar(id, sn, NONE, beam_healing_aps) \
33 w_cvar(id, sn, NONE, beam_healing_hmax) \
34 w_cvar(id, sn, NONE, beam_healing_hps) \
35 w_cvar(id, sn, NONE, beam_maxangle) \
36 w_cvar(id, sn, NONE, beam_nonplayerdamage) \
37 w_cvar(id, sn, NONE, beam_range) \
38 w_cvar(id, sn, NONE, beam_refire) \
39 w_cvar(id, sn, NONE, beam_returnspeed) \
40 w_cvar(id, sn, NONE, beam_tightness) \
41 w_cvar(id, sn, NONE, burst_ammo) \
42 w_cvar(id, sn, NONE, burst_damage) \
43 w_cvar(id, sn, NONE, burst_healing_aps) \
44 w_cvar(id, sn, NONE, burst_healing_hps) \
45 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
46 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
47 w_prop(id, sn, string, weaponreplace, weaponreplace) \
48 w_prop(id, sn, float, weaponstart, weaponstart) \
49 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
50 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
53 #define ARC_MAX_SEGMENTS 20
54 vector arc_shotorigin[4];
64 #define ARC_BT_BURST_MISS 10
65 #define ARC_BT_BURST_WALL 11
66 #define ARC_BT_BURST_HEAL 12
67 #define ARC_BT_BURST_HIT 13
68 #define ARC_BT_BURSTMASK 10
70 #define ARC_SF_SETTINGS 1
71 #define ARC_SF_START 2
72 #define ARC_SF_WANTDIR 4
73 #define ARC_SF_BEAMDIR 8
74 #define ARC_SF_BEAMTYPE 16
75 #define ARC_SF_LOCALMASK 14
78 ARC_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
80 .float BUTTON_ATCK_prev; // for better animation control
82 .float beam_initialized;
86 void Ent_ReadArcBeam(float isnew);
90 void spawnfunc_weapon_arc(void) { weapon_defaultspawnfunc(WEP_ARC); }
92 float W_Arc_Beam_Send(entity to, float sf)
94 WriteByte(MSG_ENTITY, ENT_CLIENT_ARC_BEAM);
96 // Truncate information when this beam is displayed to the owner client
97 // - The owner client has no use for beam start position or directions,
98 // it always figures this information out for itself with csqc code.
99 // - Spectating the owner also truncates this information.
100 float drawlocal = ((to == self.owner) || ((to.enemy == self.owner) && IS_SPEC(to)));
101 if(drawlocal) { sf &= ~ARC_SF_LOCALMASK; }
103 WriteByte(MSG_ENTITY, sf);
105 if(sf & ARC_SF_SETTINGS) // settings information
107 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_degreespersegment));
108 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_distancepersegment));
109 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_maxangle));
110 WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
111 WriteShort(MSG_ENTITY, WEP_CVAR(arc, beam_returnspeed));
112 WriteByte(MSG_ENTITY, WEP_CVAR(arc, beam_tightness) * 10);
114 WriteByte(MSG_ENTITY, drawlocal);
116 if(sf & ARC_SF_START) // starting location
118 WriteCoord(MSG_ENTITY, self.beam_start_x);
119 WriteCoord(MSG_ENTITY, self.beam_start_y);
120 WriteCoord(MSG_ENTITY, self.beam_start_z);
122 if(sf & ARC_SF_WANTDIR) // want/aim direction
124 WriteCoord(MSG_ENTITY, self.beam_wantdir_x);
125 WriteCoord(MSG_ENTITY, self.beam_wantdir_y);
126 WriteCoord(MSG_ENTITY, self.beam_wantdir_z);
128 if(sf & ARC_SF_BEAMDIR) // beam direction
130 WriteCoord(MSG_ENTITY, self.beam_dir_x);
131 WriteCoord(MSG_ENTITY, self.beam_dir_y);
132 WriteCoord(MSG_ENTITY, self.beam_dir_z);
134 if(sf & ARC_SF_BEAMTYPE) // beam type
136 WriteByte(MSG_ENTITY, self.beam_type);
142 void W_Arc_Beam_Think(void)
144 if(self != self.owner.arc_beam)
151 (self.owner.WEP_AMMO(ARC) <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
153 self.owner.deadflag != DEAD_NO
155 (!self.owner.BUTTON_ATCK && !self.beam_bursting)
157 self.owner.freezetag_frozen
161 // is this needed? I thought this is changed to world when removed ANYWAY
162 if(self == self.owner.arc_beam) { self.owner.arc_beam = world; }
164 entity oldself = self;
166 if(!WEP_ACTION(WEP_ARC, WR_CHECKAMMO1) && !WEP_ACTION(WEP_ARC, WR_CHECKAMMO2))
168 // note: this doesn't force the switch
169 W_SwitchToOtherWeapon(self);
177 if(self.owner.BUTTON_ATCK2 || self.beam_bursting)
179 if(!self.beam_bursting)
180 self.beam_bursting = TRUE;
181 burst = ARC_BT_BURSTMASK;
185 float coefficient = frametime;
186 if(!(self.owner.items & IT_UNLIMITED_WEAPON_AMMO))
190 { rootammo = WEP_CVAR(arc, burst_ammo); }
192 { rootammo = WEP_CVAR(arc, beam_ammo); }
196 coefficient = min(coefficient, self.owner.WEP_AMMO(ARC) / rootammo);
197 self.owner.WEP_AMMO(ARC) = max(0, self.owner.WEP_AMMO(ARC) - (rootammo * frametime));
201 makevectors(self.owner.v_angle);
209 WEP_CVAR(arc, beam_damage) * coefficient,
210 WEP_CVAR(arc, beam_range)
213 // network information: shot origin and want/aim direction
214 if(self.beam_start != w_shotorg)
216 self.SendFlags |= ARC_SF_START;
217 self.beam_start = w_shotorg;
219 if(self.beam_wantdir != w_shotdir)
221 self.SendFlags |= ARC_SF_WANTDIR;
222 self.beam_wantdir = w_shotdir;
225 if(!self.beam_initialized)
227 self.beam_dir = w_shotdir;
228 self.beam_initialized = TRUE;
231 // WEAPONTODO: Detect player velocity so that the beam curves when moving too
232 // idea: blend together self.beam_dir with the inverted direction the player is moving in
233 // might have to make some special accomodation so that it only uses view_right and view_up
235 // note that if we do this, it'll always be corrected to a maximum angle by beam_maxangle handling
238 if(self.beam_dir != w_shotdir)
240 // calculate how much we're going to move the end of the beam to the want position
241 // WEAPONTODO (server and client):
242 // blendfactor never actually becomes 0 in this situation, which is a problem
243 // regarding precision... this means that self.beam_dir and w_shotdir approach
244 // eachother, however they never actually become the same value with this method.
245 // Perhaps we should do some form of rounding/snapping?
246 float angle = vlen(w_shotdir - self.beam_dir) * RAD2DEG;
247 if(angle && (angle > WEP_CVAR(arc, beam_maxangle)))
249 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
250 float blendfactor = bound(
252 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
253 min(WEP_CVAR(arc, beam_maxangle) / angle, 1)
255 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
259 // the radius is not too far yet, no worries :D
260 float blendfactor = bound(
262 (1 - (WEP_CVAR(arc, beam_returnspeed) * frametime)),
265 self.beam_dir = normalize((w_shotdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
268 // network information: beam direction
269 self.SendFlags |= ARC_SF_BEAMDIR;
271 // calculate how many segments are needed
272 float max_allowed_segments;
274 if(WEP_CVAR(arc, beam_distancepersegment))
276 max_allowed_segments = min(
278 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment)))
281 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
283 if(WEP_CVAR(arc, beam_degreespersegment))
290 WEP_CVAR(arc, beam_maxangle)
293 WEP_CVAR(arc, beam_degreespersegment)
298 else { segments = 1; }
300 else { segments = 1; }
302 vector beam_endpos_estimate = (w_shotorg + (self.beam_dir * WEP_CVAR(arc, beam_range)));
305 float new_beam_type = 0;
306 vector last_origin = w_shotorg;
307 for(i = 1; i <= segments; ++i)
309 // WEAPONTODO (server and client):
310 // Segment blend and distance should probably really be calculated in a better way,
311 // however I am not sure how to do it properly. There are a few things I have tried,
312 // but most of them do not work properly due to my lack of understanding regarding
313 // the mathematics behind them.
315 // Ideally, we should calculate the positions along a perfect curve
316 // between wantdir and self.beam_dir with an option for depth of arc
318 // Another issue is that (on the client code) we must separate the
319 // curve into multiple rendered curves when handling warpzones.
321 // I can handle this by detecting it for each segment, however that
322 // is a fairly inefficient method in comparison to having a curved line
323 // drawing function similar to Draw_CylindricLine that accepts
324 // top and bottom origins as input, this way there would be no
325 // overlapping edges when connecting the curved pieces.
327 // WEAPONTODO (client):
328 // In order to do nice fading and pointing on the starting segment, we must always
329 // have that drawn as a separate triangle... However, that is difficult to do when
330 // keeping in mind the above problems and also optimizing the amount of segments
331 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
333 // calculate this on every segment to ensure that we always reach the full length of the attack
334 float segmentblend = bound(0, (i/segments) + WEP_CVAR(arc, beam_tightness), 1);
335 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
337 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
338 // Figure out how this actually should work.
339 vector new_dir = normalize(
340 (w_shotdir * (1 - segmentblend))
342 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
344 vector new_origin = last_origin + (new_dir * segmentdist);
346 WarpZone_traceline_antilag(
352 ANTILAG_LATENCY(self.owner)
356 trace_ent.classname == "player"
358 trace_ent.classname == "body"
360 (trace_ent.flags & FL_MONSTER)
363 if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage)))
365 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
366 vector hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
368 float falloff = ExponentialFalloff(
369 WEP_CVAR(arc, beam_falloff_mindist),
370 WEP_CVAR(arc, beam_falloff_maxdist),
371 WEP_CVAR(arc, beam_falloff_halflifedist),
372 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - w_shotorg)
375 if(is_player && SAME_TEAM(self.owner, trace_ent))
377 float roothealth, rootarmor;
380 roothealth = WEP_CVAR(arc, burst_healing_hps);
381 rootarmor = WEP_CVAR(arc, burst_healing_aps);
385 roothealth = WEP_CVAR(arc, beam_healing_hps);
386 rootarmor = WEP_CVAR(arc, beam_healing_aps);
389 if(trace_ent.health <= WEP_CVAR(arc, beam_healing_hmax) && roothealth)
391 trace_ent.health = min(
392 trace_ent.health + (roothealth * coefficient),
393 WEP_CVAR(arc, beam_healing_hmax)
396 if(trace_ent.armorvalue <= WEP_CVAR(arc, beam_healing_amax) && rootarmor)
398 trace_ent.armorvalue = min(
399 trace_ent.armorvalue + (rootarmor * coefficient),
400 WEP_CVAR(arc, beam_healing_amax)
404 // stop rot, set visual effect
405 if(roothealth || rootarmor)
407 trace_ent.pauserothealth_finished = max(
408 trace_ent.pauserothealth_finished,
409 time + autocvar_g_balance_pause_health_rot
411 trace_ent.pauserotarmor_finished = max(
412 trace_ent.pauserotarmor_finished,
413 time + autocvar_g_balance_pause_armor_rot
415 new_beam_type = ARC_BT_HEAL;
424 { rootdamage = WEP_CVAR(arc, burst_damage); }
426 { rootdamage = WEP_CVAR(arc, beam_damage); }
429 { rootdamage = WEP_CVAR(arc, beam_nonplayerdamage); }
431 if(accuracy_isgooddamage(self.owner, trace_ent))
437 rootdamage * coefficient * falloff
445 rootdamage * coefficient * falloff,
448 WEP_CVAR(arc, beam_force) * new_dir * coefficient * falloff
451 new_beam_type = ARC_BT_HIT;
455 else if(trace_fraction != 1)
457 // we collided with geometry
458 new_beam_type = ARC_BT_WALL;
463 last_origin = new_origin;
467 // if we're bursting, use burst visual effects
468 new_beam_type += burst;
470 // network information: beam type
471 if(new_beam_type != self.beam_type)
473 self.SendFlags |= ARC_SF_BEAMTYPE;
474 self.beam_type = new_beam_type;
477 self.owner.beam_prev = time;
478 self.nextthink = time;
481 void W_Arc_Beam(float burst)
483 // only play fire sound if 1 sec has passed since player let go the fire button
484 if(time - self.beam_prev > 1)
486 sound(self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
489 entity beam = self.arc_beam = spawn();
490 beam.classname = "W_Arc_Beam";
491 beam.solid = SOLID_NOT;
492 beam.think = W_Arc_Beam_Think;
494 beam.movetype = MOVETYPE_NONE;
495 beam.bot_dodge = TRUE;
496 beam.bot_dodgerating = WEP_CVAR(arc, beam_damage);
497 beam.beam_bursting = burst;
498 Net_LinkEntity(beam, FALSE, 0, W_Arc_Beam_Send);
500 entity oldself = self;
506 float W_Arc(float req)
512 if(WEP_CVAR(arc, beam_botaimspeed))
514 self.BUTTON_ATCK = bot_aim(
515 WEP_CVAR(arc, beam_botaimspeed),
517 WEP_CVAR(arc, beam_botaimlifetime),
523 self.BUTTON_ATCK = bot_aim(
535 if(self.arc_beam.beam_heat > threshold)
537 stop the beam somehow
538 play overheat animation
542 if(self.BUTTON_ATCK || self.BUTTON_ATCK2 || self.arc_beam.beam_bursting)
544 if(self.BUTTON_ATCK_prev)
547 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
548 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_arc_primary_animtime, w_ready);
551 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
554 if((!self.arc_beam) || wasfreed(self.arc_beam))
556 if(weapon_prepareattack(!!self.BUTTON_ATCK2, 0))
558 W_Arc_Beam(!!self.BUTTON_ATCK2);
560 if(!self.BUTTON_ATCK_prev)
562 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
563 self.BUTTON_ATCK_prev = 1;
570 if(self.BUTTON_ATCK_prev != 0)
572 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(arc, beam_animtime), w_ready);
573 ATTACK_FINISHED(self) = time + WEP_CVAR(arc, beam_refire) * W_WeaponRateFactor();
575 self.BUTTON_ATCK_prev = 0;
579 if(self.BUTTON_ATCK2)
580 if(weapon_prepareattack(1, autocvar_g_balance_arc_secondary_refire))
583 self.arc_count = autocvar_g_balance_arc_secondary_count;
584 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_arc_secondary_animtime, w_arc_checkattack);
585 self.arc_secondarytime = time + autocvar_g_balance_arc_secondary_refire2 * W_WeaponRateFactor();
593 precache_model("models/weapons/g_arc.md3");
594 precache_model("models/weapons/v_arc.md3");
595 precache_model("models/weapons/h_arc.iqm");
596 precache_sound("weapons/lgbeam_fire.wav");
597 if(!arc_shotorigin[0])
599 arc_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 1);
600 arc_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 2);
601 arc_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 3);
602 arc_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ARC), FALSE, FALSE, 4);
604 ARC_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
609 return ((!WEP_CVAR(arc, beam_ammo)) || (self.WEP_AMMO(ARC) > 0));
613 return ((!WEP_CVAR(arc, burst_ammo)) || (self.WEP_AMMO(ARC) > 0));
617 ARC_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
622 if(w_deathtype & HITTYPE_SECONDARY)
624 return WEAPON_ELECTRO_MURDER_ORBS;
628 if(w_deathtype & HITTYPE_BOUNCE)
629 return WEAPON_ELECTRO_MURDER_COMBO;
631 return WEAPON_ELECTRO_MURDER_BOLT;
642 .float beam_thickness;
643 .float beam_traileffect;
644 .float beam_hiteffect;
645 .float beam_hitlight[4]; // 0: radius, 123: rgb
646 .float beam_muzzleeffect;
647 .float beam_muzzlelight[4]; // 0: radius, 123: rgb
650 .entity beam_muzzleentity;
652 .float beam_degreespersegment;
653 .float beam_distancepersegment;
654 .float beam_usevieworigin;
655 .float beam_initialized;
656 .float beam_maxangle;
658 .float beam_returnspeed;
659 .float beam_tightness;
660 .vector beam_shotorigin;
663 entity Draw_ArcBeam_callback_entity;
664 vector Draw_ArcBeam_callback_new_dir;
665 float Draw_ArcBeam_callback_segmentdist;
666 float Draw_ArcBeam_callback_last_thickness;
667 vector Draw_ArcBeam_callback_last_top;
668 vector Draw_ArcBeam_callback_last_bottom;
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 vector thickdir = normalize(cross(normalize(start - hit), transformed_view_org - start));
682 if(trace_fraction != 1)
684 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
685 hitorigin = start + (Draw_ArcBeam_callback_new_dir * Draw_ArcBeam_callback_segmentdist * trace_fraction);
686 hitorigin = WarpZone_TransformOrigin(WarpZone_trace_transform, hitorigin);
696 // decide upon thickness
697 float thickness = beam.beam_thickness;
699 // draw primary beam render
700 vector top = hitorigin + (thickdir * thickness);
701 vector bottom = hitorigin - (thickdir * thickness);
702 //vector last_top = start + (thickdir * Draw_ArcBeam_callback_last_thickness);
703 //vector last_bottom = start - (thickdir * Draw_ArcBeam_callback_last_thickness);
705 R_BeginPolygon(beam.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
708 '0 0.5 0' + ('0 0.5 0' * (thickness / beam.beam_thickness)),
713 Draw_ArcBeam_callback_last_top,
714 '0 0.5 0' + ('0 0.5 0' * (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
719 Draw_ArcBeam_callback_last_bottom,
720 '0 0.5 0' * (1 - (Draw_ArcBeam_callback_last_thickness / beam.beam_thickness)),
726 '0 0.5 0' * (1 - (thickness / beam.beam_thickness)),
732 // draw trailing particles
734 // - Don't use spammy particle counts here, use a FEW small particles around the beam
735 // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
736 if(beam.beam_traileffect)
738 trailparticles(beam, beam.beam_traileffect, start, hitorigin);
741 // set up for the next
742 Draw_ArcBeam_callback_last_thickness = thickness;
743 Draw_ArcBeam_callback_last_top = top;
744 Draw_ArcBeam_callback_last_bottom = bottom;
747 void Draw_ArcBeam(void)
749 if(!self.beam_usevieworigin)
751 InterpolateOrigin_Do();
754 // origin = beam starting origin
755 // v_angle = wanted/aim direction
756 // angles = current direction of beam
759 vector wantdir; //= view_forward;
760 vector beamdir; //= self.beam_dir;
763 if(self.beam_usevieworigin)
766 // Currently we have to replicate nearly the same method of figuring
767 // out the shotdir that the server does... Ideally in the future we
768 // should be able to acquire this from a generalized function built
769 // into a weapon system for client code.
771 // find where we are aiming
772 makevectors(view_angles);
774 // decide upon start position
775 if(self.beam_usevieworigin == 2)
776 { start_pos = view_origin; }
778 { start_pos = self.origin; }
780 // trace forward with an estimation
783 start_pos + view_forward * self.beam_range,
788 // untransform in case our trace went through a warpzone
793 vector end_pos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos);
798 // un-adjust trueaim if shotend is too close
799 if(vlen(end_pos - view_origin) < g_trueaim_minrange)
800 end_pos = view_origin + (view_forward * g_trueaim_minrange);
802 // move shot origin to the actual gun muzzle origin
803 vector origin_offset =
804 view_forward * self.beam_shotorigin_x
805 + view_right * -self.beam_shotorigin_y
806 + view_up * self.beam_shotorigin_z;
808 start_pos = start_pos + origin_offset;
810 // calculate the aim direction now
811 wantdir = normalize(end_pos - start_pos);
813 if(!self.beam_initialized)
815 self.beam_dir = wantdir;
816 self.beam_initialized = TRUE;
819 if(self.beam_dir != wantdir)
821 // calculate how much we're going to move the end of the beam to the want position
822 // WEAPONTODO (server and client):
823 // blendfactor never actually becomes 0 in this situation, which is a problem
824 // regarding precision... this means that self.beam_dir and w_shotdir approach
825 // eachother, however they never actually become the same value with this method.
826 // Perhaps we should do some form of rounding/snapping?
827 float angle = vlen(wantdir - self.beam_dir) * RAD2DEG;
828 if(angle && (angle > self.beam_maxangle))
830 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
831 float blendfactor = bound(
833 (1 - (self.beam_returnspeed * frametime)),
834 min(self.beam_maxangle / angle, 1)
836 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
840 // the radius is not too far yet, no worries :D
841 float blendfactor = bound(
843 (1 - (self.beam_returnspeed * frametime)),
846 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
849 // calculate how many segments are needed
850 float max_allowed_segments;
852 if(self.beam_distancepersegment)
854 max_allowed_segments = min(
856 1 + (vlen(wantdir / self.beam_distancepersegment))
859 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
861 if(self.beam_degreespersegment)
871 self.beam_degreespersegment
876 else { segments = 1; }
878 else { segments = 1; }
880 // set the beam direction which the rest of the code will refer to
881 beamdir = self.beam_dir;
883 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
884 self.angles = fixedvectoangles2(view_forward, view_up);
888 // set the values from the provided info from the networked entity
889 start_pos = self.origin;
890 wantdir = self.v_angle;
891 beamdir = self.angles;
893 if(beamdir != wantdir)
895 float angle = vlen(wantdir - beamdir) * RAD2DEG;
897 // calculate how many segments are needed
898 float max_allowed_segments;
900 if(self.beam_distancepersegment)
902 max_allowed_segments = min(
904 1 + (vlen(wantdir / self.beam_distancepersegment))
907 else { max_allowed_segments = ARC_MAX_SEGMENTS; }
909 if(self.beam_degreespersegment)
919 self.beam_degreespersegment
924 else { segments = 1; }
926 else { segments = 1; }
929 setorigin(self, start_pos);
930 self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
932 vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
934 Draw_ArcBeam_callback_entity = self;
935 Draw_ArcBeam_callback_last_thickness = 0;
936 Draw_ArcBeam_callback_last_top = start_pos;
937 Draw_ArcBeam_callback_last_bottom = start_pos;
939 vector last_origin = start_pos;
942 for(i = 1; i <= segments; ++i)
944 // WEAPONTODO (server and client):
945 // Segment blend and distance should probably really be calculated in a better way,
946 // however I am not sure how to do it properly. There are a few things I have tried,
947 // but most of them do not work properly due to my lack of understanding regarding
948 // the mathematics behind them.
950 // Ideally, we should calculate the positions along a perfect curve
951 // between wantdir and self.beam_dir with an option for depth of arc
953 // Another issue is that (on the client code) we must separate the
954 // curve into multiple rendered curves when handling warpzones.
956 // I can handle this by detecting it for each segment, however that
957 // is a fairly inefficient method in comparison to having a curved line
958 // drawing function similar to Draw_CylindricLine that accepts
959 // top and bottom origins as input, this way there would be no
960 // overlapping edges when connecting the curved pieces.
962 // WEAPONTODO (client):
963 // In order to do nice fading and pointing on the starting segment, we must always
964 // have that drawn as a separate triangle... However, that is difficult to do when
965 // keeping in mind the above problems and also optimizing the amount of segments
966 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
968 // calculate this on every segment to ensure that we always reach the full length of the attack
969 float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
970 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
972 // WEAPONTODO: Apparently, normalize is not the correct function to use here...
973 // Figure out how this actually should work.
974 vector new_dir = normalize(
975 (wantdir * (1 - segmentblend))
977 (normalize(beam_endpos_estimate - last_origin) * segmentblend)
979 vector new_origin = last_origin + (new_dir * segmentdist);
981 Draw_ArcBeam_callback_segmentdist = segmentdist;
982 Draw_ArcBeam_callback_new_dir = new_dir;
984 WarpZone_TraceBox_ThroughZone(
992 Draw_ArcBeam_callback
995 //printf("segment: %d, warpzone transform: %d\n", i, (WarpZone_trace_transform != world));
998 // Figure out some way to detect a collision with geometry with callback...
999 // That way we can know when we are done drawing the beam and skip
1000 // the rest of the segments without breaking warpzone support.
1002 last_origin = WarpZone_TransformOrigin(WarpZone_trace_transform, new_origin);
1003 beam_endpos_estimate = WarpZone_TransformOrigin(WarpZone_trace_transform, beam_endpos_estimate);
1006 // startpoint and endpoint drawn visual effects
1007 if(self.beam_hiteffect)
1010 self.beam_hiteffect,
1016 if(self.beam_hitlight[0])
1020 self.beam_hitlight[0],
1022 self.beam_hitlight[1],
1023 self.beam_hitlight[2],
1024 self.beam_hitlight[3]
1028 if(self.beam_muzzleeffect)
1031 self.beam_muzzleeffect,
1032 start_pos + wantdir * 20,
1037 if(self.beam_muzzlelight[0])
1040 start_pos + wantdir * 20,
1041 self.beam_muzzlelight[0],
1043 self.beam_muzzlelight[1],
1044 self.beam_muzzlelight[2],
1045 self.beam_muzzlelight[3]
1051 Draw_ArcBeam_callback_entity = world;
1052 Draw_ArcBeam_callback_new_dir = '0 0 0';
1053 Draw_ArcBeam_callback_segmentdist = 0;
1054 Draw_ArcBeam_callback_last_thickness = 0;
1055 Draw_ArcBeam_callback_last_top = '0 0 0';
1056 Draw_ArcBeam_callback_last_bottom = '0 0 0';
1059 void Remove_ArcBeam(void)
1061 remove(self.beam_muzzleentity);
1062 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
1065 void Ent_ReadArcBeam(float isnew)
1067 float sf = ReadByte();
1072 // calculate shot origin offset from gun alignment
1073 float gunalign = autocvar_cl_gunalign;
1074 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
1075 gunalign = 3; // default value
1078 self.beam_shotorigin = arc_shotorigin[gunalign];
1080 // set other main attributes of the beam
1081 self.draw = Draw_ArcBeam;
1082 self.entremove = Remove_ArcBeam;
1083 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
1087 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
1088 flash.drawmask = MASK_NORMAL;
1089 flash.solid = SOLID_NOT;
1090 setattachment(flash, self, "");
1091 setorigin(flash, '0 0 0');
1093 self.beam_muzzleentity = flash;
1097 flash = self.beam_muzzleentity;
1100 if(sf & ARC_SF_SETTINGS) // settings information
1102 self.beam_degreespersegment = ReadShort();
1103 self.beam_distancepersegment = ReadShort();
1104 self.beam_maxangle = ReadShort();
1105 self.beam_range = ReadCoord();
1106 self.beam_returnspeed = ReadShort();
1107 self.beam_tightness = (ReadByte() / 10);
1111 if(autocvar_chase_active)
1112 { self.beam_usevieworigin = 1; }
1113 else // use view origin
1114 { self.beam_usevieworigin = 2; }
1118 self.beam_usevieworigin = 0;
1122 if(!self.beam_usevieworigin)
1124 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
1125 self.iflags = IFLAG_ORIGIN;
1127 InterpolateOrigin_Undo();
1130 if(sf & ARC_SF_START) // starting location
1132 self.origin_x = ReadCoord();
1133 self.origin_y = ReadCoord();
1134 self.origin_z = ReadCoord();
1136 else if(self.beam_usevieworigin) // infer the location from player location
1138 if(self.beam_usevieworigin == 2)
1141 self.origin = view_origin;
1145 // use player origin so that third person display still works
1146 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
1150 setorigin(self, self.origin);
1152 if(sf & ARC_SF_WANTDIR) // want/aim direction
1154 self.v_angle_x = ReadCoord();
1155 self.v_angle_y = ReadCoord();
1156 self.v_angle_z = ReadCoord();
1159 if(sf & ARC_SF_BEAMDIR) // beam direction
1161 self.angles_x = ReadCoord();
1162 self.angles_y = ReadCoord();
1163 self.angles_z = ReadCoord();
1166 if(sf & ARC_SF_BEAMTYPE) // beam type
1168 self.beam_type = ReadByte();
1169 switch(self.beam_type)
1173 self.beam_color = '-1 -1 1';
1174 self.beam_alpha = 0.5;
1175 self.beam_thickness = 8;
1176 self.beam_traileffect = FALSE;
1177 self.beam_hiteffect = particleeffectnum("electro_lightning");
1178 self.beam_hitlight[0] = 0;
1179 self.beam_hitlight[1] = 1;
1180 self.beam_hitlight[2] = 1;
1181 self.beam_hitlight[3] = 1;
1182 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1183 self.beam_muzzlelight[0] = 0;
1184 self.beam_muzzlelight[1] = 1;
1185 self.beam_muzzlelight[2] = 1;
1186 self.beam_muzzlelight[3] = 1;
1187 self.beam_image = "particles/lgbeam";
1188 setmodel(flash, "models/flash.md3");
1189 flash.alpha = self.beam_alpha;
1190 flash.colormod = self.beam_color;
1194 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
1196 self.beam_color = '0.5 0.5 1';
1197 self.beam_alpha = 0.5;
1198 self.beam_thickness = 8;
1199 self.beam_traileffect = FALSE;
1200 self.beam_hiteffect = particleeffectnum("electro_lightning");
1201 self.beam_hitlight[0] = 0;
1202 self.beam_hitlight[1] = 1;
1203 self.beam_hitlight[2] = 1;
1204 self.beam_hitlight[3] = 1;
1205 self.beam_muzzleeffect = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
1206 self.beam_muzzlelight[0] = 0;
1207 self.beam_muzzlelight[1] = 1;
1208 self.beam_muzzlelight[2] = 1;
1209 self.beam_muzzlelight[3] = 1;
1210 self.beam_image = "particles/lgbeam";
1211 setmodel(flash, "models/flash.md3");
1212 flash.alpha = self.beam_alpha;
1213 flash.colormod = self.beam_color;
1219 self.beam_color = '0 1 0';
1220 self.beam_alpha = 0.5;
1221 self.beam_thickness = 8;
1222 self.beam_traileffect = FALSE;
1223 self.beam_hiteffect = particleeffectnum("healray_impact");
1224 self.beam_hitlight[0] = 0;
1225 self.beam_hitlight[1] = 1;
1226 self.beam_hitlight[2] = 1;
1227 self.beam_hitlight[3] = 1;
1228 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1229 self.beam_muzzlelight[0] = 0;
1230 self.beam_muzzlelight[1] = 1;
1231 self.beam_muzzlelight[2] = 1;
1232 self.beam_muzzlelight[3] = 1;
1233 self.beam_image = "particles/lgbeam";
1234 setmodel(flash, "models/flash.md3");
1235 flash.alpha = self.beam_alpha;
1236 flash.colormod = self.beam_color;
1242 self.beam_color = '1 0 1';
1243 self.beam_alpha = 0.5;
1244 self.beam_thickness = 8;
1245 self.beam_traileffect = particleeffectnum("nex_beam");
1246 self.beam_hiteffect = particleeffectnum("electro_lightning");
1247 self.beam_hitlight[0] = 20;
1248 self.beam_hitlight[1] = 1;
1249 self.beam_hitlight[2] = 0;
1250 self.beam_hitlight[3] = 0;
1251 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1252 self.beam_muzzlelight[0] = 50;
1253 self.beam_muzzlelight[1] = 1;
1254 self.beam_muzzlelight[2] = 0;
1255 self.beam_muzzlelight[3] = 0;
1256 self.beam_image = "particles/lgbeam";
1257 setmodel(flash, "models/flash.md3");
1258 flash.alpha = self.beam_alpha;
1259 flash.colormod = self.beam_color;
1263 case ARC_BT_BURST_MISS:
1265 self.beam_color = '-1 -1 1';
1266 self.beam_alpha = 0.5;
1267 self.beam_thickness = 14;
1268 self.beam_traileffect = FALSE;
1269 self.beam_hiteffect = particleeffectnum("electro_lightning");
1270 self.beam_hitlight[0] = 0;
1271 self.beam_hitlight[1] = 1;
1272 self.beam_hitlight[2] = 1;
1273 self.beam_hitlight[3] = 1;
1274 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1275 self.beam_muzzlelight[0] = 0;
1276 self.beam_muzzlelight[1] = 1;
1277 self.beam_muzzlelight[2] = 1;
1278 self.beam_muzzlelight[3] = 1;
1279 self.beam_image = "particles/lgbeam";
1280 setmodel(flash, "models/flash.md3");
1281 flash.alpha = self.beam_alpha;
1282 flash.colormod = self.beam_color;
1286 case ARC_BT_BURST_WALL:
1288 self.beam_color = '0.5 0.5 1';
1289 self.beam_alpha = 0.5;
1290 self.beam_thickness = 14;
1291 self.beam_traileffect = FALSE;
1292 self.beam_hiteffect = particleeffectnum("electro_lightning");
1293 self.beam_hitlight[0] = 0;
1294 self.beam_hitlight[1] = 1;
1295 self.beam_hitlight[2] = 1;
1296 self.beam_hitlight[3] = 1;
1297 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1298 self.beam_muzzlelight[0] = 0;
1299 self.beam_muzzlelight[1] = 1;
1300 self.beam_muzzlelight[2] = 1;
1301 self.beam_muzzlelight[3] = 1;
1302 self.beam_image = "particles/lgbeam";
1303 setmodel(flash, "models/flash.md3");
1304 flash.alpha = self.beam_alpha;
1305 flash.colormod = self.beam_color;
1309 case ARC_BT_BURST_HEAL:
1311 self.beam_color = '0 1 0';
1312 self.beam_alpha = 0.5;
1313 self.beam_thickness = 14;
1314 self.beam_traileffect = FALSE;
1315 self.beam_hiteffect = particleeffectnum("electro_lightning");
1316 self.beam_hitlight[0] = 0;
1317 self.beam_hitlight[1] = 1;
1318 self.beam_hitlight[2] = 1;
1319 self.beam_hitlight[3] = 1;
1320 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1321 self.beam_muzzlelight[0] = 0;
1322 self.beam_muzzlelight[1] = 1;
1323 self.beam_muzzlelight[2] = 1;
1324 self.beam_muzzlelight[3] = 1;
1325 self.beam_image = "particles/lgbeam";
1326 setmodel(flash, "models/flash.md3");
1327 flash.alpha = self.beam_alpha;
1328 flash.colormod = self.beam_color;
1332 case ARC_BT_BURST_HIT:
1334 self.beam_color = '1 0 1';
1335 self.beam_alpha = 0.5;
1336 self.beam_thickness = 14;
1337 self.beam_traileffect = FALSE;
1338 self.beam_hiteffect = particleeffectnum("electro_lightning");
1339 self.beam_hitlight[0] = 0;
1340 self.beam_hitlight[1] = 1;
1341 self.beam_hitlight[2] = 1;
1342 self.beam_hitlight[3] = 1;
1343 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1344 self.beam_muzzlelight[0] = 0;
1345 self.beam_muzzlelight[1] = 1;
1346 self.beam_muzzlelight[2] = 1;
1347 self.beam_muzzlelight[3] = 1;
1348 self.beam_image = "particles/lgbeam";
1349 setmodel(flash, "models/flash.md3");
1350 flash.alpha = self.beam_alpha;
1351 flash.colormod = self.beam_color;
1356 // shouldn't be possible, but lets make it colorful if it does :D
1359 self.beam_color = randomvec();
1360 self.beam_alpha = 1;
1361 self.beam_thickness = 8;
1362 self.beam_traileffect = FALSE;
1363 self.beam_hiteffect = FALSE;
1364 self.beam_hitlight[0] = 0;
1365 self.beam_hitlight[1] = 1;
1366 self.beam_hitlight[2] = 1;
1367 self.beam_hitlight[3] = 1;
1368 self.beam_muzzleeffect = FALSE; //particleeffectnum("nex_muzzleflash");
1369 self.beam_muzzlelight[0] = 0;
1370 self.beam_muzzlelight[1] = 1;
1371 self.beam_muzzlelight[2] = 1;
1372 self.beam_muzzlelight[3] = 1;
1373 self.beam_image = "particles/lgbeam";
1374 setmodel(flash, "models/flash.md3");
1375 flash.alpha = self.beam_alpha;
1376 flash.colormod = self.beam_color;
1383 if(!self.beam_usevieworigin)
1385 InterpolateOrigin_Note();
1389 float W_Arc(float req)
1393 case WR_IMPACTEFFECT:
1400 //precache_sound("weapons/arc_impact.wav");
1401 //precache_sound("weapons/arc_impact_combo.wav");
1404 case WR_ZOOMRETICLE:
1406 // no weapon specific image for this weapon