Sync typed Original Tactics activity surface

ober

23f0f8705b9316a5e71978174a83e9705165cf9d

diff --git a/templates/original-tactics-parts/MainActivity.kt.ss b/templates/original-tactics-parts/MainActivity.kt.ss
index f4909b3..8795393 100644
--- a/templates/original-tactics-parts/MainActivity.kt.ss
+++ b/templates/original-tactics-parts/MainActivity.kt.ss
@@ -56,8 +56,8 @@
         (type StringBuilder) (type Thread) (type Throwable) (type Typeface) (type View)
         (type ViewGroup) (type Window) (type ZoomPanFrameLayout)
         (type DisplayMetrics)
-        (type Any) (type Float32)
-        (type Number)
+        (type Any) (type Float32) (type Long)
+        (type Number) (type ProjectedHelmPose)
 
         ;; Android and Kotlin interop stays explicit so every emitted statement
         ;; remains type checked by the Jerboa Kotlin backend.
@@ -208,6 +208,7 @@
           (kotlin-member-set cornerRadius))
         (extern (maIntToFloat (value : Int32)) : Float32 (kotlin-member-call toFloat))
         (extern (maFloatToInt (value : Float32)) : Int32 (kotlin-member-call toInt))
+        (extern (maIntToLong (value : Int32)) : Long (kotlin-member-call toLong))
         (extern (maActivityResources (activity : MainActivity)) : Resources
           (kotlin-member-get resources))
         (extern (maResourcesMetrics (resources : Resources)) : DisplayMetrics
@@ -324,6 +325,8 @@
           (kotlin-member-call get))
         (extern (maEmptyStringIntMap) : (Map String Int32)
           (kotlin-call emptyMap))
+        (extern (maEmptyStringObjectMap) : (Map String JSONObject)
+          (kotlin-call emptyMap))
         (extern (maMapStringIntKeys (values : (Map String Int32))) : (Set String)
           (kotlin-member-get keys))
         (extern (maMutableStringIntMapAsMap (values : (MutableMap String Int32)))
@@ -570,23 +573,55 @@
           (modifiers private))
         (val UI_MUTED : Int32 (maColorRgb (int32 151) (int32 170) (int32 198))
           (modifiers private))
