mission_ember_controller_test.lua 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package.path = "scripts/?.lua;" .. package.path
  2. local names = {
  3. "LANDING_MERCURY_ANCHOR_SQUAD", "LANDING_MERCURY_SUPPORT_A_SQUAD",
  4. "LANDING_MERCURY_SUPPORT_B_SQUAD", "LANDING_MERCURY_SUPPORT_C_SQUAD",
  5. "LANDING_MERCURY_RANGED_A_SQUAD", "LANDING_MERCURY_RANGED_B_SQUAD",
  6. "LANDING_MERCURY_BONUS_SUPPORT_A_SQUAD", "LANDING_MERCURY_BONUS_SUPPORT_B_SQUAD",
  7. "LANDING_MERCURY_BONUS_SUPPORT_C_SQUAD", "LANDING_MERCURY_BONUS_SUPPORT_D_SQUAD",
  8. }
  9. local mission = {
  10. Squad = {}, Slot = {M_DIRECTIVE_SENSOR_80B3C90A = "directive"},
  11. states = {STATE_80B3C09E_0008_0000_80B3C09C = {region_index = 64}},
  12. Directive = {
  13. FIND_AND_DISABLE_THE_ALMIGHTY_S_WEAPONS_A70DA4A6 = "clear",
  14. FIND_AND_DISABLE_THE_ALMIGHTY_S_WEAPONS_2700C0C5 = "controls",
  15. },
  16. }
  17. for _, name in ipairs(names) do
  18. mission.Squad[name] = name
  19. mission.Slot[name] = name
  20. end
  21. local devices = {
  22. "POWERHOUSE_BRIDGE_ARM_MERCURY_DEVICE", "POWERHOUSE_BRIDGE_GEAR_MERCURY_BOTTOM_DEVICE",
  23. "POWERHOUSE_BRIDGE_GEAR_MERCURY_TOP_DEVICE", "POWERHOUSE_BRIDGE_ARM_SUN_DEVICE",
  24. "POWERHOUSE_BRIDGE_GEAR_SUN_BOTTOM_DEVICE", "POWERHOUSE_BRIDGE_GEAR_SUN_TOP_DEVICE",
  25. }
  26. for _, name in ipairs(devices) do mission.Slot[name] = name end
  27. mission.Slot.EMBER_POWERHOUSE_BRIDGE_OBJECTIVE = "bridge_objective"
  28. package.preload.missions = function() return {MISSION_EMBER = "test_mission"} end
  29. package.preload.test_mission = function() return mission end
  30. local program = require("mission_ember")
  31. assert(program.initial_state == mission.states.STATE_80B3C09E_0008_0000_80B3C09C,
  32. "fresh launches must declare the opening powerhouse state")
  33. local vars, directives, placements, seeds = {}, {}, 0, 0
  34. local state = {variable = function(_, key) return vars[key] end}
  35. local closed, resets = {}, 0
  36. local context = {sdk = {squad_modes = {replace = "replace"}, device_transitions = {close = "close"}}}
  37. function context:set_variable(key, value) vars[key] = value end
  38. function context:clear_variable(key) vars[key] = nil end
  39. function context:select_state(entry)
  40. assert(entry.region_index == 64)
  41. seeds = seeds + 1
  42. end
  43. function context:squad(name)
  44. assert(mission.Squad[name])
  45. return {default_counts = {1}, place = function() placements = placements + 1 end}
  46. end
  47. function context:slot(name)
  48. for _, device in ipairs(devices) do
  49. if name == device then
  50. return {transition = function(_, args)
  51. assert(args.transition == "close" and args.snap == true)
  52. closed[#closed + 1] = name
  53. end}
  54. end
  55. end
  56. if name == "bridge_objective" then
  57. return {reset_objectives = function() resets = resets + 1 end}
  58. end
  59. if name == "directive" then
  60. return {set_directive = function(_, args) directives[#directives + 1] = args.directive end}
  61. end
  62. for index, value in ipairs(names) do
  63. if name == value then return {registry_key = 7, slot_type = 1, slot_index = index} end
  64. end
  65. error("unknown slot " .. name)
  66. end
  67. local function region(index)
  68. program.on_event_client_state_changed(context, state, {current_region_index = index})
  69. end
  70. local function cleared()
  71. for index = 1, #names do
  72. program.on_event_squad_state(context, state, {
  73. registry_key = 7, slot_type = 1, slot_index = index,
  74. alive_count = 0, previous_alive_count = 1,
  75. })
  76. end
  77. end
  78. program.on_start(context, state)
  79. assert(#closed == 6 and resets == 1 and placements == 0)
  80. region(40)
  81. assert(seeds == 0 and placements == 0)
  82. region(64); region(64)
  83. assert(seeds == 0 and placements == #names and directives[1] == "clear")
  84. region(nil); cleared()
  85. assert(#directives == 1)
  86. region(64)
  87. assert(seeds == 0 and placements == #names)
  88. cleared(); cleared()
  89. assert(#directives == 2 and directives[2] == "controls")
  90. package.loaded.mission_ember = nil
  91. program = require("mission_ember")
  92. region(64); cleared()
  93. assert(seeds == 0 and placements == #names and #directives == 2)
  94. assert(#closed == 6 and resets == 1, "transit and reload must not reset the bridge")
  95. print("controller region ownership, transit, clear and reload checks passed")