Finish subfactory interface
This commit is contained in:
parent
82394cc342
commit
ff8795cea5
11 changed files with 537 additions and 310 deletions
|
|
@ -1,24 +1,29 @@
|
||||||
subfactories:
|
subfactories:
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: military-science-pack
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 40
|
recipe: military-science-pack
|
||||||
machine: assembling-machine-3
|
num_machines: 40
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: piercing-rounds-magazine
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 12
|
recipe: piercing-rounds-magazine
|
||||||
machine: assembling-machine-3
|
num_machines: 12
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: firearm-magazine
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 4
|
recipe: firearm-magazine
|
||||||
machine: assembling-machine-3
|
num_machines: 4
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: grenade
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 32
|
recipe: grenade
|
||||||
machine: assembling-machine-3
|
num_machines: 32
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: stone-wall
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 4
|
recipe: stone-wall
|
||||||
machine: assembling-machine-3
|
num_machines: 4
|
||||||
|
machine: assembling-machine-3
|
||||||
- !ExternalConnection
|
- !ExternalConnection
|
||||||
factory_connections:
|
factory_connections:
|
||||||
- item: military-science-pack
|
- item: military-science-pack
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1,54 @@
|
||||||
subfactories:
|
subfactories:
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: chemical-science-pack
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 96
|
recipe: chemical-science-pack
|
||||||
machine: assembling-machine-3
|
num_machines: 96
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: engine-unit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 80
|
recipe: engine-unit
|
||||||
machine: assembling-machine-3
|
num_machines: 80
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: iron-gear-wheel
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 4
|
recipe: iron-gear-wheel
|
||||||
machine: assembling-machine-3
|
num_machines: 4
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: pipe
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 8
|
recipe: pipe
|
||||||
machine: assembling-machine-3
|
num_machines: 8
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: advanced-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 72
|
recipe: advanced-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 72
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 10
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 10
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 10
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 10
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 10
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 10
|
||||||
|
machine: assembling-machine-3
|
||||||
- !ExternalConnection
|
- !ExternalConnection
|
||||||
- !Splitter
|
- !Splitter
|
||||||
- !Splitter
|
- !Splitter
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,69 @@
|
||||||
subfactories:
|
subfactories:
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: chemical-science-pack
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 96
|
recipe: chemical-science-pack
|
||||||
machine: assembling-machine-3
|
num_machines: 96
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: engine-unit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 80
|
recipe: engine-unit
|
||||||
machine: assembling-machine-3
|
num_machines: 80
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: iron-gear-wheel
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 4
|
recipe: iron-gear-wheel
|
||||||
machine: assembling-machine-3
|
num_machines: 4
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: pipe
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 8
|
recipe: pipe
|
||||||
machine: assembling-machine-3
|
num_machines: 8
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: advanced-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 72
|
recipe: advanced-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 72
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 10
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 10
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 10
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 10
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 10
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 10
|
||||||
|
machine: assembling-machine-3
|
||||||
- !ExternalConnection
|
- !ExternalConnection
|
||||||
- !Distributor
|
- !Distributor
|
||||||
- !Distributor
|
- !Distributor
|
||||||
- !Distributor
|
- !Distributor
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-plate
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 64
|
recipe: copper-plate
|
||||||
machine: electric-furnace
|
num_machines: 64
|
||||||
|
machine: electric-furnace
|
||||||
- !Distributor
|
- !Distributor
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-plate
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 48
|
recipe: copper-plate
|
||||||
machine: electric-furnace
|
num_machines: 48
|
||||||
|
machine: electric-furnace
|
||||||
factory_connections:
|
factory_connections:
|
||||||
- item: chemical-science-pack
|
- item: chemical-science-pack
|
||||||
amount: 10
|
amount: 10
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,30 @@
|
||||||
subfactories:
|
subfactories:
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: iron-gear-wheel
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 2
|
recipe: iron-gear-wheel
|
||||||
machine: assembling-machine-3
|
num_machines: 2
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 9
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 9
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !Splitter
|
- !Splitter
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: inserter
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 2
|
recipe: inserter
|
||||||
machine: assembling-machine-3
|
num_machines: 2
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: fast-inserter
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 2
|
recipe: fast-inserter
|
||||||
machine: assembling-machine-3
|
num_machines: 2
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SideLoader
|
- !SideLoader
|
||||||
- !ExternalConnection
|
- !ExternalConnection
|
||||||
- !SideLoader
|
- !SideLoader
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,34 @@
|
||||||
subfactories:
|
subfactories:
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: logistic-science-pack
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 48
|
recipe: logistic-science-pack
|
||||||
machine: assembling-machine-3
|
num_machines: 48
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: inserter
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 4
|
recipe: inserter
|
||||||
machine: assembling-machine-3
|
num_machines: 4
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 4
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 4
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: transport-belt
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 2
|
recipe: transport-belt
|
||||||
machine: assembling-machine-3
|
num_machines: 2
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: iron-gear-wheel
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: iron-gear-wheel
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !ExternalConnection
|
- !ExternalConnection
|
||||||
- !Splitter
|
- !Splitter
|
||||||
factory_connections:
|
factory_connections:
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,24 @@
|
||||||
subfactories:
|
subfactories:
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: iron-gear-wheel
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: iron-gear-wheel
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: copper-cable
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 9
|
recipe: copper-cable
|
||||||
machine: assembling-machine-3
|
num_machines: 9
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: electronic-circuit
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: electronic-circuit
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !SubFactory
|
- !SubFactory
|
||||||
recipe: inserter
|
subfactory: !DoubleAssemblingLine
|
||||||
machines: 6
|
recipe: inserter
|
||||||
machine: assembling-machine-3
|
num_machines: 6
|
||||||
|
machine: assembling-machine-3
|
||||||
- !ExternalConnection
|
- !ExternalConnection
|
||||||
factory_connections:
|
factory_connections:
|
||||||
- item: iron-gear-wheel
|
- item: iron-gear-wheel
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ struct Args {
|
||||||
json: bool,
|
json: bool,
|
||||||
assembly_machines: usize,
|
assembly_machines: usize,
|
||||||
machine: String,
|
machine: String,
|
||||||
recipe: String,
|
recipe: Option<String>,
|
||||||
output_belt: Beltspeed,
|
output_belt: Beltspeed,
|
||||||
input_belt: Vec<Beltspeed>,
|
input_belt: Vec<Beltspeed>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
multistation::{StationSpec, multistation},
|
multistation::{StationSpec, multistation},
|
||||||
subfactory::assembling_line::assembly_line_2_input,
|
subfactory::{BeltConnection, SubFactory, assembling_line::assembly_line_2_input},
|
||||||
};
|
};
|
||||||
use factorio_blueprint::abstraction::{Blueprint, Entity};
|
use factorio_blueprint::abstraction::{Blueprint, Entity};
|
||||||
use factorio_core::{beltoptions::Beltspeed, prelude::*, visualize::Visualize};
|
use factorio_core::{beltoptions::Beltspeed, prelude::*, visualize::Visualize};
|
||||||
|
|
@ -18,11 +18,7 @@ pub struct FactoryGraph {
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub enum Building {
|
pub enum Building {
|
||||||
SubFactory {
|
SubFactory { subfactory: SubFactory },
|
||||||
recipe: String,
|
|
||||||
machines: usize,
|
|
||||||
machine: String,
|
|
||||||
},
|
|
||||||
ExternalConnection,
|
ExternalConnection,
|
||||||
Splitter,
|
Splitter,
|
||||||
SideLoader,
|
SideLoader,
|
||||||
|
|
@ -65,7 +61,7 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
||||||
let mut station_spec = Vec::new();
|
let mut station_spec = Vec::new();
|
||||||
|
|
||||||
for (i, b) in factory_graph.subfactories.iter().enumerate() {
|
for (i, b) in factory_graph.subfactories.iter().enumerate() {
|
||||||
let mut input_connections = factory_graph
|
let input_connections = factory_graph
|
||||||
.factory_connections
|
.factory_connections
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|
@ -82,84 +78,115 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
||||||
let block_index = blocks.len();
|
let block_index = blocks.len();
|
||||||
|
|
||||||
match b {
|
match b {
|
||||||
Building::SubFactory {
|
Building::SubFactory { subfactory } => {
|
||||||
recipe,
|
let inputs = input_connections
|
||||||
machines,
|
.iter()
|
||||||
machine,
|
.map(|(_, f)| (f.item.as_str(), f.amount))
|
||||||
} => {
|
.fold(HashMap::new(), |mut h, (s, a)| {
|
||||||
// assert_eq!(machine, "assembly-machine-3");
|
match h.entry(s) {
|
||||||
assert_eq!(output_connections.len(), 1);
|
std::collections::hash_map::Entry::Occupied(mut occupied_entry) => {
|
||||||
assert!(input_connections.len() <= 3);
|
*occupied_entry.get_mut() += a;
|
||||||
let output_connection = output_connections.first().unwrap();
|
}
|
||||||
let intermediate_output_connection = HashMap::from([(
|
std::collections::hash_map::Entry::Vacant(vacant_entry) => {
|
||||||
output_connection.0,
|
vacant_entry.insert(a);
|
||||||
IntermediateConnectionEntry {
|
}
|
||||||
block: Some(block_index),
|
}
|
||||||
interface: 0,
|
h
|
||||||
},
|
})
|
||||||
)]);
|
.into_iter()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
input_connections.sort_by(|a, b| b.1.amount.total_cmp(&a.1.amount));
|
let outputs = output_connections
|
||||||
let (input_belt1, input_belt2, addition_blocks) = if let Some(
|
.iter()
|
||||||
&[
|
.map(|(_, f)| (f.item.as_str(), f.amount))
|
||||||
(connection_id0, c0),
|
.fold(HashMap::new(), |mut h, (s, a)| {
|
||||||
(connection_id1, c1),
|
match h.entry(s) {
|
||||||
(connection_id2, c2),
|
std::collections::hash_map::Entry::Occupied(mut occupied_entry) => {
|
||||||
],
|
*occupied_entry.get_mut() += a;
|
||||||
) =
|
}
|
||||||
input_connections.first_chunk()
|
std::collections::hash_map::Entry::Vacant(vacant_entry) => {
|
||||||
{
|
vacant_entry.insert(a);
|
||||||
let c0_bigger = c0.amount > c1.amount + c2.amount;
|
}
|
||||||
intermediate_connections.push(IntermediateConnection {
|
}
|
||||||
input: HashMap::from([
|
h
|
||||||
(
|
})
|
||||||
connection_id0,
|
.into_iter()
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let (b, m, input_belts, output_belts) =
|
||||||
|
subfactory.get_subfactory(&inputs, &outputs);
|
||||||
|
|
||||||
|
assert!(output_belts.len() == 1);
|
||||||
|
assert!(output_connections.len() == 1);
|
||||||
|
assert!(output_belts[0] == BeltConnection::Full(outputs[0]));
|
||||||
|
|
||||||
|
blueprints.push(b);
|
||||||
|
blocks.push(m);
|
||||||
|
|
||||||
|
let mut intermediate_input_connections = HashMap::new();
|
||||||
|
for (interface, input_belt) in input_belts.iter().enumerate() {
|
||||||
|
match input_belt {
|
||||||
|
BeltConnection::Full((s, _a)) => {
|
||||||
|
let input_connection = input_connections
|
||||||
|
.iter()
|
||||||
|
.find(|(_, f)| f.item == *s)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
intermediate_input_connections.insert(
|
||||||
|
input_connection.0,
|
||||||
IntermediateConnectionEntry {
|
IntermediateConnectionEntry {
|
||||||
block: Some(block_index),
|
block: Some(block_index),
|
||||||
interface: if c0_bigger { 1 } else { 0 },
|
interface,
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
(
|
}
|
||||||
connection_id1,
|
|
||||||
|
BeltConnection::Split { left, right } => {
|
||||||
|
let beltspeed =
|
||||||
|
Beltspeed::from_items_per_second(2.0 * f64::max(left.1, right.1));
|
||||||
|
|
||||||
|
connections.push(Connection {
|
||||||
|
startblock: Some(blocks.len()),
|
||||||
|
startpoint: 0,
|
||||||
|
endblock: Some(block_index),
|
||||||
|
endpoint: interface,
|
||||||
|
lanes: 1,
|
||||||
|
beltspeed,
|
||||||
|
});
|
||||||
|
|
||||||
|
let input_connection_left = input_connections
|
||||||
|
.iter()
|
||||||
|
.find(|(_, f)| f.item == *left.0)
|
||||||
|
.unwrap();
|
||||||
|
intermediate_input_connections.insert(
|
||||||
|
input_connection_left.0,
|
||||||
IntermediateConnectionEntry {
|
IntermediateConnectionEntry {
|
||||||
block: Some(block_index + 1),
|
block: Some(blocks.len()),
|
||||||
interface: 0,
|
interface: 0,
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
(
|
|
||||||
connection_id2,
|
let input_connection_right = input_connections
|
||||||
|
.iter()
|
||||||
|
.find(|(_, f)| f.item == *right.0)
|
||||||
|
.unwrap();
|
||||||
|
intermediate_input_connections.insert(
|
||||||
|
input_connection_right.0,
|
||||||
IntermediateConnectionEntry {
|
IntermediateConnectionEntry {
|
||||||
block: Some(block_index + 1),
|
block: Some(blocks.len()),
|
||||||
interface: 1,
|
interface: 1,
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
]),
|
|
||||||
output: intermediate_output_connection,
|
|
||||||
});
|
|
||||||
|
|
||||||
let beltspeed =
|
let mut b = Blueprint::new();
|
||||||
Beltspeed::from_items_per_second(2.0 * f64::max(c1.amount, c2.amount));
|
b.add_entity(Entity::new_belt(
|
||||||
|
beltspeed,
|
||||||
|
Position::new(1, 1),
|
||||||
|
Direction::Up,
|
||||||
|
));
|
||||||
|
|
||||||
connections.push(Connection {
|
blueprints.push(b);
|
||||||
startblock: Some(block_index + 1),
|
blocks.push(MacroBlock {
|
||||||
startpoint: 0,
|
|
||||||
endblock: Some(block_index),
|
|
||||||
endpoint: if c0_bigger { 0 } else { 1 },
|
|
||||||
lanes: 1,
|
|
||||||
beltspeed,
|
|
||||||
});
|
|
||||||
let mut b = Blueprint::new();
|
|
||||||
|
|
||||||
b.add_entity(Entity::new_belt(
|
|
||||||
beltspeed,
|
|
||||||
Position::new(1, 1),
|
|
||||||
Direction::Up,
|
|
||||||
));
|
|
||||||
(
|
|
||||||
Beltspeed::from_items_per_second(c0.amount),
|
|
||||||
Some(beltspeed),
|
|
||||||
vec![(
|
|
||||||
MacroBlock {
|
|
||||||
size: Position::new(1, 1),
|
size: Position::new(1, 1),
|
||||||
input: vec![
|
input: vec![
|
||||||
Interface {
|
Interface {
|
||||||
|
|
@ -175,87 +202,191 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
||||||
offset: Position::new(0, 0),
|
offset: Position::new(0, 0),
|
||||||
dir: Direction::Up,
|
dir: Direction::Up,
|
||||||
}],
|
}],
|
||||||
},
|
});
|
||||||
b,
|
}
|
||||||
)],
|
}
|
||||||
)
|
}
|
||||||
} else if let Some(&[(connection_id0, c0), (connection_id1, c1)]) =
|
|
||||||
input_connections.first_chunk()
|
|
||||||
{
|
|
||||||
intermediate_connections.push(IntermediateConnection {
|
|
||||||
input: HashMap::from([
|
|
||||||
(
|
|
||||||
connection_id0,
|
|
||||||
IntermediateConnectionEntry {
|
|
||||||
block: Some(block_index),
|
|
||||||
interface: 0,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
connection_id1,
|
|
||||||
IntermediateConnectionEntry {
|
|
||||||
block: Some(block_index),
|
|
||||||
interface: 1,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
output: intermediate_output_connection,
|
|
||||||
});
|
|
||||||
(
|
|
||||||
Beltspeed::from_items_per_second(c0.amount),
|
|
||||||
Some(Beltspeed::from_items_per_second(c1.amount)),
|
|
||||||
vec![],
|
|
||||||
)
|
|
||||||
} else if let Some(&[(connection_id, c)]) = input_connections.first_chunk() {
|
|
||||||
intermediate_connections.push(IntermediateConnection {
|
|
||||||
input: HashMap::from([(
|
|
||||||
connection_id,
|
|
||||||
IntermediateConnectionEntry {
|
|
||||||
block: Some(block_index),
|
|
||||||
interface: 0,
|
|
||||||
},
|
|
||||||
)]),
|
|
||||||
output: intermediate_output_connection,
|
|
||||||
});
|
|
||||||
(Beltspeed::from_items_per_second(c.amount), None, vec![])
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
|
|
||||||
let (b, size, y_output, y_inputs) = assembly_line_2_input(
|
intermediate_connections.push(IntermediateConnection {
|
||||||
*machines,
|
input: intermediate_input_connections,
|
||||||
machine,
|
output: HashMap::from([(
|
||||||
recipe,
|
output_connections[0].0,
|
||||||
input_belt1,
|
IntermediateConnectionEntry {
|
||||||
input_belt2,
|
block: Some(block_index),
|
||||||
Beltspeed::from_items_per_second(
|
interface: 0,
|
||||||
output_connections
|
},
|
||||||
.first()
|
)]),
|
||||||
.map(|&(_, c)| c.amount)
|
|
||||||
.unwrap_or(1.0),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
blueprints.push(b);
|
|
||||||
blocks.push(MacroBlock {
|
|
||||||
size,
|
|
||||||
input: y_inputs
|
|
||||||
.iter()
|
|
||||||
.map(|&y| Interface {
|
|
||||||
offset: Position::new(0, y),
|
|
||||||
dir: Direction::Right,
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
output: vec![Interface {
|
|
||||||
offset: Position::new(0, y_output),
|
|
||||||
dir: Direction::Left,
|
|
||||||
}],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (mb, b) in addition_blocks {
|
// // assert_eq!(machine, "assembly-machine-3");
|
||||||
blueprints.push(b);
|
// assert_eq!(output_connections.len(), 1);
|
||||||
blocks.push(mb);
|
// assert!(input_connections.len() <= 3);
|
||||||
}
|
// let output_connection = output_connections.first().unwrap();
|
||||||
|
// let intermediate_output_connection = HashMap::from([(
|
||||||
|
// output_connection.0,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index),
|
||||||
|
// interface: 0,
|
||||||
|
// },
|
||||||
|
// )]);
|
||||||
|
|
||||||
|
// input_connections.sort_by(|a, b| b.1.amount.total_cmp(&a.1.amount));
|
||||||
|
// let (input_belt1, input_belt2, addition_blocks) = if let Some(
|
||||||
|
// &[
|
||||||
|
// (connection_id0, c0),
|
||||||
|
// (connection_id1, c1),
|
||||||
|
// (connection_id2, c2),
|
||||||
|
// ],
|
||||||
|
// ) =
|
||||||
|
// input_connections.first_chunk()
|
||||||
|
// {
|
||||||
|
// let c0_bigger = c0.amount > c1.amount + c2.amount;
|
||||||
|
// intermediate_connections.push(IntermediateConnection {
|
||||||
|
// input: HashMap::from([
|
||||||
|
// (
|
||||||
|
// connection_id0,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index),
|
||||||
|
// interface: if c0_bigger { 1 } else { 0 },
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// (
|
||||||
|
// connection_id1,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index + 1),
|
||||||
|
// interface: 0,
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// (
|
||||||
|
// connection_id2,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index + 1),
|
||||||
|
// interface: 1,
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// ]),
|
||||||
|
// output: intermediate_output_connection,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// let beltspeed =
|
||||||
|
// Beltspeed::from_items_per_second(2.0 * f64::max(c1.amount, c2.amount));
|
||||||
|
|
||||||
|
// connections.push(Connection {
|
||||||
|
// startblock: Some(block_index + 1),
|
||||||
|
// startpoint: 0,
|
||||||
|
// endblock: Some(block_index),
|
||||||
|
// endpoint: if c0_bigger { 0 } else { 1 },
|
||||||
|
// lanes: 1,
|
||||||
|
// beltspeed,
|
||||||
|
// });
|
||||||
|
// let mut b = Blueprint::new();
|
||||||
|
|
||||||
|
// b.add_entity(Entity::new_belt(
|
||||||
|
// beltspeed,
|
||||||
|
// Position::new(1, 1),
|
||||||
|
// Direction::Up,
|
||||||
|
// ));
|
||||||
|
// (
|
||||||
|
// Beltspeed::from_items_per_second(c0.amount),
|
||||||
|
// Some(beltspeed),
|
||||||
|
// vec![(
|
||||||
|
// MacroBlock {
|
||||||
|
// size: Position::new(1, 1),
|
||||||
|
// input: vec![
|
||||||
|
// Interface {
|
||||||
|
// offset: Position::new(0, 0),
|
||||||
|
// dir: Direction::Right,
|
||||||
|
// },
|
||||||
|
// Interface {
|
||||||
|
// offset: Position::new(0, 0),
|
||||||
|
// dir: Direction::Left,
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// output: vec![Interface {
|
||||||
|
// offset: Position::new(0, 0),
|
||||||
|
// dir: Direction::Up,
|
||||||
|
// }],
|
||||||
|
// },
|
||||||
|
// b,
|
||||||
|
// )],
|
||||||
|
// )
|
||||||
|
// } else if let Some(&[(connection_id0, c0), (connection_id1, c1)]) =
|
||||||
|
// input_connections.first_chunk()
|
||||||
|
// {
|
||||||
|
// intermediate_connections.push(IntermediateConnection {
|
||||||
|
// input: HashMap::from([
|
||||||
|
// (
|
||||||
|
// connection_id0,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index),
|
||||||
|
// interface: 0,
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// (
|
||||||
|
// connection_id1,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index),
|
||||||
|
// interface: 1,
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// ]),
|
||||||
|
// output: intermediate_output_connection,
|
||||||
|
// });
|
||||||
|
// (
|
||||||
|
// Beltspeed::from_items_per_second(c0.amount),
|
||||||
|
// Some(Beltspeed::from_items_per_second(c1.amount)),
|
||||||
|
// vec![],
|
||||||
|
// )
|
||||||
|
// } else if let Some(&[(connection_id, c)]) = input_connections.first_chunk() {
|
||||||
|
// intermediate_connections.push(IntermediateConnection {
|
||||||
|
// input: HashMap::from([(
|
||||||
|
// connection_id,
|
||||||
|
// IntermediateConnectionEntry {
|
||||||
|
// block: Some(block_index),
|
||||||
|
// interface: 0,
|
||||||
|
// },
|
||||||
|
// )]),
|
||||||
|
// output: intermediate_output_connection,
|
||||||
|
// });
|
||||||
|
// (Beltspeed::from_items_per_second(c.amount), None, vec![])
|
||||||
|
// } else {
|
||||||
|
// unreachable!()
|
||||||
|
// };
|
||||||
|
|
||||||
|
// let (b, size, y_output, y_inputs) = assembly_line_2_input(
|
||||||
|
// *machines,
|
||||||
|
// machine,
|
||||||
|
// Some(recipe),
|
||||||
|
// input_belt1,
|
||||||
|
// input_belt2,
|
||||||
|
// Beltspeed::from_items_per_second(
|
||||||
|
// output_connections
|
||||||
|
// .first()
|
||||||
|
// .map(|&(_, c)| c.amount)
|
||||||
|
// .unwrap_or(1.0),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
|
||||||
|
// blueprints.push(b);
|
||||||
|
// blocks.push(MacroBlock {
|
||||||
|
// size,
|
||||||
|
// input: y_inputs
|
||||||
|
// .iter()
|
||||||
|
// .map(|&y| Interface {
|
||||||
|
// offset: Position::new(0, y),
|
||||||
|
// dir: Direction::Right,
|
||||||
|
// })
|
||||||
|
// .collect(),
|
||||||
|
// output: vec![Interface {
|
||||||
|
// offset: Position::new(0, y_output),
|
||||||
|
// dir: Direction::Left,
|
||||||
|
// }],
|
||||||
|
// });
|
||||||
|
|
||||||
|
// for (mb, b) in addition_blocks {
|
||||||
|
// blueprints.push(b);
|
||||||
|
// blocks.push(mb);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Building::ExternalConnection => {
|
Building::ExternalConnection => {
|
||||||
// let step = 1;
|
// let step = 1;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
|
use assembling_line::assembly_line_2_input;
|
||||||
use factorio_blueprint::abstraction::Blueprint;
|
use factorio_blueprint::abstraction::Blueprint;
|
||||||
use factorio_core::beltoptions::{Beltspeed, Belttype};
|
use factorio_core::{
|
||||||
use factorio_layout::MacroBlock;
|
beltoptions::{Beltspeed, Belttype},
|
||||||
|
prelude::{Direction, Position},
|
||||||
|
};
|
||||||
|
use factorio_layout::{Interface, MacroBlock};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod assembling_line;
|
pub mod assembling_line;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub enum SubFactory {
|
pub enum SubFactory {
|
||||||
AssemblingLine {
|
AssemblingLine {
|
||||||
num_machines: usize,
|
num_machines: usize,
|
||||||
|
|
@ -17,21 +23,25 @@ pub enum SubFactory {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BeltConnection {
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
Full(String),
|
pub enum BeltConnection<'a> {
|
||||||
Split { left: String, right: String },
|
Full((&'a str, f64)),
|
||||||
|
Split {
|
||||||
|
left: (&'a str, f64),
|
||||||
|
right: (&'a str, f64),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SubFactory {
|
impl SubFactory {
|
||||||
fn get_subfactory(
|
pub fn get_subfactory<'a>(
|
||||||
&self,
|
&self,
|
||||||
inputs: &[(&str, f64)],
|
inputs: &[(&'a str, f64)],
|
||||||
outputs: &[(&str, f64)],
|
outputs: &[(&'a str, f64)],
|
||||||
) -> (
|
) -> (
|
||||||
Blueprint,
|
Blueprint,
|
||||||
MacroBlock,
|
MacroBlock,
|
||||||
Vec<BeltConnection>,
|
Vec<BeltConnection<'a>>,
|
||||||
Vec<BeltConnection>,
|
Vec<BeltConnection<'a>>,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
SubFactory::AssemblingLine {
|
SubFactory::AssemblingLine {
|
||||||
|
|
@ -61,13 +71,13 @@ impl SubFactory {
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
BeltConnection::Split {
|
BeltConnection::Split {
|
||||||
left: input1.to_owned(),
|
left: (input1, amount1),
|
||||||
right: input2.to_owned(),
|
right: (input2, amount2),
|
||||||
},
|
},
|
||||||
Beltspeed::from_items_per_second(2.0 * f64::max(amount1, amount2)),
|
Beltspeed::from_items_per_second(2.0 * f64::max(amount1, amount2)),
|
||||||
BeltConnection::Split {
|
BeltConnection::Split {
|
||||||
left: input3.to_owned(),
|
left: (input3, amount3),
|
||||||
right: input4.to_owned(),
|
right: (input4, amount4),
|
||||||
},
|
},
|
||||||
Beltspeed::from_items_per_second(2.0 * f64::max(amount3, amount4)),
|
Beltspeed::from_items_per_second(2.0 * f64::max(amount3, amount4)),
|
||||||
)
|
)
|
||||||
|
|
@ -75,11 +85,11 @@ impl SubFactory {
|
||||||
inputs.first_chunk()
|
inputs.first_chunk()
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
BeltConnection::Full(input1.to_owned()),
|
BeltConnection::Full((input1, amount1)),
|
||||||
Beltspeed::from_items_per_second(amount1),
|
Beltspeed::from_items_per_second(amount1),
|
||||||
BeltConnection::Split {
|
BeltConnection::Split {
|
||||||
left: input2.to_owned(),
|
left: (input2, amount2),
|
||||||
right: input3.to_owned(),
|
right: (input3, amount3),
|
||||||
},
|
},
|
||||||
Beltspeed::from_items_per_second(2.0 * f64::max(amount2, amount3)),
|
Beltspeed::from_items_per_second(2.0 * f64::max(amount2, amount3)),
|
||||||
)
|
)
|
||||||
|
|
@ -87,27 +97,71 @@ impl SubFactory {
|
||||||
inputs.first_chunk()
|
inputs.first_chunk()
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
BeltConnection::Full(input1.to_owned()),
|
BeltConnection::Full((input1, amount1)),
|
||||||
Beltspeed::from_items_per_second(amount1),
|
Beltspeed::from_items_per_second(amount1),
|
||||||
BeltConnection::Full(input2.to_owned()),
|
BeltConnection::Full((input2, amount2)),
|
||||||
Beltspeed::from_items_per_second(amount2),
|
Beltspeed::from_items_per_second(amount2),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (b, size, y_output, y_inputs) = assembly_line_2_input(
|
||||||
|
*num_machines,
|
||||||
|
machine,
|
||||||
|
recipe.as_ref(),
|
||||||
|
belttype1,
|
||||||
|
Some(belttype2),
|
||||||
|
Beltspeed::from_items_per_second(outputs[0].1),
|
||||||
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
todo!(),
|
b,
|
||||||
todo!(),
|
MacroBlock {
|
||||||
|
size,
|
||||||
|
input: y_inputs
|
||||||
|
.iter()
|
||||||
|
.map(|&y| Interface {
|
||||||
|
offset: Position::new(0, y),
|
||||||
|
dir: Direction::Right,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
output: vec![Interface {
|
||||||
|
offset: Position::new(0, y_output),
|
||||||
|
dir: Direction::Left,
|
||||||
|
}],
|
||||||
|
},
|
||||||
vec![input1, input2],
|
vec![input1, input2],
|
||||||
vec![BeltConnection::Full(outputs[0].0.to_owned())],
|
vec![BeltConnection::Full(outputs[0])],
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
let (b, size, y_output, y_inputs) = assembly_line_2_input(
|
||||||
|
*num_machines,
|
||||||
|
machine,
|
||||||
|
recipe.as_ref(),
|
||||||
|
Beltspeed::from_items_per_second(inputs[0].1),
|
||||||
|
None,
|
||||||
|
Beltspeed::from_items_per_second(outputs[0].1),
|
||||||
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
todo!(),
|
b,
|
||||||
todo!(),
|
MacroBlock {
|
||||||
vec![BeltConnection::Full(inputs[0].0.to_owned())],
|
size,
|
||||||
vec![BeltConnection::Full(outputs[0].0.to_owned())],
|
input: y_inputs
|
||||||
|
.iter()
|
||||||
|
.map(|&y| Interface {
|
||||||
|
offset: Position::new(0, y),
|
||||||
|
dir: Direction::Right,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
output: vec![Interface {
|
||||||
|
offset: Position::new(0, y_output),
|
||||||
|
dir: Direction::Left,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
vec![BeltConnection::Full(inputs[0])],
|
||||||
|
vec![BeltConnection::Full(outputs[0])],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ AAABBBCCC
|
||||||
pub fn assembly_line(
|
pub fn assembly_line(
|
||||||
assembly_machines: usize,
|
assembly_machines: usize,
|
||||||
machine: impl AsRef<str>,
|
machine: impl AsRef<str>,
|
||||||
recipe: impl AsRef<str>,
|
recipe: Option<impl AsRef<str>>,
|
||||||
) -> Blueprint {
|
) -> Blueprint {
|
||||||
let mut blueprint = Blueprint::new();
|
let mut blueprint = Blueprint::new();
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
|
|
@ -228,7 +228,7 @@ pub fn assembly_line(
|
||||||
pub fn assembly_line_2_input(
|
pub fn assembly_line_2_input(
|
||||||
assembly_machines: usize,
|
assembly_machines: usize,
|
||||||
machine: impl AsRef<str>,
|
machine: impl AsRef<str>,
|
||||||
recipe: impl AsRef<str>,
|
recipe: Option<impl AsRef<str>>,
|
||||||
input_belt1: Beltspeed,
|
input_belt1: Beltspeed,
|
||||||
input_belt2: Option<Beltspeed>,
|
input_belt2: Option<Beltspeed>,
|
||||||
output_belt: Beltspeed,
|
output_belt: Beltspeed,
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ pub enum EntityType {
|
||||||
},
|
},
|
||||||
Production {
|
Production {
|
||||||
name: String,
|
name: String,
|
||||||
recipe: String,
|
recipe: Option<String>,
|
||||||
size: Position,
|
size: Position,
|
||||||
},
|
},
|
||||||
Rail {
|
Rail {
|
||||||
|
|
@ -276,7 +276,7 @@ impl Entity {
|
||||||
|
|
||||||
pub fn new_production(
|
pub fn new_production(
|
||||||
name: impl AsRef<str>,
|
name: impl AsRef<str>,
|
||||||
recipe: impl AsRef<str>,
|
recipe: Option<impl AsRef<str>>,
|
||||||
position: Position,
|
position: Position,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
size: Position,
|
size: Position,
|
||||||
|
|
@ -284,7 +284,7 @@ impl Entity {
|
||||||
Self::new(
|
Self::new(
|
||||||
EntityType::Production {
|
EntityType::Production {
|
||||||
name: name.as_ref().to_owned(),
|
name: name.as_ref().to_owned(),
|
||||||
recipe: recipe.as_ref().to_owned(),
|
recipe: recipe.map(|s| s.as_ref().to_owned()),
|
||||||
size,
|
size,
|
||||||
},
|
},
|
||||||
position,
|
position,
|
||||||
|
|
@ -384,7 +384,7 @@ impl Entity {
|
||||||
name: _,
|
name: _,
|
||||||
recipe,
|
recipe,
|
||||||
size: _,
|
size: _,
|
||||||
} => Some(recipe.clone()),
|
} => recipe.clone(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue