From 590471d94cd092b289f3342d42efb66ad431c26e Mon Sep 17 00:00:00 2001 From: jeefo Date: Tue, 5 Aug 2025 12:32:58 +0300 Subject: [PATCH] mgr: added yb_first_human_restart (resolves #713) When bots are playing on dedicated server and first human joins a team the game will be restarted if yb_first_human_restart is higher than zero. Co-Authored-By: Max <161382234+dyspose@users.noreply.github.com> --- inc/manager.h | 7 +++++++ inc/message.h | 4 +++- src/combat.cpp | 4 ++-- src/engine.cpp | 3 +++ src/manager.cpp | 24 ++++++++++++++++++++++++ src/message.cpp | 8 ++++++++ 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/inc/manager.h b/inc/manager.h index e6c47e4..2a9f169 100644 --- a/inc/manager.h +++ b/inc/manager.h @@ -41,10 +41,12 @@ private: int m_lastWinner {}; // the team who won previous round int m_lastDifficulty {}; // last bots difficulty int m_bombSayStatus {}; // some bot is issued whine about bomb + int m_numPreviousPlayers {}; // number of players in game im previous player check bool m_bombPlanted {}; // is bomb planted ? bool m_botsCanPause {}; // bots can do a little pause ? bool m_roundOver {}; // well, round is over> + bool m_resetHud {}; // reset HUD is called for some one Array m_activeGrenades {}; // holds currently active grenades on the map Array m_interestingEntities {}; // holds currently interesting entities on the map @@ -96,6 +98,7 @@ public: void maintainQuota (); void maintainAutoKill (); void maintainLeaders (); + void maintainRoundRestart (); void initQuota (); void initRound (); void decrementQuota (int by = 1); @@ -231,6 +234,10 @@ public: m_teamData[team].lastRadioSlot = radio; } + void setResetHUD (bool resetHud) { + m_resetHud = resetHud; + } + int getLastRadio (const int team) const { return m_teamData[team].lastRadioSlot; } diff --git a/inc/message.h b/inc/message.h index b6556d4..8b02679 100644 --- a/inc/message.h +++ b/inc/message.h @@ -33,7 +33,8 @@ CR_DECLARE_SCOPED_ENUM (NetMsg, ItemStatus = 22, ScoreInfo = 23, ScoreAttrib = 24, - SayText = 25 + SayText = 25, + ResetHUD = 26 ) // vgui menus (since latest steam updates is obsolete, but left for old cs) @@ -124,6 +125,7 @@ private: void netMsgFlashBat (); void netMsgScoreInfo (); void netMsgScoreAttrib (); + void netMsgResetHUD (); private: Bot *pickBot (int32_t index); diff --git a/src/combat.cpp b/src/combat.cpp index 3c4beb7..46e3e0f 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -1557,8 +1557,8 @@ void Bot::attackMovement () { m_strafeSetTime = strafeUpdateTime (); } - const bool wallOnRight = checkWallOnRight (72.0f); - const bool wallOnLeft = checkWallOnLeft (72.0f); + const bool wallOnRight = checkWallOnRight (96.0f); + const bool wallOnLeft = checkWallOnLeft (96.0f); if (m_dodgeStrafeDir == Dodge::Left) { if (!wallOnLeft) { diff --git a/src/engine.cpp b/src/engine.cpp index 751ac5b..1173105 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -1112,6 +1112,9 @@ void Game::slowFrame () { // ensure the server admin is confident about features he's using ensureHealthyGameEnvironment (); + // maintain round restart for first human join + bots.maintainRoundRestart (); + // update next update time m_halfSecondFrame = nextUpdate * 0.25f + time (); } diff --git a/src/manager.cpp b/src/manager.cpp index ff29ebc..2dfa320 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -18,6 +18,7 @@ ConVar cv_think_fps ("think_fps", "30.0", "Specifies how many times per second b ConVar cv_think_fps_disable ("think_fps_disable", "1", "Allows to completely disable think fps on Xash3D.", true, 0.0f, 1.0f, Var::Xash3D); ConVar cv_autokill_delay ("autokill_delay", "0.0", "Specifies amount of time in seconds when bots will be killed if no humans left alive.", true, 0.0f, 90.0f); +ConVar cv_first_human_restart ("first_human_restart", "0.0", "Restart the game if first human player joined the bot game.", true, 0.0f, 1.0f); ConVar cv_join_after_player ("join_after_player", "0", "Specifies whether bots should join server, only when at least one human player in game."); ConVar cv_join_team ("join_team", "any", "Forces all bots to join team specified here.", false); @@ -471,6 +472,29 @@ void BotManager::maintainLeaders () { } } +void BotManager::maintainRoundRestart () { + if (!cv_first_human_restart || !game.isDedicated ()) { + return; + } + const int totalHumans = getHumansCount (true); + const int totalBots = getBotCount (); + + if (totalHumans > 0 + && m_numPreviousPlayers == 0 + && totalHumans == 1 + && totalBots > 0 + && !m_resetHud) { + + static ConVarRef sv_restartround ("sv_restartround"); + + if (sv_restartround.exists ()) { + sv_restartround.set ("1"); + } + } + m_numPreviousPlayers = totalHumans; + m_resetHud = false; +} + void BotManager::maintainAutoKill () { const float killDelay = cv_autokill_delay.as (); diff --git a/src/message.cpp b/src/message.cpp index 538d778..4df7b1f 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -431,6 +431,13 @@ void MessageDispatcher::netMsgFlashBat () { m_bot->m_flashLevel = m_args[value].long_; } +void MessageDispatcher::netMsgResetHUD () { + if (m_bot) { + m_bot->spawned (); + } + bots.setResetHUD (true); +} + MessageDispatcher::MessageDispatcher () { // register wanted message @@ -461,6 +468,7 @@ MessageDispatcher::MessageDispatcher () { addWanted ("FlashBat", NetMsg::FlashBat, &MessageDispatcher::netMsgFlashBat); addWanted ("ScoreInfo", NetMsg::ScoreInfo, &MessageDispatcher::netMsgScoreInfo); addWanted ("ScoreAttrib", NetMsg::ScoreAttrib, &MessageDispatcher::netMsgScoreAttrib); + addWanted ("ResetHUD", NetMsg::ResetHUD, &MessageDispatcher::netMsgResetHUD); // we're need next messages IDs but we're won't handle them, so they will be removed from wanted list as soon as they get engine IDs addWanted ("BotVoice", NetMsg::BotVoice, nullptr);