Cut 2 fix batch: a broken chunk absorbs no damage

Zone.Wear did not check whether the chunk was already broken. A later hit
read wear.Damage starting from 0 (the value ChunkWear carries while
BrokenUntil is in the future), stayed under hitpoints, and wrote
BrokenUntil = null -- un-breaking a chunk mid-respawn.

Damage delivered to a chunk that is currently broken (zone time <
BrokenUntil) now changes nothing: Wear returns false (this hit did not
break it -- it was already broken) and BrokenUntil, and Damage, are left
untouched. The chunk stays absent until its original respawn time, then
resumes wear from zero as before.

Adds two behavioural tests: a re-hit inside the respawn window, both
below and above hitpoints, must not un-break the chunk or move its
respawn time; and the same rule survives a save/reload round trip.
Confirmed by reverting the fix and watching both new tests fail with the
chunk reappearing early, then restoring the fix byte-exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-25 12:49:57 +02:00
commit 34994732d2
2 changed files with 83 additions and 1 deletions

View file

@ -255,13 +255,18 @@ public class Zone
// Cut 2: the only writer of chunk wear. Returns whether this hit broke the chunk. The break threshold is
// strictly greater-than, matching the deleted per-tick miner's own comparison against accumulated damage:
// damage exactly equal to hitpoints does not yet break the chunk, only damage that exceeds them does.
// A chunk that is currently broken (zone time < BrokenUntil) absorbs nothing: this hit did not break it
// (it was already broken), and its wear stays zeroed until it respawns and starts fresh.
public bool Wear(ChunkId chunk, float damage)
{
_wear.TryGetValue(chunk, out var wear);
if (wear.BrokenUntil.HasValue && wear.BrokenUntil.Value > _time)
return false;
var beltData = (AsteroidBeltData) Planets[chunk.Field];
var size = beltData.Asteroids[chunk.Index].Size;
var hitpoints = Settings.AsteroidHitpoints.Evaluate(size);
_wear.TryGetValue(chunk, out var wear);
var newDamage = wear.Damage + damage;
if (newDamage > hitpoints)