feat: add knowledge-gated pantry opportunities

This commit is contained in:
Rijad Zuzo
2026-07-13 00:46:56 +02:00
parent 9fcf6a0a58
commit c722e32a88
26 changed files with 2027 additions and 77 deletions
+54
View File
@@ -129,9 +129,63 @@ func _stage_social_history(main_scene: Node) -> bool:
):
push_error("Simulation Garden staging did not produce the retained trust consequence")
return false
if not _stage_pantry_need(main_scene, contributor, observer):
return false
var village_ui := main_scene.get_node("UI")
village_ui.selected_npc_index = simulation_manager.npcs.find(observer)
village_ui.call("_refresh_npc_inspector")
var inspector_label := (
main_scene.get_node("UI/NpcInspectorPanel/MarginContainer/NpcInspectorLabel") as Label
)
if "Open village need" not in inspector_label.text or "Food 0 / 1" not in inspector_label.text:
push_error("Simulation Garden staging did not expose the selected person's need")
return false
return true
func _stage_pantry_need(main_scene: Node, actor: SimNPC, interested: SimNPC) -> bool:
var simulation_manager := main_scene.get_node("SimulationManager")
for npc in simulation_manager.npcs:
npc.hunger = minf(npc.hunger, 70.0)
actor.hunger = 60.0
interested.hunger = 85.0
var pantry: StorageStateRecord = simulation_manager.get_pantry()
pantry.withdraw(
SimulationIds.RESOURCE_FOOD, maxf(pantry.get_amount(SimulationIds.RESOURCE_FOOD) - 1.0, 0.0)
)
simulation_manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
var withdrawn: float = simulation_manager.economy.withdraw_to_inventory(
actor, SimulationIds.RESOURCE_FOOD, pantry.get_amount(SimulationIds.RESOURCE_FOOD)
)
var opportunity: OpportunityStateRecord = simulation_manager.get_active_opportunity()
var village_need_label := (
main_scene.get_node("UI/VillagePanel/MarginContainer/VillageStatsLabel") as Label
)
if (
withdrawn <= 0.0
or opportunity == null
or opportunity.get_interested_npc_id() != interested.id
or "Village need" not in village_need_label.text
or "Food 0 / 1" not in village_need_label.text
):
push_error("Simulation Garden staging did not expose the real empty-pantry need")
return false
var previous_task := interested.current_task
if not interested.target_id.is_empty():
simulation_manager.release_npc_reservation(interested.id)
var selection: ActionSelectionResult = simulation_manager.action_selector.select_action(
interested,
simulation_manager.village,
simulation_manager.clock.time_of_day(),
simulation_manager.npcs
)
if selection == null or selection.action_id != SimulationIds.ACTION_GATHER_FOOD:
push_error("Simulation Garden staging could not replan the hungry villager")
return false
simulation_manager.latest_decisions[interested.id] = selection
interested.set_task(selection.action_id, selection.duration_override)
simulation_manager.npc_task_changed.emit(interested, previous_task, selection.action_id)
simulation_manager.npc_target_requested.emit(interested)
return true