diff options
author | wvpm <24685035+wvpm@users.noreply.github.com> | 2023-12-13 11:56:26 +0100 |
---|---|---|
committer | wvpm <24685035+wvpm@users.noreply.github.com> | 2023-12-13 21:19:07 +0100 |
commit | 2c383640d699680e99c79f0aa2601df9e0843f00 (patch) | |
tree | 9ba33c2c8800a11ef59acbba711a7230dcf2dc05 /src/openvic-simulation/map/Province.cpp | |
parent | e79ad08e28c07bac5d28d0653cbe374cd51e6bbe (diff) |
Calculate distance between adjacencies
Diffstat (limited to 'src/openvic-simulation/map/Province.cpp')
-rw-r--r-- | src/openvic-simulation/map/Province.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 8094463..717ef35 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -121,7 +121,7 @@ Province::adjacency_t::adjacency_t(Province const* province, distance_t distance assert(province != nullptr); } -bool Province::is_adjacent_to(Province const* province) { +bool Province::is_adjacent_to(Province const* province) const { for (adjacency_t adj : adjacencies) { if (adj.province == province) { return true; @@ -142,6 +142,18 @@ bool Province::add_adjacency(Province const* province, distance_t distance, flag return true; } +fvec2_t Province::get_unit_position() const { + return positions.unit.value_or(positions.center); +} + +Province::distance_t Province::calculate_distance_to(Province const* province) const { + const fvec2_t my_unit_position = get_unit_position(); + const fvec2_t other_unit_position = province->get_unit_position(); + const fvec2_t distance_vector = other_unit_position - my_unit_position; + const fixed_point_t distance = distance_vector.length_squared(); + return static_cast<Province::distance_t>(distance); +} + bool Province::reset(BuildingTypeManager const& building_type_manager) { terrain_type = default_terrain_type; life_rating = 0; |