unit influence blocks building
This commit is contained in:
@@ -33,6 +33,13 @@ namespace OpenRa
|
|||||||
return (T)inner[ typeof( T ) ];
|
return (T)inner[ typeof( T ) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T GetOrDefault<T>()
|
||||||
|
{
|
||||||
|
object o = null;
|
||||||
|
inner.TryGetValue(typeof(T), out o);
|
||||||
|
return (T)o;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<T> WithInterface<T>()
|
public IEnumerable<T> WithInterface<T>()
|
||||||
{
|
{
|
||||||
foreach( var i in inner )
|
foreach( var i in inner )
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace OpenRa.Game
|
|||||||
readonly int maxDistance; /* clip limit for voronoi cells */
|
readonly int maxDistance; /* clip limit for voronoi cells */
|
||||||
static readonly Pair<Actor, float> NoClaim = Pair.New((Actor)null, float.MaxValue);
|
static readonly Pair<Actor, float> NoClaim = Pair.New((Actor)null, float.MaxValue);
|
||||||
|
|
||||||
public BuildingInfluenceMap(World world, int maxDistance)
|
public BuildingInfluenceMap(int maxDistance)
|
||||||
{
|
{
|
||||||
this.maxDistance = maxDistance;
|
this.maxDistance = maxDistance;
|
||||||
|
|
||||||
@@ -22,9 +22,9 @@ namespace OpenRa.Game
|
|||||||
for (int i = 0; i < 128; i++)
|
for (int i = 0; i < 128; i++)
|
||||||
influence[i, j] = NoClaim;
|
influence[i, j] = NoClaim;
|
||||||
|
|
||||||
world.ActorAdded +=
|
Game.world.ActorAdded +=
|
||||||
a => { if (a.traits.Contains<Traits.Building>()) AddInfluence(a); };
|
a => { if (a.traits.Contains<Traits.Building>()) AddInfluence(a); };
|
||||||
world.ActorRemoved +=
|
Game.world.ActorRemoved +=
|
||||||
a => { if (a.traits.Contains<Traits.Building>()) RemoveInfluence(a); };
|
a => { if (a.traits.Contains<Traits.Building>()) RemoveInfluence(a); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,48 +31,50 @@ namespace OpenRa.Game
|
|||||||
public static Dictionary<int, Player> players = new Dictionary<int, Player>();
|
public static Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||||
|
|
||||||
public static Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
public static Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||||
public static BuildingInfluenceMap BuildingInfluence;
|
public static BuildingInfluenceMap BuildingInfluence;
|
||||||
|
public static UnitInfluenceMap UnitInfluence;
|
||||||
|
|
||||||
static ISoundEngine soundEngine;
|
static ISoundEngine soundEngine;
|
||||||
|
|
||||||
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
||||||
{
|
{
|
||||||
Rules.LoadRules( mapName );
|
Rules.LoadRules(mapName);
|
||||||
|
|
||||||
for( int i = 0 ; i < 8 ; i++ )
|
for (int i = 0; i < 8; i++)
|
||||||
players.Add(i, new Player(i, string.Format("Multi{0}", i), Race.Soviet));
|
players.Add(i, new Player(i, string.Format("Multi{0}", i), Race.Soviet));
|
||||||
|
|
||||||
localPlayerIndex = localPlayer;
|
localPlayerIndex = localPlayer;
|
||||||
|
|
||||||
var mapFile = new IniFile( FileSystem.Open( mapName ) );
|
var mapFile = new IniFile(FileSystem.Open(mapName));
|
||||||
map = new Map( mapFile );
|
map = new Map(mapFile);
|
||||||
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
||||||
|
|
||||||
viewport = new Viewport(clientSize, map.Size, renderer);
|
viewport = new Viewport(clientSize, map.Size, renderer);
|
||||||
|
|
||||||
terrain = new TerrainRenderer(renderer, map, viewport);
|
terrain = new TerrainRenderer(renderer, map, viewport);
|
||||||
world = new World();
|
world = new World();
|
||||||
treeCache = new TreeCache(map);
|
treeCache = new TreeCache(map);
|
||||||
|
|
||||||
foreach( TreeReference treeReference in map.Trees )
|
foreach (TreeReference treeReference in map.Trees)
|
||||||
world.Add( new Actor( treeReference, treeCache, map.Offset ) );
|
world.Add(new Actor(treeReference, treeCache, map.Offset));
|
||||||
|
|
||||||
BuildingInfluence = new BuildingInfluenceMap(world, 8);
|
BuildingInfluence = new BuildingInfluenceMap(8);
|
||||||
|
UnitInfluence = new UnitInfluenceMap();
|
||||||
LoadMapBuildings( mapFile );
|
|
||||||
LoadMapUnits( mapFile );
|
LoadMapBuildings(mapFile);
|
||||||
|
LoadMapUnits(mapFile);
|
||||||
pathFinder = new PathFinder(map, terrain.tileSet, BuildingInfluence);
|
|
||||||
|
pathFinder = new PathFinder(map, terrain.tileSet, BuildingInfluence);
|
||||||
network = new Network();
|
|
||||||
|
network = new Network();
|
||||||
controller = new Controller();
|
|
||||||
worldRenderer = new WorldRenderer(renderer);
|
controller = new Controller();
|
||||||
|
worldRenderer = new WorldRenderer(renderer);
|
||||||
soundEngine = new ISoundEngine();
|
|
||||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
soundEngine = new ISoundEngine();
|
||||||
|
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||||
PlaySound("intro.aud", false);
|
|
||||||
|
PlaySound("intro.aud", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadMapBuildings( IniFile mapfile )
|
static void LoadMapBuildings( IniFile mapfile )
|
||||||
@@ -122,14 +124,16 @@ namespace OpenRa.Game
|
|||||||
public static void Tick()
|
public static void Tick()
|
||||||
{
|
{
|
||||||
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
||||||
world.Update();
|
world.Update();
|
||||||
|
UnitInfluence.Tick();
|
||||||
|
|
||||||
viewport.DrawRegions();
|
viewport.DrawRegions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCellBuildable(int2 a, UnitMovementType umt)
|
public static bool IsCellBuildable(int2 a, UnitMovementType umt)
|
||||||
{
|
{
|
||||||
if (BuildingInfluence.GetBuildingAt(a) != null) return false;
|
if (BuildingInfluence.GetBuildingAt(a) != null) return false;
|
||||||
|
if (UnitInfluence.GetUnitAt(a) != null) return false;
|
||||||
|
|
||||||
a += map.Offset;
|
a += map.Offset;
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@
|
|||||||
<Compile Include="Graphics\Util.cs" />
|
<Compile Include="Graphics\Util.cs" />
|
||||||
<Compile Include="Graphics\Vertex.cs" />
|
<Compile Include="Graphics\Vertex.cs" />
|
||||||
<Compile Include="Graphics\Viewport.cs" />
|
<Compile Include="Graphics\Viewport.cs" />
|
||||||
|
<Compile Include="UnitInfluenceMap.cs" />
|
||||||
<Compile Include="UnitOrderGenerator.cs" />
|
<Compile Include="UnitOrderGenerator.cs" />
|
||||||
<Compile Include="VoicePool.cs" />
|
<Compile Include="VoicePool.cs" />
|
||||||
<Compile Include="World.cs" />
|
<Compile Include="World.cs" />
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
if (currentAction != null)
|
if (currentAction != null)
|
||||||
currentAction.Cancel(self, this);
|
currentAction.Cancel(self, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<int2> OccupiedCells()
|
||||||
|
{
|
||||||
|
return new[] { fromCell, toCell };
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface CurrentAction
|
public interface CurrentAction
|
||||||
|
|||||||
28
OpenRa.Game/UnitInfluenceMap.cs
Normal file
28
OpenRa.Game/UnitInfluenceMap.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class UnitInfluenceMap
|
||||||
|
{
|
||||||
|
Actor[,] influence = new Actor[128, 128];
|
||||||
|
|
||||||
|
/* todo: incremental updates for great justice [and perf] */
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
influence = new Actor[128, 128];
|
||||||
|
|
||||||
|
var units = Game.world.Actors
|
||||||
|
.Select( a => a.traits.GetOrDefault<Traits.Mobile>() ).Where( m => m != null );
|
||||||
|
|
||||||
|
foreach (var u in units)
|
||||||
|
foreach (var c in u.OccupiedCells())
|
||||||
|
influence[c.X, c.Y] = u.self;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Actor GetUnitAt(int2 a) { return influence[a.X, a.Y]; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user