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

@ -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;