Skip to content

Commit

Permalink
Always buy the cheapest options in the cities view
Browse files Browse the repository at this point in the history
When buying production with multiple cities selected in the cities view,
always buy from the cheapest cities. This ensures that we buy from as
many cities as possible.

Closes longturn#2311.
  • Loading branch information
lmoureaux committed Jul 7, 2024
1 parent 336c424 commit b1f8c86
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions client/views/view_cities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,16 @@ void city_widget::clear_worlist()
*/
void city_widget::buy()
{
const auto saved_selection =
selected_cities; // Copy to avoid invalidations
auto saved_selection = selected_cities; // Copy to avoid invalidations

// Sort cheapest first
std::sort(saved_selection.begin(), saved_selection.end(),
[](const city *lhs, const city *rhs) {
return lhs->client.buy_cost < rhs->client.buy_cost;
});

// Buy
for (auto *pcity : saved_selection) {
Q_ASSERT(pcity != nullptr);
cityrep_buy(pcity);
}
}
Expand Down

0 comments on commit b1f8c86

Please sign in to comment.