Files
WT-Offline/patches/gui/battle/pass-spawn-modifications-blk/replace.nut
T
N0VAN0M4LY 647eff35fe fix(battle): unblock LocalMP backup respawns and normalize unit names
Store the selected LocalMP backup token in a separate wtoLastBackup handler field instead of mutating requestData.wtoBackup. Mutating requestData caused respawn.nut checkReady() u.isEqual(lastRequestData, getSelectedRequestData()) to always evaluate false for backup spawns, preventing doRespawnPlayer() from ever running.

Also fix downstream ground and naval backup accounting where native UnitInfo::name carries folder prefixes (e.g. tankModels/cn_type_59) that mismatched bare unit IDs in session.spareSlots, by stripping path prefixes in local_mp_awards.c, record-local-battle-awards, battle-spares.ts, and battle-queue-requests.ts. Update hook_is_slot_ready_at_host to check USED_SPARES_MASK rather than BROKEN_SLOTS_MASK so unrepaired slots remain eligible for a backup spawn.

Verified root and launcher typecheck, 2.61.0.37 and 2.61.0.58 check-gui (50 patches / 37 .nut), check-patches (14/14), checkPatchSet, battle-spares runnable check, and MSVC temp build of wto_ws.dll (0 warnings in project C sources). Pending regular-terminal build of build/native/wto_ws.dll and in-game acceptance.
2026-12-04 23:56:13 +08:00

153 lines
6.2 KiB
Plaintext

