PC: Add custom weapon zoom amounts

This commit is contained in:
Steam Deck User 2023-01-20 00:38:37 -05:00
parent 97d76846a3
commit d3c9b20cf8
3 changed files with 92 additions and 20 deletions

View file

@ -70,6 +70,7 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init =
registercommand("showscores"); registercommand("showscores");
cvar_set("sv_cheats", ftos(1)); cvar_set("sv_cheats", ftos(1));
autocvar(r_viewmodel_default_fov, 70);
// Runtime check if we're running this in WebASM/WebGL. // Runtime check if we're running this in WebASM/WebGL.
if (cvar_string("sys_platform") == "Web") if (cvar_string("sys_platform") == "Web")
@ -453,7 +454,6 @@ noref void(float isnew) CSQC_Ent_Update =
addentity(self); addentity(self);
} }
// CALLED EVERY CLIENT RENDER FRAME // CALLED EVERY CLIENT RENDER FRAME
noref void(float width, float height, float menushown) CSQC_UpdateView = noref void(float width, float height, float menushown) CSQC_UpdateView =
{ {
@ -469,9 +469,12 @@ noref void(float width, float height, float menushown) CSQC_UpdateView =
setviewprop(VF_DRAWENGINESBAR, 0); setviewprop(VF_DRAWENGINESBAR, 0);
setviewprop(VF_DRAWCROSSHAIR, 0); setviewprop(VF_DRAWCROSSHAIR, 0);
setsensitivityscaler(getstatf(STAT_VIEWZOOM)); setsensitivityscaler(getstatf(STAT_VIEWZOOM)*getstatf(STAT_VIEWZOOM));
setviewprop(VF_AFOV, autocvar(fov,90)*getstatf(STAT_VIEWZOOM)); setviewprop(VF_AFOV, autocvar(fov,90)*getstatf(STAT_VIEWZOOM));
cvar_set("r_viewmodel_fov", ftos(cvar("r_viewmodel_default_fov")*getstatf(STAT_VIEWZOOM)));
//autoadd entities received from servers for drawing //autoadd entities received from servers for drawing
addentities(MASK_ENGINE); addentities(MASK_ENGINE);

View file

@ -2422,43 +2422,38 @@ void () Weapon_Logic =
} }
#ifdef PC #ifdef PC
else { else {
float zoom_factor = 1 - (0.018*GetWeaponZoomAmount(self.weapon));
if (self.weapon == W_KAR_SCOPE || self.weapon == W_PTRS || if (self.viewzoom > zoom_factor)
self.weapon == W_HEADCRACKER || self.weapon == W_PENETRATOR) { self.viewzoom -= 0.03;
if (self.viewzoom > 0.5) else
self.viewzoom -= 0.05; self.viewzoom = zoom_factor;
else
self.viewzoom = 0.5;
} else {
if (self.viewzoom > 0.9)
self.viewzoom -= 0.01;
else
self.viewzoom = 0.89999;
}
} }
#endif // PC #endif // PC
} }
} }
} else if (!self.button8 && self.zoom) { }
// AIM button is released
else if (!self.button8 && self.zoom) {
#ifdef PC #ifdef PC
if (self.weapon == W_KAR_SCOPE || self.weapon == W_PTRS || if (self.weapon == W_KAR_SCOPE || self.weapon == W_PTRS ||
self.weapon == W_HEADCRACKER || self.weapon == W_PENETRATOR) { self.weapon == W_HEADCRACKER || self.weapon == W_PENETRATOR) {
if (self.viewzoom == 0.2) { if (self.viewzoom == 0.2) {
self.viewzoom += 0.05; self.viewzoom += 0.03;
ReturnWeaponModel(); ReturnWeaponModel();
} else { } else {
UpdateVmodel(self.weaponmodel, GetWepSkin(self.weapon)); UpdateVmodel(self.weaponmodel, GetWepSkin(self.weapon));
UpdateV2model(self.weapon2model, 0); UpdateV2model(self.weapon2model, 0);
self.viewzoom += 0.05; self.viewzoom += 0.03;
} }
} else { } else {
if (self.viewzoom == 0.9) { if (self.viewzoom == 0.9) {
W_AimOut(); W_AimOut();
} else { } else {
self.viewzoom += 0.015; self.viewzoom += 0.03;
} }
} }
// Don't stop aiming until the camera is restored
if (self.viewzoom >= 1) { if (self.viewzoom >= 1) {
self.viewzoom = 1; self.viewzoom = 1;
self.zoom = 0; self.zoom = 0;

View file

@ -4217,6 +4217,7 @@ float (float wep) GetWeaponFlash_Size = {
case W_COMPRESSOR: case W_COMPRESSOR:
return 12; return 12;
case W_PPSH: case W_PPSH:
case W_REAPER:
return 14; return 14;
case W_MP40: case W_MP40:
case W_AFTERBURNER: case W_AFTERBURNER:
@ -4243,3 +4244,76 @@ float (float wep) GetWeaponFlash_Size = {
return 5; return 5;
} }
} }
// Returns the amount needed to zoom in a weapon. In near-fov "units".
float(float wep) GetWeaponZoomAmount =
{
switch(wep) {
case W_COLT:
return 10;
case W_KAR:
case W_ARMAGEDDON:
return 25;
case W_KAR_SCOPE:
case W_HEADCRACKER:
return 50;
case W_THOMPSON:
case W_GIBS:
return 10;
case W_TRENCH:
case W_GUT:
return 10;
case W_357:
case W_KILLU:
return 5;
case W_MG:
case W_BARRACUDA:
return 15;
case W_DB:
case W_BORE:
case W_SAWNOFF:
return 10;
case W_M1A1:
case W_WIDDER:
return 20;
case W_BAR:
case W_WIDOW:
return 30;
case W_FG:
case W_IMPELLER:
return 30;
case W_GEWEHR:
case W_COMPRESSOR:
return 25;
case W_PPSH:
case W_REAPER:
return 10;
case W_MP40:
case W_AFTERBURNER:
return 10;
case W_MP5K:
case W_KOLLIDER:
return 10;
case W_STG:
case W_SPATZ:
return 20;
case W_M1:
case W_M1000:
return 25;
case W_BROWNING:
case W_ACCELERATOR:
return 15;
case W_PTRS:
case W_PENETRATOR:
return 50;
case W_TYPE:
case W_SAMURAI:
return 10;
case W_RAY:
case W_PORTER:
return 5;
default: return 0;
}
return 0;
}