Fix GiveUnitCrateAction being limited to MobileInfo

This commit is contained in:
abcdefg30
2017-02-09 13:11:01 +01:00
parent ac9c8b93a2
commit a385835939
5 changed files with 54 additions and 21 deletions

View File

@@ -265,7 +265,11 @@ namespace OpenRA.Traits
[RequireExplicitImplementation] [RequireExplicitImplementation]
public interface ISelectionBar { float GetValue(); Color GetColor(); bool DisplayWhenEmpty { get; } } public interface ISelectionBar { float GetValue(); Color GetColor(); bool DisplayWhenEmpty { get; } }
public interface IPositionableInfo : ITraitInfoInterface { } public interface IPositionableInfo : ITraitInfoInterface
{
bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, bool checkTransientActors = true);
}
public interface IPositionable : IOccupySpace public interface IPositionable : IOccupySpace
{ {
bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any); bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any);

View File

@@ -94,6 +94,25 @@ namespace OpenRA.Mods.Common.Traits
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); } public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); }
bool IOccupySpaceInfo.SharesCell { get { return false; } } bool IOccupySpaceInfo.SharesCell { get { return false; } }
// Used to determine if an aircraft can spawn landed
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
{
if (!world.Map.Contains(cell))
return false;
var type = world.Map.GetTerrainInfo(cell).Type;
if (!LandableTerrainTypes.Contains(type))
return false;
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
return false;
if (!checkTransientActors)
return true;
return !world.ActorMap.GetActorsAt(cell).Any(x => x != ignoreActor);
}
} }
public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier, public class Aircraft : ITick, ISync, IFacing, IPositionable, IMove, IIssueOrder, IResolveOrder, IOrderVoice, IDeathActorInitModifier,

View File

@@ -38,6 +38,30 @@ namespace OpenRA.Mods.Common.Traits
} }
bool IOccupySpaceInfo.SharesCell { get { return false; } } bool IOccupySpaceInfo.SharesCell { get { return false; } }
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
{
return GetAvailableSubCell(world, cell, ignoreActor, checkTransientActors) != SubCell.Invalid;
}
public SubCell GetAvailableSubCell(World world, CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
{
if (!world.Map.Contains(cell))
return SubCell.Invalid;
var type = world.Map.GetTerrainInfo(cell).Type;
if (!TerrainTypes.Contains(type))
return SubCell.Invalid;
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
return SubCell.Invalid;
if (!checkTransientActors)
return SubCell.FullCell;
return !world.ActorMap.GetActorsAt(cell).Any(x => x != ignoreActor)
? SubCell.FullCell : SubCell.Invalid;
}
} }
class Crate : ITick, IPositionable, ICrushable, ISync, class Crate : ITick, IPositionable, ICrushable, ISync,
@@ -174,22 +198,7 @@ namespace OpenRA.Mods.Common.Traits
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; } 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) public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)
{ {
if (!self.World.Map.Contains(cell)) return info.GetAvailableSubCell(self.World, cell, ignoreActor, checkTransientActors);
return SubCell.Invalid;
var type = self.World.Map.GetTerrainInfo(cell).Type;
if (!info.TerrainTypes.Contains(type))
return SubCell.Invalid;
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null)
return SubCell.Invalid;
if (!checkTransientActors)
return SubCell.FullCell;
return !self.World.ActorMap.GetActorsAt(cell)
.Any(x => x != ignoreActor)
? SubCell.FullCell : SubCell.Invalid;
} }
public bool CanEnterCell(CPos a, Actor ignoreActor = null, bool checkTransientActors = true) public bool CanEnterCell(CPos a, Actor ignoreActor = null, bool checkTransientActors = true)

View File

@@ -97,11 +97,11 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<CPos> GetSuitableCells(CPos near, string unitName) IEnumerable<CPos> GetSuitableCells(CPos near, string unitName)
{ {
var mi = self.World.Map.Rules.Actors[unitName].TraitInfo<MobileInfo>(); var ip = self.World.Map.Rules.Actors[unitName].TraitInfo<IPositionableInfo>();
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))) if (ip.CanEnterCell(self.World, self, near + new CVec(i, j)))
yield return near + new CVec(i, j); yield return near + new CVec(i, j);
} }

View File

@@ -263,11 +263,12 @@ namespace OpenRA.Mods.Common.Traits
(current, terrainInfo) => unchecked(current * 31 + terrainInfo.Cost)); (current, terrainInfo) => unchecked(current * 31 + terrainInfo.Cost));
} }
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, CellConditions check = CellConditions.All) public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
{ {
if (MovementCostForCell(world, cell) == int.MaxValue) if (MovementCostForCell(world, cell) == int.MaxValue)
return false; return false;
var check = checkTransientActors ? CellConditions.All : CellConditions.BlockedByMovers;
return CanMoveFreelyInto(world, self, cell, ignoreActor, check); return CanMoveFreelyInto(world, self, cell, ignoreActor, check);
} }
@@ -699,7 +700,7 @@ namespace OpenRA.Mods.Common.Traits
public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true) public bool CanEnterCell(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)
{ {
return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors ? CellConditions.All : CellConditions.BlockedByMovers); return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors);
} }
public bool CanMoveFreelyInto(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true) public bool CanMoveFreelyInto(CPos cell, Actor ignoreActor = null, bool checkTransientActors = true)