Connect revealed Harass force allocation and exact casualties

Harass & Withdraw now admits legal Basic/Advanced mixed ordinary/elite commitments and multi-sector returns. A shared physical quote validates every returned counter against one exact legal dial/support complement. After both plans are revealed, the owner selects an ambiguous allocation; unique returns remain automatic. Selected counters become public before Traitor declarations, while physical transfer waits for atomic settlement and opposing-Traitor cancellation. This information is never added to a sealed Battle Plan or complete-plan inspection. Existing optional-module and Richese/Ecaz-allied gates remain.

The player panel, four AI profiles and saved event use the same quote. A versioned receipt binds the revealed plans, current typed location pools, battle and owner. Missing or altered receipts fail before reads, normalization and writes; concurrent choices select once. Previously valid legacy unique plans continue without reopening. Winner casualties now equal the selected dialed group, preventing a second smaller physical commitment after its undialed complement has returned.

Independent source and implementation review passed. Pure, engine, control and SQLite regressions cover typed/sector legality, exact complement, private pre-reveal views, public selected views, stale/malformed state, cross-owner actions, raced allocations, selected restoration, automatic exact casualties, opposing-Traitor cancellation and mandatory disposal. Types, lint and 4850 offline tests, production build and 43 HTTP/session tests pass. The first broad check caught the exhaustive decision registry and test union-narrowing omissions; those were fixed before the final stable checks. Browser testing corrected the incomplete-allocation selector label before verification.

Eight genuine card-variant Basic/Advanced games across all four homogeneous AI profiles completed with 9956 accepted actions, 266 periodic JSON restores and zero rejected candidates. Three Harass plans/returns and two Recruits plays occurred; no ambiguous allocation arose in these seeds. The new choice is exercised by targeted engine, authenticated recovery and browser cases, not inferred from those full-game samples. Full variant and combined-expansion acceptance remains incomplete.

A fresh isolated browser room used genuine Advanced card-variant setup followed by a conserved two-sector battle fixture. Actual controls rejected a partial return, selected two ordinary counters from sector nine, and preserved the selected state after refresh. Following actual owner and engine-driven opponent Traitor declines, two counters returned, the exact remaining ordinary/elite pair went to the Tanks, support cost one, and Harass discarded once. Final refresh restored 18 reserves, two Tanks, 29 spice and the same private Traitor. This is targeted browser evidence, not a complete human game.

All 1038 opening games and original seat/recovery/entry/handover records are unchanged; 1072 rooms remain including new QA. SQLite integrity and foreign keys pass. The healthy development server was reused without restart or reset. No mode/publication gate was opened.

Verified source tree: 61ee78f6e2bce47cb322b04f896db27fef28c56ba2097571a1d85bad5c121156
This commit is contained in:
Quintine committed 2026-09-14 06:37:23 +10:00
1 parent 640342527a
commit 62e87d2b96
18 files changed
+1654 -71

No files matched your search

