Add output signals

This commit is contained in:
hal8174 2025-01-25 19:16:27 +01:00
parent ce76626f79
commit aabd9486e0
3 changed files with 90 additions and 32 deletions

View file

@ -12,36 +12,64 @@ struct Args {
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
let stations: Vec<_> = (0..8) // let stations: Vec<_> = (0..2)
.map(|_| StationSpec { // .map(|_| StationSpec {
locomotives: 1, // locomotives: 1,
wagons: 2, // wagons: 2,
load: false, // load: false,
beltspeed: Beltspeed::Normal, // beltspeed: Beltspeed::Turbo,
lanes: 1, // lanes: 2,
}) // })
.collect(); // .collect();
let b = BlueprintString::Blueprint( let b = BlueprintString::Blueprint(
multistation( multistation(
&stations, // &stations,
// &[ &[
// StationSpec { StationSpec {
// locomotives: 1, locomotives: 2,
// wagons: 1, wagons: 4,
// load: false, load: false,
// beltspeed: Beltspeed::Normal, beltspeed: Beltspeed::Normal,
// lanes: 1, lanes: 4,
// }, },
// StationSpec { StationSpec {
// locomotives: 1, locomotives: 3,
// wagons: 1, wagons: 8,
// load: false, load: false,
// beltspeed: Beltspeed::Express, beltspeed: Beltspeed::Turbo,
// lanes: 1, lanes: 8,
// }, },
// ], StationSpec {
16, locomotives: 3,
wagons: 8,
load: false,
beltspeed: Beltspeed::Turbo,
lanes: 4,
},
StationSpec {
locomotives: 3,
wagons: 8,
load: false,
beltspeed: Beltspeed::Turbo,
lanes: 2,
},
StationSpec {
locomotives: 3,
wagons: 8,
load: false,
beltspeed: Beltspeed::Turbo,
lanes: 1,
},
StationSpec {
locomotives: 1,
wagons: 1,
load: false,
beltspeed: Beltspeed::Turbo,
lanes: 1,
},
],
8,
) )
.to_blueprint(), .to_blueprint(),
); );

View file

@ -202,10 +202,9 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
9, 9,
)); ));
for j in 0..dbg!( for j in 0..((7 * longest_train).div_ceil(2)
(7 * longest_train).div_ceil(2) - (7 * (station.locomotives + station.wagons)).div_ceil(2))
- (7 * (station.locomotives + station.wagons)).div_ceil(2) {
) {
blueprint.add_entity(Entity::new_rail( blueprint.add_entity(Entity::new_rail(
RailType::Straight, RailType::Straight,
Position::new( Position::new(
@ -225,7 +224,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
factorio_core::beltoptions::Belttype::Full, factorio_core::beltoptions::Belttype::Full,
); );
let station_height = PositionType::max(16, 16); let station_height = PositionType::max(12, 4 + ((3 - b.bounding_box().min().y) / 4) * 4);
assert!(station_height % 4 == 0); assert!(station_height % 4 == 0);
b.transform(Transformation::new( b.transform(Transformation::new(
@ -301,6 +300,16 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
), ),
6, 6,
)); ));
if i % 4 == 0 {
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(
outrail_x - 7 - 4 * i as PositionType,
total_stacker_height - 19 - 4 * i as PositionType,
),
6,
));
}
} }
let remaining_offset = total_stacker_height - 34 - out_diagonal_length * 4; let remaining_offset = total_stacker_height - 34 - out_diagonal_length * 4;
blueprint.add_entity(Entity::new_rail( blueprint.add_entity(Entity::new_rail(
@ -313,12 +322,24 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
Position::new(38, remaining_offset + 4), Position::new(38, remaining_offset + 4),
8, 8,
)); ));
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(41, remaining_offset + 7),
7,
));
for i in 0..(remaining_offset / 4) { for i in 0..(remaining_offset / 4) {
blueprint.add_entity(Entity::new_rail( blueprint.add_entity(Entity::new_rail(
RailType::Straight, RailType::Straight,
Position::new(38, 2 + 4 * i as PositionType), Position::new(38, 2 + 4 * i as PositionType),
0, 0,
)); ));
if i % 8 == 7 {
blueprint.add_entity(Entity::new_rail(
RailType::RailSignal,
Position::new(41, 3 + 4 * i as PositionType),
8,
));
}
} }
blueprint blueprint

View file

@ -1,4 +1,5 @@
use factorio_core::{ use factorio_core::{
aabb::AABB,
beltoptions::Beltspeed, beltoptions::Beltspeed,
direction, direction,
pathfield::PathField, pathfield::PathField,
@ -459,6 +460,14 @@ impl Blueprint {
e.transform(transform); e.transform(transform);
} }
} }
pub fn bounding_box(&self) -> AABB {
self.entities
.iter()
.map(|(_, e)| AABB::new(e.position, e.position))
.reduce(|a, b| a.combine(b))
.unwrap()
}
} }
impl Default for Blueprint { impl Default for Blueprint {