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.
68 lines
1.9 KiB
GDScript
68 lines
1.9 KiB
GDScript
class_name CrowdSystem
|
|
extends RefCounted
|
|
## Models crowd mood and public reaction (PLAN.md: Public Crowd Reaction).
|
|
|
|
const EventBus := preload("res://src/core/event_bus.gd")
|
|
## mood: 0.0 (calm) .. 1.0 (panic). attention: how many people are watching.
|
|
|
|
signal changed(payload: Dictionary)
|
|
|
|
var event_bus: EventBus = null
|
|
var mood: float = 0.05
|
|
var attention: float = 0.0
|
|
var crowd_panic := false
|
|
|
|
func set_event_bus(bus: EventBus) -> void:
|
|
event_bus = bus
|
|
|
|
## Apply a crowd event. type: "calm_professionalism", "aggressive_behavior",
|
|
## "visible_weapon", "emergency_responder", "de_escalation".
|
|
func apply_event(event_type: String) -> void:
|
|
match event_type:
|
|
"calm_professionalism":
|
|
attention = maxf(0.0, attention - 0.05)
|
|
mood = maxf(0.0, mood - 0.02)
|
|
"de_escalation":
|
|
mood = maxf(0.0, mood - 0.06)
|
|
attention = clampf(attention + 0.05, 0.0, 1.0)
|
|
"aggressive_behavior":
|
|
attention = clampf(attention + 0.20, 0.0, 1.0)
|
|
mood = clampf(mood + 0.12, 0.0, 1.0)
|
|
"visible_weapon":
|
|
attention = 1.0
|
|
mood = clampf(mood + 0.35, 0.0, 1.0)
|
|
"emergency_responder":
|
|
attention = 1.0
|
|
mood = clampf(mood + 0.25, 0.0, 1.0)
|
|
_:
|
|
pass
|
|
crowd_panic = mood >= 0.75
|
|
if event_bus:
|
|
event_bus.crowd_changed.emit({
|
|
"mood": mood,
|
|
"attention": attention,
|
|
"panic": crowd_panic,
|
|
"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,
|
|
"attention": attention,
|
|
"panic": crowd_panic,
|
|
}
|