Add methods to IOccupySpaceInfo.

This commit is contained in:
Paul Chote
2015-04-06 14:15:57 +01:00
parent 5754de141d
commit 9e5e1f1a89
8 changed files with 53 additions and 2 deletions

View File

@@ -158,7 +158,12 @@ namespace OpenRA.Traits
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IOccupySpaceInfo : ITraitInfo { } public interface IOccupySpaceInfo : ITraitInfo
{
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any);
bool SharesCell { get; }
}
public interface IOccupySpace public interface IOccupySpace
{ {
WPos CenterPosition { get; } WPos CenterPosition { get; }

View File

@@ -43,6 +43,9 @@ namespace OpenRA.Mods.Common.Traits
public virtual object Create(ActorInitializer init) { return new Aircraft(init, this); } public virtual object Create(ActorInitializer init) { return new Aircraft(init, this); }
public int GetInitialFacing() { return InitialFacing; } public int GetInitialFacing() { return InitialFacing; }
public WRange GetCruiseAltitude() { return CruiseAltitude; } public WRange GetCruiseAltitude() { return CruiseAltitude; }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); }
bool IOccupySpaceInfo.SharesCell { get { return false; } }
} }
public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld

View File

@@ -104,6 +104,16 @@ namespace OpenRA.Mods.Common.Traits
.Any(b => Math.Abs(a.X - b.X) <= Adjacent .Any(b => Math.Abs(a.X - b.X) <= Adjacent
&& Math.Abs(a.Y - b.Y) <= Adjacent)); && Math.Abs(a.Y - b.Y) <= Adjacent));
} }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos topLeft, SubCell subCell = SubCell.Any)
{
var occupied = FootprintUtils.UnpathableTiles(info.Name, this, topLeft)
.ToDictionary(c => c, c => SubCell.FullCell);
return new ReadOnlyDictionary<CPos, SubCell>(occupied);
}
bool IOccupySpaceInfo.SharesCell { get { return false; } }
} }
public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld public class Building : IOccupySpace, INotifySold, INotifyTransform, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld

View File

@@ -28,6 +28,14 @@ namespace OpenRA.Mods.Common.Traits
public readonly string CrushClass = "crate"; public readonly string CrushClass = "crate";
public object Create(ActorInitializer init) { return new Crate(init, this); } public object Create(ActorInitializer init) { return new Crate(init, this); }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
{
var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
return new ReadOnlyDictionary<CPos, SubCell>(occupied);
}
bool IOccupySpaceInfo.SharesCell { get { return false; } }
} }
class Crate : ITick, IPositionable, ICrushable, ISync, INotifyParachuteLanded, INotifyAddedToWorld, INotifyRemovedFromWorld class Crate : ITick, IPositionable, ICrushable, ISync, INotifyParachuteLanded, INotifyAddedToWorld, INotifyRemovedFromWorld

View File

@@ -24,6 +24,14 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new Husk(init, this); } public object Create(ActorInitializer init) { return new Husk(init, this); }
public int GetInitialFacing() { return 128; } public int GetInitialFacing() { return 128; }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
{
var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
return new ReadOnlyDictionary<CPos, SubCell>(occupied);
}
bool IOccupySpaceInfo.SharesCell { get { return false; } }
} }
public class Husk : IPositionable, IFacing, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisable public class Husk : IPositionable, IFacing, ISync, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisable

View File

@@ -18,6 +18,16 @@ namespace OpenRA.Mods.Common.Traits
{ {
public readonly bool OccupiesSpace = true; public readonly bool OccupiesSpace = true;
public object Create(ActorInitializer init) { return new Immobile(init, this); } public object Create(ActorInitializer init) { return new Immobile(init, this); }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
{
var occupied = OccupiesSpace ? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } } :
new Dictionary<CPos, SubCell>();
return new ReadOnlyDictionary<CPos, SubCell>(occupied);
}
bool IOccupySpaceInfo.SharesCell { get { return false; } }
} }
class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld class Immobile : IOccupySpace, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld

View File

@@ -295,6 +295,13 @@ namespace OpenRA.Mods.Common.Traits
} }
public int GetInitialFacing() { return InitialFacing; } public int GetInitialFacing() { return InitialFacing; }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
{
return new ReadOnlyDictionary<CPos, SubCell>(new Dictionary<CPos, SubCell>() { { location, subCell } });
}
bool IOccupySpaceInfo.SharesCell { get { return SharesCell; } }
} }
public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits namespace OpenRA.Mods.RA.Traits
{ {
class MineInfo : ITraitInfo, IOccupySpaceInfo class MineInfo : ITraitInfo
{ {
public readonly string[] CrushClasses = { }; public readonly string[] CrushClasses = { };
public readonly bool AvoidFriendly = true; public readonly bool AvoidFriendly = true;