wip healing

This commit is contained in:
ktyl 2022-12-21 22:12:01 +00:00
parent ece699b68e
commit f13fe16317
1 changed files with 43 additions and 6 deletions

View File

@ -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<T>(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()