Add IMove.MoveOntoTarget interface
In `TraitsInterfaces` we expose offset as WPos instead of CPos. In an upcoming PR we'll translate the same change to yaml.
This commit is contained in:
committed by
Matthias Mailänder
parent
ad683d9226
commit
dc390a7301
@@ -206,6 +206,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
public Activity ReturnToCell(Actor self) { return null; }
|
public Activity ReturnToCell(Actor self) { return null; }
|
||||||
public Activity MoveToTarget(Actor self, in Target target,
|
public Activity MoveToTarget(Actor self, in Target target,
|
||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
|
||||||
|
public Activity MoveOntoTarget(Actor self, in Target target, in WVec offset,
|
||||||
|
WAngle? facing, Color? targetLineColor = null) { return null; }
|
||||||
public Activity MoveIntoTarget(Actor self, in Target target) { return null; }
|
public Activity MoveIntoTarget(Actor self, in Target target) { return null; }
|
||||||
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos) { return null; }
|
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos) { return null; }
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
}
|
}
|
||||||
|
|
||||||
aircraft.MakeReservation(dest);
|
aircraft.MakeReservation(dest);
|
||||||
QueueChild(new Land(self, Target.FromActor(dest), offset, facing, Color.Green));
|
QueueChild(aircraft.MoveOntoTarget(self, Target.FromActor(dest), offset, facing, Color.Green));
|
||||||
QueueChild(new Resupply(self, dest, WDist.Zero, alwaysLand));
|
QueueChild(new Resupply(self, dest, WDist.Zero, alwaysLand));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,12 +62,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
proc = harv.LinkedProc;
|
proc = harv.LinkedProc;
|
||||||
var iao = proc.Trait<IAcceptResources>();
|
var iao = proc.Trait<IAcceptResources>();
|
||||||
|
|
||||||
if (self.Location != proc.Location + iao.DeliveryOffset)
|
if (self.CenterPosition != iao.DeliveryPosition)
|
||||||
{
|
{
|
||||||
foreach (var n in notifyHarvesterActions)
|
foreach (var n in notifyHarvesterActions)
|
||||||
n.MovingToRefinery(self, proc);
|
n.MovingToRefinery(self, proc);
|
||||||
|
|
||||||
QueueChild(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0));
|
var target = Target.FromActor(proc);
|
||||||
|
QueueChild(movement.MoveOntoTarget(self, target, iao.DeliveryPosition - proc.CenterPosition, iao.DeliveryAngle));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,10 +131,10 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var lastproc = harv.LastLinkedProc ?? harv.LinkedProc;
|
var lastproc = harv.LastLinkedProc ?? harv.LinkedProc;
|
||||||
if (lastproc != null && !lastproc.Disposed)
|
if (lastproc != null && !lastproc.Disposed)
|
||||||
{
|
{
|
||||||
var deliveryLoc = lastproc.Location + lastproc.Trait<IAcceptResources>().DeliveryOffset;
|
var deliveryLoc = lastproc.Trait<IAcceptResources>().DeliveryPosition;
|
||||||
if (self.Location == deliveryLoc && harv.IsEmpty)
|
if (self.CenterPosition == deliveryLoc && harv.IsEmpty)
|
||||||
{
|
{
|
||||||
var unblockCell = deliveryLoc + harv.Info.UnblockCell;
|
var unblockCell = self.World.Map.CellContaining(deliveryLoc) + harv.Info.UnblockCell;
|
||||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
||||||
QueueChild(mobile.MoveTo(moveTo, 1));
|
QueueChild(mobile.MoveTo(moveTo, 1));
|
||||||
}
|
}
|
||||||
@@ -246,10 +246,10 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
CPos? GetSearchFromProcLocation()
|
CPos? GetSearchFromProcLocation()
|
||||||
{
|
{
|
||||||
if (harv.LastLinkedProc != null && !harv.LastLinkedProc.IsDead && harv.LastLinkedProc.IsInWorld)
|
if (harv.LastLinkedProc != null && !harv.LastLinkedProc.IsDead && harv.LastLinkedProc.IsInWorld)
|
||||||
return harv.LastLinkedProc.Location + harv.LastLinkedProc.Trait<IAcceptResources>().DeliveryOffset;
|
return harv.LastLinkedProc.World.Map.CellContaining(harv.LastLinkedProc.Trait<IAcceptResources>().DeliveryPosition);
|
||||||
|
|
||||||
if (harv.LinkedProc != null && !harv.LinkedProc.IsDead && harv.LinkedProc.IsInWorld)
|
if (harv.LinkedProc != null && !harv.LinkedProc.IsDead && harv.LinkedProc.IsInWorld)
|
||||||
return harv.LinkedProc.Location + harv.LinkedProc.Trait<IAcceptResources>().DeliveryOffset;
|
return harv.LinkedProc.World.Map.CellContaining(harv.LinkedProc.Trait<IAcceptResources>().DeliveryPosition);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public class HarvesterDockSequence : Activity
|
public class HarvesterDockSequence : Activity
|
||||||
{
|
{
|
||||||
protected enum DockingState { Wait, Turn, Drag, Dock, Loop, Undock, Complete }
|
protected enum DockingState { Wait, Drag, Dock, Loop, Undock, Complete }
|
||||||
|
|
||||||
protected readonly Actor RefineryActor;
|
protected readonly Actor RefineryActor;
|
||||||
protected readonly Refinery Refinery;
|
|
||||||
protected readonly WithDockingOverlay DockHostSpriteOverlay;
|
protected readonly WithDockingOverlay DockHostSpriteOverlay;
|
||||||
protected readonly Harvester Harv;
|
protected readonly Harvester Harv;
|
||||||
protected readonly IDockClientBody DockClientBody;
|
protected readonly IDockClientBody DockClientBody;
|
||||||
protected readonly WAngle DockAngle;
|
|
||||||
protected readonly bool IsDragRequired;
|
protected readonly bool IsDragRequired;
|
||||||
protected readonly WVec DragOffset;
|
protected readonly WVec DragOffset;
|
||||||
protected readonly int DragLength;
|
protected readonly int DragLength;
|
||||||
@@ -45,11 +43,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public HarvesterDockSequence(Actor self, Actor refineryActor, Refinery refinery)
|
public HarvesterDockSequence(Actor self, Actor refineryActor, Refinery refinery)
|
||||||
{
|
{
|
||||||
dockingState = DockingState.Turn;
|
dockingState = DockingState.Drag;
|
||||||
Refinery = refinery;
|
|
||||||
RefineryActor = refineryActor;
|
RefineryActor = refineryActor;
|
||||||
DockHostSpriteOverlay = refineryActor.TraitOrDefault<WithDockingOverlay>();
|
DockHostSpriteOverlay = refineryActor.TraitOrDefault<WithDockingOverlay>();
|
||||||
DockAngle = refinery.DeliveryAngle;
|
|
||||||
IsDragRequired = refinery.IsDragRequired;
|
IsDragRequired = refinery.IsDragRequired;
|
||||||
DragOffset = refinery.DragOffset;
|
DragOffset = refinery.DragOffset;
|
||||||
DragLength = refinery.DragLength;
|
DragLength = refinery.DragLength;
|
||||||
@@ -68,11 +64,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
case DockingState.Wait:
|
case DockingState.Wait:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case DockingState.Turn:
|
|
||||||
dockingState = DockingState.Drag;
|
|
||||||
QueueChild(new Turn(self, DockAngle));
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case DockingState.Drag:
|
case DockingState.Drag:
|
||||||
if (IsCanceling || !RefineryActor.IsInWorld || RefineryActor.IsDead || Harv.IsTraitDisabled)
|
if (IsCanceling || !RefineryActor.IsInWorld || RefineryActor.IsDead || Harv.IsTraitDisabled)
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
43
OpenRA.Mods.Common/Activities/Move/MoveOntoAndTurn.cs
Normal file
43
OpenRA.Mods.Common/Activities/Move/MoveOntoAndTurn.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright (c) The OpenRA Developers and Contributors
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Activities
|
||||||
|
{
|
||||||
|
public class MoveOntoAndTurn : MoveOnto
|
||||||
|
{
|
||||||
|
readonly WAngle? desiredFacing;
|
||||||
|
|
||||||
|
public MoveOntoAndTurn(Actor self, in Target target, in WVec offset, WAngle? desiredFacing, Color? targetLineColor = null)
|
||||||
|
: base(self, target, offset, null, targetLineColor)
|
||||||
|
{
|
||||||
|
this.desiredFacing = desiredFacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (base.Tick(self))
|
||||||
|
{
|
||||||
|
if (!IsCanceling && desiredFacing.HasValue && desiredFacing.Value != Mobile.Facing)
|
||||||
|
{
|
||||||
|
QueueChild(new Turn(self, desiredFacing.Value));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -132,12 +132,13 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
else if (activeResupplyTypes != 0 && aircraft == null && !isCloseEnough)
|
else if (activeResupplyTypes != 0 && aircraft == null && !isCloseEnough)
|
||||||
{
|
{
|
||||||
var targetCell = self.World.Map.CellContaining(host.Actor.CenterPosition);
|
var targetCell = self.World.Map.CellContaining(host.Actor.CenterPosition);
|
||||||
QueueChild(move.MoveWithinRange(host, closeEnough, targetLineColor: moveInfo.GetTargetLineColor()));
|
|
||||||
|
|
||||||
// HACK: Repairable needs the actor to move to host center.
|
// HACK: Repairable needs the actor to move to host center.
|
||||||
// TODO: Get rid of this or at least replace it with something less hacky.
|
// TODO: Get rid of this or at least replace it with something less hacky.
|
||||||
if (repairableNear == null)
|
if (repairableNear == null)
|
||||||
QueueChild(move.MoveTo(targetCell, targetLineColor: moveInfo.GetTargetLineColor()));
|
QueueChild(move.MoveOntoTarget(self, host, WVec.Zero, null, moveInfo.GetTargetLineColor()));
|
||||||
|
else
|
||||||
|
QueueChild(move.MoveWithinRange(host, closeEnough, targetLineColor: moveInfo.GetTargetLineColor()));
|
||||||
|
|
||||||
var delta = (self.CenterPosition - host.CenterPosition).LengthSquared;
|
var delta = (self.CenterPosition - host.CenterPosition).LengthSquared;
|
||||||
transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell);
|
transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell);
|
||||||
|
|||||||
@@ -935,6 +935,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return new Land(self, target);
|
return new Land(self, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Activity MoveOntoTarget(Actor self, in Target target, in WVec offset, WAngle? facing, Color? targetLineColor = null)
|
||||||
|
{
|
||||||
|
return new Land(self, target, offset, facing, targetLineColor);
|
||||||
|
}
|
||||||
|
|
||||||
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos)
|
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos)
|
||||||
{
|
{
|
||||||
// TODO: Ignore repulsion when moving
|
// TODO: Ignore repulsion when moving
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool preventDock = false;
|
bool preventDock = false;
|
||||||
|
|
||||||
public bool AllowDocking => !preventDock;
|
public bool AllowDocking => !preventDock;
|
||||||
public CVec DeliveryOffset => info.DockOffset;
|
public WPos DeliveryPosition => self.World.Map.CenterOfCell(self.Location + info.DockOffset);
|
||||||
public WAngle DeliveryAngle => info.DockAngle;
|
public WAngle DeliveryAngle => info.DockAngle;
|
||||||
public bool IsDragRequired => info.IsDragRequired;
|
public bool IsDragRequired => info.IsDragRequired;
|
||||||
public WVec DragOffset => info.DragOffset;
|
public WVec DragOffset => info.DragOffset;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor)
|
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor)
|
||||||
{
|
{
|
||||||
var iao = refineryActor.Trait<IAcceptResources>();
|
var iao = refineryActor.Trait<IAcceptResources>();
|
||||||
var location = refineryActor.Location + iao.DeliveryOffset;
|
var location = self.World.Map.CellContaining(iao.DeliveryPosition);
|
||||||
foreach (var t in transports)
|
foreach (var t in transports)
|
||||||
t.RequestTransport(self, location);
|
t.RequestTransport(self, location);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
.Where(r => r.Actor != ignore && r.Actor.Owner == self.Owner && IsAcceptableProcType(r.Actor))
|
.Where(r => r.Actor != ignore && r.Actor.Owner == self.Owner && IsAcceptableProcType(r.Actor))
|
||||||
.Select(r => new
|
.Select(r => new
|
||||||
{
|
{
|
||||||
Location = r.Actor.Location + r.Trait.DeliveryOffset,
|
Location = r.Actor.World.Map.CellContaining(r.Trait.DeliveryPosition),
|
||||||
Actor = r.Actor,
|
Actor = r.Actor,
|
||||||
Occupancy = self.World.ActorsHavingTrait<Harvester>(h => h.LinkedProc == r.Actor).Count()
|
Occupancy = self.World.ActorsHavingTrait<Harvester>(h => h.LinkedProc == r.Actor).Count()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -704,6 +704,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return WrapMove(new LocalMoveIntoTarget(self, target, new WDist(512)));
|
return WrapMove(new LocalMoveIntoTarget(self, target, new WDist(512)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Activity MoveOntoTarget(Actor self, in Target target, in WVec offset, WAngle? facing, Color? targetLineColor = null)
|
||||||
|
{
|
||||||
|
return WrapMove(new MoveOntoAndTurn(self, target, offset, facing, targetLineColor));
|
||||||
|
}
|
||||||
|
|
||||||
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos)
|
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos)
|
||||||
{
|
{
|
||||||
return WrapMove(LocalMove(self, fromPos, toPos, self.Location));
|
return WrapMove(LocalMove(self, fromPos, toPos, self.Location));
|
||||||
|
|||||||
@@ -271,7 +271,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
void OnDock(Actor harv, DeliverResources dockOrder);
|
void OnDock(Actor harv, DeliverResources dockOrder);
|
||||||
int AcceptResources(string resourceType, int count = 1);
|
int AcceptResources(string resourceType, int count = 1);
|
||||||
CVec DeliveryOffset { get; }
|
WPos DeliveryPosition { get; }
|
||||||
|
WAngle DeliveryAngle { get; }
|
||||||
bool AllowDocking { get; }
|
bool AllowDocking { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,6 +456,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
WPos? initialTargetPosition = null, Color? targetLineColor = null);
|
WPos? initialTargetPosition = null, Color? targetLineColor = null);
|
||||||
Activity ReturnToCell(Actor self);
|
Activity ReturnToCell(Actor self);
|
||||||
Activity MoveIntoTarget(Actor self, in Target target);
|
Activity MoveIntoTarget(Actor self, in Target target);
|
||||||
|
Activity MoveOntoTarget(Actor self, in Target target, in WVec offset,
|
||||||
|
WAngle? facing, Color? targetLineColor = null);
|
||||||
Activity LocalMove(Actor self, WPos fromPos, WPos toPos);
|
Activity LocalMove(Actor self, WPos fromPos, WPos toPos);
|
||||||
int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos);
|
int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos);
|
||||||
CPos NearestMoveableCell(CPos target);
|
CPos NearestMoveableCell(CPos target);
|
||||||
|
|||||||
Reference in New Issue
Block a user