starting to fix refs to Rules.UnitInfo

This commit is contained in:
Bob
2010-01-12 22:22:10 +13:00
parent d707fe420f
commit 16a9189bec
2 changed files with 18 additions and 17 deletions

View File

@@ -731,14 +731,15 @@ namespace OpenRa.Game
rgbaRenderer.DrawSprite(tooltipSprite, p, PaletteType.Chrome);
rgbaRenderer.Flush();
var info = Rules.UnitInfo[unit];
var info = Rules.NewUnitInfo[unit];
var buildable = info.Traits.Get<BuildableInfo>();
renderer.DrawText2(info.Description, p.ToInt2() + new int2(5,5), Color.White);
renderer.DrawText2(buildable.Description, p.ToInt2() + new int2(5,5), Color.White);
DrawRightAligned( "${0}".F(info.Cost), pos + new int2(-5,5),
Game.LocalPlayer.Cash + Game.LocalPlayer.Ore >= info.Cost ? Color.White : Color.Red);
DrawRightAligned( "${0}".F(buildable.Cost), pos + new int2(-5,5),
Game.LocalPlayer.Cash + Game.LocalPlayer.Ore >= buildable.Cost ? Color.White : Color.Red);
var bi = info as LegacyBuildingInfo;
var bi = info.Traits.GetOrDefault<BuildingInfo>();
if (bi != null)
DrawRightAligned("ϟ{0}".F(bi.Power), pos + new int2(-5, 20),
Game.LocalPlayer.PowerProvided - Game.LocalPlayer.PowerDrained + bi.Power >= 0
@@ -749,18 +750,18 @@ namespace OpenRa.Game
p += new int2(0, 15);
if (!Rules.TechTree.CanBuild(info, Game.LocalPlayer, buildings))
{
var prereqs = info.Prerequisite
.Select(a => Rules.UnitInfo[a.ToLowerInvariant()])
var prereqs = buildable.Prerequisites
.Select(a => Rules.NewUnitInfo[a.ToLowerInvariant()].Traits.Get<BuildableInfo>())
.Where( u => u.Owner.Any( o => o == Game.LocalPlayer.Race ) )
.Select( a => a.Description );
renderer.DrawText("Requires {0}".F( string.Join( ", ", prereqs.ToArray() ) ), p.ToInt2(),
Color.White);
}
if (info.LongDesc != null)
if (buildable.LongDesc != null)
{
p += new int2(0, 15);
renderer.DrawText(info.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White);
renderer.DrawText(buildable.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White);
}
}

View File

@@ -29,20 +29,20 @@ namespace OpenRa.Game.GameRules
return ret;
}
public bool CanBuild( LegacyUnitInfo unit, Player player, Cache<string, List<Actor>> playerBuildings )
public bool CanBuild( NewUnitInfo info, Player player, Cache<string, List<Actor>> playerBuildings )
{
if( unit.TechLevel == -1 )
var bi = info.Traits.GetOrDefault<BuildableInfo>();
if( bi == null ) return false;
if( !bi.Owner.Any( x => x == player.Race ) )
return false;
if( !unit.Owner.Any( x => x == player.Race ) )
return false;
foreach( var p in unit.Prerequisite )
foreach( var p in bi.Prerequisites )
if (Rules.UnitInfo[p.ToLowerInvariant()].Owner.Any(x => x == player.Race))
if( playerBuildings[ p ].Count == 0 )
return false;
if( producesIndex[ Rules.UnitCategory[ unit.Name ] ].All( x => playerBuildings[ x.Name ].Count == 0 ) )
if( producesIndex[ Rules.UnitCategory[ info.Name ] ].All( x => playerBuildings[ x.Name ].Count == 0 ) )
return false;
return true;
@@ -51,7 +51,7 @@ namespace OpenRa.Game.GameRules
public IEnumerable<string> BuildableItems( Player player, params string[] categories )
{
var playerBuildings = GatherBuildings( player );
foreach( var unit in categories.SelectMany( x => Rules.Categories[ x ] ).Select( x => Rules.UnitInfo[ x ] ) )
foreach( var unit in categories.SelectMany( x => Rules.Categories[ x ] ).Select( x => Rules.NewUnitInfo[ x ] ) )
if( CanBuild( unit, player, playerBuildings ) )
yield return unit.Name;
}