diff --git a/half-earth/resources/tile_types/developed.tres b/half-earth/resources/tile_types/developed.tres index 211c470..70a9358 100644 --- a/half-earth/resources/tile_types/developed.tres +++ b/half-earth/resources/tile_types/developed.tres @@ -8,3 +8,4 @@ Name = "Developed" BuildLabel = "[D]eveloped" Key = 68 Color = Color( 0.372549, 0.372549, 0.372549, 1 ) +HeatGeneration = 0.1 diff --git a/half-earth/resources/tile_types/wild.tres b/half-earth/resources/tile_types/wild.tres index 238de57..eae570c 100644 --- a/half-earth/resources/tile_types/wild.tres +++ b/half-earth/resources/tile_types/wild.tres @@ -8,3 +8,4 @@ Name = "Wild" BuildLabel = "[W]ild" Key = 87 Color = Color( 0, 0.545098, 0.0196078, 1 ) +HeatGeneration = -0.025 diff --git a/half-earth/scripts/WorldGrid.cs b/half-earth/scripts/WorldGrid.cs index 661b202..d454cb3 100644 --- a/half-earth/scripts/WorldGrid.cs +++ b/half-earth/scripts/WorldGrid.cs @@ -40,7 +40,7 @@ public class WorldGrid : Node2D { var tile = _tiles[x, y]; var material = tile.material; - material.SetShaderParam("t", tile.value); + material.SetShaderParam("t", tile.temperature); } } } @@ -100,7 +100,7 @@ public class WorldGrid : Node2D { var tile = new Tile(); tile.isHighlighted = false; - tile.value = 0.0f; + tile.temperature = 0.0f; tile.type = _startTileType; var node = TileScene.Instance(); @@ -122,6 +122,7 @@ public class WorldGrid : Node2D public void _on_Clock_OnTick(int ticks) { + GenerateHeat(); Diffuse(); } @@ -135,13 +136,27 @@ public class WorldGrid : Node2D private void GetNeighbourTemperatures(int x, int y, out float nx, out float ny, out float px, out float py) { // default value - var t = _tiles[x, y].value; + var t = _tiles[x, y].temperature; - nx = x > 0 ? _tiles[x - 1, y].value : t; - px = x < Size - 1 ? _tiles[x + 1, y].value : t; + nx = x > 0 ? _tiles[x - 1, y].temperature : t; + px = x < Size - 1 ? _tiles[x + 1, y].temperature : t; - ny = y > 0 ? _tiles[x, y - 1].value : t; - py = y < Size - 1 ? _tiles[x, y + 1].value : t; + ny = y > 0 ? _tiles[x, y - 1].temperature : t; + py = y < Size - 1 ? _tiles[x, y + 1].temperature : t; + } + + private void GenerateHeat() + { + for (int x = 0; x < Size; x++) + { + for (int y = 0; y < Size; y++) + { + var tile = _tiles[x, y]; + var type = tile.type; + tile.temperature += type.HeatGeneration; + _tiles[x, y] = tile; + } + } } private void Diffuse() @@ -150,7 +165,7 @@ public class WorldGrid : Node2D { for (int y = 0; y < Size; y++) { - float t = _tiles[x, y].value; + float t = _tiles[x, y].temperature; var D = DiffusionCoefficient; GetNeighbourTemperatures( @@ -161,7 +176,10 @@ public class WorldGrid : Node2D out var py); // current value - _nextValues[x, y] = TransferHeat(t, D, nx, ny, px, py); + var temperature = TransferHeat(t, D, nx, ny, px, py); + // TODO: what if it's really really cold out? + temperature = Mathf.Max(0, temperature); + _nextValues[x, y] = temperature; } } @@ -169,7 +187,7 @@ public class WorldGrid : Node2D { for (int y = 0; y < Size; y++) { - _tiles[x, y].value = _nextValues[x, y]; + _tiles[x, y].temperature = _nextValues[x, y]; } } } diff --git a/half-earth/scripts/tile/Tile.cs b/half-earth/scripts/tile/Tile.cs index 70560a0..e247129 100644 --- a/half-earth/scripts/tile/Tile.cs +++ b/half-earth/scripts/tile/Tile.cs @@ -3,7 +3,7 @@ using Godot; public struct Tile { public bool isHighlighted; - public float value; + public float temperature; public ShaderMaterial material; public TileType type; } \ No newline at end of file diff --git a/half-earth/scripts/tile/TileType.cs b/half-earth/scripts/tile/TileType.cs index c6dc2ab..8d8e777 100644 --- a/half-earth/scripts/tile/TileType.cs +++ b/half-earth/scripts/tile/TileType.cs @@ -14,6 +14,9 @@ public class TileType : Resource [Export] public Color Color { get; private set; } + [Export] + public float HeatGeneration { get; private set; } + public override string ToString() { return Name;