feat: add person history and trust reactions
This commit is contained in:
@@ -41,7 +41,11 @@ func _run() -> void:
|
||||
if not demo_controller.debug_overlay_visible:
|
||||
demo_controller.toggle_debug_overlay()
|
||||
|
||||
if not _stage_social_history(main_scene):
|
||||
quit(1)
|
||||
return
|
||||
await _stage_wind_gust(main_scene)
|
||||
await _settle_trust_reaction()
|
||||
var debug_analysis := _capture(DEBUG_OUTPUT_PATH)
|
||||
if debug_analysis.is_empty():
|
||||
quit(1)
|
||||
@@ -49,7 +53,11 @@ func _run() -> void:
|
||||
|
||||
if demo_controller.has_method("toggle_debug_overlay") and demo_controller.debug_overlay_visible:
|
||||
demo_controller.toggle_debug_overlay()
|
||||
if not _restart_trust_reaction(main_scene):
|
||||
quit(1)
|
||||
return
|
||||
await _stage_wind_gust(main_scene)
|
||||
await _settle_trust_reaction()
|
||||
|
||||
var cinematic_analysis := _capture(CINEMATIC_OUTPUT_PATH)
|
||||
if cinematic_analysis.is_empty():
|
||||
@@ -65,6 +73,83 @@ func _run() -> void:
|
||||
quit(0)
|
||||
|
||||
|
||||
func _stage_social_history(main_scene: Node) -> bool:
|
||||
var simulation_manager := main_scene.get_node("SimulationManager")
|
||||
var world_view := main_scene.get_node("WorldViewManager")
|
||||
if simulation_manager.npcs.size() < 2:
|
||||
push_error("Simulation Garden social-history staging needs two NPCs")
|
||||
return false
|
||||
var contributor: SimNPC = simulation_manager.npcs[0]
|
||||
var observer: SimNPC = simulation_manager.npcs[1]
|
||||
var contributor_visual: Node3D = world_view.active_npc_visuals.get(contributor.id)
|
||||
var observer_visual: Node3D = world_view.active_npc_visuals.get(observer.id)
|
||||
if contributor_visual == null or observer_visual == null:
|
||||
push_error("Simulation Garden social-history staging needs both active NPC visuals")
|
||||
return false
|
||||
var relationship: RelationshipStateRecord = (
|
||||
simulation_manager.relationship_system.get_relationship(observer.id, contributor.id)
|
||||
)
|
||||
if relationship == null:
|
||||
push_error("Simulation Garden staging pair needs an existing directed relationship")
|
||||
return false
|
||||
var previous_trust := relationship.get_trust()
|
||||
simulation_manager.set_process(false)
|
||||
contributor_visual.set_physics_process(false)
|
||||
observer_visual.set_physics_process(false)
|
||||
observer_visual.global_position = contributor_visual.global_position + Vector3(1.0, 0.0, 0.0)
|
||||
simulation_manager.synchronize_npc_position(contributor.id, contributor_visual.global_position)
|
||||
simulation_manager.synchronize_npc_position(observer.id, observer_visual.global_position)
|
||||
observer.hunger = 85.0
|
||||
contributor.add_inventory(SimulationIds.RESOURCE_FOOD, 1.0)
|
||||
var deposited: float = simulation_manager.economy.deposit_inventory(
|
||||
contributor, SimulationIds.RESOURCE_FOOD
|
||||
)
|
||||
if not is_equal_approx(deposited, 1.0):
|
||||
push_error("Simulation Garden staging could not deposit one food")
|
||||
return false
|
||||
simulation_manager.emit_signal("village_changed", simulation_manager.village)
|
||||
var contributor_events: Array = simulation_manager.get_npc_events(contributor.id, 1)
|
||||
if contributor_events.is_empty():
|
||||
push_error("Simulation Garden staging did not record the deposit event")
|
||||
return false
|
||||
var deposit_event := contributor_events[0] as EconomicEventRecord
|
||||
var retained_memories: Array = simulation_manager.get_retained_memory_events(observer.id, 1)
|
||||
var reaction_root := observer_visual.get_node_or_null("TrustReactionRoot") as Node3D
|
||||
if (
|
||||
StringName(deposit_event.data["event_type"]) != SimulationIds.EVENT_STORAGE_DEPOSITED
|
||||
or relationship.get_trust() <= previous_trust
|
||||
or relationship.get_last_trust_cause_event_id() != int(deposit_event.data["event_id"])
|
||||
or retained_memories.is_empty()
|
||||
or retained_memories[0] != deposit_event
|
||||
or not simulation_manager.is_known_event_lasting(
|
||||
observer.id, int(deposit_event.data["event_id"])
|
||||
)
|
||||
or reaction_root == null
|
||||
or not reaction_root.visible
|
||||
):
|
||||
push_error("Simulation Garden staging did not produce the retained trust consequence")
|
||||
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")
|
||||
return true
|
||||
|
||||
|
||||
func _restart_trust_reaction(main_scene: Node) -> bool:
|
||||
var simulation_manager := main_scene.get_node("SimulationManager")
|
||||
var world_view := main_scene.get_node("WorldViewManager")
|
||||
if simulation_manager.npcs.size() < 2:
|
||||
push_error("Simulation Garden trust-reaction staging needs two NPCs")
|
||||
return false
|
||||
var observer: SimNPC = simulation_manager.npcs[1]
|
||||
var observer_visual: Node3D = world_view.active_npc_visuals.get(observer.id)
|
||||
if observer_visual == null or not observer_visual.has_method("play_trust_gain_reaction"):
|
||||
push_error("Simulation Garden trust-reaction staging needs an active observer visual")
|
||||
return false
|
||||
observer_visual.play_trust_gain_reaction()
|
||||
return observer_visual.get_node("TrustReactionRoot").visible
|
||||
|
||||
|
||||
func _stage_wind_gust(main_scene: Node) -> void:
|
||||
var gust_field := (
|
||||
main_scene.get_node_or_null("JajceWorld/AtmosphereRoot/WindGustField") as WindGustField
|
||||
@@ -76,6 +161,11 @@ func _stage_wind_gust(main_scene: Node) -> void:
|
||||
await process_frame
|
||||
|
||||
|
||||
func _settle_trust_reaction() -> void:
|
||||
for _frame in 12:
|
||||
await process_frame
|
||||
|
||||
|
||||
func _capture(output_path: String) -> Dictionary:
|
||||
var image := root.get_texture().get_image()
|
||||
if image == null or image.is_empty():
|
||||
|
||||
Reference in New Issue
Block a user