'use client';
import { useState } from 'react';
import type { Action, GameView } from '@/game/engine';
import { faction } from '@/game/catalog';
import { HOMEWORLD_CARDS } from '@/game/homeworld-cards';
import type { NativeReserveSelections } from '@/game/homeworld-native-reserves';
import { HomeworldFace } from './homeworld-cards';
import { EcazPoisonIncome } from './ecaz-poison-income';
import { Button } from './ui/button';
import { Input } from './ui/input';
export function HomeworldTable({ game: g }: { game: GameView }) {
const worlds = g.homeworlds?.worlds;
if (!worlds) return null;
return (
Homeworlds
Native forces here are your reserves. Salusa Secundus counts Sardaukar
for its population.
{worlds.map((world) => {
const card = HOMEWORLD_CARDS.find((c) => c.id === world.card)!;
const owner = g.players.find((p) => p.id === world.native)!;
return (
{card.name}
{world.side} population · {world.population}
{faction(owner.faction).name} · {owner.name}
{Object.entries(world.forces).map(([id, forces]) => (
{id === world.native
? 'Native reserves'
: g.players.find((p) => p.id === id)?.name}
: {forces.normal} normal
{forces.elite > 0
? ` + ${forces.elite} ${owner.faction === 'emperor' && id === owner.id ? 'Sardaukar' : 'special'}`
: ''}
))}
{card.name} card
);
})}
);
}
/** The complementary Kaitain allocation is explicit in the submitted order. */
export function NativeShipmentChoice({
game: g,
amount,
elite,
sources,
onChange,
busy,
}: {
game: GameView;
amount: number;
elite: number;
sources: NativeReserveSelections | null;
onChange: (sources: NativeReserveSelections) => void;
busy: boolean;
}) {
const homes = g.homeworlds?.worlds?.filter((w) => w.native === g.me);
if (!homes || homes.length !== 2 || !sources) return null;
const salusa = homes.find((w) => w.secondary)!;
const kaitain = homes.find((w) => !w.secondary)!;
const chosen = sources[salusa.id];
const requested = { normal: amount - elite, elite };
return (
);
}
export function EmperorHomeworldMovement({
game: g,
act,
busy,
}: {
game: GameView;
act: (action: Action) => void;
busy: boolean;
}) {
const [origin, setOrigin] = useState('homeworld:emperor');
const [normal, setNormal] = useState(0);
const [elite, setElite] = useState(0);
const option = g.homeworldMove;
const homes = g.homeworlds?.worlds?.filter((w) => w.native === g.me);
if (!option || !homes || homes.length !== 2) return null;
const source = homes.find((w) => w.id === origin)!;
const destination = homes.find((w) => w.id !== origin)!;
const available = source.forces[g.me];
const name = (id: string) =>
id === 'homeworld:emperor' ? 'Kaitain' : 'Salusa Secundus';
const invalid =
!Number.isSafeInteger(normal) ||
!Number.isSafeInteger(elite) ||
normal < 0 ||
elite < 0 ||
normal > available.normal ||
elite > available.elite ||
normal + elite === 0;
return (
Move between Imperial Homeworlds
Move normal forces or Sardaukar between Kaitain and Salusa Secundus.
Costs one movement and no spice. Moving first passes your unused
shipment.
{option.blocked && (
)}
);
}