mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
First part of fix for 1712
- implemented recursive search for missing dependencies - todo - update GUI. As of now Gui may provide incorrect information
This commit is contained in:
parent
d918621d66
commit
16eb4b3267
@ -403,20 +403,38 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
|
||||
return EBuildingState::NO_WATER; //lack of water
|
||||
}
|
||||
|
||||
auto buildTest = [&](const BuildingID & id)
|
||||
/// returns true if building prerequisites are fulfilled
|
||||
std::function<bool(BuildingID)> buildTest;
|
||||
|
||||
auto dependTest = [&](BuildingID id) -> bool
|
||||
{
|
||||
return t->hasBuilt(id);
|
||||
const CBuilding * build = t->town->buildings.at(id);
|
||||
|
||||
if (build->upgrade != BuildingID::NONE)
|
||||
{
|
||||
if (!t->hasBuilt(build->upgrade))
|
||||
return false;
|
||||
|
||||
if (!t->town->buildings.at(build->upgrade)->requirements.test(buildTest))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!build->requirements.test(buildTest))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!building->requirements.test(buildTest))
|
||||
buildTest = [&](BuildingID bid)
|
||||
{
|
||||
return t->hasBuilt(bid) && dependTest(bid);
|
||||
};
|
||||
|
||||
if (!dependTest(ID))
|
||||
return EBuildingState::PREREQUIRES;
|
||||
|
||||
if(t->builded >= VLC->modh->settings.MAX_BUILDING_PER_TURN)
|
||||
return EBuildingState::CANT_BUILD_TODAY; //building limit
|
||||
|
||||
if (building->upgrade != BuildingID::NONE && !t->hasBuilt(building->upgrade))
|
||||
return EBuildingState::MISSING_BASE;
|
||||
|
||||
//checking resources
|
||||
if(!building->resources.canBeAfforded(getPlayer(t->tempOwner)->resources))
|
||||
return EBuildingState::NO_RESOURCES; //lack of res
|
||||
|
Loading…
x
Reference in New Issue
Block a user