Improve automatic splitter

This commit is contained in:
hal8174 2025-04-01 18:56:28 +02:00
parent aee56af22f
commit 618d9ca9de
2 changed files with 60 additions and 19 deletions

View file

@ -449,22 +449,6 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
}); });
} }
Building::Distributor => { 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 { let macro_block = MacroBlock {
size: Position::new(2, 1), size: Position::new(2, 1),
input: vec![ input: vec![
@ -514,7 +498,7 @@ pub fn generate_factory<L: Layouter, P: Pathfinder + Sync, R: Rng + SeedableRng
endblock: Some(blocks.len()), endblock: Some(blocks.len()),
endpoint: 0, endpoint: 0,
lanes: 1, lanes: 1,
beltspeed: Beltspeed::Turbo, beltspeed: Beltspeed::from_items_per_second(amount),
}); });
} }
intermediate_connections_input.insert( 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()); blueprints.push(blueprint.clone());
blocks.push(macro_block.clone()); blocks.push(macro_block.clone());
amount += input_connections[input_index].1.amount; 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()), endblock: Some(blocks.len()),
endpoint: 0, endpoint: 0,
lanes: 1, 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()); blueprints.push(blueprint.clone());
blocks.push(macro_block.clone()); blocks.push(macro_block.clone());
} else { } 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()); blocks.push(macro_block.clone());
amount += input_connections[input_index].1.amount; amount += input_connections[input_index].1.amount;
input_index += 1; input_index += 1;

View file

@ -144,6 +144,7 @@ pub enum EntityType {
beltspeed: Beltspeed, beltspeed: Beltspeed,
input_priority_left: Option<bool>, input_priority_left: Option<bool>,
output_priority_left: Option<bool>, output_priority_left: Option<bool>,
filter: Option<String>,
}, },
ElectricPole(ElectricPoleType), ElectricPole(ElectricPoleType),
Inserter { Inserter {
@ -212,6 +213,7 @@ impl Entity {
beltspeed, beltspeed,
input_priority_left: None, input_priority_left: None,
output_priority_left: None, output_priority_left: None,
filter: None,
}, },
position, position,
direction, direction,
@ -224,12 +226,14 @@ impl Entity {
direction: Direction, direction: Direction,
input_priority_left: Option<bool>, input_priority_left: Option<bool>,
output_priority_left: Option<bool>, output_priority_left: Option<bool>,
filter: Option<String>,
) -> Self { ) -> Self {
Self::new( Self::new(
EntityType::Splitter { EntityType::Splitter {
beltspeed, beltspeed,
input_priority_left, input_priority_left,
output_priority_left, output_priority_left,
filter,
}, },
position, position,
direction, direction,
@ -321,6 +325,7 @@ impl Entity {
beltspeed, beltspeed,
input_priority_left: _, input_priority_left: _,
output_priority_left: _, output_priority_left: _,
filter: _,
} => beltspeed.string_splitter(), } => beltspeed.string_splitter(),
EntityType::Unknown { EntityType::Unknown {
name, name,
@ -379,6 +384,7 @@ impl Entity {
beltspeed: _, beltspeed: _,
input_priority_left, input_priority_left,
output_priority_left: _, output_priority_left: _,
filter: _,
} => match input_priority_left { } => match input_priority_left {
Some(true) => Some("left".to_string()), Some(true) => Some("left".to_string()),
Some(false) => Some("right".to_string()), Some(false) => Some("right".to_string()),
@ -394,6 +400,7 @@ impl Entity {
beltspeed: _, beltspeed: _,
input_priority_left: _, input_priority_left: _,
output_priority_left, output_priority_left,
filter: _,
} => match output_priority_left { } => match output_priority_left {
Some(true) => Some("left".to_string()), Some(true) => Some("left".to_string()),
Some(false) => Some("right".to_string()), Some(false) => Some("right".to_string()),
@ -402,6 +409,19 @@ impl Entity {
_ => None, _ => 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 { pub fn size(&self) -> Position {
match &self.entity { match &self.entity {
EntityType::Splitter { .. } => Position::new(4, 2), EntityType::Splitter { .. } => Position::new(4, 2),
@ -631,6 +651,7 @@ impl Blueprint {
.maybe_recipe(e.get_maybe_recipe()) .maybe_recipe(e.get_maybe_recipe())
.maybe_input_priority(e.get_maybe_input_priority()) .maybe_input_priority(e.get_maybe_input_priority())
.maybe_output_priority(e.get_maybe_output_priority()) .maybe_output_priority(e.get_maybe_output_priority())
.maybe_filter(e.get_maybe_filter())
.build() .build()
}) })
.collect(); .collect();