diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 46bb94cd05..158acad021 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -28,22 +28,21 @@ namespace OpenRa.Game CenterLocation = Traits.Util.CenterOfCell(Location); Owner = owner; - if( Info != null ) - { - Health = Info.Strength; /* todo: handle cases where this is not true! */ + if (Info == null) return; - if( Info.Traits != null ) - { - foreach( var traitName in Info.Traits ) - { - var type = typeof( Traits.Mobile ).Assembly.GetType( typeof( Traits.Mobile ).Namespace + "." + traitName, true, false ); - var ctor = type.GetConstructor( new[] { typeof( Actor ) } ); - traits.Add( type, ctor.Invoke( new object[] { this } ) ); - } - } - else - throw new InvalidOperationException( "No Actor traits for " + Info.Name - + "; add Traits= to units.ini for appropriate unit" ); + Health = Info.Strength; /* todo: handle cases where this is not true! */ + + if( Info.Traits == null ) + throw new InvalidOperationException( "No Actor traits for {0}; add Traits= to units.ini for appropriate unit".F(Info.Name) ); + + foreach (var traitName in Info.Traits) + { /* todo: a better solution than `the assembly Mobile lives in`, for mod support & sanity. */ + var type = typeof(Mobile).Assembly.GetType(typeof(Mobile).Namespace + "." + traitName, true, false); + var ctor = type.GetConstructor(new[] { typeof(Actor) }); + if (ctor == null) + throw new InvalidOperationException("Trait {0} does not have the correct constructor: {0}(Actor self)".F(type.Name)); + + traits.Add(type, ctor.Invoke(new object[] { this })); } } @@ -56,7 +55,7 @@ namespace OpenRa.Game nextActivity = nextActivity.Tick( this ); } - foreach (var tick in traits.WithInterface()) + foreach (var tick in traits.WithInterface()) tick.Tick(this); } @@ -74,7 +73,7 @@ namespace OpenRa.Game public IEnumerable> Render() { - return traits.WithInterface().SelectMany( x => x.Render( this ) ); + return traits.WithInterface().SelectMany( x => x.Render( this ) ); } public Order Order( int2 xy, MouseInput mi ) @@ -90,7 +89,7 @@ namespace OpenRa.Game if (underCursor != null && !underCursor.Info.Selectable) underCursor = null; - return traits.WithInterface() + return traits.WithInterface() .Select( x => x.IssueOrder( this, xy, mi, underCursor ) ) .FirstOrDefault( x => x != null ); } diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index e608c4f258..a39cb7b456 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -149,7 +149,7 @@ namespace OpenRa.Game } } - Cache> cache = new Cache>(_ => new List()); + Cache> controlGroups = new Cache>(_ => new List()); public void DoControlGroup(int group, Modifiers mods) { @@ -159,19 +159,19 @@ namespace OpenRa.Game if (uog == null || !uog.selection.Any()) return; - cache[group].Clear(); - cache[group].AddRange(uog.selection); + controlGroups[group].Clear(); + controlGroups[group].AddRange(uog.selection); return; } if (mods.HasModifier(Modifiers.Alt)) { - Game.viewport.Center(cache[group]); + Game.viewport.Center(controlGroups[group]); return; } if (uog == null) return; - CombineSelection(cache[group], mods.HasModifier(Modifiers.Shift), false); + CombineSelection(controlGroups[group], mods.HasModifier(Modifiers.Shift), false); } } } diff --git a/OpenRa.Game/Game Code.cd b/OpenRa.Game/Game Code.cd index 73e48dc116..9121b137c1 100644 --- a/OpenRa.Game/Game Code.cd +++ b/OpenRa.Game/Game Code.cd @@ -1,10 +1,11 @@  - + - + + + AAIAAAAABAAACABCAAYAEEAAAABAAAAAAAAgAEEIwBE= Graphics\Viewport.cs - + - + @@ -81,7 +95,12 @@ - + + + QEEEAAQAAAIAQQAACAMAACCAAAAAAA0gCAEAAQABQAA= Player.cs @@ -123,7 +142,17 @@ - + + + AAAAAAAAAAAAAAAgAACAAAICAAgAEoAAMAAAAAAAAgA= PathFinder.cs