From bc9978be121f2601193f18acf448ce0d07af825f Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Tue, 7 Apr 2020 13:06:41 +0200 Subject: [PATCH] Cstrike: Added sniper scopes to the AWP, G3SG1, Scout and SG550. Their zoom-levels aren't final, I am pretty sure CS 1.5 had different zoom levels for each weapon. We'll have to research those values. --- src/client/cstrike/crosshair.c | 43 ++++++++++++++++++++++++++++++++++ src/client/cstrike/defs.h | 3 ++- src/client/cstrike/init.c | 27 ++++++++------------- src/client/valve/init.c | 16 ++++++------- src/shared/cstrike/w_awp.c | 25 ++++++++++++++++++-- src/shared/cstrike/w_g3sg1.c | 25 ++++++++++++++++++-- src/shared/cstrike/w_scout.c | 25 ++++++++++++++++++-- src/shared/cstrike/w_sg550.c | 25 ++++++++++++++++++-- 8 files changed, 154 insertions(+), 35 deletions(-) diff --git a/src/client/cstrike/crosshair.c b/src/client/cstrike/crosshair.c index 61d089b3..2861c6cc 100644 --- a/src/client/cstrike/crosshair.c +++ b/src/client/cstrike/crosshair.c @@ -78,3 +78,46 @@ Cstrike_DrawSimpleCrosshair(void) cross_pos = g_hudmins + (g_hudres / 2) + [-12,-12]; drawsubpic(cross_pos, [24,24], "sprites/crosshairs.spr_0.tga", [0.1875,0], [0.1875, 0.1875], [1,1,1], 1, DRAWFLAG_NORMAL); } + +/* +================= +HUD_DrawScope + +Tries to draw a scope whenever viewzoom < 1.0f +================= +*/ +void +Cstrike_DrawScope(void) +{ + vector scope_pos; + static float scope_offset; + static float scope_scale; + + static void Cstrike_ScopePic(vector pos, vector sz, string img) { + drawpic((pos * scope_scale) + [scope_offset, 0], img, sz * scope_scale, [1,1,1], 1.0f); + } + + // Draw the scope in the middle, seperately from the border + scope_pos = g_hudmins + (g_hudres / 2) + [-128,-128]; + drawpic(scope_pos, "sprites/sniper_scope.spr_0.tga", [256,256], [1,1,1], 1.0f, DRAWFLAG_NORMAL); + + // Border scale to fit the screen + scope_scale = g_hudres[1] / 480; + scope_offset = (g_hudres[0] / 2) - ((640 * scope_scale) / 2); + + // Type 1 Border... more coming soon? + Cstrike_ScopePic([0,0], [192,112], "sprites/top_left.spr_0.tga"); + Cstrike_ScopePic([192,0], [256,112], "sprites/top.spr_0.tga"); + Cstrike_ScopePic([448,0], [192,112], "sprites/top_right.spr_0.tga"); + Cstrike_ScopePic([0,112], [192,256], "sprites/left.spr_0.tga"); + Cstrike_ScopePic([448,112], [192,256], "sprites/right.spr_0.tga"); + Cstrike_ScopePic([0,368], [192,112], "sprites/bottom_left.spr_0.tga"); + Cstrike_ScopePic([192,368], [256,112], "sprites/bottom.spr_0.tga"); + Cstrike_ScopePic([448,368], [192,112], "sprites/bottom_right.spr_0.tga"); + + // Rect borders left and right + if (scope_offset > 0) { + drawfill([0,0], [scope_offset, g_hudres[1]], [0,0,0], 1.0f); + drawfill([(640 * scope_scale) + scope_offset, 0], [scope_offset, g_hudres[1]], [0,0,0], 1.0f); + } +} diff --git a/src/client/cstrike/defs.h b/src/client/cstrike/defs.h index fd1204ca..65122b6c 100644 --- a/src/client/cstrike/defs.h +++ b/src/client/cstrike/defs.h @@ -15,4 +15,5 @@ */ void Cstrike_DrawCrosshair(void); -void Cstrike_DrawSimpleCrosshair(); +void Cstrike_DrawSimpleCrosshair(void); +void Cstrike_DrawScope(void); diff --git a/src/client/cstrike/init.c b/src/client/cstrike/init.c index 9e554fe2..b4061c43 100644 --- a/src/client/cstrike/init.c +++ b/src/client/cstrike/init.c @@ -14,9 +14,6 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -float(entity foo, float chanid) getchannellevel = #0; - - /* ================= Client_Init @@ -25,6 +22,16 @@ Comparable to worldspawn in SSQC in that it's mostly used for precaches ================= */ void Client_Init(float apilevel, string enginename, float engineversion) +{ +} + +void Client_InitDone(void) +{ + /* change this to the motd */ + //VGUI_ChooseTeam(); +} + +void Game_RendererRestarted(string rstr) { precache_model("sprites/640hud1.spr"); precache_model("sprites/640hud2.spr"); @@ -40,9 +47,6 @@ void Client_Init(float apilevel, string enginename, float engineversion) precache_model("sprites/640hud14.spr"); precache_model("sprites/640hud15.spr"); precache_model("sprites/640hud16.spr"); - precache_model("sprites/hud640_01.spr"); - precache_model("sprites/hud640_02.spr"); - precache_model("sprites/hud640_04.spr"); precache_model("sprites/bottom.spr"); precache_model("sprites/bottom_left.spr"); precache_model("sprites/bottom_right.spr"); @@ -53,16 +57,5 @@ void Client_Init(float apilevel, string enginename, float engineversion) precache_model("sprites/top.spr"); precache_model("sprites/top_left.spr"); precache_model("sprites/top_right.spr"); - BEAM_TRIPMINE = particleeffectnum("beam_tripmine"); } - -void Client_InitDone(void) -{ - /* change this to the motd */ - //VGUI_ChooseTeam(); -} - -void Game_RendererRestarted(string rstr) -{ -} diff --git a/src/client/valve/init.c b/src/client/valve/init.c index 3ec19fb1..92c678ec 100644 --- a/src/client/valve/init.c +++ b/src/client/valve/init.c @@ -23,14 +23,6 @@ Comparable to worldspawn in SSQC in that it's mostly used for precaches */ void Client_Init(float apilevel, string enginename, float engineversion) { - precache_model("sprites/640hud1.spr"); - precache_model("sprites/640hud2.spr"); - precache_model("sprites/640hud3.spr"); - precache_model("sprites/640hud4.spr"); - precache_model("sprites/640hud5.spr"); - precache_model("sprites/640hud6.spr"); - - BEAM_TRIPMINE = particleeffectnum("beam_tripmine"); } void Client_InitDone(void) @@ -39,5 +31,11 @@ void Client_InitDone(void) void Game_RendererRestarted(string rstr) { - + precache_model("sprites/640hud1.spr"); + precache_model("sprites/640hud2.spr"); + precache_model("sprites/640hud3.spr"); + precache_model("sprites/640hud4.spr"); + precache_model("sprites/640hud5.spr"); + precache_model("sprites/640hud6.spr"); + BEAM_TRIPMINE = particleeffectnum("beam_tripmine"); } diff --git a/src/shared/cstrike/w_awp.c b/src/shared/cstrike/w_awp.c index ab824b48..a6839a8c 100644 --- a/src/shared/cstrike/w_awp.c +++ b/src/shared/cstrike/w_awp.c @@ -160,6 +160,24 @@ w_awp_primary(void) pl.w_idle_next = pl.w_attack_next; } +void +w_awp_secondary(void) +{ + player pl = (player)self; + if (pl.w_attack_next) { + return; + } + /* Simple toggle of fovs */ + if (pl.viewzoom == 1.0f) { + pl.viewzoom = 0.45f; + } else if (pl.viewzoom == 0.45f) { + pl.viewzoom = 0.1f; + } else { + pl.viewzoom = 1.0f; + } + pl.w_attack_next = 0.5f; +} + void w_awp_reload(void) { @@ -203,7 +221,10 @@ void w_awp_hud(void) { #ifdef CSQC - Cstrike_DrawCrosshair(); + player pl = (player)self; + if (pl.viewzoom < 1.0f) { + Cstrike_DrawScope(); + } HUD_DrawAmmo1(); HUD_DrawAmmo2(); vector aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42]; @@ -252,7 +273,7 @@ weapon_t w_awp = w_awp_draw, __NULL__, w_awp_primary, - __NULL__, + w_awp_secondary, w_awp_reload, w_cstrike_weaponrelease, w_awp_hud, diff --git a/src/shared/cstrike/w_g3sg1.c b/src/shared/cstrike/w_g3sg1.c index ac01694b..6aa248fb 100644 --- a/src/shared/cstrike/w_g3sg1.c +++ b/src/shared/cstrike/w_g3sg1.c @@ -156,6 +156,24 @@ w_g3sg1_primary(void) pl.w_idle_next = pl.w_attack_next; } +void +w_g3sg1_secondary(void) +{ + player pl = (player)self; + if (pl.w_attack_next) { + return; + } + /* Simple toggle of fovs */ + if (pl.viewzoom == 1.0f) { + pl.viewzoom = 0.45f; + } else if (pl.viewzoom == 0.45f) { + pl.viewzoom = 0.1f; + } else { + pl.viewzoom = 1.0f; + } + pl.w_attack_next = 0.5f; +} + void w_g3sg1_reload(void) { @@ -199,7 +217,10 @@ void w_g3sg1_hud(void) { #ifdef CSQC - Cstrike_DrawCrosshair(); + player pl = (player)self; + if (pl.viewzoom < 1.0f) { + Cstrike_DrawScope(); + } HUD_DrawAmmo1(); HUD_DrawAmmo2(); vector aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42]; @@ -248,7 +269,7 @@ weapon_t w_g3sg1 = w_g3sg1_draw, __NULL__, w_g3sg1_primary, - __NULL__, + w_g3sg1_secondary, w_g3sg1_reload, w_cstrike_weaponrelease, w_g3sg1_hud, diff --git a/src/shared/cstrike/w_scout.c b/src/shared/cstrike/w_scout.c index 9a81cfad..40b0c08b 100644 --- a/src/shared/cstrike/w_scout.c +++ b/src/shared/cstrike/w_scout.c @@ -157,6 +157,24 @@ w_scout_primary(void) pl.w_idle_next = pl.w_attack_next; } +void +w_scout_secondary(void) +{ + player pl = (player)self; + if (pl.w_attack_next) { + return; + } + /* Simple toggle of fovs */ + if (pl.viewzoom == 1.0f) { + pl.viewzoom = 0.45f; + } else if (pl.viewzoom == 0.45f) { + pl.viewzoom = 0.1f; + } else { + pl.viewzoom = 1.0f; + } + pl.w_attack_next = 0.5f; +} + void w_scout_reload(void) { @@ -200,7 +218,10 @@ void w_scout_hud(void) { #ifdef CSQC - Cstrike_DrawCrosshair(); + player pl = (player)self; + if (pl.viewzoom < 1.0f) { + Cstrike_DrawScope(); + } HUD_DrawAmmo1(); HUD_DrawAmmo2(); vector aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42]; @@ -249,7 +270,7 @@ weapon_t w_scout = w_scout_draw, __NULL__, w_scout_primary, - __NULL__, + w_scout_secondary, w_scout_reload, w_cstrike_weaponrelease, w_scout_hud, diff --git a/src/shared/cstrike/w_sg550.c b/src/shared/cstrike/w_sg550.c index 3619b76a..6da9c341 100644 --- a/src/shared/cstrike/w_sg550.c +++ b/src/shared/cstrike/w_sg550.c @@ -157,6 +157,24 @@ w_sg550_primary(void) pl.w_idle_next = pl.w_attack_next; } +void +w_sg550_secondary(void) +{ + player pl = (player)self; + if (pl.w_attack_next) { + return; + } + /* Simple toggle of fovs */ + if (pl.viewzoom == 1.0f) { + pl.viewzoom = 0.45f; + } else if (pl.viewzoom == 0.45f) { + pl.viewzoom = 0.1f; + } else { + pl.viewzoom = 1.0f; + } + pl.w_attack_next = 0.5f; +} + void w_sg550_reload(void) { @@ -200,7 +218,10 @@ void w_sg550_hud(void) { #ifdef CSQC - Cstrike_DrawCrosshair(); + player pl = (player)self; + if (pl.viewzoom < 1.0f) { + Cstrike_DrawScope(); + } HUD_DrawAmmo1(); HUD_DrawAmmo2(); vector aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42]; @@ -249,7 +270,7 @@ weapon_t w_sg550 = w_sg550_draw, __NULL__, w_sg550_primary, - __NULL__, + w_sg550_secondary, w_sg550_reload, w_cstrike_weaponrelease, w_sg550_hud,