Remove Replacable actors for LineBuild too.

This commit is contained in:
Mustafa Alperen Seki
2022-03-04 20:44:18 +03:00
committed by abcdefg30
parent a7004b2db7
commit 2f1edd4516

View File

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