feat: add witnessed knowledge and wind ambience
This commit is contained in:
+91
-41
@@ -27,6 +27,10 @@ func _ready() -> void:
|
||||
simulation_manager.state_restored.connect(_on_state_restored)
|
||||
if simulation_manager.has_signal("speed_changed"):
|
||||
simulation_manager.speed_changed.connect(_on_speed_changed)
|
||||
if simulation_manager.has_signal("relationship_changed"):
|
||||
simulation_manager.relationship_changed.connect(_on_relationship_changed)
|
||||
if simulation_manager.has_signal("event_knowledge_changed"):
|
||||
simulation_manager.event_knowledge_changed.connect(_on_event_knowledge_changed)
|
||||
|
||||
if "village" in simulation_manager:
|
||||
_on_village_changed(simulation_manager.village)
|
||||
@@ -119,6 +123,16 @@ func _on_speed_changed(_multiplier: float) -> void:
|
||||
_on_village_changed(simulation_manager.village)
|
||||
|
||||
|
||||
func _on_relationship_changed(
|
||||
_relationship: RelationshipStateRecord, _cause_event: EconomicEventRecord
|
||||
) -> void:
|
||||
_refresh_npc_inspector()
|
||||
|
||||
|
||||
func _on_event_knowledge_changed(_knower_id: int, _event: EconomicEventRecord) -> void:
|
||||
_refresh_npc_inspector()
|
||||
|
||||
|
||||
func _refresh_npc_inspector() -> void:
|
||||
if not debug_overlay_visible:
|
||||
return
|
||||
@@ -147,44 +161,58 @@ func _refresh_npc_inspector() -> void:
|
||||
for action_id in score_keys:
|
||||
if decision.rejections.has(action_id):
|
||||
rejection_rows.append(
|
||||
"%s — %s"
|
||||
% [_get_action_name(StringName(action_id)), String(decision.rejections[action_id])]
|
||||
(
|
||||
"%s — %s"
|
||||
% [
|
||||
_get_action_name(StringName(action_id)),
|
||||
String(decision.rejections[action_id])
|
||||
]
|
||||
)
|
||||
)
|
||||
continue
|
||||
score_rows.append(
|
||||
"%s %.2f" % [_get_action_name(StringName(action_id)), float(decision.scores[action_id])]
|
||||
(
|
||||
"%s %.2f"
|
||||
% [_get_action_name(StringName(action_id)), float(decision.scores[action_id])]
|
||||
)
|
||||
)
|
||||
if not score_rows.is_empty():
|
||||
score_text = "\n\nUtility\n" + "\n".join(score_rows)
|
||||
if not rejection_rows.is_empty():
|
||||
score_text += "\n\nUnavailable\n" + "\n".join(rejection_rows)
|
||||
var event_text := _build_event_history(npc)
|
||||
var housemate_text := _build_housemate_display(npc)
|
||||
var relationship_text := _build_relationship_display(npc)
|
||||
var known_fact_text := _build_known_fact_display(npc)
|
||||
npc_inspector_label.text = (
|
||||
"%s · %s\n"
|
||||
+ "Task: %s (%s)\n"
|
||||
+ "Destination: %s\n"
|
||||
+ "Hunger: %.0f Energy: %.0f\n"
|
||||
+ "Carrying food: %.0f wood: %.0f\n"
|
||||
+ "%s\n"
|
||||
+ "Why\n%s%s\n\n"
|
||||
+ "Recent\n%s\n\n"
|
||||
+ "[Tab] Next villager [F10] Cinematic/debug [F12] Demo reset"
|
||||
) % [
|
||||
npc.npc_name,
|
||||
profession_name,
|
||||
action_name,
|
||||
npc.task_state,
|
||||
destination_name,
|
||||
npc.hunger,
|
||||
npc.energy,
|
||||
npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD),
|
||||
npc.get_inventory_amount(SimulationIds.RESOURCE_WOOD),
|
||||
housemate_text,
|
||||
reason_text,
|
||||
score_text,
|
||||
event_text
|
||||
]
|
||||
(
|
||||
"%s · %s\n"
|
||||
+ "Task: %s (%s)\n"
|
||||
+ "Destination: %s\n"
|
||||
+ "Hunger: %.0f Energy: %.0f\n"
|
||||
+ "Carrying food: %.0f wood: %.0f\n"
|
||||
+ "%s\n"
|
||||
+ "%s\n"
|
||||
+ "Why\n%s%s\n\n"
|
||||
+ "Recent\n%s\n\n"
|
||||
+ "[Tab] Next villager [F10] Cinematic/debug [F12] Demo reset"
|
||||
)
|
||||
% [
|
||||
npc.npc_name,
|
||||
profession_name,
|
||||
action_name,
|
||||
npc.task_state,
|
||||
destination_name,
|
||||
npc.hunger,
|
||||
npc.energy,
|
||||
npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD),
|
||||
npc.get_inventory_amount(SimulationIds.RESOURCE_WOOD),
|
||||
relationship_text,
|
||||
known_fact_text,
|
||||
reason_text,
|
||||
score_text,
|
||||
event_text
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func _get_action_name(action_id: StringName) -> String:
|
||||
@@ -220,22 +248,44 @@ func _build_event_history(npc: SimNPC) -> String:
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
func _build_housemate_display(npc: SimNPC) -> String:
|
||||
if npc.familiarity.is_empty():
|
||||
func _build_relationship_display(npc: SimNPC) -> String:
|
||||
if not simulation_manager.has_method("get_primary_relationship"):
|
||||
return ""
|
||||
var highest_id: int = -1
|
||||
var highest_score := -1.0
|
||||
for key in npc.familiarity:
|
||||
var other_id: int = int(key)
|
||||
var score: float = float(npc.familiarity[key])
|
||||
if score > highest_score:
|
||||
highest_score = score
|
||||
highest_id = other_id
|
||||
if highest_id < 0:
|
||||
var relationship: RelationshipStateRecord = simulation_manager.get_primary_relationship(npc.id)
|
||||
if relationship == null:
|
||||
return ""
|
||||
var other_name := "Someone"
|
||||
for other_npc in simulation_manager.npcs:
|
||||
if other_npc.id == highest_id:
|
||||
if other_npc.id == relationship.get_subject_id():
|
||||
other_name = other_npc.npc_name
|
||||
break
|
||||
return "Familiar: %s (%.0f%%)" % [other_name, highest_score * 100.0]
|
||||
var display := (
|
||||
"Relationship: %s — familiar %.0f%%, trust %.0f%%"
|
||||
% [
|
||||
other_name,
|
||||
relationship.get_familiarity() * 100.0,
|
||||
relationship.get_trust() * 100.0,
|
||||
]
|
||||
)
|
||||
if not simulation_manager.has_method("get_relationship_cause"):
|
||||
return display
|
||||
var cause: EconomicEventRecord = simulation_manager.get_relationship_cause(relationship)
|
||||
if cause == null:
|
||||
return display
|
||||
var name_map := {}
|
||||
for other_npc in simulation_manager.npcs:
|
||||
name_map[other_npc.id] = other_npc.npc_name
|
||||
return "%s\nBecause: %s" % [display, cause.description(name_map)]
|
||||
|
||||
|
||||
func _build_known_fact_display(npc: SimNPC) -> String:
|
||||
if not simulation_manager.has_method("get_known_events"):
|
||||
return ""
|
||||
var known_events: Array = simulation_manager.get_known_events(npc.id, 1)
|
||||
if known_events.is_empty():
|
||||
return "Known fact: none yet"
|
||||
var name_map := {}
|
||||
for other_npc in simulation_manager.npcs:
|
||||
name_map[other_npc.id] = other_npc.npc_name
|
||||
var latest_event := known_events[known_events.size() - 1] as EconomicEventRecord
|
||||
return "Known fact: %s" % latest_event.description(name_map)
|
||||
|
||||
Reference in New Issue
Block a user