'use client'; import { useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { guildHomeworldShipmentChoice, guildHomeworldShipmentOrigins, } from '@/game/guild-homeworld-shipment-options'; import { homeworldName, type HomeworldShipmentSources, } from '@/game/homeworld-shipment-options'; import { Button } from './ui/button'; import { Input } from './ui/input'; export function GuildHomeworldShipment({ game: g, act, busy, }: { game: GameView; act: (action: Action) => void; busy: boolean; }) { const origins = guildHomeworldShipmentOrigins(g); const me = g.players.find((player) => player.id === g.me)!; const targets = (g.homeworlds?.worlds ?? []).filter( (world) => world.native !== me.ally, ); const [origin, setOrigin] = useState(origins[0]?.territory.id ?? ''); const [destination, setDestination] = useState( targets.find((world) => world.native === me.id)?.id ?? targets[0]?.id ?? '', ); const [sources, setSources] = useState({}); const [allyPayment, setAllyPayment] = useState(0); const option = g.guildHomeworldShipment; if (!option || me.faction !== 'guild') return null; const selectedOrigin = origins.find( (candidate) => candidate.territory.id === origin, ); const selected = Object.fromEntries( (selectedOrigin?.pools ?? []).flatMap((pool) => { const chosen = sources[pool.key]; return chosen && chosen.normal + chosen.elite > 0 ? [[pool.key, chosen]] : []; }), ); const quote = guildHomeworldShipmentChoice( g, destination, selected, allyPayment, ); return (
Guild transport from Arrakis to a Homeworld

Ship forces from one Arrakis territory to Junction or another faction’s Homeworld. You may combine forces in different sectors of that territory. Allied Homeworlds cannot be destinations.

Pay one spice per two forces, rounded up. This uses your shipment; your normal movement remains available.

{option.blocked && ( {option.blocked} )}
{selectedOrigin?.pools.map((pool) => { const label = `${selectedOrigin.territory.name}${pool.sector === null ? '' : ` sector ${pool.sector}`}`; const storm = pool.sector === g.storm; return ( ); })} {me.ally && ( )}

Your available spice: {me.spice ?? 0}. Allied pledge:{' '} {g.aid.available}.

{quote.amount} forces · {quote.cost} spice total {quote.amount > 0 ? ` · you pay ${quote.ownPayment}, ally pays ${quote.allyPayment}` : ''} .{quote.blocked && ` ${quote.blocked}`}
); }