Use StationSpec for basic station

This commit is contained in:
hal8174 2025-05-03 15:18:10 +02:00
parent 7f563b37a4
commit a98e2cfb2b
4 changed files with 63 additions and 60 deletions

View file

@ -1,6 +1,9 @@
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode}; use factorio_blueprint::{BlueprintBook, BlueprintBookEntry, BlueprintString, encode};
use factorio_blueprint_generator::station::{StationBasicSpec, basic_station}; use factorio_blueprint_generator::{
multistation::StationSpec,
station::{StationBasicSpec, basic_station},
};
use factorio_core::beltoptions::{Beltspeed, Belttype}; use factorio_core::beltoptions::{Beltspeed, Belttype};
#[derive(Parser)] #[derive(Parser)]
@ -63,13 +66,15 @@ fn main() {
let o = 1 << o; let o = 1 << o;
let blueprint = basic_station( let blueprint = basic_station(
load, &StationSpec {
locomotives, locomotives,
cargo, wagons: cargo,
o, load,
beltspeed, beltspeed,
Belttype::Full, lanes: o,
false, belttype: Belttype::Full,
stacked: false,
},
&factorio_blueprint_generator::station::StationBasicSpec::default(), &factorio_blueprint_generator::station::StationBasicSpec::default(),
); );
@ -132,13 +137,15 @@ fn main() {
} => { } => {
let b = BlueprintString::Blueprint( let b = BlueprintString::Blueprint(
basic_station( basic_station(
load, &StationSpec {
locomotives, locomotives,
length, wagons: length,
outputs, load,
beltspeed, beltspeed,
belttype, lanes: outputs,
false, belttype,
stacked: false,
},
&StationBasicSpec::default(), &StationBasicSpec::default(),
) )
.to_blueprint(), .to_blueprint(),

View file

@ -6,12 +6,12 @@ pub fn merger(
beltspeed: Beltspeed, beltspeed: Beltspeed,
intervall: usize, intervall: usize,
outputs: usize, outputs: usize,
lines: usize, inputs: usize,
) -> Blueprint { ) -> Blueprint {
let section_size = lines / outputs; let section_size = inputs / outputs;
assert!(lines % outputs == 0); assert!(inputs % outputs == 0);
assert!(section_size.is_power_of_two()); assert!(section_size.is_power_of_two());
assert!(outputs <= lines); assert!(outputs <= inputs);
let mut b = Blueprint::new(); let mut b = Blueprint::new();

View file

@ -266,16 +266,7 @@ pub fn multistation(
} }
// station // station
let mut b = basic_station( let mut b = basic_station(station, basic_spec);
station.load,
station.locomotives,
station.wagons,
station.lanes,
station.beltspeed,
station.belttype,
station.stacked,
basic_spec,
);
let output_height = -b.bounding_box().min().y; let output_height = -b.bounding_box().min().y;
b.transform(Transformation::new( b.transform(Transformation::new(

View file

@ -6,7 +6,7 @@ use factorio_core::{
prelude::*, prelude::*,
}; };
use crate::binary_merger::merger; use crate::{binary_merger::merger, multistation::StationSpec};
pub struct StationBasicSpec { pub struct StationBasicSpec {
pub inserter_type: InserterType, pub inserter_type: InserterType,
@ -224,28 +224,19 @@ pub fn one_loader(
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn basic_station( pub fn basic_station(station_spec: &StationSpec, basic_spec: &StationBasicSpec) -> Blueprint {
load: bool, let section_size = station_spec.wagons / station_spec.lanes;
locomotives: usize, assert!(station_spec.wagons % station_spec.lanes == 0);
length: usize,
outputs: usize,
beltspeed: Beltspeed,
belttype: Belttype,
stacked: bool,
basic_spec: &StationBasicSpec,
) -> Blueprint {
let section_size = length / outputs;
assert!(length % outputs == 0);
assert!(section_size.is_power_of_two()); assert!(section_size.is_power_of_two());
assert!(outputs <= length); assert!(station_spec.lanes <= station_spec.wagons);
let mut blueprint = Blueprint::new(); let mut blueprint = Blueprint::new();
let global_x_offset = locomotives * 7; let global_x_offset = station_spec.locomotives * 7;
// electric poles // electric poles
let mut poles = Vec::new(); let mut poles = Vec::new();
for l in 1..=(length + locomotives) { for l in 1..=(station_spec.wagons + station_spec.locomotives) {
poles.push(blueprint.add_entity(Entity::new_electric_pole( poles.push(blueprint.add_entity(Entity::new_electric_pole(
ElectricPoleType::Medium, ElectricPoleType::Medium,
Position::new(1, 1) + 2 * Position::new(7 * l as PositionType, -2), Position::new(1, 1) + 2 * Position::new(7 * l as PositionType, -2),
@ -258,30 +249,38 @@ pub fn basic_station(
// unloader // unloader
let (_, output_y) = match load { let (_, output_y) = match station_spec.load {
false => unloader( false => unloader(
beltspeed.halvings((length / outputs).ilog2() as usize), station_spec
belttype, .beltspeed
stacked, .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize),
station_spec.belttype,
station_spec.stacked,
basic_spec, basic_spec,
), ),
true => one_loader( true => one_loader(
beltspeed.halvings((length / outputs).ilog2() as usize), station_spec
stacked, .beltspeed
.halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize),
station_spec.stacked,
basic_spec, basic_spec,
), ),
}; };
for l in 0..length { for l in 0..station_spec.wagons {
let (mut unloader, _) = match load { let (mut unloader, _) = match station_spec.load {
false => unloader( false => unloader(
beltspeed.halvings((length / outputs).ilog2() as usize), station_spec
belttype, .beltspeed
stacked, .halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize),
station_spec.belttype,
station_spec.stacked,
basic_spec, basic_spec,
), ),
true => one_loader( true => one_loader(
beltspeed.halvings((length / outputs).ilog2() as usize), station_spec
stacked, .beltspeed
.halvings((station_spec.wagons / station_spec.lanes).ilog2() as usize),
station_spec.stacked,
basic_spec, basic_spec,
), ),
}; };
@ -303,7 +302,7 @@ pub fn basic_station(
)); ));
// rails // rails
for l in 0..(length * 7 + global_x_offset).div_ceil(2) { for l in 0..(station_spec.wagons * 7 + global_x_offset).div_ceil(2) {
blueprint.add_entity(Entity::new_unknown( blueprint.add_entity(Entity::new_unknown(
"straight-rail", "straight-rail",
Position::new(2 + 4 * l as PositionType, 2), Position::new(2 + 4 * l as PositionType, 2),
@ -314,7 +313,13 @@ pub fn basic_station(
// output and merging // output and merging
let mut m = merger(load, beltspeed, 7, outputs, length); let mut m = merger(
station_spec.load,
station_spec.beltspeed,
7,
station_spec.lanes,
station_spec.wagons,
);
m.transform(Transformation::new( m.transform(Transformation::new(
Direction::Up, Direction::Up,