mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Check if building's dependencies are allowed
This commit is contained in:
@ -520,6 +520,28 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
|
||||
if(vstd::contains(t->forbiddenBuildings, ID))
|
||||
return EBuildingState::FORBIDDEN; //forbidden
|
||||
|
||||
std::function<bool(BuildingID id)> allowedTest;
|
||||
std::function<bool(BuildingID id)> possiblyNotBuiltTest;
|
||||
|
||||
allowedTest = [&](BuildingID id) -> bool
|
||||
{
|
||||
if (vstd::contains(t->forbiddenBuildings, id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return t->genBuildingRequirements(id, true).satisfiable(allowedTest, possiblyNotBuiltTest);
|
||||
};
|
||||
|
||||
possiblyNotBuiltTest = [&](BuildingID id) -> bool
|
||||
{
|
||||
//TODO consider destroing
|
||||
return !t->hasBuilt(id);
|
||||
};
|
||||
|
||||
if (!t->genBuildingRequirements(ID, true).satisfiable(allowedTest, possiblyNotBuiltTest))
|
||||
return EBuildingState::FORBIDDEN;
|
||||
|
||||
if(ID == BuildingID::CAPITOL)
|
||||
{
|
||||
const PlayerState *ps = getPlayer(t->tempOwner, false);
|
||||
|
Reference in New Issue
Block a user