.float beam_traileffect;
.float beam_hiteffect;
.float beam_muzzleflash;
-//.string beam_muzzlemodel;
-//.vector beam_muzzlecolor; // todo: should we just use beam_color?
.string beam_image;
+// WEAPONTODO: Add beam_hitlight and beam_muzzlelight which uses direct real time light control
+
+.entity beam_muzzleentity;
+
.float beam_usevieworigin;
.float beam_initialized;
.float beam_maxangle;
.float beam_range;
.float beam_returnspeed;
+.float beam_tightness;
.vector beam_shotorigin;
.vector beam_dir;
void Draw_ArcBeam()
vector wantdir; //= view_forward;
vector beamdir; //= self.beam_dir;
+ float segments;
if(self.beam_usevieworigin)
{
+ // WEAPONTODO:
+ // Currently we have to replicate nearly the same method of figuring
+ // out the shotdir that the server does... Ideally in the future we
+ // should be able to acquire this from a generalized function built
+ // into a weapon system for client code.
+
// find where we are aiming
makevectors(view_angles);
self.beam_initialized = TRUE;
}
+ // WEAPONTODO: Calculate segments dyanmically similarly to the server code
+ segments = 20;
if(self.beam_dir != wantdir)
{
float angle = ceil(vlen(wantdir - self.beam_dir) * RAD2DEG);
// calculate how much we're going to move the end of the beam to the want position
float blendfactor = bound(0, anglelimit * (1 - (self.beam_returnspeed * frametime)), 1);
self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
+
+ // WEAPONTODO (server and client):
+ // blendfactor never actually becomes 0 in this situation, which is a problem
+ // regarding precision... this means that self.beam_dir and w_shotdir approach
+ // eachother, however they never actually become the same value with this method.
+
+ // Perhaps we should do some form of rounding/snapping?
+
+ // printf("blendfactor = %f\n", blendfactor);
+
+ #if 0
+ // calculate how many segments are needed
+ float max_allowed_segments;
+
+ if(WEP_CVAR(arc, beam_distancepersegment))
+ max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
+ else
+ max_allowed_segments = ARC_MAX_SEGMENTS;
+
+ if(WEP_CVAR(arc, beam_degreespersegment))
+ {
+ segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
+ }
+ else
+ {
+ segments = 1;
+ }
+ #endif
+ }
+ #if 0
+ else
+ {
+ segments = 1;
}
+ #endif
- // finally, set the beam direction which the rest of the code will refer to
+ // set the beam direction which the rest of the code will refer to
beamdir = self.beam_dir;
+
+ // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
+ self.angles = fixedvectoangles2(view_forward, view_up);
}
else
{
start_pos = self.origin;
wantdir = self.v_angle;
beamdir = self.angles;
+
+ // WEAPONTODO: Calculate segments dyanmically similarly to the server code
+ segments = 20;
+ #if 0
+ if(beamdir != wantdir)
+ {
+ // calculate how many segments are needed
+ float max_allowed_segments;
+
+ if(WEP_CVAR(arc, beam_distancepersegment))
+ max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
+ else
+ max_allowed_segments = ARC_MAX_SEGMENTS;
+
+ if(WEP_CVAR(arc, beam_degreespersegment))
+ {
+ segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
+ }
+ else
+ {
+ segments = 1;
+ }
+ }
+ else
+ {
+ segments = 1;
+ }
+ #endif
}
setorigin(self, start_pos);
+ self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
- float segments = 20; // todo: calculate this in a similar way to server does
float maxthickness = self.beam_thickness;
vector thickdir = normalize(cross(beamdir, view_origin - start_pos));
vector hitorigin = start_pos;
- /*
- _len = vlen(self.origin - self.move_origin);
- _dir = normalize(self.move_origin - self.origin);
-
- if(self.total_damages < time)
- {
- boxparticles(self.traileffect, self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA);
- boxparticles(self.lip, self, self.move_origin, self.move_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA);
- self.total_damages = time + 0.1;
- }
- */
-
-
float i;
for(i = 1; i <= segments; ++i)
{
+ // WEAPONTODO (server and client):
+ // Segment blend and distance should probably really be calculated in a better way,
+ // however I am not sure how to do it properly. There are a few things I have tried,
+ // but most of them do not work properly due to my lack of understanding regarding
+ // the mathematics behind them.
+
+ // Ideally, we should calculate the positions along a perfect curve
+ // between wantdir and self.beam_dir with an option for depth of arc
+
+ // Another issue is that (on the client code) we must separate the
+ // curve into multiple rendered curves when handling warpzones.
+
+ // I can handle this by detecting it for each segment, however that
+ // is a fairly inefficient method in comparison to having a curved line
+ // drawing function similar to Draw_CylindricLine that accepts
+ // top and bottom origins as input, this way there would be no
+ // overlapping edges when connecting the curved pieces.
+
+ // WEAPONTODO (client):
+ // In order to do nice fading and pointing on the starting segment, we must always
+ // have that drawn as a separate triangle... However, that is difficult to do when
+ // keeping in mind the above problems and also optimizing the amount of segments
+ // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
+
// calculate this on every segment to ensure that we always reach the full length of the attack
- float segmentblend = (i/segments);
+ float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
vector new_dir = normalize( (wantdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
//float falloff = 1;
#endif
+ // draw primary beam render
vector top = hitorigin + (thickdir * self.beam_thickness);
vector bottom = hitorigin - (thickdir * self.beam_thickness);
R_PolygonVertex(bottom, '0 0.5 0' * (1 - (self.beam_thickness / maxthickness)), self.beam_color, self.beam_alpha);
R_EndPolygon();
+ // draw trailing particles
+ // NOTES:
+ // - Don't use spammy particle counts here, use a FEW small particles around the beam
+ // - We're not using WarpZone_TrailParticles here because we will handle warpzones ourselves.
+ if(self.beam_traileffect)
+ {
+ trailparticles(self, self.beam_traileffect, last_origin, hitorigin);
+ }
+
// check if we're going to proceed with drawing
if(trace_fraction != 1)
{
void Remove_ArcBeam(void)
{
+ remove(self.beam_muzzleentity);
sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
}
void Ent_ReadArcBeam(float isnew)
{
float sf = ReadByte();
+ entity flash;
// self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
self.iflags = IFLAG_ORIGIN;
InterpolateOrigin_Undo();
+ if(isnew)
+ {
+ // calculate shot origin offset from gun alignment
+ float gunalign = autocvar_cl_gunalign;
+ if(gunalign != 1 && gunalign != 2 && gunalign != 4)
+ gunalign = 3; // default value
+ --gunalign;
+
+ self.beam_shotorigin = arc_shotorigin[gunalign];
+
+ // set other main attributes of the beam
+ self.draw = Draw_ArcBeam;
+ self.entremove = Remove_ArcBeam;
+ sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
+
+ flash = spawn();
+ flash.owner = self;
+ flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
+ flash.drawmask = MASK_NORMAL;
+ flash.solid = SOLID_NOT;
+ setattachment(flash, self, "");
+ setorigin(flash, '0 0 0');
+
+ self.beam_muzzleentity = flash;
+ }
+ else
+ {
+ flash = self.beam_muzzleentity;
+ }
+
if(sf & 1) // settings information
{
self.beam_maxangle = ReadShort();
self.beam_range = ReadCoord();
self.beam_returnspeed = ReadShort();
+ self.beam_tightness = (ReadByte() / 10);
+
+ if(ReadByte())
+ {
+ if(autocvar_chase_active)
+ { self.beam_usevieworigin = 1; }
+ else // use view origin
+ { self.beam_usevieworigin = 2; }
+ }
+ else
+ {
+ self.beam_usevieworigin = 0;
+ }
}
if(sf & 2) // starting location
self.origin_x = ReadCoord();
self.origin_y = ReadCoord();
self.origin_z = ReadCoord();
- setorigin(self, self.origin);
- self.beam_usevieworigin = 0;
}
- else // infer the location from player location
+ else if(self.beam_usevieworigin) // infer the location from player location
{
- if(autocvar_chase_active) // use player origin so that third person display still works
+ if(self.beam_usevieworigin == 2)
{
- self.beam_usevieworigin = 1;
- self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
+ // use view origin
+ self.origin = view_origin;
}
- else // use view origin
+ else
{
- self.beam_usevieworigin = 2;
- self.origin = view_origin; // note that this is only necessary for the sound to be properly located
+ // use player origin so that third person display still works
+ self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
}
- setorigin(self, self.origin);
}
+ setorigin(self, self.origin);
+
if(sf & 4) // want/aim direction
{
self.v_angle_x = ReadCoord();
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_HEAL:
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("healray_impact");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_HIT:
self.beam_color = '1 0 1';
self.beam_alpha = 0.5;
self.beam_thickness = 8;
- self.beam_traileffect = FALSE;
+ self.beam_traileffect = particleeffectnum("nex_beam");
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_BURST_MISS:
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_BURST_WALL:
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_BURST_HEAL:
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
case ARC_BT_BURST_HIT:
self.beam_traileffect = FALSE;
self.beam_hiteffect = particleeffectnum("electro_lightning");
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
self.beam_traileffect = FALSE;
self.beam_hiteffect = FALSE;
self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
- //self.beam_muzzlemodel = "models/uziflash.md3";
- //self.beam_muzzlecolor = '-1 -1 1';
self.beam_image = "particles/lgbeam";
+ setmodel(flash, "models/flash.md3");
+ flash.alpha = self.beam_alpha;
+ flash.colormod = self.beam_color;
+ flash.scale = 0.5;
break;
}
}
InterpolateOrigin_Note();
- if(isnew)
- {
- // calculate shot origin offset from gun alignment
- float gunalign = autocvar_cl_gunalign;
- if(gunalign != 1 && gunalign != 2 && gunalign != 4)
- gunalign = 3; // default value
- --gunalign;
-
- self.beam_shotorigin = arc_shotorigin[gunalign];
-
- // set other main attributes of the beam
- self.draw = Draw_ArcBeam;
- self.entremove = Remove_ArcBeam;
- sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
- }
-
#if 0
printf(
"Ent_ReadArcBeam(%d): sf = %d, start = %s, want = %s, dir = %s, type = %d\n",