Add single assembling line

This commit is contained in:
hal8174 2025-04-19 22:23:44 +02:00
parent cfc132f2d7
commit cd86679d65
2 changed files with 217 additions and 119 deletions

View file

@ -1,4 +1,4 @@
use assembling_line::assembly_line_2_input; use assembling_line::{assembly_line, assembly_line_2_input};
use clap::Subcommand; use clap::Subcommand;
use factorio_blueprint::abstraction::Blueprint; use factorio_blueprint::abstraction::Blueprint;
use factorio_core::{ use factorio_core::{
@ -49,8 +49,8 @@ impl SubFactory {
num_machines, num_machines,
machine, machine,
recipe, recipe,
} => todo!(), }
SubFactory::DoubleAssemblingLine { | SubFactory::DoubleAssemblingLine {
num_machines, num_machines,
machine, machine,
recipe, recipe,
@ -107,14 +107,27 @@ impl SubFactory {
unreachable!() unreachable!()
}; };
let (b, size, y_output, y_inputs) = assembly_line_2_input( let (b, size, y_output, y_inputs) =
*num_machines, if matches!(self, SubFactory::DoubleAssemblingLine { .. }) {
machine, assembly_line_2_input(
recipe.as_ref(), *num_machines,
belttype1, machine,
Some(belttype2), recipe.as_ref(),
Beltspeed::from_items_per_second(outputs[0].1), 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, b,
@ -136,14 +149,27 @@ impl SubFactory {
vec![BeltConnection::Full(outputs[0])], vec![BeltConnection::Full(outputs[0])],
) )
} else { } else {
let (b, size, y_output, y_inputs) = assembly_line_2_input( let (b, size, y_output, y_inputs) =
*num_machines, if matches!(self, SubFactory::DoubleAssemblingLine { .. }) {
machine, assembly_line_2_input(
recipe.as_ref(), *num_machines,
Beltspeed::from_items_per_second(inputs[0].1), machine,
None, recipe.as_ref(),
Beltspeed::from_items_per_second(outputs[0].1), 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, b,

View file

@ -1,17 +1,15 @@
use factorio_blueprint::abstraction::{Blueprint, ElectricPoleType, Entity, InserterType}; use factorio_blueprint::abstraction::{Blueprint, ElectricPoleType, Entity, InserterType};
use factorio_core::{beltoptions::Beltspeed, prelude::*}; use factorio_core::{beltoptions::Beltspeed, prelude::*};
/*
AAABBBCCC
*/
pub fn assembly_line( pub fn assembly_line(
assembly_machines: usize, assembly_machines: usize,
machine: impl AsRef<str>, machine: impl AsRef<str>,
recipe: Option<impl AsRef<str>>, recipe: Option<impl AsRef<str>>,
) -> Blueprint { input_belt1: Beltspeed,
input_belt2: Option<Beltspeed>,
input_belt3: Option<Beltspeed>,
output_belt: Beltspeed,
) -> (Blueprint, Position, PositionType, Vec<PositionType>) {
let mut blueprint = Blueprint::new(); let mut blueprint = Blueprint::new();
let mut last = None; let mut last = None;
for i in 0..assembly_machines.div_ceil(3) { for i in 0..assembly_machines.div_ceil(3) {
@ -45,18 +43,27 @@ pub fn assembly_line(
match i % 3 { match i % 3 {
0 => { 0 => {
blueprint.add_entity(Entity::new_inserter( if input_belt3.is_some() {
InserterType::Long, blueprint.add_entity(Entity::new_inserter(
None, InserterType::Long,
Position::new(3 + 6 * i as PositionType, 5), None,
Direction::Down, Position::new(3 + 6 * i as PositionType, 5),
)); Direction::Down,
blueprint.add_entity(Entity::new_inserter( ));
InserterType::Fast, blueprint.add_entity(Entity::new_inserter(
None, InserterType::Fast,
Position::new(5 + 6 * i as PositionType, 5), None,
Direction::Up, 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( blueprint.add_entity(Entity::new_inserter(
InserterType::Long, InserterType::Long,
None, None,
@ -71,18 +78,27 @@ pub fn assembly_line(
)); ));
} }
1 => { 1 => {
blueprint.add_entity(Entity::new_inserter( if input_belt3.is_some() {
InserterType::Long, blueprint.add_entity(Entity::new_inserter(
None, InserterType::Long,
Position::new(1 + 6 * i as PositionType, 5), None,
Direction::Down, Position::new(1 + 6 * i as PositionType, 5),
)); Direction::Down,
blueprint.add_entity(Entity::new_inserter( ));
InserterType::Fast, blueprint.add_entity(Entity::new_inserter(
None, InserterType::Fast,
Position::new(5 + 6 * i as PositionType, 5), None,
Direction::Up, 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( blueprint.add_entity(Entity::new_inserter(
InserterType::Long, InserterType::Long,
None, None,
@ -97,18 +113,27 @@ pub fn assembly_line(
)); ));
} }
2 => { 2 => {
blueprint.add_entity(Entity::new_inserter( if input_belt3.is_some() {
InserterType::Long, blueprint.add_entity(Entity::new_inserter(
None, InserterType::Long,
Position::new(1 + 6 * i as PositionType, 5), None,
Direction::Down, Position::new(1 + 6 * i as PositionType, 5),
)); Direction::Down,
blueprint.add_entity(Entity::new_inserter( ));
InserterType::Fast, blueprint.add_entity(Entity::new_inserter(
None, InserterType::Fast,
Position::new(3 + 6 * i as PositionType, 5), None,
Direction::Up, 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( blueprint.add_entity(Entity::new_inserter(
InserterType::Long, InserterType::Long,
None, 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) { 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( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt2.1,
Position::new(1 + 2 * i as PositionType, 1),
Direction::Left,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(1 + 2 * i as PositionType, 3), Position::new(1 + 2 * i as PositionType, 3),
Direction::Right, belt2.0,
)); ));
blueprint.add_entity(Entity::new_belt( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt3.1,
Position::new(1 + 2 * i as PositionType, 15), Position::new(1 + 2 * i as PositionType, 15),
Direction::Right, belt3.0,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(1 + 2 * i as PositionType, 17),
Direction::Right,
)); ));
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 { match assembly_machines % 3 {
0 => { 0 => {
let i = 3 * (assembly_machines - 1); 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( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt3.1,
Position::new(3 + 2 * i as PositionType, 3),
Direction::Right,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(3 + 2 * i as PositionType, 15), Position::new(3 + 2 * i as PositionType, 15),
Direction::Right, belt3.0,
)); ));
} }
1 => { 1 => {
let i = 3 * (assembly_machines - 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( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt2.1,
Position::new(3 + 2 * i as PositionType, 1),
Direction::Left,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(3 + 2 * i as PositionType, 3), 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( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt3.1,
Position::new(3 + 2 * i as PositionType, 15), Position::new(3 + 2 * i as PositionType, 15),
Direction::Right, belt3.0,
)); ));
blueprint.add_entity(Entity::new_belt( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt3.1,
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,
Position::new(5 + 2 * i as PositionType, 15), 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 => { 2 => {
let i = 3 * (assembly_machines - 1); 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( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt3.1,
Position::new(3 + 2 * i as PositionType, 3),
Direction::Right,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(3 + 2 * i as PositionType, 15), Position::new(3 + 2 * i as PositionType, 15),
Direction::Right, belt3.0,
)); ));
blueprint.add_entity(Entity::new_belt( blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal, belt3.1,
Position::new(5 + 2 * i as PositionType, 3),
Direction::Right,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(5 + 2 * i as PositionType, 15), Position::new(5 + 2 * i as PositionType, 15),
Direction::Right, belt3.0,
)); ));
} }
_ => unreachable!(), _ => 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( pub fn assembly_line_2_input(