cleaning techtree & sidebar; building placement is mostly fixed
This commit is contained in:
@@ -122,14 +122,14 @@ namespace OpenRa.Game
|
|||||||
viewport.DrawRegions();
|
viewport.DrawRegions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCellBuildable(int2 a)
|
public static bool IsCellBuildable(int2 a, UnitMovementType umt)
|
||||||
{
|
{
|
||||||
if (LocalPlayerBuildings[a] != null) return false;
|
if (LocalPlayerBuildings[a] != null) return false;
|
||||||
|
|
||||||
a += map.Offset;
|
a += map.Offset;
|
||||||
|
|
||||||
return map.IsInMap(a.X, a.Y) &&
|
return map.IsInMap(a.X, a.Y) &&
|
||||||
TerrainCosts.Cost(UnitMovementType.Wheel,
|
TerrainCosts.Cost(umt,
|
||||||
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,6 +96,8 @@
|
|||||||
<Compile Include="Graphics\WorldRenderer.cs" />
|
<Compile Include="Graphics\WorldRenderer.cs" />
|
||||||
<Compile Include="BuildingInfluenceMap.cs" />
|
<Compile Include="BuildingInfluenceMap.cs" />
|
||||||
<Compile Include="IOrderGenerator.cs" />
|
<Compile Include="IOrderGenerator.cs" />
|
||||||
|
<Compile Include="PlaceBuilding.cs" />
|
||||||
|
<Compile Include="PlaceBuildingOrder.cs" />
|
||||||
<Compile Include="TechTree\Item.cs" />
|
<Compile Include="TechTree\Item.cs" />
|
||||||
<Compile Include="Network\Packet.cs" />
|
<Compile Include="Network\Packet.cs" />
|
||||||
<Compile Include="Player.cs" />
|
<Compile Include="Player.cs" />
|
||||||
|
|||||||
34
OpenRa.Game/PlaceBuilding.cs
Normal file
34
OpenRa.Game/PlaceBuilding.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.Game.GameRules;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class PlaceBuilding : IOrderGenerator
|
||||||
|
{
|
||||||
|
public readonly Player Owner;
|
||||||
|
public readonly string Name;
|
||||||
|
|
||||||
|
public PlaceBuilding(Player owner, string name)
|
||||||
|
{
|
||||||
|
Owner = owner;
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Order> Order(int2 xy)
|
||||||
|
{
|
||||||
|
// todo: check that space is free
|
||||||
|
if (Footprint.Tiles(Name, xy).Any(t => !Game.IsCellBuildable(t, UnitMovementType.Wheel)))
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
yield return new PlaceBuildingOrder(this, xy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrepareOverlay(int2 xy)
|
||||||
|
{
|
||||||
|
Game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
OpenRa.Game/PlaceBuildingOrder.cs
Normal file
51
OpenRa.Game/PlaceBuildingOrder.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class PlaceBuildingOrder : Order
|
||||||
|
{
|
||||||
|
PlaceBuilding building;
|
||||||
|
int2 xy;
|
||||||
|
|
||||||
|
public PlaceBuildingOrder(PlaceBuilding building, int2 xy)
|
||||||
|
{
|
||||||
|
this.building = building;
|
||||||
|
this.xy = xy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Apply(bool leftMouseButton)
|
||||||
|
{
|
||||||
|
if (leftMouseButton)
|
||||||
|
{
|
||||||
|
Game.world.AddFrameEndTask(_ =>
|
||||||
|
{
|
||||||
|
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
||||||
|
|
||||||
|
//Adjust placement for cursor to be in middle
|
||||||
|
var footprint = Rules.Footprint.GetFootprint(building.Name);
|
||||||
|
int maxWidth = 0;
|
||||||
|
foreach (var row in footprint)
|
||||||
|
if (row.Length > maxWidth)
|
||||||
|
maxWidth = row.Length;
|
||||||
|
|
||||||
|
Game.world.Add(new Actor(building.Name,
|
||||||
|
xy - new int2(maxWidth / 2, footprint.Length / 2), building.Owner));
|
||||||
|
|
||||||
|
Game.controller.orderGenerator = null;
|
||||||
|
Game.worldRenderer.uiOverlay.KillOverlay();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Game.world.AddFrameEndTask(_ =>
|
||||||
|
{
|
||||||
|
Game.controller.orderGenerator = null;
|
||||||
|
Game.worldRenderer.uiOverlay.KillOverlay();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -173,70 +173,4 @@ namespace OpenRa.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlaceBuilding : IOrderGenerator
|
|
||||||
{
|
|
||||||
public readonly Player Owner;
|
|
||||||
public readonly string Name;
|
|
||||||
|
|
||||||
public PlaceBuilding( Player owner, string name )
|
|
||||||
{
|
|
||||||
Owner = owner;
|
|
||||||
Name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Order> Order( int2 xy )
|
|
||||||
{
|
|
||||||
// todo: check that space is free
|
|
||||||
yield return new PlaceBuildingOrder( this, xy );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PrepareOverlay(int2 xy)
|
|
||||||
{
|
|
||||||
Game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PlaceBuildingOrder : Order
|
|
||||||
{
|
|
||||||
PlaceBuilding building;
|
|
||||||
int2 xy;
|
|
||||||
|
|
||||||
public PlaceBuildingOrder(PlaceBuilding building, int2 xy)
|
|
||||||
{
|
|
||||||
this.building = building;
|
|
||||||
this.xy = xy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Apply(bool leftMouseButton)
|
|
||||||
{
|
|
||||||
if (leftMouseButton)
|
|
||||||
{
|
|
||||||
Game.world.AddFrameEndTask(_ =>
|
|
||||||
{
|
|
||||||
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
|
||||||
|
|
||||||
//Adjust placement for cursor to be in middle
|
|
||||||
var footprint = Rules.Footprint.GetFootprint(building.Name);
|
|
||||||
int maxWidth = 0;
|
|
||||||
foreach (var row in footprint)
|
|
||||||
if (row.Length > maxWidth)
|
|
||||||
maxWidth = row.Length;
|
|
||||||
|
|
||||||
Game.world.Add(new Actor(building.Name, xy - new int2(maxWidth / 2, footprint.Length / 2), building.Owner));
|
|
||||||
|
|
||||||
Game.controller.orderGenerator = null;
|
|
||||||
Game.worldRenderer.uiOverlay.KillOverlay();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Game.world.AddFrameEndTask(_ =>
|
|
||||||
{
|
|
||||||
Game.controller.orderGenerator = null;
|
|
||||||
Game.worldRenderer.uiOverlay.KillOverlay();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRa.TechTree
|
|||||||
|
|
||||||
owner = ParseOwner(unitInfo.Owner, unitInfo.DoubleOwned);
|
owner = ParseOwner(unitInfo.Owner, unitInfo.DoubleOwned);
|
||||||
techLevel = unitInfo.TechLevel;
|
techLevel = unitInfo.TechLevel;
|
||||||
Tuple<string[], string[]> pre = ParsePrerequisites(unitInfo.Prerequisite, tag);
|
var pre = ParsePrerequisites(unitInfo.Prerequisite, tag);
|
||||||
alliedPrerequisites = pre.a;
|
alliedPrerequisites = pre.a;
|
||||||
sovietPrerequisites = pre.b;
|
sovietPrerequisites = pre.b;
|
||||||
}
|
}
|
||||||
@@ -41,37 +41,25 @@ namespace OpenRa.TechTree
|
|||||||
|
|
||||||
static Tuple<string[],string[]> ParsePrerequisites(string[] prerequisites, string tag)
|
static Tuple<string[],string[]> ParsePrerequisites(string[] prerequisites, string tag)
|
||||||
{
|
{
|
||||||
List<string> allied = prerequisites.Select( x => x.ToLowerInvariant() ).ToList();
|
var allied = prerequisites.Select( x => x.ToLowerInvariant() ).ToList();
|
||||||
List<string> soviet = new List<string>(allied);
|
var soviet = new List<string>(allied);
|
||||||
|
|
||||||
if (allied.Remove("stek"))
|
if (allied.Remove("stek")) allied.Add("atek");
|
||||||
allied.Add("atek");
|
if (soviet.Remove("atek")) soviet.Add("stek");
|
||||||
|
if (soviet.Remove("tent")) soviet.Add("barr");
|
||||||
if (soviet.Remove("atek"))
|
if (allied.Remove("barr")) allied.Add("tent");
|
||||||
soviet.Add("stek");
|
|
||||||
|
|
||||||
if (soviet.Remove("tent"))
|
|
||||||
soviet.Add("barr");
|
|
||||||
|
|
||||||
if (allied.Remove("barr"))
|
|
||||||
allied.Add("tent");
|
|
||||||
|
|
||||||
// TODO: rewrite this based on "InfantryTypes" in units.ini
|
// TODO: rewrite this based on "InfantryTypes" in units.ini
|
||||||
if ((tag.Length == 2 && tag[0] == 'e') || tag == "medi" || tag == "thf" || tag == "spy")
|
if ((tag.Length == 2 && tag[0] == 'e') || tag == "medi" || tag == "thf" || tag == "spy")
|
||||||
{
|
{
|
||||||
if (!allied.Contains("tent"))
|
if (!allied.Contains("tent")) allied.Add("tent");
|
||||||
allied.Add("tent");
|
if (!soviet.Contains("barr")) soviet.Add("barr");
|
||||||
if (!soviet.Contains("barr"))
|
|
||||||
soviet.Add("barr");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == "lst")
|
if (tag == "lst")
|
||||||
{
|
{
|
||||||
if (!soviet.Contains("spen"))
|
if (!soviet.Contains("spen")) soviet.Add("spen");
|
||||||
soviet.Add("spen");
|
if (!allied.Contains("syrd")) allied.Add("syrd");
|
||||||
|
|
||||||
if (!allied.Contains("syrd"))
|
|
||||||
allied.Add("syrd");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<string[], string[]>(
|
return new Tuple<string[], string[]>(
|
||||||
@@ -91,11 +79,7 @@ namespace OpenRa.TechTree
|
|||||||
if (racePrerequisites.Length == 0)
|
if (racePrerequisites.Length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
List<string> p = new List<string>(racePrerequisites);
|
return racePrerequisites.Except(buildings).Count() == 0;
|
||||||
foreach (string b in buildings)
|
|
||||||
p.Remove(b);
|
|
||||||
|
|
||||||
return p.Count == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShouldMakeUnbuildable(IEnumerable<string> buildings, string[] racePrerequisites)
|
bool ShouldMakeUnbuildable(IEnumerable<string> buildings, string[] racePrerequisites)
|
||||||
@@ -103,20 +87,18 @@ namespace OpenRa.TechTree
|
|||||||
if (racePrerequisites.Length == 0)
|
if (racePrerequisites.Length == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
List<string> p = new List<string>(racePrerequisites);
|
return racePrerequisites.Except(buildings).Count() == racePrerequisites.Length;
|
||||||
foreach (string b in buildings)
|
|
||||||
p.Remove(b);
|
|
||||||
|
|
||||||
return p.Count == racePrerequisites.Length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckForBoth(IEnumerable<string> buildings)
|
void CheckForBoth(IEnumerable<string> buildings)
|
||||||
{
|
{
|
||||||
if (canBuild && (ShouldMakeUnbuildable(buildings, alliedPrerequisites) && ShouldMakeUnbuildable(buildings, sovietPrerequisites)))
|
if (CanBuild && (ShouldMakeUnbuildable(buildings, alliedPrerequisites)
|
||||||
canBuild = false;
|
&& ShouldMakeUnbuildable(buildings, sovietPrerequisites)))
|
||||||
|
CanBuild = false;
|
||||||
|
|
||||||
else if (!canBuild && (ShouldMakeBuildable(buildings, alliedPrerequisites) || ShouldMakeBuildable(buildings, sovietPrerequisites)))
|
else if (!CanBuild && (ShouldMakeBuildable(buildings, alliedPrerequisites)
|
||||||
canBuild = true;
|
|| ShouldMakeBuildable(buildings, sovietPrerequisites)))
|
||||||
|
CanBuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckPrerequisites(IEnumerable<string> buildings, Race currentRace)
|
public void CheckPrerequisites(IEnumerable<string> buildings, Race currentRace)
|
||||||
@@ -127,15 +109,14 @@ namespace OpenRa.TechTree
|
|||||||
{
|
{
|
||||||
string[] racePrerequisites = (currentRace == Race.Allies) ? alliedPrerequisites : sovietPrerequisites;
|
string[] racePrerequisites = (currentRace == Race.Allies) ? alliedPrerequisites : sovietPrerequisites;
|
||||||
|
|
||||||
if ((canBuild && ShouldMakeUnbuildable(buildings, racePrerequisites)) || !((owner & currentRace) == currentRace))
|
if ((CanBuild && ShouldMakeUnbuildable(buildings, racePrerequisites)) || !((owner & currentRace) == currentRace))
|
||||||
canBuild = false;
|
CanBuild = false;
|
||||||
else if (!canBuild && ShouldMakeBuildable(buildings, racePrerequisites))
|
else if (!CanBuild && ShouldMakeBuildable(buildings, racePrerequisites))
|
||||||
canBuild = true;
|
CanBuild = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canBuild;
|
public bool CanBuild { get; private set; }
|
||||||
public bool CanBuild { get { return canBuild; } }
|
|
||||||
public string Tooltip { get { return string.Format("{0} ({1})\n{2}", friendlyName, tag, owner); } }
|
public string Tooltip { get { return string.Format("{0} ({1})\n{2}", friendlyName, tag, owner); } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,20 +32,6 @@ namespace OpenRa.TechTree
|
|||||||
CheckAll();
|
CheckAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Tuple<string, string, bool>> Lines(string filename, bool param)
|
|
||||||
{
|
|
||||||
Regex pattern = new Regex(@"^(\w+),([\w ]+),(\w+)$");
|
|
||||||
foreach (string s in File.ReadAllLines("../../../../" + filename))
|
|
||||||
{
|
|
||||||
Match m = pattern.Match(s);
|
|
||||||
if (m == null || !m.Success)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
yield return new Tuple<string, string, bool>(
|
|
||||||
m.Groups[1].Value, m.Groups[2].Value, param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadRules()
|
void LoadRules()
|
||||||
{
|
{
|
||||||
var allBuildings = Rules.AllRules.GetSection( "BuildingTypes" ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
var allBuildings = Rules.AllRules.GetSection( "BuildingTypes" ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
||||||
@@ -63,12 +49,9 @@ namespace OpenRa.TechTree
|
|||||||
built.Add(key);
|
built.Add(key);
|
||||||
CheckAll();
|
CheckAll();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Build(string key)
|
public bool Build(string key) { return Build(key, false); }
|
||||||
{
|
|
||||||
return Build(key, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Unbuild(string key)
|
public bool Unbuild(string key)
|
||||||
{
|
{
|
||||||
@@ -86,18 +69,9 @@ namespace OpenRa.TechTree
|
|||||||
unit.CheckPrerequisites(built, currentRace);
|
unit.CheckPrerequisites(built, currentRace);
|
||||||
|
|
||||||
BuildableItemsChanged();
|
BuildableItemsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Item> BuildableItems
|
public IEnumerable<Item> BuildableItems { get { return objects.Values.Where(b => b.CanBuild); } }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
foreach (Item b in objects.Values)
|
|
||||||
if (b.CanBuild)
|
|
||||||
yield return b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public event Action BuildableItemsChanged = () => { };
|
public event Action BuildableItemsChanged = () => { };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ namespace OpenRa.Game
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var t in Footprint.Tiles(name,position))
|
foreach (var t in Footprint.Tiles(name,position))
|
||||||
spriteRenderer.DrawSprite(Game.IsCellBuildable(t) ? buildOk : buildBlocked, Game.CellSize * t, 0);
|
spriteRenderer.DrawSprite(Game.IsCellBuildable(t, UnitMovementType.Wheel)
|
||||||
|
? buildOk : buildBlocked, Game.CellSize * t, 0);
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user