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 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};
#[derive(Parser)]
@ -63,13 +66,15 @@ fn main() {
let o = 1 << o;
let blueprint = basic_station(
load,
locomotives,
cargo,
o,
beltspeed,
Belttype::Full,
false,
&StationSpec {
locomotives,
wagons: cargo,
load,
beltspeed,
lanes: o,
belttype: Belttype::Full,
stacked: false,
},
&factorio_blueprint_generator::station::StationBasicSpec::default(),
);
@ -132,13 +137,15 @@ fn main() {
} => {
let b = BlueprintString::Blueprint(
basic_station(
load,
locomotives,
length,
outputs,
beltspeed,
belttype,
false,
&StationSpec {
locomotives,
wagons: length,
load,
beltspeed,
lanes: outputs,
belttype,
stacked: false,
},
&StationBasicSpec::default(),
)
.to_blueprint(),

View file

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

View file

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

View file

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