diff options
author | zaaarf <80046572+zaaarf@users.noreply.github.com> | 2023-09-19 18:08:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-19 18:08:07 +0200 |
commit | 7a55877367282749e89ff938ca1d7910f7166fe6 (patch) | |
tree | 46ae571e7dddc83ebc7e87ae83726356d0f71934 /src/openvic-simulation/map/Province.cpp | |
parent | 9c89100e0c8854dff3174b078d235148585a8b03 (diff) | |
parent | 88948eb11127c6d3442fbd476f7b456643b58728 (diff) |
Merge pull request #18 from OpenVicProject/province-adjacencies-bis
Basic province adjacencies algorithm/logic
Diffstat (limited to 'src/openvic-simulation/map/Province.cpp')
-rw-r--r-- | src/openvic-simulation/map/Province.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 775c0a4..db7e784 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -1,7 +1,9 @@ #include "Province.hpp" #include <cassert> +#include <cstddef> #include <iomanip> +#include <iterator> #include <sstream> using namespace OpenVic; @@ -137,3 +139,39 @@ void Province::tick(Date const& today) { for (Building& building : buildings.get_items()) building.tick(today); } + +Province::adjacency_t::adjacency_t(Province const* province, distance_t distance, flags_t flags) + : province { province }, distance { distance }, flags { flags } { + assert(province != nullptr); +} + +Province::distance_t Province::adjacency_t::get_distance() const { + return distance; +} + +Province::flags_t Province::adjacency_t::get_flags() { + return flags; +} + +bool Province::is_adjacent_to(Province const* province) { + for (adjacency_t adj : adjacencies) + if (adj.province == province) + return true; + return false; +} + +bool Province::add_adjacency(Province const* province, distance_t distance, flags_t flags) { + if (province == nullptr) { + Logger::error("Tried to create null adjacency province for province ", get_identifier(), "!"); + return false; + } + + if (is_adjacent_to(province)) + return false; + adjacencies.push_back({ province, distance, flags }); + return true; +} + +std::vector<Province::adjacency_t> const& Province::get_adjacencies() const { + return adjacencies; +}
\ No newline at end of file |