瀏覽代碼

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

Ivan Savenko 1 年之前
父節點
當前提交
9277761da5
共有 1 個文件被更改,包括 16 次插入4 次删除
  1. 16 4
      lib/mapObjects/IObjectInterface.cpp

+ 16 - 4
lib/mapObjects/IObjectInterface.cpp

@@ -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