[MapRotation]: Add next map feature (#736)

This commit is contained in:
Edo 2023-01-27 19:48:51 +00:00 committed by GitHub
parent 3444e0fa8e
commit b1f022b34f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 10 deletions

View File

@ -39,6 +39,11 @@ namespace Components
return this->rotationEntries_.at(index);
}
MapRotation::RotationData::rotationEntry& MapRotation::RotationData::peekNextEntry()
{
return this->rotationEntries_.at(this->index_);
}
void MapRotation::RotationData::parse(const std::string& data)
{
const auto tokens = Utils::String::Split(data, ' ');
@ -74,16 +79,6 @@ namespace Components
void MapRotation::LoadRotation(const std::string& data)
{
static auto loaded = false;
if (loaded)
{
// Load the rotation once
return;
}
loaded = true;
try
{
DedicatedRotation.parse(data);
@ -98,6 +93,15 @@ namespace Components
void MapRotation::LoadMapRotation()
{
static auto loaded = false;
if (loaded)
{
// Load the rotation once
return;
}
loaded = true;
const std::string mapRotation = (*Game::sv_mapRotation)->current.string;
// People may have sv_mapRotation empty because they only use 'addMap' or 'addGametype'
if (!mapRotation.empty())
@ -252,6 +256,28 @@ namespace Components
ApplyRotation(rotationCurrent);
}
void MapRotation::SetNextMap(RotationData& rotation)
{
assert(!rotation.empty());
const auto& entry = rotation.peekNextEntry();
if (entry.first == "map"s)
{
Game::Dvar_SetString(*Game::nextmap, entry.second.data());
}
}
void MapRotation::SetNextMap(const char* value)
{
assert(value);
Game::Dvar_SetString(*Game::nextmap, value);
}
void MapRotation::ClearNextMap()
{
Game::Dvar_SetString(*Game::nextmap, "");
}
void MapRotation::RandomizeMapRotation()
{
if (SVRandomMapRotation.get<bool>())
@ -280,6 +306,7 @@ namespace Components
{
Logger::Debug("Applying {}", (*Game::sv_mapRotationCurrent)->name);
ApplyMapRotationCurrent(mapRotationCurrent);
ClearNextMap();
return;
}
@ -288,12 +315,14 @@ namespace Components
{
Logger::Print(Game::CON_CHANNEL_SERVER, "{} is empty or contains invalid data. Restarting map\n", (*Game::sv_mapRotation)->name);
RestartCurrentMap();
SetNextMap("map_restart");
return;
}
RandomizeMapRotation();
ApplyRotation(DedicatedRotation);
SetNextMap(DedicatedRotation);
}
MapRotation::MapRotation()

View File

@ -32,6 +32,7 @@ namespace Components
[[nodiscard]] std::size_t getEntriesSize() const noexcept;
rotationEntry& getNextEntry();
rotationEntry& peekNextEntry();
void parse(const std::string& data);
@ -63,6 +64,11 @@ namespace Components
static void RestartCurrentMap();
static void ApplyRotation(RotationData& rotation);
static void ApplyMapRotationCurrent(const std::string& data);
// Utils functions
static void SetNextMap(RotationData& rotation); // Only call this after ApplyRotation
static void SetNextMap(const char* value);
static void ClearNextMap();
static void RandomizeMapRotation();
static void SV_MapRotate_f();

View File

@ -55,6 +55,8 @@ namespace Game
const dvar_t** sv_cheats = reinterpret_cast<const dvar_t**>(0x2098DE0);
const dvar_t** sv_voiceQuality = reinterpret_cast<const dvar_t**>(0x2098DB0);
const dvar_t** nextmap = reinterpret_cast<const dvar_t**>(0x1AD7924);
const dvar_t** cl_showSend = reinterpret_cast<const dvar_t**>(0xA1E870);
const dvar_t** cl_voice = reinterpret_cast<const dvar_t**>(0xB2BB44);
const dvar_t** cl_ingame = reinterpret_cast<const dvar_t**>(0xB2BB80);

View File

@ -107,6 +107,8 @@ namespace Game
extern const dvar_t** sv_cheats;
extern const dvar_t** sv_voiceQuality;
extern const dvar_t** nextmap;
extern const dvar_t** cl_showSend;
extern const dvar_t** cl_voice;
extern const dvar_t** cl_ingame;