1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Do not allow building boat if there is already boat with hero in it

This commit is contained in:
Ivan Savenko
2023-11-28 15:49:03 +02:00
parent d326c53b9a
commit 9277761da5

View File

@ -89,11 +89,23 @@ int3 IBoatGenerator::bestLocation() const
int3 targetTile = getObject()->visitablePos() + offset;
const TerrainTile *tile = getObject()->cb->getTile(targetTile, false);
if(tile) //tile is in the map
if(!tile)
continue; // tile not visible / outside the map
if(!tile->terType->isWater())
continue;
if (tile->blocked)
{
if(tile->terType->isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat
return targetTile;
bool hasBoat = false;
for (auto const * object : tile->blockingObjects)
if (object->ID == Obj::BOAT || object->ID == Obj::HERO)
hasBoat = true;
if (!hasBoat)
continue; // tile is blocked, but not by boat -> check next potential position
}
return targetTile;
}
return int3 (-1,-1,-1);
}
@ -112,7 +124,7 @@ IBoatGenerator::EGeneratorState IBoatGenerator::shipyardStatus() const
if(t->blockingObjects.empty())
return GOOD; //OK
if(t->blockingObjects.front()->ID == Obj::BOAT)
if(t->blockingObjects.front()->ID == Obj::BOAT || t->blockingObjects.front()->ID == Obj::HERO)
return BOAT_ALREADY_BUILT; //blocked with boat
return TILE_BLOCKED; //blocked