diff --git a/OpenRA.FileFormats/TerrainColorSet.cs b/OpenRA.FileFormats/TerrainColorSet.cs index 93782c3bbe..aa6fd169ea 100644 --- a/OpenRA.FileFormats/TerrainColorSet.cs +++ b/OpenRA.FileFormats/TerrainColorSet.cs @@ -21,12 +21,12 @@ using System.Collections.Generic; using System.IO; using System.Drawing; - +using System; namespace OpenRA.FileFormats { public class TerrainColorSet { - public readonly Dictionary colors = new Dictionary(); + public readonly Dictionary colors = new Dictionary(); string NextLine( StreamReader reader ) { @@ -51,17 +51,17 @@ namespace OpenRA.FileFormats string line = NextLine( file ); if( line == null ) break; - - string[] entries = line.Split(','); - int key = int.Parse(entries[0]); - Color val = Color.FromArgb(int.Parse(entries[1]),int.Parse(entries[2]),int.Parse(entries[3])); + string[] kv = line.Split('='); + TerrainType key = (TerrainType)Enum.Parse(typeof(TerrainType),kv[0]); + string[] entries = kv[1].Split(','); + Color val = Color.FromArgb(int.Parse(entries[0]),int.Parse(entries[1]),int.Parse(entries[2])); colors.Add(key,val); } file.Close(); } - public Color ColorForTerrainType(int type) + public Color ColorForTerrainType(TerrainType type) { return colors[type]; } diff --git a/OpenRA.FileFormats/TileSet.cs b/OpenRA.FileFormats/TileSet.cs index 5f446fc705..6860158ec8 100644 --- a/OpenRA.FileFormats/TileSet.cs +++ b/OpenRA.FileFormats/TileSet.cs @@ -99,7 +99,7 @@ namespace OpenRA.FileFormats return missingTile; } - public int GetTerrainType(TileReference r) + public TerrainType GetTerrainType(TileReference r) { if (r.tile == 0xff || r.tile == 0xffff) r.image = 0; diff --git a/OpenRA.FileFormats/Walkability.cs b/OpenRA.FileFormats/Walkability.cs index 44e23fa7ea..ab62a356b3 100644 --- a/OpenRA.FileFormats/Walkability.cs +++ b/OpenRA.FileFormats/Walkability.cs @@ -20,9 +20,24 @@ using System.Collections.Generic; using System.Linq; - +using System; namespace OpenRA.FileFormats { + public enum TerrainType : byte + { + Clear = 0, + Water = 1, + Road = 2, + Rock = 3, + Tree = 4, + River = 5, + Rough = 6, + Wall = 7, + Beach = 8, + Ore = 9, + Special = 10, + } + public class TileTemplate { public int Index; // not valid for `interior` stuff. only used for bridges. @@ -30,9 +45,9 @@ namespace OpenRA.FileFormats public int2 Size; public string Bridge; public float HP; - public Dictionary TerrainType = new Dictionary(); + public Dictionary TerrainType = new Dictionary(); } - + public class Walkability { Dictionary walkability @@ -53,11 +68,12 @@ namespace OpenRA.FileFormats .Where(p => p.Key.StartsWith("tiletype")) .ToDictionary( p => int.Parse(p.Key.Substring(8)), - p => int.Parse(p.Value)), + p => (TerrainType)Enum.Parse(typeof(TerrainType),p.Value)), Name = section.GetValue("Name", null).ToLowerInvariant(), Bridge = section.GetValue("bridge", null), HP = float.Parse(section.GetValue("hp", "0")) }; + tile.Index = -1; int.TryParse(section.Name.Substring(3), out tile.Index); diff --git a/OpenRA.Game/Combat.cs b/OpenRA.Game/Combat.cs index f4ea66bbe4..e704101b45 100644 --- a/OpenRA.Game/Combat.cs +++ b/OpenRA.Game/Combat.cs @@ -23,6 +23,7 @@ using System.Linq; using OpenRA.Effects; using OpenRA.GameRules; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA { @@ -41,7 +42,7 @@ namespace OpenRA var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2(); - var isWater = (Game.world.GetTerrainType(targetTile) == TerrainMovementType.Water); + var isWater = (Game.world.GetTerrainType(targetTile) == TerrainType.Water); if (warhead.Explosion != 0) world.AddFrameEndTask( diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 8152cba8d2..b20d77ef51 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -120,7 +120,7 @@ namespace OpenRA.Graphics for (var y = world.Map.YOffset; y < world.Map.YOffset + world.Map.Height; y++) for (var x = world.Map.XOffset; x < world.Map.XOffset + world.Map.Width; x++) if (res.GetResource(new int2(x,y)) != null) - oreLayer.SetPixel(x, y, Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType((int)TerrainMovementType.Ore))); + oreLayer.SetPixel(x, y, Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Ore))); } mapOnlySheet.Texture.SetData(oreLayer); @@ -151,7 +151,7 @@ namespace OpenRA.Graphics var b = world.WorldActor.traits.Get().GetBuildingAt(new int2(x, y)); if (b != null) *(c + (y * bitmapData.Stride >> 2) + x) = - (b.Owner != null ? Color.FromArgb(alpha, b.Owner.Color) : Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(4))).ToArgb(); + (b.Owner != null ? Color.FromArgb(alpha, b.Owner.Color) : Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Tree))).ToArgb(); } } diff --git a/OpenRA.Game/TerrainCosts.cs b/OpenRA.Game/TerrainCosts.cs index a873df9152..45a4a0ef17 100644 --- a/OpenRA.Game/TerrainCosts.cs +++ b/OpenRA.Game/TerrainCosts.cs @@ -19,6 +19,7 @@ #endregion using OpenRA.Graphics; +using OpenRA.FileFormats; namespace OpenRA { @@ -31,21 +32,6 @@ namespace OpenRA Fly = 4, } - public enum TerrainMovementType : byte - { - Clear = 0, - Water = 1, - Road = 2, - Rock = 3, - //Tree = 4, - River = 5, - Rough = 6, - Wall = 7, - Beach = 8, - Ore = 9, - Special = 10, - } - static class TerrainCosts { static float[][] costs = Util.MakeArray(4, @@ -57,7 +43,7 @@ namespace OpenRA for( int i = 0 ; i < 11 ; i++ ) { if( i == 4 ) continue; - var section = Rules.AllRules.GetSection( ( (TerrainMovementType)i ).ToString() ); + var section = Rules.AllRules.GetSection( ( (TerrainType)i ).ToString() ); for( int j = 0 ; j < 4 ; j++ ) { string val = section.GetValue( ( (UnitMovementType)j ).ToString(), "0%" ); @@ -67,14 +53,14 @@ namespace OpenRA } } - public static bool Buildable(int r) + public static bool Buildable(TerrainType r) { - return buildable[r]; + return buildable[(int)r]; } - public static float Cost( UnitMovementType unitMovementType, int r ) + public static float Cost( UnitMovementType unitMovementType, TerrainType r ) { - return costs[ (byte)unitMovementType ][ r ]; + return costs[ (byte)unitMovementType ][ (int)r ]; } } } diff --git a/OpenRA.Game/Traits/Crate.cs b/OpenRA.Game/Traits/Crate.cs index b9761716eb..70f1d093d5 100644 --- a/OpenRA.Game/Traits/Crate.cs +++ b/OpenRA.Game/Traits/Crate.cs @@ -56,7 +56,7 @@ namespace OpenRA.Traits this.self = self; self.World.WorldActor.traits.Get().Add(self, this); - if (self.World.GetTerrainType(self.Location) == TerrainMovementType.Water) + if (self.World.GetTerrainType(self.Location) == TerrainType.Water) self.traits.Get().anim.PlayRepeating("water"); } diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 3dfdf143ac..2df7b8254f 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -49,7 +49,7 @@ namespace OpenRA if (world.WorldActor.traits.Get().GetUnitsAt(a).Any(b => b != toIgnore)) return false; if (waterBound) - return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == TerrainMovementType.Water; + return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == TerrainType.Water; return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Buildable(world.TileSet.GetTerrainType(world.Map.MapTiles[a.X, a.Y])); } @@ -129,9 +129,9 @@ namespace OpenRA .FirstOrDefault(); } - public static TerrainMovementType GetTerrainType(this World world, int2 cell) + public static TerrainType GetTerrainType(this World world, int2 cell) { - return (TerrainMovementType)world.TileSet.GetTerrainType(world.Map.MapTiles[cell.X, cell.Y]); + return (TerrainType)world.TileSet.GetTerrainType(world.Map.MapTiles[cell.X, cell.Y]); } public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore) diff --git a/mods/cnc/desert.col b/mods/cnc/desert.col index 261fba9236..456a2042e9 100644 --- a/mods/cnc/desert.col +++ b/mods/cnc/desert.col @@ -1,13 +1,13 @@ ; Minimap colors for cnc DESERT theater -; Format: terraintype,R,G,B -0,134,95,69 -1,93,165,206 -2,168,123,83 -3,116,90,63 -4,28,32,36 -5,111,132,139 -6,68,68,60 -7,208,192,160 -8,176,156,120 -9,161,226,28 -10,124,124,124 \ No newline at end of file +; Format: terraintype=R,G,B +Clear=134,95,69 +Water=93,165,206 +Road=168,123,83 +Rock=116,90,63 +Tree=28,32,36 +River=111,132,139 +Rough=68,68,60 +Wall=208,192,160 +Beach=176,156,120 +Ore=161,226,28 +Special=124,124,124 \ No newline at end of file diff --git a/mods/cnc/temperat.col b/mods/cnc/temperat.col index 5e510be3b9..7f8717c545 100644 --- a/mods/cnc/temperat.col +++ b/mods/cnc/temperat.col @@ -1,13 +1,13 @@ ; Minimap colors for cnc TEMPERAT theater ; Format: terraintype,R,G,B -0,40,68,40 -1,92,116,164 -2,88,116,116 -3,68,68,60 -4,28,32,36 -5,92,140,180 -6,68,68,60 -7,208,192,160 -8,176,156,120 -9,161,226,28 -10,124,124,124 \ No newline at end of file +Clear=40,68,40 +Water=92,116,164 +Road=88,116,116 +Rock=68,68,60 +Tree=28,32,36 +River=92,140,180 +Rough=68,68,60 +Wall=208,192,160 +Beach=176,156,120 +Ore=161,226,28 +Special=124,124,124 \ No newline at end of file diff --git a/mods/cnc/winter.col b/mods/cnc/winter.col index 8fccd60983..89bdf32953 100644 --- a/mods/cnc/winter.col +++ b/mods/cnc/winter.col @@ -1,13 +1,13 @@ ; Minimap colors for cnc WINTER theater ; Format: terraintype,R,G,B -0,40,68,40 -1,92,116,164 -2,88,116,116 -3,68,68,60 -4,28,32,36 -5,92,140,180 -6,68,68,60 -7,208,192,160 -8,176,156,120 -9,161,226,28 -10,124,124,124 \ No newline at end of file +Clear=40,68,40 +Water=92,116,164 +Road=88,116,116 +Rock=68,68,60 +Tree=28,32,36 +River=92,140,180 +Rough=68,68,60 +Wall=208,192,160 +Beach=176,156,120 +Ore=161,226,28 +Special=124,124,124 \ No newline at end of file diff --git a/mods/ra/snow.col b/mods/ra/snow.col index 9d40b90598..455299b8cb 100644 --- a/mods/ra/snow.col +++ b/mods/ra/snow.col @@ -1,13 +1,13 @@ ; Minimap colors for ra SNOW theater ; Format: terraintype,R,G,B -0,196,196,196 -1,92,116,164 -2,88,116,116 -3,68,68,60 -4,28,32,36 -5,92,140,180 -6,68,68,60 -7,208,192,160 -8,176,156,120 -9,148,128,96 -10,124,124,124 \ No newline at end of file +Clear=196,196,196 +Water=92,116,164 +Road=88,116,116 +Rock=68,68,60 +Tree=28,32,36 +River=92,140,180 +Rough=68,68,60 +Wall=208,192,160 +Beach=176,156,120 +Ore=148,128,96 +Special=124,124,124 \ No newline at end of file diff --git a/mods/ra/temperat.col b/mods/ra/temperat.col index b8d8a1a62b..12192143da 100644 --- a/mods/ra/temperat.col +++ b/mods/ra/temperat.col @@ -1,13 +1,13 @@ ; Minimap colors for ra TEMPERAT theater ; Format: terraintype,R,G,B -0,40,68,40 -1,92,116,164 -2,88,116,116 -3,68,68,60 -4,28,32,36 -5,92,140,180 -6,68,68,60 -7,208,192,160 -8,176,156,120 -9,148,128,96 -10,124,124,124 \ No newline at end of file +Clear=40,68,40 +Water=92,116,164 +Road=88,116,116 +Rock=68,68,60 +Tree=28,32,36 +River=92,140,180 +Rough=68,68,60 +Wall=208,192,160 +Beach=176,156,120 +Ore=148,128,96 +Special=124,124,124 \ No newline at end of file