Repath around blocking units or structures.
This commit is contained in:
@@ -8,7 +8,7 @@ using IrrKlang;
|
||||
using IjwFramework.Collections;
|
||||
using System;
|
||||
using IjwFramework.Types;
|
||||
using OpenRa.Game.Traits;
|
||||
using OpenRa.Game.Traits;
|
||||
using OpenRa.Game.GameRules;
|
||||
|
||||
namespace OpenRa.Game
|
||||
@@ -22,7 +22,7 @@ namespace OpenRa.Game
|
||||
static TreeCache treeCache;
|
||||
public static TerrainRenderer terrain;
|
||||
public static Viewport viewport;
|
||||
public static PathFinder pathFinder;
|
||||
public static PathFinder PathFinder;
|
||||
public static Network network;
|
||||
public static WorldRenderer worldRenderer;
|
||||
public static Controller controller;
|
||||
@@ -32,50 +32,50 @@ namespace OpenRa.Game
|
||||
public static Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||
|
||||
public static Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||
public static BuildingInfluenceMap BuildingInfluence;
|
||||
public static BuildingInfluenceMap BuildingInfluence;
|
||||
public static UnitInfluenceMap UnitInfluence;
|
||||
|
||||
static ISoundEngine soundEngine;
|
||||
|
||||
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
||||
{
|
||||
Rules.LoadRules(mapName);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
players.Add(i, new Player(i, string.Format("Multi{0}", i), Race.Soviet));
|
||||
|
||||
localPlayerIndex = localPlayer;
|
||||
|
||||
var mapFile = new IniFile(FileSystem.Open(mapName));
|
||||
map = new Map(mapFile);
|
||||
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
||||
|
||||
viewport = new Viewport(clientSize, map.Size, renderer);
|
||||
|
||||
terrain = new TerrainRenderer(renderer, map, viewport);
|
||||
world = new World();
|
||||
treeCache = new TreeCache(map);
|
||||
|
||||
foreach (TreeReference treeReference in map.Trees)
|
||||
world.Add(new Actor(treeReference, treeCache, map.Offset));
|
||||
|
||||
BuildingInfluence = new BuildingInfluenceMap(8);
|
||||
UnitInfluence = new UnitInfluenceMap();
|
||||
|
||||
LoadMapBuildings(mapFile);
|
||||
LoadMapUnits(mapFile);
|
||||
|
||||
pathFinder = new PathFinder(map, terrain.tileSet);
|
||||
|
||||
network = new Network();
|
||||
|
||||
controller = new Controller();
|
||||
worldRenderer = new WorldRenderer(renderer);
|
||||
|
||||
soundEngine = new ISoundEngine();
|
||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||
|
||||
PlaySound("intro.aud", false);
|
||||
static ISoundEngine soundEngine;
|
||||
|
||||
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
|
||||
{
|
||||
Rules.LoadRules(mapName);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
players.Add(i, new Player(i, string.Format("Multi{0}", i), Race.Soviet));
|
||||
|
||||
localPlayerIndex = localPlayer;
|
||||
|
||||
var mapFile = new IniFile(FileSystem.Open(mapName));
|
||||
map = new Map(mapFile);
|
||||
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
||||
|
||||
viewport = new Viewport(clientSize, map.Size, renderer);
|
||||
|
||||
terrain = new TerrainRenderer(renderer, map, viewport);
|
||||
world = new World();
|
||||
treeCache = new TreeCache(map);
|
||||
|
||||
foreach (TreeReference treeReference in map.Trees)
|
||||
world.Add(new Actor(treeReference, treeCache, map.Offset));
|
||||
|
||||
BuildingInfluence = new BuildingInfluenceMap(8);
|
||||
UnitInfluence = new UnitInfluenceMap();
|
||||
|
||||
LoadMapBuildings(mapFile);
|
||||
LoadMapUnits(mapFile);
|
||||
|
||||
PathFinder = new PathFinder(map, terrain.tileSet);
|
||||
|
||||
network = new Network();
|
||||
|
||||
controller = new Controller();
|
||||
worldRenderer = new WorldRenderer(renderer);
|
||||
|
||||
soundEngine = new ISoundEngine();
|
||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||
|
||||
PlaySound("intro.aud", false);
|
||||
}
|
||||
|
||||
static void LoadMapBuildings( IniFile mapfile )
|
||||
@@ -125,7 +125,7 @@ namespace OpenRa.Game
|
||||
public static void Tick()
|
||||
{
|
||||
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
||||
world.Update();
|
||||
world.Update();
|
||||
UnitInfluence.Tick();
|
||||
|
||||
viewport.DrawRegions();
|
||||
@@ -133,7 +133,7 @@ namespace OpenRa.Game
|
||||
|
||||
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;
|
||||
@@ -158,19 +158,19 @@ namespace OpenRa.Game
|
||||
{
|
||||
return FindUnits(a - new float2(r, r), a + new float2(r, r))
|
||||
.Where(x => (x.CenterLocation - a).LengthSquared < r * r);
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> FindTilesInCircle(int2 a, int r)
|
||||
{
|
||||
var min = a - new int2(r, r);
|
||||
var max = a + new int2(r, r);
|
||||
|
||||
for (var j = min.Y; j <= max.Y; j++)
|
||||
for (var i = min.X; i <= max.X; i++)
|
||||
if (r * r >= (new int2(i, j) - a).LengthSquared)
|
||||
yield return new int2(i, j);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> FindTilesInCircle(int2 a, int r)
|
||||
{
|
||||
var min = a - new int2(r, r);
|
||||
var max = a + new int2(r, r);
|
||||
|
||||
for (var j = min.Y; j <= max.Y; j++)
|
||||
for (var i = min.X; i <= max.X; i++)
|
||||
if (r * r >= (new int2(i, j) - a).LengthSquared)
|
||||
yield return new int2(i, j);
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> SelectUnitsInBox(float2 a, float2 b)
|
||||
{
|
||||
return FindUnits(a, b).Where(x => x.Owner == LocalPlayer && x.traits.Contains<Traits.Mobile>());
|
||||
@@ -197,52 +197,52 @@ namespace OpenRa.Game
|
||||
public static readonly Pair<VoicePool, VoicePool> SovietVoices =
|
||||
Pair.New(
|
||||
new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"),
|
||||
new VoicePool("await1", "ready", "report1", "yessir1"));
|
||||
|
||||
static int2? FindAdjacentTile(Actor a, UnitMovementType umt)
|
||||
{
|
||||
var tiles = Footprint.Tiles(a);
|
||||
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
||||
var max = tiles.Aggregate(int2.Max) + new int2(1, 1);
|
||||
|
||||
for (var j = min.Y; j <= max.Y; j++)
|
||||
for (var i = min.X; i <= max.X; i++)
|
||||
if (IsCellBuildable(new int2(i, j), umt))
|
||||
return new int2(i, j);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
new VoicePool("await1", "ready", "report1", "yessir1"));
|
||||
|
||||
static int2? FindAdjacentTile(Actor a, UnitMovementType umt)
|
||||
{
|
||||
var tiles = Footprint.Tiles(a);
|
||||
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
||||
var max = tiles.Aggregate(int2.Max) + new int2(1, 1);
|
||||
|
||||
for (var j = min.Y; j <= max.Y; j++)
|
||||
for (var i = min.X; i <= max.X; i++)
|
||||
if (IsCellBuildable(new int2(i, j), umt))
|
||||
return new int2(i, j);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void BuildUnit(Player player, string name)
|
||||
{
|
||||
{
|
||||
var producerTypes = Rules.UnitInfo[name].BuiltAt;
|
||||
var producer = world.Actors
|
||||
.FirstOrDefault(a => a.unitInfo != null
|
||||
&& producerTypes.Contains(a.unitInfo.Name) && a.Owner == player);
|
||||
|
||||
if (producer == null)
|
||||
throw new InvalidOperationException("BuildUnit without suitable production structure!");
|
||||
|
||||
Actor unit;
|
||||
|
||||
if (producerTypes.Contains("spen") || producerTypes.Contains("syrd"))
|
||||
{
|
||||
var space = FindAdjacentTile(producer, Rules.UnitInfo[name].WaterBound ?
|
||||
UnitMovementType.Float : UnitMovementType.Wheel ); /* hackety hack */
|
||||
|
||||
if (space == null)
|
||||
throw new NotImplementedException("Nowhere to place this unit.");
|
||||
|
||||
unit = new Actor(name, space.Value, player);
|
||||
var mobile = unit.traits.Get<Mobile>();
|
||||
mobile.facing = SharedRandom.Next(256);
|
||||
}
|
||||
else
|
||||
{
|
||||
unit = new Actor(name, (1 / 24f * producer.CenterLocation).ToInt2(), player);
|
||||
var mobile = unit.traits.Get<Mobile>();
|
||||
mobile.facing = 128;
|
||||
mobile.QueueActivity(new Mobile.MoveTo(unit.Location + new int2(0, 3)));
|
||||
throw new InvalidOperationException("BuildUnit without suitable production structure!");
|
||||
|
||||
Actor unit;
|
||||
|
||||
if (producerTypes.Contains("spen") || producerTypes.Contains("syrd"))
|
||||
{
|
||||
var space = FindAdjacentTile(producer, Rules.UnitInfo[name].WaterBound ?
|
||||
UnitMovementType.Float : UnitMovementType.Wheel ); /* hackety hack */
|
||||
|
||||
if (space == null)
|
||||
throw new NotImplementedException("Nowhere to place this unit.");
|
||||
|
||||
unit = new Actor(name, space.Value, player);
|
||||
var mobile = unit.traits.Get<Mobile>();
|
||||
mobile.facing = SharedRandom.Next(256);
|
||||
}
|
||||
else
|
||||
{
|
||||
unit = new Actor(name, (1 / 24f * producer.CenterLocation).ToInt2(), player);
|
||||
var mobile = unit.traits.Get<Mobile>();
|
||||
mobile.facing = 128;
|
||||
mobile.QueueActivity(new Mobile.MoveTo(unit.Location + new int2(0, 3)));
|
||||
}
|
||||
|
||||
world.AddFrameEndTask(_ => world.Add(unit));
|
||||
|
||||
Reference in New Issue
Block a user