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:
Gustas
2023-01-20 21:29:50 +02:00
committed by Matthias Mailänder
parent ad683d9226
commit dc390a7301
13 changed files with 76 additions and 25 deletions

View File

@@ -206,6 +206,8 @@ namespace OpenRA.Mods.Cnc.Traits
public Activity ReturnToCell(Actor self) { return null; }
public Activity MoveToTarget(Actor self, in Target target,
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 LocalMove(Actor self, WPos fromPos, WPos toPos) { return null; }

View File

@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Activities
}
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));
return true;
}

View File

@@ -62,12 +62,13 @@ namespace OpenRA.Mods.Common.Activities
proc = harv.LinkedProc;
var iao = proc.Trait<IAcceptResources>();
if (self.Location != proc.Location + iao.DeliveryOffset)
if (self.CenterPosition != iao.DeliveryPosition)
{
foreach (var n in notifyHarvesterActions)
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;
}

View File

@@ -131,10 +131,10 @@ namespace OpenRA.Mods.Common.Activities
var lastproc = harv.LastLinkedProc ?? harv.LinkedProc;
if (lastproc != null && !lastproc.Disposed)
{
var deliveryLoc = lastproc.Location + lastproc.Trait<IAcceptResources>().DeliveryOffset;
if (self.Location == deliveryLoc && harv.IsEmpty)
var deliveryLoc = lastproc.Trait<IAcceptResources>().DeliveryPosition;
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);
QueueChild(mobile.MoveTo(moveTo, 1));
}
@@ -246,10 +246,10 @@ namespace OpenRA.Mods.Common.Activities
CPos? GetSearchFromProcLocation()
{
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)
return harv.LinkedProc.Location + harv.LinkedProc.Trait<IAcceptResources>().DeliveryOffset;
return harv.LinkedProc.World.Map.CellContaining(harv.LinkedProc.Trait<IAcceptResources>().DeliveryPosition);
return null;
}

View File

@@ -22,14 +22,12 @@ namespace OpenRA.Mods.Common.Activities
{
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 Refinery Refinery;
protected readonly WithDockingOverlay DockHostSpriteOverlay;
protected readonly Harvester Harv;
protected readonly IDockClientBody DockClientBody;
protected readonly WAngle DockAngle;
protected readonly bool IsDragRequired;
protected readonly WVec DragOffset;
protected readonly int DragLength;
@@ -45,11 +43,9 @@ namespace OpenRA.Mods.Common.Activities
public HarvesterDockSequence(Actor self, Actor refineryActor, Refinery refinery)
{
dockingState = DockingState.Turn;
Refinery = refinery;
dockingState = DockingState.Drag;
RefineryActor = refineryActor;
DockHostSpriteOverlay = refineryActor.TraitOrDefault<WithDockingOverlay>();
DockAngle = refinery.DeliveryAngle;
IsDragRequired = refinery.IsDragRequired;
DragOffset = refinery.DragOffset;
DragLength = refinery.DragLength;
@@ -68,11 +64,6 @@ namespace OpenRA.Mods.Common.Activities
case DockingState.Wait:
return false;
case DockingState.Turn:
dockingState = DockingState.Drag;
QueueChild(new Turn(self, DockAngle));
return false;
case DockingState.Drag:
if (IsCanceling || !RefineryActor.IsInWorld || RefineryActor.IsDead || Harv.IsTraitDisabled)
return true;

View 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;
}
}
}

View File

@@ -132,12 +132,13 @@ namespace OpenRA.Mods.Common.Activities
else if (activeResupplyTypes != 0 && aircraft == null && !isCloseEnough)
{
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.
// TODO: Get rid of this or at least replace it with something less hacky.
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;
transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell);

View File

@@ -935,6 +935,11 @@ namespace OpenRA.Mods.Common.Traits
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)
{
// TODO: Ignore repulsion when moving

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
bool preventDock = false;
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 bool IsDragRequired => info.IsDragRequired;
public WVec DragOffset => info.DragOffset;

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor)
{
var iao = refineryActor.Trait<IAcceptResources>();
var location = refineryActor.Location + iao.DeliveryOffset;
var location = self.World.Map.CellContaining(iao.DeliveryPosition);
foreach (var t in transports)
t.RequestTransport(self, location);
}

View File

@@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Traits
.Where(r => r.Actor != ignore && r.Actor.Owner == self.Owner && IsAcceptableProcType(r.Actor))
.Select(r => new
{
Location = r.Actor.Location + r.Trait.DeliveryOffset,
Location = r.Actor.World.Map.CellContaining(r.Trait.DeliveryPosition),
Actor = r.Actor,
Occupancy = self.World.ActorsHavingTrait<Harvester>(h => h.LinkedProc == r.Actor).Count()
})

View File

@@ -704,6 +704,11 @@ namespace OpenRA.Mods.Common.Traits
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)
{
return WrapMove(LocalMove(self, fromPos, toPos, self.Location));

View File

@@ -271,7 +271,8 @@ namespace OpenRA.Mods.Common.Traits
{
void OnDock(Actor harv, DeliverResources dockOrder);
int AcceptResources(string resourceType, int count = 1);
CVec DeliveryOffset { get; }
WPos DeliveryPosition { get; }
WAngle DeliveryAngle { get; }
bool AllowDocking { get; }
}
@@ -455,6 +456,8 @@ namespace OpenRA.Mods.Common.Traits
WPos? initialTargetPosition = null, Color? targetLineColor = null);
Activity ReturnToCell(Actor self);
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);
int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos);
CPos NearestMoveableCell(CPos target);