When changing rally point also make primary building #12855

This commit is contained in:
rob-v
2017-03-17 12:36:32 +01:00
parent b6810f3dd3
commit bfcb37e1b7
2 changed files with 30 additions and 7 deletions

View File

@@ -36,10 +36,14 @@ namespace OpenRA.Mods.Common.Traits
public class RallyPoint : IIssueOrder, IResolveOrder, ISync, INotifyOwnerChanged, INotifyCreated
{
const string OrderID = "SetRallyPoint";
[Sync] public CPos Location;
public RallyPointInfo Info;
public string PaletteName { get; private set; }
const uint ForceSet = 1;
public void ResetLocation(Actor self)
{
Location = self.Location + Info.Offset;
@@ -72,23 +76,30 @@ namespace OpenRA.Mods.Common.Traits
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID == "SetRallyPoint")
return new Order(order.OrderID, self, false) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition), SuppressVisualFeedback = true };
if (order.OrderID == OrderID)
return new Order(order.OrderID, self, false) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition), SuppressVisualFeedback = true,
ExtraData = ((RallyPointOrderTargeter)order).ForceSet ? ForceSet : 0 };
return null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "SetRallyPoint")
if (order.OrderString == OrderID)
Location = order.TargetLocation;
}
public static bool IsForceSet(Order order)
{
return order.OrderString == OrderID && order.ExtraData == ForceSet;
}
class RallyPointOrderTargeter : IOrderTargeter
{
public string OrderID { get { return "SetRallyPoint"; } }
public int OrderPriority { get { return 0; } }
public bool TargetOverridesSelection(TargetModifiers modifiers) { return true; }
public bool ForceSet { get; private set; }
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
@@ -99,6 +110,15 @@ namespace OpenRA.Mods.Common.Traits
if (self.World.Map.Contains(location))
{
cursor = "ability";
// Notify force-set 'RallyPoint' order watchers with Ctrl and only if this is the only building of its type selected
if (modifiers.HasModifier(TargetModifiers.ForceAttack))
{
var selfName = self.Info.Name;
if (!self.World.Selection.Actors.Any(a => a.Info.Name == selfName && a.ActorID != self.ActorID))
ForceSet = true;
}
return true;
}