Add loader station
This commit is contained in:
parent
b715c4ad06
commit
505ca6ff5c
12 changed files with 479 additions and 494 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode};
|
||||
use factorio_blueprint_generator::station::basic_unload_station;
|
||||
use factorio_blueprint_generator::station::basic_station;
|
||||
use factorio_core::beltoptions::{Beltspeed, Belttype};
|
||||
|
||||
#[derive(Parser)]
|
||||
|
|
@ -13,6 +13,7 @@ struct Args {
|
|||
enum Command {
|
||||
Book,
|
||||
Single {
|
||||
load: bool,
|
||||
locomotives: usize,
|
||||
length: usize,
|
||||
outputs: usize,
|
||||
|
|
@ -41,27 +42,31 @@ fn main() {
|
|||
];
|
||||
|
||||
for (i, (locomotives, cargo)) in layouts.into_iter().enumerate() {
|
||||
for load in [false, true] {
|
||||
let mut inner_b = Vec::new();
|
||||
|
||||
let mut j = 0;
|
||||
for beltspeed in [
|
||||
for (j, beltspeed) in [
|
||||
Beltspeed::Normal,
|
||||
Beltspeed::Fast,
|
||||
Beltspeed::Express,
|
||||
Beltspeed::Turbo,
|
||||
] {
|
||||
let belttypes: &[_] = match beltspeed {
|
||||
Beltspeed::Normal => &[Belttype::Full, Belttype::Left, Belttype::Right],
|
||||
_ => &[Belttype::Full],
|
||||
};
|
||||
for &belttype in belttypes {
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let mut inner_inner_b = Vec::new();
|
||||
|
||||
for (l, o) in (0..=(cargo as u32).ilog2()).enumerate() {
|
||||
let o = 1 << o;
|
||||
|
||||
let blueprint =
|
||||
basic_unload_station(locomotives, cargo, o, beltspeed, belttype);
|
||||
let blueprint = basic_station(
|
||||
load,
|
||||
locomotives,
|
||||
cargo,
|
||||
o,
|
||||
beltspeed,
|
||||
Belttype::Full,
|
||||
);
|
||||
|
||||
inner_inner_b.push(BlueprintBookEntry::new(
|
||||
BlueprintString::Blueprint(blueprint),
|
||||
|
|
@ -74,13 +79,11 @@ fn main() {
|
|||
BlueprintBook::builder()
|
||||
.blueprints(inner_inner_b)
|
||||
.active_index(0)
|
||||
.label(format!("{:?}-{:?}", beltspeed, belttype))
|
||||
.label(format!("{:?}", beltspeed))
|
||||
.build(),
|
||||
),
|
||||
j,
|
||||
j as u32,
|
||||
));
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
|
||||
b.push(BlueprintBookEntry::new(
|
||||
|
|
@ -88,12 +91,16 @@ fn main() {
|
|||
BlueprintBook::builder()
|
||||
.blueprints(inner_b)
|
||||
.active_index(0)
|
||||
.label(format!("{locomotives}-{cargo}"))
|
||||
.label(format!("{locomotives}-{cargo}-{}", match load {
|
||||
true => "load",
|
||||
false => "unload",
|
||||
}))
|
||||
.build(),
|
||||
),
|
||||
i as u32,
|
||||
2 * i as u32 + load as u32,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let b = BlueprintString::BlueprintBook(
|
||||
BlueprintBook::builder()
|
||||
|
|
@ -105,13 +112,15 @@ fn main() {
|
|||
println!("{}", encode(&serde_json::to_string(&b).unwrap()));
|
||||
}
|
||||
Command::Single {
|
||||
load,
|
||||
locomotives,
|
||||
length,
|
||||
outputs,
|
||||
beltspeed,
|
||||
belttype,
|
||||
} => {
|
||||
let b = BlueprintString::Blueprint(basic_unload_station(
|
||||
let b = BlueprintString::Blueprint(basic_station(
|
||||
load,
|
||||
locomotives,
|
||||
length,
|
||||
outputs,
|
||||
|
|
|
|||
122
factorio-blueprint-generator/src/binary_merger.rs
Normal file
122
factorio-blueprint-generator/src/binary_merger.rs
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
use factorio_blueprint::{BlueprintEntity, BlueprintPosition};
|
||||
use factorio_core::beltoptions::Beltspeed;
|
||||
|
||||
pub fn merger(
|
||||
reverse: bool,
|
||||
beltspeed: Beltspeed,
|
||||
offset_x: f64,
|
||||
offset_y: f64,
|
||||
outer_offset: u32,
|
||||
intervall: usize,
|
||||
outputs: usize,
|
||||
lines: usize,
|
||||
) -> Vec<BlueprintEntity> {
|
||||
let section_size = lines / outputs;
|
||||
assert!(lines % outputs == 0);
|
||||
assert!(section_size.is_power_of_two());
|
||||
assert!(outputs <= lines);
|
||||
|
||||
let flip = match reverse {
|
||||
true => 8,
|
||||
false => 0,
|
||||
};
|
||||
|
||||
let mut e = Vec::new();
|
||||
|
||||
// output and merging
|
||||
for o in 0..outputs {
|
||||
// stubs
|
||||
let stubspeed = beltspeed.halvings(section_size.ilog2() as usize);
|
||||
for i in 0..section_size {
|
||||
let depth = o + i.count_ones() as usize;
|
||||
|
||||
for j in 0..depth {
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
stubspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (i + o * section_size)) as f64 + offset_x,
|
||||
offset_y - j as f64,
|
||||
),
|
||||
)
|
||||
.direction(flip)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
stubspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (i + o * section_size)) as f64 + offset_x,
|
||||
offset_y - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(match reverse {
|
||||
true => 8,
|
||||
false => 12,
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
// merger
|
||||
for i in 1..(section_size.ilog2() as usize + 1) {
|
||||
let p = 1 << i;
|
||||
let mergespeed = beltspeed.halvings((section_size.ilog2() as usize) - i);
|
||||
for j in 0..(section_size / p) {
|
||||
let depth = o + j.count_ones() as usize;
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
mergespeed.string_splitter(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (j * p + o * section_size)) as f64 - i as f64 + offset_x,
|
||||
offset_y - i as f64 + 0.5 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12 - flip)
|
||||
.build(),
|
||||
);
|
||||
e.extend((0..(7 * p / 2)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
mergespeed.halve().string(),
|
||||
offset + 1 + l as u32,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (j * p + o * section_size)) as f64 - i as f64
|
||||
+ offset_x
|
||||
+ l as f64
|
||||
+ 1.0,
|
||||
offset_y - i as f64 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12 - flip)
|
||||
.build()
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// connect
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
let step = o + section_size.ilog2() as usize;
|
||||
e.extend((0..(7 * o * section_size)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset + l as u32,
|
||||
BlueprintPosition::new(
|
||||
l as f64 + offset_x - section_size.ilog2() as f64,
|
||||
offset_y - step as f64,
|
||||
),
|
||||
)
|
||||
.direction(12 - flip)
|
||||
.build()
|
||||
}));
|
||||
}
|
||||
|
||||
e
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod balancer;
|
||||
pub mod binary_merger;
|
||||
pub mod station;
|
||||
pub mod train;
|
||||
|
|
|
|||
|
|
@ -1,178 +1,10 @@
|
|||
use factorio_blueprint::{Blueprint, BlueprintEntity, BlueprintPosition};
|
||||
use factorio_core::beltoptions::{Beltspeed, Belttype};
|
||||
|
||||
pub fn station_unload(
|
||||
length: usize,
|
||||
locomotives: usize,
|
||||
unloader: &[BlueprintEntity],
|
||||
beltspeed: Beltspeed,
|
||||
outputs: usize,
|
||||
output_x: f64,
|
||||
output_y: f64,
|
||||
) -> Blueprint {
|
||||
let section_size = length / outputs;
|
||||
assert!(length % outputs == 0);
|
||||
assert!(section_size.is_power_of_two());
|
||||
assert!(outputs <= length);
|
||||
|
||||
let mut e = Vec::new();
|
||||
|
||||
let global_x_offset = locomotives * 7;
|
||||
|
||||
// electric poles
|
||||
for l in 1..=(length + locomotives) {
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"medium-electric-pole".to_owned(),
|
||||
l as u32 - 1,
|
||||
BlueprintPosition::new((7 * l) as f64 + 0.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
// unloader
|
||||
let offset = e.len();
|
||||
for l in 0..length {
|
||||
e.extend(unloader.iter().cloned().map(|mut e| {
|
||||
e.position.x += (7 * l + global_x_offset) as f64;
|
||||
e.entity_number += (offset + unloader.len() * l) as u32;
|
||||
e
|
||||
}));
|
||||
}
|
||||
|
||||
// train stop
|
||||
let offset = e.len();
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"train-stop".to_owned(),
|
||||
offset as u32,
|
||||
BlueprintPosition::new(1.0, -1.0),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
|
||||
// rails
|
||||
for l in 0..((length * 7 + global_x_offset + 1) / 2) {
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"straight-rail".to_owned(),
|
||||
offset,
|
||||
BlueprintPosition::new(2.0 * l as f64 + 1.0, 1.0),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
// output and merging
|
||||
for o in 0..outputs {
|
||||
// stubs
|
||||
let stubspeed = beltspeed.halvings(section_size.ilog2() as usize);
|
||||
for i in 0..section_size {
|
||||
let depth = o + i.count_ones() as usize;
|
||||
|
||||
for j in 0..depth {
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
stubspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * (i + o * section_size) + global_x_offset) as f64 + output_x,
|
||||
output_y - j as f64,
|
||||
),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
stubspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * (i + o * section_size) + global_x_offset) as f64 + output_x,
|
||||
output_y - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
// merger
|
||||
for i in 1..(section_size.ilog2() as usize + 1) {
|
||||
let p = 1 << i;
|
||||
let mergespeed = beltspeed.halvings((section_size.ilog2() as usize) - i);
|
||||
for j in 0..(section_size / p) {
|
||||
let depth = o + j.count_ones() as usize;
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
mergespeed.string_splitter(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * (j * p + o * section_size) + global_x_offset) as f64 - i as f64
|
||||
+ output_x,
|
||||
output_y - i as f64 + 0.5 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
e.extend((0..(7 * p / 2)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
mergespeed.halve().string(),
|
||||
offset + 1 + l as u32,
|
||||
BlueprintPosition::new(
|
||||
(7 * (j * p + o * section_size) + global_x_offset) as f64 - i as f64
|
||||
+ output_x
|
||||
+ l as f64
|
||||
+ 1.0,
|
||||
output_y - i as f64 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build()
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// connect
|
||||
let offset = e.len() as u32;
|
||||
let step = o + section_size.ilog2() as usize;
|
||||
e.extend((0..(7 * o * section_size)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset + l as u32,
|
||||
BlueprintPosition::new(
|
||||
(l + global_x_offset) as f64 + output_x - section_size.ilog2() as f64,
|
||||
output_y - step as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build()
|
||||
}));
|
||||
}
|
||||
|
||||
Blueprint::builder()
|
||||
.label("station".to_owned())
|
||||
.entities(e)
|
||||
.wires(
|
||||
(0..((length + locomotives - 1) as u32))
|
||||
.map(|i| [i, 5, i + 1, 5])
|
||||
.collect(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
use crate::binary_merger::merger;
|
||||
|
||||
pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntity>, f64) {
|
||||
match beltspeed {
|
||||
Beltspeed::Normal => {
|
||||
if beltspeed == Beltspeed::Normal {
|
||||
let mut e = vec![
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
|
|
@ -235,14 +67,15 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntit
|
|||
}
|
||||
|
||||
(e, -2.5)
|
||||
}
|
||||
Beltspeed::Fast => {
|
||||
} else {
|
||||
let (belt_inserter, stack_size, quality) = match beltspeed {
|
||||
Beltspeed::Normal => unreachable!(),
|
||||
Beltspeed::Fast => ("fast-inserter", None, None),
|
||||
Beltspeed::Express => ("bulk-inserter", Some(8), None),
|
||||
Beltspeed::Turbo => ("fast-inserter", None, Some(String::from("epic"))),
|
||||
};
|
||||
let mut e = vec![
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
0,
|
||||
BlueprintPosition::new(3.5, -3.5),
|
||||
)
|
||||
BlueprintEntity::builder(beltspeed.string(), 0, BlueprintPosition::new(3.5, -3.5))
|
||||
.build(),
|
||||
];
|
||||
|
||||
|
|
@ -263,14 +96,16 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntit
|
|||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
belt_inserter.to_owned(),
|
||||
offset + 2,
|
||||
BlueprintPosition::new(1.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.maybe_override_stack_size(stack_size)
|
||||
.maybe_quality(quality.clone())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
beltspeed.string(),
|
||||
offset + 3,
|
||||
BlueprintPosition::new(1.5, -3.5),
|
||||
)
|
||||
|
|
@ -290,14 +125,16 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntit
|
|||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
belt_inserter.to_owned(),
|
||||
offset + 6,
|
||||
BlueprintPosition::new(2.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.maybe_override_stack_size(stack_size)
|
||||
.maybe_quality(quality.clone())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
beltspeed.string(),
|
||||
offset + 7,
|
||||
BlueprintPosition::new(2.5, -3.5),
|
||||
)
|
||||
|
|
@ -323,14 +160,16 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntit
|
|||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
belt_inserter.to_owned(),
|
||||
offset + 2,
|
||||
BlueprintPosition::new(4.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.maybe_override_stack_size(stack_size)
|
||||
.maybe_quality(quality.clone())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
beltspeed.string(),
|
||||
offset + 3,
|
||||
BlueprintPosition::new(4.5, -3.5),
|
||||
)
|
||||
|
|
@ -350,14 +189,16 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntit
|
|||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
belt_inserter.to_owned(),
|
||||
offset + 6,
|
||||
BlueprintPosition::new(5.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.maybe_override_stack_size(stack_size)
|
||||
.maybe_quality(quality.clone())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
beltspeed.string(),
|
||||
offset + 7,
|
||||
BlueprintPosition::new(5.5, -3.5),
|
||||
)
|
||||
|
|
@ -368,164 +209,172 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Vec<BlueprintEntit
|
|||
|
||||
(e, -4.5)
|
||||
}
|
||||
Beltspeed::Express => {
|
||||
let mut e = vec![
|
||||
BlueprintEntity::builder(
|
||||
"express-transport-belt".to_owned(),
|
||||
0,
|
||||
BlueprintPosition::new(3.5, -3.5),
|
||||
)
|
||||
.build(),
|
||||
];
|
||||
|
||||
if belttype.contains_left() {
|
||||
let offset = e.len() as u32;
|
||||
e.extend_from_slice(&[
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
offset,
|
||||
BlueprintPosition::new(1.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 1,
|
||||
BlueprintPosition::new(1.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 2,
|
||||
BlueprintPosition::new(1.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.override_stack_size(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"express-transport-belt".to_owned(),
|
||||
offset + 3,
|
||||
BlueprintPosition::new(1.5, -3.5),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
offset + 4,
|
||||
BlueprintPosition::new(2.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 5,
|
||||
BlueprintPosition::new(2.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 6,
|
||||
BlueprintPosition::new(2.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.override_stack_size(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"express-transport-belt".to_owned(),
|
||||
offset + 7,
|
||||
BlueprintPosition::new(2.5, -3.5),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
]);
|
||||
}
|
||||
|
||||
if belttype.contains_right() {
|
||||
let offset = e.len() as u32;
|
||||
e.extend_from_slice(&[
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
offset,
|
||||
BlueprintPosition::new(4.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 1,
|
||||
BlueprintPosition::new(4.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 2,
|
||||
BlueprintPosition::new(4.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.override_stack_size(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"express-transport-belt".to_owned(),
|
||||
offset + 3,
|
||||
BlueprintPosition::new(4.5, -3.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
offset + 4,
|
||||
BlueprintPosition::new(5.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 5,
|
||||
BlueprintPosition::new(5.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
offset + 6,
|
||||
BlueprintPosition::new(5.5, -2.5),
|
||||
)
|
||||
.direction(8)
|
||||
.override_stack_size(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"express-transport-belt".to_owned(),
|
||||
offset + 7,
|
||||
BlueprintPosition::new(5.5, -3.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
]);
|
||||
}
|
||||
|
||||
(e, -4.5)
|
||||
}
|
||||
Beltspeed::Turbo => (Vec::new(), -4.5),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn basic_unload_station(
|
||||
pub fn one_loader(beltspeed: Beltspeed) -> (Vec<BlueprintEntity>, f64) {
|
||||
let (belt_inserter, quality) = match beltspeed {
|
||||
Beltspeed::Normal => ("fast-inserter", None),
|
||||
Beltspeed::Fast => ("bulk-inserter", Some(String::from("uncommon"))),
|
||||
Beltspeed::Express => ("bulk-inserter", Some(String::from("rare"))),
|
||||
Beltspeed::Turbo => ("bulk-inserter", Some(String::from("legendary"))),
|
||||
};
|
||||
|
||||
(
|
||||
vec![
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string_splitter(),
|
||||
0,
|
||||
BlueprintPosition::new(4.0, -4.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(beltspeed.string(), 1, BlueprintPosition::new(2.5, -3.5))
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(beltspeed.string(), 2, BlueprintPosition::new(3.5, -3.5))
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(beltspeed.string(), 3, BlueprintPosition::new(4.5, -3.5))
|
||||
.direction(4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(beltspeed.string(), 4, BlueprintPosition::new(5.5, -3.5))
|
||||
.direction(4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
belt_inserter.to_owned(),
|
||||
5,
|
||||
BlueprintPosition::new(2.5, -2.5),
|
||||
)
|
||||
.maybe_quality(quality.clone())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
belt_inserter.to_owned(),
|
||||
6,
|
||||
BlueprintPosition::new(5.5, -2.5),
|
||||
)
|
||||
.maybe_quality(quality.clone())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
7,
|
||||
BlueprintPosition::new(2.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
8,
|
||||
BlueprintPosition::new(5.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
9,
|
||||
BlueprintPosition::new(2.5, -0.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
10,
|
||||
BlueprintPosition::new(5.5, -0.5),
|
||||
)
|
||||
.build(),
|
||||
],
|
||||
-5.5,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn basic_station(
|
||||
load: bool,
|
||||
locomotives: usize,
|
||||
length: usize,
|
||||
outputs: usize,
|
||||
beltspeed: Beltspeed,
|
||||
belttype: Belttype,
|
||||
) -> Blueprint {
|
||||
let (unloader, output_y) = unloader(
|
||||
let section_size = length / outputs;
|
||||
assert!(length % outputs == 0);
|
||||
assert!(section_size.is_power_of_two());
|
||||
assert!(outputs <= length);
|
||||
|
||||
let mut e = Vec::new();
|
||||
|
||||
let global_x_offset = locomotives * 7;
|
||||
|
||||
// electric poles
|
||||
for l in 1..=(length + locomotives) {
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"medium-electric-pole".to_owned(),
|
||||
l as u32 - 1,
|
||||
BlueprintPosition::new((7 * l) as f64 + 0.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
// unloader
|
||||
let (unloader, output_y) = match load {
|
||||
false => unloader(
|
||||
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||
belttype,
|
||||
);
|
||||
station_unload(
|
||||
length,
|
||||
locomotives,
|
||||
&unloader,
|
||||
beltspeed,
|
||||
outputs,
|
||||
3.5,
|
||||
output_y,
|
||||
),
|
||||
true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)),
|
||||
};
|
||||
|
||||
let offset = e.len();
|
||||
for l in 0..length {
|
||||
e.extend(unloader.iter().cloned().map(|mut e| {
|
||||
e.position.x += (7 * l + global_x_offset) as f64;
|
||||
e.entity_number += (offset + unloader.len() * l) as u32;
|
||||
e
|
||||
}));
|
||||
}
|
||||
|
||||
// train stop
|
||||
let offset = e.len();
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"train-stop".to_owned(),
|
||||
offset as u32,
|
||||
BlueprintPosition::new(1.0, -1.0),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
|
||||
// rails
|
||||
for l in 0..((length * 7 + global_x_offset + 1) / 2) {
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"straight-rail".to_owned(),
|
||||
offset,
|
||||
BlueprintPosition::new(2.0 * l as f64 + 1.0, 1.0),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
// output and merging
|
||||
e.extend(merger(
|
||||
load,
|
||||
beltspeed,
|
||||
global_x_offset as f64 + 3.5,
|
||||
output_y,
|
||||
e.len() as u32,
|
||||
7,
|
||||
outputs,
|
||||
length,
|
||||
));
|
||||
|
||||
Blueprint::builder()
|
||||
.label("station".to_owned())
|
||||
.entities(e)
|
||||
.wires(
|
||||
(0..((length + locomotives - 1) as u32))
|
||||
.map(|i| [i, 5, i + 1, 5])
|
||||
.collect(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
0eNqdkMsKgzAQRf9l1qPUaFrMr4gUH0MZMIkksa1I/r3RLroodFFmc+d15jIb9NNCs2MTQG3AgzUeVLOB55vppr1mOk2gQNPIi85ooiE4HrLZTgQRgc1IT1BFbBHIBA5Mb8KRrFez6J5cGsCfJITZ+rRszX4zAS8ilwgrqKyoTrmMEb+Q4n9kWe7IZPnB7vDbFCj2aDEpmZRsU5cD6YT//AjhTs4fSHkWdVXXUlZS1GUR4wvMGmsM
|
||||
|
|
@ -0,0 +1 @@
|
|||
0eNqd0M0KgzAMAOB3yTnKWu2GfRWR4U8YgbZKrdtE+u6r7rDDYIfdkib5ErpBZxaaPLsAegPuRzeDrjeY+eZas7+51hJosDTwYjMy1AfPfTaNhiAisBvoCVrEBoFc4MD0Fo5kvbrFduRTA/6UEKZxTsOj23cm8CJzhbCCzkR5ylWM+EXK/8mi2Ml08oP9cW8tUKBE0WCKVIpUk6ocyCb+80cId/LzQaqzrMqqUqpUsipEjC/LnmsK
|
||||
1
factorio-blueprint/blueprints/inserter-quality.bp
Normal file
1
factorio-blueprint/blueprints/inserter-quality.bp
Normal file
|
|
@ -0,0 +1 @@
|
|||
0eNqtkLEOwjAMRP/Fc4pIIUDyKwhVoTXIonUhSRFQ5d8xMDAgJAZG2+e7pxth2w54DMQJ3AhU9xzBrUeItGffPnbsOwQHOx9TQRwxJAyg4DT4ltJVLsEHhKyAuMELOJ03CpATJcKX13O4Vjx0W3l1Wn3zPPZRvnp+xIpToacTo0AyiqWdGIloKGD9Uqw+EBT0ZwyBGqxi8vWhinSTlFlWHwjl7wj6LwhSCSXsRPfuW4Fo49PJLEo7t9aYuSntTOd8Bwiih1s=
|
||||
1
factorio-blueprint/blueprints/rail-curve.bp
Normal file
1
factorio-blueprint/blueprints/rail-curve.bp
Normal file
|
|
@ -0,0 +1 @@
|
|||
0eNqN0UsKgzAQBuC7zDqCUaMmVyml+BjKgMYSo1Qkd2/USmnrwuU8/m8xM0PZDPgwpC2oGajqdA/qMkNPd100S08XLYICU1ADjgHpGp+guLsyQG3JEm6JtZhuemhLNH6B7clqMCPWwQIEBTB4dL1PdXrBvSRyyWACFfAw9X5NBqttzEPH/tzo0C2P3Gx3+Qk3Pu/GmyuzbzY5UJPTV8jytyp+VX9osth64/MrBiOafl0QaSQTKYVIRCRj7twLWaaXjg==
|
||||
1
factorio-blueprint/blueprints/rail-diagonal.bp
Normal file
1
factorio-blueprint/blueprints/rail-diagonal.bp
Normal file
|
|
@ -0,0 +1 @@
|
|||
0eNpFjtEKgzAMRf/lPleYzg7aXxljVA0uoFHaOibSf19Vxh6T3HNyNzTDQrNnibAbuJ0kwN43BO7FDftO3Eiw8I4HJAWWjj6wZXookESOTCdxDOtTlrEhnwPqR4aY2f4Vi0OhME8hU5Ps8mzSplZYYQtzyfqOPbXntdpfcKQxO/4tFd7kwxHQt8rUxmhd68pcy5S+PTBDgg==
|
||||
|
|
@ -1,8 +1,5 @@
|
|||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD;
|
||||
use base64::prelude::BASE64_STANDARD;
|
||||
use std::io::Cursor;
|
||||
use std::io::Read;
|
||||
use base64::{Engine, engine::general_purpose::STANDARD, prelude::BASE64_STANDARD};
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
pub mod belt;
|
||||
pub mod structs;
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ pub struct BlueprintEntity {
|
|||
switch_state: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
tags: Option<serde_json::Value>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
quality: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use factorio_blueprint::{encode, misc::Beltspeed, Blueprint, BlueprintString};
|
||||
use factorio_core::visualize::Visualize;
|
||||
use factorio_blueprint::{encode, Blueprint, BlueprintString};
|
||||
use factorio_core::{beltoptions::Beltspeed, visualize::Visualize};
|
||||
use factorio_pathfinding::belt_finding::{
|
||||
conflict_avoidance::ConflictAvoidance, problems, Problem,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue