Allow stationary interfaces for layouting
This commit is contained in:
parent
8c8cdcc802
commit
fda5361a2b
3 changed files with 40 additions and 24 deletions
|
|
@ -103,9 +103,9 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
Beltspeed::from_items_per_second(2.0 * f64::max(c1.amount, c2.amount));
|
||||
|
||||
connections.push(Connection {
|
||||
startblock: block_index + 1,
|
||||
startblock: Some(block_index + 1),
|
||||
startpoint: 0,
|
||||
endblock: block_index,
|
||||
endblock: Some(block_index),
|
||||
endpoint: if c0_bigger { 0 } else { 1 },
|
||||
lanes: 1,
|
||||
beltspeed,
|
||||
|
|
@ -335,9 +335,9 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
for (i, c) in factory_graph.factory_connections.iter().enumerate() {
|
||||
// dbg!(i, c);
|
||||
connections.push(Connection {
|
||||
startblock: intermediate_connections[c.from].1[&i].0,
|
||||
startblock: Some(intermediate_connections[c.from].1[&i].0),
|
||||
startpoint: intermediate_connections[c.from].1[&i].1,
|
||||
endblock: intermediate_connections[c.to].0[&i].0,
|
||||
endblock: Some(intermediate_connections[c.to].0[&i].0),
|
||||
endpoint: intermediate_connections[c.to].0[&i].1,
|
||||
lanes: 1,
|
||||
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
||||
|
|
@ -348,6 +348,8 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
// dbg!(&connections);
|
||||
|
||||
let layout_input = LayoutInput {
|
||||
input: Vec::new(),
|
||||
output: Vec::new(),
|
||||
blocks,
|
||||
connections,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,11 +27,12 @@ pub struct Interface {
|
|||
pub dir: Direction,
|
||||
}
|
||||
|
||||
/// None: The static input and output interface of the layout input
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Connection {
|
||||
pub startblock: usize,
|
||||
pub startblock: Option<usize>,
|
||||
pub startpoint: usize,
|
||||
pub endblock: usize,
|
||||
pub endblock: Option<usize>,
|
||||
pub endpoint: usize,
|
||||
pub lanes: usize,
|
||||
pub beltspeed: Beltspeed,
|
||||
|
|
@ -40,6 +41,8 @@ pub struct Connection {
|
|||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct LayoutInput {
|
||||
pub blocks: Vec<MacroBlock>,
|
||||
pub input: Vec<Interface>,
|
||||
pub output: Vec<Interface>,
|
||||
pub connections: Vec<Connection>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
use crate::{LayoutInput, LayoutResult};
|
||||
use factorio_core::prelude::*;
|
||||
use factorio_pathfinding::{Connection, examples::HashMapMap};
|
||||
use rand::{
|
||||
Rng,
|
||||
seq::IndexedRandom,
|
||||
};
|
||||
use rand::{Rng, seq::IndexedRandom};
|
||||
|
||||
pub fn initally_set_blocks(
|
||||
input: &LayoutInput,
|
||||
|
|
@ -113,20 +110,34 @@ pub fn path_input_from_blocks_positions(
|
|||
}
|
||||
|
||||
for c in &input.connections {
|
||||
let start_transform = block_positions[c.startblock].block_to_world();
|
||||
let start_pos = input.blocks[c.startblock].output[c.startpoint]
|
||||
let start_pos;
|
||||
let start_dir;
|
||||
if let Some(block) = c.startblock {
|
||||
let start_transform = block_positions[block].block_to_world();
|
||||
start_pos = input.blocks[block].output[c.startpoint]
|
||||
.offset
|
||||
.transform(start_transform);
|
||||
let start_dir = input.blocks[c.startblock].output[c.startpoint]
|
||||
start_dir = input.blocks[block].output[c.startpoint]
|
||||
.dir
|
||||
.transform(start_transform);
|
||||
let end_transform = block_positions[c.endblock].block_to_world();
|
||||
let end_pos = input.blocks[c.endblock].input[c.endpoint]
|
||||
} else {
|
||||
start_pos = input.output[c.startpoint].offset;
|
||||
start_dir = input.output[c.startpoint].dir;
|
||||
}
|
||||
let end_pos;
|
||||
let end_dir;
|
||||
if let Some(block) = c.endblock {
|
||||
let end_transform = block_positions[block].block_to_world();
|
||||
end_pos = input.blocks[block].input[c.endpoint]
|
||||
.offset
|
||||
.transform(end_transform);
|
||||
let end_dir = input.blocks[c.endblock].input[c.endpoint]
|
||||
end_dir = input.blocks[block].input[c.endpoint]
|
||||
.dir
|
||||
.transform(end_transform);
|
||||
} else {
|
||||
end_pos = input.input[c.endpoint].offset;
|
||||
end_dir = input.input[c.endpoint].dir;
|
||||
}
|
||||
|
||||
connections.push(Connection {
|
||||
start_pos,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue