From a98e2cfb2b751d8de8afb1fe0e8a69a7774de29e Mon Sep 17 00:00:00 2001 From: hal8174 Date: Sat, 3 May 2025 15:18:10 +0200 Subject: [PATCH] Use StationSpec for basic station --- .../src/bin/station.rs | 37 +++++----- .../src/binary_merger.rs | 8 +-- .../src/multistation.rs | 11 +-- factorio-blueprint-generator/src/station.rs | 67 ++++++++++--------- 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/factorio-blueprint-generator/src/bin/station.rs b/factorio-blueprint-generator/src/bin/station.rs index c5db350..b35fcaf 100644 --- a/factorio-blueprint-generator/src/bin/station.rs +++ b/factorio-blueprint-generator/src/bin/station.rs @@ -1,6 +1,9 @@ use clap::{Parser, Subcommand}; use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode}; -use factorio_blueprint_generator::station::{StationBasicSpec, basic_station}; +use factorio_blueprint_generator::{ + multistation::StationSpec, + station::{StationBasicSpec, basic_station}, +}; use factorio_core::beltoptions::{Beltspeed, Belttype}; #[derive(Parser)] @@ -63,13 +66,15 @@ fn main() { let o = 1 << o; let blueprint = basic_station( - load, - locomotives, - cargo, - o, - beltspeed, - Belttype::Full, - false, + &StationSpec { + locomotives, + wagons: cargo, + load, + beltspeed, + lanes: o, + belttype: Belttype::Full, + stacked: false, + }, &factorio_blueprint_generator::station::StationBasicSpec::default(), ); @@ -132,13 +137,15 @@ fn main() { } => { let b = BlueprintString::Blueprint( basic_station( - load, - locomotives, - length, - outputs, - beltspeed, - belttype, - false, + &StationSpec { + locomotives, + wagons: length, + load, + beltspeed, + lanes: outputs, + belttype, + stacked: false, + }, &StationBasicSpec::default(), ) .to_blueprint(), diff --git a/factorio-blueprint-generator/src/binary_merger.rs b/factorio-blueprint-generator/src/binary_merger.rs index 9a20039..f493c29 100644 --- a/factorio-blueprint-generator/src/binary_merger.rs +++ b/factorio-blueprint-generator/src/binary_merger.rs @@ -6,12 +6,12 @@ pub fn merger( beltspeed: Beltspeed, intervall: usize, outputs: usize, - lines: usize, + inputs: usize, ) -> Blueprint { - let section_size = lines / outputs; - assert!(lines % outputs == 0); + let section_size = inputs / outputs; + assert!(inputs % outputs == 0); assert!(section_size.is_power_of_two()); - assert!(outputs <= lines); + assert!(outputs <= inputs); let mut b = Blueprint::new(); diff --git a/factorio-blueprint-generator/src/multistation.rs b/factorio-blueprint-generator/src/multistation.rs index 24f0d08..8bda938 100644 --- a/factorio-blueprint-generator/src/multistation.rs +++ b/factorio-blueprint-generator/src/multistation.rs @@ -266,16 +266,7 @@ pub fn multistation( } // station - let mut b = basic_station( - station.load, - station.locomotives, - station.wagons, - station.lanes, - station.beltspeed, - station.belttype, - station.stacked, - basic_spec, - ); + let mut b = basic_station(station, basic_spec); let output_height = -b.bounding_box().min().y; b.transform(Transformation::new( diff --git a/factorio-blueprint-generator/src/station.rs b/factorio-blueprint-generator/src/station.rs index 1f28a98..5d32be5 100644 --- a/factorio-blueprint-generator/src/station.rs +++ b/factorio-blueprint-generator/src/station.rs @@ -6,7 +6,7 @@ use factorio_core::{ prelude::*, }; -use crate::binary_merger::merger; +use crate::{binary_merger::merger, multistation::StationSpec}; pub struct StationBasicSpec { pub inserter_type: InserterType, @@ -224,28 +224,19 @@ pub fn one_loader( } #[allow(clippy::too_many_arguments)] -pub fn basic_station( - load: bool, - locomotives: usize, - length: usize, - outputs: usize, - beltspeed: Beltspeed, - belttype: Belttype, - stacked: bool, - basic_spec: &StationBasicSpec, -) -> Blueprint { - let section_size = length / outputs; - assert!(length % outputs == 0); +pub fn basic_station(station_spec: &StationSpec, basic_spec: &StationBasicSpec) -> Blueprint { + let section_size = station_spec.wagons / station_spec.lanes; + assert!(station_spec.wagons % station_spec.lanes == 0); assert!(section_size.is_power_of_two()); - assert!(outputs <= length); + assert!(station_spec.lanes <= station_spec.wagons); let mut blueprint = Blueprint::new(); - let global_x_offset = locomotives * 7; + let global_x_offset = station_spec.locomotives * 7; // electric poles let mut poles = Vec::new(); - for l in 1..=(length + locomotives) { + for l in 1..=(station_spec.wagons + station_spec.locomotives) { poles.push(blueprint.add_entity(Entity::new_electric_pole( ElectricPoleType::Medium, Position::new(1, 1) + 2 * Position::new(7 * l as PositionType, -2), @@ -258,30 +249,38 @@ pub fn basic_station( // unloader - let (_, output_y) = match load { + let (_, output_y) = match station_spec.load { false => unloader( - beltspeed.halvings((length / outputs).ilog2() as usize), - belttype, - stacked, + station_spec + .beltspeed + .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), + station_spec.belttype, + station_spec.stacked, basic_spec, ), true => one_loader( - beltspeed.halvings((length / outputs).ilog2() as usize), - stacked, + station_spec + .beltspeed + .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), + station_spec.stacked, basic_spec, ), }; - for l in 0..length { - let (mut unloader, _) = match load { + for l in 0..station_spec.wagons { + let (mut unloader, _) = match station_spec.load { false => unloader( - beltspeed.halvings((length / outputs).ilog2() as usize), - belttype, - stacked, + station_spec + .beltspeed + .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), + station_spec.belttype, + station_spec.stacked, basic_spec, ), true => one_loader( - beltspeed.halvings((length / outputs).ilog2() as usize), - stacked, + station_spec + .beltspeed + .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), + station_spec.stacked, basic_spec, ), }; @@ -303,7 +302,7 @@ pub fn basic_station( )); // rails - for l in 0..(length * 7 + global_x_offset).div_ceil(2) { + for l in 0..(station_spec.wagons * 7 + global_x_offset).div_ceil(2) { blueprint.add_entity(Entity::new_unknown( "straight-rail", Position::new(2 + 4 * l as PositionType, 2), @@ -314,7 +313,13 @@ pub fn basic_station( // output and merging - let mut m = merger(load, beltspeed, 7, outputs, length); + let mut m = merger( + station_spec.load, + station_spec.beltspeed, + 7, + station_spec.lanes, + station_spec.wagons, + ); m.transform(Transformation::new( Direction::Up,