Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions src/xrGame/UIGameCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,18 @@ void CMapListHelper::Load()
{
string_path cfgFileName;
FS.update_path(cfgFileName, "$game_config$", "mp" DELIMITER "map_list.ltx");
if (!FS.exist(cfgFileName))
{
Log("~ Can't open MP map list:", cfgFileName);
return;
}

CInifile maplistCfg(cfgFileName);
if (!maplistCfg.section_exist("weather"))
{
Log("~ MP map list has no [weather] section:", cfgFileName);
return;
}
// read weathers set
CInifile::Sect weatherCfg = maplistCfg.r_section("weather");
m_weathers.reserve(weatherCfg.Data.size());
Expand Down Expand Up @@ -468,17 +479,27 @@ void CMapListHelper::Load()
FS.unload_archive(arch);
}
levelsPath->_set_root(prevRoot.c_str());
// XXX nitrocaster: is that really fatal?
R_ASSERT2(m_storage.size() > 0, "unable to fill map list");
R_ASSERT2(m_weathers.size() > 0, "unable to fill weathers list");
if (m_storage.empty())
Log("! Unable to fill MP map list (no maps discovered).");
if (m_weathers.empty())
Log("! Unable to fill MP weather list (no weather presets discovered).");
}

const SGameTypeMaps& CMapListHelper::GetMapListFor(const shared_str& gameType)
{
if (m_storage.size() == 0)
Load();
// XXX nitrocaster: always use enum for game type representation
return *GetMapListInt(gameType);
if (auto* maps = GetMapListInt(gameType))
return *maps;

static SGameTypeMaps empty{};
if (!empty.m_game_type_name.size())
{
empty.m_game_type_name = "unknown";
empty.m_game_type_id = eGameIDNoGame;
}
return empty;
}

SGameTypeMaps* CMapListHelper::GetMapListInt(const shared_str& gameType)
Expand All @@ -496,8 +517,16 @@ const SGameTypeMaps& CMapListHelper::GetMapListFor(const EGameIDs gameId)
if (m_storage.size() == 0)
{
Load();
// XXX nitrocaster: is that really fatal?
R_ASSERT2(m_storage.size() > 0, "unable to fill map list");
}
if (m_storage.empty())
{
static SGameTypeMaps empty{};
if (!empty.m_game_type_name.size())
{
empty.m_game_type_name = "unknown";
empty.m_game_type_id = eGameIDNoGame;
}
return empty;
}
for (SGameTypeMaps& maps : m_storage)
{
Expand All @@ -509,7 +538,7 @@ const SGameTypeMaps& CMapListHelper::GetMapListFor(const EGameIDs gameId)

const xr_vector<MPWeatherDesc>& CMapListHelper::GetGameWeathers()
{
if (m_weathers.size() == 0)
if (m_weathers.empty())
Load();
return m_weathers;
}
Loading