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
@@ -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