1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

First implementation that works

This commit is contained in:
Tomasz Zieliński
2025-03-09 08:16:18 +01:00
parent 946e47ee22
commit 6e7dfc6ee4
2 changed files with 26 additions and 4 deletions

View File

@ -100,6 +100,7 @@ void Modificator::run()
void Modificator::dependency(Modificator * modificator) void Modificator::dependency(Modificator * modificator)
{ {
//TODO: Check for circular dependencies
if(modificator && modificator != this) if(modificator && modificator != this)
{ {
//TODO: use vstd::contains //TODO: use vstd::contains
@ -110,6 +111,7 @@ void Modificator::dependency(Modificator * modificator)
void Modificator::postfunction(Modificator * modificator) void Modificator::postfunction(Modificator * modificator)
{ {
// TODO:Check for circular dependencies
if(modificator && modificator != this) if(modificator && modificator != this)
{ {
if(std::find(modificator->preceeders.begin(), modificator->preceeders.end(), this) == modificator->preceeders.end()) if(std::find(modificator->preceeders.begin(), modificator->preceeders.end(), this) == modificator->preceeders.end())

View File

@ -46,7 +46,25 @@ void TownPlacer::process()
void TownPlacer::init() void TownPlacer::init()
{ {
// TODO: Depend on other zones for(auto & townHint : zone.getTownHints())
{
logGlobal->info("Town hint of zone %d: %d", zone.getId(), townHint.likeZone);
if(townHint.likeZone != rmg::ZoneOptions::NO_ZONE)
{
logGlobal->info("Dependency on town type of zone %d", townHint.likeZone);
dependency(map.getZones().at(townHint.likeZone)->getModificator<TownPlacer>());
}
else if(townHint.notLikeZone != rmg::ZoneOptions::NO_ZONE)
{
logGlobal->info("Dependency on town unlike type of zone %d", townHint.notLikeZone);
dependency(map.getZones().at(townHint.notLikeZone)->getModificator<TownPlacer>());
}
else if(townHint.relatedToZoneTerrain != rmg::ZoneOptions::NO_ZONE)
{
logGlobal->info("Dependency on town related to zone terrain of zone %d", townHint.relatedToZoneTerrain);
dependency(map.getZones().at(townHint.relatedToZoneTerrain)->getModificator<TownPlacer>());
}
}
POSTFUNCTION(MinePlacer); POSTFUNCTION(MinePlacer);
POSTFUNCTION(RoadPlacer); POSTFUNCTION(RoadPlacer);
} }
@ -54,7 +72,6 @@ void TownPlacer::init()
void TownPlacer::placeTowns(ObjectManager & manager) void TownPlacer::placeTowns(ObjectManager & manager)
{ {
// TODO: Configurew each subseqquent town based on townHints // TODO: Configurew each subseqquent town based on townHints
// TODO: First town should be set to type chosen by player
if(zone.getOwner() && ((zone.getType() == ETemplateZoneType::CPU_START) || (zone.getType() == ETemplateZoneType::PLAYER_START))) if(zone.getOwner() && ((zone.getType() == ETemplateZoneType::CPU_START) || (zone.getType() == ETemplateZoneType::PLAYER_START)))
{ {
@ -120,7 +137,7 @@ void TownPlacer::placeTowns(ObjectManager & manager)
} }
else //randomize town types for non-player zones else //randomize town types for non-player zones
{ {
zone.setTownType(getRandomTownType()); zone.setTownType(getTownTypeFromHint(0));
} }
addNewTowns(zone.getNeutralTowns().getCastleCount(), true, PlayerColor::NEUTRAL, manager); addNewTowns(zone.getNeutralTowns().getCastleCount(), true, PlayerColor::NEUTRAL, manager);
@ -128,6 +145,7 @@ void TownPlacer::placeTowns(ObjectManager & manager)
if(!totalTowns) //if there's no town present, get random faction for dwellings and pandoras if(!totalTowns) //if there's no town present, get random faction for dwellings and pandoras
{ {
// TODO: Use townHints also when there are no towns in zone
//25% chance for neutral //25% chance for neutral
if (zone.getRand().nextInt(1, 100) <= 25) if (zone.getRand().nextInt(1, 100) <= 25)
{ {
@ -188,7 +206,9 @@ FactionID TownPlacer::getTownTypeFromHint(size_t hintIndex)
{ {
const auto & hints = zone.getTownHints(); const auto & hints = zone.getTownHints();
if(hints.size() <= hintIndex) if(hints.size() <= hintIndex)
return zone.getTownType(); {
return *RandomGeneratorUtil::nextItem(zone.getTownTypes(), zone.getRand());
}
const auto & townHints = hints[hintIndex]; const auto & townHints = hints[hintIndex];
FactionID subType = zone.getTownType(); FactionID subType = zone.getTownType();