Extended IMove for Enter logic
This commit is contained in:
@@ -206,9 +206,12 @@ namespace OpenRA.Traits
|
|||||||
Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange);
|
Activity MoveWithinRange(Target target, WRange minRange, WRange maxRange);
|
||||||
Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange);
|
Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange);
|
||||||
Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any);
|
Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any);
|
||||||
|
Activity MoveToTarget(Actor self, Target target);
|
||||||
|
Activity MoveIntoTarget(Actor self, Target target);
|
||||||
Activity VisualMove(Actor self, WPos fromPos, WPos toPos);
|
Activity VisualMove(Actor self, WPos fromPos, WPos toPos);
|
||||||
CPos NearestMoveableCell(CPos target);
|
CPos NearestMoveableCell(CPos target);
|
||||||
bool IsMoving { get; set; }
|
bool IsMoving { get; set; }
|
||||||
|
bool CanEnterTargetNow(Actor self, Target target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); }
|
public interface INotifyBlockingMove { void OnNotifyBlockingMove(Actor self, Actor blocking); }
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
if (afld == null)
|
if (afld == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var res = afld.Trait<Reservable>();
|
var res = afld.TraitOrDefault<Reservable>();
|
||||||
|
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
@@ -204,6 +204,18 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true) { return SubCell.Invalid; } // Does not use any subcell
|
public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true) { return SubCell.Invalid; } // Does not use any subcell
|
||||||
public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true) { return true; }
|
public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true) { return true; }
|
||||||
|
|
||||||
|
public bool CanEnterTargetNow(Actor self, Target target)
|
||||||
|
{
|
||||||
|
if (target.Positions.Any(p => self.World.ActorMap.GetUnitsAt(self.World.Map.CellContaining(p)).Any(a => a != self && a != target.Actor)))
|
||||||
|
return false;
|
||||||
|
var res = target.Actor.TraitOrDefault<Reservable>();
|
||||||
|
if (res == null)
|
||||||
|
return true;
|
||||||
|
UnReserve();
|
||||||
|
Reservation = res.Reserve(target.Actor, self, this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public int MovementSpeed
|
public int MovementSpeed
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -153,6 +154,12 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
return new HeliFly(self, Target.FromCell(self.World, cell, subCell));
|
return new HeliFly(self, Target.FromCell(self.World, cell, subCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Activity MoveIntoTarget(Actor self, Target target) { return new HeliLand(false); }
|
||||||
|
public Activity MoveToTarget(Actor self, Target target)
|
||||||
|
{
|
||||||
|
return Util.SequenceActivities(new HeliFly(self, target), new Turn(Info.InitialFacing));
|
||||||
|
}
|
||||||
|
|
||||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||||
{
|
{
|
||||||
// TODO: Ignore repulsion when moving
|
// TODO: Ignore repulsion when moving
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -129,5 +130,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|
|
||||||
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any) { return new Fly(self, Target.FromCell(self.World, cell)); }
|
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any) { return new Fly(self, Target.FromCell(self.World, cell)); }
|
||||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) { return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos))); }
|
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) { return Util.SequenceActivities(new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos))); }
|
||||||
|
public Activity MoveToTarget(Actor self, Target target) { return new Fly(self, target, WRange.FromCells(3), WRange.FromCells(5)); }
|
||||||
|
public Activity MoveIntoTarget(Actor self, Target target) { return new Land(target); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -660,18 +660,38 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
SetPosition(self, cell, subCell);
|
SetPosition(self, cell, subCell);
|
||||||
SetVisualPosition(self, pos);
|
SetVisualPosition(self, pos);
|
||||||
|
|
||||||
// Animate transition
|
return VisualMove(self, pos, self.World.Map.CenterOfSubCell(cell, subCell), cell);
|
||||||
var to = self.World.Map.CenterOfSubCell(cell, subCell);
|
}
|
||||||
var speed = MovementSpeedForCell(self, cell);
|
|
||||||
var length = speed > 0 ? (to - pos).Length / speed : 0;
|
|
||||||
|
|
||||||
var facing = Util.GetFacing(to - pos, Facing);
|
public Activity MoveToTarget(Actor self, Target target)
|
||||||
return Util.SequenceActivities(new Turn(facing), new Drag(pos, to, length));
|
{
|
||||||
|
if (target.Type == TargetType.Invalid)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new MoveAdjacentTo(self, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Activity MoveIntoTarget(Actor self, Target target)
|
||||||
|
{
|
||||||
|
if (target.Type == TargetType.Invalid)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return VisualMove(self, self.CenterPosition, target.CenterPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CanEnterTargetNow(Actor self, Target target)
|
||||||
|
{
|
||||||
|
return self.Location == self.World.Map.CellContaining(target.CenterPosition) || Util.AdjacentCells(self.World, target).Any(c => c == self.Location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||||
{
|
{
|
||||||
var speed = MovementSpeedForCell(self, self.Location);
|
return VisualMove(self, fromPos, toPos, self.Location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos, CPos cell)
|
||||||
|
{
|
||||||
|
var speed = MovementSpeedForCell(self, cell);
|
||||||
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
||||||
|
|
||||||
var facing = Util.GetFacing(toPos - fromPos, Facing);
|
var facing = Util.GetFacing(toPos - fromPos, Facing);
|
||||||
|
|||||||
Reference in New Issue
Block a user