Cleaned up some casts. (BuildingInfo)

This commit is contained in:
Bob
2009-11-14 02:57:52 +13:00
parent f4e55572d6
commit c285f1d210
12 changed files with 76 additions and 72 deletions

View File

@@ -42,7 +42,7 @@ namespace OpenRa.Game.Traits.Activities
umt = mobile.GetMovementType(),
checkForBlocked = false,
};
var refineries = Game.world.Actors.Where( x => x.unitInfo == Rules.UnitInfo[ "proc" ] ).ToList();
var refineries = Game.world.Actors.Where( x => x.unitInfo.Name == "proc" ).ToList();
if( refinery != null )
search.AddInitialCell( refinery.Location + refineryDeliverOffset );
else

View File

@@ -8,8 +8,11 @@ namespace OpenRa.Game.Traits
{
class Building : ITick, INotifyBuildComplete
{
public readonly UnitInfo.BuildingInfo unitInfo;
public Building(Actor self)
{
unitInfo = (UnitInfo.BuildingInfo)self.unitInfo;
}
bool first = true;
@@ -23,10 +26,7 @@ namespace OpenRa.Game.Traits
public void BuildingComplete(Actor self)
{
UnitInfo.BuildingInfo bi = self.unitInfo as UnitInfo.BuildingInfo;
if (bi == null) return;
self.Owner.ChangePower(bi.Power);
self.Owner.ChangePower(unitInfo.Power);
}
}
}

View File

@@ -1,23 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class McvDeploy : IOrder
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class McvDeploy : IOrder
{
public McvDeploy(Actor self) { }
public McvDeploy(Actor self) { }
public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor)
{
if (lmb) return null;
if (xy == self.Location)
return OpenRa.Game.Order.DeployMcv(self, !Game.CanPlaceBuilding("fact", xy - new int2(1,1), self, false));
if( xy != self.Location ) return null;
return null;
}
}
}
var factBuildingInfo = (UnitInfo.BuildingInfo)Rules.UnitInfo[ "fact" ];
return OpenRa.Game.Order.DeployMcv(self, !Game.CanPlaceBuilding(factBuildingInfo, xy - new int2(1,1), self, false));
}
}
}

View File

@@ -84,10 +84,19 @@ namespace OpenRa.Game.Traits
public UnitMovementType GetMovementType()
{
var vi = self.unitInfo as UnitInfo.VehicleInfo;
if (vi == null) return UnitMovementType.Foot;
if (vi.WaterBound) return UnitMovementType.Float;
return vi.Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
switch( Rules.UnitCategory[ self.unitInfo.Name ] )
{
case "Infantry":
return UnitMovementType.Foot;
case "Vehicle":
return ( self.unitInfo as UnitInfo.VehicleInfo ).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
case "Ship":
return UnitMovementType.Float;
case "Plane":
return UnitMovementType.Track; // FIXME: remove this when planes actually fly.
default:
throw new InvalidOperationException( "GetMovementType on unit that shouldn't be aable to move." );
}
}
public IEnumerable<int2> GetCurrentPath()

View File

@@ -15,7 +15,7 @@ namespace OpenRa.Game.Traits
public RallyPoint(Actor self)
{
var bi = (UnitInfo.BuildingInfo)self.unitInfo;
var bi = self.traits.Get<Building>().unitInfo;
rallyPoint = self.Location + new int2(bi.RallyPoint[0], bi.RallyPoint[1]);
anim = new Animation("flagfly");
anim.PlayRepeating("idle");

View File

@@ -43,7 +43,7 @@ namespace OpenRa.Game.Traits
void DoBib(Actor self, bool isRemove)
{
var buildingInfo = (UnitInfo.BuildingInfo)self.unitInfo;
var buildingInfo = self.traits.Get<Building>().unitInfo;
if (buildingInfo.Bib)
{
var size = buildingInfo.Dimensions.X;