this.origin += bobmodel_ofs(view);
}
-.vector viewmodel_origin, viewmodel_angles;
.float weapon_nextthink;
.float weapon_eta_last;
.float weapon_switchdelay;
void viewmodel_draw(entity this)
{
- if(!this.activeweapon || !autocvar_r_drawviewmodel)
- return;
int mask = (intermission || (STAT(HEALTH) <= 0) || autocvar_chase_active) ? 0 : MASK_NORMAL;
float a = ((autocvar_cl_viewmodel_alpha) ? bound(-1, autocvar_cl_viewmodel_alpha, this.m_alpha) : this.m_alpha);
int wepskin = this.m_skin;
{
this.name_last = name;
CL_WeaponEntity_SetModel(this, name, swap);
- this.viewmodel_origin = this.origin;
- this.viewmodel_angles = this.angles;
+ this.origin += autocvar_cl_gunoffset;
}
anim_update(this);
if ((!this.animstate_override && !this.animstate_looping) || time > this.animstate_endtime)
}
}
this.weapon_eta_last = f;
- this.origin = this.viewmodel_origin;
- this.angles = this.viewmodel_angles;
this.angles_x = (-90 * f * f);
viewmodel_animate(this);
MUTATOR_CALLHOOK(DrawViewModel, this);
// run viewmodel_draw before updating view_angles to the angles calculated by WarpZone_FixView
// viewmodel_draw needs to use the view_angles set by the engine on every CSQC_UpdateView call
- for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
- viewmodel_draw(viewmodels[slot]);
+ if(autocvar_r_drawviewmodel)
+ for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+ if(viewmodels[slot].activeweapon)
+ viewmodel_draw(viewmodels[slot]);
// Render the Scene
view_origin = getpropertyvec(VF_ORIGIN);
string autocvar__togglezoom;
int autocvar_cl_nade_timer;
bool autocvar_r_drawviewmodel;
+vector autocvar_cl_gunoffset;
void calc_followmodel_ofs(entity view);
REPLICATE(cvar_r_drawviewmodel, int, "r_drawviewmodel");
#ifdef SVQC
-void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
+void SpawnCasing(vector vel, vector ang, int casingtype, entity casingowner, .entity weaponentity)
{
vector org = casingowner.(weaponentity).spawnorigin;
org = casingowner.origin + casingowner.view_ofs + org.x * v_forward - org.y * v_right + org.z * v_up;
FOREACH_CLIENT(true, {
if (!(CS_CVAR(it).cvar_cl_casings))
continue;
- if (it == casingowner && !(CS_CVAR(it).cvar_r_drawviewmodel))
+
+ casingtype &= 0x3F; // reset any bitflags that were set for the previous client
+
+ if (it == casingowner || (IS_SPEC(it) && it.enemy == casingowner))
+ {
+ if (!(CS_CVAR(it).cvar_r_drawviewmodel))
+ continue;
+
+ casingtype |= 0x40; // client will apply autocvar_cl_gunoffset in first person
+ }
+ else if (1 & ~checkpvs(it.origin + it.view_ofs, casingowner)) // 1 or 3 means visible
continue;
- msg_entity = it;
+ msg_entity = it; // sound_allowed checks this
if (!sound_allowed(MSG_ONE, it))
casingtype |= 0x80; // silent
WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
WriteByte(MSG_ONE, ang.x * 256 / 360);
WriteByte(MSG_ONE, ang.y * 256 / 360);
- WriteByte(MSG_ONE, ang.z * 256 / 360);
+ // weapons only have pitch and yaw, so no need to send ang.z
});
}
#endif
classfield(Casing) .int state;
classfield(Casing) .float cnt;
+// this is only needed because LimitedChildrenRubble() takes a func pointer
void Casing_Delete(entity this)
{
delete(this);
if (this.alpha < ALPHA_MIN_VISIBLE)
{
- Casing_Delete(this);
+ delete(this);
this.drawmask = 0;
return;
}
+ trace_startsolid = 0; // due to cl_casings_ticrate, traces are not always performed
Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
//if (wasfreed(this))
// return; // deleted by touch function
+
+ // prevent glitchy casings when the gun model is poking into a wall
+ // doing this here is cheaper than doing it on the server as the client performs the trace anyway
+ if (trace_startsolid)
+ {
+ delete(this);
+ this.drawmask = 0;
+ return;
+ }
}
SOUND(BRASS1, W_Sound("brass1"));
{
if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
{
- Casing_Delete(this);
+ delete(this);
return;
}
NET_HANDLE(casings, bool isNew)
{
- int _state = ReadByte();
- vector org = ReadVector();
- vector vel = decompressShortVector(ReadShort());
- vector ang;
- ang_x = ReadByte() * 360 / 256;
- ang_y = ReadByte() * 360 / 256;
- ang_z = ReadByte() * 360 / 256;
+ Casing casing = ListNewChildRubble(CasingsNGibs, new(casing));
+
+ casing.state = ReadByte();
+ casing.origin = ReadVector();
+ casing.velocity = decompressShortVector(ReadShort());
+ casing.angles_x = ReadByte() * 360 / 256;
+ casing.angles_y = ReadByte() * 360 / 256;
+
return = true;
- Casing casing = ListNewChildRubble(CasingsNGibs, new(casing));
- casing.silent = (_state & 0x80);
- casing.state = (_state & 0x7F);
- casing.origin = org;
+ casing.silent = casing.state & 0x80;
+ if (casing.state & 0x40 && !autocvar_chase_active)
+ casing.origin += autocvar_cl_gunoffset.x * v_forward
+ - autocvar_cl_gunoffset.y * v_right
+ + autocvar_cl_gunoffset.z * v_up;
+ casing.state &= 0x3F; // the 2 most significant bits are reserved for the silent and casingowner bitflags
+
setorigin(casing, casing.origin);
- casing.velocity = vel;
- casing.angles = ang;
casing.drawmask = MASK_NORMAL;
-
casing.draw = Casing_Draw;
if (isNew) IL_PUSH(g_drawables, casing);
- casing.velocity = casing.velocity + 2 * prandomvec();
- casing.avelocity = '0 250 0' + 100 * prandomvec();
+ casing.velocity += 2 * prandomvec();
+ casing.avelocity = '0 10 0' + 100 * prandomvec();
set_movetype(casing, MOVETYPE_BOUNCE);
- casing.bouncefactor = 0.25;
settouch(casing, Casing_Touch);
casing.move_time = time;
casing.event_damage = Casing_Damage;
{
case 1:
setmodel(casing, MDL_CASING_SHELL);
+ casing.bouncefactor = 0.25;
casing.cnt = time + autocvar_cl_casings_shell_time;
break;
default:
setmodel(casing, MDL_CASING_BULLET);
+ casing.bouncefactor = 0.5;
casing.cnt = time + autocvar_cl_casings_bronze_time;
break;
}
- setsize(casing, '0 0 -1', '0 0 -1');
-
LimitedChildrenRubble(CasingsNGibs, "casing", autocvar_cl_casings_maxcount, Casing_Delete, NULL);
}
int autocvar_cl_casings_maxcount = 100;
float autocvar_cl_casings_shell_time;
bool autocvar_cl_casings_sloppy = 1;
-float autocvar_cl_casings_ticrate = 0.1;
+float autocvar_cl_casings_ticrate;
#endif
#ifdef GAMEQC
#ifdef SVQC
int autocvar_g_casings;
-void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity);
+void SpawnCasing(vector vel, vector ang, int casingtype, entity casingowner, .entity weaponentity);
#endif
if (autocvar_g_casings >= 2) // casing code
{
makevectors(actor.v_angle); // for some reason, this is lost
- SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
+ SpawnCasing(((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
}
ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(okhmg, refire) * W_WeaponRateFactor(actor);
if(autocvar_g_casings >= 2) // casing code
{
makevectors(actor.v_angle); // for some reason, this is lost
- SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
+ SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
}
ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(okmachinegun, refire) * W_WeaponRateFactor(actor);
* this.origin, this.angles
* this.weaponchild
* this.movedir, this.view_ofs, this.movedir_aligned
+ * this.spawnorigin (SVQC only)
* attachment stuff
* anim stuff
* to free:
if (this.weaponchild) delete(this.weaponchild);
this.weaponchild = NULL;
this.movedir = '0 0 0';
+#ifdef SVQC
this.spawnorigin = '0 0 0';
+#endif
this.oldorigin = '0 0 0';
this.anim_fire1 = '0 1 0.01';
this.anim_fire2 = '0 1 0.01';
this.movedir = '0 0 0';
}
}
+#ifdef SVQC
{
int idx = 0;
// v_ model attached to invisible h_ model
this.spawnorigin = this.movedir;
}
}
+#endif
if (v_shot_idx)
{
this.oldorigin = '0 0 0'; // use regular attachment
vector v = this.movedir;
this.movedir = shotorg_adjust(v, false, false, algn);
this.movedir_aligned = shotorg_adjust(v, false, true, algn);
- this.view_ofs = shotorg_adjust(v, false, true, algn) - v;
+ this.view_ofs = this.movedir_aligned - v;
}
int compressed_shotorg = compressShotOrigin(this.movedir);
// make them match perfectly
#endif
this.movedir = decompressShotOrigin(compressed_shotorg);
+#ifdef SVQC
this.spawnorigin += this.view_ofs; // offset the casings origin by the same amount
+#endif
// check if an instant weapon switch occurred
setorigin(this, this.view_ofs);
//.int weapon; // current weapon
.string weaponname; // name of .weapon
+#ifdef SVQC
.vector spawnorigin; // for casings
+#endif
.vector movedir_aligned; // shot origin based on weapon alignment (unaffected by shootfromeye)
if(autocvar_g_casings >= 2)
{
makevectors(actor.v_angle); // for some reason, this is lost
- SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
+ SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
}
if(actor.(weaponentity).misc_bulletcounter == 1)
if(autocvar_g_casings >= 2) // casing code
{
makevectors(actor.v_angle); // for some reason, this is lost
- SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
+ SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
}
ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(machinegun, first_refire) * W_WeaponRateFactor(actor);
if(autocvar_g_casings >= 2) // casing code
{
makevectors(actor.v_angle); // for some reason, this is lost
- SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
+ SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
}
actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
if(autocvar_g_casings >= 2)
{
makevectors(actor.v_angle); // for some reason, this is lost
- SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, actor, weaponentity);
+ SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
}
}
{
makevectors(actor.v_angle); // for some reason, this is lost
//for(int sc = 0;sc < WEP_CVAR_PRI(shotgun, ammo);sc = sc + 1)
- SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1, actor, weaponentity);
+ SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 30) * v_up), vectoangles(v_forward), 1, actor, weaponentity);
}
}
cl_decals_fadetime 5
cl_decals_time 1
seta cl_gunalign 3 "Gun alignment; 1 = center, 3 = right, 4 = left; requires reconnect"
+seta cl_gunoffset "0 0 0" "Adjust the weapon viewmodel position, applies only to your own first person view and is relative to cl_gunalign"
seta cl_nogibs 0 "reduce number of violence effects, or remove them totally"
seta cl_particlegibs 0 "simpler gibs"
seta cl_gibs_damageforcescale 3.5 "force to push around gibs"
seta cl_casings 1 "enable or disable bullet casings"
seta cl_casings_shell_time 30 "shell casing lifetime"
seta cl_casings_bronze_time 10 "bullet casings lifetime"
-seta cl_casings_ticrate 0.1 "ticrate for casings"
+seta cl_casings_ticrate 0.03125 "ticrate for casings"
seta cl_casings_sloppy 1 "sloppy casings, may temporarily penetrate walls"
seta cl_projectiles_sloppy 1 "sloppy projectiles, may temporarily penetrate walls"
cl_stainmaps 0