diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index 8b40d7631f..970392fab0 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -99,6 +99,16 @@ namespace OpenRA.Mods.Common.Traits if (buildableInfo != null && buildableInfo.ForceFaction != null) faction = buildableInfo.ForceFaction; + var replaceableTypes = actorInfo.TraitInfos() + .SelectMany(r => r.ReplaceableTypes) + .ToHashSet(); + + if (replaceableTypes.Any()) + foreach (var t in buildingInfo.Tiles(targetLocation)) + foreach (var a in self.World.ActorMap.GetActorsAt(t)) + if (a.TraitsImplementing().Any(r => !r.IsTraitDisabled && r.Info.Types.Overlaps(replaceableTypes))) + self.World.Remove(a); + if (os == "LineBuild") { // Build the parent actor first @@ -123,7 +133,17 @@ namespace OpenRA.Mods.Common.Traits if (t.Cell == targetLocation) continue; - w.CreateActor(t.Cell == targetLocation ? actorInfo.Name : segmentType, new TypeDictionary + var segment = self.World.Map.Rules.Actors[segmentType]; + var replaceableSegments = segment.TraitInfos() + .SelectMany(r => r.ReplaceableTypes) + .ToHashSet(); + + if (replaceableSegments.Any()) + foreach (var a in self.World.ActorMap.GetActorsAt(t.Cell)) + if (a.TraitsImplementing().Any(r => !r.IsTraitDisabled && r.Info.Types.Overlaps(replaceableSegments))) + self.World.Remove(a); + + w.CreateActor(segmentType, new TypeDictionary { new LocationInit(t.Cell), new OwnerInit(order.Player), @@ -163,16 +183,6 @@ namespace OpenRA.Mods.Common.Traits || !buildingInfo.IsCloseEnoughToBase(self.World, order.Player, actorInfo, targetLocation)) return; - var replaceableTypes = actorInfo.TraitInfos() - .SelectMany(r => r.ReplaceableTypes) - .ToHashSet(); - - if (replaceableTypes.Any()) - foreach (var t in buildingInfo.Tiles(targetLocation)) - foreach (var a in self.World.ActorMap.GetActorsAt(t)) - if (a.TraitsImplementing().Any(r => !r.IsTraitDisabled && r.Info.Types.Overlaps(replaceableTypes))) - self.World.Remove(a); - var building = w.CreateActor(actorInfo.Name, new TypeDictionary { new LocationInit(targetLocation),