Files
WT-Offline/gui-patches/battle/launch-local-battle-from-queue/replace.nut
T
N0VAN0M4LY db981ab834 refactor(patches)!: migrate definitions to JSONC and script fragments
Patch definitions under exe-patches/ and gui-patches/ move from
patch.json/locate.json to patch.jsonc/locate.jsonc. Each file now holds
only the data needed to apply the patch plus a short English comment
stating what it changes, why the local service cannot provide it, and
what happens without it. Every definition records the game versions it
was verified on (verified_on, required).

GUI patches keep their stock text and replacement in find.nut and
replace.nut next to patch.jsonc instead of escaped JSON strings, so the
script edits are readable, diffable and can carry Quirrel comments.
Matching treats CRLF and LF as the same line break because stock
scripts mix both; only the matched span is rewritten.

Loaders on both sides (packages/build, packages/exepatch, wtotools)
reject unknown keys so analysis text cannot creep back into the data.
JSONC parsing moves into a shared @wto/jsonc package; the build now
parses tuning/store.jsonc instead of scanning it with a regex.

Verified: npm run typecheck; check-patches (10/10 ready on 2.61.0.37);
check-gui (33 patches, 24 scripts compile); the TypeScript and Python
appliers produce identical scripts, byte-identical to the previous
definitions except one stock script with mixed line endings.

The 15 battle patches are migrated mechanically and still carry the
pending-review comment; they are rewritten by the LocalMP review.

BREAKING CHANGE: Patch loaders require JSONC definitions. Migrate patch.json and locate.json and move embedded GUI edits to separate Quirrel files.
2026-11-28 03:24:12 +08:00

209 lines
7.6 KiB
Plaintext

