Added a small grace period to survival mechanic to allow easier start of the game.

This commit is contained in:
2026-05-09 22:55:05 +02:00
parent 09df4334b9
commit 112728b5a9
4 changed files with 57 additions and 4 deletions
+31
View File
@@ -12,6 +12,7 @@ public partial class TestRunner : Node
Run("Inventory adds, stacks and removes items", TestInventoryStacksAndRemovesItems);
Run("Inventory crafting checks stacked totals", TestInventoryCanCraftAcrossStacks);
Run("Survival consumes stored food and water", TestSurvivalConsumesFoodAndWater);
Run("Survival grace period prevents early death", TestSurvivalGracePeriodPreventsEarlyDeath);
Run("Survival death disables movement", TestSurvivalDeathDisablesMovement);
Run("Robot research effects change robot stats", TestRobotResearchEffects);
Run("Research completion applies effects once", TestResearchCompletionAppliesEffectsOnce);
@@ -21,6 +22,7 @@ public partial class TestRunner : Node
Run("Resource extraction and save data roundtrip", TestResourceSaveRoundtrip);
Run("Robot save data roundtrip keeps robot state", TestRobotSaveRoundtrip);
Run("Save data captures and restores global state", TestSaveDataRestoresGlobalState);
Run("Save data restores survival timer", TestSaveDataRestoresSurvivalTimer);
Run("Split save files store and load data", TestSplitSaveFilesRoundtrip);
Run("Split save files include one file per saved layer", TestSplitSaveFilesIncludeLayerFiles);
Run("If node evaluates inventory comparisons", TestIfNodeEvaluatesInventoryComparisons);
@@ -95,6 +97,7 @@ public partial class TestRunner : Node
private void TestSurvivalDeathDisablesMovement()
{
GameData.canMove = true;
GameData.survival.gracePeriodEnabled = false;
GameData.survival.energy = 0.01f;
GameData.survival.Update(2.0);
@@ -103,6 +106,22 @@ public partial class TestRunner : Node
AssertFalse(GameData.canMove, "movement should be disabled");
}
private void TestSurvivalGracePeriodPreventsEarlyDeath()
{
GameData.canMove = true;
GameData.survival.hunger = 0f;
GameData.survival.thirst = 0f;
GameData.survival.energy = 0f;
GameData.survival.Update(1.0);
AssertFalse(GameData.survival.isDead, "survival should not fail during grace period");
AssertTrue(GameData.canMove, "movement should stay enabled during grace period");
AssertTrue(GameData.survival.hunger > 0f, "hunger should be clamped above zero");
AssertTrue(GameData.survival.thirst > 0f, "thirst should be clamped above zero");
AssertTrue(GameData.survival.energy > 0f, "energy should be clamped above zero");
}
private void TestRobotResearchEffects()
{
RobotStats stats = new RobotStats();
@@ -202,6 +221,18 @@ public partial class TestRunner : Node
AssertEqual(ResearchState.RESEARCHED, GameData.availableResearch["stoneage"].state, "saved research");
}
private void TestSaveDataRestoresSurvivalTimer()
{
GameData.survival.elapsedSeconds = 321.5;
SaveGameData saveData = SaveGameManager.CreateSaveData();
GameData.ResetRunState();
SaveGameManager.ApplyWorldData(saveData);
AssertClose(321.5f, (float)GameData.survival.elapsedSeconds, 0.001f, "saved survival timer");
}
private void TestResearchExecutionPaysResourcesAndFinishes()
{
GameData.inventory.AddItem(new Item { data = GameData.availableItems["stone"] }, 5);