From cd86679d65dc42e488d03693ba2b174696193209 Mon Sep 17 00:00:00 2001 From: hal8174 Date: Sat, 19 Apr 2025 22:23:44 +0200 Subject: [PATCH] Add single assembling line --- .../src/subfactory.rs | 64 +++-- .../src/subfactory/assembling_line.rs | 272 +++++++++++------- 2 files changed, 217 insertions(+), 119 deletions(-) diff --git a/factorio-blueprint-generator/src/subfactory.rs b/factorio-blueprint-generator/src/subfactory.rs index 415b1da..2553701 100644 --- a/factorio-blueprint-generator/src/subfactory.rs +++ b/factorio-blueprint-generator/src/subfactory.rs @@ -1,4 +1,4 @@ -use assembling_line::assembly_line_2_input; +use assembling_line::{assembly_line, assembly_line_2_input}; use clap::Subcommand; use factorio_blueprint::abstraction::Blueprint; use factorio_core::{ @@ -49,8 +49,8 @@ impl SubFactory { num_machines, machine, recipe, - } => todo!(), - SubFactory::DoubleAssemblingLine { + } + | SubFactory::DoubleAssemblingLine { num_machines, machine, recipe, @@ -107,14 +107,27 @@ impl SubFactory { unreachable!() }; - let (b, size, y_output, y_inputs) = assembly_line_2_input( - *num_machines, - machine, - recipe.as_ref(), - belttype1, - Some(belttype2), - Beltspeed::from_items_per_second(outputs[0].1), - ); + let (b, size, y_output, y_inputs) = + if matches!(self, SubFactory::DoubleAssemblingLine { .. }) { + assembly_line_2_input( + *num_machines, + machine, + recipe.as_ref(), + belttype1, + Some(belttype2), + Beltspeed::from_items_per_second(outputs[0].1), + ) + } else { + assembly_line( + *num_machines, + machine, + recipe.as_ref(), + belttype1, + Some(belttype2), + None, + Beltspeed::from_items_per_second(outputs[0].1), + ) + }; ( b, @@ -136,14 +149,27 @@ impl SubFactory { vec![BeltConnection::Full(outputs[0])], ) } else { - let (b, size, y_output, y_inputs) = assembly_line_2_input( - *num_machines, - machine, - recipe.as_ref(), - Beltspeed::from_items_per_second(inputs[0].1), - None, - Beltspeed::from_items_per_second(outputs[0].1), - ); + let (b, size, y_output, y_inputs) = + if matches!(self, SubFactory::DoubleAssemblingLine { .. }) { + assembly_line_2_input( + *num_machines, + machine, + recipe.as_ref(), + Beltspeed::from_items_per_second(inputs[0].1), + None, + Beltspeed::from_items_per_second(outputs[0].1), + ) + } else { + assembly_line( + *num_machines, + machine, + recipe.as_ref(), + Beltspeed::from_items_per_second(inputs[0].1), + None, + None, + Beltspeed::from_items_per_second(outputs[0].1), + ) + }; ( b, diff --git a/factorio-blueprint-generator/src/subfactory/assembling_line.rs b/factorio-blueprint-generator/src/subfactory/assembling_line.rs index ac68a94..54f7dd7 100644 --- a/factorio-blueprint-generator/src/subfactory/assembling_line.rs +++ b/factorio-blueprint-generator/src/subfactory/assembling_line.rs @@ -1,17 +1,15 @@ use factorio_blueprint::abstraction::{Blueprint, ElectricPoleType, Entity, InserterType}; use factorio_core::{beltoptions::Beltspeed, prelude::*}; -/* - -AAABBBCCC - - -*/ pub fn assembly_line( assembly_machines: usize, machine: impl AsRef, recipe: Option>, -) -> Blueprint { + input_belt1: Beltspeed, + input_belt2: Option, + input_belt3: Option, + output_belt: Beltspeed, +) -> (Blueprint, Position, PositionType, Vec) { let mut blueprint = Blueprint::new(); let mut last = None; for i in 0..assembly_machines.div_ceil(3) { @@ -45,18 +43,27 @@ pub fn assembly_line( match i % 3 { 0 => { - blueprint.add_entity(Entity::new_inserter( - InserterType::Long, - None, - Position::new(3 + 6 * i as PositionType, 5), - Direction::Down, - )); - blueprint.add_entity(Entity::new_inserter( - InserterType::Fast, - None, - Position::new(5 + 6 * i as PositionType, 5), - Direction::Up, - )); + if input_belt3.is_some() { + blueprint.add_entity(Entity::new_inserter( + InserterType::Long, + None, + Position::new(3 + 6 * i as PositionType, 5), + Direction::Down, + )); + blueprint.add_entity(Entity::new_inserter( + InserterType::Fast, + None, + Position::new(5 + 6 * i as PositionType, 5), + Direction::Up, + )); + } else { + blueprint.add_entity(Entity::new_inserter( + InserterType::Fast, + None, + Position::new(3 + 6 * i as PositionType, 5), + Direction::Down, + )); + } blueprint.add_entity(Entity::new_inserter( InserterType::Long, None, @@ -71,18 +78,27 @@ pub fn assembly_line( )); } 1 => { - blueprint.add_entity(Entity::new_inserter( - InserterType::Long, - None, - Position::new(1 + 6 * i as PositionType, 5), - Direction::Down, - )); - blueprint.add_entity(Entity::new_inserter( - InserterType::Fast, - None, - Position::new(5 + 6 * i as PositionType, 5), - Direction::Up, - )); + if input_belt3.is_some() { + blueprint.add_entity(Entity::new_inserter( + InserterType::Long, + None, + Position::new(1 + 6 * i as PositionType, 5), + Direction::Down, + )); + blueprint.add_entity(Entity::new_inserter( + InserterType::Fast, + None, + Position::new(5 + 6 * i as PositionType, 5), + Direction::Up, + )); + } else { + blueprint.add_entity(Entity::new_inserter( + InserterType::Fast, + None, + Position::new(1 + 6 * i as PositionType, 5), + Direction::Down, + )); + } blueprint.add_entity(Entity::new_inserter( InserterType::Long, None, @@ -97,18 +113,27 @@ pub fn assembly_line( )); } 2 => { - blueprint.add_entity(Entity::new_inserter( - InserterType::Long, - None, - Position::new(1 + 6 * i as PositionType, 5), - Direction::Down, - )); - blueprint.add_entity(Entity::new_inserter( - InserterType::Fast, - None, - Position::new(3 + 6 * i as PositionType, 5), - Direction::Up, - )); + if input_belt3.is_some() { + blueprint.add_entity(Entity::new_inserter( + InserterType::Long, + None, + Position::new(1 + 6 * i as PositionType, 5), + Direction::Down, + )); + blueprint.add_entity(Entity::new_inserter( + InserterType::Fast, + None, + Position::new(3 + 6 * i as PositionType, 5), + Direction::Up, + )); + } else { + blueprint.add_entity(Entity::new_inserter( + InserterType::Fast, + None, + Position::new(1 + 6 * i as PositionType, 5), + Direction::Down, + )); + } blueprint.add_entity(Entity::new_inserter( InserterType::Long, None, @@ -126,103 +151,150 @@ pub fn assembly_line( } } + let (belt1, belt2) = if let Some(input_belt3) = input_belt3 { + ( + Some((Direction::Left, output_belt)), + (Direction::Right, input_belt3), + ) + } else { + (None, (Direction::Left, output_belt)) + }; + + let belt3 = (Direction::Right, input_belt1); + let belt4 = if let Some(input_belt2) = input_belt2 { + Some((Direction::Right, input_belt2)) + } else { + None + }; + for i in 0..(3 * (assembly_machines - 1) + 1) { + if let Some((d, t)) = belt1 { + blueprint.add_entity(Entity::new_belt( + t, + Position::new(1 + 2 * i as PositionType, 1), + d, + )); + } blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(1 + 2 * i as PositionType, 1), - Direction::Left, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt2.1, Position::new(1 + 2 * i as PositionType, 3), - Direction::Right, + belt2.0, )); blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt3.1, Position::new(1 + 2 * i as PositionType, 15), - Direction::Right, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(1 + 2 * i as PositionType, 17), - Direction::Right, + belt3.0, )); + if let Some((d, t)) = belt4 { + blueprint.add_entity(Entity::new_belt( + t, + Position::new(1 + 2 * i as PositionType, 17), + d, + )); + } } match assembly_machines % 3 { 0 => { let i = 3 * (assembly_machines - 1); + if input_belt3.is_some() { + blueprint.add_entity(Entity::new_belt( + belt2.1, + Position::new(3 + 2 * i as PositionType, 3), + belt2.0, + )); + } blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(3 + 2 * i as PositionType, 3), - Direction::Right, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt3.1, Position::new(3 + 2 * i as PositionType, 15), - Direction::Right, + belt3.0, )); } 1 => { let i = 3 * (assembly_machines - 1); + if let Some((d, t)) = belt1 { + blueprint.add_entity(Entity::new_belt( + t, + Position::new(3 + 2 * i as PositionType, 1), + d, + )); + } blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(3 + 2 * i as PositionType, 1), - Direction::Left, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt2.1, Position::new(3 + 2 * i as PositionType, 3), - Direction::Right, + belt2.0, )); + if input_belt3.is_some() { + blueprint.add_entity(Entity::new_belt( + belt2.1, + Position::new(5 + 2 * i as PositionType, 3), + belt2.0, + )); + } blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt3.1, Position::new(3 + 2 * i as PositionType, 15), - Direction::Right, + belt3.0, )); blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(3 + 2 * i as PositionType, 17), - Direction::Right, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(5 + 2 * i as PositionType, 3), - Direction::Right, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt3.1, Position::new(5 + 2 * i as PositionType, 15), - Direction::Right, + belt3.0, )); + if let Some((d, t)) = belt4 { + blueprint.add_entity(Entity::new_belt( + t, + Position::new(3 + 2 * i as PositionType, 17), + d, + )); + } } 2 => { let i = 3 * (assembly_machines - 1); + if input_belt3.is_some() { + blueprint.add_entity(Entity::new_belt( + belt2.1, + Position::new(3 + 2 * i as PositionType, 3), + belt2.0, + )); + blueprint.add_entity(Entity::new_belt( + belt2.1, + Position::new(5 + 2 * i as PositionType, 3), + belt2.0, + )); + } blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(3 + 2 * i as PositionType, 3), - Direction::Right, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt3.1, Position::new(3 + 2 * i as PositionType, 15), - Direction::Right, + belt3.0, )); blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, - Position::new(5 + 2 * i as PositionType, 3), - Direction::Right, - )); - blueprint.add_entity(Entity::new_belt( - Beltspeed::Normal, + belt3.1, Position::new(5 + 2 * i as PositionType, 15), - Direction::Right, + belt3.0, )); } _ => unreachable!(), } - blueprint + if input_belt3.is_none() { + blueprint.transform(Transformation::new(Direction::Up, Position::new(0, -2))); + } + + ( + blueprint, + Position::new( + 3 * assembly_machines as PositionType, + 7 + input_belt2.is_some() as PositionType + input_belt3.is_some() as PositionType, + ), + 0, + match (input_belt2.is_some(), input_belt3.is_some()) { + (true, true) => vec![6, 7, 1], + (true, false) => vec![6, 7], + (false, true) => vec![7, 1], + (false, false) => vec![6], + }, + ) } pub fn assembly_line_2_input(