feat: surface inspected villager's open village need in field notes

This commit is contained in:
Rijad Zuzo
2026-08-10 23:36:47 +02:00
parent 8a7e6b12eb
commit 9ed985d6a3
5 changed files with 154 additions and 3 deletions
+97 -1
View File
@@ -142,6 +142,7 @@ func get_nearby_villager_inspection() -> VillagerInspectionResult:
var decision: ActionSelectionResult = simulation_manager.get_latest_decision(npc.id)
if decision != null and decision.action_id == npc.current_task:
reason = decision.reason
var need := _get_open_need_for_npc(npc)
return VillagerInspectionResult.new(
npc.id,
npc.npc_name,
@@ -151,10 +152,105 @@ func get_nearby_villager_inspection() -> VillagerInspectionResult:
npc.target_id,
target_name,
carried_amounts,
reason
reason,
need
)
func _get_open_need_for_npc(npc: SimNPC) -> Dictionary:
if not simulation_manager.has_method("get_latest_opportunity_for_npc"):
return {
"has_open_need": false,
"need_type": &"",
"progress": "",
"response": "",
}
var opportunity: OpportunityStateRecord = simulation_manager.get_latest_opportunity_for_npc(
npc.id
)
if (
opportunity == null
or opportunity.get_status() != OpportunityStateRecord.STATUS_OPEN
or opportunity.get_interested_npc_id() != npc.id
):
return {
"has_open_need": false,
"need_type": &"",
"progress": "",
"response": "",
}
var resource_name := String(opportunity.get_resource_id()).capitalize()
var current_amount := _get_need_storage_amount(opportunity)
var progress := (
"%s %.0f / %.0f" % [resource_name, current_amount, opportunity.get_target_amount()]
)
var response := "No one is able to supply this right now."
if simulation_manager.has_method("get_active_opportunity_helper"):
var helper: OpportunityHelperResult = simulation_manager.get_active_opportunity_helper()
if helper != null and helper.opportunity_id == opportunity.get_opportunity_id():
var helper_name := _get_npc_name(helper.helper_npc_id)
var action_phrase := _get_action_phrase(helper.action_id)
response = "%s can %s." % [helper_name, action_phrase]
if response == "No one is able to supply this right now.":
if simulation_manager.has_method("get_active_opportunity_player_response"):
var player_route: OpportunityPlayerResponseResult = (
simulation_manager.get_active_opportunity_player_response()
)
if player_route != null:
var route_phrase := (
"forage food"
if opportunity.get_resource_id() == SimulationIds.RESOURCE_FOOD
else "harvest a tree"
)
response = (
"You can help — %s to the %s."
% [route_phrase, _get_need_target_name(opportunity)]
)
return {
"has_open_need": true,
"need_type": opportunity.get_opportunity_type(),
"progress": progress,
"response": response,
}
func _get_need_storage_amount(opportunity: OpportunityStateRecord) -> float:
if not simulation_manager.has_method("get_pantry"):
return 0.0
match opportunity.get_target_id():
SimulationIds.STORAGE_VILLAGE_PANTRY:
var pantry: StorageStateRecord = simulation_manager.get_pantry()
return pantry.get_amount(opportunity.get_resource_id()) if pantry != null else 0.0
SimulationIds.STORAGE_VILLAGE_WOODPILE:
if simulation_manager.has_method("get_woodpile"):
var woodpile: StorageStateRecord = simulation_manager.get_woodpile()
return (
woodpile.get_amount(opportunity.get_resource_id()) if woodpile != null else 0.0
)
return 0.0
func _get_npc_name(npc_id: int) -> String:
for npc in simulation_manager.npcs:
if npc.id == npc_id:
return npc.npc_name
return "Someone"
func _get_action_phrase(action_id: StringName) -> String:
var definition := SimulationDefinitions.get_action(action_id)
return definition.display_name.to_lower() if definition != null else String(action_id)
func _get_need_target_name(opportunity: OpportunityStateRecord) -> String:
match opportunity.get_target_id():
SimulationIds.STORAGE_VILLAGE_PANTRY:
return "village pantry"
SimulationIds.STORAGE_VILLAGE_WOODPILE:
return "village woodpile"
return String(opportunity.get_target_id()).replace("_", " ")
func _find_feed_animal() -> AnimalNode:
if not ("animal_care" in simulation_manager) or simulation_manager.animal_care == null:
push_error("Player: SimulationManager has no animal-care service")