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 => {
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;