cache => controlGroups; not sure what i was smoking then. also more sane exceptions in Actor.ctor
This commit is contained in:
@@ -28,22 +28,21 @@ namespace OpenRa.Game
|
|||||||
CenterLocation = Traits.Util.CenterOfCell(Location);
|
CenterLocation = Traits.Util.CenterOfCell(Location);
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
|
|
||||||
if( Info != null )
|
if (Info == null) return;
|
||||||
{
|
|
||||||
Health = Info.Strength; /* todo: handle cases where this is not true! */
|
|
||||||
|
|
||||||
if( Info.Traits != null )
|
Health = Info.Strength; /* todo: handle cases where this is not true! */
|
||||||
{
|
|
||||||
foreach( var traitName in Info.Traits )
|
if( Info.Traits == null )
|
||||||
{
|
throw new InvalidOperationException( "No Actor traits for {0}; add Traits= to units.ini for appropriate unit".F(Info.Name) );
|
||||||
var type = typeof( Traits.Mobile ).Assembly.GetType( typeof( Traits.Mobile ).Namespace + "." + traitName, true, false );
|
|
||||||
var ctor = type.GetConstructor( new[] { typeof( Actor ) } );
|
foreach (var traitName in Info.Traits)
|
||||||
traits.Add( type, ctor.Invoke( new object[] { this } ) );
|
{ /* 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) });
|
||||||
else
|
if (ctor == null)
|
||||||
throw new InvalidOperationException( "No Actor traits for " + Info.Name
|
throw new InvalidOperationException("Trait {0} does not have the correct constructor: {0}(Actor self)".F(type.Name));
|
||||||
+ "; add Traits= to units.ini for appropriate unit" );
|
|
||||||
|
traits.Add(type, ctor.Invoke(new object[] { this }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ namespace OpenRa.Game
|
|||||||
nextActivity = nextActivity.Tick( this );
|
nextActivity = nextActivity.Tick( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var tick in traits.WithInterface<Traits.ITick>())
|
foreach (var tick in traits.WithInterface<ITick>())
|
||||||
tick.Tick(this);
|
tick.Tick(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +73,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public IEnumerable<Tuple<Sprite, float2, int>> Render()
|
public IEnumerable<Tuple<Sprite, float2, int>> Render()
|
||||||
{
|
{
|
||||||
return traits.WithInterface<Traits.IRender>().SelectMany( x => x.Render( this ) );
|
return traits.WithInterface<IRender>().SelectMany( x => x.Render( this ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order Order( int2 xy, MouseInput mi )
|
public Order Order( int2 xy, MouseInput mi )
|
||||||
@@ -90,7 +89,7 @@ namespace OpenRa.Game
|
|||||||
if (underCursor != null && !underCursor.Info.Selectable)
|
if (underCursor != null && !underCursor.Info.Selectable)
|
||||||
underCursor = null;
|
underCursor = null;
|
||||||
|
|
||||||
return traits.WithInterface<Traits.IOrder>()
|
return traits.WithInterface<IOrder>()
|
||||||
.Select( x => x.IssueOrder( this, xy, mi, underCursor ) )
|
.Select( x => x.IssueOrder( this, xy, mi, underCursor ) )
|
||||||
.FirstOrDefault( x => x != null );
|
.FirstOrDefault( x => x != null );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache<int, List<Actor>> cache = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
||||||
|
|
||||||
public void DoControlGroup(int group, Modifiers mods)
|
public void DoControlGroup(int group, Modifiers mods)
|
||||||
{
|
{
|
||||||
@@ -159,19 +159,19 @@ namespace OpenRa.Game
|
|||||||
if (uog == null || !uog.selection.Any())
|
if (uog == null || !uog.selection.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cache[group].Clear();
|
controlGroups[group].Clear();
|
||||||
cache[group].AddRange(uog.selection);
|
controlGroups[group].AddRange(uog.selection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mods.HasModifier(Modifiers.Alt))
|
if (mods.HasModifier(Modifiers.Alt))
|
||||||
{
|
{
|
||||||
Game.viewport.Center(cache[group]);
|
Game.viewport.Center(controlGroups[group]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uog == null) return;
|
if (uog == null) return;
|
||||||
CombineSelection(cache[group], mods.HasModifier(Modifiers.Shift), false);
|
CombineSelection(controlGroups[group], mods.HasModifier(Modifiers.Shift), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||||
<Class Name="OpenRa.Game.Game">
|
<Class Name="OpenRa.Game.Game">
|
||||||
<Position X="9.5" Y="9.25" Width="1.5" />
|
<Position X="9.5" Y="9.25" Width="2.25" />
|
||||||
<Members>
|
<Members>
|
||||||
<Method Name="FindUnits" Hidden="true" />
|
<Method Name="FindUnits" Hidden="true" />
|
||||||
<Field Name="lastTime" Hidden="true" />
|
<Field Name="lastTime" Hidden="true" />
|
||||||
|
<Method Name="LoadMapActors" Hidden="true" />
|
||||||
<Field Name="localPlayerIndex" Hidden="true" />
|
<Field Name="localPlayerIndex" Hidden="true" />
|
||||||
<Field Name="oreFrequency" Hidden="true" />
|
<Field Name="oreFrequency" Hidden="true" />
|
||||||
<Field Name="oreTicks" Hidden="true" />
|
<Field Name="oreTicks" Hidden="true" />
|
||||||
@@ -24,12 +25,16 @@
|
|||||||
<Position X="6.5" Y="10.75" Width="1.75" />
|
<Position X="6.5" Y="10.75" Width="1.75" />
|
||||||
<Members>
|
<Members>
|
||||||
<Method Name="ApplyOrders" Hidden="true" />
|
<Method Name="ApplyOrders" Hidden="true" />
|
||||||
|
<Method Name="CombineSelection" Hidden="true" />
|
||||||
|
<Field Name="controlGroups" Hidden="true" />
|
||||||
|
<Method Name="CursorForOrderString" Hidden="true" />
|
||||||
<Field Name="dragEnd" Hidden="true" />
|
<Field Name="dragEnd" Hidden="true" />
|
||||||
<Field Name="dragStart" Hidden="true" />
|
<Field Name="dragStart" Hidden="true" />
|
||||||
|
<Field Name="GetModifierKeys" Hidden="true" />
|
||||||
<Field Name="recentOrders" Hidden="true" />
|
<Field Name="recentOrders" Hidden="true" />
|
||||||
</Members>
|
</Members>
|
||||||
<TypeIdentifier>
|
<TypeIdentifier>
|
||||||
<HashCode>ACACAACoAAAAAAAAAAQDEgQAABAAAAAAAAAAKAACCAA=</HashCode>
|
<HashCode>AAACAACoAAAAAAAAAAQDEgQAABAAABAAAAAAKAACCAA=</HashCode>
|
||||||
<FileName>Controller.cs</FileName>
|
<FileName>Controller.cs</FileName>
|
||||||
</TypeIdentifier>
|
</TypeIdentifier>
|
||||||
<ShowAsAssociation>
|
<ShowAsAssociation>
|
||||||
@@ -38,14 +43,23 @@
|
|||||||
<Lollipop Position="0.2" />
|
<Lollipop Position="0.2" />
|
||||||
</Class>
|
</Class>
|
||||||
<Class Name="OpenRa.Game.Graphics.Viewport">
|
<Class Name="OpenRa.Game.Graphics.Viewport">
|
||||||
<Position X="12.5" Y="10.25" Width="1.5" />
|
<Position X="13.5" Y="10.25" Width="1.75" />
|
||||||
|
<Members>
|
||||||
|
<Field Name="cursorFrame" Hidden="true" />
|
||||||
|
<Field Name="cursorRenderer" Hidden="true" />
|
||||||
|
<Field Name="dragRegion" Hidden="true" />
|
||||||
|
<Field Name="mousePos" Hidden="true" />
|
||||||
|
<Field Name="renderer" Hidden="true" />
|
||||||
|
<Field Name="screenSize" Hidden="true" />
|
||||||
|
<Field Name="scrollPosition" Hidden="true" />
|
||||||
|
</Members>
|
||||||
<TypeIdentifier>
|
<TypeIdentifier>
|
||||||
<HashCode>AAIAAAAABAAACABCAAYAEEAAAABAAAAAAAAgAEEIwBE=</HashCode>
|
<HashCode>AAIAAAAABAAACABCAAYAEEAAAABAAAAAAAAgAEEIwBE=</HashCode>
|
||||||
<FileName>Graphics\Viewport.cs</FileName>
|
<FileName>Graphics\Viewport.cs</FileName>
|
||||||
</TypeIdentifier>
|
</TypeIdentifier>
|
||||||
</Class>
|
</Class>
|
||||||
<Class Name="OpenRa.Game.World">
|
<Class Name="OpenRa.Game.World">
|
||||||
<Position X="4.75" Y="17.25" Width="1.5" />
|
<Position X="4.75" Y="17.25" Width="2" />
|
||||||
<Members>
|
<Members>
|
||||||
<Field Name="actors" Hidden="true" />
|
<Field Name="actors" Hidden="true" />
|
||||||
<Field Name="effects" Hidden="true" />
|
<Field Name="effects" Hidden="true" />
|
||||||
@@ -61,7 +75,7 @@
|
|||||||
</ShowAsCollectionAssociation>
|
</ShowAsCollectionAssociation>
|
||||||
</Class>
|
</Class>
|
||||||
<Class Name="OpenRa.Game.Actor">
|
<Class Name="OpenRa.Game.Actor">
|
||||||
<Position X="9.5" Y="16.75" Width="1.5" />
|
<Position X="9.5" Y="16.75" Width="1.75" />
|
||||||
<Members>
|
<Members>
|
||||||
<Field Name="currentActivity" Hidden="true" />
|
<Field Name="currentActivity" Hidden="true" />
|
||||||
</Members>
|
</Members>
|
||||||
@@ -81,7 +95,12 @@
|
|||||||
</TypeIdentifier>
|
</TypeIdentifier>
|
||||||
</Class>
|
</Class>
|
||||||
<Class Name="OpenRa.Game.Player">
|
<Class Name="OpenRa.Game.Player">
|
||||||
<Position X="11.75" Y="16.75" Width="1.5" />
|
<Position X="11.75" Y="16.75" Width="2.25" />
|
||||||
|
<Members>
|
||||||
|
<Field Name="displayCashDeltaPerFrame" Hidden="true" />
|
||||||
|
<Method Name="GiveAdvice" Hidden="true" />
|
||||||
|
<Method Name="UpdatePower" Hidden="true" />
|
||||||
|
</Members>
|
||||||
<TypeIdentifier>
|
<TypeIdentifier>
|
||||||
<HashCode>QEEEAAQAAAIAQQAACAMAACCAAAAAAA0gCAEAAQABQAA=</HashCode>
|
<HashCode>QEEEAAQAAAIAQQAACAMAACCAAAAAAA0gCAEAAQABQAA=</HashCode>
|
||||||
<FileName>Player.cs</FileName>
|
<FileName>Player.cs</FileName>
|
||||||
@@ -123,7 +142,17 @@
|
|||||||
</TypeIdentifier>
|
</TypeIdentifier>
|
||||||
</Class>
|
</Class>
|
||||||
<Class Name="OpenRa.Game.PathFinder">
|
<Class Name="OpenRa.Game.PathFinder">
|
||||||
<Position X="15" Y="7.75" Width="1.5" />
|
<Position X="9.25" Y="6.25" Width="1.75" />
|
||||||
|
<Members>
|
||||||
|
<Method Name="AvoidUnitsNear" Hidden="true" />
|
||||||
|
<Method Name="CheckSanePath" Hidden="true" />
|
||||||
|
<Method Name="CheckSanePath2" Hidden="true" />
|
||||||
|
<Method Name="FindBidiPath" Hidden="true" />
|
||||||
|
<Method Name="IsBlocked" Hidden="true" />
|
||||||
|
<Method Name="MakeBidiPath" Hidden="true" />
|
||||||
|
<Method Name="MakePath" Hidden="true" />
|
||||||
|
<Field Name="passableCost" Hidden="true" />
|
||||||
|
</Members>
|
||||||
<TypeIdentifier>
|
<TypeIdentifier>
|
||||||
<HashCode>AAAAAAAAAAAAAAAgAACAAAICAAgAEoAAMAAAAAAAAgA=</HashCode>
|
<HashCode>AAAAAAAAAAAAAAAgAACAAAICAAgAEoAAMAAAAAAAAgA=</HashCode>
|
||||||
<FileName>PathFinder.cs</FileName>
|
<FileName>PathFinder.cs</FileName>
|
||||||
|
|||||||
Reference in New Issue
Block a user