Remove BuildingInfluence from Plug placement.

This commit is contained in:
Paul Chote
2020-10-25 20:01:35 +00:00
committed by Matthias Mailänder
parent 90b25be1b6
commit 79019b06ca
2 changed files with 20 additions and 22 deletions

View File

@@ -81,9 +81,9 @@ namespace OpenRA.Mods.Common.Orders
} }
} }
readonly World world;
readonly ProductionQueue queue; readonly ProductionQueue queue;
readonly PlaceBuildingInfo placeBuildingInfo; readonly PlaceBuildingInfo placeBuildingInfo;
readonly BuildingInfluence buildingInfluence;
readonly ResourceLayer resourceLayer; readonly ResourceLayer resourceLayer;
readonly Viewport viewport; readonly Viewport viewport;
readonly VariantWrapper[] variants; readonly VariantWrapper[] variants;
@@ -91,10 +91,9 @@ namespace OpenRA.Mods.Common.Orders
public PlaceBuildingOrderGenerator(ProductionQueue queue, string name, WorldRenderer worldRenderer) public PlaceBuildingOrderGenerator(ProductionQueue queue, string name, WorldRenderer worldRenderer)
{ {
var world = queue.Actor.World;
this.queue = queue; this.queue = queue;
world = queue.Actor.World;
placeBuildingInfo = queue.Actor.Owner.PlayerActor.Info.TraitInfo<PlaceBuildingInfo>(); placeBuildingInfo = queue.Actor.Owner.PlayerActor.Info.TraitInfo<PlaceBuildingInfo>();
buildingInfluence = world.WorldActor.Trait<BuildingInfluence>();
resourceLayer = world.WorldActor.TraitOrDefault<ResourceLayer>(); resourceLayer = world.WorldActor.TraitOrDefault<ResourceLayer>();
viewport = worldRenderer.Viewport; viewport = worldRenderer.Viewport;
@@ -225,12 +224,12 @@ namespace OpenRA.Mods.Common.Orders
bool AcceptsPlug(CPos cell, PlugInfo plug) bool AcceptsPlug(CPos cell, PlugInfo plug)
{ {
var host = buildingInfluence.GetBuildingAt(cell); foreach (var a in world.ActorMap.GetActorsAt(cell))
if (host == null) foreach (var p in a.TraitsImplementing<Pluggable>())
return false; if (p.AcceptsPlug(a, plug.Type))
return true;
var location = host.Location; return false;
return host.TraitsImplementing<Pluggable>().Any(p => p.AcceptsPlug(host, plug.Type));
} }
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; } IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }

View File

@@ -135,27 +135,26 @@ namespace OpenRA.Mods.Common.Traits
} }
else if (os == "PlacePlug") else if (os == "PlacePlug")
{ {
var host = self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(targetLocation);
if (host == null)
return;
var plugInfo = actorInfo.TraitInfoOrDefault<PlugInfo>(); var plugInfo = actorInfo.TraitInfoOrDefault<PlugInfo>();
if (plugInfo == null) if (plugInfo == null)
return; return;
var location = host.Location; foreach (var a in self.World.ActorMap.GetActorsAt(targetLocation))
var pluggableLocations = host.TraitsImplementing<Pluggable>() {
.Where(p => p.AcceptsPlug(host, plugInfo.Type)); var pluggables = a.TraitsImplementing<Pluggable>()
.Where(p => p.AcceptsPlug(a, plugInfo.Type))
.ToList();
var pluggable = pluggableLocations.FirstOrDefault(p => location + p.Info.Offset == targetLocation) var pluggable = pluggables.FirstOrDefault(p => a.Location + p.Info.Offset == targetLocation)
?? pluggableLocations.FirstOrDefault(); ?? pluggables.FirstOrDefault();
if (pluggable == null) if (pluggable == null)
return; return;
pluggable.EnablePlug(host, plugInfo.Type); pluggable.EnablePlug(a, plugInfo.Type);
foreach (var s in buildingInfo.BuildSounds) foreach (var s in buildingInfo.BuildSounds)
Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, host.CenterPosition); Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, a.CenterPosition);
}
} }
else else
{ {