Add multistation to factory
This commit is contained in:
parent
41a528a49c
commit
5f5fe0c149
8 changed files with 98 additions and 46 deletions
|
|
@ -16,12 +16,10 @@ subfactories:
|
|||
machines: 32
|
||||
machine: assembly-machine-3
|
||||
- !SubFactory
|
||||
recipe: wall
|
||||
recipe: stone-wall
|
||||
machines: 4
|
||||
machine: assembly-machine-3
|
||||
- !ExternalConnection
|
||||
inputs: 1
|
||||
outputs: 6
|
||||
factory_connections:
|
||||
- item: military-science-pack
|
||||
amount: 10
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ subfactories:
|
|||
machines: 10
|
||||
machine: assembly-machine-3
|
||||
- !ExternalConnection
|
||||
inputs: 1
|
||||
outputs: 10
|
||||
- !Splitter
|
||||
- !Splitter
|
||||
- !Splitter
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ subfactories:
|
|||
machine: assembly-machine-3
|
||||
- !SideLoader
|
||||
- !ExternalConnection
|
||||
inputs: 1
|
||||
outputs: 8
|
||||
- !SideLoader
|
||||
factory_connections:
|
||||
- item: iron-gear-wheel
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ subfactories:
|
|||
machines: 6
|
||||
machine: assembly-machine-3
|
||||
- !ExternalConnection
|
||||
inputs: 1
|
||||
outputs: 5
|
||||
- !Splitter
|
||||
factory_connections:
|
||||
- item: logistic-science-pack
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ subfactories:
|
|||
machines: 6
|
||||
machine: assembly-machine-3
|
||||
- !ExternalConnection
|
||||
inputs: 1
|
||||
outputs: 5
|
||||
factory_connections:
|
||||
- item: iron-gear-wheel
|
||||
amount: 15
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@ use factorio_pathfinding::Pathfinder;
|
|||
use rand::{Rng, SeedableRng, seq::IndexedRandom};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::assembly::assembly_line_2_input;
|
||||
use crate::{
|
||||
assembly::assembly_line_2_input,
|
||||
multistation::{StationSpec, multistation},
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FactoryGraph {
|
||||
|
|
@ -22,10 +25,7 @@ pub enum Building {
|
|||
machines: usize,
|
||||
machine: String,
|
||||
},
|
||||
ExternalConnection {
|
||||
inputs: usize,
|
||||
outputs: usize,
|
||||
},
|
||||
ExternalConnection,
|
||||
Splitter,
|
||||
SideLoader,
|
||||
}
|
||||
|
|
@ -59,8 +59,9 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
let mut connections = Vec::new();
|
||||
let mut intermediate_connections = Vec::new();
|
||||
|
||||
let mut static_input = Vec::new();
|
||||
let mut static_output = Vec::new();
|
||||
let mut static_input_offset = 0;
|
||||
let mut static_output_offset = 0;
|
||||
let mut station_spec = Vec::new();
|
||||
|
||||
for (i, b) in factory_graph.subfactories.iter().enumerate() {
|
||||
let mut input_connections = factory_graph
|
||||
|
|
@ -254,25 +255,39 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
blocks.push(mb);
|
||||
}
|
||||
}
|
||||
Building::ExternalConnection { inputs, outputs } => {
|
||||
let step = 4;
|
||||
let static_input_offset = static_input.len();
|
||||
let static_output_offset = static_output.len();
|
||||
static_input.extend((0..*inputs).map(|y| Interface {
|
||||
offset: Position::new(
|
||||
0,
|
||||
step * (y + static_input_offset + static_output_offset) as PositionType,
|
||||
),
|
||||
dir: Direction::Left,
|
||||
Building::ExternalConnection => {
|
||||
let step = 1;
|
||||
// static_input.extend((0..*inputs).map(|y| Interface {
|
||||
// offset: Position::new(
|
||||
// -1,
|
||||
// step * (y + static_input_offset + static_output_offset) as PositionType,
|
||||
// ),
|
||||
// dir: Direction::Left,
|
||||
// }));
|
||||
// static_output.extend((0..*outputs).map(|y| Interface {
|
||||
// offset: Position::new(
|
||||
// -1,
|
||||
// step * (y + static_input_offset + static_output_offset + inputs)
|
||||
// as PositionType,
|
||||
// ),
|
||||
// dir: Direction::Right,
|
||||
// }));
|
||||
|
||||
station_spec.extend(input_connections.iter().map(|&(_, c)| StationSpec {
|
||||
locomotives: 2,
|
||||
wagons: 4,
|
||||
load: true,
|
||||
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
||||
lanes: 1,
|
||||
}));
|
||||
static_output.extend((0..*outputs).map(|y| Interface {
|
||||
offset: Position::new(
|
||||
0,
|
||||
step * (y + static_input_offset + static_output_offset + inputs)
|
||||
as PositionType,
|
||||
),
|
||||
dir: Direction::Right,
|
||||
station_spec.extend(output_connections.iter().map(|&(_, c)| StationSpec {
|
||||
locomotives: 2,
|
||||
wagons: 4,
|
||||
load: false,
|
||||
beltspeed: Beltspeed::from_items_per_second(c.amount),
|
||||
lanes: 1,
|
||||
}));
|
||||
|
||||
intermediate_connections.push(IntermediateConnection {
|
||||
input: input_connections
|
||||
.iter()
|
||||
|
|
@ -301,6 +316,8 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
})
|
||||
.collect::<HashMap<_, _>>(),
|
||||
});
|
||||
static_input_offset += input_connections.len();
|
||||
static_output_offset += output_connections.len();
|
||||
}
|
||||
Building::SideLoader => {
|
||||
let mut blueprint = Blueprint::new();
|
||||
|
|
@ -449,6 +466,44 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
// dbg!(&blocks);
|
||||
// dbg!(&connections);
|
||||
|
||||
let (multistation_blueprint, multistation_x_offset, mut multistation_y_offsets) =
|
||||
multistation(&station_spec, 8);
|
||||
|
||||
let multistation_y_offset = multistation_y_offsets[0];
|
||||
multistation_y_offsets.iter_mut().for_each(move |y| {
|
||||
*y -= multistation_y_offset;
|
||||
});
|
||||
|
||||
let static_input = station_spec
|
||||
.iter()
|
||||
.zip(multistation_y_offsets.iter())
|
||||
.filter_map(|(s, y)| {
|
||||
if s.load {
|
||||
Some(Interface {
|
||||
offset: Position::new(-1, y / 2),
|
||||
dir: Direction::Left,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let static_output = station_spec
|
||||
.iter()
|
||||
.zip(multistation_y_offsets.iter())
|
||||
.filter_map(|(s, y)| {
|
||||
if !s.load {
|
||||
Some(Interface {
|
||||
offset: Position::new(-1, y / 2),
|
||||
dir: Direction::Right,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let layout_input = LayoutInput {
|
||||
static_input,
|
||||
static_output,
|
||||
|
|
@ -476,5 +531,12 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
b.add_path(&path[1..], connection.beltspeed);
|
||||
}
|
||||
|
||||
b.transform(Transformation::new(
|
||||
Direction::Up,
|
||||
Position::new(multistation_x_offset, multistation_y_offset - 2),
|
||||
));
|
||||
|
||||
b.add_blueprint(multistation_blueprint);
|
||||
|
||||
b
|
||||
}
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ pub fn multistation(
|
|||
}
|
||||
}
|
||||
|
||||
blueprint.transform(Transformation::new(Direction::Right, Position::new(0, 0)));
|
||||
// blueprint.transform(Transformation::new(Direction::Right, Position::new(0, 0)));
|
||||
|
||||
(blueprint, outrail_x + 5, output_heights)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
use crate::examples::HashMapMap;
|
||||
use crate::graph::wheighted_graph::shortest_path::a_star;
|
||||
use crate::graph::wheighted_graph::WheightedGraph;
|
||||
use crate::misc::Map;
|
||||
use crate::priority_queue::binary_heap::FastBinaryHeap;
|
||||
use crate::Connection;
|
||||
use crate::Map as _;
|
||||
use crate::SinglePathInput;
|
||||
use crate::SinglePathfinder;
|
||||
use crate::examples::HashMapMap;
|
||||
use crate::graph::wheighted_graph::WheightedGraph;
|
||||
use crate::graph::wheighted_graph::shortest_path::a_star;
|
||||
use crate::misc::Map;
|
||||
use crate::priority_queue::binary_heap::FastBinaryHeap;
|
||||
use factorio_core::{prelude::*, visualize::Visualize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::span;
|
||||
use tracing::Level;
|
||||
use tracing::span;
|
||||
|
||||
pub mod brute_force;
|
||||
|
||||
|
|
@ -119,8 +119,8 @@ impl Problem {
|
|||
}
|
||||
|
||||
for (i, path) in self.path.iter().enumerate() {
|
||||
if i != without {
|
||||
for p in path {
|
||||
if i != without && !path.is_empty() {
|
||||
for p in &path[1..] {
|
||||
let weight = 1000.0;
|
||||
let x = p.0.x as usize;
|
||||
let y = p.0.y as usize;
|
||||
|
|
@ -238,8 +238,8 @@ impl WheightedGraph for MapInternal<'_> {
|
|||
let penalty = self.map.get(next.x as usize, next.y as usize).weight;
|
||||
match num {
|
||||
0 => Some(((next, node.1), 1.5 + penalty)),
|
||||
1 => Some(((next, node.1.counter_clockwise()), 1.5 + penalty)),
|
||||
2 => Some(((next, node.1.clockwise()), 1.5 + penalty)),
|
||||
1 => Some(((next, node.1.counter_clockwise()), 2.0 + penalty)),
|
||||
2 => Some(((next, node.1.clockwise()), 2.0 + penalty)),
|
||||
_ => {
|
||||
let mut count = 2;
|
||||
for l in 2..=6 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue