Add crowd presentation, fix NPC navigation, refresh screenshots
NPC navigation (previously dead in the live game) - Only assign NavigationAgent3D.target_position when it changes: re-assigning every frame invalidated the path, so get_next_path_position() kept returning the current point and avatars never moved. - Follow the first path point that is closer to the destination than the avatars are. Nav points sit on the navmesh plane (y=0) while bodies stand at y~0.5, so the old 3D distance test always looked "already there"; path[0] is also the old start point, so a naive "far enough away" pick steered backwards and oscillated. - Fix fsm.state -> fsm.current_state in the idle-lifetime check. Crowd presentation - Aggressive behavior, visible weapons, and responder arrivals make idle bystanders stop and face the incident for 12 s; someone waiting at the entrance keeps focus. - Panic (mood >= 0.75) walks people away from the door at 2.4 m/s, then they despawn. - Wire reactions to EventBus.crowd_changed: CrowdSystem.apply_event() emits on the bus, not on its own `changed` signal (the first wiring received nothing). - Measured a 16-NPC entrance at ~1.2 ms/frame (824 fps, vsync off), so no LOD/culling. World and HUD - Skyline is now a ring of four alpha-scissored planes at 200 m instead of a single plane; PlaneMesh defaults to horizontal, which is why the backdrop rendered as a band overhead. Larger ground plane, mipmapped texture, scissor threshold 0.5 (0.3 left mip dashes in the sky), lifted albedo so the city is not pure black. - Flashlight aims straight ahead and lights the person/door instead of the ground. - Shorter HUD controls line so it stops overlapping itself. Tests, tooling, docs - Headless suite 98 -> 105 (new test_crowd_presentation.gd, 7 tests). - New smoke_crowd.gd: rubbernecking, panic, and flee-target sanity. - capture_screenshots.gd starts a shift from the venue menu and stages the night set properly; all six README screenshots regenerated. - README, TODO/DONE (crowd section moved), MEMORY updated. Version 0.2.4.
This commit is contained in:
1 parent
f5ad1642b5
commit
71b0b53705
21 files changed
+512
-60
No files matched your search
@@ -45,6 +45,20 @@ func apply_event(event_type: String) -> void:
|
||||
"event": event_type,
|
||||
})
|
||||
|
||||
## Presentation cue for the avatars after a crowd event (PLAN: Public Crowd
|
||||
## Reaction). "watch" = rubberneck at the incident, "flee" = move away from the
|
||||
## door, "" = no reaction. Pure so it is headless-testable.
|
||||
static func reaction_for_event(event_type: String) -> String:
|
||||
match event_type:
|
||||
"aggressive_behavior", "visible_weapon", "emergency_responder":
|
||||
return "watch"
|
||||
_:
|
||||
return ""
|
||||
|
||||
## True once the crowd is panicking hard enough that people should clear out.
|
||||
func should_flee() -> bool:
|
||||
return crowd_panic
|
||||
|
||||
func summary() -> Dictionary:
|
||||
return {
|
||||
"mood": mood,
|
||||
|
||||
@@ -9,6 +9,7 @@ const AccessArtifact := preload("res://src/core/access_artifact.gd")
|
||||
const AccessLoadout := preload("res://src/core/access_loadout.gd")
|
||||
const AccessVerifier := preload("res://src/core/access_verifier.gd")
|
||||
const DoorState := preload("res://src/core/door_state.gd")
|
||||
const CrowdSystem := preload("res://src/core/crowd_system.gd")
|
||||
const WandScreener := preload("res://src/core/wand_screener.gd")
|
||||
const RadioSystem := preload("res://src/core/radio_system.gd")
|
||||
const ScenarioFactory := preload("res://src/content/scenario_factory.gd")
|
||||
@@ -134,6 +135,7 @@ func _ready() -> void:
|
||||
coordinator.npc_spawn_requested.connect(_spawn_npc)
|
||||
coordinator.shift_ended.connect(_on_shift_ended)
|
||||
coordinator.radio.responder_arrived.connect(_on_responder_arrived)
|
||||
_connect_crowd()
|
||||
|
||||
_build_ui()
|
||||
_last_phase = -1
|
||||
@@ -160,10 +162,13 @@ func _build_guard() -> GuardController:
|
||||
flashlight.name = "Flashlight"
|
||||
flashlight.visible = false
|
||||
flashlight.position = Vector3(0, -0.15, -0.4)
|
||||
flashlight.rotation_degrees = Vector3(-10, 0, 0)
|
||||
flashlight.spot_range = 18.0
|
||||
flashlight.spot_angle = 28.0
|
||||
flashlight.light_energy = 2.5
|
||||
# Aim straight ahead: tilting it down made the cone hit the ground right in
|
||||
# front of the guard instead of the person or door being checked.
|
||||
flashlight.rotation_degrees = Vector3.ZERO
|
||||
flashlight.spot_range = 22.0
|
||||
flashlight.spot_angle = 30.0
|
||||
flashlight.light_energy = 4.0
|
||||
flashlight.spot_attenuation = 0.6
|
||||
head.add_child(flashlight)
|
||||
var collider := CollisionShape3D.new()
|
||||
var shape := CapsuleShape3D.new()
|
||||
@@ -217,6 +222,7 @@ func _reset_shift_state() -> void:
|
||||
hud.set_body_camera(false)
|
||||
scenario_duration_s = selected_scenario.shift_duration_s
|
||||
coordinator.setup(selected_scenario, scenario_duration_s, 4242)
|
||||
_connect_crowd()
|
||||
_last_phase = -1
|
||||
_apply_phase_lighting()
|
||||
|
||||
@@ -481,6 +487,51 @@ func _on_responder_arrived(call: Dictionary) -> void:
|
||||
})
|
||||
coordinator.crowd.apply_event("emergency_responder" if call.get("type", "") == "emergency" else "calm_professionalism")
|
||||
|
||||
## Crowd presentation (PLAN: Public Crowd Reaction). The crowd system is a
|
||||
## mood/attention float; this turns its events into avatar behavior.
|
||||
func _connect_crowd() -> void:
|
||||
# CrowdSystem routes its updates through the EventBus (`event_bus.crowd_changed`);
|
||||
# its own `changed` signal is not emitted by apply_event().
|
||||
if coordinator == null or coordinator.event_bus == null:
|
||||
return
|
||||
if not coordinator.event_bus.crowd_changed.is_connected(_on_crowd_changed):
|
||||
coordinator.event_bus.crowd_changed.connect(_on_crowd_changed)
|
||||
|
||||
func _on_crowd_changed(payload: Dictionary) -> void:
|
||||
var event_type := str(payload.get("event", ""))
|
||||
var panic := bool(payload.get("panic", false))
|
||||
# Panic wins: people clear away from the entrance.
|
||||
if panic or event_type == "crowd_panic":
|
||||
_flee_crowd()
|
||||
return
|
||||
if CrowdSystem.reaction_for_event(event_type) == "watch":
|
||||
_rubberneck_crowd()
|
||||
|
||||
func _incident_point() -> Vector3:
|
||||
if targeted_npc is Node3D and is_instance_valid(targeted_npc):
|
||||
return (targeted_npc as Node3D).global_position
|
||||
if guard:
|
||||
return guard.global_position
|
||||
return Vector3(0, 0, 1.2)
|
||||
|
||||
## Idle bystanders stop and face the incident instead of walking on.
|
||||
func _rubberneck_crowd() -> void:
|
||||
var point := _incident_point()
|
||||
for npc in npcs:
|
||||
if not is_instance_valid(npc) or not npc.has_method("start_rubberneck"):
|
||||
continue
|
||||
if npc == targeted_npc:
|
||||
continue
|
||||
npc.start_rubberneck(point)
|
||||
|
||||
## Panic: everyone nearby moves away from the door.
|
||||
func _flee_crowd() -> void:
|
||||
var door_pos: Vector3 = selected_scenario._location_or_default("entrance", Vector3(0, 0.5, 1.2))
|
||||
for npc in npcs:
|
||||
if not is_instance_valid(npc) or not npc.has_method("start_flee"):
|
||||
continue
|
||||
npc.start_flee(door_pos)
|
||||
|
||||
func _responder_profile() -> NpcProfile:
|
||||
var p := NpcProfile.new()
|
||||
p.id = "responder"
|
||||
|
||||
+105
-6
@@ -17,6 +17,14 @@ var arrived := false
|
||||
var idle_s := 0.0
|
||||
var lifetime_s := 90.0
|
||||
var ephemeral := true
|
||||
## Crowd presentation (PLAN: Public Crowd Reaction). "watch" rubbernecks at the
|
||||
## incident, "flee" clears away from it, "" is normal navigation.
|
||||
var reaction_mode := ""
|
||||
var reaction_point := Vector3.ZERO
|
||||
var _reaction_timer := 0.0
|
||||
const RUBBERNECK_S := 12.0
|
||||
const FLEE_S := 20.0
|
||||
const FLEE_SPEED := 2.4
|
||||
var agent: NavigationAgent3D = null
|
||||
## Set once the nav agent proves it has a path; direct movement is the fallback.
|
||||
var _nav_usable := false
|
||||
@@ -225,10 +233,78 @@ func _add_box_prop(parent: Node3D, size: Vector3, pos: Vector3, color: Color) ->
|
||||
mi.material_override = _material(color)
|
||||
parent.add_child(mi)
|
||||
|
||||
## Rubberneck: idle people stop and turn toward the incident. Returns false when
|
||||
## this NPC is too engaged (walking, being talked to, already leaving) to watch.
|
||||
func start_rubberneck(at: Vector3) -> bool:
|
||||
if not arrived or npc.leave_requested or leave_requested_by_lifetime:
|
||||
return false
|
||||
# Someone actually waiting at the entrance is being dealt with, not a bystander.
|
||||
# Avatars live under the identity SceneRoot, so `position` matches world space
|
||||
# and also works before the node enters the tree (tests).
|
||||
if awaiting_interaction and (position - door_position).length() < 3.0:
|
||||
return false
|
||||
if reaction_mode == "flee":
|
||||
return false
|
||||
reaction_mode = "watch"
|
||||
reaction_point = at
|
||||
_reaction_timer = RUBBERNECK_S
|
||||
velocity = Vector3.ZERO
|
||||
return true
|
||||
|
||||
## Panic: clear away from the incident (usually the door) in a straight line.
|
||||
func start_flee(from: Vector3) -> void:
|
||||
if npc.leave_requested or leave_requested_by_lifetime:
|
||||
return
|
||||
reaction_mode = "flee"
|
||||
reaction_point = from
|
||||
_reaction_timer = FLEE_S
|
||||
var away := global_position - from
|
||||
away.y = 0.0
|
||||
if away.length() < 0.5:
|
||||
away = Vector3(0.0, 0.0, 1.0)
|
||||
target_position = global_position + away.normalized() * 25.0
|
||||
target_position.y = 0.5
|
||||
arrived = false
|
||||
awaiting_interaction = false
|
||||
|
||||
func reaction_is_active() -> bool:
|
||||
return reaction_mode != ""
|
||||
|
||||
func _tick_reaction(delta: float) -> void:
|
||||
if reaction_mode == "":
|
||||
return
|
||||
_reaction_timer -= delta
|
||||
if reaction_mode == "flee":
|
||||
if _reaction_timer <= 0.0 or (global_position - target_position).length() < 1.5:
|
||||
reaction_mode = ""
|
||||
queue_free()
|
||||
return
|
||||
if _reaction_timer <= 0.0:
|
||||
reaction_mode = ""
|
||||
|
||||
## Turn the body toward the reaction point without moving.
|
||||
func _face_reaction_point(delta: float) -> void:
|
||||
var to_point := reaction_point - global_position
|
||||
to_point.y = 0.0
|
||||
if to_point.length() < 0.1:
|
||||
return
|
||||
var target_yaw := atan2(-to_point.x, -to_point.z)
|
||||
rotation.y = lerp_angle(rotation.y, target_yaw, clampf(delta * 4.0, 0.0, 1.0))
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if npc == null or npc.fsm == null:
|
||||
return
|
||||
_advance_fsm(delta)
|
||||
_tick_reaction(delta)
|
||||
if reaction_mode == "watch":
|
||||
velocity = Vector3.ZERO
|
||||
_face_reaction_point(delta)
|
||||
_animate(delta)
|
||||
return
|
||||
if reaction_mode == "flee":
|
||||
_move_toward_target(delta)
|
||||
_animate(delta)
|
||||
return
|
||||
_move_toward_target(delta)
|
||||
_animate(delta)
|
||||
|
||||
@@ -264,7 +340,7 @@ func _animate(delta: float) -> void:
|
||||
func _advance_fsm(delta: float) -> void:
|
||||
# Routine traffic despawns after a while once it has finished its walk, so
|
||||
# the crowd cap is not permanently occupied by idle standers.
|
||||
if ephemeral and arrived and npc.fsm.state != "LEAVING":
|
||||
if ephemeral and arrived and npc.fsm.current_state != "LEAVING":
|
||||
idle_s += delta
|
||||
if idle_s >= lifetime_s:
|
||||
leave_requested_by_lifetime = true
|
||||
@@ -291,7 +367,11 @@ func _move_toward_target(delta: float) -> void:
|
||||
if agent == null:
|
||||
_move_direct(delta)
|
||||
return
|
||||
agent.target_position = target_position
|
||||
# Re-assigning the target every physics frame invalidates the path, so
|
||||
# get_next_path_position() keeps returning the current position and the
|
||||
# avatar never moves. Only update the agent when the target changes.
|
||||
if agent.target_position != target_position:
|
||||
agent.target_position = target_position
|
||||
if agent.is_navigation_finished():
|
||||
if (global_position - target_position).length() < 3.0:
|
||||
_arrive()
|
||||
@@ -308,14 +388,32 @@ func _move_toward_target(delta: float) -> void:
|
||||
_move_direct(delta)
|
||||
return
|
||||
var next := agent.get_next_path_position()
|
||||
# Godot reports the current position as the first path point (on the navmesh
|
||||
# plane, so below the body) and only advances past it once the agent is within
|
||||
# path_desired_distance. Steering at the point we are standing on gives a
|
||||
# zero-length direction, and steering at any point merely "far enough" away can
|
||||
# pick the old start behind us. Follow the first path point that is genuinely
|
||||
# closer to the destination than we are.
|
||||
var path := agent.get_current_navigation_path()
|
||||
if path.size() >= 2:
|
||||
var goal: Vector3 = path[path.size() - 1]
|
||||
var here_to_goal := Vector2(goal.x - global_position.x, goal.z - global_position.z).length()
|
||||
for i in range(1, path.size()):
|
||||
var candidate: Vector3 = path[i]
|
||||
candidate.y = global_position.y
|
||||
var candidate_to_goal := Vector2(goal.x - candidate.x, goal.z - candidate.z).length()
|
||||
if candidate_to_goal < here_to_goal - 0.05:
|
||||
next = candidate
|
||||
break
|
||||
var dir := (next - global_position)
|
||||
dir.y = 0.0
|
||||
if dir.length() < 0.2:
|
||||
velocity = Vector3.ZERO
|
||||
return
|
||||
dir = dir.normalized()
|
||||
velocity.x = dir.x * 1.3
|
||||
velocity.z = dir.z * 1.3
|
||||
var speed := FLEE_SPEED if reaction_mode == "flee" else 1.3
|
||||
velocity.x = dir.x * speed
|
||||
velocity.z = dir.z * speed
|
||||
velocity.y -= 9.8 * delta
|
||||
look_at(global_position + Vector3(dir.x, 0, dir.z), Vector3.UP)
|
||||
move_and_slide()
|
||||
@@ -329,8 +427,9 @@ func _move_direct(delta: float) -> void:
|
||||
_arrive()
|
||||
return
|
||||
var dir := to_target.normalized()
|
||||
velocity.x = dir.x * 1.3
|
||||
velocity.z = dir.z * 1.3
|
||||
var speed := FLEE_SPEED if reaction_mode == "flee" else 1.3
|
||||
velocity.x = dir.x * speed
|
||||
velocity.z = dir.z * speed
|
||||
velocity.y -= 9.8 * delta
|
||||
look_at(global_position + Vector3(dir.x, 0, dir.z), Vector3.UP)
|
||||
move_and_slide()
|
||||
|
||||
+38
-16
@@ -57,9 +57,11 @@ func _add_box(parent: Node3D, size: Vector3, pos: Vector3, color: Color, cast_sh
|
||||
func _build_ground() -> void:
|
||||
var ground := StaticBody3D.new()
|
||||
ground.name = "Ground"
|
||||
_add_box(root, Vector3(160, 0.5, 160), Vector3(0, -0.25, 20), Color(0.22, 0.24, 0.26))
|
||||
# Large enough that the ground meets the distant skyline ring (no gap of sky
|
||||
# under the buildings when looking down the boulevard).
|
||||
_add_box(root, Vector3(500, 0.5, 500), Vector3(0, -0.25, 20), Color(0.22, 0.24, 0.26))
|
||||
var col := BoxShape3D.new()
|
||||
col.size = Vector3(160, 1, 160)
|
||||
col.size = Vector3(500, 1, 500)
|
||||
var shape_owner := ground.create_shape_owner(ground)
|
||||
ground.shape_owner_add_shape(shape_owner, col)
|
||||
root.add_child(ground)
|
||||
@@ -165,29 +167,49 @@ func _build_navmesh() -> void:
|
||||
root.add_child(region)
|
||||
|
||||
func _build_skyline_backdrop() -> void:
|
||||
## Skyline silhouette backdrop behind the building. The texture has a
|
||||
## transparent sky, so only the building silhouettes show; the material must
|
||||
## be set up for alpha or the plane renders as an opaque slab (ADR/TODO).
|
||||
## Distant skyline surrounding the block. The texture's sky is transparent
|
||||
## (alpha scissor), so only building silhouettes show. Four planes form a
|
||||
## ring: a single plane placed behind the building reads as a floating black
|
||||
## band from the sidewalk.
|
||||
var backdrop := Node3D.new()
|
||||
backdrop.name = "SkylineBackdrop"
|
||||
var plane := MeshInstance3D.new()
|
||||
var mesh := PlaneMesh.new()
|
||||
mesh.size = Vector2(240, 60) # wide, low horizon
|
||||
plane.mesh = mesh
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.albedo_texture = T_SKYLINE
|
||||
mat.texture_repeat = true
|
||||
mat.uv1_scale = Vector3(2.0, 1.0, 1.0)
|
||||
mat.uv1_scale = Vector3(3.0, 1.0, 1.0)
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_SCISSOR
|
||||
mat.alpha_scissor_threshold = 0.3
|
||||
mat.alpha_scissor_threshold = 0.5
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
plane.material_override = mat
|
||||
plane.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
plane.position = Vector3(0, 18, -60) # behind and above the building
|
||||
backdrop.add_child(plane)
|
||||
root.add_child(backdrop)
|
||||
# Unshaded silhouettes read as pure black at 255-scale; lift the albedo so the
|
||||
# distant skyline sits closer to a hazy daytime city.
|
||||
mat.albedo_color = Color(2.6, 2.7, 3.0, 1.0)
|
||||
_skyline_mat = mat
|
||||
var mesh := PlaneMesh.new()
|
||||
# PlaneMesh defaults to a horizontal (XZ) plane; the skyline must stand up.
|
||||
mesh.orientation = PlaneMesh.FACE_Z
|
||||
mesh.size = Vector2(400, 60)
|
||||
# Far enough that the skyline reads as background and its top edge stays out
|
||||
# of the middle of the sky.
|
||||
const DIST := 200.0
|
||||
# The texture keeps its buildings in the lower part of the image, so the plane
|
||||
# center sits at half its height: the building bases meet the ground.
|
||||
const CENTER_Y := 30.0
|
||||
var placements := [
|
||||
[Vector3(0, CENTER_Y, -DIST), 0.0],
|
||||
[Vector3(0, CENTER_Y, DIST), 0.0],
|
||||
[Vector3(-DIST, CENTER_Y, 0), PI / 2.0],
|
||||
[Vector3(DIST, CENTER_Y, 0), PI / 2.0],
|
||||
]
|
||||
for placement in placements:
|
||||
var plane := MeshInstance3D.new()
|
||||
plane.mesh = mesh
|
||||
plane.material_override = mat
|
||||
plane.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
plane.position = placement[0]
|
||||
plane.rotation.y = placement[1]
|
||||
backdrop.add_child(plane)
|
||||
root.add_child(backdrop)
|
||||
|
||||
var _skyline_mat: StandardMaterial3D = null
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ func _process(_delta: float) -> bool:
|
||||
quit(1)
|
||||
return true
|
||||
if gm != null and not camera_staged:
|
||||
# The game boots into the venue menu now; start the Hollywood shift first.
|
||||
var menu = gm.get("start_menu")
|
||||
if menu != null and menu.visible:
|
||||
gm.call("_on_venue_selected", "hollywood_building")
|
||||
gm.guard.global_position = Vector3(0, 0.1, 10.5)
|
||||
gm.guard.rotation.y = 0.0
|
||||
gm.guard.head.rotation.x = deg_to_rad(2.0)
|
||||
@@ -52,7 +56,8 @@ func _advance() -> void:
|
||||
state = 1
|
||||
state_frames = 0
|
||||
1:
|
||||
# Wait for a nearby NPC so the interaction HUD has a target.
|
||||
# Wait for a nearby NPC so the interaction HUD has a target. NPCs now
|
||||
# walk in from the street, so this can take a few simulated seconds.
|
||||
if gm != null and gm.npcs.size() > 0:
|
||||
gm.call("_cycle_nearby_target")
|
||||
_face_target()
|
||||
@@ -83,24 +88,27 @@ func _advance() -> void:
|
||||
# Close the radio form, then jump the shift to the LATE phase.
|
||||
if gm != null:
|
||||
gm.radio_panel.hide()
|
||||
gm.guard.rotation.y = 0.0
|
||||
gm.guard.head.rotation.x = deg_to_rad(2.0)
|
||||
gm.hud.set_action_hint("")
|
||||
gm.coordinator.elapsed_s = 750.0
|
||||
state = 5
|
||||
state_frames = 0
|
||||
5:
|
||||
# Let the phase transition (and street lamps / marquee) settle, then
|
||||
# take the night avenue shot.
|
||||
# Stage the avenue view down the boulevard (not into the wall) and let
|
||||
# the night lighting and street lamps settle.
|
||||
if state_frames == 1 and gm != null:
|
||||
gm.guard.rotation.y = deg_to_rad(-70)
|
||||
gm.guard.head.rotation.x = deg_to_rad(3.0)
|
||||
if state_frames >= 90:
|
||||
gm.guard.rotation.y = 0.0
|
||||
gm.guard.head.rotation.x = deg_to_rad(2.0)
|
||||
_shoot("05-late-night-avenue.png")
|
||||
if gm != null:
|
||||
gm.call("_toggle_flashlight")
|
||||
state = 6
|
||||
state_frames = 0
|
||||
6:
|
||||
if state_frames >= 40:
|
||||
# Face the entrance again and switch the flashlight on for the night set.
|
||||
if state_frames == 1 and gm != null:
|
||||
gm.guard.rotation.y = 0.0
|
||||
gm.guard.head.rotation.x = deg_to_rad(4.0)
|
||||
gm.call("_toggle_flashlight")
|
||||
if state_frames >= 30:
|
||||
_shoot("06-night-flashlight.png")
|
||||
state = 7
|
||||
quit(0)
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
extends SceneTree
|
||||
## Crowd-presentation smoke: starts a shift, waits for bystanders to settle, then
|
||||
## checks that an aggressive crowd event makes idle NPCs stop and watch, and that
|
||||
## panic sends them away from the door.
|
||||
##
|
||||
## Usage:
|
||||
## godot --headless --path . --script res://src/test/smoke_crowd.gd
|
||||
## Exit code 0 = pass, 1 = failure.
|
||||
|
||||
const MAX_FRAMES := 2400
|
||||
|
||||
var frame := 0
|
||||
var gm: Node = null
|
||||
var started := false
|
||||
var phase := 0
|
||||
var failures: Array[String] = []
|
||||
|
||||
func _initialize() -> void:
|
||||
root.size = Vector2i(1280, 720)
|
||||
root.add_child(load("res://scenes/main.tscn").instantiate())
|
||||
|
||||
func _process(_delta: float) -> bool:
|
||||
frame += 1
|
||||
if gm == null:
|
||||
gm = root.find_child("GameManager", true, false)
|
||||
return false
|
||||
if not started:
|
||||
gm.call("_on_venue_selected", "hollywood_building")
|
||||
started = true
|
||||
return false
|
||||
if frame > MAX_FRAMES:
|
||||
_fail("timeout before crowd reactions were observed")
|
||||
return true
|
||||
match phase:
|
||||
0:
|
||||
if frame < 300:
|
||||
return false
|
||||
# Wait until at least one settled bystander is away from the door (someone
|
||||
# waiting at the entrance is being dealt with and must not rubberneck).
|
||||
if _bystander_count() == 0:
|
||||
return false
|
||||
gm.coordinator.crowd.apply_event("aggressive_behavior")
|
||||
var watching := _count_mode("watch")
|
||||
_check(watching > 0, "aggressive behavior makes idle NPCs watch (%d watching)" % watching)
|
||||
phase = 1
|
||||
1:
|
||||
if frame < 320:
|
||||
return false
|
||||
var door: Vector3 = gm.selected_scenario._location_or_default("entrance", Vector3(0, 0.5, 1.2))
|
||||
for npc in gm.npcs:
|
||||
if is_instance_valid(npc) and npc.has_method("reaction_is_active"):
|
||||
pass
|
||||
gm.coordinator.crowd.apply_event("visible_weapon")
|
||||
gm.coordinator.crowd.apply_event("aggressive_behavior")
|
||||
gm.coordinator.crowd.apply_event("aggressive_behavior")
|
||||
gm.coordinator.crowd.apply_event("emergency_responder")
|
||||
_check(gm.coordinator.crowd.should_flee(), "stacked alarms panic the crowd")
|
||||
var fleeing := _count_mode("flee")
|
||||
_check(fleeing > 0, "panic sends NPCs away from the door (%d fleeing)" % fleeing)
|
||||
var away_ok := true
|
||||
for npc in gm.npcs:
|
||||
if not is_instance_valid(npc) or npc.reaction_mode != "flee":
|
||||
continue
|
||||
if (npc.target_position - door).length() <= (npc.global_position - door).length():
|
||||
away_ok = false
|
||||
_check(away_ok, "every fleeing NPC targets a point farther from the door")
|
||||
phase = 2
|
||||
_:
|
||||
_finish()
|
||||
return true
|
||||
return false
|
||||
|
||||
func _bystander_count() -> int:
|
||||
var n := 0
|
||||
for npc in gm.npcs:
|
||||
if not is_instance_valid(npc) or not npc.arrived:
|
||||
continue
|
||||
if npc.awaiting_interaction and npc.global_position.distance_to(npc.door_position) < 3.0:
|
||||
continue
|
||||
n += 1
|
||||
return n
|
||||
|
||||
func _settled_count() -> int:
|
||||
var n := 0
|
||||
for npc in gm.npcs:
|
||||
if is_instance_valid(npc) and npc.arrived:
|
||||
n += 1
|
||||
return n
|
||||
|
||||
func _count_mode(mode: String) -> int:
|
||||
var n := 0
|
||||
for npc in gm.npcs:
|
||||
if is_instance_valid(npc) and npc.reaction_mode == mode:
|
||||
n += 1
|
||||
return n
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
if condition:
|
||||
print("ok: " + message)
|
||||
else:
|
||||
_fail(message)
|
||||
|
||||
func _fail(message: String) -> void:
|
||||
failures.append(message)
|
||||
_finish()
|
||||
|
||||
func _finish() -> void:
|
||||
if failures.is_empty():
|
||||
print("SMOKE OK: crowd rubberneck and panic flee")
|
||||
quit(0)
|
||||
else:
|
||||
for message in failures:
|
||||
printerr("SMOKE FAIL: " + message)
|
||||
quit(1)
|
||||
@@ -0,0 +1,106 @@
|
||||
extends RefCounted
|
||||
## Crowd presentation: rubbernecking on aggressive/emergency events and clearing
|
||||
## out when the crowd panics (PLAN: Public Crowd Reaction).
|
||||
|
||||
const CrowdSystem := preload("res://src/core/crowd_system.gd")
|
||||
const NpcAvatar := preload("res://src/game/npc_avatar.gd")
|
||||
const NpcProfile := preload("res://src/core/npc_profile.gd")
|
||||
const Rules := preload("res://src/core/rules.gd")
|
||||
|
||||
func _profile() -> NpcProfile:
|
||||
var p := NpcProfile.new()
|
||||
p.id = "bystander"
|
||||
p.display_name = "Bystander"
|
||||
p.npc_type = Rules.NpcType.TOURIST
|
||||
return p
|
||||
|
||||
func _avatar() -> Node:
|
||||
var avatar: Node = NpcAvatar.new()
|
||||
avatar.setup(_profile(), "photo", 99, Vector3(4, 0.5, 8), Vector3(2, 0.5, 12))
|
||||
return avatar
|
||||
|
||||
func test_reaction_for_event() -> bool:
|
||||
var a := TestUtils.check_eq(CrowdSystem.reaction_for_event("aggressive_behavior"), "watch", "aggression draws watchers")
|
||||
var b := TestUtils.check_eq(CrowdSystem.reaction_for_event("emergency_responder"), "watch", "responder draws watchers")
|
||||
var c := TestUtils.check_eq(CrowdSystem.reaction_for_event("visible_weapon"), "watch", "a weapon draws watchers")
|
||||
var d := TestUtils.check_eq(CrowdSystem.reaction_for_event("de_escalation"), "", "de-escalation is not a watch cue")
|
||||
var e := TestUtils.check_eq(CrowdSystem.reaction_for_event("calm_professionalism"), "", "calm is not a watch cue")
|
||||
return a and b and c and d and e
|
||||
|
||||
func test_panic_flag_and_flee_cue() -> bool:
|
||||
var crowd := CrowdSystem.new()
|
||||
var a := TestUtils.check(not crowd.should_flee(), "crowd starts calm")
|
||||
crowd.apply_event("visible_weapon")
|
||||
crowd.apply_event("aggressive_behavior")
|
||||
crowd.apply_event("aggressive_behavior")
|
||||
crowd.apply_event("emergency_responder")
|
||||
var b := TestUtils.check(crowd.should_flee(), "stacked alarms reach panic")
|
||||
var c := TestUtils.check_eq(crowd.summary().get("panic"), true, "summary reports panic")
|
||||
var calm := CrowdSystem.new()
|
||||
calm.apply_event("de_escalation")
|
||||
calm.apply_event("calm_professionalism")
|
||||
var d := TestUtils.check(not calm.should_flee(), "a calm crowd does not flee")
|
||||
crowd = null
|
||||
calm = null
|
||||
return a and b and c and d
|
||||
|
||||
func test_idle_bystander_rubbernecks() -> bool:
|
||||
var avatar := _avatar()
|
||||
# Still walking: should refuse so traffic is not frozen mid-approach.
|
||||
var walking := TestUtils.check(not avatar.start_rubberneck(Vector3(0, 1, 1)), "walkers keep walking")
|
||||
avatar.arrived = true
|
||||
var accepted := TestUtils.check(avatar.start_rubberneck(Vector3(0, 1, 1)), "idle bystander watches")
|
||||
var mode := TestUtils.check_eq(avatar.reaction_mode, "watch", "watch mode is set")
|
||||
var active := TestUtils.check(avatar.reaction_is_active(), "reaction is active")
|
||||
avatar.free()
|
||||
return walking and accepted and mode and active
|
||||
|
||||
func test_engaged_person_does_not_rubberneck() -> bool:
|
||||
var avatar := _avatar()
|
||||
avatar.arrived = true
|
||||
avatar.awaiting_interaction = true
|
||||
# Not in a tree, so use local position (global_position is a no-op here).
|
||||
avatar.position = avatar.door_position
|
||||
var ok := TestUtils.check(not avatar.start_rubberneck(Vector3.ZERO), "someone waiting at the door does not rubberneck")
|
||||
# The same person further away is an ordinary bystander and does watch.
|
||||
avatar.position = avatar.door_position + Vector3(8, 0, 0)
|
||||
var far_ok := TestUtils.check(avatar.start_rubberneck(Vector3.ZERO), "a bystander away from the door still watches")
|
||||
avatar.free()
|
||||
return ok and far_ok
|
||||
|
||||
func test_panic_moves_people_away_from_the_door() -> bool:
|
||||
var avatar := _avatar()
|
||||
avatar.position = Vector3(1, 0.5, 2)
|
||||
var door := Vector3(0, 0.5, 1.2)
|
||||
avatar.start_flee(door)
|
||||
var a := TestUtils.check_eq(avatar.reaction_mode, "flee", "flee mode is set")
|
||||
var b := TestUtils.check((avatar.target_position - door).length() > (avatar.position - door).length(),
|
||||
"flee target is farther from the door than the start")
|
||||
var c := TestUtils.check(not avatar.awaiting_interaction, "fleeing cancels waiting at the entrance")
|
||||
avatar.free()
|
||||
return a and b and c
|
||||
|
||||
func test_crowd_updates_arrive_through_the_event_bus() -> bool:
|
||||
## CrowdSystem.apply_event() emits EventBus.crowd_changed, not its own
|
||||
## `changed` signal; wiring the wrong one silently disables crowd reactions.
|
||||
var src := FileAccess.get_file_as_string("res://src/game/game_manager.gd")
|
||||
var ok := TestUtils.check(src.contains("event_bus.crowd_changed.connect(_on_crowd_changed)"),
|
||||
"GameManager listens on EventBus.crowd_changed")
|
||||
var bus: Object = load("res://src/core/event_bus.gd").new()
|
||||
var seen: Array = []
|
||||
bus.crowd_changed.connect(func(payload): seen.append(payload.get("event", "")))
|
||||
var crowd := CrowdSystem.new()
|
||||
crowd.set_event_bus(bus)
|
||||
crowd.apply_event("aggressive_behavior")
|
||||
var delivers := TestUtils.check_eq(seen, ["aggressive_behavior"], "apply_event reaches the bus listener")
|
||||
bus = null
|
||||
crowd = null
|
||||
return ok and delivers
|
||||
|
||||
func test_leaving_npc_does_not_flee() -> bool:
|
||||
var avatar := _avatar()
|
||||
avatar.npc.leave_requested = true
|
||||
avatar.start_flee(Vector3.ZERO)
|
||||
var ok := TestUtils.check_eq(avatar.reaction_mode, "", "someone already leaving is left alone")
|
||||
avatar.free()
|
||||
return ok
|
||||
Reference in new issue
Block a user