diff --git a/factorio-blueprint-generator/src/bin/multistation.rs b/factorio-blueprint-generator/src/bin/multistation.rs index c8350df..6717d7e 100644 --- a/factorio-blueprint-generator/src/bin/multistation.rs +++ b/factorio-blueprint-generator/src/bin/multistation.rs @@ -2,7 +2,7 @@ use clap::Parser; use factorio_blueprint::abstraction::serde::AbstractBlueprintString; use factorio_blueprint::{BlueprintString, encode}; use factorio_blueprint_generator::multistation::{StationSpec, multistation}; -use factorio_core::beltoptions::Beltspeed; +use factorio_core::beltoptions::{Beltspeed, Belttype}; use factorio_core::visualize::Visualize; #[derive(Parser)] @@ -29,11 +29,7 @@ fn main() { let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes"); - let (lanes, belttype) = if s.ends_with(['l', 'r']) { - s.split_at(s.len() - 1) - } else { - (s, "") - }; + let lanes = s.trim_end_matches(['r', 'l', 's']); StationSpec { locomotives: locomotives.parse().expect("parsing locomotive count"), @@ -51,12 +47,14 @@ fn main() { _ => panic!("unknown belt speed {beltspeed}"), }, lanes: lanes.parse().expect("parsing lane count"), - belttype: match belttype { - "" => factorio_core::beltoptions::Belttype::Full, - "r" => factorio_core::beltoptions::Belttype::Right, - "l" => factorio_core::beltoptions::Belttype::Left, - _ => panic!("unknown belttype {belttype}"), + belttype: if s.contains('l') { + Belttype::Left + } else if s.contains('r') { + Belttype::Right + } else { + Belttype::Full }, + stacked: s.contains('s'), } }) .collect::>(); diff --git a/factorio-blueprint-generator/src/bin/station.rs b/factorio-blueprint-generator/src/bin/station.rs index 5c401a6..1db7d89 100644 --- a/factorio-blueprint-generator/src/bin/station.rs +++ b/factorio-blueprint-generator/src/bin/station.rs @@ -69,6 +69,7 @@ fn main() { o, beltspeed, Belttype::Full, + false, ); inner_inner_b.push(BlueprintBookEntry::new( @@ -94,10 +95,13 @@ fn main() { BlueprintBook::builder() .blueprints(inner_b) .active_index(0) - .label(format!("{locomotives}-{cargo}-{}", match load { - true => "load", - false => "unload", - })) + .label(format!( + "{locomotives}-{cargo}-{}", + match load { + true => "load", + false => "unload", + } + )) .build(), ), 2 * i as u32 + load as u32, @@ -126,8 +130,16 @@ fn main() { belttype, } => { let b = BlueprintString::Blueprint( - basic_station(load, locomotives, length, outputs, beltspeed, belttype) - .to_blueprint(), + basic_station( + load, + locomotives, + length, + outputs, + beltspeed, + belttype, + false, + ) + .to_blueprint(), ); if args.json { diff --git a/factorio-blueprint-generator/src/factory.rs b/factorio-blueprint-generator/src/factory.rs index 47d0476..050a3ef 100644 --- a/factorio-blueprint-generator/src/factory.rs +++ b/factorio-blueprint-generator/src/factory.rs @@ -413,6 +413,7 @@ pub fn generate_factory (Blueprint, PositionType) { +pub fn unloader( + beltspeed: Beltspeed, + belttype: Belttype, + stacked: bool, +) -> (Blueprint, PositionType) { let mut b = Blueprint::new(); + let (belt_inserter, stack_size, quality) = match (beltspeed, stacked) { + (Beltspeed::Normal, false) => (InserterType::Fast, None, Quality::Normal), + (Beltspeed::Fast, false) => (InserterType::Fast, None, Quality::Normal), + (Beltspeed::Express, false) => (InserterType::Bulk, Some(7), Quality::Normal), + (Beltspeed::Turbo, false) => (InserterType::Bulk, Some(10), Quality::Normal), + (Beltspeed::Normal, true) => (InserterType::Stack, None, Quality::Normal), + (Beltspeed::Fast, true) => (InserterType::Stack, None, Quality::Normal), + (Beltspeed::Express, true) => (InserterType::Stack, None, Quality::Rare), + (Beltspeed::Turbo, true) => (InserterType::Stack, None, Quality::Epic), + }; if beltspeed == Beltspeed::Normal { b.add_entity(Entity::new_belt( Beltspeed::Fast, @@ -30,12 +44,15 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, Positio Direction::Down, )); - b.add_entity(Entity::new_inserter( - InserterType::Fast, - None, - Position::new(1, 1) + 2 * Position::new(4, -2), - Direction::Right, - )); + b.add_entity( + Entity::new_inserter( + belt_inserter, + stack_size, + Position::new(1, 1) + 2 * Position::new(4, -2), + Direction::Right, + ) + .quality(quality), + ); } if belttype.contains_right() { @@ -52,23 +69,19 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, Positio Direction::Down, )); - b.add_entity(Entity::new_inserter( - InserterType::Fast, - None, - Position::new(1, 1) + 2 * Position::new(2, -2), - Direction::Left, - )); + b.add_entity( + Entity::new_inserter( + belt_inserter, + stack_size, + Position::new(1, 1) + 2 * Position::new(2, -2), + Direction::Left, + ) + .quality(quality), + ); } (b, -3) } else { - let (belt_inserter, stack_size, quality) = match beltspeed { - Beltspeed::Normal => unreachable!(), - Beltspeed::Fast => (InserterType::Fast, None, Quality::Normal), - Beltspeed::Express => (InserterType::Bulk, Some(7), Quality::Normal), - Beltspeed::Turbo => (InserterType::Bulk, Some(10), Quality::Normal), - }; - b.add_entity(Entity::new_belt( beltspeed, Position::new(1, 1) + 2 * Position::new(3, -4), @@ -118,12 +131,16 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, Positio } } -pub fn one_loader(beltspeed: Beltspeed) -> (Blueprint, PositionType) { - let (belt_inserter, quality) = match beltspeed { - Beltspeed::Normal => (InserterType::Fast, Quality::Normal), - Beltspeed::Fast => (InserterType::Bulk, Quality::Uncommon), - Beltspeed::Express => (InserterType::Bulk, Quality::Rare), - Beltspeed::Turbo => (InserterType::Bulk, Quality::Legendary), +pub fn one_loader(beltspeed: Beltspeed, stacked: bool) -> (Blueprint, PositionType) { + let (belt_inserter, quality) = match (beltspeed, stacked) { + (Beltspeed::Normal, false) => (InserterType::Fast, Quality::Normal), + (Beltspeed::Fast, false) => (InserterType::Bulk, Quality::Uncommon), + (Beltspeed::Express, false) => (InserterType::Bulk, Quality::Rare), + (Beltspeed::Turbo, false) => (InserterType::Bulk, Quality::Legendary), + (Beltspeed::Normal, true) => todo!(), + (Beltspeed::Fast, true) => todo!(), + (Beltspeed::Express, true) => todo!(), + (Beltspeed::Turbo, true) => todo!(), }; let mut b = Blueprint::new(); @@ -186,6 +203,7 @@ pub fn basic_station( outputs: usize, beltspeed: Beltspeed, belttype: Belttype, + stacked: bool, ) -> Blueprint { let section_size = length / outputs; assert!(length % outputs == 0); @@ -215,16 +233,24 @@ pub fn basic_station( false => unloader( beltspeed.halvings((length / outputs).ilog2() as usize), belttype, + stacked, + ), + true => one_loader( + beltspeed.halvings((length / outputs).ilog2() as usize), + stacked, ), - true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)), }; for l in 0..length { let (mut unloader, _) = match load { false => unloader( beltspeed.halvings((length / outputs).ilog2() as usize), belttype, + stacked, + ), + true => one_loader( + beltspeed.halvings((length / outputs).ilog2() as usize), + stacked, ), - true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)), }; unloader.transform(Transformation::new(