aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/State.hpp
blob: 44b194739390a788040e0babad03d5a58ec2a96c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once

#include <string>
#include <vector>

#include <plf_colony.h>

#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 CountryInstance;
   struct ProvinceInstance;

   struct State {
      friend struct StateManager;

   private:
      StateSet const& PROPERTY(state_set);
      CountryInstance* PROPERTY(owner);
      ProvinceInstance* PROPERTY(capital);
      std::vector<ProvinceInstance*> PROPERTY(provinces);
      ProvinceInstance::colony_status_t PROPERTY(colony_status);

      Pop::pop_size_t PROPERTY(total_population);
      fixed_point_t PROPERTY(average_literacy);
      fixed_point_t PROPERTY(average_consciousness);
      fixed_point_t PROPERTY(average_militancy);
      IndexedMap<PopType, fixed_point_t> PROPERTY(pop_type_distribution);

      State(
         StateSet const& new_state_set, CountryInstance* owner, ProvinceInstance* capital,
         std::vector<ProvinceInstance*>&& provinces, ProvinceInstance::colony_status_t colony_status,
         decltype(pop_type_distribution)::keys_t const& pop_type_keys
      );

   public:
      std::string get_identifier() const;

      void update_gamestate();
   };

   struct Region;

   struct StateSet {
      friend struct StateManager;

      using states_t = plf::colony<State>;

   private:
      Region const& PROPERTY(region);
      states_t PROPERTY(states);

      StateSet(Region const& new_region);

   public:
      size_t get_state_count() const;

      void update_gamestate();
   };

   struct MapInstance;

   /* Contains all current states.*/
   struct StateManager {
   private:
      std::vector<StateSet> PROPERTY(state_sets);

      bool add_state_set(
         MapInstance& map_instance, Region const& region,
         decltype(State::pop_type_distribution)::keys_t const& pop_type_keys
      );

   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. */
      bool generate_states(MapInstance& map_instance, decltype(State::pop_type_distribution)::keys_t const& pop_type_keys);

      void reset();

      void update_gamestate();
   };
}