'use client'; import { useId, useState } from 'react'; import type { Action, GameView } from '@/game/engine'; import { planetologistLeader, type PlanetologistMoveMode, } from '@/game/planetologist-movement'; import { gameTerritories, location, splitLocation, territory, } from '@/game/board'; import { planetologistFlightSelection, type PlanetologistFlight } from '@/game/planetologist-flight'; import { PlanetologistMovementAction, planetologistMoveDraft, planetologistMovementBlocked, planetologistNoFieldMarker, } from './planetologist-movement-action'; import { Input } from './ui/input'; export { planetologistMoveDraft } from './planetologist-movement-action'; type Counts = Record; type Props = { game: GameView; act: (action: Action) => void; busy: boolean; destination: string; sector: number; unavailableReason?: string | null; }; export function PlanetologistMovement(props: Props) { const marker = planetologistNoFieldMarker(props.game); const me = props.game.players.find(player => player.id === props.game.me); return ; } function PlanetologistMovementDraft({ game, act, busy, destination, sector, unavailableReason, }: Props) { const id = useId(); const [mode, setMode] = useState('range'); const [forces, setForces] = useState({}); const [elites, setElites] = useState({}); const [includeNoField, setIncludeNoField] = useState(false); const [flight, setFlight] = useState(game.ornithopter?.active?.mode ?? 'ordinary'); const me = game.players.find((player) => player.id === game.me); const leader = me && planetologistLeader(game, me.id); if (!me || !leader) return null; const transport = planetologistFlightSelection(game, flight); const sources = Object.entries(me.forces).map(([from, count]) => { if (!transport.cohort) return [from, count] as const; const currentElite = me.elites?.forces[from] ?? 0; const cohortElite = transport.cohort.elites[from] ?? 0; const normal = Math.min(count - currentElite, (transport.cohort.forces[from] ?? 0) - cohortElite); return [from, normal + Math.min(currentElite, cohortElite)] as const; }).filter(([, count]) => count > 0); const marker = planetologistNoFieldMarker(game); const markerAvailable = !transport.cohort || !!(marker && transport.cohort.noField && marker.tokenId === transport.cohort.noField.tokenId && marker.event === transport.cohort.noField.event && location(marker.location.territory, marker.location.sector) === transport.cohort.noField.from); const draft = planetologistMoveDraft( game, mode, destination, sector, forces, elites, includeNoField, flight, ); const blocked = planetologistMovementBlocked(game, draft, unavailableReason, flight); const leaderName = game.allLeaders.find((candidate) => candidate.id === leader)?.name ?? leader; return (

Planetologist movement

{leaderName} may add one territory to one movement, up to three, or gather forces from exactly two territories into the selected destination.

{game.advanced&&me.faction==='beneGesserit'&&mode==='gather'&&(

When joining your residents, each incoming origin that changes type has its own matching response. Both groups wait for every required allowance. Prevention leaves the movement unused and keeps both groups in place.

)} {(game.ornithopter || game.discoveryOrnithopter) && ( <>

Provisional flight composition: fixed-range Ornithopter and Discovery flight stay at three territories for either skill choice, including each origin of a gather. Two-group card flight uses extra range up to three, or gathers two origins using each origin’s normal range. A gather counts as one card movement; the next movement must use different original forces. Only one flight source is used per movement.

{game.ornithopter?.active && !transport.blocked && (

{game.ornithopter.active.completed} card movements completed ·{' '} {game.ornithopter.active.remaining} remaining. Select original unmoved forces below for the next movement.

)} )}

Destination: {territory(destination).name}, sector {sector}. Select the physical forces to move below.

{marker && ( <>

Provisional range composition: the concealed marker moves as one force with Planetologist’s extra range, up to three territories. Move it alone or with physical forces from its own territory; its value stays concealed. No direct joint FAQ settles this combination.

Provisional gather composition: the concealed marker supplies one of exactly two origin territories, alone or with physical forces there. Select physical forces from one other territory.{' '} {transport.rangeOverride ? 'Every origin uses the selected flight’s fixed range of three.' : 'Every origin uses its normal range; gather adds no extra range.'}{' '} Its value stays concealed.

{!markerAvailable &&

This marker is outside the original unmoved card cohort.

} {game.homeworldMobility?.noFieldMovementBlocked && (

{game.homeworldMobility.noFieldMovementBlocked}

)} )} {draft.action?.fighters === true && (

Provisional mixed-gather policy: both groups arrive as fighters. The advisor flip is declared before either group moves. If canceled, both groups stay in place and no movement is spent; flipping remains blocked for that movement opportunity.

)} {me.faction === 'ixians' && (

Each origin uses its own selected cyborgs for movement range. Cyborgs from one territory cannot carry suboids from the other territory farther.

)} {sources.length ? ( sources.map(([from, owned]) => { const source = splitLocation(from); const sourceName = gameTerritories(game).find( (candidate) => candidate.id === source.territory, )?.name ?? source.territory; const selected = forces[from] ?? 0; const ownedElite = transport.cohort ? Math.min(me.elites?.forces[from] ?? 0, transport.cohort.elites[from] ?? 0) : me.elites?.forces[from] ?? 0; const minimumElite = Math.max(0, selected - (owned - ownedElite)); return (
{me.elites && ( )}
); }) ) : (

No physical board forces are available to move.

)} {blocked && ( {blocked} )}

Only one flight source may be used for each movement. Normal movement and arrival rules still apply.

); }