Refactor universe sim and observer HUD

This commit is contained in:
2026-03-12 00:53:52 -04:00
parent 5979a74d46
commit fbdf8d0d5a
11 changed files with 1832 additions and 622 deletions

View File

@@ -2,252 +2,205 @@
## Project State
This repository now contains a playable Three.js/Vite prototype for a space RTS / economy sim testbed inspired by EVE Online and X4.
This repository now contains a playable Three.js/Vite autonomous space-sim prototype that has moved away from a player-command RTS testbed and toward a game-master / observer simulation.
The codebase has been refactored away from a single monolithic `GameApp.ts` toward a more maintainable, data-driven structure. Authored game content now lives in JSON catalogs, while runtime code is split into domain types, world-building helpers, UI presenters, and rendering helpers.
The codebase is still TypeScript + Three.js on Vite, with authored catalogs under `src/game/data/`, but the runtime now centers on:
The current prototype includes:
- procedural universe generation
- autonomous faction behavior
- fleet / wing hierarchy
- economic production loops
- pirate harassment
- strategic system control
- observer-oriented HUD and camera controls
- Two solar systems: `Helios Reach` and `Perseus Gate`
- A large space environment with stars, planets, orbit lines, nebulae, asteroid/resource fields, and starfield
- RTS-style ship selection, command issuance, camera movement, zoom levels, and follow-camera support
- Three view levels based on zoom: `local`, `solar`, and `universe`
- A bottom command bar with selection info, order buttons, and a minimap
- A strategic HUD overlay that switches to NATO / military-style symbols at higher zoom levels
- A generic window layer, with an initial fleet command window for managing multi-wing groups
- App windows can now be dragged by their headers and resized from a corner grip
- `stargate` now exists as a constructible category in the same authored pipeline as other stations
## Current Prototype
## Major Gameplay Systems Added
The current build includes:
### World / Navigation
- a generated universe with a few dozen systems
- 4 empire factions inspired by EVE-style sovereign powers
- multiple pirate factions that raid empire space
- rich central systems that factions contest for control
- faction-owned stations, ships, inventories, and combat stats
- autonomous shipbuilding and limited outpost growth
- fleet and wing structure with behaviors such as:
- `command`
- `screen`
- `mining`
- `logistics`
- `escort`
- observer controls for camera orbit, pan, focus, and inspection
- Ships can travel between the two systems using staged FTL travel
- Travel flow includes:
- leaving gravity well
- FTL spool
- warp
- arrival
- FTL speed was increased and a basic warp streak / tunnel effect was added
- Local ship movement is no longer purely straight-line:
- ships bias toward curved orbital-style transfers around the system center
- idle ships hold a passive orbit instead of freezing in place
## Major Gameplay / Sim Systems
### Orbital Model
### Universe Generation
- Stations are no longer static arbitrary points
- Stations in `Helios` are placed on Lagrange-style offsets relative to planets
- Stations update position over time with the planetary orbital motion
- Ships and stations are beginning to behave like orbitals rather than free-floating markers
- Startup no longer uses the fixed two-system authored sandbox.
- `src/game/world/universeGenerator.ts` now generates:
- empire capitals
- empire mining systems
- pirate base systems
- central high-value systems
- frontier filler systems
- The generated scenario also assigns:
- faction definitions
- initial faction-owned stations
- initial ship formations
- central system IDs
### Units / AI / Orders
### Factions
- Ship roles currently in the prototype:
- military
- transport
- mining
- Ship classes now distinguish:
- frigate
- destroyer
- cruiser
- industrial
- capital
- Unit state machine now includes states for:
- idle / moving
- FTL travel
- mining and delivery
- docking approach / docking / docked / undocking
- patrol / escort
- Fleets are now a first-class gameplay concept:
- fleets have a commander, stance, high-level fleet order, and explicit wings
- wings can be nested via parent/child relationships to represent sub-wings
- ships now carry behavior metadata such as command, mining, escort, screen, or logistics
- fleet orders fan out into ship-level execution orders, keeping "order" separate from "behavior"
- Fleet tree selection is now manager-backed:
- fleets, wings, sub-wings, and ships can be selected directly from the fleet window
- selection is now handled through a dedicated selection manager rather than scattered UI state mutations
- Orders currently supported:
- move
- transfer
- mine
- patrol
- escort
- Runtime faction state now exists in `src/game/types.ts`.
- Factions track:
- credits
- ore mined
- goods produced
- ships built
- stations built
- ships lost
- enemy ships destroyed
- raids completed
- stolen cargo
- owned systems
- Empire factions and pirate factions are distinct runtime kinds.
### Docking / Logistics
### High-Level AI / Delegation
- Docking was added as a required step for transfer to stations
- Stations have limited docking capacity and explicit docking ports
- Carriers now act as mobile docking hosts for smaller combatants
- Carrier recovery was corrected so docking ships reserve a pad early and approach the moving pad directly instead of stalling behind the hull
- Mining ships now:
- mine ore in `Perseus`
- return to `Helios`
- dock at a refinery
- transfer ore
- undock and repeat
- Mining ships now correctly leave for the refinery once full even when the delivery leg is inter-system
- Faction AI now acts at a strategic level instead of directly micromanaging every ship.
- Empire AI chooses high-level goals such as:
- secure home and mining space
- contest central systems
- assign industrial fleets to mining loops
- Pirate AI chooses raid targets and dispatches fleets into hostile space.
- Fleet-level orders are now the intended command boundary between:
- faction strategy
- fleet / wing execution
- This work was specifically done to stop faction AI from stomping `screen` behavior with raw ship move orders.
### Economy / Inventory Foundations
### Fleets / Wings
- Added item storage classes:
- `bulk-solid`
- `bulk-liquid`
- `bulk-gas`
- `container`
- `manufactured`
- Added itemized manufactured goods for industrial progression:
- `hull-sections`
- `ammo-crates`
- `naval-guns`
- `ship-equipment`
- `ship-parts`
- Added deployable constructible kit items so buildables are also producible:
- `trade-hub-kit`
- `refinery-kit`
- `farm-ring-kit`
- `manufactory-kit`
- `shipyard-kit`
- `defense-grid-kit`
- `stargate-kit`
- Added module categories and starter module definitions for ships/stations
- Added explicit recipe data for refinery and fabrication processing
- Ships and stations now expose compatible cargo/storage/module metadata
- Refineries track:
- ore stored
- active refining batch
- refining timer
- refined output stock
- Stations now also maintain per-item stock internally
- Fabricator-array stations can now build ship parts, ammo, guns, and equipment from recipe data
- Fabricator-array stations can now also assemble deployable kits for constructibles, including stargates
- Refinery/manufactory processing now consumes itemized inputs and produces itemized outputs through a shared recipe-driven flow
- Fleet creation now groups ships per faction and role in `src/game/fleet/runtime.ts`.
- War fleets and industry fleets are generated from faction-owned ships.
- Wing behaviors remain meaningful at the tactical layer.
- `screen` is intended to remain subordinate to fleet command rather than independent faction micromanagement.
### Energy / Fuel
### Economy / Production
- Ships now track:
- fuel
- energy
- Stations now track:
- fuel
- energy
- Ships consume energy/fuel depending on activity
- Docked ships recharge energy
- Stations recharge energy passively
- Mining, refining, and fabrication still run through recipe-driven station logic.
- Faction-owned inventories are effectively pooled across faction stations for recipe consumption.
- Factions can build new ships when enough goods exist.
- Empires can build limited defense outposts in central systems they control.
## Testbed Layout
### Combat / Control
- `Helios Reach` is now the industrial / infrastructure system
- stations are concentrated there
- refinery loop terminates there
- `Perseus Gate` is now the extraction / resource system
- resource asteroid nodes are concentrated there
- miners operate there before hauling back
- Ships and relevant stations now have combat stats:
- health
- damage
- range
- cooldown
- Combat is lightweight and proximity-based.
- Central systems track control progress and controlling faction.
- Pirate ships can steal cargo from vulnerable civilian ships.
## Starting State
- Empires now start very small for easier debugging and growth observation.
- Each empire currently starts with only 3 ships:
- 1 frigate
- 1 hauler
- 1 miner
- Pirates still start with small raiding groups.
## UI / UX State
- Ship and station selection is supported
- Ship multi-selection is supported via click modifiers and marquee drag selection
- Selected ships can now be ordered to dock with the nearest friendly carrier
- Active fleets can be selected and focused through the fleet command window
- The fleet window now renders fleets as a real tree rather than a flat list
- Fleet tree nodes show order, behavior, and state on ship-level entries
- `Solar` and `universe` views now overlay high-level tactical symbology instead of relying only on 3D meshes
- `Solar` view now shows fleet hierarchy links between commanders and wing leaders
- Ships use role-specific long-range symbols:
- military: hostile/combat-style diamond iconography
- transport: boxed logistics symbol
- mining: angular resource / industrial symbol
- Stations and constructibles use square strategic markers with category-specific internal glyphs
- `Universe` view groups ships into fleet counts per system and role for cleaner strategic readability
- Focusing works for:
- single ships: follow camera
- stations: focus camera on the station
- Selection panels show:
- ship state, order, cargo, hold type, fuel, energy, modules
- station role, docking occupancy, stored resources, refinery timing, fuel, energy, modules
### Observer HUD
- The old summary panel is gone.
- The old bottom RTS command bar has been removed.
- The bottom HUD is now a selection dock that shows:
- selection title
- status line
- horizontally scrolling cards for selected entities
- fallback observer details when nothing specific is selected
- Fleet launch controls were removed from the main HUD.
- A dedicated `Debug` window now contains the `New Universe` button.
### Selection / Inspection
- Selection is no longer limited to ships and stations.
- It is now possible to select:
- systems
- planets
- ships
- stations
- Double-click centers / focuses the clicked target.
- Multiple ship selections render as horizontal cards in the bottom dock.
- Fleet window tree selection still works.
### Windows
- Generic draggable / resizable app windows still exist.
- Main windows currently in use:
- `Fleet Command`
- `Debug`
### Strategic Rendering
- Strategic overlay and minimap infrastructure still exist.
- The minimap canvas is still created for renderer use, but it is no longer shown in the visible HUD.
## Controls
- `Left Click`: select ships or stations
- `Shift + Left Click`: add ships to ship selection
- `Ctrl/Cmd + Left Click`: toggle ships in selection
- `Left Drag`: marquee-select multiple ships
- `Right Click`: issue move/transfer orders
- `Right Click` with no ship selection and an active fleet: issue a fleet move order
- `Left Click`: inspect / select systems, planets, ships, or stations
- `Shift + Left Click`: add ships to multi-selection
- `Ctrl/Cmd + Left Click`: toggle ships in multi-selection
- `Left Drag`: marquee-select multiple visible ships
- `Double Click`: center / focus the clicked target
- `Middle Drag`: orbit camera
- `Shift + Middle Drag`: pan camera
- `Mouse Wheel` or `-` / `=`: zoom
- `W A S D`: pan camera
- `Q / E`: rotate camera
- `F`: focus selection, and follow a single selected ship
- `G`: toggle the fleet command window
- `R`: assign selected compatible ships to dock with the nearest friendly carrier
- `F`: focus current selection
- `G`: toggle fleet command window
- `Tab`: jump camera between systems
- `B`: toggle build mode
- `1-7`: choose constructible
- `M`: assign mining
- `P`: assign patrol
- `E`: assign escort
## Technical Notes
- The prototype is built with:
- Vite
- TypeScript
- Three.js
- Authored data now lives in JSON files under `src/game/data/`, including:
- `items.json`
- `recipes.json`
- `systems.json`
- `modules.json`
- `ships.json`
- `constructibles.json`
- `scenario.json`
- `balance.json`
- Shared domain and runtime types now live in `src/game/types.ts`
- Stations now carry both coarse storage totals and itemized stock for recipes
- The recipe graph now covers every current constructible and every current catalog item ID
- World construction is extracted into `src/game/world/worldFactory.ts`
- HUD creation and presentation logic are extracted into:
- Main runtime remains concentrated in `src/game/GameApp.ts`
- World construction and entity instancing:
- `src/game/world/worldFactory.ts`
- Procedural universe generation:
- `src/game/world/universeGenerator.ts`
- Fleet composition helpers:
- `src/game/fleet/runtime.ts`
- Selection state:
- `src/game/state/selectionManager.ts`
- HUD / presentation:
- `src/game/ui/hud.ts`
- `src/game/ui/presenters.ts`
- `src/game/ui/strategicRenderer.ts`
- Fleet composition helpers now live in:
- `src/game/fleet/runtime.ts`
- Inventory helpers now live in `src/game/state/inventory.ts`
- Selection logic is now centralized in:
- `src/game/state/selectionManager.ts`
- Ship-to-ship docking now reuses the same generalized docking path as station docking inside `src/game/GameApp.ts`
- High-level symbology is rendered through a dedicated 2D HUD overlay canvas layered above the 3D scene
- Production build is currently passing with `npm run build`
## Known Limitations / Caveats
- Orbital behavior is still an approximation for gameplay, not a full orbital mechanics simulation
- Stations are on Lagrange-style offsets, but not using a physically rigorous orbital solver
- Ship transfer paths are curved and orbit-biased, but still use authored steering rather than patched conics or n-body integration
- Fuel / energy exist but station refueling, resupply, and depletion failure states are still minimal
- Module definitions exist, and a generic window framework now exists, but there is still no actual ship/station designer yet
- Production is still automated by recipe priority; there is not yet a player-facing queue UI for choosing or reordering station recipes
- Constructible recipes currently output kit items, but build mode still spawns structures directly rather than consuming those kits
- Docking works for logistics, but there is not yet a richer docking queue / reservation UI
- NATO-style symbology is gameplay-oriented inspiration, not a strict APP-6 / MIL-STD implementation
- Fleet orders currently cover patrol, move, hold, and mining, but wing-specific doctrine editing is still minimal
- Carrier recovery exists, but launch/redeploy flows and richer carrier doctrine are still minimal
- Window positions and sizes are not yet persisted across reloads
- `GameApp.ts` is still carrying too much simulation responsibility.
- Faction AI is improved, but still fairly heuristic and not yet a deep planning system.
- Combat is lightweight and does not yet model formations, threat evaluation, or target priorities in a sophisticated way.
- Economic logistics are still abstracted heavily.
- Ship construction is recipe-gated but still simplified.
- Stations consume pooled faction stock rather than explicit transport delivery chains.
- Fleet window remains useful, but the overall UI is now only partially refit for observer mode.
- There is still no persistence layer for window layouts, saves, or generated universe seeds.
## Suggested Next Steps
- Continue shrinking `GameApp.ts` by extracting simulation/order logic into dedicated gameplay systems once the current rules stabilize
- Add JSON schema validation or runtime validation for the authored data catalogs to catch content errors earlier
- Move constructible placement and future unit spawning onto a shared scenario/entity factory pipeline
- Introduce explicit orbital anchors for:
- stars
- planets
- stations
- asteroid belts / resource fields
- Replace the current movement approximation with a more formal orbital transfer model
- Add refueling and power management gameplay
- Add ship/station fitting data structures that can later drive a designer UI
- Expand the economy beyond ore/refining into manufactured goods and trade lanes
- Improve FTL visuals with a fullscreen post-process distortion or tunnel effect
- Expand the strategic overlay with threat rings, route arrows, and fleet stance/status markers
- Extract fleet command propagation and ship AI execution out of `GameApp.ts` into dedicated simulation systems now that the fleet model has stabilized enough to justify it
- Extract faction strategy into a dedicated AI / planning module
- Extract fleet order execution into its own gameplay system
- Separate economic simulation from UI and rendering concerns
- Improve transport logistics so goods physically move through faction supply chains
- Add explicit shipyard construction queues and faction production priorities
- Improve combat behavior so `screen`, `escort`, and `command` have stronger distinct tactical roles
- Add system-level threat, ownership, and economy views for game-master inspection
- Add save/load support for generated universes and long-running simulations