Improve automatic splitter
This commit is contained in:
parent
aee56af22f
commit
618d9ca9de
2 changed files with 60 additions and 19 deletions
|
|
@ -449,22 +449,6 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
});
|
||||
}
|
||||
Building::Distributor => {
|
||||
let mut blueprint = Blueprint::new();
|
||||
blueprint.add_entity(Entity::new_splitter_with_priority(
|
||||
Beltspeed::from_items_per_second(
|
||||
input_connections
|
||||
.iter()
|
||||
.chain(output_connections.iter())
|
||||
.map(|&(_, c)| c.amount)
|
||||
.max_by(|x, y| x.partial_cmp(y).unwrap())
|
||||
.unwrap_or(1.0),
|
||||
),
|
||||
Position::new(2, 1),
|
||||
Direction::Up,
|
||||
None,
|
||||
Some(true),
|
||||
));
|
||||
|
||||
let macro_block = MacroBlock {
|
||||
size: Position::new(2, 1),
|
||||
input: vec![
|
||||
|
|
@ -514,7 +498,7 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
endblock: Some(blocks.len()),
|
||||
endpoint: 0,
|
||||
lanes: 1,
|
||||
beltspeed: Beltspeed::Turbo,
|
||||
beltspeed: Beltspeed::from_items_per_second(amount),
|
||||
});
|
||||
}
|
||||
intermediate_connections_input.insert(
|
||||
|
|
@ -525,6 +509,17 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
},
|
||||
);
|
||||
|
||||
let mut blueprint = Blueprint::new();
|
||||
blueprint.add_entity(Entity::new_splitter_with_priority(
|
||||
Beltspeed::from_items_per_second(
|
||||
amount + input_connections[input_index].1.amount,
|
||||
),
|
||||
Position::new(2, 1),
|
||||
Direction::Up,
|
||||
None,
|
||||
Some(true),
|
||||
Some("deconstruction-planner".to_string()),
|
||||
));
|
||||
blueprints.push(blueprint.clone());
|
||||
blocks.push(macro_block.clone());
|
||||
amount += input_connections[input_index].1.amount;
|
||||
|
|
@ -538,7 +533,7 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
endblock: Some(blocks.len()),
|
||||
endpoint: 0,
|
||||
lanes: 1,
|
||||
beltspeed: Beltspeed::Turbo,
|
||||
beltspeed: Beltspeed::from_items_per_second(amount),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -551,6 +546,15 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
},
|
||||
);
|
||||
|
||||
let mut blueprint = Blueprint::new();
|
||||
blueprint.add_entity(Entity::new_splitter_with_priority(
|
||||
Beltspeed::from_items_per_second(amount),
|
||||
Position::new(2, 1),
|
||||
Direction::Up,
|
||||
None,
|
||||
Some(true),
|
||||
None,
|
||||
));
|
||||
blueprints.push(blueprint.clone());
|
||||
blocks.push(macro_block.clone());
|
||||
} else {
|
||||
|
|
@ -569,7 +573,23 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
|
|||
},
|
||||
);
|
||||
|
||||
blueprints.push(blueprint.clone());
|
||||
let mut blueprint = Blueprint::new();
|
||||
blueprint.add_entity(Entity::new_splitter_with_priority(
|
||||
Beltspeed::from_items_per_second(f64::max(
|
||||
f64::max(amount, input_connections[input_index].1.amount),
|
||||
f64::max(
|
||||
amount + input_connections[input_index].1.amount
|
||||
- output_connections[output_index].1.amount,
|
||||
output_connections[output_index].1.amount,
|
||||
),
|
||||
)),
|
||||
Position::new(2, 1),
|
||||
Direction::Up,
|
||||
None,
|
||||
Some(true),
|
||||
None,
|
||||
));
|
||||
blueprints.push(blueprint);
|
||||
blocks.push(macro_block.clone());
|
||||
amount += input_connections[input_index].1.amount;
|
||||
input_index += 1;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ pub enum EntityType {
|
|||
beltspeed: Beltspeed,
|
||||
input_priority_left: Option<bool>,
|
||||
output_priority_left: Option<bool>,
|
||||
filter: Option<String>,
|
||||
},
|
||||
ElectricPole(ElectricPoleType),
|
||||
Inserter {
|
||||
|
|
@ -212,6 +213,7 @@ impl Entity {
|
|||
beltspeed,
|
||||
input_priority_left: None,
|
||||
output_priority_left: None,
|
||||
filter: None,
|
||||
},
|
||||
position,
|
||||
direction,
|
||||
|
|
@ -224,12 +226,14 @@ impl Entity {
|
|||
direction: Direction,
|
||||
input_priority_left: Option<bool>,
|
||||
output_priority_left: Option<bool>,
|
||||
filter: Option<String>,
|
||||
) -> Self {
|
||||
Self::new(
|
||||
EntityType::Splitter {
|
||||
beltspeed,
|
||||
input_priority_left,
|
||||
output_priority_left,
|
||||
filter,
|
||||
},
|
||||
position,
|
||||
direction,
|
||||
|
|
@ -321,6 +325,7 @@ impl Entity {
|
|||
beltspeed,
|
||||
input_priority_left: _,
|
||||
output_priority_left: _,
|
||||
filter: _,
|
||||
} => beltspeed.string_splitter(),
|
||||
EntityType::Unknown {
|
||||
name,
|
||||
|
|
@ -379,6 +384,7 @@ impl Entity {
|
|||
beltspeed: _,
|
||||
input_priority_left,
|
||||
output_priority_left: _,
|
||||
filter: _,
|
||||
} => match input_priority_left {
|
||||
Some(true) => Some("left".to_string()),
|
||||
Some(false) => Some("right".to_string()),
|
||||
|
|
@ -394,6 +400,7 @@ impl Entity {
|
|||
beltspeed: _,
|
||||
input_priority_left: _,
|
||||
output_priority_left,
|
||||
filter: _,
|
||||
} => match output_priority_left {
|
||||
Some(true) => Some("left".to_string()),
|
||||
Some(false) => Some("right".to_string()),
|
||||
|
|
@ -402,6 +409,19 @@ impl Entity {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_maybe_filter(&self) -> Option<String> {
|
||||
match &self.entity {
|
||||
EntityType::Splitter {
|
||||
beltspeed: _,
|
||||
input_priority_left: _,
|
||||
output_priority_left: _,
|
||||
filter,
|
||||
} => filter.clone(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn size(&self) -> Position {
|
||||
match &self.entity {
|
||||
EntityType::Splitter { .. } => Position::new(4, 2),
|
||||
|
|
@ -631,6 +651,7 @@ impl Blueprint {
|
|||
.maybe_recipe(e.get_maybe_recipe())
|
||||
.maybe_input_priority(e.get_maybe_input_priority())
|
||||
.maybe_output_priority(e.get_maybe_output_priority())
|
||||
.maybe_filter(e.get_maybe_filter())
|
||||
.build()
|
||||
})
|
||||
.collect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue