diff --git a/Game/Assets/Scripts/Model/Map.cs b/Game/Assets/Scripts/Model/Map.cs
index c98d82d..0ba9477 100644
--- a/Game/Assets/Scripts/Model/Map.cs
+++ b/Game/Assets/Scripts/Model/Map.cs
@@ -11,7 +11,7 @@ namespace TransportGame.Model
[XmlRoot("map")]
public class Map
{
- private float[,] grid;
+ private float[,] heightmap;
private float[,] population;
#region Properties
@@ -36,7 +36,7 @@ namespace TransportGame.Model
{
get
{
- return grid;
+ return heightmap;
}
}
@@ -48,11 +48,11 @@ namespace TransportGame.Model
{
get
{
- return grid.ToByteArray();
+ return heightmap.ToByteArray();
}
set
{
- grid = value.GetFloatMatrix();
+ heightmap = value.GetFloatMatrix();
}
}
@@ -60,13 +60,13 @@ namespace TransportGame.Model
/// Gets width of heightmap
///
[XmlIgnore]
- public int Width { get { return (grid == null) ? 0 : grid.GetLength(0); } }
+ public int Width { get { return (heightmap == null) ? 0 : heightmap.GetLength(0); } }
///
/// Gets height of heightmap
///
[XmlIgnore]
- public int Height { get { return (grid == null) ? 0 : grid.GetLength(1); } }
+ public int Height { get { return (heightmap == null) ? 0 : heightmap.GetLength(1); } }
///
/// Gets the population map
@@ -139,7 +139,7 @@ namespace TransportGame.Model
/// Height
public Map(int width, int height)
{
- grid = new float[width, height];
+ heightmap = new float[width, height];
}
#endregion
@@ -152,7 +152,7 @@ namespace TransportGame.Model
/// Value
public float GetHeight(int x, int y)
{
- return grid[x, y] * Biome.Height;
+ return heightmap[x, y] * Biome.Height;
}
///
@@ -163,7 +163,7 @@ namespace TransportGame.Model
/// Value
public void SetHeight(int x, int y, float value)
{
- grid[x, y] = value / Biome.Height;
+ heightmap[x, y] = value / Biome.Height;
}
///
@@ -187,5 +187,22 @@ namespace TransportGame.Model
{
return x >= 0 && y >= 0 && x < Width && y < Height;
}
+
+ ///
+ /// Gets steepness in specified point
+ ///
+ /// X
+ /// Y
+ /// Steepness
+ public float GetSteepness(int x, int y)
+ {
+ if (x == 0) x++;
+ if (y == 0) y++;
+
+ float dx = GetHeight(x - 1, y) - GetHeight(x, y);
+ float dy = GetHeight(x, y - 1) - GetHeight(x, y);
+
+ return dx * dx + dy * dy;
+ }
}
}
diff --git a/Game/Assets/Scripts/Unity/TerrainGeneratorScript.cs b/Game/Assets/Scripts/Unity/TerrainGeneratorScript.cs
index ed16b26..3a6b8f9 100644
--- a/Game/Assets/Scripts/Unity/TerrainGeneratorScript.cs
+++ b/Game/Assets/Scripts/Unity/TerrainGeneratorScript.cs
@@ -123,12 +123,7 @@ public class TerrainGeneratorScript : MonoBehaviour
float height = map.GetHeight(ix, iy);
// Get steepness
- int safex = (ix == 0) ? 1 : ix;
- int safey = (iy == 0) ? 1 : iy;
-
- float dx = map.GetHeight(safex - 1, safey) - height;
- float dy = map.GetHeight(safex, safey - 1) - height;
- float steepness = dx * dx + dy * dy;
+ float steepness = map.GetSteepness(ix, iy);
// Go through each texture layer
float[] weights = new float[terrainData.alphamapLayers];