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));
|
Beltspeed::from_items_per_second(2.0 * f64::max(c1.amount, c2.amount));
|
||||||
|
|
||||||
connections.push(Connection {
|
connections.push(Connection {
|
||||||
startblock: block_index + 1,
|
startblock: Some(block_index + 1),
|
||||||
startpoint: 0,
|
startpoint: 0,
|
||||||
endblock: block_index,
|
endblock: Some(block_index),
|
||||||
endpoint: if c0_bigger { 0 } else { 1 },
|
endpoint: if c0_bigger { 0 } else { 1 },
|
||||||
lanes: 1,
|
lanes: 1,
|
||||||
beltspeed,
|
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() {
|
for (i, c) in factory_graph.factory_connections.iter().enumerate() {
|
||||||
// dbg!(i, c);
|
// dbg!(i, c);
|
||||||
connections.push(Connection {
|
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,
|
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,
|
endpoint: intermediate_connections[c.to].0[&i].1,
|
||||||
lanes: 1,
|
lanes: 1,
|
||||||
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
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);
|
// dbg!(&connections);
|
||||||
|
|
||||||
let layout_input = LayoutInput {
|
let layout_input = LayoutInput {
|
||||||
|
input: Vec::new(),
|
||||||
|
output: Vec::new(),
|
||||||
blocks,
|
blocks,
|
||||||
connections,
|
connections,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,12 @@ pub struct Interface {
|
||||||
pub dir: Direction,
|
pub dir: Direction,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// None: The static input and output interface of the layout input
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
pub startblock: usize,
|
pub startblock: Option<usize>,
|
||||||
pub startpoint: usize,
|
pub startpoint: usize,
|
||||||
pub endblock: usize,
|
pub endblock: Option<usize>,
|
||||||
pub endpoint: usize,
|
pub endpoint: usize,
|
||||||
pub lanes: usize,
|
pub lanes: usize,
|
||||||
pub beltspeed: Beltspeed,
|
pub beltspeed: Beltspeed,
|
||||||
|
|
@ -40,6 +41,8 @@ pub struct Connection {
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct LayoutInput {
|
pub struct LayoutInput {
|
||||||
pub blocks: Vec<MacroBlock>,
|
pub blocks: Vec<MacroBlock>,
|
||||||
|
pub input: Vec<Interface>,
|
||||||
|
pub output: Vec<Interface>,
|
||||||
pub connections: Vec<Connection>,
|
pub connections: Vec<Connection>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
use crate::{LayoutInput, LayoutResult};
|
use crate::{LayoutInput, LayoutResult};
|
||||||
use factorio_core::prelude::*;
|
use factorio_core::prelude::*;
|
||||||
use factorio_pathfinding::{Connection, examples::HashMapMap};
|
use factorio_pathfinding::{Connection, examples::HashMapMap};
|
||||||
use rand::{
|
use rand::{Rng, seq::IndexedRandom};
|
||||||
Rng,
|
|
||||||
seq::IndexedRandom,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn initally_set_blocks(
|
pub fn initally_set_blocks(
|
||||||
input: &LayoutInput,
|
input: &LayoutInput,
|
||||||
|
|
@ -113,20 +110,34 @@ pub fn path_input_from_blocks_positions(
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in &input.connections {
|
for c in &input.connections {
|
||||||
let start_transform = block_positions[c.startblock].block_to_world();
|
let start_pos;
|
||||||
let start_pos = input.blocks[c.startblock].output[c.startpoint]
|
let start_dir;
|
||||||
.offset
|
if let Some(block) = c.startblock {
|
||||||
.transform(start_transform);
|
let start_transform = block_positions[block].block_to_world();
|
||||||
let start_dir = input.blocks[c.startblock].output[c.startpoint]
|
start_pos = input.blocks[block].output[c.startpoint]
|
||||||
.dir
|
.offset
|
||||||
.transform(start_transform);
|
.transform(start_transform);
|
||||||
let end_transform = block_positions[c.endblock].block_to_world();
|
start_dir = input.blocks[block].output[c.startpoint]
|
||||||
let end_pos = input.blocks[c.endblock].input[c.endpoint]
|
.dir
|
||||||
.offset
|
.transform(start_transform);
|
||||||
.transform(end_transform);
|
} else {
|
||||||
let end_dir = input.blocks[c.endblock].input[c.endpoint]
|
start_pos = input.output[c.startpoint].offset;
|
||||||
.dir
|
start_dir = input.output[c.startpoint].dir;
|
||||||
.transform(end_transform);
|
}
|
||||||
|
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);
|
||||||
|
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 {
|
connections.push(Connection {
|
||||||
start_pos,
|
start_pos,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue