Add connect output belt to station
This commit is contained in:
parent
aabd9486e0
commit
1af9712bcb
4 changed files with 435 additions and 139 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use factorio_blueprint::abstraction::{Blueprint, Entity, EntityType, RailType};
|
||||
use factorio_blueprint::abstraction::{Blueprint, Entity, EntityType, RailType, UndergroundType};
|
||||
use factorio_core::{beltoptions::Beltspeed, prelude::*};
|
||||
|
||||
use crate::station::basic_station;
|
||||
use crate::{balancer::binary_balancer, station::basic_station};
|
||||
|
||||
pub struct StationSpec {
|
||||
pub locomotives: usize,
|
||||
|
|
@ -11,6 +11,35 @@ pub struct StationSpec {
|
|||
pub lanes: usize,
|
||||
}
|
||||
|
||||
fn calculate_station_height(
|
||||
output_height: PositionType,
|
||||
lanes: usize,
|
||||
beltspeed: Beltspeed,
|
||||
) -> PositionType {
|
||||
let station_height = match beltspeed {
|
||||
Beltspeed::Normal => {
|
||||
if lanes == 1 && output_height % 4 == 1 {
|
||||
4 + ((3 + output_height) & !0b11)
|
||||
} else {
|
||||
4 + ((15 + output_height) & !0b11)
|
||||
}
|
||||
}
|
||||
Beltspeed::Fast => {
|
||||
if lanes == 1 || lanes == 2 && output_height % 4 == 3 {
|
||||
4 + ((3 + output_height) & !0b11)
|
||||
} else {
|
||||
4 + ((9 + output_height) & !0b11)
|
||||
}
|
||||
}
|
||||
Beltspeed::Express | Beltspeed::Turbo => 4 + ((3 + output_height) & !0b11),
|
||||
};
|
||||
|
||||
let station_height = PositionType::max(12, station_height);
|
||||
assert!(station_height % 4 == 0);
|
||||
|
||||
station_height
|
||||
}
|
||||
|
||||
pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint {
|
||||
let longest_train = stations
|
||||
.iter()
|
||||
|
|
@ -215,6 +244,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
|||
));
|
||||
}
|
||||
|
||||
// station
|
||||
let mut b = basic_station(
|
||||
station.load,
|
||||
station.locomotives,
|
||||
|
|
@ -223,9 +253,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
|||
station.beltspeed,
|
||||
factorio_core::beltoptions::Belttype::Full,
|
||||
);
|
||||
|
||||
let station_height = PositionType::max(12, 4 + ((3 - b.bounding_box().min().y) / 4) * 4);
|
||||
assert!(station_height % 4 == 0);
|
||||
let output_height = -b.bounding_box().min().y;
|
||||
|
||||
b.transform(Transformation::new(
|
||||
Direction::Down,
|
||||
|
|
@ -237,6 +265,263 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
|||
|
||||
blueprint.add_blueprint(b);
|
||||
|
||||
// belt output
|
||||
let station_height =
|
||||
calculate_station_height(output_height, station.lanes, station.beltspeed);
|
||||
|
||||
// rail crossing
|
||||
let (beltdirection, underground_left, underground_right) = match station.load {
|
||||
true => (
|
||||
Direction::Left,
|
||||
UndergroundType::Output,
|
||||
UndergroundType::Input,
|
||||
),
|
||||
false => (
|
||||
Direction::Right,
|
||||
UndergroundType::Input,
|
||||
UndergroundType::Output,
|
||||
),
|
||||
};
|
||||
let mut belt_x = outrail_x - 28 - 14 * station.locomotives as PositionType - 3
|
||||
+ 2 * (station.wagons / station.lanes).ilog2() as PositionType;
|
||||
|
||||
let (balancer_length, mut b) = binary_balancer(station.lanes, station.beltspeed);
|
||||
|
||||
if station.load {
|
||||
b.transform(Transformation::new(
|
||||
Direction::Down,
|
||||
Position::new(balancer_length, 2 * station.lanes as PositionType),
|
||||
));
|
||||
}
|
||||
|
||||
b.transform(Transformation::new(
|
||||
Direction::Up,
|
||||
Position::new(
|
||||
belt_x - 1,
|
||||
31 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * station.lanes as PositionType,
|
||||
),
|
||||
));
|
||||
|
||||
blueprint.add_blueprint(b);
|
||||
|
||||
belt_x += balancer_length;
|
||||
|
||||
for j in 0..station.lanes {
|
||||
let (underground_x, signal) = match station_height
|
||||
- (output_height - 2 * j as PositionType)
|
||||
{
|
||||
5 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 23,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_right,
|
||||
Position::new(
|
||||
outrail_x - 9,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 7,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 23, false)
|
||||
}
|
||||
7 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 17,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
if station.beltspeed != Beltspeed::Turbo {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_right,
|
||||
Position::new(
|
||||
outrail_x - 7,
|
||||
30 + total_stacker_height
|
||||
+ previous_station_heights
|
||||
+ output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 5,
|
||||
30 + total_stacker_height
|
||||
+ previous_station_heights
|
||||
+ output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
}
|
||||
(outrail_x - 17, false)
|
||||
}
|
||||
9 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 15,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 15, false)
|
||||
}
|
||||
11 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 11,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 11, false)
|
||||
}
|
||||
13 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 9,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 9, false)
|
||||
}
|
||||
15 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 9,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 9, true)
|
||||
}
|
||||
17 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 7,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 7, false)
|
||||
}
|
||||
19 | 21 | 23 => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 5,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 5, false)
|
||||
}
|
||||
_ => {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_left,
|
||||
Position::new(
|
||||
outrail_x - 3,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
(outrail_x - 3, false)
|
||||
}
|
||||
};
|
||||
|
||||
if signal {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_right,
|
||||
Position::new(
|
||||
outrail_x + 5,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
} else {
|
||||
blueprint.add_entity(Entity::new_underground_belt(
|
||||
station.beltspeed,
|
||||
underground_right,
|
||||
Position::new(
|
||||
outrail_x + 3,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
blueprint.add_entity(Entity::new_belt(
|
||||
station.beltspeed,
|
||||
Position::new(
|
||||
outrail_x + 5,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
}
|
||||
|
||||
for l in 0..((underground_x - belt_x) / 2) {
|
||||
blueprint.add_entity(Entity::new_belt(
|
||||
station.beltspeed,
|
||||
Position::new(
|
||||
belt_x + 2 * l,
|
||||
30 + total_stacker_height + previous_station_heights + output_height
|
||||
- 2 * j as PositionType,
|
||||
),
|
||||
beltdirection,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// rail connection
|
||||
if i != stations.len() - 1 {
|
||||
for j in 0..(station_height / 4) {
|
||||
|
|
@ -262,7 +547,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
|||
RailType::ChainSignal,
|
||||
Position::new(
|
||||
inrail_x - 3,
|
||||
total_stacker_height + 13 + previous_station_heights,
|
||||
total_stacker_height + 15 + previous_station_heights,
|
||||
),
|
||||
0,
|
||||
));
|
||||
|
|
@ -270,7 +555,7 @@ pub fn multistation(stations: &[StationSpec], stacker_size: usize) -> Blueprint
|
|||
RailType::RailSignal,
|
||||
Position::new(
|
||||
outrail_x + 3,
|
||||
total_stacker_height + 13 + previous_station_heights,
|
||||
total_stacker_height + 15 + previous_station_heights,
|
||||
),
|
||||
8,
|
||||
));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue