Convert station to abstraction
This commit is contained in:
parent
2f12802507
commit
e969ba848b
6 changed files with 522 additions and 448 deletions
|
|
@ -1,27 +1,19 @@
|
|||
use factorio_blueprint::{BlueprintEntity, BlueprintPosition};
|
||||
use factorio_core::beltoptions::Beltspeed;
|
||||
use factorio_blueprint::abstraction::{Blueprint, Entity};
|
||||
use factorio_core::{beltoptions::Beltspeed, prelude::*};
|
||||
|
||||
pub fn merger(
|
||||
reverse: bool,
|
||||
beltspeed: Beltspeed,
|
||||
offset_x: f64,
|
||||
offset_y: f64,
|
||||
outer_offset: u32,
|
||||
intervall: usize,
|
||||
outputs: usize,
|
||||
lines: usize,
|
||||
) -> Vec<BlueprintEntity> {
|
||||
) -> Blueprint {
|
||||
let section_size = lines / outputs;
|
||||
assert!(lines % outputs == 0);
|
||||
assert!(section_size.is_power_of_two());
|
||||
assert!(outputs <= lines);
|
||||
|
||||
let flip = match reverse {
|
||||
true => 8,
|
||||
false => 0,
|
||||
};
|
||||
|
||||
let mut e = Vec::new();
|
||||
let mut b = Blueprint::new();
|
||||
|
||||
// output and merging
|
||||
for o in 0..outputs {
|
||||
|
|
@ -31,37 +23,30 @@ pub fn merger(
|
|||
let depth = o + i.count_ones() as usize;
|
||||
|
||||
for j in 0..depth {
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
stubspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (i + o * section_size)) as f64 + offset_x,
|
||||
offset_y - j as f64,
|
||||
),
|
||||
)
|
||||
.direction(flip)
|
||||
.build(),
|
||||
);
|
||||
b.add_entity(Entity::new_belt(
|
||||
stubspeed,
|
||||
Position::new(
|
||||
(intervall * (i + o * section_size)) as PositionType,
|
||||
-(j as PositionType),
|
||||
),
|
||||
match reverse {
|
||||
true => Direction::Down,
|
||||
false => Direction::Up,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
stubspeed.string(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (i + o * section_size)) as f64 + offset_x,
|
||||
offset_y - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(match reverse {
|
||||
true => 8,
|
||||
false => 12,
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
b.add_entity(Entity::new_belt(
|
||||
stubspeed,
|
||||
Position::new(
|
||||
(intervall * (i + o * section_size)) as PositionType,
|
||||
-(depth as PositionType),
|
||||
),
|
||||
match reverse {
|
||||
true => Direction::Down,
|
||||
false => Direction::Left,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
// merger
|
||||
|
|
@ -70,53 +55,53 @@ pub fn merger(
|
|||
let mergespeed = beltspeed.halvings((section_size.ilog2() as usize) - i);
|
||||
for j in 0..(section_size / p) {
|
||||
let depth = o + j.count_ones() as usize;
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
e.push(
|
||||
BlueprintEntity::builder(
|
||||
mergespeed.string_splitter(),
|
||||
offset,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (j * p + o * section_size)) as f64 - i as f64 + offset_x,
|
||||
offset_y - i as f64 + 0.5 - depth as f64,
|
||||
|
||||
b.add_entity(Entity::new_splitter(
|
||||
mergespeed,
|
||||
Position::new(
|
||||
(intervall * (j * p + o * section_size)) as PositionType
|
||||
- i as PositionType,
|
||||
0 - i as PositionType - depth as PositionType + !reverse as PositionType,
|
||||
),
|
||||
match reverse {
|
||||
true => Direction::Right,
|
||||
false => Direction::Left,
|
||||
},
|
||||
));
|
||||
|
||||
for l in 0..(7 * p / 2) {
|
||||
b.add_entity(Entity::new_belt(
|
||||
mergespeed.halve(),
|
||||
Position::new(
|
||||
(intervall * (j * p + o * section_size) + l + 1) as PositionType
|
||||
- i as PositionType,
|
||||
0 - i as PositionType - depth as PositionType,
|
||||
),
|
||||
)
|
||||
.direction(12 - flip)
|
||||
.build(),
|
||||
);
|
||||
e.extend((0..(7 * p / 2)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
mergespeed.halve().string(),
|
||||
offset + 1 + l as u32,
|
||||
BlueprintPosition::new(
|
||||
(intervall * (j * p + o * section_size)) as f64 - i as f64
|
||||
+ offset_x
|
||||
+ l as f64
|
||||
+ 1.0,
|
||||
offset_y - i as f64 - depth as f64,
|
||||
),
|
||||
)
|
||||
.direction(12 - flip)
|
||||
.build()
|
||||
}));
|
||||
match reverse {
|
||||
true => Direction::Right,
|
||||
false => Direction::Left,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// connect
|
||||
let offset = outer_offset + e.len() as u32;
|
||||
let step = o + section_size.ilog2() as usize;
|
||||
e.extend((0..(7 * o * section_size)).map(|l| {
|
||||
BlueprintEntity::builder(
|
||||
beltspeed.string(),
|
||||
offset + l as u32,
|
||||
BlueprintPosition::new(
|
||||
l as f64 + offset_x - section_size.ilog2() as f64,
|
||||
offset_y - step as f64,
|
||||
for l in 0..(7 * o * section_size) {
|
||||
b.add_entity(Entity::new_belt(
|
||||
beltspeed,
|
||||
Position::new(
|
||||
l as PositionType - section_size.ilog2() as PositionType,
|
||||
-(step as PositionType),
|
||||
),
|
||||
)
|
||||
.direction(12 - flip)
|
||||
.build()
|
||||
}));
|
||||
match reverse {
|
||||
true => Direction::Right,
|
||||
false => Direction::Left,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
e
|
||||
b
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue