From 7ef42e520213f317deba233903448ecbf77bf62b Mon Sep 17 00:00:00 2001 From: hal8174 Date: Thu, 24 Apr 2025 20:49:05 +0200 Subject: [PATCH] Add wagon inserter options to multistation --- .../src/bin/multistation.rs | 18 ++++- .../src/bin/station.rs | 4 + factorio-blueprint-generator/src/factory.rs | 8 +- .../src/multistation.rs | 6 +- factorio-blueprint-generator/src/station.rs | 81 +++++++++++++------ factorio-blueprint/src/abstraction.rs | 5 +- 6 files changed, 89 insertions(+), 33 deletions(-) diff --git a/factorio-blueprint-generator/src/bin/multistation.rs b/factorio-blueprint-generator/src/bin/multistation.rs index 6717d7e..8996678 100644 --- a/factorio-blueprint-generator/src/bin/multistation.rs +++ b/factorio-blueprint-generator/src/bin/multistation.rs @@ -1,6 +1,7 @@ use clap::Parser; use factorio_blueprint::abstraction::serde::AbstractBlueprintString; -use factorio_blueprint::{BlueprintString, encode}; +use factorio_blueprint::abstraction::{InserterType, Quality}; +use factorio_blueprint::encode; use factorio_blueprint_generator::multistation::{StationSpec, multistation}; use factorio_core::beltoptions::{Beltspeed, Belttype}; use factorio_core::visualize::Visualize; @@ -9,6 +10,13 @@ use factorio_core::visualize::Visualize; struct Args { #[arg(short, long)] json: bool, + + #[arg(short, long, default_value = "bulk")] + wagon_inserter_type: InserterType, + + #[arg(short, long, default_value = "normal")] + wagon_inserter_quality: Quality, + stacker_size: usize, /// format: -[lu][nfet][lr]? stations: Vec, @@ -61,7 +69,13 @@ fn main() { dbg!(&stations); - let mut b = multistation(&stations, args.stacker_size).0; + let mut b = multistation( + &stations, + args.stacker_size, + args.wagon_inserter_type, + args.wagon_inserter_quality, + ) + .0; b.connect_power_networks(); diff --git a/factorio-blueprint-generator/src/bin/station.rs b/factorio-blueprint-generator/src/bin/station.rs index 1db7d89..ce9ebc8 100644 --- a/factorio-blueprint-generator/src/bin/station.rs +++ b/factorio-blueprint-generator/src/bin/station.rs @@ -70,6 +70,8 @@ fn main() { beltspeed, Belttype::Full, false, + factorio_blueprint::abstraction::InserterType::Bulk, + factorio_blueprint::abstraction::Quality::Normal, ); inner_inner_b.push(BlueprintBookEntry::new( @@ -138,6 +140,8 @@ fn main() { beltspeed, belttype, false, + factorio_blueprint::abstraction::InserterType::Bulk, + factorio_blueprint::abstraction::Quality::Normal, ) .to_blueprint(), ); diff --git a/factorio-blueprint-generator/src/factory.rs b/factorio-blueprint-generator/src/factory.rs index 050a3ef..01164e3 100644 --- a/factorio-blueprint-generator/src/factory.rs +++ b/factorio-blueprint-generator/src/factory.rs @@ -780,8 +780,12 @@ pub fn generate_factory (Blueprint, PositionType, Vec) { let longest_train = stations .iter() @@ -270,6 +272,8 @@ pub fn multistation( station.beltspeed, station.belttype, station.stacked, + wagon_inserter_type, + wagon_inserter_quality, ); let output_height = -b.bounding_box().min().y; diff --git a/factorio-blueprint-generator/src/station.rs b/factorio-blueprint-generator/src/station.rs index 9d29a4a..8bc0adc 100644 --- a/factorio-blueprint-generator/src/station.rs +++ b/factorio-blueprint-generator/src/station.rs @@ -10,6 +10,8 @@ pub fn unloader( beltspeed: Beltspeed, belttype: Belttype, stacked: bool, + wagon_inserter_type: InserterType, + wagon_inserter_quality: Quality, ) -> (Blueprint, PositionType) { let mut b = Blueprint::new(); @@ -20,7 +22,7 @@ pub fn unloader( (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::Express, true) => (InserterType::Stack, Some(12), Quality::Rare), (Beltspeed::Turbo, true) => (InserterType::Stack, None, Quality::Epic), }; if beltspeed == Beltspeed::Normal { @@ -37,12 +39,15 @@ pub fn unloader( Direction::Up, Position::new(2, 2), )); - b.add_entity(Entity::new_inserter( - InserterType::Bulk, - None, - Position::new(1, 1) + 2 * Position::new(5, -1), - Direction::Down, - )); + b.add_entity( + Entity::new_inserter( + wagon_inserter_type, + None, + Position::new(1, 1) + 2 * Position::new(5, -1), + Direction::Down, + ) + .quality(wagon_inserter_quality), + ); b.add_entity( Entity::new_inserter( @@ -62,12 +67,15 @@ pub fn unloader( Direction::Up, Position::new(2, 2), )); - b.add_entity(Entity::new_inserter( - InserterType::Bulk, - None, - Position::new(1, 1) + 2 * Position::new(1, -1), - Direction::Down, - )); + b.add_entity( + Entity::new_inserter( + wagon_inserter_type, + None, + Position::new(1, 1) + 2 * Position::new(1, -1), + Direction::Down, + ) + .quality(wagon_inserter_quality), + ); b.add_entity( Entity::new_inserter( @@ -109,12 +117,15 @@ pub fn unloader( Direction::Up, Position::new(2, 2), )); - b.add_entity(Entity::new_inserter( - InserterType::Bulk, - None, - Position::new(1, 1) + 2 * Position::new(x, -1), - Direction::Down, - )); + b.add_entity( + Entity::new_inserter( + wagon_inserter_type, + None, + Position::new(1, 1) + 2 * Position::new(x, -1), + Direction::Down, + ) + .quality(wagon_inserter_quality), + ); }; if belttype.contains_left() { @@ -131,7 +142,12 @@ pub fn unloader( } } -pub fn one_loader(beltspeed: Beltspeed, stacked: bool) -> (Blueprint, PositionType) { +pub fn one_loader( + beltspeed: Beltspeed, + stacked: bool, + wagon_inserter_type: InserterType, + wagon_inserter_quality: Quality, +) -> (Blueprint, PositionType) { let (belt_inserter, quality) = match (beltspeed, stacked) { (Beltspeed::Normal, false) => (InserterType::Fast, Quality::Normal), (Beltspeed::Fast, false) => (InserterType::Fast, Quality::Normal), @@ -174,12 +190,15 @@ pub fn one_loader(beltspeed: Beltspeed, stacked: bool) -> (Blueprint, PositionTy Direction::Up, Position::new(2, 2), )); - b.add_entity(Entity::new_inserter( - InserterType::Bulk, - None, - Position::new(x, -1), - Direction::Up, - )); + b.add_entity( + Entity::new_inserter( + wagon_inserter_type, + None, + Position::new(x, -1), + Direction::Up, + ) + .quality(wagon_inserter_quality), + ); } (b, -6) @@ -193,6 +212,8 @@ pub fn basic_station( beltspeed: Beltspeed, belttype: Belttype, stacked: bool, + wagon_inserter_type: InserterType, + wagon_inserter_quality: Quality, ) -> Blueprint { let section_size = length / outputs; assert!(length % outputs == 0); @@ -223,10 +244,14 @@ pub fn basic_station( beltspeed.halvings((length / outputs).ilog2() as usize), belttype, stacked, + wagon_inserter_type, + wagon_inserter_quality, ), true => one_loader( beltspeed.halvings((length / outputs).ilog2() as usize), stacked, + wagon_inserter_type, + wagon_inserter_quality, ), }; for l in 0..length { @@ -235,10 +260,14 @@ pub fn basic_station( beltspeed.halvings((length / outputs).ilog2() as usize), belttype, stacked, + wagon_inserter_type, + wagon_inserter_quality, ), true => one_loader( beltspeed.halvings((length / outputs).ilog2() as usize), stacked, + wagon_inserter_type, + wagon_inserter_quality, ), }; diff --git a/factorio-blueprint/src/abstraction.rs b/factorio-blueprint/src/abstraction.rs index d6eb50c..9825fb6 100644 --- a/factorio-blueprint/src/abstraction.rs +++ b/factorio-blueprint/src/abstraction.rs @@ -1,4 +1,5 @@ use crate::{BlueprintEntity, BlueprintPosition}; +use clap::ValueEnum; use factorio_core::{ aabb::AABB, beltoptions::Beltspeed, @@ -24,7 +25,7 @@ pub enum UndergroundType { Output, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)] pub enum InserterType { Burner, Normal, @@ -82,7 +83,7 @@ impl ElectricPoleType { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)] pub enum Quality { Normal, Uncommon,