From 61983ec2d808b04f84a620960f648f4238fa5bc2 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Tue, 9 Jun 2020 00:23:18 +0200 Subject: [PATCH] Counter-Strike: Add progress bar for defusal and other tasks. --- src/client/cstrike/hud.c | 27 +++++++++++++++++ src/server/cstrike/gamerules_multiplayer.cpp | 7 +---- src/server/cstrike/item_c4bomb.cpp | 31 +++++++++++++++++++- src/server/cstrike/server.c | 1 + src/shared/cstrike/defs.h | 1 + src/shared/cstrike/player.h | 2 ++ 6 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/client/cstrike/hud.c b/src/client/cstrike/hud.c index 2a99d8bc..ed090acb 100644 --- a/src/client/cstrike/hud.c +++ b/src/client/cstrike/hud.c @@ -587,6 +587,32 @@ HUD_DrawZones(void) } } +/* defusal etc. progress bar */ +void +HUD_DrawProgress(void) +{ + vector vSize = [540,16]; + vector vMainPos; + float progress; + + progress = getstatf(STAT_PROGRESS) / 10.0f; + + if (progress > 0) { + vMainPos = g_hudmins; + vMainPos[0] += (g_hudres[0] / 2) - (vSize[0] / 2); + vMainPos[1] += (g_hudres[1] / 2) - (vSize[1] / 2); + + vector vBar = vSize; + vBar[0] = 538 * progress; + vBar[1] = 14; + drawfill(vMainPos + [1,1], vBar, g_hud_color, 1.0, DRAWFLAG_ADDITIVE); + drawfill(vMainPos, [vSize[0], 1], g_hud_color, 1.0f); // Top + drawfill([vMainPos[0], vMainPos[1] + vSize[1]], [vSize[0], 1], g_hud_color, 1.0f); // Bottom + drawfill(vMainPos, [1, vSize[1]], g_hud_color, 1.0f); // Left + drawfill([vMainPos[0] + vSize[0], vMainPos[1]], [1, vSize[1] + 1], g_hud_color, 1.0f); // Right + } +} + /* weapon/ammo pickup notifications */ void HUD_DrawNotify(void) @@ -635,6 +661,7 @@ HUD_Draw(void) HUD_DrawHealth(); HUD_DrawArmor(); HUD_DrawZones(); + HUD_DrawProgress(); HUD_DrawFlashlight(); Damage_Draw(); } diff --git a/src/server/cstrike/gamerules_multiplayer.cpp b/src/server/cstrike/gamerules_multiplayer.cpp index aeb5181a..baf60df1 100644 --- a/src/server/cstrike/gamerules_multiplayer.cpp +++ b/src/server/cstrike/gamerules_multiplayer.cpp @@ -429,16 +429,11 @@ CSMultiplayerRules::RestartRound(int iWipe) } } - // Clear the corpses/items + /* clear the corpses/items/bombs */ for (entity eFind = world; (eFind = find(eFind, ::classname, "remove_me"));) { remove(eFind); } - // Find the bombs. Destory them! - for (entity eFind = world; (eFind = find(eFind, ::classname, "c4bomb"));) { - remove(eFind); - } - // Select a random Terrorist for the bomb, if needed if (g_cs_bombzones > 0) { int iRandomT = floor(random(1, (float)g_cs_alive_t + 1)); diff --git a/src/server/cstrike/item_c4bomb.cpp b/src/server/cstrike/item_c4bomb.cpp index b31fd104..af17a8f2 100644 --- a/src/server/cstrike/item_c4bomb.cpp +++ b/src/server/cstrike/item_c4bomb.cpp @@ -8,13 +8,30 @@ class item_c4:CBaseEntity float m_flDefusalState; void(void) item_c4; + virtual void(void) ClearProgress; virtual void(void) PlayerUse; virtual void(void) Logic; }; +void +item_c4::ClearProgress(void) +{ + if (m_eUser != world) { + player pl = (player)m_eUser; + pl.progress = 0.0f; + } +} + void item_c4::PlayerUse(void) { + player pl = (player)eActivator; + + /* obvious check */ + if (pl.team != TEAM_CT) { + return; + } + /* don't allow anyone else to hijack. */ if (m_eUser == world) { m_eUser = eActivator; @@ -29,22 +46,30 @@ item_c4::Logic(void) /* check if we're being used */ if (m_eUser != world) { + player pl = (player)m_eUser; + /* we need to check if the user has changed every frame. */ if (!m_eUser.button5) { + ClearProgress(); + + /* clear user */ m_eUser = world; m_flDefusalState = 0.0f; } else { - player pl = (player)m_eUser; /* defusal kit always cuts the time in half */ if (pl.g_items & ITEM_DEFUSAL) m_flDefusalState += (frametime * 2); else m_flDefusalState += frametime; + + /* tracked stat */ + pl.progress = m_flDefusalState; } } if (m_flDefusalState > 10.0f) { + ClearProgress(); sound(this, CHAN_VOICE, "weapons/c4_disarmed.wav", 1.0, ATTN_NORM); rules.RoundOver(TEAM_CT, 3600, TRUE); Radio_BroadcastMessage(RADIO_BOMBDEF); @@ -56,6 +81,7 @@ item_c4::Logic(void) /* if our time has passed, explode */ if (m_flExplodeTime < time) { + ClearProgress(); /* In Bomb Defusal, all Terrorists receive $3500 * if they won by detonating the bomb. */ @@ -99,6 +125,9 @@ item_c4::Logic(void) void item_c4::item_c4(void) { + /* throw this in with the other temporary round entities */ + classname = "remove_me"; + SetMovetype(MOVETYPE_NONE); SetSolid(SOLID_BBOX); SetModel("models/w_c4.mdl"); diff --git a/src/server/cstrike/server.c b/src/server/cstrike/server.c index 36babbbe..833f29aa 100644 --- a/src/server/cstrike/server.c +++ b/src/server/cstrike/server.c @@ -51,6 +51,7 @@ void Game_Worldspawn(void) Weapons_Init(); clientstat(STAT_MONEY, EV_INTEGER, player::money); + clientstat(STAT_PROGRESS, EV_FLOAT, player::progress); pointerstat(STAT_GAMETIME, EV_FLOAT, &g_cs_gametime); pointerstat(STAT_GAMESTATE, EV_INTEGER, &g_cs_gamestate); diff --git a/src/shared/cstrike/defs.h b/src/shared/cstrike/defs.h index 171ab1d9..7b2151a3 100644 --- a/src/shared/cstrike/defs.h +++ b/src/shared/cstrike/defs.h @@ -30,6 +30,7 @@ enum { STAT_MONEY = 34, + STAT_PROGRESS, STAT_GAMETIME, STAT_GAMESTATE }; diff --git a/src/shared/cstrike/player.h b/src/shared/cstrike/player.h index 3191dc2f..0573acbe 100644 --- a/src/shared/cstrike/player.h +++ b/src/shared/cstrike/player.h @@ -89,5 +89,7 @@ class player:base_player int old_cs_shotmultiplier; float old_cs_shottime; + + float progress; #endif };