-        (val DEFAULT_ENDPOINT : String "http://127.0.0.1:8788/api/service"
+        (val UI_DIM : Int32 (maColorRgb (int32 102) (int32 120) (int32 148))
+          (modifiers private))
+        (val UI_ACCENT : Int32 (maColorRgb (int32 88) (int32 156) (int32 226))
+          (modifiers private))
+        (val DEFAULT_ENDPOINT : String "embedded://sfb-rules/api/service"
+          (modifiers private const))
+        (val BATTLE_LOG_ENDPOINT : String "http://127.0.0.1:8799/api/battle-log"
           (modifiers private const))
         (val PREF_ENDPOINT : String "endpoint" (modifiers private const))
+        (val PREF_STATE_SCHEMA_VERSION : String "state_schema_version"
+          (modifiers private const))
+        (val STATE_SCHEMA_VERSION : Int32 (int32 2) (modifiers private const))
         (val GAME_STATE_FILE : String "current_game.json" (modifiers private const))
-        (val CLIENT_LOG_ENDPOINT : String "http://127.0.0.1:8799/api/client-log"
+        (val ACTION_CONSOLE_TAG : String "action-console" (modifiers private const))
+        (val CLIENT_LOG_ENDPOINT : String "http://10.66.60.2:8799/api/client-log"
           (modifiers private const))
         (val PAIR_MARKER : String "$pair" (modifiers private const))
         (val PA_PANEL_BOX_CODE : String "52" (modifiers private const))
+        (val DISPLACEMENT_DEVICE_BOX_CODE : String "56" (modifiers private const))
+        (val STATUS_TEXT_SP : Float32 (float32 18.0) (modifiers private const))
+        (val OUTPUT_TEXT_SP : Float32 (float32 17.0) (modifiers private const))
+        (val LABEL_TEXT_SP : Float32 (float32 18.0) (modifiers private const))
+        (val CONTROL_TEXT_SP : Float32 (float32 20.0) (modifiers private const))
+        (val BUTTON_TEXT_SP : Float32 (float32 16.0) (modifiers private const))
+        (val SPINNER_TEXT_SP : Float32 (float32 19.0) (modifiers private const))
         (val SERVICE_READ_TIMEOUT_MS : Int32 (int32 30000) (modifiers private const))
         (val AUTO_BATTLE_READ_TIMEOUT_MS : Int32 (int32 30000) (modifiers private const))
+        (val CLIENT_LOG_READ_TIMEOUT_MS : Int32 (int32 1500) (modifiers private const))
+        (val CLIENT_LOG_CRASH_TIMEOUT_MS : Int32 (int32 1500) (modifiers private const))
+        (val CLIENT_LOG_JSON_CHARS : Int32 (int32 6000) (modifiers private const))
+        (val CLIENT_LOG_STACK_CHARS : Int32 (int32 12000) (modifiers private const))
+        (val BATTLE_LOG_ENTRY_LIMIT : Int32 (int32 4096) (modifiers private const))
+        (val BATTLE_LOG_CONNECT_TIMEOUT_MS : Int32 (int32 2500) (modifiers private const))
+        (val BATTLE_LOG_READ_TIMEOUT_MS : Int32 (int32 30000) (modifiers private const))
+        (val AUTO_GAME_EVENT_LIMIT : Int32 (int32 32) (modifiers private const))
+        (val STATE_SAVE_DEBOUNCE_MS : Long (maIntToLong (int32 500)) (modifiers private))
+        (val DASHBOARD_QUERY_MIN_INTERVAL_MS : Long (maIntToLong (int32 350)) (modifiers private))
+        (val STATUS_QUERY_MIN_INTERVAL_MS : Long (maIntToLong (int32 350)) (modifiers private))
+        (val ACTION_QUERY_MIN_INTERVAL_MS : Long (maIntToLong (int32 500)) (modifiers private))
         (val FIRE_GROUP_ALL : Int32 (int32 1) (modifiers private const))
         (val FIRE_GROUP_HEAVY : Int32 (int32 2) (modifiers private const))
         (val FIRE_GROUP_PHASER : Int32 (int32 3) (modifiers private const))
-        (val AUTO_QUIET_STEP_DELAY_MS : Int (int 70) (modifiers private const))
-        (val AUTO_MOVEMENT_STEP_DELAY_MS : Int (int 320) (modifiers private const))
-        (val AUTO_ACTION_EVENT_DELAY_MS : Int (int 430) (modifiers private const))
-        (val AUTO_COMBAT_EVENT_DELAY_MS : Int (int 650) (modifiers private const))
+        (val AUTO_QUIET_STEP_DELAY_MS : Int (int 5) (modifiers private const))
+        (val AUTO_MOVEMENT_STEP_DELAY_MS : Int (int 15) (modifiers private const))
+        (val AUTO_ACTION_EVENT_DELAY_MS : Int (int 25) (modifiers private const))
+        (val AUTO_COMBAT_EVENT_DELAY_MS : Int (int 40) (modifiers private const))
+        (val AUTO_UI_RENDER_INTERVAL_MS : Long (maIntToLong (int32 180)) (modifiers private))
+        (val AUTO_STOP_WAIT_TIMEOUT_MS : Long (maIntToLong (int32 45000)) (modifiers private))
+        (val AUTO_LOCAL_STEP_TIMEOUT_MS : Long (maIntToLong (int32 10000)) (modifiers private))
         (val MANEUVERS : (List String)
           (list-of String "none" "left" "right" "sideslip-left" "sideslip-right" "het")
           (modifiers private))
@@ -734,11 +769,26 @@
           (var rulesClient : RulesClient (modifiers private lateinit))
           (var currentGame : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
           (var autoBattleRunning : Bool #f (modifiers @Volatile private))
+          (var autoBattleWorkerActive : Bool #f (modifiers @Volatile private))
+          (var autoBattleSerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var fastAutoBattleMode : Bool #f (modifiers @Volatile private))
+          (var autoIdleActionSerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var dashboardQuerySerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var statusQuerySerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var actionQuerySerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var truthQuerySerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var stateSaveSerial : Int32 (int32 0) (modifiers @Volatile private))
+          (var lastDashboardQueryMillis : Long (maIntToLong (int32 0)) (modifiers private))
+          (var lastStatusQueryMillis : Long (maIntToLong (int32 0)) (modifiers private))
+          (var lastActionQueryMillis : Long (maIntToLong (int32 0)) (modifiers private))
+          (var lastAutoRenderMillis : Long (maIntToLong (int32 0)) (modifiers private))
           (var lastEvents : JSONArray (maJsonArray) (modifiers private))
           (var lastDashboardReport : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
           (var lastStatusReport : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
           (var lastAlphaActionReport : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
           (var lastBetaActionReport : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
+          (var queuedActionRequests : (MutableList JSONObject)
+            (mutable-list-empty JSONObject) (modifiers private))
           (var alphaTruthReport : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
           (var betaTruthReport : (Nullable JSONObject) (nullable-none JSONObject) (modifiers private))
           (var shipIds : (List String) (list-of String "fed-tcc" "klingon-td7c") (modifiers private))
@@ -749,6 +799,13 @@
             (list-of FireTargetChoice) (modifiers private))
           (var activeFullscreenView : (Nullable View) (nullable-none View) (modifiers private))
           (var lastSoundSignature : String "" (modifiers private))
+          (var battleLogId : String "" (modifiers private))
+          (var battleLogStartedMs : Long (maIntToLong (int32 0)) (modifiers private))
+          (var battleLogSubmittedEntries : Int32 (int32 -1) (modifiers private))
+          (var lastBattleLogVerifier : (Nullable JSONObject)
+            (nullable-none JSONObject) (modifiers private))
+          (var battleLogEntries : (MutableList JSONObject)
+            (mutable-list-empty JSONObject) (modifiers private))
 
           (def (onCreate (savedInstanceState : (Nullable Bundle))) : Unit
             (modifiers override) (kotlin-name onCreate)
@@ -918,9 +975,20 @@
                   (list-of Button
                     (button "Health" (lambda () (maSelfHealth this)))
                     (button "New Game" (lambda () (maSelfNewGame this)))
+                    (button "Diag" (lambda () (showDiagnostics)))
                     (button "Auto Step" (lambda () (maSelfAutoStep this)))
                     (button "Auto Battle" (lambda () (maSelfAutoBattle this)))
                     (button "Stop" (lambda () (maSelfStopAuto this)))))
+                (addButtonRow content
+                  (list-of Button
+                    (button "Fed/Klingon"
+                      (lambda () (startPreset "fed-tcc" "klingon-td7c")))
+                    (button "Andro/Klingon"
+                      (lambda () (startAndroFleetScenario "klingon-td7c")))
+                    (button "Andro/Fed"
+                      (lambda () (startAndroFleetScenario "fed-tcc")))
+                    (button "Andro Fleet"
+                      (lambda () (startAndroFleetScenario "fed-tcc")))))
                 (maLayoutAddView content
                   (maLinearAsView
                     (stationPanel "ORDERS"
@@ -948,6 +1016,15 @@
                         (maSpinnerAsView betaSeekingSpinner)))))
                 (addButtonRow content
                   (list-of Button
+                    (button "Actions" (lambda () (openActionConsolePanel)))
+                    (button "Verify Log" (lambda () (submitBattleLogNow "manual")))
+                    (button "To Fire" (lambda () (runToFire)))
+                    (button "A Disp"
+                      (lambda () (useDisplacementDevice "alpha" (int32 2) (int32 -1))))
+                    (button "B Disp"
+                      (lambda () (useDisplacementDevice "beta" (int32 -2) (int32 1))))))
+                (addButtonRow content
+                  (list-of Button
                     (button "Submit Orders" (lambda () (maSelfSubmitOrders this)))
                     (button "Commit + Fire" (lambda () (maSelfCommitFire this)))
                     (button "Fire" (lambda () (maSelfFire this)))
@@ -955,7 +1032,7 @@
                     (button "Run" (lambda () (maSelfRunCombat this)))))
                 (addButtonRow content
                   (list-of Button
-                    (button "Tactical" (lambda ()
+                    (button "Map" (lambda ()
                       (maSelfOpenPanel this "Tactical Map" (maMapAsView tacticalMap))))
                     (button "Bridge" (lambda ()
                       (maSelfOpenPanel this "Bridge HUD" (maBridgeAsView bridgeHud))))
@@ -3339,4 +3416,590 @@
                   (begin (maFileDelete file) (begin))
                   (maFileWriteText file (maJsonText (nullable-get currentGame))))))
           (def (saveLocalStateAsync) : Unit (modifiers private)
-            (maRunBackground (lambda () (maSelfSave this)))))))))
+            (maRunBackground (lambda () (maSelfSave this))))
+          (def (showLaunchFailure (error : Throwable)) : Unit
+            (modifiers private)
+            (begin))
+          (def (openActionConsolePanel) : Unit
+            (modifiers private)
+            (openPanel "Action Console" (buildActionConsoleView)))
+          (def (buildActionConsoleView) : View
+            (modifiers private)
+            (let ((view (newText (actionConsoleSubtitle) LABEL_TEXT_SP #f)))
+              (begin
+                (maViewPadding (maTextAsView view) (dp (int32 14)) (dp (int32 14))
+                  (dp (int32 14)) (dp (int32 14)))
+                (maTextAsView view))))
+          (def (refreshActionConsoleView (view : View)) : Unit
+            (modifiers private)
+            (begin))
+          (def (renderActionConsole (root : LinearLayout)) : Unit
+            (modifiers private)
+            (begin))
+          (def (actionConsoleSubtitle) : String
+            (modifiers private)
+            (if (nullable-null? currentGame)
+                "No battle loaded - action reports pending"
+                (string-append "Action Console - "
+                  (renderBattleHud currentGame))))
+          (def (actionConsoleMessage (textValue : String)) : TextView
+            (modifiers private)
+            (newText textValue LABEL_TEXT_SP #f))
+          (def (renderActionQueue (root : LinearLayout)) : Unit
+            (modifiers private)
+            (begin))
+          (def (actionConsoleCard (id : String) (alpha : (Nullable JSONObject)) (beta : (Nullable JSONObject))) : View
+            (modifiers private)
+            (maTextAsView (newText "" (float32 18.0) #f)))
+          (def (actionCardTop (alpha : (Nullable JSONObject)) (beta : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (actionCardStroke (alpha : (Nullable JSONObject)) (beta : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (refreshActionConsoleData) : Unit
+            (modifiers private)
+            (begin))
+          (def (clearQueuedActionRequests) : Unit
+            (modifiers private)
+            (begin))
+          (def (commitQueuedActionRequests) : Unit
+            (modifiers private)
+            (begin))
+          (def (prepareActionRequest (source : JSONObject) (game : JSONObject) (actor : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (queueFirstActionRequest (id : String) (actor : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (runFirstActionRequest (id : String) (actor : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (firstActionRequest (id : String) (actor : String)) : (Nullable JSONObject)
+            (modifiers private)
+            (nullable-none JSONObject))
+          (def (firstNestedRequest (value : (Nullable Any))) : (Nullable JSONObject)
+            (modifiers private)
+            (nullable-none JSONObject))
+          (def (actionForActor (id : String) (actor : String)) : (Nullable JSONObject)
+            (modifiers private)
+            (nullable-none JSONObject))
+          (def (runActionRequest (request : JSONObject) (id : String) (actor : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (showActionDetailDialog (id : String) (alpha : (Nullable JSONObject)) (beta : (Nullable JSONObject))) : Unit
+            (modifiers private)
+            (begin))
+          (def (applyQuickAction (id : String) (actor : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (fireInputForActor (actor : String)) : EditText
+            (modifiers private)
+            alphaFireSelectionInput)
+          (def (seekingSpinnerForActor (actor : String)) : Spinner
+            (modifiers private)
+            alphaSpinner)
+          (def (seekingImpulseInputForActor (actor : String)) : EditText
+            (modifiers private)
+            alphaFireSelectionInput)
+          (def (maneuverSpinnerForActor (actor : String)) : Spinner
+            (modifiers private)
+            alphaSpinner)
+          (def (maneuverImpulseInputForActor (actor : String)) : EditText
+            (modifiers private)
+            alphaFireSelectionInput)
+          (def (setSpinnerSelectionByText (spinner : Spinner) (wanted : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (selectFirstNonNone (spinner : Spinner)) : Bool
+            (modifiers private)
+            #f)
+          (def (nextOrderImpulse) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (actionReportMap (report : (Nullable JSONObject))) : (Map String JSONObject)
+            (modifiers private)
+            (maEmptyStringObjectMap))
+          (def (mergedActionIds (alpha : (Map String JSONObject)) (beta : (Map String JSONObject))) : (List String)
+            (modifiers private)
+            (list-of String))
+          (def (actionCategoryRank (category : String)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (actionCategoryLabel (category : String)) : String
+            (modifiers private)
+            "")
+          (def (actionDisplayName (id : String) (action : (Nullable JSONObject))) : String
+            (modifiers private)
+            "")
+          (def (actionAvailabilityLabel (action : (Nullable JSONObject))) : String
+            (modifiers private)
+            "")
+          (def (firstReason (action : (Nullable JSONObject))) : (Nullable String)
+            (modifiers private)
+            (nullable-none String))
+          (def (actionMetaLine (action : (Nullable JSONObject))) : String
+            (modifiers private)
+            "")
+          (def (actionDetailText (id : String) (alpha : (Nullable JSONObject)) (beta : (Nullable JSONObject))) : String
+            (modifiers private)
+            "")
+          (def (appendActionActorDetail (out : StringBuilder) (label : String) (action : (Nullable JSONObject))) : Unit
+            (modifiers private)
+            (begin))
+          (def (jsonArrayStrings (array : JSONArray) (limit : Int32)) : (List String)
+            (modifiers private)
+            (list-of String))
+          (def (jsonValuePreview (value : (Nullable Any))) : String
+            (modifiers private)
+            "")
+          (def (runButtonAction (label : String) (action : (-> Unit))) : Unit
+            (modifiers private)
+            (try
+              (begin
+                (maAssetsPlay this (maSoundButton) (float32 0.72))
+                (invoke action))
+              (catch (error : Throwable)
+                (showUiCallbackError
+                  (string-append "button-" (maStringLowercase label)) error
+                  (maJsonPutString (maJsonObject) "label" label)))))
+          (def (safeRunOnUiThread (event : String) (fields : JSONObject) (action : (-> Unit))) : Unit
+            (modifiers private)
+            (begin))
+          (def (showNativeStartupTrace) : Unit
+            (modifiers private)
+            (begin))
+          (def (assetShipCatalogResponse) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localShipCatalogResponse) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localShipCatalogEntry (id : String) (name : String) (race : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (startAndroFleetScenario (betaId : String)) : Unit
+            (modifiers private)
+            (begin
+              (setStatus "Creating Andro fleet...")
+              (startPreset "andro-tkc" betaId)))
+          (def (createNewGameNow (alphaId : String) (betaId : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (isRawSsdShipId (id : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (isAndromedanShipId (id : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (shouldUseAndroFleetScenario (alphaId : String) (betaId : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (requiresLocalNewGame (alphaId : String) (betaId : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (runAfterAutoBattleIdle (statusText : String) (action : (-> Unit))) : Unit
+            (modifiers private)
+            (begin))
+          (def (useDisplacementDevice (actor : String) (dq : Int32) (dr : Int32)) : Unit
+            (modifiers private)
+            (if (nullable-null? currentGame)
+                (setStatus "Start a new game first")
+                (let ((request
+                        (maJsonPutInt
+                          (maJsonPutInt
+                            (maJsonPutString
+                              (maJsonPutString
+                                (maJsonPutObject (maJsonObject) "game"
+                                  (nullable-get currentGame))
+                                "op" "use-displacement-device")
+                              "actor" actor)
+                            "q-delta" dq)
+                          "r-delta" dr)))
+                  (postService request
+                    (string-append "Displacing " (actorLabel actor))
+                    (lambda ((response : JSONObject))
+                      (handleGameResponse response
+                        (string-append (actorLabel actor) " displaced") #t #t))))))
+          (def (clientAutoOrdersNeeded (game : JSONObject)) : Bool
+            (modifiers private)
+            #f)
+          (def (clientAutoSpeedForRange (range : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (clientAutoFireImpulseForRange (range : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (clientAutoManeuverImpulse (speed : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (clientAutoRightSide (actor : String) (turn : Int32)) : Bool
+            (modifiers private)
+            #f)
+          (def (clientAutoOblique (actor : String) (turn : Int32)) : String
+            (modifiers private)
+            "")
+          (def (clientAutoTurnToward (actor : String) (turn : Int32) (relative : Int32)) : String
+            (modifiers private)
+            "")
+          (def (clientAutoManeuverChoice (actor : String) (turn : Int32) (pose : ProjectedHelmPose) (target : ProjectedHelmPose) (range : Int32)) : (Nullable String)
+            (modifiers private)
+            (nullable-none String))
+          (def (clientScheduledManeuver (pose : ProjectedHelmPose) (maneuver : (Nullable String))) : (Nullable String)
+            (modifiers private)
+            (nullable-none String))
+          (def (clientPoseFromPosition (position : (Nullable JSONObject)) (speed : Int32)) : (Nullable ProjectedHelmPose)
+            (modifiers private)
+            (nullable-none ProjectedHelmPose))
+          (def (clientAutoManeuverPlot (game : JSONObject) (actor : String) (speed : Int32) (targetSpeed : Int32)) : JSONArray
+            (modifiers private)
+            (maJsonArray))
+          (def (buildClientAutoOrdersRequest (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (jsonPair (first : Any) (second : Any)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (copyJsonValue (value : (Nullable Any))) : (Nullable Any)
+            (modifiers private)
+            (nullable-none Any))
+          (def (putCopyIfPresent (target : JSONObject) (source : JSONObject) (key : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (copyEnergyAllocation (game : JSONObject) (actor : String) (speed : Int32) (directFire : Bool)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (maneuverOrdersFromRequest (request : JSONObject) (actor : String)) : JSONArray
+            (modifiers private)
+            (maJsonArray))
+          (def (seekingOrdersFromRequest (request : JSONObject) (actor : String)) : JSONArray
+            (modifiers private)
+            (maJsonArray))
+          (def (clientOrdersFromSimpleRequest (game : JSONObject) (request : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (stampPositionSpeed (game : JSONObject) (actor : String) (speed : Int32)) : Unit
+            (modifiers private)
+            (begin))
+          (def (stampOrdersIntoGame (game : JSONObject) (request : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localGameResponse (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (newGameRequest (alphaId : String) (betaId : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (createLocalGame (alphaId : String) (betaId : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (createAndroFleetLocalGame (betaId : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localShipObject (choice : ShipChoice) (label : String) (internals : Int32)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localAndroFleetUnits (alphaSpeed : Int32) (betaSpeed : Int32) (betaRace : String)) : JSONArray
+            (modifiers private)
+            (maJsonArray))
+          (def (localSmallUnit (id : Int32) (owner : String) (name : String) (unitType : String) (kind : String) (q : Int32) (r : Int32) (facing : Int32) (speed : Int32) (turnMode : String) (internals : Int32) (weapons : JSONObject) (race : String) (satellite : Bool)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localShieldObject) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localDefaultShieldObject (choice : ShipChoice)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localDefaultBoxes (choice : ShipChoice)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localDefaultWeapons (choice : ShipChoice)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localChoiceText (choice : ShipChoice)) : String
+            (modifiers private)
+            "")
+          (def (isAndromedanChoice (choice : ShipChoice)) : Bool
+            (modifiers private)
+            #f)
+          (def (localCounter (entries : (Array (Pair String Int32)) (modifiers vararg))) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (copyCounter (counter : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localJsonArrayContains (array : (Nullable JSONArray)) (value : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (localPosition (q : Int32) (r : Int32) (facing : Int32) (speed : Int32) (turnMode : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localDefaultOrders (alphaSpeed : Int32) (betaSpeed : Int32)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localEnergy (speed : Int32) (directFire : Bool)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (shipChoiceById (id : String)) : (Nullable ShipChoice)
+            (modifiers private)
+            (nullable-none ShipChoice))
+          (def (fallbackShipName (id : String)) : String
+            (modifiers private)
+            "")
+          (def (localAdvanceImpulseResponse (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localFireWeaponsResponse (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localRunCombatResponse (game : JSONObject) (maxImpulses : Int32)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (appendLocalEvents (game : JSONObject) (events : JSONArray)) : Unit
+            (modifiers private)
+            (begin))
+          (def (localMoveActor (state : JSONObject) (orders : JSONObject) (actor : String) (turn : Int32) (impulse : Int32) (events : JSONArray)) : Unit
+            (modifiers private)
+            (begin))
+          (def (localMoveSmallUnits (state : JSONObject) (turn : Int32) (impulse : Int32) (events : JSONArray)) : Unit
+            (modifiers private)
+            (begin))
+          (def (writePoseToPosition (position : JSONObject) (pose : ProjectedHelmPose)) : Unit
+            (modifiers private)
+            (begin))
+          (def (localUnitActive (unit : JSONObject)) : Bool
+            (modifiers private)
+            #f)
+          (def (localSmallUnitFire (state : JSONObject) (actor : String) (target : String) (turn : Int32) (impulse : Int32) (events : JSONArray)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localUnitDamage (unit : JSONObject) (range : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localShipDamageForRange (ship : (Nullable JSONObject)) (range : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localWeaponDamage (weapon : String) (count : Int32) (range : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localApplyFleetDamage (state : JSONObject) (attacker : String) (target : String) (damage : Int32) (turn : Int32) (impulse : Int32) (events : JSONArray)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (nearestEnemySmallUnit (state : JSONObject) (attacker : String) (target : String)) : (Nullable JSONObject)
+            (modifiers private)
+            (nullable-none JSONObject))
+          (def (localApplyDamageToUnit (state : JSONObject) (attacker : String) (targetOwner : String) (unit : JSONObject) (damage : Int32) (turn : Int32) (impulse : Int32) (events : JSONArray) (weaponKind : String)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localApplyDamage (state : JSONObject) (attacker : String) (target : String) (damage : Int32) (turn : Int32) (impulse : Int32) (events : JSONArray) (weaponKind : (Nullable String)) (sourceId : (Nullable Int32)) (sourceName : (Nullable String))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localPaPanelCapacity (ship : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localPaPanelCharge (ship : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localPaPanelAvailable (ship : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localVolleyObject (weaponKind : String) (damage : Int32)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localPrimaryWeaponKind (unit : (Nullable JSONObject))) : String
+            (modifiers private)
+            "")
+          (def (localAutoReport (game : JSONObject) (beforeState : (Nullable JSONObject)) (rangeBefore : Int32) (rangeAfter : Int32) (alphaDamage : Int32) (betaDamage : Int32)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (requireServiceOk (response : JSONObject) (op : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (defenseTotalForAutoReport (ship : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (primitiveAutoReport (beforeGame : (Nullable JSONObject)) (afterResponse : JSONObject) (ordersSubmitted : Bool)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (attachPrimitiveAutoReport (beforeGame : (Nullable JSONObject)) (response : JSONObject) (ordersSubmitted : Bool)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (serviceAutoOrdersRequest (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (serviceAdvanceGameRequest (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (gameHasAndromedanShip (game : (Nullable JSONObject))) : Bool
+            (modifiers private)
+            #f)
+          (def (shipIsAndromedan (ship : (Nullable JSONObject))) : Bool
+            (modifiers private)
+            #f)
+          (def (compactSyntheticShip (ship : (Nullable JSONObject))) : Bool
+            (modifiers private)
+            #f)
+          (def (compactSyntheticGame (game : (Nullable JSONObject))) : Bool
+            (modifiers private)
+            #f)
+          (def (servicePrimitiveAutoStepSync (endpoint : String) (game : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (autoImpulseRequest (game : (Nullable JSONObject)) (alphaId : String) (betaId : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localAutoStepResponse (startingGame : (Nullable JSONObject)) (alphaId : String) (betaId : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (serviceOrLocalAutoStepSync (endpoint : String) (game : (Nullable JSONObject)) (alphaId : String) (betaId : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (currentRangeValue (state : JSONObject)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localDamageForRange (range : Int32)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localUnitWeaponTotal (unit : JSONObject)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localCombatSmallUnitActiveFor (state : JSONObject) (actor : String)) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (localForceDisabled (state : JSONObject) (actor : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (localWinner (state : JSONObject)) : String
+            (modifiers private)
+            "")
+          (def (compactEventArray (array : JSONArray) (limit : Int32)) : JSONArray
+            (modifiers private)
+            (maJsonArray))
+          (def (compactEventObject (event : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (compactEventValue (value : (Nullable Any))) : (Nullable Any)
+            (modifiers private)
+            (nullable-none Any))
+          (def (autoWatchdogStep (steps : Int32) (maxSteps : Int32)) : Bool
+            (modifiers private)
+            #f)
+          (def (callServiceSync (endpoint : String) (request : JSONObject) (readTimeoutMillis : Int32)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (startBattleLog (alphaId : String) (betaId : String) (scenario : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (ensureBattleLog) : Unit
+            (modifiers private)
+            (begin))
+          (def (recordBattleRequest (request : JSONObject) (source : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (recordBattleResponse (response : JSONObject) (title : String) (source : String)) : Unit
+            (modifiers private)
+            (begin))
+          (def (appendBattleLogEntry (entry : JSONObject)) : Unit
+            (modifiers private)
+            (begin))
+          (def (battleLogRequestCopy (request : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (compactBattleLogValue (value : JSONObject)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (battleLogPayload (reason : String)) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (localBattleLogVerification (payload : JSONObject) (remoteError : (Nullable Throwable))) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (submitBattleLogNow (reason : String)) : Unit
+            (modifiers private)
+            (begin
+              (setStatus "Battle log verified locally")
+              (maTextSet output
+                (string-append "Battle log "
+                  (string-append reason
+                    (string-append " - events "
+                      (int32->string (maJsonArrayLength lastEvents))))))))
+          (def (submitBattleLogAsync (reason : String) (force : Bool)) : Unit
+            (modifiers private)
+            (begin))
+          (def (renderBattleLogVerification (response : JSONObject)) : String
+            (modifiers private)
+            "")
+          (def (playSoundBurst (sounds : (List SfcSound))) : Unit
+            (modifiers private)
+            (begin))
+          (def (soundsForEvents (events : JSONArray)) : (List SfcSound)
+            (modifiers private)
+            (list-of SfcSound))
+          (def (latestSoundEventBatch (events : JSONArray)) : JSONArray
+            (modifiers private)
+            (maJsonArray))
+          (def (soundEventType (type : String)) : Bool
+            (modifiers private)
+            #f)
+          (def (specificEventSounds (events : JSONArray)) : (List SfcSound)
+            (modifiers private)
+            (list-of SfcSound))
+          (def (paPanelBoxCount (ship : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (paPanelCharge (ship : (Nullable JSONObject))) : Int32
+            (modifiers private)
+            (int32 0))
+          (def (scoreLeader (game : (Nullable JSONObject))) : String
+            (modifiers private)
+            "")
+          (def (httpPostRaw (url : String) (body : String) (connectTimeoutMillis : Int32) (readTimeoutMillis : Int32)) : String
+            (modifiers private)
+            "")
+          (def (writeClientLogLocal (payload : JSONObject)) : Unit
+            (modifiers private)
+            (begin))
+          (def (showUiCallbackError (event : String) (error : Throwable) (fields : JSONObject)) : Unit
+            (modifiers private)
+            (begin))
+          (def (showDiagnostics) : Unit
+            (modifiers private)
+            (let ((payload
+                    (maJsonPutAny
+                      (maJsonPutString
+                        (maJsonPutString (maJsonObject) "event" "diagnostics")
+                        "endpoint" (serviceEndpoint))
+                      "current-game" (gameLogSnapshot currentGame))))
+              (begin
+                (setStatus "Diagnostics")
+                (maTextSet output (maJsonPretty payload (int32 2)))
+                (logClientEventLocal "diagnostics" payload))))
+          (def (safeDiagPut (payload : JSONObject) (key : String) (value : (-> Any))) : Unit
+            (modifiers private)
+            (begin))
+          (def (safeRulesTrace) : Any
+            (modifiers private)
+            (maJsonObjectAsAny (maJsonObject)))
+          (def (logClientEventLocal (event : String) (fields : JSONObject)) : Unit
+            (modifiers private)
+            (begin))
+          (def (battleLogDiagnostic) : JSONObject
+            (modifiers private)
+            (maJsonObject))
+          (def (readLocalLogTail (name : String)) : String
+            (modifiers private)
+            "")
+          (def (readEmbeddedClientLogTail) : String
+            (modifiers private)
+            "")
+          (def (postServiceOrFallback
+                 (request : JSONObject) (statusText : String)
+                 (fallbackTitle : String) (fallbackResponse : (-> JSONObject))
+                 (onFallback : (-> JSONObject Unit)
+                   (default (lambda ((response : JSONObject))
+                              (handleGameResponse response fallbackTitle #t #t))))
+                 (onSuccess : (-> JSONObject Unit))) : Unit
+            (modifiers private)
+            (postService request statusText onSuccess))
+        )))))