Add initial station generator
This commit is contained in:
parent
24b989b9f2
commit
c4a17d1792
9 changed files with 398 additions and 37 deletions
290
src/blueprint/station.rs
Normal file
290
src/blueprint/station.rs
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use super::{belt::Beltspeed, Blueprint, BlueprintEntity, BlueprintPosition};
|
||||
|
||||
pub fn station_unload(
|
||||
length: usize,
|
||||
locomotives: usize,
|
||||
unloader: &Vec<BlueprintEntity>,
|
||||
beltspeed: Beltspeed,
|
||||
double: bool,
|
||||
output_x: f64,
|
||||
output_y: f64,
|
||||
) -> Blueprint {
|
||||
assert!(length.is_power_of_two());
|
||||
|
||||
let mut e = Vec::new();
|
||||
|
||||
let global_x_offset = locomotives * 7;
|
||||
|
||||
for l in 1..=(length + locomotives) {
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"medium-electric-pole".to_owned(),
|
||||
l as u32 - 1,
|
||||
BlueprintPosition::new((7 * l) as f64 + 0.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
let offset = e.len();
|
||||
for l in 0..length {
|
||||
e.extend(unloader.iter().cloned().map(|mut e| {
|
||||
e.position.x += (7 * l + global_x_offset) as f64;
|
||||
e.entity_number += (offset + unloader.len() * l) as u32;
|
||||
e
|
||||
}));
|
||||
}
|
||||
|
||||
let offset = e.len();
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"train-stop".to_owned(),
|
||||
offset as u32,
|
||||
BlueprintPosition::new(1.0, -1.0),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
|
||||
for l in 0..((length * 7 + global_x_offset + 1) / 2) {
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
"straight-rail".to_owned(),
|
||||
offset,
|
||||
BlueprintPosition::new(2.0 * l as f64 + 1.0, 1.0),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
for i in 0..length {
|
||||
let depth = (i / 2).count_ones();
|
||||
|
||||
for j in 0..depth {
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * i + global_x_offset) as f64 + output_x,
|
||||
output_y - j as f64,
|
||||
),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
if i % 2 == 0 {
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * i + global_x_offset) as f64 + output_x,
|
||||
output_y - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string_splitter(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * i + global_x_offset) as f64 + output_x - 1.0,
|
||||
output_y - depth as f64 - 0.5,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
} else {
|
||||
let offset = e.len() as u32;
|
||||
e.extend((0..=7).map(|j| {
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset + j as u32,
|
||||
BlueprintPosition::new(
|
||||
(7 * i - j + global_x_offset) as f64 + output_x,
|
||||
output_y - depth as f64 - 1.0,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build()
|
||||
}));
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * i + global_x_offset) as f64 + output_x,
|
||||
output_y - depth as f64,
|
||||
),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for i in 2..(length.ilog2() as usize + 1) {
|
||||
let p = 1 << i;
|
||||
for j in 0..(length / p) {
|
||||
let depth = j.count_ones();
|
||||
let offset = e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string_splitter(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(7 * j * p + global_x_offset) as f64 - i as f64 + output_x,
|
||||
output_y - i as f64 + 0.5 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
);
|
||||
e.extend((0..(7 * p / 2)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset + l as u32,
|
||||
BlueprintPosition::new(
|
||||
(7 * j * p + global_x_offset) as f64 - i as f64 + output_x + l as f64 + 1.0,
|
||||
output_y - i as f64 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12)
|
||||
.build()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Blueprint::builder()
|
||||
.label("station".to_owned())
|
||||
.entities(e)
|
||||
.wires(
|
||||
(0..((length + locomotives - 1) as u32))
|
||||
.map(|i| [i, 5, i + 1, 5])
|
||||
.collect(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub fn basic_unload_station() -> Blueprint {
|
||||
let top = vec![
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
0,
|
||||
BlueprintPosition::new(1.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
1,
|
||||
BlueprintPosition::new(1.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
2,
|
||||
BlueprintPosition::new(2.5, -1.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
3,
|
||||
BlueprintPosition::new(3.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
];
|
||||
|
||||
let bottom = vec![
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
0,
|
||||
BlueprintPosition::new(1.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
1,
|
||||
BlueprintPosition::new(1.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
2,
|
||||
BlueprintPosition::new(2.5, -1.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
3,
|
||||
BlueprintPosition::new(3.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
];
|
||||
|
||||
let full = vec![
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
0,
|
||||
BlueprintPosition::new(1.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
1,
|
||||
BlueprintPosition::new(1.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
2,
|
||||
BlueprintPosition::new(2.5, -1.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"steel-chest".to_owned(),
|
||||
0,
|
||||
BlueprintPosition::new(5.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"bulk-inserter".to_owned(),
|
||||
1,
|
||||
BlueprintPosition::new(5.5, -0.5),
|
||||
)
|
||||
.direction(8)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-inserter".to_owned(),
|
||||
2,
|
||||
BlueprintPosition::new(4.5, -1.5),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"fast-transport-belt".to_owned(),
|
||||
3,
|
||||
BlueprintPosition::new(3.5, -1.5),
|
||||
)
|
||||
.build(),
|
||||
];
|
||||
|
||||
station_unload(64, 3, &full, Beltspeed::Normal, false, 3.5, -2.5)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue