walkability, thanks to freera's templates.ini, although it was broken :D
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1303 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -61,6 +61,8 @@ namespace OpenRa.FileFormats
|
||||
sections.TryGetValue( s, out section );
|
||||
return section;
|
||||
}
|
||||
|
||||
public IEnumerable<IniSection> Sections { get { return sections.Values; } }
|
||||
}
|
||||
|
||||
public class IniSection : IEnumerable<KeyValuePair<string, string>>
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<Compile Include="ShpReader.cs" />
|
||||
<Compile Include="Terrain.cs" />
|
||||
<Compile Include="TileSet.cs" />
|
||||
<Compile Include="Walkability.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace OpenRa.FileFormats
|
||||
public class TileSet
|
||||
{
|
||||
public readonly Dictionary<ushort, Terrain> tiles = new Dictionary<ushort, Terrain>();
|
||||
public readonly Dictionary<ushort, Dictionary<int, int>> walk =
|
||||
new Dictionary<ushort, Dictionary<int, int>>(); // cjf will fix
|
||||
|
||||
public readonly Package MixFile;
|
||||
|
||||
string NextLine( StreamReader reader )
|
||||
@@ -27,6 +30,8 @@ namespace OpenRa.FileFormats
|
||||
|
||||
public TileSet( Package mixFile, string suffix )
|
||||
{
|
||||
Walkability walkability = new Walkability();
|
||||
|
||||
char tileSetChar = char.ToUpperInvariant( suffix[ 1 ] );
|
||||
MixFile = mixFile;
|
||||
StreamReader tileIdFile = File.OpenText( "../../../tileSet.til" );
|
||||
@@ -36,7 +41,7 @@ namespace OpenRa.FileFormats
|
||||
string tileSetStr = NextLine( tileIdFile );
|
||||
string countStr = NextLine( tileIdFile );
|
||||
string startStr = NextLine( tileIdFile );
|
||||
string pattern = NextLine( tileIdFile ) + suffix;
|
||||
string pattern = NextLine( tileIdFile );
|
||||
if( tileSetStr == null || countStr == null || startStr == null || pattern == null )
|
||||
break;
|
||||
|
||||
@@ -47,7 +52,12 @@ namespace OpenRa.FileFormats
|
||||
int start = int.Parse( startStr, NumberStyles.HexNumber );
|
||||
for( int i = 0 ; i < count ; i++ )
|
||||
{
|
||||
Stream s = mixFile.GetContent(string.Format(pattern, i + 1));
|
||||
string tilename = string.Format(pattern, i + 1);
|
||||
|
||||
if (!walk.ContainsKey((ushort)(start + i)))
|
||||
walk.Add((ushort)(start + i), walkability.GetWalkability(tilename));
|
||||
|
||||
Stream s = mixFile.GetContent(tilename + suffix);
|
||||
if (!tiles.ContainsKey((ushort)(start + i)))
|
||||
tiles.Add((ushort)(start + i), new Terrain(s));
|
||||
}
|
||||
|
||||
42
OpenRa.FileFormats/Walkability.cs
Normal file
42
OpenRa.FileFormats/Walkability.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public class Walkability
|
||||
{
|
||||
const string src = "../../../templates.ini";
|
||||
|
||||
Dictionary<string, Dictionary<int, int>> walkability =
|
||||
new Dictionary<string, Dictionary<int, int>>();
|
||||
|
||||
public Walkability()
|
||||
{
|
||||
IniFile file = new IniFile(File.OpenRead(src));
|
||||
Regex pattern = new Regex(@"tiletype(\d+)");
|
||||
|
||||
foreach (IniSection 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)
|
||||
{
|
||||
Match m = pattern.Match(p.Key);
|
||||
if (m != null && m.Success)
|
||||
tileWalkability.Add(int.Parse(m.Groups[1].Value), int.Parse(p.Value));
|
||||
}
|
||||
|
||||
walkability[name] = tileWalkability;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, int> GetWalkability(string terrainName)
|
||||
{
|
||||
return walkability[terrainName];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,21 @@ namespace OpenRa.Game
|
||||
bool[ , ] passable = new bool[ 128, 128 ];
|
||||
Map map;
|
||||
|
||||
static bool IsPassable(int terrainType)
|
||||
{
|
||||
switch (terrainType)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
case 6:
|
||||
case 8:
|
||||
case 9:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public PathFinder( Map map, TileSet tileSet )
|
||||
{
|
||||
this.map = map;
|
||||
@@ -26,9 +41,11 @@ namespace OpenRa.Game
|
||||
passable[x, y] = false;
|
||||
else
|
||||
{
|
||||
// HACK: water( tiles 1 and 2) are impassable
|
||||
passable[ x, y ] = ( map.MapTiles[ x, y ].tile != 1 && map.MapTiles[ x, y ].tile != 2 );
|
||||
// TODO: implement all the different terrain classes, including bonuses for roads etc
|
||||
TileReference r = map.MapTiles[x, y];
|
||||
if (r.tile == 0xffff || r.tile == 0xff)
|
||||
r.image = 0;
|
||||
|
||||
passable[x, y] = IsPassable(tileSet.walk[r.tile][r.image]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2800
templates.ini
Normal file
2800
templates.ini
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user