initial bridges hack
This commit is contained in:
@@ -1,35 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public class Walkability
|
||||
public class TileTemplate
|
||||
{
|
||||
Dictionary<string, Dictionary<int, int>> walkability =
|
||||
new Dictionary<string, Dictionary<int, int>>();
|
||||
public int Index;
|
||||
public string Name;
|
||||
public int2 Size;
|
||||
public bool IsBridge;
|
||||
public float HP;
|
||||
public Dictionary<int, int> TerrainType = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
class Walkability
|
||||
{
|
||||
public Dictionary<string, TileTemplate> walkability
|
||||
= new Dictionary<string,TileTemplate>();
|
||||
|
||||
public Walkability()
|
||||
{
|
||||
IniFile file = new IniFile( FileSystem.Open( "templates.ini" ) );
|
||||
Regex pattern = new Regex(@"tiletype(\d+)");
|
||||
var file = new IniFile( FileSystem.Open( "templates.ini" ) );
|
||||
|
||||
foreach (IniSection section in file.Sections)
|
||||
foreach (var section in file.Sections)
|
||||
{
|
||||
string name = section.GetValue("Name", null).ToLowerInvariant();
|
||||
|
||||
Dictionary<int, int> tileWalkability = new Dictionary<int, int>();
|
||||
foreach (KeyValuePair<string, string> p in section)
|
||||
var tile = new TileTemplate
|
||||
{
|
||||
Match m = pattern.Match(p.Key);
|
||||
if (m != null && m.Success)
|
||||
tileWalkability.Add(int.Parse(m.Groups[1].Value), int.Parse(p.Value));
|
||||
}
|
||||
Size = new int2(
|
||||
int.Parse(section.GetValue("width", "0")),
|
||||
int.Parse(section.GetValue("height", "0"))),
|
||||
TerrainType = section
|
||||
.Where(p => p.Key.StartsWith("tiletype"))
|
||||
.ToDictionary(
|
||||
p => int.Parse(p.Key.Substring(8)),
|
||||
p => int.Parse(p.Value)),
|
||||
Name = section.GetValue("Name", null).ToLowerInvariant(),
|
||||
Index = int.Parse(section.Name.Substring(3)),
|
||||
IsBridge = section.GetValue("bridge", "no") != "no",
|
||||
HP = float.Parse(section.GetValue("hp", "0"))
|
||||
};
|
||||
|
||||
walkability[name] = tileWalkability;
|
||||
walkability[tile.Name] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, int> GetWalkability(string terrainName)
|
||||
public TileTemplate GetWalkability(string terrainName)
|
||||
{
|
||||
return walkability[terrainName];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user