Pull ActorMap back out into a trait.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,7 +83,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="ActorInitializer.cs" />
|
<Compile Include="ActorInitializer.cs" />
|
||||||
<Compile Include="ActorMap.cs" />
|
|
||||||
<Compile Include="ActorReference.cs" />
|
<Compile Include="ActorReference.cs" />
|
||||||
<Compile Include="Graphics\QuadRenderer.cs" />
|
<Compile Include="Graphics\QuadRenderer.cs" />
|
||||||
<Compile Include="PVecInt.cs" />
|
<Compile Include="PVecInt.cs" />
|
||||||
@@ -239,6 +238,7 @@
|
|||||||
<Compile Include="Traits\Player\PlayerColorPalette.cs" />
|
<Compile Include="Traits\Player\PlayerColorPalette.cs" />
|
||||||
<Compile Include="Traits\Player\PlayerHighlightPalette.cs" />
|
<Compile Include="Traits\Player\PlayerHighlightPalette.cs" />
|
||||||
<Compile Include="Traits\World\ScreenMap.cs" />
|
<Compile Include="Traits\World\ScreenMap.cs" />
|
||||||
|
<Compile Include="Traits\World\ActorMap.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -12,10 +12,15 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
public enum SubCell { FullCell, TopLeft, TopRight, Center, BottomLeft, BottomRight }
|
public enum SubCell { FullCell, TopLeft, TopRight, Center, BottomLeft, BottomRight }
|
||||||
|
|
||||||
|
class ActorMapInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new ActorMap(init.world); }
|
||||||
|
}
|
||||||
|
|
||||||
public class ActorMap
|
public class ActorMap
|
||||||
{
|
{
|
||||||
class InfluenceNode
|
class InfluenceNode
|
||||||
@@ -28,29 +33,31 @@ namespace OpenRA
|
|||||||
InfluenceNode[,] influence;
|
InfluenceNode[,] influence;
|
||||||
Map map;
|
Map map;
|
||||||
|
|
||||||
public ActorMap( World world )
|
public ActorMap(World world)
|
||||||
{
|
{
|
||||||
map = world.Map;
|
map = world.Map;
|
||||||
influence = new InfluenceNode[world.Map.MapSize.X, world.Map.MapSize.Y];
|
influence = new InfluenceNode[world.Map.MapSize.X, world.Map.MapSize.Y];
|
||||||
|
|
||||||
world.ActorAdded += a => Add( a, a.OccupiesSpace );
|
world.ActorAdded += a => Add(a, a.OccupiesSpace);
|
||||||
world.ActorRemoved += a => Remove( a, a.OccupiesSpace );
|
world.ActorRemoved += a => Remove(a, a.OccupiesSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> GetUnitsAt(CPos a)
|
public IEnumerable<Actor> GetUnitsAt(CPos a)
|
||||||
{
|
{
|
||||||
if (!map.IsInMap(a)) yield break;
|
if (!map.IsInMap(a))
|
||||||
|
yield break;
|
||||||
|
|
||||||
for( var i = influence[ a.X, a.Y ] ; i != null ; i = i.next )
|
for (var i = influence[a.X, a.Y]; i != null; i = i.next)
|
||||||
if (!i.actor.Destroyed)
|
if (!i.actor.Destroyed)
|
||||||
yield return i.actor;
|
yield return i.actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub)
|
public IEnumerable<Actor> GetUnitsAt(CPos a, SubCell sub)
|
||||||
{
|
{
|
||||||
if (!map.IsInMap(a)) yield break;
|
if (!map.IsInMap(a))
|
||||||
|
yield break;
|
||||||
|
|
||||||
for( var i = influence[ a.X, a.Y ] ; i != null ; i = i.next )
|
for (var i = influence[a.X, a.Y]; i != null; i = i.next)
|
||||||
if (!i.actor.Destroyed && (i.subCell == sub || i.subCell == SubCell.FullCell))
|
if (!i.actor.Destroyed && (i.subCell == sub || i.subCell == SubCell.FullCell))
|
||||||
yield return i.actor;
|
yield return i.actor;
|
||||||
}
|
}
|
||||||
@@ -60,7 +67,7 @@ namespace OpenRA
|
|||||||
if (!AnyUnitsAt(a))
|
if (!AnyUnitsAt(a))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return new[]{ SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
return new[] { SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||||
SubCell.BottomLeft, SubCell.BottomRight }.Any(b => !AnyUnitsAt(a,b));
|
SubCell.BottomLeft, SubCell.BottomRight }.Any(b => !AnyUnitsAt(a,b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,54 +76,55 @@ namespace OpenRA
|
|||||||
if (!HasFreeSubCell(a))
|
if (!HasFreeSubCell(a))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new[]{ SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
return new[] { SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
|
||||||
SubCell.BottomLeft, SubCell.BottomRight }.First(b => !AnyUnitsAt(a,b));
|
SubCell.BottomLeft, SubCell.BottomRight }.First(b => !AnyUnitsAt(a,b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool AnyUnitsAt(CPos a)
|
public bool AnyUnitsAt(CPos a)
|
||||||
{
|
{
|
||||||
return influence[ a.X, a.Y ] != null;
|
return influence[a.X, a.Y] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AnyUnitsAt(CPos a, SubCell sub)
|
public bool AnyUnitsAt(CPos a, SubCell sub)
|
||||||
{
|
{
|
||||||
for( var i = influence[ a.X, a.Y ] ; i != null ; i = i.next )
|
for (var i = influence[a.X, a.Y]; i != null; i = i.next)
|
||||||
if (i.subCell == sub || i.subCell == SubCell.FullCell)
|
if (i.subCell == sub || i.subCell == SubCell.FullCell)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add( Actor self, IOccupySpace unit )
|
public void Add(Actor self, IOccupySpace unit)
|
||||||
{
|
|
||||||
if (unit != null)
|
|
||||||
foreach( var c in unit.OccupiedCells() )
|
|
||||||
influence[ c.First.X, c.First.Y ] = new InfluenceNode { next = influence[ c.First.X, c.First.Y ], subCell = c.Second, actor = self };
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove( Actor self, IOccupySpace unit )
|
|
||||||
{
|
{
|
||||||
if (unit != null)
|
if (unit != null)
|
||||||
foreach (var c in unit.OccupiedCells())
|
foreach (var c in unit.OccupiedCells())
|
||||||
RemoveInner( ref influence[ c.First.X, c.First.Y ], self );
|
influence[c.First.X, c.First.Y] = new InfluenceNode { next = influence[c.First.X, c.First.Y], subCell = c.Second, actor = self };
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveInner( ref InfluenceNode influenceNode, Actor toRemove )
|
public void Remove(Actor self, IOccupySpace unit)
|
||||||
{
|
{
|
||||||
if( influenceNode == null )
|
if (unit != null)
|
||||||
|
foreach (var c in unit.OccupiedCells())
|
||||||
|
RemoveInner(ref influence[c.First.X, c.First.Y], self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveInner(ref InfluenceNode influenceNode, Actor toRemove)
|
||||||
|
{
|
||||||
|
if (influenceNode == null)
|
||||||
return;
|
return;
|
||||||
else if( influenceNode.actor == toRemove )
|
else if (influenceNode.actor == toRemove)
|
||||||
influenceNode = influenceNode.next;
|
influenceNode = influenceNode.next;
|
||||||
|
|
||||||
if (influenceNode != null)
|
if (influenceNode != null)
|
||||||
RemoveInner( ref influenceNode.next, toRemove );
|
RemoveInner(ref influenceNode.next, toRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(Actor self, IOccupySpace unit)
|
public void Update(Actor self, IOccupySpace unit)
|
||||||
{
|
{
|
||||||
Remove(self, unit);
|
Remove(self, unit);
|
||||||
if (!self.IsDead()) Add(self, unit);
|
if (!self.IsDead())
|
||||||
|
Add(self, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ namespace OpenRA
|
|||||||
SharedRandom = new XRandom(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
|
SharedRandom = new XRandom(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
|
||||||
|
|
||||||
WorldActor = CreateActor("World", new TypeDictionary());
|
WorldActor = CreateActor("World", new TypeDictionary());
|
||||||
ActorMap = new ActorMap(this);
|
ActorMap = WorldActor.Trait<ActorMap>();
|
||||||
ScreenMap = WorldActor.Trait<ScreenMap>();
|
ScreenMap = WorldActor.Trait<ScreenMap>();
|
||||||
|
|
||||||
// Add players
|
// Add players
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ Player:
|
|||||||
|
|
||||||
World:
|
World:
|
||||||
ScreenMap:
|
ScreenMap:
|
||||||
|
ActorMap:
|
||||||
LoadWidgetAtGameStart:
|
LoadWidgetAtGameStart:
|
||||||
Widget: INGAME_ROOT
|
Widget: INGAME_ROOT
|
||||||
CncMenuPaletteEffect:
|
CncMenuPaletteEffect:
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ Player:
|
|||||||
|
|
||||||
World:
|
World:
|
||||||
ScreenMap:
|
ScreenMap:
|
||||||
|
ActorMap:
|
||||||
LoadWidgetAtGameStart:
|
LoadWidgetAtGameStart:
|
||||||
Widget: INGAME_ROOT
|
Widget: INGAME_ROOT
|
||||||
ScreenShaker:
|
ScreenShaker:
|
||||||
|
|||||||
@@ -530,6 +530,7 @@ Player:
|
|||||||
|
|
||||||
World:
|
World:
|
||||||
ScreenMap:
|
ScreenMap:
|
||||||
|
ActorMap:
|
||||||
LoadWidgetAtGameStart:
|
LoadWidgetAtGameStart:
|
||||||
Widget: INGAME_ROOT
|
Widget: INGAME_ROOT
|
||||||
ScreenShaker:
|
ScreenShaker:
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ Player:
|
|||||||
|
|
||||||
World:
|
World:
|
||||||
ScreenMap:
|
ScreenMap:
|
||||||
|
ActorMap:
|
||||||
LoadWidgetAtGameStart:
|
LoadWidgetAtGameStart:
|
||||||
Widget: INGAME_ROOT
|
Widget: INGAME_ROOT
|
||||||
BuildingInfluence:
|
BuildingInfluence:
|
||||||
|
|||||||
Reference in New Issue
Block a user