Files
security-game/src/core/incident_recorder.gd
T
zwitschi f5ad1642b5
Full build / Import + headless tests (push) Successful in 26s
Full build / Full desktop build + optional release (push) Failing after 3m31s
Add PLAN verbs and fix dead incident recording
Verbs (PLAN levels 1-3)
- Eye contact: own Level 1 radial slice, logged as "eye contact".
- Recognition is a player decision: "Recognize" sets NPCController.player_recognized,
  writes access evidence, and GameManager only then appends a RECOGNITION artifact.
  It is no longer implied by NPC type.
- Body camera: real flag (off by default) driving the REC overlay; B toggles it and
  a formal warning arms it automatically, writing a body_camera incident event.
- Blocking stations the guard 0.9 m from the person toward the entrance and turns
  to face them, instead of only emitting the escalation level.
- Request reason: Level 3 ask answered from the NPC's seeded dialogue_lines.
- Radial grows to 12 slices (174 px outer radius, centered labels).

Incident recording fix
- IncidentRecorder.start_incident() was never called, so add_event /
  add_access_evidence / add_escalation silently no-opped and the shift review
  always reported zero incidents. Incidents now open on focus (guarded by
  has_open_incident), verbs call _ensure_incident, and ShiftCoordinator closes
  leftovers as "unresolved" before building the review.

Copy and docs
- 9 new string keys (eye contact, body camera, recognition, reason, station).
- README controls, 26-step smoke checklist, test count, status lists.
- TODO section moved to DONE; MEMORY records the verb design and the recorder bug.

Verification: headless 98/98, smoke_plan_verbs.gd + smoke_session_shell.gd +
windowed smoke_focus_radial.gd all pass. Version bumped to 0.2.3.
2026-10-31 20:29:50 +01:00

99 lines
3.2 KiB
GDScript

class_name IncidentRecorder
extends RefCounted
const EventBus := preload("res://src/core/event_bus.gd")
var event_bus: EventBus = null
func set_event_bus(bus: EventBus) -> void:
event_bus = bus
## Structured incident history (ADR-0005). Records observations, player actions,
## access evidence, escalation levels, responses, and outcomes for evidence,
## reputation, crowd reactions, and shift review.
var incidents: Array[Dictionary] = []
var _open_incidents: Dictionary = {} # npc_id -> incident dict
## Begin an incident for an NPC. Returns incident_id.
func start_incident(npc_id: String, trigger: String) -> String:
var incident := {
"id": "inc_%s_%d" % [npc_id, Time.get_ticks_usec()],
"npc_id": npc_id,
"trigger": trigger,
"opened_at_ms": Time.get_ticks_msec(),
"events": [],
"access_evidence": [],
"escalation_history": [],
"outcome": null,
}
_open_incidents[npc_id] = incident
return incident["id"]
func add_event(npc_id: String, event: Dictionary) -> void:
if not _open_incidents.has(npc_id):
return
var incident: Dictionary = _open_incidents[npc_id]
event["at_ms"] = Time.get_ticks_msec()
incident["events"].append(event)
if event_bus:
event_bus.incident_recorded.emit(incident.duplicate(true))
func add_access_evidence(npc_id: String, evidence: Dictionary) -> void:
if not _open_incidents.has(npc_id):
return
var incident: Dictionary = _open_incidents[npc_id]
incident["access_evidence"].append(evidence)
if event_bus:
event_bus.access_decided.emit(evidence.duplicate(true))
incident["events"].append({
"type": "access_check",
"at_ms": Time.get_ticks_msec(),
"evidence": evidence,
})
func add_escalation(npc_id: String, level: int, reason: String) -> void:
if not _open_incidents.has(npc_id):
return
var incident: Dictionary = _open_incidents[npc_id]
incident["escalation_history"].append({
"level": level,
"reason": reason,
"at_ms": Time.get_ticks_msec(),
})
## Close an incident. outcome: e.g. "peaceful", "escort_off_property",
## "assisted", "responded", "custody". Returns the closed incident.
func close_incident(npc_id: String, outcome: String) -> Dictionary:
if not _open_incidents.has(npc_id):
return {}
var incident: Dictionary = _open_incidents[npc_id]
incident["outcome"] = outcome
incident["closed_at_ms"] = Time.get_ticks_msec()
incidents.append(incident)
_open_incidents.erase(npc_id)
if event_bus:
event_bus.incident_recorded.emit(incident.duplicate(true))
return incident
func open_incidents_count() -> int:
return _open_incidents.size()
## True when an incident is already open for this NPC (avoids duplicating one
## incident every time the player re-focuses the same person).
func has_open_incident(npc_id: String) -> bool:
return _open_incidents.has(npc_id)
## Close every still-open incident at shift end so the review does not silently
## drop interactions the player never resolved. Returns how many were closed.
func close_all_open(outcome: String = "unresolved") -> int:
var ids: Array = _open_incidents.keys()
for npc_id in ids:
close_incident(str(npc_id), outcome)
return ids.size()
func to_dict() -> Dictionary:
return {
"incidents": incidents.duplicate(true),
"open_count": _open_incidents.size(),
}