matchingApiFunc("match.enqueue", cb, params)
}
function fillWtoBotEntries(parentBlk, blockName, entries) {
if (entries == null)
return
foreach (entry in entries) {
let b = parentBlk.addNewBlock(blockName)
b.name = entry.name
b.weight = (entry?.weight ?? 1.0).tofloat()
b.country = entry.country
}
}
function copyWtoMissionMetadata(misBlk, missionFile, difficulty) {
if (missionFile == null || missionFile == "")
return
let { blkOptFromPath } = require("%sqstd/datablock.nut")
let rawMis = blkOptFromPath(missionFile)?.mission_settings?.mission
if (rawMis == null)
return
let ruleKeys = [
"scoreLimit", "timeLimit", "killLimit", "deathPenaltyMul",
"ctaCaptureZoneEqualPenaltyMul", "ctaCaptureZonePenaltyMul",
"captureZonePenaltyMul", "scorePerSec",
"ctaInstantDecreaseTicketsWhenNoRespawn",
"randomSpawnTeams", "remapAiTankModels", "useAlternativeMapCoord"
]
foreach (key in [
"locName", "locDesc", "locNameTeamA", "locNameTeamB",
"locDescTeamA", "locDescTeamB", "loc_name", "postfix", "restoreType"
].extend(ruleKeys)) {
let val = rawMis?[key]
if (val != null)
misBlk[key] = val
}
let targetDiff = (difficulty == "simulator" || difficulty == "fullreal") ? "hardcore"
: (difficulty == "historical" ? "realistic" : difficulty)
foreach (sub in (rawMis % "mission")) {
let subDiff = sub?.difficulty
if (subDiff != difficulty && subDiff != targetDiff)
continue
foreach (dKey in ruleKeys) {
let dVal = sub?[dKey]
if (dVal != null)
misBlk[dKey] = dVal
}
}
}
function toWtoPrefixedCountries(list, fallback) {
let src = (list != null && list.len() > 0) ? list : [fallback]
return src.map(@(c) c.indexof("country_") == 0 ? c : $"country_{c}")
}
function buildWtoMissionBlk(ev, gmConsts, guiMis) {
let DataBlock = require("DataBlock")
let misBlk = DataBlock()
let baseBlk = guiMis.get_meta_mission_info_by_gm_and_name(gmConsts.GM_SKIRMISH, ev.missionName)
?? guiMis.get_meta_mission_info_by_name(ev.missionName)
copyWtoMissionMetadata(misBlk, ev?.missionFile, ev.difficulty)
let levelVal = ev?.level ?? baseBlk?.level ?? misBlk?.level
let envVal = ev?.environment ?? baseBlk?.environment ?? misBlk?.environment
let weatherVal = ev?.weather ?? baseBlk?.weather ?? misBlk?.weather
if (levelVal != null)
misBlk.level = levelVal
if (envVal != null)
misBlk.environment = envVal
if (weatherVal != null)
misBlk.weather = weatherVal
misBlk.localMP = true
misBlk._gameMode = gmConsts.GM_DOMINATION
misBlk.name = ev.missionName
misBlk.economicName = ev.economicName
misBlk.mis_file = ev.missionFile
misBlk.chapter = "skirmish"
misBlk.type = ev.missionType
misBlk.difficulty = ev.difficulty
misBlk.country_allies = ev.countryAllies
misBlk.country_axis = ev.countryAxis
misBlk.arcadeCountry = true
misBlk.symmetricTeams = ev?.symmetricTeams ?? false
misBlk.gt_versus = true
misBlk.gt_mp_tickets = true
misBlk.gt_mp_capture = true
misBlk.gt_mp_solo = false
misBlk.gt_use_wp = true
misBlk.gt_use_xp = true
misBlk.gt_use_stats = true
misBlk.gt_use_unlocks = true
misBlk.useSpawnScore = ev?.useSpawnScore ?? false
misBlk.allowSpare = true
misBlk.isLimitedAmmo = true
misBlk.allowUseArtillerySupport = true
misBlk.isBotsAllowed = true
misBlk.useTankBots = ev?.useTankBots ?? false
misBlk.useShipBots = ev?.useShipBots ?? false
misBlk.autoBalance = true
misBlk.maxPlayers = ev.maxPlayers
misBlk.maxBots = ev.maxBots
let extraSlots = ev?.extraBattleSlots ?? []
local persistentBlk = null
foreach (slot in extraSlots) {
let cost = slot?.persistentCost ?? 0
let uName = slot?.unitName ?? ""
if (cost > 0 && uName != "") {
if (persistentBlk == null)
persistentBlk = misBlk.addNewBlock("customSpawnScore").addNewBlock("persistent_costs")
persistentBlk[uName] = cost.tointeger()
}
}
foreach (tag in ["ranks", "forcedRanks"]) {
let rBlk = misBlk.addNewBlock(tag)
rBlk.min = ev.minMrank
rBlk.max = ev.maxMrank
}
let alliesBare = ev?.countriesAllies ?? [ev.countryAllies]
let axisBare = ev?.countriesAxis ?? [ev.countryAxis]
let botsBlk = misBlk.addNewBlock("customBots")
botsBlk.wtoPlayerTeam = $"{ev?.playerTeam ?? 1}"
botsBlk.wtoTeamACountries = ";".join(alliesBare)
botsBlk.wtoTeamBCountries = ";".join(axisBare)
botsBlk.numBotRespawnsInMultiSlot = ev.airBotRespawns
botsBlk.numTankBotRespawnsInMultiSlot = ev.tankBotRespawns
botsBlk.numBotRespawnsInVersus = ev.airBotRespawns
botsBlk.numTankBotRespawnsInVersus = ev.tankBotRespawns
fillWtoBotEntries(botsBlk.addNewBlock("allowedTanks"), "tank", ev?.customBots?.tanks)
fillWtoBotEntries(botsBlk.addNewBlock("allowedAircrafts"), "aircraft", ev?.customBots?.aircrafts)
fillWtoBotEntries(botsBlk.addNewBlock("allowedShips"), "ship", ev?.customBots?.ships)
return misBlk
}
function enterWtoSessionRoom(ev, gmConsts) {
let lobbyStates = require("%scripts/matchingRooms/lobbyStates.nut")
let { setSessionLobbySettings, switchSessionLobbyStatus } = require("%scripts/matchingRooms/sessionLobbyManager.nut")
let alliesCountries = toWtoPrefixedCountries(ev?.countriesAllies, ev.countryAllies)
let axisCountries = toWtoPrefixedCountries(ev?.countriesAxis, ev.countryAxis)
setSessionLobbySettings({
game_mode_id = ev.modeId
game_mode_name = ev.modeName
economicName = ev.economicName
symmetricTeams = ev?.symmetricTeams ?? false
country_allies = alliesCountries
country_axis = axisCountries
mission = {
name = ev.missionName
_gameMode = gmConsts.GM_DOMINATION
difficulty = ev.difficulty
}
}, true, false)
switchSessionLobbyStatus(lobbyStates.IN_SESSION)
}
function onWtoBattleNotify(ev) {
if (ev?.func != "launch" || isInFlight())
return
let { ndbWrite } = require("nestdb")
let guiMis = require("guiMission")
let missionMod = require("mission")
let gmConsts = 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")
notifyQueueLeave({})
destroySessionScripted("on start wto local battle")
ndbWrite(["wto", "activeBattle"], {
sessionId = ev.sessionId
modeName = ev.modeName
economicName = ev.economicName
country = ev.country
missionName = ev.missionName
extraBattleSlots = ev?.extraBattleSlots ?? []
randomUnits = ev?.randomUnits ?? {}
randomUnitsEventName = ev?.randomUnitsEventName ?? ""
})
invalidateCrewsList(true)
let misBlk = buildWtoMissionBlk(ev, gmConsts, guiMis)
currentCampaignMission.set(ev.missionName)
missionMod.set_game_mode(gmConsts.GM_DOMINATION)
enterWtoSessionRoom(ev, gmConsts)
reset_cur_mission_mode()
guiMis.select_training_mission(misBlk)
reset_cur_mission_mode()
guiStartFlight()
}
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)