Add wagon inserter options to multistation

This commit is contained in:
hal8174 2025-04-24 20:49:05 +02:00
parent 7638081f26
commit 7ef42e5202
6 changed files with 89 additions and 33 deletions

View file

@ -1,6 +1,7 @@
use clap::Parser; use clap::Parser;
use factorio_blueprint::abstraction::serde::AbstractBlueprintString; 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_blueprint_generator::multistation::{StationSpec, multistation};
use factorio_core::beltoptions::{Beltspeed, Belttype}; use factorio_core::beltoptions::{Beltspeed, Belttype};
use factorio_core::visualize::Visualize; use factorio_core::visualize::Visualize;
@ -9,6 +10,13 @@ use factorio_core::visualize::Visualize;
struct Args { struct Args {
#[arg(short, long)] #[arg(short, long)]
json: bool, 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, stacker_size: usize,
/// format: <locomotives>-<wagons>[lu][nfet]<lanes>[lr]? /// format: <locomotives>-<wagons>[lu][nfet]<lanes>[lr]?
stations: Vec<String>, stations: Vec<String>,
@ -61,7 +69,13 @@ fn main() {
dbg!(&stations); 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(); b.connect_power_networks();

View file

@ -70,6 +70,8 @@ fn main() {
beltspeed, beltspeed,
Belttype::Full, Belttype::Full,
false, false,
factorio_blueprint::abstraction::InserterType::Bulk,
factorio_blueprint::abstraction::Quality::Normal,
); );
inner_inner_b.push(BlueprintBookEntry::new( inner_inner_b.push(BlueprintBookEntry::new(
@ -138,6 +140,8 @@ fn main() {
beltspeed, beltspeed,
belttype, belttype,
false, false,
factorio_blueprint::abstraction::InserterType::Bulk,
factorio_blueprint::abstraction::Quality::Normal,
) )
.to_blueprint(), .to_blueprint(),
); );

View file

@ -780,8 +780,12 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
// dbg!(&blocks); // dbg!(&blocks);
// dbg!(&connections); // dbg!(&connections);
let (multistation_blueprint, multistation_x_offset, mut multistation_y_offsets) = let (multistation_blueprint, multistation_x_offset, mut multistation_y_offsets) = multistation(
multistation(&station_spec, 8); &station_spec,
8,
factorio_blueprint::abstraction::InserterType::Bulk,
factorio_blueprint::abstraction::Quality::Normal,
);
let multistation_y_offset = multistation_y_offsets[0]; let multistation_y_offset = multistation_y_offsets[0];
multistation_y_offsets.iter_mut().for_each(move |y| { multistation_y_offsets.iter_mut().for_each(move |y| {

View file

@ -1,6 +1,6 @@
use crate::{balancer::binary_balancer, station::basic_station}; use crate::{balancer::binary_balancer, station::basic_station};
use factorio_blueprint::abstraction::{ use factorio_blueprint::abstraction::{
Blueprint, ElectricPoleType, Entity, RailType, UndergroundType, Blueprint, ElectricPoleType, Entity, Quality, RailType, UndergroundType,
}; };
use factorio_core::{ use factorio_core::{
beltoptions::{Beltspeed, Belttype}, beltoptions::{Beltspeed, Belttype},
@ -50,6 +50,8 @@ fn calculate_station_height(
pub fn multistation( pub fn multistation(
stations: &[StationSpec], stations: &[StationSpec],
stacker_size: usize, stacker_size: usize,
wagon_inserter_type: factorio_blueprint::abstraction::InserterType,
wagon_inserter_quality: Quality,
) -> (Blueprint, PositionType, Vec<PositionType>) { ) -> (Blueprint, PositionType, Vec<PositionType>) {
let longest_train = stations let longest_train = stations
.iter() .iter()
@ -270,6 +272,8 @@ pub fn multistation(
station.beltspeed, station.beltspeed,
station.belttype, station.belttype,
station.stacked, station.stacked,
wagon_inserter_type,
wagon_inserter_quality,
); );
let output_height = -b.bounding_box().min().y; let output_height = -b.bounding_box().min().y;

View file

@ -10,6 +10,8 @@ pub fn unloader(
beltspeed: Beltspeed, beltspeed: Beltspeed,
belttype: Belttype, belttype: Belttype,
stacked: bool, stacked: bool,
wagon_inserter_type: InserterType,
wagon_inserter_quality: Quality,
) -> (Blueprint, PositionType) { ) -> (Blueprint, PositionType) {
let mut b = Blueprint::new(); let mut b = Blueprint::new();
@ -20,7 +22,7 @@ pub fn unloader(
(Beltspeed::Turbo, false) => (InserterType::Bulk, Some(10), Quality::Normal), (Beltspeed::Turbo, false) => (InserterType::Bulk, Some(10), Quality::Normal),
(Beltspeed::Normal, true) => (InserterType::Stack, None, Quality::Normal), (Beltspeed::Normal, true) => (InserterType::Stack, None, Quality::Normal),
(Beltspeed::Fast, 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), (Beltspeed::Turbo, true) => (InserterType::Stack, None, Quality::Epic),
}; };
if beltspeed == Beltspeed::Normal { if beltspeed == Beltspeed::Normal {
@ -37,12 +39,15 @@ pub fn unloader(
Direction::Up, Direction::Up,
Position::new(2, 2), Position::new(2, 2),
)); ));
b.add_entity(Entity::new_inserter( b.add_entity(
InserterType::Bulk, Entity::new_inserter(
None, wagon_inserter_type,
Position::new(1, 1) + 2 * Position::new(5, -1), None,
Direction::Down, Position::new(1, 1) + 2 * Position::new(5, -1),
)); Direction::Down,
)
.quality(wagon_inserter_quality),
);
b.add_entity( b.add_entity(
Entity::new_inserter( Entity::new_inserter(
@ -62,12 +67,15 @@ pub fn unloader(
Direction::Up, Direction::Up,
Position::new(2, 2), Position::new(2, 2),
)); ));
b.add_entity(Entity::new_inserter( b.add_entity(
InserterType::Bulk, Entity::new_inserter(
None, wagon_inserter_type,
Position::new(1, 1) + 2 * Position::new(1, -1), None,
Direction::Down, Position::new(1, 1) + 2 * Position::new(1, -1),
)); Direction::Down,
)
.quality(wagon_inserter_quality),
);
b.add_entity( b.add_entity(
Entity::new_inserter( Entity::new_inserter(
@ -109,12 +117,15 @@ pub fn unloader(
Direction::Up, Direction::Up,
Position::new(2, 2), Position::new(2, 2),
)); ));
b.add_entity(Entity::new_inserter( b.add_entity(
InserterType::Bulk, Entity::new_inserter(
None, wagon_inserter_type,
Position::new(1, 1) + 2 * Position::new(x, -1), None,
Direction::Down, Position::new(1, 1) + 2 * Position::new(x, -1),
)); Direction::Down,
)
.quality(wagon_inserter_quality),
);
}; };
if belttype.contains_left() { 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) { let (belt_inserter, quality) = match (beltspeed, stacked) {
(Beltspeed::Normal, false) => (InserterType::Fast, Quality::Normal), (Beltspeed::Normal, false) => (InserterType::Fast, Quality::Normal),
(Beltspeed::Fast, 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, Direction::Up,
Position::new(2, 2), Position::new(2, 2),
)); ));
b.add_entity(Entity::new_inserter( b.add_entity(
InserterType::Bulk, Entity::new_inserter(
None, wagon_inserter_type,
Position::new(x, -1), None,
Direction::Up, Position::new(x, -1),
)); Direction::Up,
)
.quality(wagon_inserter_quality),
);
} }
(b, -6) (b, -6)
@ -193,6 +212,8 @@ pub fn basic_station(
beltspeed: Beltspeed, beltspeed: Beltspeed,
belttype: Belttype, belttype: Belttype,
stacked: bool, stacked: bool,
wagon_inserter_type: InserterType,
wagon_inserter_quality: Quality,
) -> Blueprint { ) -> Blueprint {
let section_size = length / outputs; let section_size = length / outputs;
assert!(length % outputs == 0); assert!(length % outputs == 0);
@ -223,10 +244,14 @@ pub fn basic_station(
beltspeed.halvings((length / outputs).ilog2() as usize), beltspeed.halvings((length / outputs).ilog2() as usize),
belttype, belttype,
stacked, stacked,
wagon_inserter_type,
wagon_inserter_quality,
), ),
true => one_loader( true => one_loader(
beltspeed.halvings((length / outputs).ilog2() as usize), beltspeed.halvings((length / outputs).ilog2() as usize),
stacked, stacked,
wagon_inserter_type,
wagon_inserter_quality,
), ),
}; };
for l in 0..length { for l in 0..length {
@ -235,10 +260,14 @@ pub fn basic_station(
beltspeed.halvings((length / outputs).ilog2() as usize), beltspeed.halvings((length / outputs).ilog2() as usize),
belttype, belttype,
stacked, stacked,
wagon_inserter_type,
wagon_inserter_quality,
), ),
true => one_loader( true => one_loader(
beltspeed.halvings((length / outputs).ilog2() as usize), beltspeed.halvings((length / outputs).ilog2() as usize),
stacked, stacked,
wagon_inserter_type,
wagon_inserter_quality,
), ),
}; };

View file

@ -1,4 +1,5 @@
use crate::{BlueprintEntity, BlueprintPosition}; use crate::{BlueprintEntity, BlueprintPosition};
use clap::ValueEnum;
use factorio_core::{ use factorio_core::{
aabb::AABB, aabb::AABB,
beltoptions::Beltspeed, beltoptions::Beltspeed,
@ -24,7 +25,7 @@ pub enum UndergroundType {
Output, Output,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]
pub enum InserterType { pub enum InserterType {
Burner, Burner,
Normal, 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 { pub enum Quality {
Normal, Normal,
Uncommon, Uncommon,