feat: seed household familiarity from shared home proximity

NPCs whose home positions are within 4m of each other gain mutual familiarity at baseline 0.5. Stored per NPC as a Dictionary keyed by other npc_id, serialized through NPCStateRecord with backward-compatible fallback for old saves. Household pairs form naturally from the home_positions configuration in main.tscn. Includes save/load round-trip test verifying familiarity persists.
This commit is contained in:
2026-07-09 00:03:20 +02:00
parent 8094975094
commit fce5c533fe
4 changed files with 70 additions and 1 deletions
+58
View File
@@ -14,6 +14,7 @@ func _run() -> void:
_test_sleep_restores_energy()
_test_schedule_serialization()
_test_sleep_targets_home()
_test_household_familiarity()
if failures.is_empty():
print("[TEST] NPC schedule passed")
@@ -181,6 +182,63 @@ func _test_sleep_targets_home() -> void:
manager.free()
func _test_household_familiarity() -> void:
var manager: Node = load("res://simulation/SimulationManager.gd").new()
manager.simulation_seed = 700
manager.debug_logs = false
manager.set_process(false)
manager.home_positions = [
Vector3(-15.0, 2.0, 7.0),
Vector3(-15.0, 2.0, 8.0),
Vector3(-8.5, 2.0, 3.0),
Vector3(-6.5, 2.0, 1.5),
Vector3(20.0, 0.0, 20.0),
Vector3(22.0, 0.0, 22.0)
]
root.add_child(manager)
var a: SimNPC = manager.npcs[0]
var b: SimNPC = manager.npcs[1]
var c: SimNPC = manager.npcs[2]
var d: SimNPC = manager.npcs[3]
var e: SimNPC = manager.npcs[4]
_check(
a.familiarity.has(b.id) and b.familiarity.has(a.id),
"NPCs with nearby homes should be mutual household members"
)
_check(
is_equal_approx(float(a.familiarity[b.id]), 0.5),
"Household familiarity should start at baseline 0.5"
)
_check(
c.familiarity.has(d.id) and d.familiarity.has(c.id),
"Second household pair should also be familiar"
)
_check(
not a.familiarity.has(e.id),
"Distant NPCs should not have household familiarity"
)
var saved_json: String = manager.serialize_state()
var restored: Node = load("res://simulation/SimulationManager.gd").new()
restored.debug_logs = false
root.add_child(restored)
restored.set_process(false)
_check(
restored.restore_state_from_json(saved_json),
"Familiarity should survive save/load round-trip"
)
var ra: SimNPC = restored.npcs[0]
_check(
ra.familiarity.size() > 0,
"Restored NPC should retain household familiarity"
)
manager.free()
restored.free()
func _check(condition: bool, message: String) -> void:
if not condition:
failures.append(message)