From 37cdd775ac738b2a1264e32471385376e5a34f3a Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 3 Jun 2024 23:39:34 +0100 Subject: Province const/mutable separation + State cleanup --- src/openvic-simulation/map/State.hpp | 61 ++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'src/openvic-simulation/map/State.hpp') diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp index bae83f7..e030a0b 100644 --- a/src/openvic-simulation/map/State.hpp +++ b/src/openvic-simulation/map/State.hpp @@ -1,48 +1,75 @@ #pragma once -#include "openvic-simulation/map/Province.hpp" -#include "openvic-simulation/map/Region.hpp" -#include "openvic-simulation/country/Country.hpp" +#include -#include +#include "openvic-simulation/map/ProvinceInstance.hpp" +#include "openvic-simulation/pop/Pop.hpp" +#include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { + struct StateManager; + struct StateSet; + struct Country; + struct ProvinceInstance; + struct State { + friend struct StateManager; + private: - Country const* PROPERTY_RW(owner); - Province const* PROPERTY_RW(capital); - Region::provinces_t PROPERTY(provinces); - Province::colony_status_t PROPERTY_RW(colony_status); + StateSet const& PROPERTY(state_set); + Country const* PROPERTY(owner); + ProvinceInstance* PROPERTY(capital); + std::vector PROPERTY(provinces); + ProvinceInstance::colony_status_t PROPERTY(colony_status); + + Pop::pop_size_t PROPERTY(total_population); - public: State( - Country const* owner, Province const* capital, Region::provinces_t&& provinces, - Province::colony_status_t colony_status + StateSet const& new_state_set, Country const* owner, ProvinceInstance* capital, + std::vector&& provinces, ProvinceInstance::colony_status_t colony_status ); + + public: + void update_gamestate(); }; + struct Region; + struct StateSet { - using states_t = std::deque; + friend struct StateManager; + + // TODO - use a container that supports adding and removing items without invalidating pointers + using states_t = std::vector; private: Region const& PROPERTY(region); states_t PROPERTY(states); + StateSet(Region const& new_region); + public: - StateSet(Map& map, Region const& new_region); + size_t get_state_count() const; - states_t& get_states(); + void update_gamestate(); }; + struct Map; + /* Contains all current states.*/ struct StateManager { private: - std::vector PROPERTY(regions); + std::vector PROPERTY(state_sets); + + bool add_state_set(Map& map, Region const& region); public: /* Creates states from current province gamestate & regions, sets province state value. * After this function, the `regions` property is unmanaged and must be carefully updated and * validated by functions that modify it. */ - void generate_states(Map& map); + bool generate_states(Map& map); + + void reset(); + + void update_gamestate(); }; -} // namespace OpenVic +} -- cgit v1.2.3-56-ga3b1