diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 50addb641b..7ed631fc74 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -339,7 +339,7 @@ namespace OpenRa.Game heuristic = loc => { var b = Game.BuildingInfluence.GetBuildingAt(loc); - if (b != null && b.Owner == p && (b.LegacyInfo as LegacyBuildingInfo).BaseNormal) return 0; + if (b != null && b.Owner == p && b.Info.Traits.Get().BaseNormal) return 0; if ((loc - position).Length > maxDistance) return float.PositiveInfinity; /* not quite right */ return 1; diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index c732f7819d..57b707f670 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using IjwFramework.Collections; +using OpenRa.Game.Traits; namespace OpenRa.Game.GameRules { @@ -21,8 +22,8 @@ namespace OpenRa.Game.GameRules public Cache> GatherBuildings( Player player ) { var ret = new Cache>( x => new List() ); - foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.LegacyInfo is LegacyBuildingInfo ) ) - ret[ b.LegacyInfo.Name ].Add( b ); + foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info != null && x.Info.Traits.Contains() ) ) + ret[ b.Info.Name ].Add( b ); return ret; } diff --git a/OpenRa.Game/Orders/PowerDownOrderGenerator.cs b/OpenRa.Game/Orders/PowerDownOrderGenerator.cs index 2bfbb12359..84631b0596 100644 --- a/OpenRa.Game/Orders/PowerDownOrderGenerator.cs +++ b/OpenRa.Game/Orders/PowerDownOrderGenerator.cs @@ -25,7 +25,7 @@ namespace OpenRa.Game.Orders var underCursor = Game.FindUnits(loc, loc) .Where(a => a.Owner == Game.LocalPlayer && a.traits.Contains() - && a.LegacyInfo.Selectable).FirstOrDefault(); + && a.traits.Contains()).FirstOrDefault(); var building = underCursor != null ? underCursor.LegacyInfo as LegacyBuildingInfo : null; diff --git a/OpenRa.Game/Orders/RepairOrderGenerator.cs b/OpenRa.Game/Orders/RepairOrderGenerator.cs index 3d87fe6b6d..60d36c79ef 100644 --- a/OpenRa.Game/Orders/RepairOrderGenerator.cs +++ b/OpenRa.Game/Orders/RepairOrderGenerator.cs @@ -25,11 +25,11 @@ namespace OpenRa.Game.Orders var underCursor = Game.FindUnits(loc, loc) .Where(a => a.Owner == Game.LocalPlayer && a.traits.Contains() - && a.LegacyInfo.Selectable).FirstOrDefault(); + && a.traits.Contains()).FirstOrDefault(); - var building = underCursor != null ? underCursor.LegacyInfo as LegacyBuildingInfo : null; + var building = underCursor != null ? underCursor.Info.Traits.Get() : null; - if (building != null && building.Repairable && underCursor.Health < building.Strength) + if (building != null && building.Repairable && underCursor.Health < building.HP) yield return new Order("Repair", underCursor, null, int2.Zero, null); } } diff --git a/OpenRa.Game/Orders/SellOrderGenerator.cs b/OpenRa.Game/Orders/SellOrderGenerator.cs index b74c3b79cb..5c6f240f5b 100644 --- a/OpenRa.Game/Orders/SellOrderGenerator.cs +++ b/OpenRa.Game/Orders/SellOrderGenerator.cs @@ -25,9 +25,9 @@ namespace OpenRa.Game.Orders var underCursor = Game.FindUnits(loc, loc) .Where(a => a.Owner == Game.LocalPlayer && a.traits.Contains() - && a.LegacyInfo.Selectable).FirstOrDefault(); + && a.traits.Contains()).FirstOrDefault(); - var building = underCursor != null ? underCursor.LegacyInfo as LegacyBuildingInfo : null; + var building = underCursor != null ? underCursor.Info.Traits.Get() : null; if (building != null && !building.Unsellable) yield return new Order("Sell", underCursor, null, int2.Zero, null); diff --git a/OpenRa.Game/Traits/Activities/HeliReturn.cs b/OpenRa.Game/Traits/Activities/HeliReturn.cs index 83dd9cac75..3595f7dd6f 100644 --- a/OpenRa.Game/Traits/Activities/HeliReturn.cs +++ b/OpenRa.Game/Traits/Activities/HeliReturn.cs @@ -24,9 +24,11 @@ namespace OpenRa.Game.Traits.Activities if (isCanceled) return NextActivity; var dest = ChooseHelipad(self); + var initialFacing = self.Info.Traits.WithInterface().First().InitialFacing; + if (dest == null) return Util.SequenceActivities( - new Turn(self.LegacyInfo.InitialFacing), + new Turn(initialFacing), new HeliLand(true), NextActivity); @@ -34,12 +36,13 @@ namespace OpenRa.Game.Traits.Activities if (res != null) self.traits.Get().reservation = res.Reserve(self); - var offset = (dest.LegacyInfo as LegacyBuildingInfo).SpawnOffset; + var pi = dest.Info.Traits.GetOrDefault(); + var offset = pi != null ? pi.SpawnOffset : null; var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero; return Util.SequenceActivities( new HeliFly(dest.CenterLocation + offsetVec), - new Turn(self.LegacyInfo.InitialFacing), + new Turn(initialFacing), new HeliLand(false), new Rearm(), NextActivity); diff --git a/OpenRa.Game/Traits/Building.cs b/OpenRa.Game/Traits/Building.cs index c8a6c4c08a..66608059ae 100644 --- a/OpenRa.Game/Traits/Building.cs +++ b/OpenRa.Game/Traits/Building.cs @@ -31,6 +31,7 @@ namespace OpenRa.Game.Traits public readonly string[] Produces = { }; // does this go somewhere else? public readonly int2 Dimensions = new int2(1, 1); public readonly bool WaterBound = false; + public readonly bool Unsellable = false; public object Create(Actor self) { return new Building(self); } } diff --git a/OpenRa.Game/Traits/Repairable.cs b/OpenRa.Game/Traits/Repairable.cs index 77de5d6e35..0cada1212e 100644 --- a/OpenRa.Game/Traits/Repairable.cs +++ b/OpenRa.Game/Traits/Repairable.cs @@ -21,7 +21,7 @@ namespace OpenRa.Game.Traits if (mi.Button != MouseButton.Right) return null; if (underCursor == null) return null; - if (underCursor.LegacyInfo == Rules.UnitInfo["FIX"] + if (underCursor.Info.Name == "fix" && underCursor.Owner == self.Owner && !Reservable.IsReserved(underCursor)) return new Order("Enter", self, underCursor, int2.Zero, null); diff --git a/RulesConverter/Program.cs b/RulesConverter/Program.cs index 345476347b..4c51a1fe1d 100644 --- a/RulesConverter/Program.cs +++ b/RulesConverter/Program.cs @@ -116,7 +116,8 @@ namespace RulesConverter { "Crewed", "Crewed" }, { "WaterBound", "WaterBound" }, { "InitialFacing", "InitialFacing" }, - { "Sight", "Sight" } } + { "Sight", "Sight" }, + { "Unsellable", "Unsellable" } } }, { "StoresOre", new PL {