1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fix RMG to place special dwellings like elemental conflux

This commit is contained in:
Andrii Danylchenko 2022-04-05 20:41:56 +03:00 committed by Andrii Danylchenko
parent 73906d5a97
commit 8b11b42aaf
2 changed files with 43 additions and 32 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
brew update brew update
brew pin python@3.9 #brew pin python@3.9
brew install smpeg2 libpng freetype qt5 ffmpeg@4 ninja boost tbb luajit brew install smpeg2 libpng freetype qt5 ffmpeg@4 ninja boost tbb luajit
brew install sdl2 sdl2_ttf sdl2_image sdl2_mixer brew install sdl2 sdl2_ttf sdl2_image sdl2_mixer

View File

@ -1401,8 +1401,11 @@ bool CRmgTemplateZone::createRequiredObjects()
auto tilesBlockedByObject = obj.first->getBlockedOffsets(); auto tilesBlockedByObject = obj.first->getBlockedOffsets();
bool finished = false; bool finished = false;
while (!finished) bool attempt = true;
while (!finished && attempt)
{ {
attempt = false;
std::vector<int3> tiles(possibleTiles.begin(), possibleTiles.end()); std::vector<int3> tiles(possibleTiles.begin(), possibleTiles.end());
//new tiles vector after each object has been placed, OR misplaced area has been sealed off //new tiles vector after each object has been placed, OR misplaced area has been sealed off
@ -1433,12 +1436,13 @@ bool CRmgTemplateZone::createRequiredObjects()
for (auto tile : tiles) for (auto tile : tiles)
{ {
//code partially adapted from findPlaceForObject() //code partially adapted from findPlaceForObject()
if(areAllTilesAvailable(obj.first, tile, tilesBlockedByObject)) if(areAllTilesAvailable(obj.first, tile, tilesBlockedByObject))
gen->setOccupied(pos, ETileType::BLOCKED); //why? gen->setOccupied(pos, ETileType::BLOCKED); //why?
else else
continue; continue;
attempt = true;
EObjectPlacingResult::EObjectPlacingResult result = tryToPlaceObjectAndConnectToPath(obj.first, tile); EObjectPlacingResult::EObjectPlacingResult result = tryToPlaceObjectAndConnectToPath(obj.first, tile);
if (result == EObjectPlacingResult::SUCCESS) if (result == EObjectPlacingResult::SUCCESS)
{ {
@ -2243,17 +2247,23 @@ void CRmgTemplateZone::addAllPossibleObjects()
oi.maxPerZone = std::numeric_limits<ui32>().max(); oi.maxPerZone = std::numeric_limits<ui32>().max();
//dwellings //dwellings
auto dwellingTypes = {Obj::CREATURE_GENERATOR1, Obj::CREATURE_GENERATOR4};
auto subObjects = VLC->objtypeh->knownSubObjects(Obj::CREATURE_GENERATOR1); for(auto dwellingType : dwellingTypes)
{
auto subObjects = VLC->objtypeh->knownSubObjects(dwellingType);
if(dwellingType == Obj::CREATURE_GENERATOR1)
{
//don't spawn original "neutral" dwellings that got replaced by Conflux dwellings in AB //don't spawn original "neutral" dwellings that got replaced by Conflux dwellings in AB
static int elementalConfluxROE[] = {7, 13, 16, 47}; static int elementalConfluxROE[] = {7, 13, 16, 47};
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
vstd::erase_if_present(subObjects, elementalConfluxROE[i]); vstd::erase_if_present(subObjects, elementalConfluxROE[i]);
}
for(auto secondaryID : subObjects) for(auto secondaryID : subObjects)
{ {
auto dwellingHandler = dynamic_cast<const CDwellingInstanceConstructor*>(VLC->objtypeh->getHandlerFor(Obj::CREATURE_GENERATOR1, secondaryID).get()); auto dwellingHandler = dynamic_cast<const CDwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(dwellingType, secondaryID).get());
auto creatures = dwellingHandler->getProducedCreatures(); auto creatures = dwellingHandler->getProducedCreatures();
if(creatures.empty()) if(creatures.empty())
continue; continue;
@ -2265,23 +2275,24 @@ void CRmgTemplateZone::addAllPossibleObjects()
oi.value = static_cast<ui32>(cre->AIValue * cre->growth * (1 + (nativeZonesCount / gen->getTotalZoneCount()) + (nativeZonesCount / 2))); oi.value = static_cast<ui32>(cre->AIValue * cre->growth * (1 + (nativeZonesCount / gen->getTotalZoneCount()) + (nativeZonesCount / 2)));
oi.probability = 40; oi.probability = 40;
for (auto temp : dwellingHandler->getTemplates()) for(auto tmplate : dwellingHandler->getTemplates())
{ {
if (temp.canBePlacedAt(terrainType)) if(tmplate.canBePlacedAt(terrainType))
{ {
oi.generateObject = [temp, secondaryID]() -> CGObjectInstance * oi.generateObject = [tmplate, secondaryID, dwellingType]() -> CGObjectInstance *
{ {
auto obj = VLC->objtypeh->getHandlerFor(Obj::CREATURE_GENERATOR1, secondaryID)->create(temp); auto obj = VLC->objtypeh->getHandlerFor(dwellingType, secondaryID)->create(tmplate);
obj->tempOwner = PlayerColor::NEUTRAL; obj->tempOwner = PlayerColor::NEUTRAL;
return obj; return obj;
}; };
oi.templ = temp; oi.templ = tmplate;
possibleObjects.push_back(oi); possibleObjects.push_back(oi);
} }
} }
} }
} }
}
static const int scrollValues[] = { 500, 2000, 3000, 4000, 5000 }; static const int scrollValues[] = { 500, 2000, 3000, 4000, 5000 };