opening.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. -- Arrival cinematic and control handoff. The cinematic owns a separate authored state.
  2. return function(mission, landing)
  3. local entry = assert(mission.states.STATE_80B3C09E_0006_0001_80B3C09A)
  4. local cinematic = assert(mission.Slot.PF_CINEMATIC_BOOKEND_CINEMATIC)
  5. local function phase(state) return state:variable("ember.cinematic") or 0 end
  6. local function finish(context, state)
  7. if phase(state) ~= 1 then return end
  8. context:set_variable("ember.cinematic", 2)
  9. context:slot(cinematic):set_cinematic_active{active = false}
  10. context:select_state(landing.initial_state)
  11. context:set_phase(2)
  12. end
  13. return {
  14. initial_state = entry,
  15. playable = function(state) return phase(state) == 2 end,
  16. client_state = function(context, state, event)
  17. local held = event.held_region_index or event.current_region_index
  18. -- Only a held-region report starts the movie; a requested destination is insufficient.
  19. if held == entry.region_index and phase(state) == 0 then
  20. context:set_variable("ember.cinematic", 1)
  21. context:set_phase(1)
  22. context:slot(cinematic):set_cinematic_active{active = true}
  23. end
  24. end,
  25. -- Native completion and cinematic_skip use the same exact source identity.
  26. -- finish() commits phase 2 before requesting stop, so the ensuing finished
  27. -- incident (or a repeated Escape) cannot start the spawn handoff twice.
  28. terminated = function(context, state, event)
  29. if phase(state) ~= 1 then return end
  30. local slot = context:slot(cinematic)
  31. if event.registry_key ~= slot.registry_key or event.slot_type ~= slot.slot_type
  32. or event.slot_index ~= slot.slot_index then return end
  33. finish(context, state)
  34. end,
  35. }
  36. end