function sendWtoAircraftAndWeaponRequest(requestData, isSilent = false) {
let wtoNdb = require("nestdb")
if (!wtoNdb.ndbExists(["wto", "activeBattle"])) {
this.wtoLastBackup = null
return requestAircraftAndWeaponWithSpare(requestData, requestData.idInCountry,
requestData.respBaseId, requestData.spareUid)
}
let wtoBattle = wtoNdb.ndbTryRead(["wto", "activeBattle"])
let wtoGuiRespawn = require("guiRespawn")
let wtoChardRes = require("chardResearch")
let wtoUnitName = requestData?.name ?? ""
local wtoExtraSlot = null
foreach (slot in (wtoBattle?.extraBattleSlots ?? [])) {
if (slot?.unitName == wtoUnitName) {
wtoExtraSlot = slot
break
}
}
if ((wtoExtraSlot?.forceWeapon ?? "") != "")
requestData.weapon = wtoExtraSlot.forceWeapon
let wtoSlotMods = wtoExtraSlot?.modifications ?? []
let wtoUnit = getAircraftByName(wtoUnitName) ?? this.getCurSlotUnit()
let wtoGlobalModsBlk = require("blkGetters").get_modifications_blk()?.modifications
let wtoUnitModsBlk = wtoUnitName != ""
? require("%scripts/unit/unitParams.nut").getFullUnitBlk(wtoUnitName)?.modifications
: null
// Only the bulletMod belts chosen in this spawn request may enter enabledMods; sending every
// unlocked belt lets the last belt in wpcost.blk (usually stealth) overwrite single-belt guns.
let wtoSelectedBullets = {}
for (local wtoBi = 0; wtoBi < BULLETS_SETS_QUANTITY; wtoBi++) {
let wtoBulName = requestData?[$"bullets{wtoBi}"] ?? ""
if (wtoBulName != "")
wtoSelectedBullets[wtoBulName] <- true
}
let wtoModNames = []
let wtoSeenMods = {}
foreach (wtoMod in (wtoUnit?.getModifications() ?? [])) {
let wtoName = wtoMod?.name ?? ""
if (wtoName != "" && !(wtoName in wtoSeenMods)) {
wtoSeenMods[wtoName] <- true
wtoModNames.append(wtoName)
}
}
if (wtoUnitModsBlk != null) {
for (local wtoMi = 0; wtoMi < wtoUnitModsBlk.blockCount(); wtoMi++) {
let wtoName = wtoUnitModsBlk.getBlock(wtoMi).getBlockName()
if (wtoName != "" && !(wtoName in wtoSeenMods)) {
wtoSeenMods[wtoName] <- true
wtoModNames.append(wtoName)
}
}
}
let wtoEnabledMods = []
let wtoDisabledMods = []
foreach (wtoModName in wtoModNames) {
let wtoIsEnabled = wtoExtraSlot == null
? wtoChardRes.shopIsModificationEnabled(wtoUnitName, wtoModName)
: (wtoExtraSlot?.allModifications == true || wtoSlotMods.contains(wtoModName))
let wtoGlobalModBlk = wtoGlobalModsBlk?.getBlockByName(wtoModName)
let wtoUnitModBlk = wtoUnitModsBlk?.getBlockByName(wtoModName)
let wtoHasBulletMod = (wtoUnitModBlk?.getBlockByName("effects")?.paramExists("bulletMod") ?? false)
|| (wtoGlobalModBlk?.getBlockByName("effects")?.paramExists("bulletMod") ?? false)
if (wtoHasBulletMod) {
if (wtoIsEnabled && (wtoModName in wtoSelectedBullets))
wtoEnabledMods.append(wtoModName)
continue
}
// Match UnitModifications::initFromSave / initFromLists: invertEnableLogic mods encode stock
// penalties in effects{} and must move to disabledMods once enabled; normal unequipped mods
// only enter disabledMods when they define disableModEffects{}.
local wtoInvert = wtoGlobalModBlk?.getBool("invertEnableLogic", false) ?? false
if (wtoUnitModBlk != null)
wtoInvert = wtoUnitModBlk.getBool("invertEnableLogic", wtoInvert)
let wtoHasDisableEffects = wtoUnitModBlk?.getBlockByName("disableModEffects") != null
|| wtoGlobalModBlk?.getBlockByName("disableModEffects") != null
if (wtoInvert) {
if (wtoIsEnabled)
wtoDisabledMods.append(wtoModName)
else
wtoEnabledMods.append(wtoModName)
}
else if (wtoIsEnabled)
wtoEnabledMods.append(wtoModName)
else if (wtoHasDisableEffects)
wtoDisabledMods.append(wtoModName)
}
let wtoBlk = DataBlock()
wtoBlk.enabledMods = ";".join(wtoEnabledMods)
wtoBlk.disabledMods = ";".join(wtoDisabledMods)
wtoBlk.isSilentPreview = isSilent ? "1" : "0"
// Keep backup metadata off requestData so checkReady()'s u.isEqual(lastRequestData, getSelectedRequestData()) stays true.
local wtoBackupToken = null
if (!isSilent) {
let source = this.getWtoBackupSourceForRequest(requestData)
let backup = this.getWtoBackupToken(requestData, source)
if (backup == null)
return -1
if (backup != "") {
wtoBackupToken = backup
wtoBlk.wtoBackup = backup
}
if (source == "vehicle") {
this.universalSpareUidForRespawn = ""
requestData.spareUid = ""
}
}
let wtoTaskId = wtoGuiRespawn.requestAircraftAndWeaponWithSlots(requestData, requestData.idInCountry,
requestData.respBaseId, requestData.spareUid, wtoBlk, DataBlock())
if (wtoTaskId >= 0)
this.wtoLastBackup = wtoBackupToken
return wtoTaskId
}
function requestAircraftAndWeapon(requestData) {
if (this.requestInProgress)
return
set_aircraft_accepted_cb(this, this.aircraftAcceptedCb);
let _taskId = this.sendWtoAircraftAndWeaponRequest(requestData, false)
if (_taskId < 0)
set_aircraft_accepted_cb(null, null);
else {
this.requestInProgress = true
this.showTaskProgressBox(loc("charServer/purchase0"), function() { this.requestInProgress = false })
this.lastRequestData = requestData
}
}
function requestChangeUnitSilent() {
let unit = this.getCurSlotUnit()
if (!unit?.isHuman() || !this.canChangeAircraft || this.isApplyPressed) {
this.isSilentRequestPending = false
return
}
this.isSilentRequestPending = this.requestInProgress || !canRequestAircraftNow()
if (this.isSilentRequestPending)
return
let requestData = this.getSelectedRequestData(true)
if (!requestData)
return
set_aircraft_accepted_cb(this, this.silentAircraftAcceptedCb);
let _taskId = this.sendWtoAircraftAndWeaponRequest(requestData, true)
if (_taskId < 0)
set_aircraft_accepted_cb(null, null);
else {
this.requestInProgress = true
this.lastRequestData = requestData
}
}