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 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(
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(
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,

View file

@ -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<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 last = None;
for i in 0..assembly_machines.div_ceil(3) {
@ -45,6 +43,7 @@ pub fn assembly_line(
match i % 3 {
0 => {
if input_belt3.is_some() {
blueprint.add_entity(Entity::new_inserter(
InserterType::Long,
None,
@ -57,6 +56,14 @@ pub fn assembly_line(
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,6 +78,7 @@ pub fn assembly_line(
));
}
1 => {
if input_belt3.is_some() {
blueprint.add_entity(Entity::new_inserter(
InserterType::Long,
None,
@ -83,6 +91,14 @@ pub fn assembly_line(
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,6 +113,7 @@ pub fn assembly_line(
));
}
2 => {
if input_belt3.is_some() {
blueprint.add_entity(Entity::new_inserter(
InserterType::Long,
None,
@ -109,6 +126,14 @@ pub fn assembly_line(
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(
Beltspeed::Normal,
t,
Position::new(1 + 2 * i as PositionType, 1),
Direction::Left,
d,
));
}
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,
belt3.0,
));
if let Some((d, t)) = belt4 {
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
t,
Position::new(1 + 2 * i as PositionType, 17),
Direction::Right,
d,
));
}
}
match assembly_machines % 3 {
0 => {
let i = 3 * (assembly_machines - 1);
if input_belt3.is_some() {
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
belt2.1,
Position::new(3 + 2 * i as PositionType, 3),
Direction::Right,
belt2.0,
));
}
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(
Beltspeed::Normal,
t,
Position::new(3 + 2 * i as PositionType, 1),
Direction::Left,
d,
));
}
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(
Beltspeed::Normal,
Position::new(3 + 2 * i as PositionType, 15),
Direction::Right,
));
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,
belt2.1,
Position::new(5 + 2 * i as PositionType, 3),
Direction::Right,
belt2.0,
));
}
blueprint.add_entity(Entity::new_belt(
belt3.1,
Position::new(3 + 2 * i as PositionType, 15),
belt3.0,
));
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(
Beltspeed::Normal,
belt2.1,
Position::new(3 + 2 * i as PositionType, 3),
Direction::Right,
belt2.0,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
Position::new(3 + 2 * i as PositionType, 15),
Direction::Right,
));
blueprint.add_entity(Entity::new_belt(
Beltspeed::Normal,
belt2.1,
Position::new(5 + 2 * i as PositionType, 3),
Direction::Right,
belt2.0,
));
}
blueprint.add_entity(Entity::new_belt(
belt3.1,
Position::new(3 + 2 * i as PositionType, 15),
belt3.0,
));
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(