Add stacked belts to station
This commit is contained in:
parent
65e2c03824
commit
59d7cf50cb
5 changed files with 85 additions and 45 deletions
|
|
@ -2,7 +2,7 @@ use clap::Parser;
|
||||||
use factorio_blueprint::abstraction::serde::AbstractBlueprintString;
|
use factorio_blueprint::abstraction::serde::AbstractBlueprintString;
|
||||||
use factorio_blueprint::{BlueprintString, encode};
|
use factorio_blueprint::{BlueprintString, encode};
|
||||||
use factorio_blueprint_generator::multistation::{StationSpec, multistation};
|
use factorio_blueprint_generator::multistation::{StationSpec, multistation};
|
||||||
use factorio_core::beltoptions::Beltspeed;
|
use factorio_core::beltoptions::{Beltspeed, Belttype};
|
||||||
use factorio_core::visualize::Visualize;
|
use factorio_core::visualize::Visualize;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
@ -29,11 +29,7 @@ fn main() {
|
||||||
|
|
||||||
let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes");
|
let (beltspeed, s) = s.split_at_checked(1).expect("extracting lanes");
|
||||||
|
|
||||||
let (lanes, belttype) = if s.ends_with(['l', 'r']) {
|
let lanes = s.trim_end_matches(['r', 'l', 's']);
|
||||||
s.split_at(s.len() - 1)
|
|
||||||
} else {
|
|
||||||
(s, "")
|
|
||||||
};
|
|
||||||
|
|
||||||
StationSpec {
|
StationSpec {
|
||||||
locomotives: locomotives.parse().expect("parsing locomotive count"),
|
locomotives: locomotives.parse().expect("parsing locomotive count"),
|
||||||
|
|
@ -51,12 +47,14 @@ fn main() {
|
||||||
_ => panic!("unknown belt speed {beltspeed}"),
|
_ => panic!("unknown belt speed {beltspeed}"),
|
||||||
},
|
},
|
||||||
lanes: lanes.parse().expect("parsing lane count"),
|
lanes: lanes.parse().expect("parsing lane count"),
|
||||||
belttype: match belttype {
|
belttype: if s.contains('l') {
|
||||||
"" => factorio_core::beltoptions::Belttype::Full,
|
Belttype::Left
|
||||||
"r" => factorio_core::beltoptions::Belttype::Right,
|
} else if s.contains('r') {
|
||||||
"l" => factorio_core::beltoptions::Belttype::Left,
|
Belttype::Right
|
||||||
_ => panic!("unknown belttype {belttype}"),
|
} else {
|
||||||
|
Belttype::Full
|
||||||
},
|
},
|
||||||
|
stacked: s.contains('s'),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ fn main() {
|
||||||
o,
|
o,
|
||||||
beltspeed,
|
beltspeed,
|
||||||
Belttype::Full,
|
Belttype::Full,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
inner_inner_b.push(BlueprintBookEntry::new(
|
inner_inner_b.push(BlueprintBookEntry::new(
|
||||||
|
|
@ -94,10 +95,13 @@ fn main() {
|
||||||
BlueprintBook::builder()
|
BlueprintBook::builder()
|
||||||
.blueprints(inner_b)
|
.blueprints(inner_b)
|
||||||
.active_index(0)
|
.active_index(0)
|
||||||
.label(format!("{locomotives}-{cargo}-{}", match load {
|
.label(format!(
|
||||||
true => "load",
|
"{locomotives}-{cargo}-{}",
|
||||||
false => "unload",
|
match load {
|
||||||
}))
|
true => "load",
|
||||||
|
false => "unload",
|
||||||
|
}
|
||||||
|
))
|
||||||
.build(),
|
.build(),
|
||||||
),
|
),
|
||||||
2 * i as u32 + load as u32,
|
2 * i as u32 + load as u32,
|
||||||
|
|
@ -126,8 +130,16 @@ fn main() {
|
||||||
belttype,
|
belttype,
|
||||||
} => {
|
} => {
|
||||||
let b = BlueprintString::Blueprint(
|
let b = BlueprintString::Blueprint(
|
||||||
basic_station(load, locomotives, length, outputs, beltspeed, belttype)
|
basic_station(
|
||||||
.to_blueprint(),
|
load,
|
||||||
|
locomotives,
|
||||||
|
length,
|
||||||
|
outputs,
|
||||||
|
beltspeed,
|
||||||
|
belttype,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.to_blueprint(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if args.json {
|
if args.json {
|
||||||
|
|
|
||||||
|
|
@ -413,6 +413,7 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
||||||
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
||||||
lanes: 1,
|
lanes: 1,
|
||||||
belttype: factorio_core::beltoptions::Belttype::Full,
|
belttype: factorio_core::beltoptions::Belttype::Full,
|
||||||
|
stacked: false,
|
||||||
}));
|
}));
|
||||||
station_spec.extend(output_connections.iter().map(|&(_, c)| StationSpec {
|
station_spec.extend(output_connections.iter().map(|&(_, c)| StationSpec {
|
||||||
locomotives: 2,
|
locomotives: 2,
|
||||||
|
|
@ -421,6 +422,7 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
||||||
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
||||||
lanes: 1,
|
lanes: 1,
|
||||||
belttype: factorio_core::beltoptions::Belttype::Full,
|
belttype: factorio_core::beltoptions::Belttype::Full,
|
||||||
|
stacked: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
intermediate_connections.push(IntermediateConnection {
|
intermediate_connections.push(IntermediateConnection {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ pub struct StationSpec {
|
||||||
pub beltspeed: Beltspeed,
|
pub beltspeed: Beltspeed,
|
||||||
pub lanes: usize,
|
pub lanes: usize,
|
||||||
pub belttype: Belttype,
|
pub belttype: Belttype,
|
||||||
|
pub stacked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_station_height(
|
fn calculate_station_height(
|
||||||
|
|
@ -268,6 +269,7 @@ pub fn multistation(
|
||||||
station.lanes,
|
station.lanes,
|
||||||
station.beltspeed,
|
station.beltspeed,
|
||||||
station.belttype,
|
station.belttype,
|
||||||
|
station.stacked,
|
||||||
);
|
);
|
||||||
let output_height = -b.bounding_box().min().y;
|
let output_height = -b.bounding_box().min().y;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,23 @@ use factorio_core::{
|
||||||
|
|
||||||
use crate::binary_merger::merger;
|
use crate::binary_merger::merger;
|
||||||
|
|
||||||
pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, PositionType) {
|
pub fn unloader(
|
||||||
|
beltspeed: Beltspeed,
|
||||||
|
belttype: Belttype,
|
||||||
|
stacked: bool,
|
||||||
|
) -> (Blueprint, PositionType) {
|
||||||
let mut b = Blueprint::new();
|
let mut b = Blueprint::new();
|
||||||
|
|
||||||
|
let (belt_inserter, stack_size, quality) = match (beltspeed, stacked) {
|
||||||
|
(Beltspeed::Normal, false) => (InserterType::Fast, None, Quality::Normal),
|
||||||
|
(Beltspeed::Fast, false) => (InserterType::Fast, None, Quality::Normal),
|
||||||
|
(Beltspeed::Express, false) => (InserterType::Bulk, Some(7), Quality::Normal),
|
||||||
|
(Beltspeed::Turbo, false) => (InserterType::Bulk, Some(10), Quality::Normal),
|
||||||
|
(Beltspeed::Normal, true) => (InserterType::Stack, None, Quality::Normal),
|
||||||
|
(Beltspeed::Fast, true) => (InserterType::Stack, None, Quality::Normal),
|
||||||
|
(Beltspeed::Express, true) => (InserterType::Stack, None, Quality::Rare),
|
||||||
|
(Beltspeed::Turbo, true) => (InserterType::Stack, None, Quality::Epic),
|
||||||
|
};
|
||||||
if beltspeed == Beltspeed::Normal {
|
if beltspeed == Beltspeed::Normal {
|
||||||
b.add_entity(Entity::new_belt(
|
b.add_entity(Entity::new_belt(
|
||||||
Beltspeed::Fast,
|
Beltspeed::Fast,
|
||||||
|
|
@ -30,12 +44,15 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, Positio
|
||||||
Direction::Down,
|
Direction::Down,
|
||||||
));
|
));
|
||||||
|
|
||||||
b.add_entity(Entity::new_inserter(
|
b.add_entity(
|
||||||
InserterType::Fast,
|
Entity::new_inserter(
|
||||||
None,
|
belt_inserter,
|
||||||
Position::new(1, 1) + 2 * Position::new(4, -2),
|
stack_size,
|
||||||
Direction::Right,
|
Position::new(1, 1) + 2 * Position::new(4, -2),
|
||||||
));
|
Direction::Right,
|
||||||
|
)
|
||||||
|
.quality(quality),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if belttype.contains_right() {
|
if belttype.contains_right() {
|
||||||
|
|
@ -52,23 +69,19 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, Positio
|
||||||
Direction::Down,
|
Direction::Down,
|
||||||
));
|
));
|
||||||
|
|
||||||
b.add_entity(Entity::new_inserter(
|
b.add_entity(
|
||||||
InserterType::Fast,
|
Entity::new_inserter(
|
||||||
None,
|
belt_inserter,
|
||||||
Position::new(1, 1) + 2 * Position::new(2, -2),
|
stack_size,
|
||||||
Direction::Left,
|
Position::new(1, 1) + 2 * Position::new(2, -2),
|
||||||
));
|
Direction::Left,
|
||||||
|
)
|
||||||
|
.quality(quality),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(b, -3)
|
(b, -3)
|
||||||
} else {
|
} else {
|
||||||
let (belt_inserter, stack_size, quality) = match beltspeed {
|
|
||||||
Beltspeed::Normal => unreachable!(),
|
|
||||||
Beltspeed::Fast => (InserterType::Fast, None, Quality::Normal),
|
|
||||||
Beltspeed::Express => (InserterType::Bulk, Some(7), Quality::Normal),
|
|
||||||
Beltspeed::Turbo => (InserterType::Bulk, Some(10), Quality::Normal),
|
|
||||||
};
|
|
||||||
|
|
||||||
b.add_entity(Entity::new_belt(
|
b.add_entity(Entity::new_belt(
|
||||||
beltspeed,
|
beltspeed,
|
||||||
Position::new(1, 1) + 2 * Position::new(3, -4),
|
Position::new(1, 1) + 2 * Position::new(3, -4),
|
||||||
|
|
@ -118,12 +131,16 @@ pub fn unloader(beltspeed: Beltspeed, belttype: Belttype) -> (Blueprint, Positio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn one_loader(beltspeed: Beltspeed) -> (Blueprint, PositionType) {
|
pub fn one_loader(beltspeed: Beltspeed, stacked: bool) -> (Blueprint, PositionType) {
|
||||||
let (belt_inserter, quality) = match beltspeed {
|
let (belt_inserter, quality) = match (beltspeed, stacked) {
|
||||||
Beltspeed::Normal => (InserterType::Fast, Quality::Normal),
|
(Beltspeed::Normal, false) => (InserterType::Fast, Quality::Normal),
|
||||||
Beltspeed::Fast => (InserterType::Bulk, Quality::Uncommon),
|
(Beltspeed::Fast, false) => (InserterType::Bulk, Quality::Uncommon),
|
||||||
Beltspeed::Express => (InserterType::Bulk, Quality::Rare),
|
(Beltspeed::Express, false) => (InserterType::Bulk, Quality::Rare),
|
||||||
Beltspeed::Turbo => (InserterType::Bulk, Quality::Legendary),
|
(Beltspeed::Turbo, false) => (InserterType::Bulk, Quality::Legendary),
|
||||||
|
(Beltspeed::Normal, true) => todo!(),
|
||||||
|
(Beltspeed::Fast, true) => todo!(),
|
||||||
|
(Beltspeed::Express, true) => todo!(),
|
||||||
|
(Beltspeed::Turbo, true) => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut b = Blueprint::new();
|
let mut b = Blueprint::new();
|
||||||
|
|
@ -186,6 +203,7 @@ pub fn basic_station(
|
||||||
outputs: usize,
|
outputs: usize,
|
||||||
beltspeed: Beltspeed,
|
beltspeed: Beltspeed,
|
||||||
belttype: Belttype,
|
belttype: Belttype,
|
||||||
|
stacked: bool,
|
||||||
) -> Blueprint {
|
) -> Blueprint {
|
||||||
let section_size = length / outputs;
|
let section_size = length / outputs;
|
||||||
assert!(length % outputs == 0);
|
assert!(length % outputs == 0);
|
||||||
|
|
@ -215,16 +233,24 @@ pub fn basic_station(
|
||||||
false => unloader(
|
false => unloader(
|
||||||
beltspeed.halvings((length / outputs).ilog2() as usize),
|
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||||
belttype,
|
belttype,
|
||||||
|
stacked,
|
||||||
|
),
|
||||||
|
true => one_loader(
|
||||||
|
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||||
|
stacked,
|
||||||
),
|
),
|
||||||
true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)),
|
|
||||||
};
|
};
|
||||||
for l in 0..length {
|
for l in 0..length {
|
||||||
let (mut unloader, _) = match load {
|
let (mut unloader, _) = match load {
|
||||||
false => unloader(
|
false => unloader(
|
||||||
beltspeed.halvings((length / outputs).ilog2() as usize),
|
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||||
belttype,
|
belttype,
|
||||||
|
stacked,
|
||||||
|
),
|
||||||
|
true => one_loader(
|
||||||
|
beltspeed.halvings((length / outputs).ilog2() as usize),
|
||||||
|
stacked,
|
||||||
),
|
),
|
||||||
true => one_loader(beltspeed.halvings((length / outputs).ilog2() as usize)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
unloader.transform(Transformation::new(
|
unloader.transform(Transformation::new(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue