Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/feature-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,12 @@ Three traps, all hit while truncating ship names in XIT DISPATCH:
directive, a ResizeObserver and a feedback-loop hazard — widening the column is usually the
better trade.

### XIT DISPATCH: two ships on one base

A base stores assigned ships in `ships`, in drop order, at most two. Older tile state has `ship` and no `ships`; copy it once when `ships` is missing, and do not rewrite a row whose `ships` array is already present. Dropping a third ship or a duplicate does nothing. Each chip has its own clear control. The assign cell stays 84px (`.shipAssigned` / `.shipPlaceholder`); names truncate inside it so a couple of characters still show beside each x.

Resupply and repair for that base fill the first ship, then spill. Fit on a two-ship base uses the combined free capacity of both holds. Both ships get an SFC when the dispatch runs, including a second ship whose portion is empty. That empty ship gets one SFC-only action and no Manual load group: an empty group fails the whole package before any ship is sent. A ship shared across bases still uses the milk-run planner; a two-ship base contributes only its portion of the bill to each ship. Earlier rows claim capacity first, so one hold is not packed twice at CX departure.

### Alignment Belongs to the Column, Not the Layout Mode

When a cell component aligns its own content unconditionally, the matching header rule must be
Expand Down
28 changes: 26 additions & 2 deletions src/features/XIT/ACT/actions/mtra/mtra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ act.addAction<Config>({
type: 'MTRA',
shortDescription: 'Transfer materials between storages at the same location',
description: (action, config) => {
if (action.sfcOnly === true) {
return action.sfcDestination ? `Open SFC to ${action.sfcDestination}` : 'Open SFC';
}
if (!action.group || !action.origin || !action.dest) {
return '--';
}
Expand Down Expand Up @@ -57,10 +60,31 @@ act.addAction<Config>({
ctx;
const assert: AssertFn = ctx.assert;

// Empty DISPATCH ship: SFC only. Do not look up a group — there isn't one,
// and an empty Manual group fails the whole package.
if (data.sfcOnly === true) {
const serializedDest = data.dest === configurableValue ? config?.destination : data.dest;
const destMaybe = deserializeStorage(serializedDest);
assert(destMaybe, 'Invalid destination');
if (destMaybe.type === 'SHIP_STORE' && shouldEmitAutoSfc(data, config, packageName)) {
emitStep(
OPEN_SFC({
shipId: destMaybe.addressableId,
destination: data.sfcDestination,
}),
);
}
return;
}

// Assert-narrowed locals (rebound so nested helpers keep the non-undefined type).
// A finish action may have no load group when the CX bill was empty but a
// pickup or offload list still has to run.
const materialsMaybe = await getMaterialGroup(data.group);
assert(materialsMaybe, 'Invalid material group');
const materials = materialsMaybe;
if (materialsMaybe === undefined) {
assert(data.finishOnly === true, 'Invalid material group');
}
const materials = materialsMaybe ?? {};

const serializedOrigin = data.origin === configurableValue ? config?.origin : data.origin;
const originMaybe = deserializeStorage(serializedOrigin);
Expand Down
50 changes: 50 additions & 0 deletions src/features/XIT/ACT/actions/mtra/two-phase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
import { buildDispatchShipPackage } from '@src/features/XIT/ACT/actions/mtra/two-phase';

const here = dirname(fileURLToPath(import.meta.url));

describe('empty DISPATCH ship package', () => {
it('sends an empty portion with an SFC-only action and no load group', () => {
const pkg = buildDispatchShipPackage({
loadName: 'Load Hauler',
shipName: 'Hauler',
origin: 'Antares Station Warehouse',
dest: 'Hauler Cargo',
sfcDestination: 'OT-580b',
materials: {},
offloadGroups: [],
agentGroups: [],
repairGroups: [],
pickupGroups: [],
});

expect(pkg.loadGroup).toBeUndefined();
expect(pkg.load).toBeUndefined();
expect(pkg.finish).toEqual({
type: 'MTRA',
name: 'Send Hauler',
origin: 'Antares Station Warehouse',
dest: 'Hauler Cargo',
sfcOnly: true,
sfcDestination: 'OT-580b',
});
expect(pkg.finish.group).toBeUndefined();
expect(pkg.finish.noSfc).toBeUndefined();

const dispatch = readFileSync(join(here, '../../../DISPATCH/DISPATCH.vue'), 'utf8');
expect(dispatch).toContain('buildDispatchShipPackage');
expect(dispatch).toContain('if (shipPkg.loadGroup !== undefined)');
expect(dispatch).not.toMatch(/groups\.push\(\{\s*type: 'Manual',\s*name: loadName/);

const mtra = readFileSync(join(here, 'mtra.ts'), 'utf8');
const sfcOnly = mtra.indexOf('data.sfcOnly === true');
const groupLookup = mtra.indexOf('getMaterialGroup(data.group)');
expect(sfcOnly).toBeGreaterThan(-1);
expect(groupLookup).toBeGreaterThan(sfcOnly);
expect(mtra.slice(sfcOnly, groupLookup)).toContain('return');
expect(mtra.slice(sfcOnly, groupLookup)).toContain('OPEN_SFC({');
});
});
72 changes: 72 additions & 0 deletions src/features/XIT/ACT/actions/mtra/two-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,75 @@ export function buildTwoPhaseMtraActions(opts: TwoPhaseMtraOptions): {
finish,
};
}

export interface DispatchShipPackageOptions {
loadName: string;
shipName: string;
origin: string;
dest: string;
sfcDestination: string;
materials: Record<string, number>;
offloadGroups: string[];
agentGroups: string[];
repairGroups: string[];
pickupGroups: string[];
}

export interface DispatchShipPackage {
// Absent when the CX load is empty. An empty Manual group fails the package.
loadGroup: UserData.MaterialGroupData | undefined;
// Transfer action. Absent when there is nothing to load.
load: UserData.ActionData | undefined;
// SFC, plus offload/agent/repair when this ship carries any.
finish: UserData.ActionData;
}

// A ship with nothing to load still has to be sent. That action must not name a
// material group: manual.ts rejects an empty bill, and the MTRA step then fails
// the whole package.
export function buildDispatchShipPackage(opts: DispatchShipPackageOptions): DispatchShipPackage {
const loadEmpty = Object.keys(opts.materials).length === 0;
const hasFinishWork =
opts.offloadGroups.length > 0 ||
opts.agentGroups.length > 0 ||
opts.repairGroups.length > 0 ||
opts.pickupGroups.length > 0;
if (loadEmpty && !hasFinishWork) {
return {
loadGroup: undefined,
load: undefined,
finish: {
type: 'MTRA',
name: `Send ${opts.shipName}`,
origin: opts.origin,
dest: opts.dest,
sfcOnly: true,
sfcDestination: opts.sfcDestination,
},
};
}

const built = buildTwoPhaseMtraActions({
loadName: opts.loadName,
finishName: `Offload ${opts.shipName}`,
group: opts.loadName,
origin: opts.origin,
dest: opts.dest,
sfcDestination: opts.sfcDestination,
offloadGroups: opts.offloadGroups,
agentGroups: opts.agentGroups,
repairGroups: opts.repairGroups,
pickupGroups: opts.pickupGroups,
});
return {
loadGroup: loadEmpty
? undefined
: {
type: 'Manual',
name: opts.loadName,
materials: opts.materials,
},
load: loadEmpty ? undefined : built.load,
finish: built.finish,
};
}
Loading
Loading