diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 51b31518a2..b802a517cf 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -26,10 +26,10 @@ namespace OpenRa.Game public int Health; IActivity currentActivity; - public Actor( ActorInfo info, int2 location, Player owner ) + public Actor( string name, int2 location, Player owner ) { ActorID = Game.world.NextAID(); - LegacyInfo = (LegacyUnitInfo)info; // temporary + LegacyInfo = name != null ? Rules.UnitInfo[name.ToLowerInvariant()] : null; // temporary Location = location; CenterLocation = Traits.Util.CenterOfCell(Location); Owner = owner; @@ -38,10 +38,7 @@ namespace OpenRa.Game Health = LegacyInfo.Strength; /* todo: fix walls, etc so this is always true! */ - if( LegacyInfo.Traits == null ) - throw new InvalidOperationException( "No Actor traits for {0}; add Traits= to units.ini for appropriate unit".F(LegacyInfo.Name) ); - - Info = Rules.NewUnitInfo[LegacyInfo.Name.ToLowerInvariant()]; + Info = Rules.NewUnitInfo[name.ToLowerInvariant()]; foreach (var trait in Info.Traits.WithInterface()) traits.Add(trait.Create(this)); @@ -66,12 +63,13 @@ namespace OpenRa.Game } public float2 CenterLocation; - public float2 SelectedSize + float2 SelectedSize { - get + get // todo: inline into GetBounds { - if (LegacyInfo != null && LegacyInfo.SelectionSize != null) - return new float2(LegacyInfo.SelectionSize[0], LegacyInfo.SelectionSize[1]); + var si = Info != null ? Info.Traits.GetOrDefault() : null; + if (si != null && si.Bounds != null) + return new float2(si.Bounds[0], si.Bounds[1]); var firstSprite = Render().FirstOrDefault(); if (firstSprite.Sprite == null) return float2.Zero; @@ -97,7 +95,7 @@ namespace OpenRa.Game var loc = mi.Location + Game.viewport.Location; var underCursor = Game.FindUnits(loc, loc).FirstOrDefault(); - if (underCursor != null && !underCursor.LegacyInfo.Selectable) + if (underCursor != null && !underCursor.traits.Contains()) underCursor = null; return traits.WithInterface() @@ -107,10 +105,13 @@ namespace OpenRa.Game public RectangleF GetBounds(bool useAltitude) { + var si = Info != null ? Info.Traits.GetOrDefault() : null; + var size = SelectedSize; var loc = CenterLocation - 0.5f * size; - if (LegacyInfo != null && LegacyInfo.SelectionSize != null && LegacyInfo.SelectionSize.Length > 2) - loc += new float2(LegacyInfo.SelectionSize[2], LegacyInfo.SelectionSize[3]); + + if (si != null && si.Bounds != null && si.Bounds.Length > 2) + loc += new float2(si.Bounds[2], si.Bounds[3]); if (useAltitude) { diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 7ed631fc74..c3237a5470 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -78,8 +78,8 @@ namespace OpenRa.Game } var worldActor = new Actor(null, new int2(int.MaxValue, int.MaxValue), null); - worldActor.traits.Add(new Traits.WaterPaletteRotation(worldActor)); - worldActor.traits.Add(new Traits.ChronoshiftPaletteEffect(worldActor)); + worldActor.traits.Add(new WaterPaletteRotation(worldActor)); + worldActor.traits.Add(new ChronoshiftPaletteEffect(worldActor)); Game.world.Add(worldActor); Rules.Map.InitOreDensity(); @@ -95,9 +95,7 @@ namespace OpenRa.Game skipMakeAnims = true; foreach (var treeReference in Rules.Map.Trees) - world.Add(new Actor(Rules.UnitInfo[treeReference.Image], - new int2(treeReference.Location), - null)); + world.Add(new Actor(treeReference.Image, new int2(treeReference.Location), null)); LoadMapActors(Rules.AllRules); skipMakeAnims = false; @@ -148,7 +146,7 @@ namespace OpenRa.Game //num=owner,type,health,location,facing,... var parts = s.Value.Split( ',' ); var loc = int.Parse(parts[3]); - world.Add(new Actor(Rules.UnitInfo[parts[1].ToLowerInvariant()], new int2(loc % 128, loc / 128), + world.Add(new Actor(parts[1].ToLowerInvariant(), new int2(loc % 128, loc / 128), players.Values.FirstOrDefault(p => p.InternalName == parts[0]) ?? players[0])); } } diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index b90d6ec98f..44b1d197ab 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -220,7 +220,7 @@ namespace OpenRa.Game.Graphics spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, PaletteType.Chrome); pipxyOffset += new float2(4, 0); - if (pipxyOffset.X+5 > selectedUnit.SelectedSize.X) + if (pipxyOffset.X+5 > selectedUnit.GetBounds(false).Width) { pipxyOffset.X = 0; pipxyOffset.Y -= 4; diff --git a/OpenRa.Game/Orders/UnitOrders.cs b/OpenRa.Game/Orders/UnitOrders.cs index 66646d787c..327f1e3a05 100644 --- a/OpenRa.Game/Orders/UnitOrders.cs +++ b/OpenRa.Game/Orders/UnitOrders.cs @@ -15,22 +15,19 @@ namespace OpenRa.Game.Orders { Game.world.AddFrameEndTask( _ => { - var queue = order.Player.PlayerActor.traits.Get(); - var building = (LegacyBuildingInfo)Rules.UnitInfo[ order.TargetString ]; + var queue = order.Player.PlayerActor.traits.Get(); var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]); if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) return; - Log.Write( "Player \"{0}\" builds {1}", order.Player.PlayerName, building.Name ); - - Game.world.Add( new Actor( building, order.TargetLocation - GameRules.Footprint.AdjustForBuildingSize( building ), order.Player ) ); + Game.world.Add( new Actor( order.TargetString, order.TargetLocation - Footprint.AdjustForBuildingSize( (LegacyBuildingInfo)Rules.UnitInfo[ order.TargetString ] ), order.Player ) ); if (order.Player == Game.LocalPlayer) { Sound.Play("placbldg.aud"); Sound.Play("build5.aud"); } - queue.FinishProduction(Rules.UnitCategory[building.Name]); + queue.FinishProduction(Rules.UnitCategory[order.TargetString]); } ); break; } diff --git a/OpenRa.Game/Traits/AcceptsOre.cs b/OpenRa.Game/Traits/AcceptsOre.cs index 6c8c200afa..6029420859 100644 --- a/OpenRa.Game/Traits/AcceptsOre.cs +++ b/OpenRa.Game/Traits/AcceptsOre.cs @@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits Game.world.AddFrameEndTask( w => { /* create the free harvester! */ - var harvester = new Actor(Rules.UnitInfo["harv"], self.Location + new int2(1, 2), self.Owner); + var harvester = new Actor("harv", self.Location + new int2(1, 2), self.Owner); var unit = harvester.traits.Get(); var mobile = harvester.traits.Get(); unit.Facing = 64; diff --git a/OpenRa.Game/Traits/Activities/DeployMcv.cs b/OpenRa.Game/Traits/Activities/DeployMcv.cs index 49b8488abf..a738664e8a 100755 --- a/OpenRa.Game/Traits/Activities/DeployMcv.cs +++ b/OpenRa.Game/Traits/Activities/DeployMcv.cs @@ -17,7 +17,7 @@ namespace OpenRa.Game.Traits.Activities Sound.Play("placbldg.aud"); Sound.Play("build5.aud"); } - Game.world.Add( new Actor( Rules.UnitInfo["fact"], self.Location - new int2( 1, 1 ), self.Owner ) ); + Game.world.Add( new Actor( "fact", self.Location - new int2( 1, 1 ), self.Owner ) ); } ); return this; } diff --git a/OpenRa.Game/Traits/Activities/UndeployMcv.cs b/OpenRa.Game/Traits/Activities/UndeployMcv.cs index 7e9241157d..912c993616 100644 --- a/OpenRa.Game/Traits/Activities/UndeployMcv.cs +++ b/OpenRa.Game/Traits/Activities/UndeployMcv.cs @@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits.Activities ns.Sold(self); w.Remove(self); - var mcv = new Actor(Rules.UnitInfo["MCV"], self.Location + new int2(1, 1), self.Owner); + var mcv = new Actor("mcv", self.Location + new int2(1, 1), self.Owner); mcv.traits.Get().Facing = 96; w.Add(mcv); } diff --git a/OpenRa.Game/Traits/AutoHeal.cs b/OpenRa.Game/Traits/AutoHeal.cs index 66cc04ba6a..d31041939a 100644 --- a/OpenRa.Game/Traits/AutoHeal.cs +++ b/OpenRa.Game/Traits/AutoHeal.cs @@ -48,7 +48,7 @@ namespace OpenRa.Game.Traits return inRange .Where(a => a.Owner == self.Owner && a != self) /* todo: one day deal with friendly players */ .Where(a => Combat.HasAnyValidWeapons(self, a)) - .Where(a => a.Health < a.LegacyInfo.Strength) + .Where(a => a.Health < a.Info.Traits.WithInterface().First().HP) .OrderBy(a => (a.Location - self.Location).LengthSquared) .FirstOrDefault(); } diff --git a/OpenRa.Game/Traits/Minelayer.cs b/OpenRa.Game/Traits/Minelayer.cs index cc590269c7..0f5c5194f6 100644 --- a/OpenRa.Game/Traits/Minelayer.cs +++ b/OpenRa.Game/Traits/Minelayer.cs @@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits // todo: delay a bit? (req making deploy-mine an activity) Game.world.AddFrameEndTask( - w => w.Add(new Actor(Rules.UnitInfo[self.LegacyInfo.Primary], self.Location, self.Owner))); + w => w.Add(new Actor(self.LegacyInfo.Primary, self.Location, self.Owner))); } } } diff --git a/OpenRa.Game/Traits/Production.cs b/OpenRa.Game/Traits/Production.cs index 8ed3520461..ade7b28856 100755 --- a/OpenRa.Game/Traits/Production.cs +++ b/OpenRa.Game/Traits/Production.cs @@ -35,7 +35,7 @@ namespace OpenRa.Game.Traits if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() ) return false; - var newUnit = new Actor( producee, location.Value, self.Owner ); + var newUnit = new Actor( producee.Name, location.Value, self.Owner ); newUnit.traits.Get().Facing = CreationFacing( self, newUnit ); ; var rp = self.traits.GetOrDefault();