Award the nuclear strike in LocalMP battles

Online the battle server gives killStreak_bomber_nuclear_success (mode
killStreakNuclearSuccess, 10000 SL) when a player's nuclear bomb
explodes; the LocalMP host has no battle server, so the award was never
given.

The native nuke module now remembers whether the local player launched
the instant-win bomb and, when it explodes, raises the HUD script event
wtoLocalMpNuclearStrike. The battle record keeps it as a strike, sends
it live (wto_battle.fact kind "strike") and reports it after the battle
(strikes{}); the local service awards killStreakNuclearSuccess once per
strike, live as the award banner and in the settlement.

Checked with typecheck, check-gui, check-offsets and the native build;
not yet verified in game.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 19:03:24 +08:00
1 parent 28aa6ec971
commit 6ab941a086
9 files changed
+72 -14

No files matched your search

@@ -151,6 +151,15 @@ function wtoOnHudMessage(msg) {
wtoSendLiveFact("kill", kill)
}
// The local player's nuclear bomb exploded (raised by the native bridge, local_mp_nuke.c).
function wtoOnLocalMpNuclearStrike(_ev) {
if (!require("nestdb").ndbExists(["wto", "activeBattle"]))
return
let strike = { time = require("mission").get_mission_time() }
wtoAppendBattleLog("strikes", strike)
wtoSendLiveFact("strike", strike)
}
// The battle ends for the local player: close the open life and keep the end time, which the
// settlement report needs after the mission has been left (the mission is unloaded before the
// debriefing, so its time and status are gone by then). The first end counts.
@@ -182,6 +191,7 @@ function wtoSubscribeBattleAwards() {
g_hud_event_manager.subscribe("LocalPlayerDead", wtoOnLocalPlayerDead)
g_hud_event_manager.subscribe("HudMessage", wtoOnHudMessage)
g_hud_event_manager.subscribe("MissionResult", wtoOnMissionResult)
g_hud_event_manager.subscribe("wtoLocalMpNuclearStrike", wtoOnLocalMpNuclearStrike)
}
// Leaving the battle from the menu before it has ended.
@@ -55,6 +55,11 @@ function buildWtoBattleReport(wtoBattle, res) {
evBlk.modifier = ev.modifier
evBlk.damage = ev.damage.tointeger()
}
let strikesBlk = blk.addNewBlock("strikes")
foreach (strike in (battleLog?.strikes ?? [])) {
let strikeBlk = strikesBlk.addNewBlock("s")
strikeBlk.time = strike.time.tofloat()
}
let sparesBlk = blk.addNewBlock("spares")
foreach (spUnit, spCnt in (wtoBattle?.usedSpares ?? {}))
if (spUnit != "" && spCnt > 0)
+15
View File
@@ -81,6 +81,21 @@ void local_mp_report_award_event(const LocalMpAwardEvent *ev)
fn_blk_dtor(blk);
}
/* The fact behind the award killStreak_bomber_nuclear_success, which online the battle server
* judges itself; the event carries no fields. */
void local_mp_report_nuclear_strike(void)
{
__declspec(align(16)) uint8_t blk[LMP_BLK_SIZE];
uint8_t *gsd = g_game_save_data ? *g_game_save_data : NULL;
if (gsd == NULL || fn_hud_notify_script == NULL)
return;
memset(blk, 0, sizeof(blk));
fn_blk_ctor(blk);
fn_hud_notify_script(gsd + g_hud_queue_off, LMP_NUCLEAR_STRIKE_EVENT_NAME, blk);
fn_blk_dtor(blk);
}
static void *call_target(uint8_t *score_msg, size_t call_off)
{
return local_mp_resolve_rip(score_msg + call_off, 1, 5);
+3
View File
@@ -12,6 +12,8 @@
/* HUD script event raised for each combat event of the local player (local_mp_awards.c). */
#define LMP_AWARD_EVENT_NAME "wtoLocalMpExpEvent"
/* HUD script event raised when the local player's instant-win bomb explodes (local_mp_nuke.c). */
#define LMP_NUCLEAR_STRIKE_EVENT_NAME "wtoLocalMpNuclearStrike"
typedef char *(__fastcall *LmpGetPlayerCountryFn)(uint8_t *mis, int32_t pid, char *buf, int32_t buf_size);
typedef void (__fastcall *LmpSetPlayerGuiStateFn)(int32_t player_id, int32_t state);
@@ -62,6 +64,7 @@ void local_mp_players_queue_spawn(int32_t slot_id, int32_t spare_type, int is_si
/* Combat event reporting to the GUI scripts (local_mp_awards.c). */
void local_mp_report_award_event(const LocalMpAwardEvent *ev);
void local_mp_report_nuclear_strike(void);
const char *local_mp_unit_exp_class(const uint8_t *unit);
/* Mission scores of combat events from the mission settings (local_mp_scores.c). */
+18 -11
View File
@@ -14,7 +14,9 @@
* 2. Projectile explosion 0xbe7c00: the host's shell update passes the launch record's flag as
* its 8th argument (movzx eax, byte [r15+0x70] at 0x2fd778, call at 0x2fd7c3); with the flag
* set it plays the nuclear explosion (flag 0x7bf4958+0x2be2, camera type 0x17 at 0xbe97e6) and
* nothing else. The remembered team becomes the winner.
* nothing else. The remembered team becomes the winner; a bomb of the local player is also
* reported to the scripts (LMP_NUCLEAR_STRIKE_EVENT_NAME), the fact of the award
* killStreak_bomber_nuclear_success that online the battle server gives.
* 3. Domination logic cta_logic_action (0x11bc400, the mp_update_trig action registered at
* 0x11ba558): before it runs, the loser's mission variable mpTi1 / mpTi2 (tickets of team 1 / 2,
* looked up at 0x11bd1c7) is set to 0. The stock logic then ends the battle as on tickets:
@@ -38,24 +40,22 @@ static ShellLaunchFn orig_shell_launch;
static ShellExplodeFn orig_shell_explode;
static LogicActionFn orig_cta_logic;
/* Team of the last launched instant-win bomb, and the team that won with it (0 = none). */
/* Team of the last launched instant-win bomb and whether the local player launched it, and the
* team that won with it (0 = none). */
static volatile uint8_t g_bomb_team;
static volatile uint8_t g_bomb_is_local;
static volatile uint8_t g_winner_team;
static uint8_t *g_logic_ctx;
static uint8_t owner_team(const uint8_t *unit)
static const uint8_t *owner_mplayer(const uint8_t *unit)
{
const uint8_t *mp;
if (unit == NULL)
return 0;
mp = *(uint8_t *const *)(unit + LMP_UNIT_OFF_MPLAYER);
return mp != NULL ? mp[LMP_MP_OFF_TEAM] : 0;
return unit != NULL ? *(const uint8_t *const *)(unit + LMP_UNIT_OFF_MPLAYER) : NULL;
}
static void __fastcall hook_shell_launch(void **launch, void *a2, uint8_t *owner, void *a4, uint64_t a5, uint64_t a6)
{
const uint8_t *record;
const uint8_t *mp;
uint8_t team;
orig_shell_launch(launch, a2, owner, a4, a5, a6);
@@ -64,12 +64,14 @@ static void __fastcall hook_shell_launch(void **launch, void *a2, uint8_t *owner
record = (const uint8_t *)launch[LMP_SHELL_LAUNCH_IDX_RECORD];
if (record == NULL || record[LMP_SHELL_REC_OFF_INSTANT_WIN] != 1)
return;
team = owner_team(owner);
mp = owner_mplayer(owner);
team = mp != NULL ? mp[LMP_MP_OFF_TEAM] : 0;
if (team != 1 && team != 2)
return;
if (g_bomb_team != team)
log_line("local_mp: instant-win bomb launched by team %u", (unsigned)team);
g_bomb_team = team;
g_bomb_is_local = local_mp_is_local_mplayer(mp) ? 1 : 0;
}
static void __fastcall hook_shell_explode(void *a1, uint64_t a2, void *a3, void *a4, void *a5, void *a6,
@@ -80,7 +82,11 @@ static void __fastcall hook_shell_explode(void *a1, uint64_t a2, void *a3, void
return;
g_winner_team = g_bomb_team;
g_bomb_team = 0;
log_line("local_mp: nuclear explosion, team %u wins", (unsigned)g_winner_team);
log_line("local_mp: nuclear explosion, team %u wins%s", (unsigned)g_winner_team,
g_bomb_is_local ? " (local player's bomb)" : "");
if (g_bomb_is_local)
local_mp_report_nuclear_strike();
g_bomb_is_local = 0;
}
static int *mission_int_var(uint8_t *ctx, const char *name)
@@ -106,6 +112,7 @@ static uint64_t __fastcall hook_cta_logic(uint8_t *ctx, void *a2, void *a3, void
/* A new mission: nothing launched or won in the previous one carries over. */
g_logic_ctx = ctx;
g_bomb_team = 0;
g_bomb_is_local = 0;
g_winner_team = 0;
}
if (ctx != NULL && g_winner_team != 0 && local_mp_is_host()) {
@@ -11,6 +11,7 @@ export interface LiveBattleLog {
readonly events: ReportedCombatEvent[];
readonly lives: BattleLife[];
readonly feed: FeedKill[];
readonly nuclearStrikes: number[];
/** Keys of the awards already announced (battle-streaks.ts AwardedStreak.key). */
readonly announced: Set<string>;
}
@@ -26,7 +27,7 @@ export class BattleLiveLogs {
of(sessionId: string): LiveBattleLog {
let log = this.#logs.get(sessionId);
if (!log) {
log = { events: [], lives: [], feed: [], announced: new Set() };
log = { events: [], lives: [], feed: [], nuclearStrikes: [], announced: new Set() };
this.#logs.set(sessionId, log);
while (this.#logs.size > this.#maxRetained) this.#logs.delete(this.#logs.keys().next().value!);
}
@@ -15,6 +15,8 @@
* players{ p{ id:i team:i score:i kills:i groundKills:i humanKills:i navalKills:i aiKills:i
* aiGroundKills:i aiNavalKills:i assists:i deaths:i } ... }
* the final scoreboard
* strikes{ s{ time:r } ... } explosions of the local player's
* nuclear bombs (native local_mp_nuke.c)
* spares{ <unit>:i ... } backup vehicles used
*/
import { findBlock, type BlkBlock } from '@wto/blk';
@@ -79,6 +81,8 @@ export interface BattleReport {
readonly events: readonly ReportedCombatEvent[];
readonly feed: readonly FeedKill[];
readonly players: readonly ScoreboardPlayer[];
/** Mission times at which the local player's nuclear bombs exploded. */
readonly nuclearStrikes: readonly number[];
readonly usedSpares: Readonly<Record<string, number>>;
}
@@ -134,6 +138,7 @@ export function parseBattleReport(payload: BlkBlock): BattleReport | undefined {
team: intOf(block, 'team'),
...Object.fromEntries(SCOREBOARD_FIELDS.map((field) => [field, Math.max(0, intOf(block, field))])) as Record<(typeof SCOREBOARD_FIELDS)[number], number>,
})),
nuclearStrikes: (findBlock(payload, 'strikes')?.blocks ?? []).map((block) => realOf(block, 'time')).sort((a, b) => a - b),
usedSpares: parseSpareMap(findBlock(payload, 'spares')),
};
}
@@ -23,9 +23,11 @@
* (not those limited by battle rating, e.g. heroic_punisher)
* unlocks `num` of the listed awards earned in the battle (all when
* num is missing, as scripts unlocksConditions.nut counts)
* killStreakNuclearSuccess each explosion of the local player's nuclear bomb
* (killStreak_bomber_nuclear_success)
* Not supported (the facts are not reported): finalBlow, lastManStanding, killWithoutHit,
* hitWithoutDeath, killWithoutMiss, landings, scout / repair / extinguish help, squad awards,
* kill-streak support vehicles, shell interception, specified naval damage, event missions; and
* other kill-streak support vehicles, shell interception, specified naval damage, event missions; and
* any award with a condition on weapon, distance, head shot, scouting, death reason, offender
* flags, unit tags or the awards' platform-free "customOnline" / "mission". Their awards are
* never given.
@@ -46,6 +48,8 @@ export interface StreakFacts {
readonly events: readonly ReportedCombatEvent[];
readonly lives: readonly BattleLife[];
readonly feed: readonly FeedKill[];
/** Mission times at which the local player's nuclear bombs exploded. */
readonly nuclearStrikes: readonly number[];
readonly localPlayerId: number;
readonly localTeam: number;
/** The final scoreboard; absent while the battle runs (after-battle awards are then skipped). */
@@ -167,6 +171,9 @@ export function evaluateStreaks(definitions: readonly StreakDefinition[], facts:
case 'missionsWon':
if (facts.outcome === 'win') award(def, facts.sessionEnd, 1);
break;
case 'killStreakNuclearSuccess':
for (const time of facts.nuclearStrikes) award(def, time, 1);
break;
case 'firstKill': {
const first = facts.feed.find((k) => k.killerTeam !== k.victimTeam);
if (first && first.killer === facts.localPlayerId) award(def, first.time, 1);
@@ -8,6 +8,7 @@
* "event": time:f unit:s code:i expClass:s victim:s victimIsPlayer:b friendly:b modifier:s damage:i
* "life": unit:s start:f end:f died:b
* "kill": time:f killer:i killerTeam:i victim:i victimTeam:i
* "strike": time:f the local player's nuclear bomb exploded
* answer: { streaks: [{ id:s stage:i (-1 = single-stage) stageParam:i wp:i exp:i }] }
*/
import type { BattleLiveLogs } from '../battle/battle-live-log.ts';
@@ -34,9 +35,10 @@ export function battleLiveRequests(deps: BattleLiveDependencies): Array<[string,
events: log.events,
lives: log.lives,
feed: log.feed,
nuclearStrikes: log.nuclearStrikes,
localPlayerId: int(p.localPlayerId, -1),
localTeam: int(p.localTeam, 0),
sessionEnd: Math.max(0, ...log.lives.map((life) => life.end), ...log.events.map((e) => e.time)),
sessionEnd: Math.max(0, ...log.lives.map((life) => life.end), ...log.events.map((e) => e.time), ...log.nuclearStrikes),
}, session);
const fresh = awarded.filter((streak) => !streak.hidden && !log.announced.has(streak.key));
for (const streak of fresh) log.announced.add(streak.key);
@@ -62,6 +64,9 @@ function recordFact(log: ReturnType<BattleLiveLogs['of']>, p: Readonly<Record<st
case 'kill':
log.feed.push({ time: num(p.time), killer: int(p.killer, -1), killerTeam: int(p.killerTeam, 0), victim: int(p.victim, -1), victimTeam: int(p.victimTeam, 0) });
return true;
case 'strike':
log.nuclearStrikes.push(num(p.time));
return true;
default:
return false;
}