2022-05-25 12:03:26 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class MapRotation : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MapRotation();
|
|
|
|
|
2022-08-24 10:38:14 -04:00
|
|
|
static bool Contains(const std::string& key, const std::string& value);
|
|
|
|
|
2022-06-13 11:32:45 -04:00
|
|
|
bool unitTest() override;
|
|
|
|
|
2022-05-25 12:03:26 -04:00
|
|
|
private:
|
|
|
|
struct ParseRotationError : public std::exception
|
|
|
|
{
|
|
|
|
const char* what() const noexcept override { return "Parse Rotation Error"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class RotationData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using rotationEntry = std::pair<std::string, std::string>;
|
|
|
|
|
|
|
|
RotationData();
|
|
|
|
|
|
|
|
void randomize();
|
|
|
|
|
|
|
|
// In case a new way to enrich the map rotation is added (other than sv_mapRotation)
|
|
|
|
// this method should be called to add a new entry (gamemode/map & value)
|
|
|
|
void addEntry(const std::string& key, const std::string& value);
|
|
|
|
|
2022-12-06 16:18:29 -05:00
|
|
|
[[nodiscard]] std::size_t getEntriesSize() const noexcept;
|
2022-05-25 12:03:26 -04:00
|
|
|
rotationEntry& getNextEntry();
|
|
|
|
|
|
|
|
void parse(const std::string& data);
|
|
|
|
|
2022-12-06 16:18:29 -05:00
|
|
|
[[nodiscard]] bool empty() const noexcept;
|
2022-08-24 10:38:14 -04:00
|
|
|
[[nodiscard]] bool contains(const std::string& key, const std::string& value) const;
|
|
|
|
|
2022-05-25 12:03:26 -04:00
|
|
|
private:
|
2022-06-11 05:55:12 -04:00
|
|
|
std::vector<rotationEntry> rotationEntries_;
|
2022-05-25 12:03:26 -04:00
|
|
|
|
|
|
|
std::size_t index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Rotation Dvars
|
|
|
|
static Dvar::Var SVRandomMapRotation;
|
|
|
|
static Dvar::Var SVDontRotate;
|
|
|
|
|
|
|
|
// Holds the parsed data from sv_mapRotation
|
|
|
|
static RotationData DedicatedRotation;
|
|
|
|
|
|
|
|
static void LoadRotation(const std::string& data);
|
2022-08-24 10:38:14 -04:00
|
|
|
static void LoadMapRotation();
|
2022-05-25 12:03:26 -04:00
|
|
|
|
2022-06-13 11:32:45 -04:00
|
|
|
// Use these commands before SV_MapRotate_f is called
|
|
|
|
static void AddMapRotationCommands();
|
|
|
|
|
2022-05-25 12:03:26 -04:00
|
|
|
static bool ShouldRotate();
|
2022-06-24 15:22:46 -04:00
|
|
|
static void ApplyMap(const std::string& map);
|
|
|
|
static void ApplyGametype(const std::string& gametype);
|
2022-05-25 12:03:26 -04:00
|
|
|
static void RestartCurrentMap();
|
2022-06-24 15:22:46 -04:00
|
|
|
static void ApplyRotation(RotationData& rotation);
|
|
|
|
static void ApplyMapRotationCurrent(const std::string& data);
|
2022-06-16 12:19:51 -04:00
|
|
|
static void RandomizeMapRotation();
|
2022-05-25 12:03:26 -04:00
|
|
|
|
|
|
|
static void SV_MapRotate_f();
|
|
|
|
};
|
|
|
|
}
|