Skip to main content

GalaxyModel

Struct GalaxyModel 

Source
pub struct GalaxyModel {
    pub graph: StableGraph<SystemId, f64, Undirected>,
    pub spatial: RTree<SystemPoint>,
    pub systems: HashMap<SystemId, System>,
    pub planets: HashMap<PlanetKey, Planet>,
    pub bases: HashMap<String, PlayerBase>,
    pub biome_index: HashMap<Biome, Vec<PlanetKey>>,
    pub name_index: HashMap<String, SystemId>,
    pub address_to_id: HashMap<u64, SystemId>,
    pub node_map: HashMap<SystemId, NodeIndex>,
    pub player_state: Option<PlayerState>,
}
Expand description

The in-memory galactic model.

Three parallel data structures kept in sync:

  1. petgraph – topology (pathfinding, routing)
  2. R-tree – spatial (nearest-neighbor, radius queries)
  3. HashMaps – associative (name, biome, address lookups)

Fields§

§graph: StableGraph<SystemId, f64, Undirected>

Graph topology: nodes are systems, edge weights are distance in ly.

§spatial: RTree<SystemPoint>

3D spatial index of system positions.

§systems: HashMap<SystemId, System>

System data by ID.

§planets: HashMap<PlanetKey, Planet>

Planet data by (SystemId, planet_index).

§bases: HashMap<String, PlayerBase>

Base lookup by name (lowercase).

§biome_index: HashMap<Biome, Vec<PlanetKey>>

Biome -> list of planets with that biome.

§name_index: HashMap<String, SystemId>

System name -> SystemId (lowercase, only for named systems).

§address_to_id: HashMap<u64, SystemId>

Packed address (planet bits zeroed) -> SystemId.

§node_map: HashMap<SystemId, NodeIndex>

SystemId -> petgraph NodeIndex.

§player_state: Option<PlayerState>

Current player state (position, currencies).

Implementations§

Source§

impl GalaxyModel

Source

pub fn build_edges(&mut self, strategy: EdgeStrategy)

Build edges using the given strategy. Clears existing edges first.

Source

pub fn connect_new_system(&mut self, sys_id: SystemId, k: usize)

Add KNN edges for a single newly inserted system.

Call this after insert_system() to connect the new node to its neighbors without rebuilding the entire graph.

Source§

impl GalaxyModel

Source

pub fn new() -> Self

Create an empty GalaxyModel.

Source

pub fn from_save(save: &SaveRoot) -> Self

Build a GalaxyModel from a parsed save file.

Source

pub fn system_count(&self) -> usize

Number of systems in the model.

Source

pub fn planet_count(&self) -> usize

Number of planets in the model.

Source

pub fn base_count(&self) -> usize

Number of bases in the model.

Source

pub fn system(&self, id: &SystemId) -> Option<&System>

Look up a system by its ID.

Source

pub fn system_by_name(&self, name: &str) -> Option<(&SystemId, &System)>

Look up a system by name (case-insensitive).

Source

pub fn base(&self, name: &str) -> Option<&PlayerBase>

Look up a base by name (case-insensitive).

Source

pub fn player_position(&self) -> Option<&GalacticAddress>

Get the player’s current position, if available.

Source

pub fn planets_by_biome(&self, biome: Biome) -> Vec<&Planet>

Get all planets with a given biome.

Source

pub fn insert_system(&mut self, system: System)

Insert a new system into all indexes.

Source

pub fn insert_base(&mut self, base: PlayerBase)

Insert a base into the model.

Source§

impl GalaxyModel

Source

pub fn resolve_position( &self, address: Option<&GalacticAddress>, base_name: Option<&str>, ) -> Result<GalacticAddress, GraphError>

Resolve a reference point to a GalacticAddress.

Accepts:

  • A direct address (returned as-is)
  • A base name (looked up in the base index)
  • None for both (uses player position)
Source

pub fn nearest_systems( &self, from: &GalacticAddress, n: usize, ) -> Vec<(SystemId, f64)>

Find the N nearest systems to a reference point.

Returns (SystemId, distance_in_ly) pairs sorted by distance ascending.

Source

pub fn systems_within_radius( &self, from: &GalacticAddress, radius_ly: f64, ) -> Vec<(SystemId, f64)>

Find all systems within a radius (in light-years) of a reference point.

Returns (SystemId, distance_in_ly) pairs sorted by distance ascending.

Source

pub fn nearest_planets<'a>( &'a self, from: &GalacticAddress, n: usize, filter: &BiomeFilter, ) -> Vec<(PlanetKey, &'a Planet, f64)>

Find the N nearest planets to a reference point, with optional filtering.

Iterates systems by proximity, then checks their planets against the filter. Returns (PlanetKey, &Planet, system_distance_ly) tuples.

Source

pub fn planets_within_radius<'a>( &'a self, from: &GalacticAddress, radius_ly: f64, filter: &BiomeFilter, ) -> Vec<(PlanetKey, &'a Planet, f64)>

Find all planets within a radius that match a filter.

Source§

impl GalaxyModel

Source

pub fn shortest_path( &self, from: SystemId, to: SystemId, ) -> Result<Route, RouteError>

Find the shortest path between two systems using A* (Dijkstra with zero heuristic).

If no graph path exists, falls back to a direct Euclidean hop.

Source

pub fn tsp_nearest_neighbor( &self, start: SystemId, targets: &[SystemId], return_to_start: bool, ) -> Result<Route, RouteError>

Plan a route visiting all targets using nearest-neighbor greedy.

Uses Euclidean distances directly (not graph edges) for the TSP ordering.

Source

pub fn build_route_from_order(&self, order: &[SystemId]) -> Route

Convert an ordered list of SystemIds into a Route.

Source

pub fn two_opt_improve(&self, order: Vec<SystemId>) -> Route

Improve a route using 2-opt local search.

Iteratively reverses segments when doing so reduces total distance. Runs until no improvement is found (local optimum).

Source

pub fn tsp_two_opt( &self, start: SystemId, targets: &[SystemId], return_to_start: bool, ) -> Result<Route, RouteError>

Plan a route using nearest-neighbor + 2-opt.

Source

pub fn constrain_hops(&self, route: &Route, max_ly: f64) -> Route

Constrain a route so no hop exceeds max_ly.

Inserts intermediate known systems as waypoints when a hop is too long. Waypoints are marked with is_waypoint: true.

Source

pub fn warp_jump_count(route: &Route, warp_range: f64) -> usize

Count the number of warp jumps needed for a route at a given range.

Source

pub fn reachable_systems( &self, start: SystemId, warp_range: f64, ) -> Result<Vec<SystemId>, RouteError>

Find all systems reachable from start within a given warp range.

Uses DFS over the spatial index (no graph clone needed).

Trait Implementations§

Source§

impl Debug for GalaxyModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GalaxyModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.