Fix station type for multistation

This commit is contained in:
hal8174 2025-05-11 16:57:30 +02:00
parent d26449195b
commit 0f6c96f737
3 changed files with 90 additions and 36 deletions

View file

@ -75,12 +75,16 @@ fn main() {
s.contains('s'),
)
}
"e" => StationSpec::new_empty(
locomotives.parse().expect("parsing locomotive count"),
wagons.parse().expect("parsing wagon count"),
format!("test"),
s.parse().expect("Unable to parse space"),
),
"e" => {
let (left, right) = s.split_once('-').expect("parsing space");
StationSpec::new_empty(
locomotives.parse().expect("parsing locomotive count"),
wagons.parse().expect("parsing wagon count"),
format!("test"),
left.parse().expect("Unable to parse left space"),
right.parse().expect("Unable to parse right space"),
)
}
_ => panic!("unknown station type"),
}
})

View file

@ -7,7 +7,7 @@ use factorio_blueprint::abstraction::{
};
use factorio_core::{beltoptions::Beltspeed, prelude::*};
fn calculate_station_height(
pub fn calculate_station_height(
output_height: PositionType,
lanes: usize,
beltspeed: Beltspeed,
@ -189,10 +189,10 @@ pub fn multistation(
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(
inrail_x + 3,
total_stacker_height + 17 + previous_station_heights,
inrail_x + 5,
total_stacker_height + 21 + previous_station_heights,
),
15,
14,
));
// out turn
@ -231,10 +231,10 @@ pub fn multistation(
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(
outrail_x - 3,
total_stacker_height + 17 + previous_station_heights,
outrail_x - 5,
total_stacker_height + 21 + previous_station_heights,
),
9,
10,
));
for j in 0..((7 * longest_train).div_ceil(2)
@ -266,16 +266,25 @@ pub fn multistation(
blueprint.add_blueprint(b);
let station_height = match &station_spec.station_type {
crate::station::StationType::Empty(station_type_empty) => 4 + station_type_empty.space,
let mut station_height = 4
+ station_spec.get_space_right()
+ (stations.get(i + 1).map(|s| s.get_space_left()).unwrap_or(0));
// ensure station_height is divisible by 4
station_height = (station_height + 3) & !0b11;
match &station_spec.station_type {
crate::station::StationType::Empty(_station_type_empty) => (),
crate::station::StationType::Belt(station_type_belt) => {
// belt output
let station_height = calculate_station_height(
let old_station_height = calculate_station_height(
output_height,
station_type_belt.lanes,
station_type_belt.beltspeed,
);
station_height = station_height.max(old_station_height);
output_heights
.push(30 + total_stacker_height + previous_station_heights + output_height);
@ -566,7 +575,6 @@ pub fn multistation(
));
}
}
station_height
}
};
@ -591,22 +599,24 @@ pub fn multistation(
));
}
blueprint.add_entity(Entity::new_rail(
RailType::ChainSignal,
Position::new(
inrail_x - 3,
total_stacker_height + 15 + previous_station_heights,
),
0,
));
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(
outrail_x + 3,
total_stacker_height + 15 + previous_station_heights,
),
8,
));
if station_height > 8 {
blueprint.add_entity(Entity::new_rail(
RailType::ChainSignal,
Position::new(
inrail_x - 3,
total_stacker_height + 15 + previous_station_heights,
),
0,
));
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(
outrail_x + 3,
total_stacker_height + 15 + previous_station_heights,
),
8,
));
}
}
previous_station_heights += station_height;

View file

@ -29,7 +29,8 @@ pub enum StationType {
#[derive(Debug)]
pub struct StationTypeEmpty {
pub space: PositionType,
pub space_left: PositionType,
pub space_right: PositionType,
}
#[derive(Debug)]
@ -101,15 +102,54 @@ impl StationSpec {
locomotives: usize,
wagons: usize,
station_name: String,
space: PositionType,
space_left: PositionType,
space_right: PositionType,
) -> Self {
Self::new(
locomotives,
wagons,
station_name,
StationType::Empty(StationTypeEmpty { space }),
StationType::Empty(StationTypeEmpty {
space_left,
space_right,
}),
)
}
pub fn get_space_left(&self) -> PositionType {
match &self.station_type {
StationType::Empty(station_type_empty) => station_type_empty.space_left,
StationType::Belt(_station_type_belt) => 0,
}
}
pub fn get_space_right(&self) -> PositionType {
match &self.station_type {
StationType::Empty(station_type_empty) => station_type_empty.space_right,
StationType::Belt(station_type_belt) => {
let mut r = 2 * station_type_belt.lanes as PositionType;
r += 2
* (self.train_information.wagons / station_type_belt.lanes).ilog2()
as PositionType;
r += if station_type_belt.load {
10
} else {
if station_type_belt.beltspeed.halvings(
(self.train_information.wagons / station_type_belt.lanes).ilog2() as usize,
) == Beltspeed::Normal
{
4
} else {
8
}
};
r
}
}
}
}
impl Default for StationBasicSpec {