fix(battle): show and debit confirmed backup vehicles

Use the signed i64 profile encoding identified in PR #13. Make attached backups selectable in LocalMP after the daily quota, and debit backups only after the engine confirms the selected slot entered play.

Record the stock daily allowance once per room and slot. Settle owned backups using the confirmed spawn facts and keep repeat settlement from charging the same battle again.

Verified server and launcher types, MSVC compilation, three client builds for patch and Quirrel checks, and a temporary 2.61.0.58 build. In-game acceptance is pending.

Co-authored-by: duduyagame <[email protected]>
This commit is contained in:
N0VAN0M4LYandduduyagame committed 2026-12-04 06:24:34 +08:00
1 parent 6d0abf9caf
commit 3282320fb7
34 files changed
+402 -46

No files matched your search

+5 -2
View File
@@ -11,15 +11,18 @@
import { setParam, type BlkBlock } from '@wto/blk';
import type { Account } from '../accounts/account-store.ts';
import { appearance, DEFAULT_PILOT_ICON } from './profile-appearance.ts';
import { DAILY_SPARES_BLOCK } from './profile-daily-spares.ts';
import { clearStoreCart } from './profile-store-cart.ts';
import { clientHangarSpares } from './profile-vehicle-state.ts';
import { serverTimeNow } from './server-time.ts';
export function clientProfile(saved: BlkBlock, account: Account): BlkBlock {
// Shallow-copy only the top-level lists; child blocks are never mutated here.
// Clone the hangar entries whose spare count has a different wire representation.
const profile: BlkBlock = {
name: saved.name,
params: [...saved.params],
blocks: [...saved.blocks],
blocks: saved.blocks.filter((block) => block.name !== DAILY_SPARES_BLOCK)
.map((block) => block.name === 'hangar' ? clientHangarSpares(block) : block),
};
clearStoreCart(profile);
const pilotIcon = appearance(profile).pilotIcon || DEFAULT_PILOT_ICON;
@@ -0,0 +1,33 @@
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
export const DAILY_SPARES_BLOCK = 'wtoDailySpares';
// Stock quota from the Spearhead release notes and aces.exe 2.61.0.58 at 0x967a8d.
const FREE_SPARES_PER_DAY = 5;
const DAY_SECONDS = 24 * 60 * 60;
function utcDay(seconds: number): string {
return String(Math.floor(seconds / DAY_SECONDS));
}
function dayOf(profile: BlkBlock, startedAtSec: number): BlkBlock | undefined {
const ledger = findBlock(profile, DAILY_SPARES_BLOCK);
return ledger && findBlock(ledger, utcDay(startedAtSec));
}
export function dailySparesLeft(profile: BlkBlock, startedAtSec: number): number {
return Math.max(0, FREE_SPARES_PER_DAY - (dayOf(profile, startedAtSec)?.params.length ?? 0));
}
export function usedDailySpare(profile: BlkBlock, startedAtSec: number, key: string): boolean {
const day = dayOf(profile, startedAtSec);
return day !== undefined && findParam(day, key) !== undefined;
}
/** One receipt per room and crew slot, shared by the live and settlement writes. */
export function recordDailySpare(profile: BlkBlock, startedAtSec: number, key: string): boolean {
if (usedDailySpare(profile, startedAtSec, key) || dailySparesLeft(profile, startedAtSec) === 0) return false;
const day = ensureBlock(ensureBlock(profile, DAILY_SPARES_BLOCK), utcDay(startedAtSec));
setParam(day, key, { type: 'bool', value: true });
return true;
}
@@ -5,7 +5,7 @@
* investMode:t the modification being researched, empty = none (AircraftInfo+0x100)
* investModePrev:t the modification whose research just finished (+0x108)
* tierNumber:i the highest open modification tier (script is_tier_available)
* spareAircraftsCount:i spares the player has for this vehicle
* spareAircraftsCount:i owned spares in the saved profile, encoded as a negative i64 on the wire
* excessExp:i64 banked modification research points (+0x70)
* freeRepairs:i64 free repairs used (0x941cef; shop_get_free_repairs_used at 0x17a4b80)
*/
@@ -55,6 +55,19 @@ export function setSpareCount(profile: BlkBlock, vehicle: string, count: number)
if (entry) setParam(entry, SPARES, { type: 'int', value: count });
}
/** SpareAircraftStat reads i64 and clears positive values. The getter negates the stat
* (aces.exe 2.61.0.58 0x9447bb, 0x94f7ab, 0x17abe70). */
export function clientHangarSpares(hangar: BlkBlock): BlkBlock {
const blocks = hangar.blocks.map((vehicle) => {
const count = findParam(vehicle, SPARES)?.value;
if (count?.type !== 'int') return vehicle;
const clientVehicle = { ...vehicle, params: [...vehicle.params] };
setParam(clientVehicle, SPARES, { type: 'int64', value: -BigInt(count.value) });
return clientVehicle;
});
return { ...hangar, blocks };
}
/** Uses one free repair on an owned vehicle if it still has an allowance. */
export function consumeFreeRepair(profile: BlkBlock, vehicle: string, allowance: number): boolean {
const entry = vehicleEntry(profile, vehicle);