feat: allow bots to be added into the game even if no default spawn points (ref #511)

This commit is contained in:
jeefo 2024-01-21 00:59:15 +03:00
commit 05e10bae6e
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
6 changed files with 36 additions and 4 deletions

View file

@ -20,3 +20,11 @@ C4ModelName = c4.mdl
; cvar here. ; cvar here.
; ;
AMXParachuteCvar = sv_parachute AMXParachuteCvar = sv_parachute
;
; For CSDM mods that add custom spawn points other than info_player_start and
; In info_player_deathmatch, you can specify the class name of this spawn point.
; So bot's will be able to join the game without default spawn entities.
;
CustomCSDMSpawnPoint = view_spawn

View file

@ -220,6 +220,9 @@ public:
// search entities in sphere // search entities in sphere
void searchEntities (const Vector &position, float radius, EntitySearch functor); void searchEntities (const Vector &position, float radius, EntitySearch functor);
// check if map has entity
bool hasEntityInGame (StringRef classname);
// print the version to server console on startup // print the version to server console on startup
void printBotVersion (); void printBotVersion ();

View file

@ -46,9 +46,9 @@ private:
bool m_leaderChoosen[kGameTeamNum] {}; // is team leader choose thees round bool m_leaderChoosen[kGameTeamNum] {}; // is team leader choose thees round
bool m_economicsGood[kGameTeamNum] {}; // is team able to buy anything bool m_economicsGood[kGameTeamNum] {}; // is team able to buy anything
bool m_bombPlanted {}; bool m_bombPlanted {}; // is bomb planted ?
bool m_botsCanPause {}; bool m_botsCanPause {}; // bots can do a little pause ?
bool m_roundOver {}; bool m_roundOver {}; // well, round is over>
Array <edict_t *> m_activeGrenades {}; // holds currently active grenades on the map Array <edict_t *> m_activeGrenades {}; // holds currently active grenades on the map
Array <edict_t *> m_interestingEntities {}; // holds currently interesting entities on the map Array <edict_t *> m_interestingEntities {}; // holds currently interesting entities on the map
@ -124,6 +124,7 @@ public:
bool isTeamStacked (int team); bool isTeamStacked (int team);
bool kickRandom (bool decQuota = true, Team fromTeam = Team::Unassigned); bool kickRandom (bool decQuota = true, Team fromTeam = Team::Unassigned);
bool hasCustomCSDMSpawnEntities ();
public: public:
const Array <edict_t *> &getActiveGrenades () { const Array <edict_t *> &getActiveGrenades () {

View file

@ -651,6 +651,7 @@ void BotConfig::loadCustomConfig () {
m_custom["C4ModelName"] = "c4.mdl"; m_custom["C4ModelName"] = "c4.mdl";
m_custom["AMXParachuteCvar"] = "sv_parachute"; m_custom["AMXParachuteCvar"] = "sv_parachute";
m_custom["CustomCSDMSpawnPoint"] = "view_spawn";
// custom initialization // custom initialization
if (openConfig ("custom", "Custom config file not found. Loading defaults.", &file)) { if (openConfig ("custom", "Custom config file not found. Loading defaults.", &file)) {

View file

@ -1054,6 +1054,10 @@ void Game::searchEntities (const Vector &position, float radius, EntitySearch fu
} }
} }
bool Game::hasEntityInGame (StringRef classname) {
return !isNullEntity (engfuncs.pfnFindEntityByString (nullptr, "classname", classname.chars ()));
}
void Game::printBotVersion () { void Game::printBotVersion () {
String gameVersionStr; String gameVersionStr;
StringArray botRuntimeFlags; StringArray botRuntimeFlags;

View file

@ -441,7 +441,12 @@ void BotManager::maintainQuota () {
else { else {
desiredBotCount = cr::min <int> (desiredBotCount, maxClients - humanPlayersInGame); desiredBotCount = cr::min <int> (desiredBotCount, maxClients - humanPlayersInGame);
} }
int maxSpawnCount = game.getSpawnCount (Team::Terrorist) + game.getSpawnCount (Team::CT) - humanPlayersInGame; auto maxSpawnCount = game.getSpawnCount (Team::Terrorist) + game.getSpawnCount (Team::CT) - humanPlayersInGame;
// if has some custom spawn points, max out spawn point counter
if (desiredBotCount > botsInGame && hasCustomCSDMSpawnEntities ()) {
maxSpawnCount = game.maxClients () + 1;
}
// sent message only to console from here // sent message only to console from here
ctrl.setFromConsole (true); ctrl.setFromConsole (true);
@ -760,6 +765,16 @@ bool BotManager::kickRandom (bool decQuota, Team fromTeam) {
return false; return false;
} }
bool BotManager::hasCustomCSDMSpawnEntities () {
if (!game.is (GameFlags::CSDM | GameFlags::FreeForAll)) {
return false;
}
auto customSpawnClass = conf.fetchCustom ("CustomCSDMSpawnPoint");
// check for custom entity
return game.hasEntityInGame (customSpawnClass);
}
void BotManager::setLastWinner (int winner) { void BotManager::setLastWinner (int winner) {
m_lastWinner = winner; m_lastWinner = winner;
m_roundOver = true; m_roundOver = true;