mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Simplify code, fix AI not building dwelling upgrades
This commit is contained in:
@@ -18,36 +18,36 @@ namespace NKAI
|
||||
|
||||
void BuildAnalyzer::updateTownDwellings(TownDevelopmentInfo & developmentInfo)
|
||||
{
|
||||
std::map<BuildingID, BuildingID> parentMap;
|
||||
|
||||
for(auto &pair : developmentInfo.town->getTown()->buildings)
|
||||
{
|
||||
if(pair.second->upgrade != BuildingID::NONE)
|
||||
{
|
||||
parentMap[pair.second->upgrade] = pair.first;
|
||||
}
|
||||
}
|
||||
|
||||
for(int level = 0; level < developmentInfo.town->getTown()->creatures.size(); level++)
|
||||
{
|
||||
logAi->trace("Checking dwelling level %d", level);
|
||||
std::vector<BuildingID> dwellingsInTown;
|
||||
|
||||
for(BuildingID buildID = BuildingID::getDwellingFromLevel(level, 0); buildID.hasValue(); BuildingID::advanceDwelling(buildID))
|
||||
if(developmentInfo.town->getTown()->buildings.count(buildID) != 0)
|
||||
dwellingsInTown.push_back(buildID);
|
||||
|
||||
// find best, already built dwelling
|
||||
for (const auto & buildID : boost::adaptors::reverse(dwellingsInTown))
|
||||
{
|
||||
if(developmentInfo.town->getTown()->buildings.count(buildID) == 0)
|
||||
continue; // no such building in town
|
||||
|
||||
auto info = getBuildingOrPrerequisite(developmentInfo.town, buildID);
|
||||
|
||||
if (!info.exists && !info.canBuild && !info.notEnoughRes)
|
||||
if (!developmentInfo.town->hasBuilt(buildID))
|
||||
continue;
|
||||
|
||||
if(info.exists)
|
||||
developmentInfo.addExistingDwelling(info);
|
||||
else
|
||||
developmentInfo.addBuildingToBuild(info);
|
||||
|
||||
const auto & info = getBuildingOrPrerequisite(developmentInfo.town, buildID);
|
||||
developmentInfo.addExistingDwelling(info);
|
||||
break;
|
||||
}
|
||||
|
||||
// find all non-built dwellings that can be built and add them for consideration
|
||||
for (const auto & buildID : dwellingsInTown)
|
||||
{
|
||||
if (developmentInfo.town->hasBuilt(buildID))
|
||||
continue;
|
||||
|
||||
const auto & info = getBuildingOrPrerequisite(developmentInfo.town, buildID);
|
||||
if (info.canBuild || info.notEnoughRes)
|
||||
developmentInfo.addBuildingToBuild(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user