Refactor int -> TerrainType. This had a bigger footprint than i initially intended.
This commit is contained in:
@@ -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<int, Color> colors = new Dictionary<int, Color>();
|
||||
public readonly Dictionary<TerrainType, Color> colors = new Dictionary<TerrainType, Color>();
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<int, int> TerrainType = new Dictionary<int, int>();
|
||||
public Dictionary<int, TerrainType> TerrainType = new Dictionary<int, TerrainType>();
|
||||
}
|
||||
|
||||
|
||||
public class Walkability
|
||||
{
|
||||
Dictionary<string, TileTemplate> 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);
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<BuildingInfluence>().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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<float[]>(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 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Traits
|
||||
this.self = self;
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||
|
||||
if (self.World.GetTerrainType(self.Location) == TerrainMovementType.Water)
|
||||
if (self.World.GetTerrainType(self.Location) == TerrainType.Water)
|
||||
self.traits.Get<RenderSimple>().anim.PlayRepeating("water");
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA
|
||||
if (world.WorldActor.traits.Get<UnitInfluence>().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)
|
||||
|
||||
@@ -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
|
||||
; 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
|
||||
@@ -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
|
||||
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
|
||||
@@ -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
|
||||
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
|
||||
@@ -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
|
||||
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
|
||||
@@ -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
|
||||
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
|
||||
Reference in New Issue
Block a user