From d26449195bbfe1173b79b08b92c9c906c69bf962 Mon Sep 17 00:00:00 2001 From: hal8174 Date: Sat, 10 May 2025 22:22:35 +0200 Subject: [PATCH] Refactor StationSpec --- .../src/bin/multistation.rs | 82 +-- .../src/bin/station.rs | 49 +- factorio-blueprint-generator/src/factory.rs | 76 +-- .../src/multistation.rs | 534 ++++++++++-------- factorio-blueprint-generator/src/station.rs | 239 ++++++-- 5 files changed, 570 insertions(+), 410 deletions(-) diff --git a/factorio-blueprint-generator/src/bin/multistation.rs b/factorio-blueprint-generator/src/bin/multistation.rs index dfc3197..453bedf 100644 --- a/factorio-blueprint-generator/src/bin/multistation.rs +++ b/factorio-blueprint-generator/src/bin/multistation.rs @@ -2,8 +2,8 @@ use clap::Parser; use factorio_blueprint::abstraction::serde::AbstractBlueprintString; use factorio_blueprint::abstraction::{ChestType, InserterType, Quality}; use factorio_blueprint::encode; -use factorio_blueprint_generator::multistation::{StationSpec, multistation}; -use factorio_blueprint_generator::station::StationBasicSpec; +use factorio_blueprint_generator::multistation::multistation; +use factorio_blueprint_generator::station::StationSpec; use factorio_core::beltoptions::{Beltspeed, Belttype}; use factorio_core::visualize::Visualize; @@ -38,55 +38,57 @@ fn main() { .map(|os| { let (locomotives, s) = os.split_once('-').expect("extracting locomotive count"); - let (wagons, s) = s.split_at(s.find(['u', 'l']).expect("extracting wagon count")); + let (wagons, s) = s.split_at(s.find(['u', 'l', 'e']).expect("extracting wagon count")); let (load, s) = s.split_at_checked(1).expect("extracting direction"); - let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes"); + match load { + "l" | "u" => { + let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes"); - let lanes = s.trim_end_matches(['r', 'l', 's']); + let lanes = s.trim_end_matches(['r', 'l', 's']); - StationSpec { - locomotives: locomotives.parse().expect("parsing locomotive count"), - wagons: wagons.parse().expect("parsing wagon count"), - load: match load { - "l" => true, - "u" => false, - _ => panic!("unknown directino {load}"), - }, - beltspeed: match beltspeed { - "n" => Beltspeed::Normal, - "f" => Beltspeed::Fast, - "e" => Beltspeed::Express, - "t" => Beltspeed::Turbo, - _ => panic!("unknown belt speed {beltspeed}"), - }, - lanes: lanes.parse().expect("parsing lane count"), - belttype: if s.contains('l') { - Belttype::Left - } else if s.contains('r') { - Belttype::Right - } else { - Belttype::Full - }, - stacked: s.contains('s'), + StationSpec::new_belt( + locomotives.parse().expect("parsing locomotive count"), + wagons.parse().expect("parsing wagon count"), + format!("test"), + match load { + "l" => true, + "u" => false, + _ => panic!("unknown directino {load}"), + }, + match beltspeed { + "n" => Beltspeed::Normal, + "f" => Beltspeed::Fast, + "e" => Beltspeed::Express, + "t" => Beltspeed::Turbo, + _ => panic!("unknown belt speed {beltspeed}"), + }, + lanes.parse().expect("parsing lane count"), + if s.contains('l') { + Belttype::Left + } else if s.contains('r') { + Belttype::Right + } else { + Belttype::Full + }, + s.contains('s'), + ) + } + "e" => StationSpec::new_empty( + locomotives.parse().expect("parsing locomotive count"), + wagons.parse().expect("parsing wagon count"), + format!("test"), + s.parse().expect("Unable to parse space"), + ), + _ => panic!("unknown station type"), } }) .collect::>(); dbg!(&stations); - let mut b = multistation( - &stations, - args.stacker_size, - &StationBasicSpec { - inserter_type: args.wagon_inserter_type, - inserter_quality: args.wagon_inserter_quality, - chest_type: args.chest_type, - chest_quality: args.chest_quality, - }, - ) - .0; + let mut b = multistation(&stations, args.stacker_size).0; b.connect_power_networks(); diff --git a/factorio-blueprint-generator/src/bin/station.rs b/factorio-blueprint-generator/src/bin/station.rs index b35fcaf..9e91b51 100644 --- a/factorio-blueprint-generator/src/bin/station.rs +++ b/factorio-blueprint-generator/src/bin/station.rs @@ -1,9 +1,6 @@ use clap::{Parser, Subcommand}; use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode}; -use factorio_blueprint_generator::{ - multistation::StationSpec, - station::{StationBasicSpec, basic_station}, -}; +use factorio_blueprint_generator::station::{StationSpec, station}; use factorio_core::beltoptions::{Beltspeed, Belttype}; #[derive(Parser)] @@ -65,18 +62,16 @@ fn main() { for (l, o) in (0..=(cargo as u32).ilog2()).enumerate() { let o = 1 << o; - let blueprint = basic_station( - &StationSpec { - locomotives, - wagons: cargo, - load, - beltspeed, - lanes: o, - belttype: Belttype::Full, - stacked: false, - }, - &factorio_blueprint_generator::station::StationBasicSpec::default(), - ); + let blueprint = station(&StationSpec::new_belt( + locomotives, + cargo, + format!("test"), + load, + beltspeed, + o, + Belttype::Full, + false, + )); inner_inner_b.push(BlueprintBookEntry::new( BlueprintString::Blueprint(blueprint.to_blueprint()), @@ -136,18 +131,16 @@ fn main() { belttype, } => { let b = BlueprintString::Blueprint( - basic_station( - &StationSpec { - locomotives, - wagons: length, - load, - beltspeed, - lanes: outputs, - belttype, - stacked: false, - }, - &StationBasicSpec::default(), - ) + station(&StationSpec::new_belt( + locomotives, + length, + format!("test"), + load, + beltspeed, + outputs, + belttype, + false, + )) .to_blueprint(), ); diff --git a/factorio-blueprint-generator/src/factory.rs b/factorio-blueprint-generator/src/factory.rs index c5f6ad3..5de8943 100644 --- a/factorio-blueprint-generator/src/factory.rs +++ b/factorio-blueprint-generator/src/factory.rs @@ -1,5 +1,6 @@ use crate::{ - multistation::{StationSpec, multistation}, + multistation::multistation, + station::{StationSpec, StationType}, subfactory::{BeltConnection, SubFactory}, }; use factorio_blueprint::abstraction::{Blueprint, Entity}; @@ -406,23 +407,29 @@ pub fn generate_factory (Blueprint, PositionType, Vec) { let longest_train = stations .iter() - .map(|s| s.locomotives + s.wagons) + .map(|s| s.train_information.locomotives + s.train_information.wagons) .max() .unwrap(); @@ -167,7 +152,7 @@ pub fn multistation( let mut output_heights = Vec::new(); let mut previous_station_heights = 0; // station - for (i, station) in stations.iter().enumerate() { + for (i, station_spec) in stations.iter().enumerate() { // in turn blueprint.add_entity(Entity::new_rail( RailType::CurvedA, @@ -253,7 +238,9 @@ pub fn multistation( )); for j in 0..((7 * longest_train).div_ceil(2) - - (7 * (station.locomotives + station.wagons)).div_ceil(2)) + - (7 * (station_spec.train_information.locomotives + + station_spec.train_information.wagons)) + .div_ceil(2)) { blueprint.add_entity(Entity::new_rail( RailType::Straight, @@ -266,7 +253,7 @@ pub fn multistation( } // station - let mut b = basic_station(station, basic_spec); + let mut b = station(station_spec); let output_height = -b.bounding_box().min().y; b.transform(Transformation::new( @@ -279,104 +266,259 @@ pub fn multistation( blueprint.add_blueprint(b); - // belt output - let station_height = - calculate_station_height(output_height, station.lanes, station.beltspeed); + let station_height = match &station_spec.station_type { + crate::station::StationType::Empty(station_type_empty) => 4 + station_type_empty.space, + crate::station::StationType::Belt(station_type_belt) => { + // belt output + let station_height = calculate_station_height( + output_height, + station_type_belt.lanes, + station_type_belt.beltspeed, + ); - output_heights.push(30 + total_stacker_height + previous_station_heights + output_height); + output_heights + .push(30 + total_stacker_height + previous_station_heights + output_height); - // rail crossing - let (beltdirection, underground_left, underground_right) = match station.load { - true => ( - Direction::Left, - UndergroundType::Output, - UndergroundType::Input, - ), - false => ( - Direction::Right, - UndergroundType::Input, - UndergroundType::Output, - ), - }; - let mut belt_x = outrail_x - 28 - 14 * station.locomotives as PositionType - 3 - + 2 * (station.wagons / station.lanes).ilog2() as PositionType; - - let (balancer_length, mut b) = binary_balancer(station.lanes, station.beltspeed); - - if station.load { - b.transform(Transformation::new( - Direction::Down, - Position::new(balancer_length, 2 * station.lanes as PositionType), - )); - } - - b.transform(Transformation::new( - Direction::Up, - Position::new( - belt_x - 1, - 31 + total_stacker_height + previous_station_heights + output_height - - 2 * station.lanes as PositionType, - ), - )); - - blueprint.add_blueprint(b); - - belt_x += balancer_length; - - for j in 0..station.lanes { - let (underground_x, signal) = match station_height - - (output_height - 2 * j as PositionType) - { - 5 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 23, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, + // rail crossing + let (beltdirection, underground_left, underground_right) = + match station_type_belt.load { + true => ( + Direction::Left, + UndergroundType::Output, + UndergroundType::Input, ), - beltdirection, - )); - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_right, - Position::new( - outrail_x - 9, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, + false => ( + Direction::Right, + UndergroundType::Input, + UndergroundType::Output, ), - beltdirection, + }; + let mut belt_x = outrail_x + - 28 + - 14 * station_spec.train_information.locomotives as PositionType + - 3 + + 2 * (station_spec.train_information.wagons / station_type_belt.lanes).ilog2() + as PositionType; + + let (balancer_length, mut b) = + binary_balancer(station_type_belt.lanes, station_type_belt.beltspeed); + + if station_type_belt.load { + b.transform(Transformation::new( + Direction::Down, + Position::new(balancer_length, 2 * station_type_belt.lanes as PositionType), )); - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 7, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 23, false) } - 7 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 17, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - if station.beltspeed != Beltspeed::Turbo { + + b.transform(Transformation::new( + Direction::Up, + Position::new( + belt_x - 1, + 31 + total_stacker_height + previous_station_heights + output_height + - 2 * station_type_belt.lanes as PositionType, + ), + )); + + blueprint.add_blueprint(b); + + belt_x += balancer_length; + + for j in 0..station_type_belt.lanes { + let (underground_x, signal) = + match station_height - (output_height - 2 * j as PositionType) { + 5 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 23, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_right, + Position::new( + outrail_x - 9, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 7, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 23, false) + } + 7 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 17, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + if station_type_belt.beltspeed != Beltspeed::Turbo { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_right, + Position::new( + outrail_x - 7, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 5, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + } + (outrail_x - 17, false) + } + 9 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 15, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 15, false) + } + 11 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 11, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 11, false) + } + 13 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 9, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 9, false) + } + 15 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 9, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 9, true) + } + 17 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 7, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 7, false) + } + 19 | 21 | 23 => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 5, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 5, false) + } + _ => { + blueprint.add_entity(Entity::new_underground_belt( + station_type_belt.beltspeed, + underground_left, + Position::new( + outrail_x - 3, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + (outrail_x - 3, false) + } + }; + + if signal { blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, + station_type_belt.beltspeed, underground_right, Position::new( - outrail_x - 7, + outrail_x + 5, 30 + total_stacker_height + previous_station_heights + output_height @@ -384,11 +526,23 @@ pub fn multistation( ), beltdirection, )); + } else { blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, + station_type_belt.beltspeed, + underground_right, Position::new( - outrail_x - 5, + outrail_x + 3, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + blueprint.add_entity(Entity::new_belt( + station_type_belt.beltspeed, + Position::new( + outrail_x + 5, 30 + total_stacker_height + previous_station_heights + output_height @@ -397,146 +551,24 @@ pub fn multistation( beltdirection, )); } - (outrail_x - 17, false) - } - 9 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 15, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 15, false) - } - 11 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 11, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 11, false) - } - 13 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 9, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 9, false) - } - 15 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 9, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 9, true) - } - 17 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 7, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 7, false) - } - 19 | 21 | 23 => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 5, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 5, false) - } - _ => { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_left, - Position::new( - outrail_x - 3, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - (outrail_x - 3, false) - } - }; - if signal { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_right, - Position::new( - outrail_x + 5, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - } else { - blueprint.add_entity(Entity::new_underground_belt( - station.beltspeed, - underground_right, - Position::new( - outrail_x + 3, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - blueprint.add_entity(Entity::new_belt( - station.beltspeed, - Position::new( - outrail_x + 5, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); + for l in 0..((underground_x - belt_x) / 2) { + blueprint.add_entity(Entity::new_belt( + station_type_belt.beltspeed, + Position::new( + belt_x + 2 * l, + 30 + total_stacker_height + + previous_station_heights + + output_height + - 2 * j as PositionType, + ), + beltdirection, + )); + } + } + station_height } - - for l in 0..((underground_x - belt_x) / 2) { - blueprint.add_entity(Entity::new_belt( - station.beltspeed, - Position::new( - belt_x + 2 * l, - 30 + total_stacker_height + previous_station_heights + output_height - - 2 * j as PositionType, - ), - beltdirection, - )); - } - } + }; // rail connection if i != stations.len() - 1 { diff --git a/factorio-blueprint-generator/src/station.rs b/factorio-blueprint-generator/src/station.rs index 5d32be5..b012fa7 100644 --- a/factorio-blueprint-generator/src/station.rs +++ b/factorio-blueprint-generator/src/station.rs @@ -6,15 +6,112 @@ use factorio_core::{ prelude::*, }; -use crate::{binary_merger::merger, multistation::StationSpec}; +use crate::binary_merger::merger; -pub struct StationBasicSpec { +#[derive(Debug)] +pub struct StationSpec { + pub train_information: TrainInformation, + pub station_name: String, + pub station_type: StationType, +} + +#[derive(Debug)] +pub struct TrainInformation { + pub locomotives: usize, + pub wagons: usize, +} + +#[derive(Debug)] +pub enum StationType { + Empty(StationTypeEmpty), + Belt(StationTypeBelt), +} + +#[derive(Debug)] +pub struct StationTypeEmpty { + pub space: PositionType, +} + +#[derive(Debug)] +pub struct StationTypeBelt { + pub load: bool, + pub beltspeed: Beltspeed, + pub lanes: usize, + pub belttype: Belttype, + pub stacked: bool, pub inserter_type: InserterType, pub inserter_quality: Quality, pub chest_type: ChestType, pub chest_quality: Quality, } +#[derive(Debug)] +struct StationBasicSpec { + inserter_type: InserterType, + inserter_quality: Quality, + chest_type: ChestType, + chest_quality: Quality, +} + +impl StationSpec { + pub fn new( + locomotives: usize, + wagons: usize, + station_name: String, + station_type: StationType, + ) -> Self { + Self { + train_information: TrainInformation { + locomotives, + wagons, + }, + station_name, + station_type, + } + } + pub fn new_belt( + locomotives: usize, + wagons: usize, + station_name: String, + load: bool, + beltspeed: Beltspeed, + lanes: usize, + belttype: Belttype, + stacked: bool, + ) -> Self { + Self::new( + locomotives, + wagons, + station_name, + StationType::Belt(StationTypeBelt { + load, + beltspeed, + lanes, + belttype, + stacked, + inserter_type: InserterType::Bulk, + inserter_quality: Quality::Normal, + chest_type: ChestType::Steel, + chest_quality: Quality::Normal, + }), + ) + } + + pub fn new_empty( + locomotives: usize, + wagons: usize, + station_name: String, + space: PositionType, + ) -> Self { + Self::new( + locomotives, + wagons, + station_name, + StationType::Empty(StationTypeEmpty { space }), + ) + } +} + impl Default for StationBasicSpec { fn default() -> Self { Self { @@ -26,7 +123,7 @@ impl Default for StationBasicSpec { } } -pub fn unloader( +fn unloader( beltspeed: Beltspeed, belttype: Belttype, stacked: bool, @@ -164,7 +261,7 @@ pub fn unloader( } } -pub fn one_loader( +fn one_loader( beltspeed: Beltspeed, stacked: bool, basic_spec: &StationBasicSpec, @@ -223,20 +320,28 @@ pub fn one_loader( (b, -6) } -#[allow(clippy::too_many_arguments)] -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); +fn belt_station( + blueprint: &mut Blueprint, + train_information: &TrainInformation, + station_type_belt: &StationTypeBelt, +) { + let section_size = train_information.wagons / station_type_belt.lanes; + assert!(train_information.wagons % station_type_belt.lanes == 0); assert!(section_size.is_power_of_two()); - assert!(station_spec.lanes <= station_spec.wagons); + assert!(station_type_belt.lanes <= train_information.wagons); - let mut blueprint = Blueprint::new(); + let global_x_offset = train_information.locomotives * 7; - let global_x_offset = station_spec.locomotives * 7; + let basic_spec = StationBasicSpec { + inserter_type: station_type_belt.inserter_type, + inserter_quality: station_type_belt.inserter_quality, + chest_type: station_type_belt.chest_type, + chest_quality: station_type_belt.chest_quality, + }; // electric poles let mut poles = Vec::new(); - for l in 1..=(station_spec.wagons + station_spec.locomotives) { + for l in 1..=(train_information.wagons + train_information.locomotives) { poles.push(blueprint.add_entity(Entity::new_electric_pole( ElectricPoleType::Medium, Position::new(1, 1) + 2 * Position::new(7 * l as PositionType, -2), @@ -247,43 +352,42 @@ pub fn basic_station(station_spec: &StationSpec, basic_spec: &StationBasicSpec) blueprint.add_wire(a, 5, b, 5); } - // unloader - - let (_, output_y) = match station_spec.load { + let (_, output_y) = match station_type_belt.load { false => unloader( - station_spec + station_type_belt .beltspeed - .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), - station_spec.belttype, - station_spec.stacked, - basic_spec, + .halvings((train_information.wagons / station_type_belt.lanes).ilog2() as usize), + station_type_belt.belttype, + station_type_belt.stacked, + &basic_spec, ), true => one_loader( - station_spec + station_type_belt .beltspeed - .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), - station_spec.stacked, - basic_spec, + .halvings((train_information.wagons / station_type_belt.lanes).ilog2() as usize), + station_type_belt.stacked, + &basic_spec, ), }; - for l in 0..station_spec.wagons { - let (mut unloader, _) = match station_spec.load { - false => unloader( - station_spec - .beltspeed - .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), - station_spec.belttype, - station_spec.stacked, - basic_spec, - ), - true => one_loader( - station_spec - .beltspeed - .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize), - station_spec.stacked, - basic_spec, - ), - }; + for l in 0..train_information.wagons { + let (mut unloader, _) = + match station_type_belt.load { + false => unloader( + station_type_belt.beltspeed.halvings( + (train_information.wagons / station_type_belt.lanes).ilog2() as usize, + ), + station_type_belt.belttype, + station_type_belt.stacked, + &basic_spec, + ), + true => one_loader( + station_type_belt.beltspeed.halvings( + (train_information.wagons / station_type_belt.lanes).ilog2() as usize, + ), + station_type_belt.stacked, + &basic_spec, + ), + }; unloader.transform(Transformation::new( Direction::Up, @@ -293,6 +397,27 @@ pub fn basic_station(station_spec: &StationSpec, basic_spec: &StationBasicSpec) blueprint.add_blueprint(unloader); } + let mut m = merger( + station_type_belt.load, + station_type_belt.beltspeed, + 7, + station_type_belt.lanes, + train_information.wagons, + ); + + m.transform(Transformation::new( + Direction::Up, + 2 * Position::new(global_x_offset as PositionType + 3, output_y), + )); + + blueprint.add_blueprint(m); +} + +pub fn station(station_spec: &StationSpec) -> Blueprint { + let mut blueprint = Blueprint::new(); + + // unloader + // train stop blueprint.add_entity(Entity::new_unknown( "train-stop", @@ -302,7 +427,11 @@ pub fn basic_station(station_spec: &StationSpec, basic_spec: &StationBasicSpec) )); // rails - for l in 0..(station_spec.wagons * 7 + global_x_offset).div_ceil(2) { + for l in 0..((station_spec.train_information.wagons + + station_spec.train_information.locomotives) + * 7) + .div_ceil(2) + { blueprint.add_entity(Entity::new_unknown( "straight-rail", Position::new(2 + 4 * l as PositionType, 2), @@ -311,22 +440,14 @@ pub fn basic_station(station_spec: &StationSpec, basic_spec: &StationBasicSpec) )); } - // output and merging - - let mut m = merger( - station_spec.load, - station_spec.beltspeed, - 7, - station_spec.lanes, - station_spec.wagons, - ); - - m.transform(Transformation::new( - Direction::Up, - 2 * Position::new(global_x_offset as PositionType + 3, output_y), - )); - - blueprint.add_blueprint(m); + match &station_spec.station_type { + StationType::Empty(_station_type_empty) => (), + StationType::Belt(station_type_belt) => belt_station( + &mut blueprint, + &station_spec.train_information, + station_type_belt, + ), + } blueprint }