diff --git a/OpenRA.FileFormats/ConnectedComponents.cs b/OpenRA.FileFormats/ConnectedComponents.cs new file mode 100644 index 0000000000..a1216cdb86 --- /dev/null +++ b/OpenRA.FileFormats/ConnectedComponents.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRA.FileFormats +{ + public static class ConnectedComponents + { + static readonly int2[] Neighbors + = { new int2(-1, -1), new int2(0, -1), new int2(1, -1), new int2(-1, 0) }; + + public static int[,] Extract(Map m, Func f) + { + var result = new int[m.MapSize, m.MapSize]; + var types = new int[m.MapSize, m.MapSize]; + var d = new Dictionary(); + var n = 1; + + for( var j = m.YOffset; j < m.YOffset + m.Height; j++ ) + for (var i = m.XOffset; i < m.XOffset + m.Width; i++) + { + types[i, j] = f(i, j); + + var k = n; + foreach (var a in Neighbors) + if (types[i + a.X, j + a.Y] == types[i, j] && result[i + a.X, j + a.Y] < k) + k = result[i + a.X, j + a.Y]; + + // todo: finish this + } + + return result; + } + } +} diff --git a/OpenRA.FileFormats/Evaluator.cs b/OpenRA.FileFormats/Evaluator.cs index 4cec92809a..95b5d435ea 100644 --- a/OpenRA.FileFormats/Evaluator.cs +++ b/OpenRA.FileFormats/Evaluator.cs @@ -22,10 +22,10 @@ namespace OpenRA.FileFormats { switch (t[0]) { - case '+': ApplyBinop(s, (x, y) => x + y); break; - case '-': ApplyBinop(s, (x, y) => x - y); break; - case '*': ApplyBinop(s, (x, y) => x * y); break; - case '/': ApplyBinop(s, (x, y) => x / y); break; + case '+': ApplyBinop(s, (x, y) => y + x); break; + case '-': ApplyBinop(s, (x, y) => y - x); break; + case '*': ApplyBinop(s, (x, y) => y * x); break; + case '/': ApplyBinop(s, (x, y) => y / x); break; default: s.Push(int.Parse(t)); break; } } @@ -65,7 +65,7 @@ namespace OpenRA.FileFormats } static readonly Dictionary Prec - = new Dictionary { { "+", 0 }, { "-", 0 }, { "*", 1 }, { "/", 1 } }; + = new Dictionary { { "+", 0 }, { "-", 0 }, { "*", 1 }, { "/", 1 }, { "(", -1 } }; static IEnumerable Tokens(string expr, string ops) { diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index 22932f3639..0f09e98ca2 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -54,6 +54,7 @@ +