Files
WT-Offline/gui-patches/battle/launch-local-battle-from-queue/replace.nut
T
N0VAN0M4LY b1392c0512 Build the local battle mission settings in the local service
The launch script patch used to assemble the whole MissionSettings block
on the client: reading the mission file for localization keys and ticket
rules, filling the AI vehicle pool, rank window and extra slot costs.
All of that is pre-battle data the local service already owns.

- multiplayer-missions dataset v3 keeps the scalar parameters of
  mission_settings.mission and of each per-difficulty sub-block, with
  their BLK types.
- battle-mission-settings.ts builds the complete MissionSettings block
  from the launch plan (same parameters as before).
- battle-launch-notify.ts sends it as a typed tree, so ints and reals
  keep the types the engine reads, plus the lobby settings and the
  per-battle record the in-battle patches read from nestdb.
- The launch patch shrinks from 208 to about 70 lines: rebuild the
  DataBlock, set _gameMode from the client's own native constant, enter
  the session lobby and start the LocalMP battle.

Behaviour is unchanged; coalitions, extra slots and economy are reworked
in later commits. Verified: npm run typecheck, check-gui (33 patches).
2026-11-28 03:39:53 +08:00

74 lines
3.0 KiB
Plaintext

matchingApiFunc("match.enqueue", cb, params)
}
// WTOffline: rebuild a DataBlock sent by the local service as { p = [[name, type, value]], b = [[name, node]] }.
// The type ("t", "i", "r", "b") travels with each value because the engine reads ints and reals with typed getters.
function wtoBlkFromWire(blk, node) {
foreach (param in (node?.p ?? [])) {
let [name, kind, value] = param
blk[name] <- kind == "i" ? value.tointeger()
: kind == "r" ? value.tofloat()
: kind == "b" ? value == true
: value.tostring()
}
foreach (child in (node?.b ?? []))
wtoBlkFromWire(blk.addNewBlock(child[0]), child[1])
return blk
}
// WTOffline: start a local battle pushed by the local service (mrpc.generic_notify, from = "wto_battle").
// The service sends the complete mission settings; the client hosts the battle as a LocalMP session.
function onWtoBattleNotify(ev) {
if (ev?.func != "launch" || isInFlight())
return
let DataBlock = require("DataBlock")
let { ndbWrite } = require("nestdb")
let guiMis = require("guiMission")
let { set_game_mode } = require("mission")
let { GM_DOMINATION } = require("%globalScripts/gameModeNativeConsts.nut")
let { reset_cur_mission_mode } = require("%appGlobals/ranks_common_shared.nut")
let { notifyQueueLeave } = require("%scripts/queue/queueManager.nut")
let destroySessionScripted = require("%scripts/matchingRooms/destroySessionScripted.nut")
let { invalidateCrewsList } = require("%scripts/slotbar/crewsList.nut")
let { guiStartFlight } = require("%scripts/missions/startMissionsList.nut")
let { currentCampaignMission } = require("%scripts/missions/missionsStates.nut")
let lobbyStates = require("%scripts/matchingRooms/lobbyStates.nut")
let { setSessionLobbySettings, switchSessionLobbyStatus } = require("%scripts/matchingRooms/sessionLobbyManager.nut")
notifyQueueLeave({})
destroySessionScripted("on start wto local battle")
ndbWrite(["wto", "activeBattle"], ev.battle)
invalidateCrewsList(true)
let misBlk = wtoBlkFromWire(DataBlock(), ev.mission)
misBlk._gameMode = GM_DOMINATION
let lobby = ev.lobby
lobby.mission._gameMode <- GM_DOMINATION
currentCampaignMission.set(misBlk.name)
set_game_mode(GM_DOMINATION)
setSessionLobbySettings(lobby, true, false)
switchSessionLobbyStatus(lobbyStates.IN_SESSION)
reset_cur_mission_mode()
guiMis.select_training_mission(misBlk)
reset_cur_mission_mode()
guiStartFlight()
}
// WTOffline: forget the battle record when the session ends outside a battle (left before loading).
require("%sqStdLibs/helpers/subscriptions.nut").addListenersWithoutEnv({
SessionDestroyed = function(_p) {
if (!isInFlight()) {
let { ndbExists, ndbDelete } = require("nestdb")
if (ndbExists(["wto", "activeBattle"])) {
ndbDelete(["wto", "activeBattle"])
require("%scripts/slotbar/crewsList.nut").invalidateCrewsList(true)
}
}
}
})
require("%scripts/matching/serviceNotifications/mrpc.nut").mnSubscribe("wto_battle", onWtoBattleNotify)
matchingRpcSubscribe("match.notify_clusters_changed", onClustersChanged)