mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Support roads and teams customization in engine
This commit is contained in:
parent
bcf95c32e9
commit
f27a40dd34
@ -230,6 +230,26 @@ void CMapGenOptions::setMapTemplate(const std::string & name)
|
||||
setMapTemplate(VLC->tplh->getTemplate(name));
|
||||
}
|
||||
|
||||
void CMapGenOptions::setRoadEnabled(const std::string & roadName, bool enable)
|
||||
{
|
||||
if(enable)
|
||||
disabledRoads.erase(roadName);
|
||||
else
|
||||
disabledRoads.insert(roadName);
|
||||
}
|
||||
|
||||
bool CMapGenOptions::isRoadEnabled(const std::string & roadName) const
|
||||
{
|
||||
return !disabledRoads.count(roadName);
|
||||
}
|
||||
|
||||
void CMapGenOptions::setPlayerTeam(PlayerColor color, TeamID team)
|
||||
{
|
||||
auto it = players.find(color);
|
||||
if(it == players.end()) assert(0);
|
||||
it->second.setTeam(team);
|
||||
}
|
||||
|
||||
void CMapGenOptions::finalize(CRandomGenerator & rand)
|
||||
{
|
||||
logGlobal->info("RMG map: %dx%d, %s underground", getWidth(), getHeight(), getHasTwoLevels() ? "WITH" : "NO");
|
||||
@ -473,7 +493,7 @@ const CRmgTemplate * CMapGenOptions::getPossibleTemplate(CRandomGenerator & rand
|
||||
return *RandomGeneratorUtil::nextItem(templates, rand);
|
||||
}
|
||||
|
||||
CMapGenOptions::CPlayerSettings::CPlayerSettings() : color(0), startingTown(RANDOM_TOWN), playerType(EPlayerType::AI)
|
||||
CMapGenOptions::CPlayerSettings::CPlayerSettings() : color(0), startingTown(RANDOM_TOWN), playerType(EPlayerType::AI), team(TeamID::NO_TEAM)
|
||||
{
|
||||
|
||||
}
|
||||
@ -515,4 +535,14 @@ void CMapGenOptions::CPlayerSettings::setPlayerType(EPlayerType::EPlayerType val
|
||||
playerType = value;
|
||||
}
|
||||
|
||||
TeamID CMapGenOptions::CPlayerSettings::getTeam() const
|
||||
{
|
||||
return team;
|
||||
}
|
||||
|
||||
void CMapGenOptions::CPlayerSettings::setTeam(TeamID value)
|
||||
{
|
||||
team = value;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -51,6 +51,10 @@ public:
|
||||
/// The default value is EPlayerType::AI.
|
||||
EPlayerType::EPlayerType getPlayerType() const;
|
||||
void setPlayerType(EPlayerType::EPlayerType value);
|
||||
|
||||
/// Team id for this player. TeamID::NO_TEAM by default - team will be randomly assigned
|
||||
TeamID getTeam() const;
|
||||
void setTeam(TeamID value);
|
||||
|
||||
/// Constant for a random town selection.
|
||||
static const si32 RANDOM_TOWN = -1;
|
||||
@ -59,6 +63,7 @@ public:
|
||||
PlayerColor color;
|
||||
si32 startingTown;
|
||||
EPlayerType::EPlayerType playerType;
|
||||
TeamID team;
|
||||
|
||||
public:
|
||||
template <typename Handler>
|
||||
@ -67,6 +72,8 @@ public:
|
||||
h & color;
|
||||
h & startingTown;
|
||||
h & playerType;
|
||||
if(version >= 806)
|
||||
h & team;
|
||||
}
|
||||
};
|
||||
|
||||
@ -105,6 +112,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);
|
||||
|
||||
/// 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.
|
||||
@ -113,6 +123,8 @@ public:
|
||||
/// Sets a player type for a standard player. A standard player is the opposite of a computer only player. The
|
||||
/// values which can be chosen for the player type are EPlayerType::AI or EPlayerType::HUMAN.
|
||||
void setPlayerTypeForStandardPlayer(PlayerColor color, EPlayerType::EPlayerType playerType);
|
||||
|
||||
void setPlayerTeam(PlayerColor color, TeamID team = TeamID::NO_TEAM);
|
||||
|
||||
/// The random map template to generate the map with or empty/not set if the template should be chosen randomly.
|
||||
/// Default: Not set/random.
|
||||
@ -147,6 +159,8 @@ private:
|
||||
EWaterContent::EWaterContent waterContent;
|
||||
EMonsterStrength::EMonsterStrength monsterStrength;
|
||||
std::map<PlayerColor, CPlayerSettings> players;
|
||||
std::set<std::string> disabledRoads;
|
||||
|
||||
const CRmgTemplate * mapTemplate;
|
||||
|
||||
public:
|
||||
@ -168,11 +182,15 @@ public:
|
||||
{
|
||||
templateName = mapTemplate->getId();
|
||||
}
|
||||
//if(version > xxx) do not forget to bump version
|
||||
h & templateName;
|
||||
if(!h.saving)
|
||||
if(version >= 806)
|
||||
{
|
||||
setMapTemplate(templateName);
|
||||
h & templateName;
|
||||
if(!h.saving)
|
||||
{
|
||||
setMapTemplate(templateName);
|
||||
}
|
||||
|
||||
h & disabledRoads;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -76,6 +76,11 @@ 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;
|
||||
}
|
||||
|
||||
const CMapGenerator::Config & CMapGenerator::getConfig() const
|
||||
@ -238,14 +243,21 @@ void CMapGenerator::addPlayerInfo()
|
||||
player.canHumanPlay = true;
|
||||
}
|
||||
|
||||
if (teamNumbers[j].empty())
|
||||
if(pSettings.getTeam() != TeamID::NO_TEAM)
|
||||
{
|
||||
logGlobal->error("Not enough places in team for %s player", ((j == CPUONLY) ? "CPU" : "CPU or human"));
|
||||
assert (teamNumbers[j].size());
|
||||
player.team = pSettings.getTeam();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (teamNumbers[j].empty())
|
||||
{
|
||||
logGlobal->error("Not enough places in team for %s player", ((j == CPUONLY) ? "CPU" : "CPU or human"));
|
||||
assert (teamNumbers[j].size());
|
||||
}
|
||||
auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand);
|
||||
player.team = TeamID(*itTeam);
|
||||
teamNumbers[j].erase(itTeam);
|
||||
}
|
||||
auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand);
|
||||
player.team = TeamID(*itTeam);
|
||||
teamNumbers[j].erase(itTeam);
|
||||
map->map().players[pSettings.getColor().getNum()] = player;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,9 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
void RoadPlacer::process()
|
||||
{
|
||||
if(generator.getConfig().defaultRoadType.empty() && generator.getConfig().secondaryRoadType.empty())
|
||||
return; //do not generate roads at all
|
||||
|
||||
connectRoads();
|
||||
}
|
||||
|
||||
@ -68,6 +71,10 @@ bool RoadPlacer::createRoad(const int3 & dst)
|
||||
|
||||
void RoadPlacer::drawRoads(bool secondary)
|
||||
{
|
||||
if((secondary && generator.getConfig().secondaryRoadType.empty())
|
||||
|| (!secondary && generator.getConfig().defaultRoadType.empty()))
|
||||
return;
|
||||
|
||||
zone.areaPossible().subtract(roads);
|
||||
zone.freePaths().unite(roads);
|
||||
map.getEditManager()->getTerrainSelection().setSelection(roads.getTilesVector());
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
const ui32 SERIALIZATION_VERSION = 805;
|
||||
const ui32 SERIALIZATION_VERSION = 806;
|
||||
const ui32 MINIMAL_SERIALIZATION_VERSION = 805;
|
||||
const std::string SAVEGAME_MAGIC = "VCMISVG";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user