Counter-Strike: Add progress bar for defusal and other tasks.

This commit is contained in:
Marco Cawthorne 2020-06-09 00:23:18 +02:00
parent 8aa66987e5
commit 61983ec2d8
6 changed files with 62 additions and 7 deletions

View file

@ -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();
}

View file

@ -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));

View file

@ -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");

View file

@ -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);

View file

@ -30,6 +30,7 @@
enum
{
STAT_MONEY = 34,
STAT_PROGRESS,
STAT_GAMETIME,
STAT_GAMESTATE
};

View file

@ -89,5 +89,7 @@ class player:base_player
int old_cs_shotmultiplier;
float old_cs_shottime;
float progress;
#endif
};