Add assembly generation
This commit is contained in:
parent
fec7dd70db
commit
05f4edf83a
4 changed files with 286 additions and 0 deletions
217
factorio-blueprint-generator/src/assembly.rs
Normal file
217
factorio-blueprint-generator/src/assembly.rs
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
use factorio_blueprint::abstraction::{Blueprint, ElectricPoleType, Entity, InserterType};
|
||||
use factorio_core::{beltoptions::Beltspeed, prelude::*};
|
||||
|
||||
pub fn assembly_line(assembly_machines: usize) -> Blueprint {
|
||||
let mut blueprint = Blueprint::new();
|
||||
|
||||
let mut last = None;
|
||||
for i in 0..assembly_machines.div_ceil(3) {
|
||||
let top = blueprint.add_entity(Entity::new_electric_pole(
|
||||
ElectricPoleType::Medium,
|
||||
Position::new(9 + 18 * i as PositionType, 5),
|
||||
));
|
||||
|
||||
let bottom = blueprint.add_entity(Entity::new_electric_pole(
|
||||
ElectricPoleType::Medium,
|
||||
Position::new(9 + 18 * i as PositionType, 13),
|
||||
));
|
||||
|
||||
blueprint.add_wire(top, 5, bottom, 5);
|
||||
if let Some((last_top, last_bottom)) = last {
|
||||
blueprint.add_wire(top, 5, last_top, 5);
|
||||
blueprint.add_wire(bottom, 5, last_bottom, 5);
|
||||
}
|
||||
|
||||
last = Some((top, bottom));
|
||||
}
|
||||
|
||||
for i in 0..assembly_machines {
|
||||
blueprint.add_entity(Entity::new_production(
|
||||
"assembling-machine-3",
|
||||
"iron-gears",
|
||||
Position::new(3 + 6 * i as PositionType, 9),
|
||||
Direction::Up,
|
||||
Position::new(6, 6),
|
||||
));
|
||||
|
||||
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,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_inserter(
|
||||
InserterType::Long,
|
||||
None,
|
||||
Position::new(3 + 6 * i as PositionType, 13),
|
||||
Direction::Down,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_inserter(
|
||||
InserterType::Fast,
|
||||
None,
|
||||
Position::new(5 + 6 * i as PositionType, 13),
|
||||
Direction::Down,
|
||||
));
|
||||
}
|
||||
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,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_inserter(
|
||||
InserterType::Long,
|
||||
None,
|
||||
Position::new(1 + 6 * i as PositionType, 13),
|
||||
Direction::Down,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_inserter(
|
||||
InserterType::Fast,
|
||||
None,
|
||||
Position::new(5 + 6 * i as PositionType, 13),
|
||||
Direction::Down,
|
||||
));
|
||||
}
|
||||
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,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_inserter(
|
||||
InserterType::Long,
|
||||
None,
|
||||
Position::new(1 + 6 * i as PositionType, 13),
|
||||
Direction::Down,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_inserter(
|
||||
InserterType::Fast,
|
||||
None,
|
||||
Position::new(3 + 6 * i as PositionType, 13),
|
||||
Direction::Down,
|
||||
));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
for i in 0..(3 * (assembly_machines - 1) + 1) {
|
||||
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,
|
||||
Position::new(1 + 2 * i as PositionType, 3),
|
||||
Direction::Right,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_belt(
|
||||
Beltspeed::Normal,
|
||||
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,
|
||||
));
|
||||
}
|
||||
|
||||
match assembly_machines % 3 {
|
||||
0 => {
|
||||
let i = 3 * (assembly_machines - 1);
|
||||
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,
|
||||
Position::new(3 + 2 * i as PositionType, 15),
|
||||
Direction::Right,
|
||||
));
|
||||
}
|
||||
1 => {
|
||||
let i = 3 * (assembly_machines - 1);
|
||||
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,
|
||||
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),
|
||||
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,
|
||||
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),
|
||||
Direction::Right,
|
||||
));
|
||||
}
|
||||
2 => {
|
||||
let i = 3 * (assembly_machines - 1);
|
||||
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,
|
||||
Position::new(3 + 2 * i as PositionType, 15),
|
||||
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),
|
||||
Direction::Right,
|
||||
));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
blueprint
|
||||
}
|
||||
21
factorio-blueprint-generator/src/bin/assembly.rs
Normal file
21
factorio-blueprint-generator/src/bin/assembly.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use clap::Parser;
|
||||
use factorio_blueprint::{BlueprintString, encode};
|
||||
use factorio_blueprint_generator::assembly::assembly_line;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[arg(short, long)]
|
||||
json: bool,
|
||||
assembly_machines: usize,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
let b = BlueprintString::Blueprint(assembly_line(args.assembly_machines).to_blueprint());
|
||||
|
||||
if args.json {
|
||||
println!("{}", serde_json::to_string_pretty(&b).unwrap());
|
||||
}
|
||||
|
||||
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod assembly;
|
||||
pub mod balancer;
|
||||
pub mod binary_merger;
|
||||
pub mod station;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue