Index: binaries/data/mods/public/simulation/components/BuildRestrictions.js
===================================================================
--- binaries/data/mods/public/simulation/components/BuildRestrictions.js	(revision 18001)
+++ binaries/data/mods/public/simulation/components/BuildRestrictions.js	(working copy)
@@ -171,30 +171,71 @@
 
 	var pos = cmpPosition.GetPosition2D();
 	var tileOwner = cmpTerritoryManager.GetOwner(pos.x, pos.y);
-	var isOwn = (tileOwner == cmpPlayer.GetPlayerID());
-	var isNeutral = (tileOwner == 0);
-	var isAlly = !isOwn && cmpPlayer.IsAlly(tileOwner);
-	// We count neutral players as enemies, so you can't build in their territory.
-	var isEnemy = !isNeutral && (cmpPlayer.IsEnemy(tileOwner) || cmpPlayer.IsNeutral(tileOwner));
+	var isConnected = cmpTerritoryManager.IsConnected(pos.x, pos.y);
+	if (!isConnected)
+	{
+		// if the area itself isn't connected, check if it's connected to an ally
+		var neighbours = cmpTerritoryManager.GetNeighbours(pos.x, pos.y, true);
+		isConnected = neighbours.some((v, i) => v > 0 && cmpPlayer.IsMutualAlly(i));
+	}
 
-	var territoryFail = true;
+	var isOwn = tileOwner == cmpPlayer.GetPlayerID();
+	var isMutualAlly = cmpPlayer.IsExclusiveMutualAlly(tileOwner);
+	var isNeutral = tileOwner == 0;
+
+	var territoryValid = true;
 	var territoryType = "";
-	if (isAlly && !this.HasTerritory("ally"))
-		// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
-		territoryType = markForTranslationWithContext("Territory type", "ally");
-	else if (isOwn && !this.HasTerritory("own"))
-		// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
-		territoryType = markForTranslationWithContext("Territory type", "own");
-	else if (isNeutral && !this.HasTerritory("neutral"))
-		// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
-		territoryType = markForTranslationWithContext("Territory type", "neutral");
-	else if (isEnemy && !this.HasTerritory("enemy"))
-		// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
-		territoryType = markForTranslationWithContext("Territory type", "enemy");
+	if (isOwn)
+	{
+		if (!this.HasTerritory("own"))
+		{
+			territoryValid = false;
+			// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
+			territoryType = markForTranslationWithContext("Territory type", "own");
+		}
+		else if (!isConnected)
+		{
+			territoryValid = false;
+			// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
+			territoryType = markForTranslationWithContext("Territory type", "unconnected");
+		}
+	}
+	else if (isMutualAlly)
+	{
+		if (!this.HasTerritory("ally"))
+		{
+			territoryValid = false;
+			// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
+			territoryType = markForTranslationWithContext("Territory type", "allied");
+		}
+		else if (!isConnected)
+		{
+			territoryValid = false;
+			// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
+			territoryType = markForTranslationWithContext("Territory type", "unconnected");
+		}
+	}
+	else if (isNeutral)
+	{
+		if (!this.HasTerritory("neutral"))
+		{
+			territoryValid = false;
+			// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
+			territoryType = markForTranslationWithContext("Territory type", "neutral");
+		}
+	}
 	else
-		territoryFail = false;
+	{
+		// consider everything else enemy territory
+		if (!this.HasTerritory("enemy"))
+		{
+			territoryValid = false;
+			// Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
+			territoryType = markForTranslationWithContext("Territory type", "enemy");
+		}
+	}
 
-	if (territoryFail)
+	if (!territoryValid)
 	{
 		result.message = markForTranslation("%(name)s cannot be built in %(territoryType)s territory. Valid territories: %(validTerritories)s");
 		result.translateParameters.push("territoryType");
