Skip to content

Commit

Permalink
improve province_set_port_to logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ineveraskedforthis committed Jan 20, 2025
1 parent ae0460d commit 5736f8f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/gamestate/system_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3049,15 +3049,26 @@ void state::load_scenario_data(parsers::error_handler& err, sys::year_month_day

// make ports
province::for_each_land_province(*this, [&](dcon::province_id p) {

auto best_port = dcon::province_id{ };
auto best_border_length = 0;

for(auto adj : world.province_get_province_adjacency(p)) {
auto& border = map_state.map_data.borders[adj.id.index()];
auto other = adj.get_connected_provinces(0) != p ? adj.get_connected_provinces(0) : adj.get_connected_provinces(1);
auto bits = adj.get_type();
if(other && (bits & province::border::coastal_bit) != 0 && (bits & province::border::impassible_bit) == 0) {
world.province_set_port_to(p, other.id);
world.province_set_is_coast(p, true);
return;
if(best_border_length < border.count) {
best_port = other.id;
best_border_length = border.count;
}
}
}

if(best_port) {
world.province_set_port_to(p, best_port);
}
});

// fix worker types
Expand Down

0 comments on commit 5736f8f

Please sign in to comment.