move some MobileInfo-related bits onto MobileInfo
This commit is contained in:
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Crates
|
||||
var mi = Rules.Info[Info.Unit].Traits.GetOrDefault<MobileInfo>();
|
||||
for (var i = -1; i < 2; i++)
|
||||
for (var j = -1; j < 2; j++)
|
||||
if (Mobile.CanEnterCell(self.World, mi, near + new int2(i, j), null, true))
|
||||
if (mi.CanEnterCell(self.World, near + new int2(i, j), null, true))
|
||||
yield return near + new int2(i, j);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,20 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
[FieldLoader.LoadUsing("LoadSpeeds")]
|
||||
public readonly Dictionary<string, TerrainInfo> TerrainSpeeds;
|
||||
[FieldLoader.Load] public readonly string[] Crushes;
|
||||
[FieldLoader.Load] public readonly int WaitAverage = 60;
|
||||
[FieldLoader.Load] public readonly int WaitSpread = 20;
|
||||
[FieldLoader.Load] public readonly int InitialFacing = 128;
|
||||
[FieldLoader.Load] public readonly int ROT = 255;
|
||||
[FieldLoader.Load] public readonly int Speed = 1;
|
||||
[FieldLoader.Load] public readonly bool OnRails = false;
|
||||
[FieldLoader.Load]
|
||||
public readonly string[] Crushes;
|
||||
[FieldLoader.Load]
|
||||
public readonly int WaitAverage = 60;
|
||||
[FieldLoader.Load]
|
||||
public readonly int WaitSpread = 20;
|
||||
[FieldLoader.Load]
|
||||
public readonly int InitialFacing = 128;
|
||||
[FieldLoader.Load]
|
||||
public readonly int ROT = 255;
|
||||
[FieldLoader.Load]
|
||||
public readonly int Speed = 1;
|
||||
[FieldLoader.Load]
|
||||
public readonly bool OnRails = false;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }
|
||||
|
||||
@@ -54,6 +61,44 @@ namespace OpenRA.Mods.RA.Move
|
||||
public int Cost = int.MaxValue;
|
||||
public decimal Speed = 0;
|
||||
}
|
||||
|
||||
public int MovementCostForCell(World world, int2 cell)
|
||||
{
|
||||
if (!world.Map.IsInMap(cell.X, cell.Y))
|
||||
return int.MaxValue;
|
||||
|
||||
var type = world.GetTerrainType(cell);
|
||||
if (!TerrainSpeeds.ContainsKey(type))
|
||||
return int.MaxValue;
|
||||
|
||||
return TerrainSpeeds[type].Cost;
|
||||
}
|
||||
|
||||
public bool CanEnterCell(World world, UnitInfluence uim, int2 cell, Actor ignoreActor, bool checkTransientActors)
|
||||
{
|
||||
if (MovementCostForCell(world, cell) == int.MaxValue)
|
||||
return false;
|
||||
|
||||
var blockingActors = uim.GetUnitsAt(cell).Where(x => x != ignoreActor).ToList();
|
||||
if (checkTransientActors && blockingActors.Count > 0)
|
||||
{
|
||||
// We can enter a cell with nonshareable units only if we can crush all of them
|
||||
if (Crushes == null)
|
||||
return false;
|
||||
|
||||
if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() &&
|
||||
a.TraitsImplementing<ICrushable>().Any(b => b.CrushClasses.Intersect(Crushes).Any()))))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanEnterCell(World world, int2 cell, Actor ignoreActor, bool checkTransientActors)
|
||||
{
|
||||
var uim = world.WorldActor.Trait<UnitInfluence>();
|
||||
return CanEnterCell(world, uim, cell, ignoreActor, checkTransientActors);
|
||||
}
|
||||
}
|
||||
|
||||
public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IOccupySpace, IMove, IFacing, INudge
|
||||
@@ -235,36 +280,10 @@ namespace OpenRA.Mods.RA.Move
|
||||
return CanEnterCell(p, null, true);
|
||||
}
|
||||
|
||||
public static bool CanEnterCell( World world, MobileInfo mi, int2 cell, Actor ignoreActor, bool checkTransientActors )
|
||||
{
|
||||
var uim = world.WorldActor.Trait<UnitInfluence>();
|
||||
return Mobile.CanEnterCell( mi, world, uim, cell, ignoreActor, checkTransientActors );
|
||||
}
|
||||
|
||||
public bool CanEnterCell(int2 cell, Actor ignoreActor, bool checkTransientActors)
|
||||
{
|
||||
var uim = self.World.WorldActor.Trait<UnitInfluence>();
|
||||
return CanEnterCell( Info, self.World, uim, cell, ignoreActor, checkTransientActors );
|
||||
}
|
||||
|
||||
public static bool CanEnterCell( MobileInfo mobileInfo, World world, UnitInfluence uim, int2 cell, Actor ignoreActor, bool checkTransientActors )
|
||||
{
|
||||
if (MovementCostForCell(mobileInfo, world, cell) == int.MaxValue)
|
||||
return false;
|
||||
|
||||
var blockingActors = uim.GetUnitsAt( cell ).Where( x => x != ignoreActor ).ToList();
|
||||
if (checkTransientActors && blockingActors.Count > 0)
|
||||
{
|
||||
// We can enter a cell with nonshareable units only if we can crush all of them
|
||||
if (mobileInfo.Crushes == null)
|
||||
return false;
|
||||
|
||||
if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() &&
|
||||
a.TraitsImplementing<ICrushable>().Any(b => b.CrushClasses.Intersect(mobileInfo.Crushes).Any()))))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Info.CanEnterCell(self.World, uim, cell, ignoreActor, checkTransientActors);
|
||||
}
|
||||
|
||||
public void FinishedMoving(Actor self)
|
||||
@@ -278,18 +297,6 @@ namespace OpenRA.Mods.RA.Move
|
||||
}
|
||||
}
|
||||
|
||||
public static int MovementCostForCell(MobileInfo info, World world, int2 cell)
|
||||
{
|
||||
if (!world.Map.IsInMap(cell.X,cell.Y))
|
||||
return int.MaxValue;
|
||||
|
||||
var type = world.GetTerrainType(cell);
|
||||
if (!info.TerrainSpeeds.ContainsKey(type))
|
||||
return int.MaxValue;
|
||||
|
||||
return info.TerrainSpeeds[type].Cost;
|
||||
}
|
||||
|
||||
public int MovementSpeedForCell(Actor self, int2 cell)
|
||||
{
|
||||
var type = self.World.GetTerrainType(cell);
|
||||
@@ -380,7 +387,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
IsQueued = forceQueued;
|
||||
cursor = "move";
|
||||
if (!self.World.Map.IsInMap(location) || (self.World.LocalPlayer.Shroud.IsExplored(location) &&
|
||||
Mobile.MovementCostForCell(self.Trait<Mobile>().Info, self.World, location) == int.MaxValue))
|
||||
self.Trait<Mobile>().Info.MovementCostForCell(self.World, location) == int.MaxValue))
|
||||
cursor = "move-blocked";
|
||||
|
||||
return true;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
var tilesInRange = world.FindTilesInCircle(target, range)
|
||||
.Where( t => Mobile.CanEnterCell(self.World, mi, t, null, true));
|
||||
.Where( t => mi.CanEnterCell(self.World, t, null, true));
|
||||
|
||||
var path = FindBidiPath(
|
||||
PathSearch.FromPoints(world, mi, tilesInRange, src, true)
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
cellInfo[p.Location.X, p.Location.Y].Seen = true;
|
||||
|
||||
var thisCost = Mobile.MovementCostForCell(mobileInfo, world, p.Location);
|
||||
var thisCost = mobileInfo.MovementCostForCell(world, p.Location);
|
||||
|
||||
if (thisCost == int.MaxValue)
|
||||
return p.Location;
|
||||
@@ -100,12 +100,12 @@ namespace OpenRA.Mods.RA.Move
|
||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||
continue;
|
||||
|
||||
var costHere = Mobile.MovementCostForCell(mobileInfo, world, newHere);
|
||||
var costHere = mobileInfo.MovementCostForCell(world, newHere);
|
||||
|
||||
if (costHere == int.MaxValue)
|
||||
continue;
|
||||
|
||||
if (!Mobile.CanEnterCell(mobileInfo, world, uim, newHere, ignoreBuilding, checkForBlocked))
|
||||
if (!mobileInfo.CanEnterCell(world, uim, newHere, ignoreBuilding, checkForBlocked))
|
||||
continue;
|
||||
|
||||
if (customBlock != null && customBlock(newHere))
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA
|
||||
// Pick a spawn/exit point pair
|
||||
// Todo: Reorder in a synced random way
|
||||
foreach (var s in self.Info.Traits.WithInterface<ExitInfo>())
|
||||
if( Mobile.CanEnterCell( mobileInfo, self.World, uim, self.Location + s.ExitCell,self,true ) )
|
||||
if( mobileInfo.CanEnterCell( self.World, uim, self.Location + s.ExitCell,self,true ) )
|
||||
{
|
||||
DoProduction(self, producee, s);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user