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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user