IOccupySpace split off; BuildingInfo.BaseNormal works again.

This commit is contained in:
Chris Forbes
2009-12-08 20:07:39 +13:00
parent ff8de0b676
commit 2c4b29bd51
3 changed files with 34 additions and 37 deletions

View File

@@ -239,14 +239,6 @@ namespace OpenRa.Game
.FirstOrDefault(); .FirstOrDefault();
} }
public static int GetDistanceToBase(int2 b, Player p)
{
var building = BuildingInfluence.GetNearestBuilding(b);
if (building == null || building.Owner != p)
return int.MaxValue;
return BuildingInfluence.GetDistanceToBuilding(b);
}
public static Random SharedRandom = new Random(0); /* for things that require sync */ public static Random SharedRandom = new Random(0); /* for things that require sync */
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */ public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
@@ -282,7 +274,7 @@ namespace OpenRa.Game
heuristic = loc => heuristic = loc =>
{ {
var b = Game.BuildingInfluence.GetBuildingAt(loc); var b = Game.BuildingInfluence.GetBuildingAt(loc);
if (b != null && b.Owner == p) return 0; if (b != null && b.Owner == p && (b.Info as BuildingInfo).BaseNormal) return 0;
if ((loc - position).Length > maxDistance) if ((loc - position).Length > maxDistance)
return float.PositiveInfinity; /* not quite right */ return float.PositiveInfinity; /* not quite right */
return 1; return 1;

View File

@@ -5,42 +5,46 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class Mobile : IOrder class Mobile : IOrder, IOccupySpace
{ {
public Actor self; public Actor self;
int2 __fromCell; int2 __fromCell;
public int2 fromCell { get { return __fromCell; } set { Game.UnitInfluence.Remove( this ); __fromCell = value; Game.UnitInfluence.Add( this ); } } public int2 fromCell
public int2 toCell { get { return self.Location; } set { Game.UnitInfluence.Remove( this ); self.Location = value; Game.UnitInfluence.Add( this ); } } {
get { return __fromCell; }
set { Game.UnitInfluence.Remove(this); __fromCell = value; Game.UnitInfluence.Add(this); }
}
public int2 toCell
{
get { return self.Location; }
set { Game.UnitInfluence.Remove(this); self.Location = value; Game.UnitInfluence.Add(this); }
}
public Mobile(Actor self) public Mobile(Actor self)
{ {
this.self = self; this.self = self;
fromCell = toCell; fromCell = toCell;
Game.UnitInfluence.Update( this ); Game.UnitInfluence.Update(this);
} }
public Order IssueOrder(Actor self, int2 xy, bool lmb, Actor underCursor) public Order IssueOrder(Actor self, int2 xy, bool lmb, Actor underCursor)
{ {
if( lmb ) return null; if (lmb) return null;
if (underCursor != null) return null;
if( underCursor != null )
return null;
if (xy == toCell) return null; if (xy == toCell) return null;
return Order.Move(self, xy);
return Order.Move( self, xy );
} }
public void ResolveOrder( Actor self, Order order ) public void ResolveOrder(Actor self, Order order)
{ {
if( order.OrderString == "Move" ) if (order.OrderString == "Move")
{ {
self.CancelActivity(); self.CancelActivity();
self.QueueActivity( new Traits.Activities.Move( order.TargetLocation, 8 ) ); self.QueueActivity(new Activities.Move(order.TargetLocation, 8));
var attackBase = self.traits.WithInterface<AttackBase>().FirstOrDefault(); var attackBase = self.traits.WithInterface<AttackBase>().FirstOrDefault();
if( attackBase != null ) if (attackBase != null)
attackBase.target = null; /* move cancels attack order */ attackBase.target = null; /* move cancels attack order */
} }
} }
@@ -52,24 +56,24 @@ namespace OpenRa.Game.Traits
public UnitMovementType GetMovementType() public UnitMovementType GetMovementType()
{ {
switch( Rules.UnitCategory[ self.Info.Name ] ) switch (Rules.UnitCategory[self.Info.Name])
{ {
case "Infantry": case "Infantry":
return UnitMovementType.Foot; return UnitMovementType.Foot;
case "Vehicle": case "Vehicle":
return ( self.Info as VehicleInfo ).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel; return (self.Info as VehicleInfo).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
case "Ship": case "Ship":
return UnitMovementType.Float; return UnitMovementType.Float;
case "Plane": case "Plane":
return UnitMovementType.Track; // FIXME: remove this when planes actually fly. return UnitMovementType.Track; // FIXME: remove this when planes actually fly.
default: default:
throw new InvalidOperationException( "GetMovementType on unit that shouldn't be aable to move." ); throw new InvalidOperationException("GetMovementType on unit that shouldn't be aable to move.");
} }
} }
public IEnumerable<int2> GetCurrentPath() public IEnumerable<int2> GetCurrentPath()
{ {
var move = self.GetCurrentActivity() as Traits.Activities.Move; var move = self.GetCurrentActivity() as Activities.Move;
if (move == null || move.path == null) return new int2[] { }; if (move == null || move.path == null) return new int2[] { };
return Enumerable.Reverse(move.path); return Enumerable.Reverse(move.path);
} }

View File

@@ -16,5 +16,6 @@ namespace OpenRa.Game.Traits
Order IssueOrder( Actor self, int2 xy, bool lmb, Actor underCursor ); Order IssueOrder( Actor self, int2 xy, bool lmb, Actor underCursor );
void ResolveOrder( Actor self, Order order ); void ResolveOrder( Actor self, Order order );
} }
interface IProducer { bool Produce( Actor self, UnitInfo produceee ); } interface IProducer { bool Produce( Actor self, UnitInfo producee ); }
interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }
} }