[MapRotation]: Add next map feature (#736)
This commit is contained in:
parent
3444e0fa8e
commit
b1f022b34f
@ -39,6 +39,11 @@ namespace Components
|
|||||||
return this->rotationEntries_.at(index);
|
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)
|
void MapRotation::RotationData::parse(const std::string& data)
|
||||||
{
|
{
|
||||||
const auto tokens = Utils::String::Split(data, ' ');
|
const auto tokens = Utils::String::Split(data, ' ');
|
||||||
@ -74,16 +79,6 @@ namespace Components
|
|||||||
|
|
||||||
void MapRotation::LoadRotation(const std::string& data)
|
void MapRotation::LoadRotation(const std::string& data)
|
||||||
{
|
{
|
||||||
static auto loaded = false;
|
|
||||||
|
|
||||||
if (loaded)
|
|
||||||
{
|
|
||||||
// Load the rotation once
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
loaded = true;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DedicatedRotation.parse(data);
|
DedicatedRotation.parse(data);
|
||||||
@ -98,6 +93,15 @@ namespace Components
|
|||||||
|
|
||||||
void MapRotation::LoadMapRotation()
|
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;
|
const std::string mapRotation = (*Game::sv_mapRotation)->current.string;
|
||||||
// People may have sv_mapRotation empty because they only use 'addMap' or 'addGametype'
|
// People may have sv_mapRotation empty because they only use 'addMap' or 'addGametype'
|
||||||
if (!mapRotation.empty())
|
if (!mapRotation.empty())
|
||||||
@ -252,6 +256,28 @@ namespace Components
|
|||||||
ApplyRotation(rotationCurrent);
|
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()
|
void MapRotation::RandomizeMapRotation()
|
||||||
{
|
{
|
||||||
if (SVRandomMapRotation.get<bool>())
|
if (SVRandomMapRotation.get<bool>())
|
||||||
@ -280,6 +306,7 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Logger::Debug("Applying {}", (*Game::sv_mapRotationCurrent)->name);
|
Logger::Debug("Applying {}", (*Game::sv_mapRotationCurrent)->name);
|
||||||
ApplyMapRotationCurrent(mapRotationCurrent);
|
ApplyMapRotationCurrent(mapRotationCurrent);
|
||||||
|
ClearNextMap();
|
||||||
return;
|
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);
|
Logger::Print(Game::CON_CHANNEL_SERVER, "{} is empty or contains invalid data. Restarting map\n", (*Game::sv_mapRotation)->name);
|
||||||
RestartCurrentMap();
|
RestartCurrentMap();
|
||||||
|
SetNextMap("map_restart");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomizeMapRotation();
|
RandomizeMapRotation();
|
||||||
|
|
||||||
ApplyRotation(DedicatedRotation);
|
ApplyRotation(DedicatedRotation);
|
||||||
|
SetNextMap(DedicatedRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapRotation::MapRotation()
|
MapRotation::MapRotation()
|
||||||
|
@ -32,6 +32,7 @@ namespace Components
|
|||||||
|
|
||||||
[[nodiscard]] std::size_t getEntriesSize() const noexcept;
|
[[nodiscard]] std::size_t getEntriesSize() const noexcept;
|
||||||
rotationEntry& getNextEntry();
|
rotationEntry& getNextEntry();
|
||||||
|
rotationEntry& peekNextEntry();
|
||||||
|
|
||||||
void parse(const std::string& data);
|
void parse(const std::string& data);
|
||||||
|
|
||||||
@ -63,6 +64,11 @@ namespace Components
|
|||||||
static void RestartCurrentMap();
|
static void RestartCurrentMap();
|
||||||
static void ApplyRotation(RotationData& rotation);
|
static void ApplyRotation(RotationData& rotation);
|
||||||
static void ApplyMapRotationCurrent(const std::string& data);
|
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 RandomizeMapRotation();
|
||||||
|
|
||||||
static void SV_MapRotate_f();
|
static void SV_MapRotate_f();
|
||||||
|
@ -55,6 +55,8 @@ namespace Game
|
|||||||
const dvar_t** sv_cheats = reinterpret_cast<const dvar_t**>(0x2098DE0);
|
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** 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_showSend = reinterpret_cast<const dvar_t**>(0xA1E870);
|
||||||
const dvar_t** cl_voice = reinterpret_cast<const dvar_t**>(0xB2BB44);
|
const dvar_t** cl_voice = reinterpret_cast<const dvar_t**>(0xB2BB44);
|
||||||
const dvar_t** cl_ingame = reinterpret_cast<const dvar_t**>(0xB2BB80);
|
const dvar_t** cl_ingame = reinterpret_cast<const dvar_t**>(0xB2BB80);
|
||||||
|
@ -107,6 +107,8 @@ namespace Game
|
|||||||
extern const dvar_t** sv_cheats;
|
extern const dvar_t** sv_cheats;
|
||||||
extern const dvar_t** sv_voiceQuality;
|
extern const dvar_t** sv_voiceQuality;
|
||||||
|
|
||||||
|
extern const dvar_t** nextmap;
|
||||||
|
|
||||||
extern const dvar_t** cl_showSend;
|
extern const dvar_t** cl_showSend;
|
||||||
extern const dvar_t** cl_voice;
|
extern const dvar_t** cl_voice;
|
||||||
extern const dvar_t** cl_ingame;
|
extern const dvar_t** cl_ingame;
|
||||||
|
Loading…
Reference in New Issue
Block a user