diff --git a/half-earth/scripts/EnvironmentSystem.cs b/half-earth/scripts/EnvironmentSystem.cs index 758b231..16895ed 100644 --- a/half-earth/scripts/EnvironmentSystem.cs +++ b/half-earth/scripts/EnvironmentSystem.cs @@ -55,13 +55,50 @@ public class EnvironmentSystem if (!(tile.type is IDamageable damageable)) return; - var surplus = tile.temperature - damageable.Threshold; - if (surplus < 0) - return; + var delta = tile.temperature - damageable.Threshold; + if (delta < 0) + { + // we want to heal based on how many wild tiles surround us + float healRate = 0.01f; - // TODO: parameterised balancing - tile.currentHealth -= surplus; - tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1); + // count neighbours + } + else + { + // take damage + // TODO: parameterised balancing + tile.currentHealth -= delta; + tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1); + } + + } + + public int GetNeighbourCount(int x, int y) where T : TileType + { + int count = 0; + + for (int i = -1; i < 1; i += 2) + { + for (int j = -1; j < 1; j += 2) + { + int xi = x + 1; + int yj = y + 1; + + // assume tiles out side of bounds are the same type as this one + if (!_tiles.IsInBounds(xi, yj)) + { + count += 1; + continue; + } + + if (!(_tiles[xi, yj] is T)) + continue; + + count++; + } + } + + return count; } private void Diffuse()