Merge pull request #6208 from atlimit8/FixUnloadCargo
Fixed UnloadCargo stacking using new subcell API exposure
This commit is contained in:
@@ -63,12 +63,13 @@ namespace OpenRA
|
|||||||
public CPos Value(World world) { return value; }
|
public CPos Value(World world) { return value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubCellInit : IActorInit<int>
|
public class SubCellInit : IActorInit<SubCell>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey] public readonly int value = 0;
|
[FieldFromYamlKey] public readonly int value = (int)SubCell.FullCell;
|
||||||
public SubCellInit() { }
|
public SubCellInit() { }
|
||||||
public SubCellInit(int init) { value = init; }
|
public SubCellInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public SubCellInit(SubCell init) { value = (int)init; }
|
||||||
|
public SubCell Value(World world) { return (SubCell)value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CenterPositionInit : IActorInit<WPos>
|
public class CenterPositionInit : IActorInit<WPos>
|
||||||
|
|||||||
@@ -79,7 +79,10 @@ namespace OpenRA
|
|||||||
public readonly TileShape TileShape;
|
public readonly TileShape TileShape;
|
||||||
[FieldLoader.Ignore]
|
[FieldLoader.Ignore]
|
||||||
public readonly WVec[] SubCellOffsets;
|
public readonly WVec[] SubCellOffsets;
|
||||||
public readonly int SubCellDefaultIndex;
|
public readonly SubCell DefaultSubCell;
|
||||||
|
public readonly SubCell LastSubCell;
|
||||||
|
|
||||||
|
public WVec OffsetOfSubCell(SubCell subCell) { return SubCellOffsets[(int)subCell]; }
|
||||||
|
|
||||||
[FieldLoader.LoadUsing("LoadOptions")]
|
[FieldLoader.LoadUsing("LoadOptions")]
|
||||||
public MapOptions Options;
|
public MapOptions Options;
|
||||||
@@ -250,7 +253,8 @@ namespace OpenRA
|
|||||||
MapResources = Exts.Lazy(() => LoadResourceTiles());
|
MapResources = Exts.Lazy(() => LoadResourceTiles());
|
||||||
TileShape = Game.modData.Manifest.TileShape;
|
TileShape = Game.modData.Manifest.TileShape;
|
||||||
SubCellOffsets = Game.modData.Manifest.SubCellOffsets;
|
SubCellOffsets = Game.modData.Manifest.SubCellOffsets;
|
||||||
SubCellDefaultIndex = Game.modData.Manifest.SubCellDefaultIndex;
|
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
|
||||||
|
DefaultSubCell = (SubCell)Game.modData.Manifest.SubCellDefaultIndex;
|
||||||
|
|
||||||
// The Uid is calculated from the data on-disk, so
|
// The Uid is calculated from the data on-disk, so
|
||||||
// format changes must be flushed to disk.
|
// format changes must be flushed to disk.
|
||||||
@@ -494,6 +498,14 @@ namespace OpenRA
|
|||||||
return new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), 0);
|
return new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WPos CenterOfSubCell(CPos cell, SubCell subCell)
|
||||||
|
{
|
||||||
|
var index = (int)subCell;
|
||||||
|
if (index >= 0 && index <= SubCellOffsets.Length)
|
||||||
|
return CenterOfCell(cell) + SubCellOffsets[index];
|
||||||
|
return CenterOfCell(cell);
|
||||||
|
}
|
||||||
|
|
||||||
public CPos CellContaining(WPos pos)
|
public CPos CellContaining(WPos pos)
|
||||||
{
|
{
|
||||||
if (TileShape == TileShape.Rectangle)
|
if (TileShape == TileShape.Rectangle)
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ namespace OpenRA.Traits
|
|||||||
int generation;
|
int generation;
|
||||||
|
|
||||||
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
|
public static Target FromPos(WPos p) { return new Target { pos = p, type = TargetType.Terrain }; }
|
||||||
public static Target FromCell(World w, CPos c) { return new Target { pos = w.Map.CenterOfCell(c), type = TargetType.Terrain }; }
|
public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell)
|
||||||
|
{
|
||||||
|
return new Target { pos = w.Map.CenterOfSubCell(c, subCell), type = TargetType.Terrain };
|
||||||
|
}
|
||||||
|
|
||||||
public static Target FromOrder(World w, Order o)
|
public static Target FromOrder(World w, Order o)
|
||||||
{
|
{
|
||||||
return o.TargetActor != null
|
return o.TargetActor != null
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
WPos CenterPosition { get; }
|
WPos CenterPosition { get; }
|
||||||
CPos TopLeft { get; }
|
CPos TopLeft { get; }
|
||||||
IEnumerable<Pair<CPos, int>> OccupiedCells();
|
IEnumerable<Pair<CPos, SubCell>> OccupiedCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IOccupySpaceExts
|
public static class IOccupySpaceExts
|
||||||
@@ -187,9 +187,11 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public interface IPositionable : IOccupySpace
|
public interface IPositionable : IOccupySpace
|
||||||
{
|
{
|
||||||
bool CanEnterCell(CPos location);
|
bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any);
|
||||||
bool CanEnterCell(CPos location, Actor ignoreActor, bool checkTransientActors);
|
bool CanEnterCell(CPos location, Actor ignoreActor = null, bool checkTransientActors = true);
|
||||||
void SetPosition(Actor self, CPos cell);
|
SubCell GetValidSubCell(SubCell preferred = SubCell.Any);
|
||||||
|
SubCell GetAvailableSubCell(CPos location, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true);
|
||||||
|
void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any);
|
||||||
void SetPosition(Actor self, WPos pos);
|
void SetPosition(Actor self, WPos pos);
|
||||||
void SetVisualPosition(Actor self, WPos pos);
|
void SetVisualPosition(Actor self, WPos pos);
|
||||||
}
|
}
|
||||||
@@ -202,7 +204,7 @@ namespace OpenRA.Traits
|
|||||||
Activity MoveWithinRange(Target target, WRange range);
|
Activity MoveWithinRange(Target target, WRange range);
|
||||||
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);
|
Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any);
|
||||||
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; }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
public enum SubCell { FullCell, TopLeft, TopRight, Center, BottomLeft, BottomRight }
|
public enum SubCell { Invalid = int.MinValue, Any = int.MinValue / 2, FullCell = 0, First = 1 }
|
||||||
|
|
||||||
public class ActorMapInfo : ITraitInfo
|
public class ActorMapInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Traits
|
|||||||
class InfluenceNode
|
class InfluenceNode
|
||||||
{
|
{
|
||||||
public InfluenceNode Next;
|
public InfluenceNode Next;
|
||||||
public int SubCell;
|
public SubCell SubCell;
|
||||||
public Actor Actor;
|
public Actor Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,42 +73,80 @@ namespace OpenRA.Traits
|
|||||||
yield return i.Actor;
|
yield return i.Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> GetUnitsAt(CPos a, int sub)
|
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub)
|
||||||
{
|
{
|
||||||
if (!map.Contains(a))
|
if (!map.Contains(a))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
for (var i = influence[a]; i != null; i = i.Next)
|
for (var i = influence[a]; i != null; i = i.Next)
|
||||||
if (!i.Actor.Destroyed && (i.SubCell == sub || i.SubCell == 0))
|
if (!i.Actor.Destroyed && (i.SubCell == sub || i.SubCell == SubCell.FullCell))
|
||||||
yield return i.Actor;
|
yield return i.Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasFreeSubCell(CPos a)
|
public bool HasFreeSubCell(CPos a, bool checkTransient = true)
|
||||||
{
|
{
|
||||||
return FreeSubCell(a) >= 0;
|
return FreeSubCell(a, SubCell.Any, checkTransient) != SubCell.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int FreeSubCell(CPos a)
|
public SubCell FreeSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, bool checkTransient = true)
|
||||||
{
|
{
|
||||||
|
if (preferredSubCell > SubCell.Any && !AnyUnitsAt(a, preferredSubCell, checkTransient))
|
||||||
|
return preferredSubCell;
|
||||||
|
|
||||||
if (!AnyUnitsAt(a))
|
if (!AnyUnitsAt(a))
|
||||||
return map.SubCellDefaultIndex;
|
return map.DefaultSubCell;
|
||||||
|
|
||||||
for (var i = 1; i < map.SubCellOffsets.Length; i++)
|
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
||||||
if (!AnyUnitsAt(a, i))
|
if (i != (int)preferredSubCell && !AnyUnitsAt(a, (SubCell)i, checkTransient))
|
||||||
return i;
|
return (SubCell)i;
|
||||||
return -1;
|
return SubCell.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubCell FreeSubCell(CPos a, SubCell preferredSubCell, Func<Actor, bool> checkIfBlocker)
|
||||||
|
{
|
||||||
|
if (preferredSubCell > SubCell.Any && !AnyUnitsAt(a, preferredSubCell, checkIfBlocker))
|
||||||
|
return preferredSubCell;
|
||||||
|
|
||||||
|
if (!AnyUnitsAt(a))
|
||||||
|
return map.DefaultSubCell;
|
||||||
|
|
||||||
|
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
||||||
|
if (i != (int)preferredSubCell && !AnyUnitsAt(a, (SubCell)i, checkIfBlocker))
|
||||||
|
return (SubCell)i;
|
||||||
|
return SubCell.Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: always includes transients with influence
|
||||||
public bool AnyUnitsAt(CPos a)
|
public bool AnyUnitsAt(CPos a)
|
||||||
{
|
{
|
||||||
return influence[a] != null;
|
return influence[a] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AnyUnitsAt(CPos a, int sub)
|
// NOTE: can not check aircraft
|
||||||
|
public bool AnyUnitsAt(CPos a, SubCell sub, bool checkTransient = true)
|
||||||
{
|
{
|
||||||
|
bool always = sub == SubCell.FullCell || sub == SubCell.Any;
|
||||||
for (var i = influence[a]; i != null; i = i.Next)
|
for (var i = influence[a]; i != null; i = i.Next)
|
||||||
if (i.SubCell == sub || i.SubCell == 0)
|
if (always || i.SubCell == sub || i.SubCell == SubCell.FullCell)
|
||||||
return true;
|
{
|
||||||
|
if (checkTransient)
|
||||||
|
return true;
|
||||||
|
var pos = i.Actor.TraitOrDefault<IPositionable>();
|
||||||
|
if (pos == null || !pos.IsLeavingCell(a, i.SubCell))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: can not check aircraft
|
||||||
|
public bool AnyUnitsAt(CPos a, SubCell sub, Func<Actor, bool> withCondition)
|
||||||
|
{
|
||||||
|
bool always = sub == SubCell.FullCell || sub == SubCell.Any;
|
||||||
|
for (var i = influence[a]; i != null; i = i.Next)
|
||||||
|
if (always || i.SubCell == sub || i.SubCell == SubCell.FullCell)
|
||||||
|
if (withCondition(i.Actor))
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
mobile.IsMoving = true;
|
mobile.IsMoving = true;
|
||||||
|
|
||||||
from = self.CenterPosition;
|
from = self.CenterPosition;
|
||||||
to = self.World.Map.CenterOfCell(targetMobile.fromCell) + self.World.Map.SubCellOffsets[targetMobile.fromSubCell];
|
to = self.World.Map.CenterOfSubCell(targetMobile.fromCell, targetMobile.fromSubCell);
|
||||||
length = Math.Max((to - from).Length / speed.Range, 1);
|
length = Math.Max((to - from).Length / speed.Range, 1);
|
||||||
|
|
||||||
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Activities
|
namespace OpenRA.Mods.RA.Activities
|
||||||
@@ -30,14 +32,15 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
this.unloadAll = unloadAll;
|
this.unloadAll = unloadAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos? ChooseExitCell(Actor passenger)
|
public Pair<CPos, SubCell>? ChooseExitSubCell(Actor passenger)
|
||||||
{
|
{
|
||||||
var pos = passenger.Trait<IPositionable>();
|
var pos = passenger.Trait<IPositionable>();
|
||||||
|
|
||||||
return cargo.CurrentAdjacentCells
|
return cargo.CurrentAdjacentCells
|
||||||
.Shuffle(self.World.SharedRandom)
|
.Shuffle(self.World.SharedRandom)
|
||||||
.Cast<CPos?>()
|
.Select(c => Pair.New(c, pos.GetAvailableSubCell(c)))
|
||||||
.FirstOrDefault(c => pos.CanEnterCell(c.Value));
|
.Cast<Pair<CPos, SubCell>?>()
|
||||||
|
.FirstOrDefault(s => s.Value.Second != SubCell.Invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<CPos> BlockedExitCells(Actor passenger)
|
IEnumerable<CPos> BlockedExitCells(Actor passenger)
|
||||||
@@ -60,8 +63,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
var actor = cargo.Peek(self);
|
var actor = cargo.Peek(self);
|
||||||
var spawn = self.CenterPosition;
|
var spawn = self.CenterPosition;
|
||||||
|
|
||||||
var exitCell = ChooseExitCell(actor);
|
var exitSubCell = ChooseExitSubCell(actor);
|
||||||
if (exitCell == null)
|
if (exitSubCell == null)
|
||||||
{
|
{
|
||||||
foreach (var blocker in BlockedExitCells(actor).SelectMany(p => self.World.ActorMap.GetUnitsAt(p)))
|
foreach (var blocker in BlockedExitCells(actor).SelectMany(p => self.World.ActorMap.GetUnitsAt(p)))
|
||||||
{
|
{
|
||||||
@@ -83,8 +86,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
w.Add(actor);
|
w.Add(actor);
|
||||||
actor.CancelActivity();
|
actor.CancelActivity();
|
||||||
pos.SetVisualPosition(actor, spawn);
|
pos.SetVisualPosition(actor, spawn);
|
||||||
actor.QueueActivity(move.MoveIntoWorld(actor, exitCell.Value));
|
actor.QueueActivity(move.MoveIntoWorld(actor, exitSubCell.Value.First, exitSubCell.Value.Second));
|
||||||
actor.SetTargetLine(Target.FromCell(w, exitCell.Value), Color.Green, false);
|
actor.SetTargetLine(Target.FromCell(w, exitSubCell.Value.First, exitSubCell.Value.Second), Color.Green, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!unloadAll || cargo.IsEmpty(self))
|
if (!unloadAll || cargo.IsEmpty(self))
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|
|
||||||
public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld
|
public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||||
{
|
{
|
||||||
static readonly Pair<CPos, int>[] NoCells = { };
|
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
||||||
|
|
||||||
readonly AircraftInfo info;
|
readonly AircraftInfo info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
@@ -170,7 +170,10 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Changes position, but not altitude
|
// Changes position, but not altitude
|
||||||
public void SetPosition(Actor self, CPos cell) { SetPosition(self, self.World.Map.CenterOfCell(cell) + new WVec(0, 0, CenterPosition.Z)); }
|
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||||
|
{
|
||||||
|
SetPosition(self, self.World.Map.CenterOfCell(cell) + new WVec(0, 0, CenterPosition.Z));
|
||||||
|
}
|
||||||
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos); }
|
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos); }
|
||||||
|
|
||||||
public void AddedToWorld(Actor self)
|
public void AddedToWorld(Actor self)
|
||||||
@@ -196,8 +199,10 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
|| info.RepairBuildings.Contains(a.Info.Name);
|
|| info.RepairBuildings.Contains(a.Info.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanEnterCell(CPos location) { return true; }
|
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; } // TODO: Handle landing
|
||||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { return true; }
|
public SubCell GetValidSubCell(SubCell preferred) { return SubCell.Invalid; }
|
||||||
|
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 int MovementSpeed
|
public int MovementSpeed
|
||||||
{
|
{
|
||||||
@@ -209,7 +214,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, int>> OccupiedCells() { return NoCells; }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return NoCells; }
|
||||||
|
|
||||||
public WVec FlyStep(int facing)
|
public WVec FlyStep(int facing)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -148,9 +148,9 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); }
|
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new Follow(self, target, minRange, maxRange); }
|
||||||
public CPos NearestMoveableCell(CPos cell) { return cell; }
|
public CPos NearestMoveableCell(CPos cell) { return cell; }
|
||||||
|
|
||||||
public Activity MoveIntoWorld(Actor self, CPos cell)
|
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
return new HeliFly(self, Target.FromCell(self.World, cell));
|
return new HeliFly(self, Target.FromCell(self.World, cell, subCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.RA.Air
|
|||||||
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
|
public Activity MoveFollow(Actor self, Target target, WRange minRange, WRange maxRange) { return new FlyFollow(self, target, minRange, maxRange); }
|
||||||
public CPos NearestMoveableCell(CPos cell) { return cell; }
|
public CPos NearestMoveableCell(CPos cell) { return cell; }
|
||||||
|
|
||||||
public Activity MoveIntoWorld(Actor self, CPos cell) { 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))); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,14 +133,14 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
this.Info = info;
|
this.Info = info;
|
||||||
|
|
||||||
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
|
occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft )
|
||||||
.Select(c => Pair.New(c, 0)).ToArray();
|
.Select(c => Pair.New(c, SubCell.FullCell)).ToArray();
|
||||||
|
|
||||||
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
|
CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info);
|
||||||
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<CPos, int>[] occupiedCells;
|
Pair<CPos, SubCell>[] occupiedCells;
|
||||||
public IEnumerable<Pair<CPos, int>> OccupiedCells() { return occupiedCells; }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
|
||||||
|
|
||||||
public void Created(Actor self)
|
public void Created(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,34 +89,40 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CPos TopLeft { get { return Location; } }
|
public CPos TopLeft { get { return Location; } }
|
||||||
public IEnumerable<Pair<CPos, int>> OccupiedCells() { yield return Pair.New(Location, 0); }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(Location, SubCell.FullCell); }
|
||||||
|
|
||||||
public WPos CenterPosition { get; private set; }
|
public WPos CenterPosition { get; private set; }
|
||||||
public void SetPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); }
|
public void SetPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); }
|
||||||
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); }
|
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, self.World.Map.CellContaining(pos)); }
|
||||||
|
|
||||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
|
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return self.Location == location && ticks + 1 == info.Lifetime * 25; }
|
||||||
|
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; }
|
||||||
|
public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
{
|
{
|
||||||
if (!self.World.Map.Contains(cell)) return false;
|
if (!self.World.Map.Contains(cell))
|
||||||
|
return SubCell.Invalid;
|
||||||
|
|
||||||
var type = self.World.Map.GetTerrainInfo(cell).Type;
|
var type = self.World.Map.GetTerrainInfo(cell).Type;
|
||||||
if (!info.TerrainTypes.Contains(type))
|
if (!info.TerrainTypes.Contains(type))
|
||||||
return false;
|
return SubCell.Invalid;
|
||||||
|
|
||||||
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
|
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
|
||||||
return false;
|
return SubCell.Invalid;
|
||||||
|
|
||||||
if (!checkTransientActors)
|
if (!checkTransientActors)
|
||||||
return true;
|
return SubCell.FullCell;
|
||||||
|
|
||||||
return !self.World.ActorMap.GetUnitsAt(cell)
|
return !self.World.ActorMap.GetUnitsAt(cell)
|
||||||
.Where(x => x != ignoreActor)
|
.Where(x => x != ignoreActor)
|
||||||
.Any();
|
.Any() ? SubCell.FullCell : SubCell.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
|
public bool CanEnterCell(CPos a, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
|
{
|
||||||
|
return GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPosition(Actor self, CPos cell)
|
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
self.World.ActorMap.RemoveInfluence(self, this);
|
self.World.ActorMap.RemoveInfluence(self, this);
|
||||||
Location = cell;
|
Location = cell;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Crates
|
|||||||
|
|
||||||
for (var i = -3; i < 4; i++)
|
for (var i = -3; i < 4; i++)
|
||||||
for (var j = -3; j < 4; j++)
|
for (var j = -3; j < 4; j++)
|
||||||
if (mi.CanEnterCell(self.World, self, near + new CVec(i, j), null, true, true))
|
if (mi.CanEnterCell(self.World, self, near + new CVec(i, j)))
|
||||||
yield return near + new CVec(i, j);
|
yield return near + new CVec(i, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.Crates
|
|||||||
|
|
||||||
for (var i = -1; i < 2; i++)
|
for (var i = -1; i < 2; i++)
|
||||||
for (var j = -1; j < 2; j++)
|
for (var j = -1; j < 2; j++)
|
||||||
if (mi.CanEnterCell(self.World, self, near + new CVec(i, j), null, true, true))
|
if (mi.CanEnterCell(self.World, self, near + new CVec(i, j)))
|
||||||
yield return near + new CVec(i, j);
|
yield return near + new CVec(i, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,25 +52,31 @@ namespace OpenRA.Mods.RA
|
|||||||
self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed));
|
self.QueueActivity(new Drag(CenterPosition, finalPos, distance / speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, int>> OccupiedCells() { yield return Pair.New(TopLeft, 0); }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
||||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
|
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; }
|
||||||
|
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; }
|
||||||
|
public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
{
|
{
|
||||||
if (!self.World.Map.Contains(cell))
|
if (!self.World.Map.Contains(cell))
|
||||||
return false;
|
return SubCell.Invalid;
|
||||||
|
|
||||||
if (!info.AllowedTerrain.Contains(self.World.Map.GetTerrainInfo(cell).Type))
|
if (!info.AllowedTerrain.Contains(self.World.Map.GetTerrainInfo(cell).Type))
|
||||||
return false;
|
return SubCell.Invalid;
|
||||||
|
|
||||||
if (!checkTransientActors)
|
if (!checkTransientActors)
|
||||||
return true;
|
return SubCell.FullCell;
|
||||||
|
|
||||||
return !self.World.ActorMap.GetUnitsAt(cell)
|
return !self.World.ActorMap.GetUnitsAt(cell)
|
||||||
.Where(x => x != ignoreActor)
|
.Where(x => x != ignoreActor)
|
||||||
.Any();
|
.Any() ? SubCell.FullCell : SubCell.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
|
public bool CanEnterCell(CPos a, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
public void SetPosition(Actor self, CPos cell) { SetPosition(self, self.World.Map.CenterOfCell(cell)); }
|
{
|
||||||
|
return GetAvailableSubCell(a, SubCell.Any, ignoreActor, checkTransientActors) != SubCell.Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any) { SetPosition(self, self.World.Map.CenterOfCell(cell)); }
|
||||||
|
|
||||||
public void SetVisualPosition(Actor self, WPos pos)
|
public void SetVisualPosition(Actor self, WPos pos)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
[Sync] readonly CPos location;
|
[Sync] readonly CPos location;
|
||||||
[Sync] readonly WPos position;
|
[Sync] readonly WPos position;
|
||||||
readonly IEnumerable<Pair<CPos, int>> occupied;
|
readonly IEnumerable<Pair<CPos, SubCell>> occupied;
|
||||||
|
|
||||||
public Immobile(ActorInitializer init, ImmobileInfo info)
|
public Immobile(ActorInitializer init, ImmobileInfo info)
|
||||||
{
|
{
|
||||||
@@ -32,14 +32,14 @@ namespace OpenRA.Mods.RA
|
|||||||
position = init.world.Map.CenterOfCell(location);
|
position = init.world.Map.CenterOfCell(location);
|
||||||
|
|
||||||
if (info.OccupiesSpace)
|
if (info.OccupiesSpace)
|
||||||
occupied = new [] { Pair.New(TopLeft, 0) };
|
occupied = new [] { Pair.New(TopLeft, SubCell.FullCell) };
|
||||||
else
|
else
|
||||||
occupied = new Pair<CPos, int>[0];
|
occupied = new Pair<CPos, SubCell>[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos TopLeft { get { return location; } }
|
public CPos TopLeft { get { return location; } }
|
||||||
public WPos CenterPosition { get { return position; } }
|
public WPos CenterPosition { get { return position; } }
|
||||||
public IEnumerable<Pair<CPos, int>> OccupiedCells() { return occupied; }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupied; }
|
||||||
|
|
||||||
public void AddedToWorld(Actor self)
|
public void AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
193
OpenRA.Mods.RA/Move/Mobile.cs
Executable file → Normal file
193
OpenRA.Mods.RA/Move/Mobile.cs
Executable file → Normal file
@@ -18,6 +18,15 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA.Move
|
namespace OpenRA.Mods.RA.Move
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum CellConditions
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
TransientActors,
|
||||||
|
BlockedByMovers,
|
||||||
|
All = TransientActors | BlockedByMovers
|
||||||
|
};
|
||||||
|
|
||||||
[Desc("Unit is able to move.")]
|
[Desc("Unit is able to move.")]
|
||||||
public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
public class MobileInfo : ITraitInfo, IOccupySpaceInfo, IFacingInfo, IMoveInfo, UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
||||||
{
|
{
|
||||||
@@ -151,12 +160,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanEnterCell(World world, CPos cell)
|
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, CellConditions check = CellConditions.All)
|
||||||
{
|
|
||||||
return CanEnterCell(world, null, cell, null, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor, bool checkTransientActors, bool blockedByMovers)
|
|
||||||
{
|
{
|
||||||
if (MovementCostForCell(world, cell) == int.MaxValue)
|
if (MovementCostForCell(world, cell) == int.MaxValue)
|
||||||
return false;
|
return false;
|
||||||
@@ -164,21 +168,25 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
|
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (checkTransientActors)
|
if (check.HasFlag(CellConditions.TransientActors))
|
||||||
{
|
{
|
||||||
var canIgnoreMovingAllies = self != null && !blockedByMovers;
|
var canIgnoreMovingAllies = self != null && !check.HasFlag(CellConditions.BlockedByMovers);
|
||||||
var needsCellExclusively = self == null || Crushes == null;
|
var needsCellExclusively = self == null || Crushes == null || !Crushes.Any();
|
||||||
foreach(var a in world.ActorMap.GetUnitsAt(cell))
|
foreach(var a in world.ActorMap.GetUnitsAt(cell))
|
||||||
{
|
{
|
||||||
if (a == ignoreActor) continue;
|
if (a == ignoreActor)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Neutral/enemy units are blockers. Allied units that are moving are not blockers.
|
// Neutral/enemy units are blockers. Allied units that are moving are not blockers.
|
||||||
if (canIgnoreMovingAllies && self.Owner.Stances[a.Owner] == Stance.Ally && IsMovingInMyDirection(self, a)) continue;
|
if (canIgnoreMovingAllies && self.Owner.Stances[a.Owner] == Stance.Ally && IsMovingInMyDirection(self, a)) continue;
|
||||||
|
|
||||||
// Non-sharable unit can enter a cell with shareable units only if it can crush all of them.
|
// Non-sharable unit can enter a cell with shareable units only if it can crush all of them.
|
||||||
if (needsCellExclusively) return false;
|
if (needsCellExclusively)
|
||||||
if (!a.HasTrait<ICrushable>()) return false;
|
return false;
|
||||||
foreach (var crushable in a.TraitsImplementing<ICrushable>())
|
var crushables = a.TraitsImplementing<ICrushable>();
|
||||||
|
if (!crushables.Any())
|
||||||
|
return false;
|
||||||
|
foreach (var crushable in crushables)
|
||||||
if (!crushable.CrushableBy(Crushes, self.Owner))
|
if (!crushable.CrushableBy(Crushes, self.Owner))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -187,6 +195,50 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubCell GetAvailableSubCell(World world, Actor self, CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, CellConditions check = CellConditions.All)
|
||||||
|
{
|
||||||
|
if (MovementCostForCell(world, cell) == int.MaxValue)
|
||||||
|
return SubCell.Invalid;
|
||||||
|
|
||||||
|
if (check.HasFlag(CellConditions.TransientActors))
|
||||||
|
{
|
||||||
|
var canIgnoreMovingAllies = self != null && !check.HasFlag(CellConditions.BlockedByMovers);
|
||||||
|
var needsCellExclusively = self == null || Crushes == null || !Crushes.Any();
|
||||||
|
|
||||||
|
Func<Actor, bool> checkTransient = a =>
|
||||||
|
{
|
||||||
|
if (a == ignoreActor)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Neutral/enemy units are blockers. Allied units that are moving are not blockers.
|
||||||
|
if (canIgnoreMovingAllies && self.Owner.Stances[a.Owner] == Stance.Ally && IsMovingInMyDirection(self, a))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Non-sharable unit can enter a cell with shareable units only if it can crush all of them.
|
||||||
|
if (needsCellExclusively)
|
||||||
|
return true;
|
||||||
|
var crushables = a.TraitsImplementing<ICrushable>();
|
||||||
|
if (!crushables.Any())
|
||||||
|
return true;
|
||||||
|
foreach (var crushable in crushables)
|
||||||
|
if (!crushable.CrushableBy(Crushes, self.Owner))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!SharesCell)
|
||||||
|
return world.ActorMap.AnyUnitsAt(cell, SubCell.FullCell, checkTransient) ? SubCell.Invalid : SubCell.FullCell;
|
||||||
|
|
||||||
|
return world.ActorMap.FreeSubCell(cell, preferredSubCell, checkTransient);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SharesCell)
|
||||||
|
return world.ActorMap.AnyUnitsAt(cell, SubCell.FullCell)? SubCell.Invalid : SubCell.FullCell;
|
||||||
|
|
||||||
|
return world.ActorMap.FreeSubCell(cell, preferredSubCell);
|
||||||
|
}
|
||||||
|
|
||||||
public int GetInitialFacing() { return InitialFacing; }
|
public int GetInitialFacing() { return InitialFacing; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +250,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
int __facing;
|
int __facing;
|
||||||
CPos __fromCell, __toCell;
|
CPos __fromCell, __toCell;
|
||||||
public int fromSubCell, toSubCell;
|
public SubCell fromSubCell, toSubCell;
|
||||||
|
|
||||||
//int __altitude;
|
//int __altitude;
|
||||||
|
|
||||||
@@ -216,7 +268,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
[Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
||||||
|
|
||||||
public void SetLocation(CPos from, int fromSub, CPos to, int toSub)
|
public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub)
|
||||||
{
|
{
|
||||||
if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub)
|
if (fromCell == from && toCell == to && fromSubCell == fromSub && toSubCell == toSub)
|
||||||
return;
|
return;
|
||||||
@@ -238,16 +290,16 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
this.self = init.self;
|
this.self = init.self;
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
|
|
||||||
toSubCell = fromSubCell = info.SharesCell ? init.world.Map.SubCellDefaultIndex : 0;
|
toSubCell = fromSubCell = info.SharesCell ? init.world.Map.DefaultSubCell : SubCell.FullCell;
|
||||||
if (init.Contains<SubCellInit>())
|
if (init.Contains<SubCellInit>())
|
||||||
{
|
{
|
||||||
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, int>();
|
this.fromSubCell = this.toSubCell = init.Get<SubCellInit, SubCell>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
if (init.Contains<LocationInit>())
|
||||||
{
|
{
|
||||||
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
|
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
|
||||||
SetVisualPosition(self, init.world.Map.CenterOfCell(fromCell) + self.World.Map.SubCellOffsets[fromSubCell]);
|
SetVisualPosition(self, init.world.Map.CenterOfSubCell(fromCell, fromSubCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
||||||
@@ -258,10 +310,32 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
SetVisualPosition(self, init.Get<CenterPositionInit, WPos>());
|
SetVisualPosition(self, init.Get<CenterPositionInit, WPos>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(Actor self, CPos cell)
|
// Returns a valid sub-cell
|
||||||
|
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any)
|
||||||
{
|
{
|
||||||
SetLocation(cell, fromSubCell, cell, fromSubCell);
|
// Try same sub-cell
|
||||||
SetVisualPosition(self, self.World.Map.CenterOfCell(fromCell) + self.World.Map.SubCellOffsets[fromSubCell]);
|
if (preferred == SubCell.Any)
|
||||||
|
preferred = fromSubCell;
|
||||||
|
|
||||||
|
// Fix sub-cell assignment
|
||||||
|
if (Info.SharesCell)
|
||||||
|
{
|
||||||
|
if (preferred <= SubCell.FullCell)
|
||||||
|
return self.World.Map.DefaultSubCell;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (preferred != SubCell.FullCell)
|
||||||
|
return SubCell.FullCell;
|
||||||
|
}
|
||||||
|
return preferred;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||||
|
{
|
||||||
|
subCell = GetValidSubCell(subCell);
|
||||||
|
SetLocation(cell, subCell, cell, subCell);
|
||||||
|
SetVisualPosition(self, self.World.Map.CenterOfSubCell(cell, subCell));
|
||||||
FinishedMoving(self);
|
FinishedMoving(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +478,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
public CPos TopLeft { get { return toCell; } }
|
public CPos TopLeft { get { return toCell; } }
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, int>> OccupiedCells()
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells()
|
||||||
{
|
{
|
||||||
if (fromCell == toCell)
|
if (fromCell == toCell)
|
||||||
yield return Pair.New(fromCell, fromSubCell);
|
yield return Pair.New(fromCell, fromSubCell);
|
||||||
@@ -417,68 +491,36 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDesiredSubcellNotBlocked(CPos a, int b, Actor ignoreActor)
|
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var blockingActors = self.World.ActorMap.GetUnitsAt(a, b).Where(c => c != ignoreActor);
|
return toCell != location && __fromCell == location
|
||||||
if (blockingActors.Any())
|
&& (subCell == SubCell.Any || fromSubCell == subCell || subCell == SubCell.FullCell || fromSubCell == SubCell.FullCell);
|
||||||
{
|
|
||||||
// Non-sharable unit can enter a cell with shareable units only if it can crush all of them
|
|
||||||
if (Info.Crushes == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (blockingActors.Any(c => !(c.HasTrait<ICrushable>() &&
|
|
||||||
c.TraitsImplementing<ICrushable>().Any(d => d.CrushableBy(Info.Crushes, self.Owner)))))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetDesiredSubcell(CPos a, Actor ignoreActor)
|
public SubCell GetAvailableSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
{
|
{
|
||||||
if (!Info.SharesCell)
|
return Info.GetAvailableSubCell(self.World, self, a, preferredSubCell, ignoreActor, checkTransientActors? CellConditions.All : CellConditions.None);
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Prioritise the current subcell
|
|
||||||
if (IsDesiredSubcellNotBlocked(a, fromSubCell, ignoreActor))
|
|
||||||
return fromSubCell;
|
|
||||||
|
|
||||||
for (var i = 1; i < self.World.Map.SubCellOffsets.Length; i++)
|
|
||||||
if (IsDesiredSubcellNotBlocked(a, i, ignoreActor))
|
|
||||||
return i;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanEnterCell(CPos p)
|
public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
|
||||||
{
|
{
|
||||||
return CanEnterCell(p, null, true);
|
return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors ? CellConditions.All : CellConditions.BlockedByMovers);
|
||||||
}
|
|
||||||
|
|
||||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
|
|
||||||
{
|
|
||||||
return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnteringCell(Actor self)
|
public void EnteringCell(Actor self)
|
||||||
{
|
{
|
||||||
var crushable = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>());
|
var crushables = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self)
|
||||||
foreach (var a in crushable)
|
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner)));
|
||||||
{
|
foreach (var crushable in crushables)
|
||||||
var crushActions = a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner));
|
crushable.WarnCrush(self);
|
||||||
foreach (var b in crushActions)
|
|
||||||
b.WarnCrush(self);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FinishedMoving(Actor self)
|
public void FinishedMoving(Actor self)
|
||||||
{
|
{
|
||||||
var crushable = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self && a.HasTrait<ICrushable>());
|
var crushables = self.World.ActorMap.GetUnitsAt(toCell).Where(a => a != self)
|
||||||
foreach (var a in crushable)
|
.SelectMany(a => a.TraitsImplementing<ICrushable>().Where(c => c.CrushableBy(Info.Crushes, self.Owner)));
|
||||||
{
|
foreach (var crushable in crushables)
|
||||||
var crushActions = a.TraitsImplementing<ICrushable>().Where(b => b.CrushableBy(Info.Crushes, self.Owner));
|
crushable.OnCrush(self);
|
||||||
foreach (var b in crushActions)
|
|
||||||
b.OnCrush(self);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MovementSpeedForCell(Actor self, CPos cell)
|
public int MovementSpeedForCell(Actor self, CPos cell)
|
||||||
@@ -603,16 +645,23 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
Nudge(self, blocking, true);
|
Nudge(self, blocking, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveIntoWorld(Actor self, CPos cell)
|
public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var pos = self.CenterPosition;
|
var pos = self.CenterPosition;
|
||||||
|
|
||||||
|
if (subCell == SubCell.Any)
|
||||||
|
subCell = self.World.ActorMap.FreeSubCell(cell, subCell);
|
||||||
|
|
||||||
|
// TODO: solve/reduce cell is full problem
|
||||||
|
if (subCell == SubCell.Invalid)
|
||||||
|
subCell = self.World.Map.DefaultSubCell;
|
||||||
|
|
||||||
// Reserve the exit cell
|
// Reserve the exit cell
|
||||||
SetPosition(self, cell);
|
SetPosition(self, cell, subCell);
|
||||||
SetVisualPosition(self, pos);
|
SetVisualPosition(self, pos);
|
||||||
|
|
||||||
// Animate transition
|
// Animate transition
|
||||||
var to = self.World.Map.CenterOfCell(cell);
|
var to = self.World.Map.CenterOfSubCell(cell, subCell);
|
||||||
var speed = MovementSpeedForCell(self, cell);
|
var speed = MovementSpeedForCell(self, cell);
|
||||||
var length = speed > 0 ? (to - pos).Length / speed : 0;
|
var length = speed > 0 ? (to - pos).Length / speed : 0;
|
||||||
|
|
||||||
|
|||||||
22
OpenRA.Mods.RA/Move/Move.cs
Executable file → Normal file
22
OpenRA.Mods.RA/Move/Move.cs
Executable file → Normal file
@@ -57,6 +57,14 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
this.nearEnough = nearEnough;
|
this.nearEnough = nearEnough;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Move(CPos destination, SubCell subCell, WRange nearEnough)
|
||||||
|
{
|
||||||
|
this.getPath = (self, mobile) => self.World.WorldActor.Trait<PathFinder>()
|
||||||
|
.FindUnitPathToRange(mobile.fromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
|
||||||
|
this.destination = destination;
|
||||||
|
this.nearEnough = nearEnough;
|
||||||
|
}
|
||||||
|
|
||||||
public Move(CPos destination, Actor ignoreBuilding)
|
public Move(CPos destination, Actor ignoreBuilding)
|
||||||
{
|
{
|
||||||
this.getPath = (self, mobile) =>
|
this.getPath = (self, mobile) =>
|
||||||
@@ -150,8 +158,8 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||||
var move = new MoveFirstHalf(
|
var move = new MoveFirstHalf(
|
||||||
this,
|
this,
|
||||||
self.World.Map.CenterOfCell(mobile.fromCell) + self.World.Map.SubCellOffsets[mobile.fromSubCell],
|
self.World.Map.CenterOfSubCell(mobile.fromCell, mobile.fromSubCell),
|
||||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (self.World.Map.SubCellOffsets[mobile.fromSubCell] + self.World.Map.SubCellOffsets[mobile.toSubCell]) / 2,
|
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (self.World.Map.OffsetOfSubCell(mobile.fromSubCell) + self.World.Map.OffsetOfSubCell(mobile.toSubCell)) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
0);
|
0);
|
||||||
@@ -180,7 +188,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<CPos, int>? PopPath(Actor self, Mobile mobile)
|
Pair<CPos, SubCell>? PopPath(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
@@ -237,7 +245,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
hasWaited = false;
|
hasWaited = false;
|
||||||
path.RemoveAt(path.Count - 1);
|
path.RemoveAt(path.Count - 1);
|
||||||
|
|
||||||
var subCell = mobile.GetDesiredSubcell(nextCell, ignoreBuilding);
|
var subCell = mobile.GetAvailableSubCell(nextCell, SubCell.Any, ignoreBuilding);
|
||||||
return Pair.New(nextCell, subCell);
|
return Pair.New(nextCell, subCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,15 +355,15 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||||
{
|
{
|
||||||
var fromSubcellOffset = self.World.Map.SubCellOffsets[mobile.fromSubCell];
|
var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.fromSubCell);
|
||||||
var toSubcellOffset = self.World.Map.SubCellOffsets[mobile.toSubCell];
|
var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.toSubCell);
|
||||||
|
|
||||||
var nextCell = parent.PopPath(self, mobile);
|
var nextCell = parent.PopPath(self, mobile);
|
||||||
if (nextCell != null)
|
if (nextCell != null)
|
||||||
{
|
{
|
||||||
if (IsTurn(mobile, nextCell.Value.First))
|
if (IsTurn(mobile, nextCell.Value.First))
|
||||||
{
|
{
|
||||||
var nextSubcellOffset = self.World.Map.SubCellOffsets[nextCell.Value.Second];
|
var nextSubcellOffset = self.World.Map.OffsetOfSubCell(nextCell.Value.Second);
|
||||||
var ret = new MoveFirstHalf(
|
var ret = new MoveFirstHalf(
|
||||||
move,
|
move,
|
||||||
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CPos> FindUnitPathToRange(CPos src, int srcSub, WPos target, WRange range, Actor self)
|
public List<CPos> FindUnitPathToRange(CPos src, SubCell srcSub, WPos target, WRange range, Actor self)
|
||||||
{
|
{
|
||||||
using (new PerfSample("Pathfinder"))
|
using (new PerfSample("Pathfinder"))
|
||||||
{
|
{
|
||||||
@@ -89,13 +89,13 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
var rangeSquared = range.Range*range.Range;
|
var rangeSquared = range.Range*range.Range;
|
||||||
|
|
||||||
// Correct for SubCell offset
|
// Correct for SubCell offset
|
||||||
target -= self.World.Map.SubCellOffsets[srcSub];
|
target -= self.World.Map.OffsetOfSubCell(srcSub);
|
||||||
|
|
||||||
// Select only the tiles that are within range from the requested SubCell
|
// Select only the tiles that are within range from the requested SubCell
|
||||||
// This assumes that the SubCell does not change during the path traversal
|
// This assumes that the SubCell does not change during the path traversal
|
||||||
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1)
|
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Range / 1024 + 1)
|
||||||
.Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= rangeSquared
|
.Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= rangeSquared
|
||||||
&& mi.CanEnterCell(self.World, self, t, null, true, true));
|
&& mi.CanEnterCell(self.World, self, t));
|
||||||
|
|
||||||
// See if there is any cell within range that does not involve a cross-domain request
|
// See if there is any cell within range that does not involve a cross-domain request
|
||||||
// Really, we only need to check the circle perimeter, but it's not clear that would be a performance win
|
// Really, we only need to check the circle perimeter, but it's not clear that would be a performance win
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if (costHere == int.MaxValue)
|
if (costHere == int.MaxValue)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!mobileInfo.CanEnterCell(world, self, newHere, IgnoreBuilding, CheckForBlocked, false))
|
if (!mobileInfo.CanEnterCell(world, self, newHere, IgnoreBuilding, CheckForBlocked ? CellConditions.TransientActors : CellConditions.None))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (customBlock != null && customBlock(newHere))
|
if (customBlock != null && customBlock(newHere))
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mobileInfo == null ||
|
return mobileInfo == null ||
|
||||||
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self, true, true);
|
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA
|
|||||||
foreach (var s in unitGroup.SupportActors)
|
foreach (var s in unitGroup.SupportActors)
|
||||||
{
|
{
|
||||||
var mi = w.Map.Rules.Actors[s.ToLowerInvariant()].Traits.Get<MobileInfo>();
|
var mi = w.Map.Rules.Actors[s.ToLowerInvariant()].Traits.Get<MobileInfo>();
|
||||||
var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, c));
|
var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, null, c));
|
||||||
if (!validCells.Any())
|
if (!validCells.Any())
|
||||||
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));
|
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user