+8
View File
@@ -153,6 +153,7 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { BattlePreparation, battlePlanCommitments, battlePlanCardValue, battlePlanCardOptions, bindBattlePlanCommitments, NexusInspectionHistory } from './battle-preparation';
import { HarassWithdrawGuide, harassWithdrawControlState } from './harass-withdraw';
import { HarassWithdrawChoice } from './harass-withdraw-choice';
import { PrivateBattlePlan } from './private-battle-plan';
import { SpiceBankerControl, spiceBankerControlState } from './spice-banker';
import { canUsePlanetologistBattleSpecial } from '../game/leader-skill-combat';
@@ -2172,6 +2173,8 @@ export function GameTable({
? g.decision.stage === 'offer' ? 'Rihani Decipherer — optional draw' : 'Choose your Traitor exchange'
: g.decision.kind === 'sukRescue'
? 'Save your battle casualties'
: g.decision.kind === 'harassWithdraw'
? 'Choose undialed forces to return'
: g.decision.kind === 'diplomatDefense'
? 'Copy an opposing defense'
: g.decision.kind === 'homeworldRevivalDeployment'
@@ -2595,6 +2598,11 @@ export function GameTable({
mode: 'ignore',
})}
</>
) : g.decision.kind === 'harassWithdraw' ? (
<>
<RevealedBattle game={g} />
<HarassWithdrawChoice key={g.decision.event} game={g} act={act} busy={busy} />
</>
) : g.decision.kind === 'diplomatDefense' ? (
<>
<RevealedBattle game={g} />
+200
View File
@@ -0,0 +1,200 @@
'use client';
import { useId, useState } from 'react';
import { splitLocation, territory } from '@/game/board';
import type { Action, GameView } from '@/game/engine';
import {
defaultHarassWithdrawAllocation,
harassWithdrawCommitments,
quoteHarassWithdraw,
type HarassWithdrawContext,
type HarassWithdrawForces,
type HarassWithdrawSelection,
} from '@/game/harass-withdraw';
import { Button } from './ui/button';
import { Input } from './ui/input';
function compactSelection(selection: HarassWithdrawSelection) {
return Object.fromEntries(
Object.entries(selection)
.filter(([, group]) => group.normal || group.elite)
.map(([key, group]) => [key, { ...group }]),
);
}
export function harassWithdrawChoiceState(
context: HarassWithdrawContext,
dial: number,
support: number,
selection: HarassWithdrawSelection,
) {
try {
const quote = quoteHarassWithdraw(
context,
dial,
support,
compactSelection(selection),
);
return { blocked: null, quote };
} catch (error) {
return {
blocked:
error instanceof Error
? error.message
: 'Choose the exact forces that return.',
quote: null,
};
}
}
function locationLabel(key: string) {
const location = splitLocation(key);
return `${territory(location.territory).name} · sector ${location.sector}`;
}
export function HarassWithdrawChoice({
game: g,
act,
busy,
}: {
game: GameView;
act: (action: Action) => void;
busy: boolean;
}) {
const id = useId();
const decision = g.decision;
const offer = g.battle?.harassAllocation;
const current =
decision?.kind === 'harassWithdraw' &&
decision.player === g.me &&
offer?.event === decision.event;
const context = offer?.context;
const commitments = context
? harassWithdrawCommitments(context, offer.dial, offer.support)
: [];
const initial = context
? (offer?.selection ??
defaultHarassWithdrawAllocation(
context,
offer.dial,
offer.support,
commitments[0],
))
: {};
const [selection, setSelection] = useState<HarassWithdrawSelection>(initial);
if (!current || !offer || !context) return null;
const state = harassWithdrawChoiceState(
context,
offer.dial,
offer.support,
selection,
);
const selectedCommitment = state.quote?.remaining;
const commitmentValue = selectedCommitment
? `${selectedCommitment.normal}:${selectedCommitment.elite}`
: '';
const update = (
key: string,
kind: keyof HarassWithdrawForces,
value: number,
) =>
setSelection((previous) => ({
...previous,
[key]: {
normal: previous[key]?.normal ?? 0,
elite: previous[key]?.elite ?? 0,
[kind]: value,
},
}));
return (
<section
aria-label="Harass and Withdraw force allocation"
className="notice space-y-3"
>
<h4>Choose Harass &amp; Withdraw forces</h4>
<p>
Your Battle Plan is revealed. Choose the exact undialed counters that
return to reserves before the Traitor decision.
</p>
<label htmlFor={`${id}-commitment`}>Dialed physical commitment</label>
<select
id={`${id}-commitment`}
value={commitmentValue}
onChange={(event) => {
const commitment = commitments.find(
(candidate) =>
`${candidate.normal}:${candidate.elite}` === event.target.value,
);
if (commitment)
setSelection(
defaultHarassWithdrawAllocation(
context,
offer.dial,
offer.support,
commitment,
),
);
}}
>
{!selectedCommitment && (
<option value="" disabled>
Complete the return allocation
</option>
)}
{commitments.map((commitment) => (
<option
key={`${commitment.normal}:${commitment.elite}`}
value={`${commitment.normal}:${commitment.elite}`}
>
{commitment.normal} ordinary · {commitment.elite} elite
</option>
))}
</select>
{Object.entries(context.locations)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, available]) => (
<fieldset key={key} className="grid gap-2 rounded-lg border p-3">
<legend>{locationLabel(key)}</legend>
{(['normal', 'elite'] as const).map((kind) => (
<label key={kind}>
Return {kind === 'normal' ? 'ordinary' : 'elite'} (0–
{available[kind]})
<Input
type="number"
min={0}
max={available[kind]}
step={1}
value={selection[key]?.[kind] ?? 0}
onChange={(event) =>
update(key, kind, Number(event.target.value))
}
/>
</label>
))}
</fieldset>
))}
{state.quote ? (
<p>
Return {state.quote.returned.normal} ordinary and{' '}
{state.quote.returned.elite} elite forces.
</p>
) : (
<output className="block">{state.blocked}</output>
)}
<Button
disabled={busy || !state.quote}
onClick={() =>
act({
type: 'decision',
event: decision.event,
returns: compactSelection(selection),
})
}
>
Confirm returned forces
</Button>
</section>
);
}
+58 -14
View File
@@ -1,4 +1,8 @@
import { quoteHarassWithdraw, type HarassWithdrawPreview } from '@/game/harass-withdraw';
import {
harassWithdrawNeedsAllocation,
quoteHarassWithdraw,
type HarassWithdrawPreview,
} from '@/game/harass-withdraw';
export function harassWithdrawControlState(
preview: HarassWithdrawPreview | null | undefined,
@@ -7,28 +11,68 @@ export function harassWithdrawControlState(
support: number,
) {
if (!selected) return { blocked: null, returned: null };
if (!preview) return { blocked: 'Harass & Withdraw is not available in this battle.', returned: null };
if (!preview)
return {
blocked: 'Harass & Withdraw is not available in this battle.',
returned: null,
};
try {
return { blocked: null, returned: quoteHarassWithdraw(preview, dial, support).returned };
if (
preview.allowAllocation &&
harassWithdrawNeedsAllocation(preview, dial, support)
)
return { blocked: null, returned: null };
return {
blocked: null,
returned: quoteHarassWithdraw(preview, dial, support).returned,
};
} catch (error) {
return { blocked: error instanceof Error ? error.message : 'Choose a supported force commitment.', returned: null };
return {
blocked:
error instanceof Error
? error.message
: 'Choose a supported force commitment.',
returned: null,
};
}
}
export function HarassWithdrawGuide({
preview, state,
preview,
state,
}: {
preview: HarassWithdrawPreview | null | undefined;
state: ReturnType<typeof harassWithdrawControlState>;
}) {
if (!preview) return null;
return <section aria-label="Harass and Withdraw battle guidance" className="notice space-y-2">
<h4>Harass &amp; Withdraw</h4>
{preview.blocked || state.blocked
? <output className="block">{preview.blocked ?? state.blocked}</output>
: state.returned
? <p>Return {state.returned.normal} ordinary and {state.returned.elite} elite undialed forces to reserves when plans resolve.</p>
: <p>Select this card in either battle-card slot. Your undialed forces return to reserves.</p>}
<p>Your leader can still die. An opponent’s successful traitor call cancels the withdrawal. Discard this card after use.</p>
</section>;
return (
<section
aria-label="Harass and Withdraw battle guidance"
className="notice space-y-2"
>
<h4>Harass &amp; Withdraw</h4>
{preview.blocked || state.blocked ? (
<output className="block">{preview.blocked ?? state.blocked}</output>
) : state.returned ? (
<p>
Return {state.returned.normal} ordinary and {state.returned.elite}{' '}
elite undialed forces to reserves when plans resolve.
</p>
) : preview.allowAllocation ? (
<p>
After plans are revealed, choose exactly which undialed ordinary and
elite forces return to reserves.
</p>
) : (
<p>
Select this card in either battle-card slot. Your undialed forces
return to reserves.
</p>
)}
<p>
Your leader can still die. An opponent’s successful traitor call cancels
the withdrawal. Discard this card after use.
</p>
</section>
);
}