45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use factorio_core::prelude::{Position, PositionType};
|
|
use factorio_pathfinding::Pathfinder;
|
|
use rand::Rng;
|
|
|
|
use crate::{
|
|
LayoutResult, Layouter,
|
|
misc::{initally_set_blocks, path_input_from_blocks_positions},
|
|
};
|
|
|
|
pub struct ValidLayout {
|
|
pub size_increases: usize,
|
|
pub retries: usize,
|
|
pub start_size: Position,
|
|
pub growth: Position,
|
|
}
|
|
|
|
impl Layouter for ValidLayout {
|
|
fn layout<R: Rng, P: Pathfinder>(
|
|
&self,
|
|
input: &crate::LayoutInput,
|
|
pathfinder: &P,
|
|
rng: &mut R,
|
|
) -> Option<LayoutResult> {
|
|
for i in 0..self.size_increases {
|
|
let size = self.start_size + i as PositionType * self.growth;
|
|
|
|
if let Some(blocks) = initally_set_blocks(input, size, self.retries, rng) {
|
|
let (connections, map) = path_input_from_blocks_positions(input, size, &blocks);
|
|
|
|
if let Some(paths) = pathfinder.find_paths(factorio_pathfinding::PathInput {
|
|
connections: &connections,
|
|
map,
|
|
}) {
|
|
return Some(LayoutResult {
|
|
positions: blocks,
|
|
path_result: paths,
|
|
size,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|
|
}
|