From ade93c528bca7321393a767a4a379a0ebae3d215 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Mon, 18 Sep 2023 18:35:13 +0200 Subject: feat: added adjacency to provinces --- src/openvic-simulation/map/Province.cpp | 25 +++++++++++++++++++++++++ src/openvic-simulation/map/Province.hpp | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'src/openvic-simulation/map') diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index 775c0a4..8dcaa42 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -137,3 +137,28 @@ void Province::tick(Date const& today) { for (Building& building : buildings.get_items()) building.tick(today); } + +Province::adjacency_t::adjacency_t(index_t new_provice_id, distance_t new_distance, flags_t new_flags) { + assert(new_provice_id != Province::NULL_INDEX); + province_id = new_provice_id; + distance = new_distance; + flags = new_flags; +} + +bool Province::is_adjacent_to(index_t province_index) { + for (adjacency_t adj : adjacencies) + if (adj.province_id == province_index) + return true; + return false; +} + +bool Province::add_adjacency(index_t province_index, distance_t distance, flags_t flags) { + if (is_adjacent_to(province_index)) + return false; + adjacencies.push_back({ province_index, distance, flags }); + return true; +} + +std::vector const& Province::get_adjacencies() const { + return adjacencies; +} \ No newline at end of file diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index bf407ae..4c89db4 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -17,6 +17,19 @@ namespace OpenVic { using index_t = uint16_t; using life_rating_t = int8_t; + using distance_t = uint16_t; + using flags_t = uint16_t; + + struct adjacency_t { + friend struct Province; + + private: + index_t province_id; + distance_t distance; + flags_t flags; + + adjacency_t(index_t provice_id, distance_t distance, flags_t flags); + }; static constexpr index_t NULL_INDEX = 0, MAX_INDEX = (1 << (8 * sizeof(index_t))) - 1; @@ -33,6 +46,8 @@ namespace OpenVic { Pop::pop_size_t total_population; distribution_t pop_types, cultures, religions; + std::vector adjacencies; + Province(const std::string_view new_identifier, colour_t new_colour, index_t new_index); public: @@ -65,5 +80,9 @@ namespace OpenVic { void update_state(Date const& today); void tick(Date const& today); + + bool is_adjacent_to(index_t province_index); + bool add_adjacency(index_t province_index, distance_t distance, flags_t flags); + std::vector const& get_adjacencies() const; }; } -- cgit v1.2.3-56-ga3b1