Remove Order.TargetLocation from building code.

This commit is contained in:
Paul Chote
2018-12-01 11:51:04 +00:00
parent 6dcd23e874
commit d91d96a2e3
2 changed files with 14 additions and 13 deletions

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (order.OrderString == OrderID) if (order.OrderString == OrderID)
Location = order.TargetLocation; Location = self.World.Map.CellContaining(order.Target.CenterPosition);
} }
public static bool IsForceSet(Order order) public static bool IsForceSet(Order order)

View File

@@ -63,6 +63,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var prevItems = GetNumBuildables(self.Owner); var prevItems = GetNumBuildables(self.Owner);
var targetActor = w.GetActorById(order.ExtraData); var targetActor = w.GetActorById(order.ExtraData);
var targetLocation = w.Map.CellContaining(order.Target.CenterPosition);
if (targetActor == null || targetActor.IsDead) if (targetActor == null || targetActor.IsDead)
return; return;
@@ -93,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits
// Build the parent actor first // Build the parent actor first
var placed = w.CreateActor(order.TargetString, new TypeDictionary var placed = w.CreateActor(order.TargetString, new TypeDictionary
{ {
new LocationInit(order.TargetLocation), new LocationInit(targetLocation),
new OwnerInit(order.Player), new OwnerInit(order.Player),
new FactionInit(faction), new FactionInit(faction),
new PlaceBuildingInit() new PlaceBuildingInit()
@@ -107,17 +108,17 @@ namespace OpenRA.Mods.Common.Traits
if (string.IsNullOrEmpty(segmentType)) if (string.IsNullOrEmpty(segmentType))
segmentType = order.TargetString; segmentType = order.TargetString;
foreach (var t in BuildingUtils.GetLineBuildCells(w, order.TargetLocation, actorInfo, buildingInfo)) foreach (var t in BuildingUtils.GetLineBuildCells(w, targetLocation, actorInfo, buildingInfo))
{ {
if (t.First == order.TargetLocation) if (t.First == targetLocation)
continue; continue;
w.CreateActor(t.First == order.TargetLocation ? order.TargetString : segmentType, new TypeDictionary w.CreateActor(t.First == targetLocation ? order.TargetString : segmentType, new TypeDictionary
{ {
new LocationInit(t.First), new LocationInit(t.First),
new OwnerInit(order.Player), new OwnerInit(order.Player),
new FactionInit(faction), new FactionInit(faction),
new LineBuildDirectionInit(t.First.X == order.TargetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X), new LineBuildDirectionInit(t.First.X == targetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X),
new LineBuildParentInit(new[] { t.Second, placed }), new LineBuildParentInit(new[] { t.Second, placed }),
new PlaceBuildingInit() new PlaceBuildingInit()
}); });
@@ -125,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
} }
else if (os == "PlacePlug") else if (os == "PlacePlug")
{ {
var host = self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(order.TargetLocation); var host = self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(targetLocation);
if (host == null) if (host == null)
return; return;
@@ -135,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits
var location = host.Location; var location = host.Location;
var pluggable = host.TraitsImplementing<Pluggable>() var pluggable = host.TraitsImplementing<Pluggable>()
.FirstOrDefault(p => location + p.Info.Offset == order.TargetLocation && p.AcceptsPlug(host, plugInfo.Type)); .FirstOrDefault(p => location + p.Info.Offset == targetLocation && p.AcceptsPlug(host, plugInfo.Type));
if (pluggable == null) if (pluggable == null)
return; return;
@@ -146,15 +147,15 @@ namespace OpenRA.Mods.Common.Traits
} }
else else
{ {
if (!self.World.CanPlaceBuilding(order.TargetLocation, actorInfo, buildingInfo, null) if (!self.World.CanPlaceBuilding(targetLocation, actorInfo, buildingInfo, null)
|| !buildingInfo.IsCloseEnoughToBase(self.World, order.Player, actorInfo, order.TargetLocation)) || !buildingInfo.IsCloseEnoughToBase(self.World, order.Player, actorInfo, targetLocation))
return; return;
var replacementInfo = actorInfo.TraitInfoOrDefault<ReplacementInfo>(); var replacementInfo = actorInfo.TraitInfoOrDefault<ReplacementInfo>();
if (replacementInfo != null) if (replacementInfo != null)
{ {
var buildingInfluence = self.World.WorldActor.Trait<BuildingInfluence>(); var buildingInfluence = self.World.WorldActor.Trait<BuildingInfluence>();
foreach (var t in buildingInfo.Tiles(order.TargetLocation)) foreach (var t in buildingInfo.Tiles(targetLocation))
{ {
var host = buildingInfluence.GetBuildingAt(t); var host = buildingInfluence.GetBuildingAt(t);
if (host != null) if (host != null)
@@ -164,7 +165,7 @@ namespace OpenRA.Mods.Common.Traits
var building = w.CreateActor(order.TargetString, new TypeDictionary var building = w.CreateActor(order.TargetString, new TypeDictionary
{ {
new LocationInit(order.TargetLocation), new LocationInit(targetLocation),
new OwnerInit(order.Player), new OwnerInit(order.Player),
new FactionInit(faction), new FactionInit(faction),
new PlaceBuildingInit() new PlaceBuildingInit()
@@ -184,7 +185,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
// May be null if the build anywhere cheat is active // May be null if the build anywhere cheat is active
// BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location // BuildingInfo.IsCloseEnoughToBase has already verified that this is a valid build location
var provider = buildingInfo.FindBaseProvider(w, self.Owner, order.TargetLocation); var provider = buildingInfo.FindBaseProvider(w, self.Owner, targetLocation);
if (provider != null) if (provider != null)
provider.BeginCooldown(); provider.BeginCooldown();
} }