1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Respect GUI settings for roads. By default, all road types are enabled.

This commit is contained in:
Tomasz Zieliński 2023-07-08 08:44:10 +02:00
parent 27c4882237
commit 730b36612c
5 changed files with 47 additions and 17 deletions

View File

@ -119,12 +119,11 @@ RandomMapTab::RandomMapTab():
std::string cbRoadType = "selectRoad_" + road->getJsonKey();
addCallback(cbRoadType, [&, road](bool on)
{
mapGenOptions->setRoadEnabled(road->getJsonKey(), on);
mapGenOptions->setRoadEnabled(road->getId(), on);
updateMapInfoByHost();
});
}
build(config);
updateMapInfoByHost();
@ -313,7 +312,7 @@ void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> opts)
{
if(auto w = widget<CToggleButton>(r->getJsonKey()))
{
w->setSelected(opts->isRoadEnabled(r->getJsonKey()));
w->setSelected(opts->isRoadEnabled(r->getId()));
}
}
}

View File

@ -1,3 +1,4 @@
#include "CMapGenOptions.h"
/*
* CMapGenOptions.cpp, part of VCMI engine
*
@ -26,6 +27,9 @@ CMapGenOptions::CMapGenOptions()
waterContent(EWaterContent::RANDOM), monsterStrength(EMonsterStrength::RANDOM), mapTemplate(nullptr)
{
resetPlayersMap();
setRoadEnabled(RoadId(Road::DIRT_ROAD), true);
setRoadEnabled(RoadId(Road::GRAVEL_ROAD), true);
setRoadEnabled(RoadId(Road::COBBLESTONE_ROAD), true);
}
si32 CMapGenOptions::getWidth() const
@ -233,17 +237,26 @@ void CMapGenOptions::setMapTemplate(const std::string & name)
setMapTemplate(VLC->tplh->getTemplate(name));
}
void CMapGenOptions::setRoadEnabled(const std::string & roadName, bool enable)
void CMapGenOptions::setRoadEnabled(const RoadId & roadType, bool enable)
{
if(enable)
disabledRoads.erase(roadName);
if (enable)
{
enabledRoads.insert(roadType);
}
else
disabledRoads.insert(roadName);
{
enabledRoads.erase(roadType);
}
}
bool CMapGenOptions::isRoadEnabled(const std::string & roadName) const
bool CMapGenOptions::isRoadEnabled(const RoadId & roadType) const
{
return !disabledRoads.count(roadName);
return enabledRoads.count(roadType);
}
bool CMapGenOptions::isRoadEnabled() const
{
return !enabledRoads.empty();
}
void CMapGenOptions::setPlayerTeam(const PlayerColor & color, const TeamID & team)

View File

@ -110,8 +110,9 @@ public:
EMonsterStrength::EMonsterStrength getMonsterStrength() const;
void setMonsterStrength(EMonsterStrength::EMonsterStrength value);
bool isRoadEnabled(const std::string & roadName) const;
void setRoadEnabled(const std::string & roadName, bool enable);
bool isRoadEnabled(const RoadId & roadType) const;
bool isRoadEnabled() const;
void setRoadEnabled(const RoadId & roadType, bool enable);
/// The first player colors belong to standard players and the last player colors belong to comp only players.
/// All standard players are by default of type EPlayerType::AI.
@ -156,7 +157,7 @@ private:
EWaterContent::EWaterContent waterContent;
EMonsterStrength::EMonsterStrength monsterStrength;
std::map<PlayerColor, CPlayerSettings> players;
std::set<std::string> disabledRoads;
std::set<RoadId> enabledRoads;
const CRmgTemplate * mapTemplate;
@ -187,7 +188,7 @@ public:
setMapTemplate(templateName);
}
h & disabledRoads;
h & enabledRoads;
}
}
};

View File

@ -80,11 +80,13 @@ void CMapGenerator::loadConfig()
config.pandoraMultiplierSpells = randomMapJson["pandoras"]["valueMultiplierSpells"].Integer();
config.pandoraSpellSchool = randomMapJson["pandoras"]["valueSpellSchool"].Integer();
config.pandoraSpell60 = randomMapJson["pandoras"]["valueSpell60"].Integer();
/*
//override config with game options
if(!mapGenOptions.isRoadEnabled(config.secondaryRoadType))
config.secondaryRoadType = "";
if(!mapGenOptions.isRoadEnabled(config.defaultRoadType))
config.defaultRoadType = config.secondaryRoadType;
*/
config.singleThread = randomMapJson["singleThread"].Bool();
}

View File

@ -79,9 +79,7 @@ bool RoadPlacer::createRoad(const int3 & dst)
}
void RoadPlacer::drawRoads(bool secondary)
{
//TODO: Check road type set in lobby. If no road, return.
{
{
//Clean space under roads even if they won't be eventually generated
Zone::Lock lock(zone.areaMutex);
@ -90,15 +88,32 @@ void RoadPlacer::drawRoads(bool secondary)
zone.freePaths().unite(roads);
}
if (!generator.getMapGenOptions().isRoadEnabled())
{
return;
}
if((secondary && generator.getConfig().secondaryRoadType.empty())
|| (!secondary && generator.getConfig().defaultRoadType.empty()))
return;
//TODO: Allow custom road type for object
//TODO: Remove these default types
auto tiles = roads.getTilesVector();
std::string roadName = (secondary ? generator.getConfig().secondaryRoadType : generator.getConfig().defaultRoadType);
RoadId roadType(*VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "road", roadName));
mapProxy->drawRoads(zone.getRand(), tiles, roadType);
//If our road type is not enabled, choose highest below it
for (int8_t bestRoad = roadType.getNum(); bestRoad > RoadId(Road::NO_ROAD).getNum(); bestRoad--)
{
if (generator.getMapGenOptions().isRoadEnabled(RoadId(bestRoad)))
{
mapProxy->drawRoads(zone.getRand(), tiles, RoadId(bestRoad));
return;
}
}
}
void RoadPlacer::addRoadNode(const int3& node)