From 023750db0640da0b9a0d93d48b8090b96ef19fc1 Mon Sep 17 00:00:00 2001 From: Abdurrahmaan Iqbal Date: Mon, 14 Oct 2019 18:50:48 +0100 Subject: [PATCH] Prevent showing wall connections in unexplored terrain --- OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs | 5 +++-- OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs | 7 ++++--- OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 4f5c0c6a41..aa1b33eae9 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -244,6 +244,7 @@ namespace OpenRA.Mods.Common.Orders var plugInfo = activeVariant.PlugInfo; var lineBuildInfo = activeVariant.LineBuildInfo; var preview = activeVariant.Preview; + var owner = queue.Actor.Owner; if (plugInfo != null) { @@ -252,7 +253,7 @@ namespace OpenRA.Mods.Common.Orders footprint.Add(topLeft, MakeCellType(AcceptsPlug(topLeft, plugInfo))); } - else if (lineBuildInfo != null) + else if (lineBuildInfo != null && owner.Shroud.IsExplored(topLeft)) { // Linebuild for walls. if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1) @@ -260,7 +261,7 @@ namespace OpenRA.Mods.Common.Orders if (!Game.GetModifierKeys().HasModifier(Modifiers.Shift)) { - foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, actorInfo, buildingInfo)) + foreach (var t in BuildingUtils.GetLineBuildCells(world, topLeft, actorInfo, buildingInfo, owner)) { var lineBuildable = world.IsCellBuildable(t.First, actorInfo, buildingInfo); var lineCloseEnough = buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, actorInfo, t.First); diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs index 91d207aa19..2ea563fb0b 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits world.IsCellBuildable(t, ai, bi, toIgnore)); } - public static IEnumerable> GetLineBuildCells(World world, CPos cell, ActorInfo ai, BuildingInfo bi) + public static IEnumerable> GetLineBuildCells(World world, CPos cell, ActorInfo ai, BuildingInfo bi, Player owner) { var lbi = ai.TraitInfo(); var topLeft = cell; // 1x1 assumption! @@ -81,9 +81,10 @@ namespace OpenRA.Mods.Common.Traits if (dirs[d] != 0) continue; + // Continue the search if the cell is empty or not visible var c = topLeft + i * vecs[d]; - if (world.IsCellBuildable(c, ai, bi)) - continue; // Cell is empty; continue search + if (world.IsCellBuildable(c, ai, bi) || !owner.Shroud.IsExplored(c)) + continue; // Cell contains an actor. Is it the type we want? connectors[d] = world.ActorMap.GetActorsAt(c) diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index fc6852e3c3..d9463790b4 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Traits if (string.IsNullOrEmpty(segmentType)) segmentType = actorInfo.Name; - foreach (var t in BuildingUtils.GetLineBuildCells(w, targetLocation, actorInfo, buildingInfo)) + foreach (var t in BuildingUtils.GetLineBuildCells(w, targetLocation, actorInfo, buildingInfo, order.Player)) { if (t.First == targetLocation) continue;