Rework Carryall drop-off queueing and ordering.

This commit is contained in:
tovl
2019-04-14 10:31:44 +02:00
committed by reaperrr
parent a403d9937d
commit 0b747ba927
5 changed files with 170 additions and 179 deletions

View File

@@ -35,13 +35,29 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Radius around the target drop location that are considered if the target tile is blocked.")]
public readonly WDist DropRange = WDist.FromCells(5);
[Desc("Cursor to display when able to unload the passengers.")]
public readonly string UnloadCursor = "deploy";
[Desc("Cursor to display when unable to unload the passengers.")]
public readonly string UnloadBlockedCursor = "deploy-blocked";
[Desc("Allow moving and unloading with one order using force-move")]
public readonly bool AllowDropOff = false;
[Desc("Cursor to display when able to drop off the passengers at location.")]
public readonly string DropOffCursor = "ability";
[Desc("Cursor to display when unable to drop off the passengers at location.")]
public readonly string DropOffBlockedCursor = "move-blocked";
[VoiceReference]
public readonly string Voice = "Action";
public virtual object Create(ActorInitializer init) { return new Carryall(init.Self, this); }
}
public class Carryall : INotifyKilled, ISync, ITick, IRender, INotifyActorDisposing, IIssueOrder, IResolveOrder, IOrderVoice
public class Carryall : INotifyKilled, ISync, ITick, IRender, INotifyActorDisposing, IIssueOrder, IResolveOrder,
IOrderVoice, IIssueDeployOrder
{
public enum CarryallState
{
@@ -52,9 +68,11 @@ namespace OpenRA.Mods.Common.Traits
public readonly CarryallInfo Info;
readonly AircraftInfo aircraftInfo;
readonly Aircraft aircraft;
readonly BodyOrientation body;
readonly IMove move;
readonly IFacing facing;
readonly Actor self;
// The actor we are currently carrying.
[Sync] public Actor Carryable { get; private set; }
@@ -74,9 +92,11 @@ namespace OpenRA.Mods.Common.Traits
State = CarryallState.Idle;
aircraftInfo = self.Info.TraitInfoOrDefault<AircraftInfo>();
aircraft = self.Trait<Aircraft>();
body = self.Trait<BodyOrientation>();
move = self.Trait<IMove>();
facing = self.Trait<IFacing>();
this.self = self;
}
void ITick.Tick(Actor self)
@@ -143,6 +163,7 @@ namespace OpenRA.Mods.Common.Traits
self.World.ScreenMap.AddOrUpdate(self);
CarryableOffset = OffsetForCarryable(self, carryable);
aircraft.AddLandingOffset(-CarryableOffset.Z);
return true;
}
@@ -152,6 +173,7 @@ namespace OpenRA.Mods.Common.Traits
self.World.ScreenMap.AddOrUpdate(self);
carryablePreview = null;
aircraft.SubtractLandingOffset(-CarryableOffset.Z);
CarryableOffset = WVec.Zero;
}
@@ -219,14 +241,22 @@ namespace OpenRA.Mods.Common.Traits
yield return b;
}
// Check if we can drop the unit at our current location.
public bool CanUnload()
{
var localOffset = CarryableOffset.Rotate(body.QuantizeOrientation(self, self.Orientation));
var targetCell = self.World.Map.CellContaining(self.CenterPosition + body.LocalToWorld(localOffset));
return Carryable != null && Carryable.Trait<IPositionable>().CanEnterCell(targetCell, self);
}
IEnumerable<IOrderTargeter> IIssueOrder.Orders
{
get
{
if (State != CarryallState.Carrying)
yield return new CarryallPickupOrderTargeter();
else
yield return new CarryallDeliverUnitTargeter(aircraftInfo, CarryableOffset);
yield return new CarryallPickupOrderTargeter();
yield return new DeployOrderTargeter("Unload", 10,
() => CanUnload() ? Info.UnloadCursor : Info.UnloadBlockedCursor);
yield return new CarryallDeliverUnitTargeter(aircraftInfo, Info, CarryableOffset);
}
}
@@ -238,43 +268,43 @@ namespace OpenRA.Mods.Common.Traits
return null;
}
Order IIssueDeployOrder.IssueDeployOrder(Actor self, bool queued)
{
return new Order("Unload", self, queued);
}
bool IIssueDeployOrder.CanIssueDeployOrder(Actor self) { return true; }
void IResolveOrder.ResolveOrder(Actor self, Order order)
{
if (State == CarryallState.Carrying)
if (order.OrderString == "DeliverUnit")
{
if (order.OrderString == "DeliverUnit")
{
var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
if (!aircraftInfo.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
return;
var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
if (!aircraftInfo.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
return;
var targetLocation = move.NearestMoveableCell(cell);
self.SetTargetLine(Target.FromCell(self.World, targetLocation), Color.Yellow);
self.QueueActivity(order.Queued, new DeliverUnit(self, targetLocation));
}
else if (order.OrderString == "Unload")
{
var targetLocation = move.NearestMoveableCell(self.Location);
self.SetTargetLine(Target.FromCell(self.World, targetLocation), Color.Yellow);
self.QueueActivity(order.Queued, new DeliverUnit(self, targetLocation));
}
var targetLocation = move.NearestMoveableCell(cell);
self.SetTargetLine(Target.FromCell(self.World, targetLocation), Color.Yellow);
self.QueueActivity(order.Queued, new DeliverUnit(self, targetLocation));
}
else
else if (order.OrderString == "Unload")
{
if (order.OrderString == "PickupUnit")
{
if (order.Target.Type != TargetType.Actor)
return;
if (!order.Queued && !CanUnload())
return;
if (!ReserveCarryable(self, order.Target.Actor))
return;
self.QueueActivity(order.Queued, new DeliverUnit(self));
}
if (!order.Queued)
self.CancelActivity();
if (order.OrderString == "PickupUnit")
{
if (order.Target.Type != TargetType.Actor)
return;
self.SetTargetLine(order.Target, Color.Yellow);
self.QueueActivity(order.Queued, new PickupUnit(self, order.Target.Actor, Info.LoadingDelay));
}
if (!order.Queued)
self.CancelActivity();
self.SetTargetLine(order.Target, Color.Yellow);
self.QueueActivity(order.Queued, new PickupUnit(self, order.Target.Actor, Info.LoadingDelay));
}
}
@@ -327,41 +357,46 @@ namespace OpenRA.Mods.Common.Traits
class CarryallDeliverUnitTargeter : AircraftMoveOrderTargeter
{
readonly AircraftInfo aircraftInfo;
readonly CarryallInfo info;
readonly WVec carryableOffset;
public CarryallDeliverUnitTargeter(AircraftInfo aircraftInfo, WVec carryableOffset)
public CarryallDeliverUnitTargeter(AircraftInfo aircraftInfo, CarryallInfo info, WVec carryableOffset)
: base(aircraftInfo)
{
OrderID = "DeliverUnit";
OrderPriority = 6;
this.carryableOffset = carryableOffset;
this.aircraftInfo = aircraftInfo;
this.info = info;
}
public override bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
{
if (modifiers.HasModifier(TargetModifiers.ForceMove))
if (!info.AllowDropOff || !modifiers.HasModifier(TargetModifiers.ForceMove))
return false;
cursor = info.DropOffCursor;
var type = target.Type;
if (type == TargetType.Actor && self == target.Actor)
{
var altitude = self.World.Map.DistanceAboveTerrain(self.CenterPosition);
if (altitude.Length - carryableOffset.Z < aircraftInfo.MinAirborneAltitude)
{
cursor = "deploy";
OrderID = "Unload";
return true;
}
}
else if ((type == TargetType.Actor && target.Actor.Info.HasTraitInfo<BuildingInfo>())
if ((type == TargetType.Actor && target.Actor.Info.HasTraitInfo<BuildingInfo>())
|| (target.Type == TargetType.FrozenActor && target.FrozenActor.Info.HasTraitInfo<BuildingInfo>()))
{
cursor = "move-blocked";
cursor = info.DropOffBlockedCursor;
return true;
}
return base.CanTarget(self, target, othersAtTarget, ref modifiers, ref cursor);
var location = self.World.Map.CellContaining(target.CenterPosition);
var explored = self.Owner.Shroud.IsExplored(location);
cursor = self.World.Map.Contains(location) ?
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? info.DropOffCursor) :
info.DropOffBlockedCursor;
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
if (!explored && !aircraftInfo.MoveIntoShroud)
cursor = info.DropOffBlockedCursor;
return true;
}
}
}