diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 8716c928c8..e4d231bba9 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -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(); - 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(); 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()) .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); } } diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index 7e1eef92b6..d2fcc9aafb 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -29,20 +29,20 @@ namespace OpenRa.Game.GameRules return ret; } - public bool CanBuild( LegacyUnitInfo unit, Player player, Cache> playerBuildings ) + public bool CanBuild( NewUnitInfo info, Player player, Cache> playerBuildings ) { - if( unit.TechLevel == -1 ) + var bi = info.Traits.GetOrDefault(); + 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 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; }