diff options
Diffstat (limited to 'src/openvic-simulation/map/Province.cpp')
-rw-r--r-- | src/openvic-simulation/map/Province.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 363be6c..717ef35 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -58,14 +58,6 @@ bool Province::expand_building(std::string_view building_type_identifier) { return building->expand(); } -bool Province::load_pop_list(PopManager const& pop_manager, ast::NodeCPtr root) { - return expect_dictionary_reserve_length(pops, - [this, &pop_manager](std::string_view pop_type_identifier, ast::NodeCPtr pop_node) -> bool { - return pop_manager.load_pop_into_province(*this, pop_type_identifier, pop_node); - } - )(root); -} - bool Province::add_pop(Pop&& pop) { if (!get_water()) { pops.push_back(std::move(pop)); @@ -76,6 +68,19 @@ bool Province::add_pop(Pop&& pop) { } } +bool Province::add_pop_vec(std::vector<Pop> const& pop_vec) { + if (!get_water()) { + pops.reserve(pops.size() + pop_vec.size()); + for (Pop const& pop : pop_vec) { + pops.push_back(pop); + } + return true; + } else { + Logger::error("Trying to add pop vector to water province ", get_identifier()); + return false; + } +} + size_t Province::get_pop_count() const { return pops.size(); } @@ -116,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; @@ -137,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; |