nil_core/world/
continent.rs1use crate::continent::{Continent, Coord, Field};
5use crate::error::{Error, Result};
6use crate::world::World;
7use rand::seq::IteratorRandom;
8
9impl World {
10 #[inline]
11 pub fn continent(&self) -> &Continent {
12 &self.continent
13 }
14
15 pub(super) fn find_spawn_point(&mut self) -> Result<(Coord, &mut Field)> {
16 let size = self.continent.size();
17 let pm = &self.precursor_manager;
18 let coord = self
19 .continent
20 .enumerate_fields()
21 .filter(|(_, field)| field.is_empty())
22 .filter_map(|(idx, _)| idx.to_coord(size).ok())
23 .filter(|coord| !pm.is_within_territory(*coord, size))
24 .choose_stable(&mut rand::rng())
25 .ok_or(Error::WorldIsFull)?;
26
27 Ok((coord, self.continent.field_mut(coord)?))
28 }
29}