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

Fixed two recursive infinite loops in case of alternate buildings.

* introduced in https://github.com/vcmi/vcmi/pull/211
This commit is contained in:
AlexVinS 2016-10-15 04:19:47 +03:00
parent cf143cd257
commit f760e22707
2 changed files with 11 additions and 10 deletions

View File

@ -539,12 +539,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
std::function<bool(BuildingID id)> allowedTest = [&](BuildingID id) -> bool
{
if (vstd::contains(t->forbiddenBuildings, id))
{
return false;
}
return t->genBuildingRequirements(id, true).satisfiable(allowedTest, possiblyNotBuiltTest);
return !vstd::contains(t->forbiddenBuildings, id);
};
if (!t->genBuildingRequirements(ID, true).satisfiable(allowedTest, possiblyNotBuiltTest))

View File

@ -1128,7 +1128,8 @@ CBuilding::TRequired CGTownInstance::genBuildingRequirements(BuildingID buildID,
{
const CBuilding * building = town->buildings.at(buildID);
deep = false;//FIXME: deep test crashes with alternate buildings
//TODO: find better solution to prevent infinite loops
std::set<BuildingID> processed;
std::function<CBuilding::TRequired::Variant(const BuildingID &)> dependTest =
[&](const BuildingID & id) -> CBuilding::TRequired::Variant
@ -1144,10 +1145,14 @@ CBuilding::TRequired CGTownInstance::genBuildingRequirements(BuildingID buildID,
return id;
}
if (build->upgrade != BuildingID::NONE)
requirements.expressions.push_back(dependTest(build->upgrade));
if(!vstd::contains(processed, id))
{
processed.insert(id);
if (build->upgrade != BuildingID::NONE)
requirements.expressions.push_back(dependTest(build->upgrade));
requirements.expressions.push_back(build->requirements.morph(dependTest));
requirements.expressions.push_back(build->requirements.morph(dependTest));
}
return requirements;
};
@ -1157,6 +1162,7 @@ CBuilding::TRequired CGTownInstance::genBuildingRequirements(BuildingID buildID,
const CBuilding * upgr = town->buildings.at(building->upgrade);
requirements.expressions.push_back(dependTest(upgr->bid));
processed.clear();
}
requirements.expressions.push_back(building->requirements.morph(dependTest));