aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/ProvinceHistory.hpp
blob: fb90cc47864e9eb7b03b841550b18596ffbb3219 (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
88
89
90
91
#pragma once

#include <bitset>
#include <map>
#include <vector>

#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/economy/Building.hpp"
#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
#include "openvic-simulation/map/Province.hpp"
#include "openvic-simulation/map/TerrainType.hpp"

namespace OpenVic {
   struct ProvinceHistoryManager;

   struct ProvinceHistory {
      friend struct ProvinceHistoryManager;

      using building_level_map_t = std::map<Building const*, Building::level_t>;

   private:
      Country const* owner;
      Country const* controller;
      Province::colony_status_t colonial;
      bool slave;
      std::vector<Country const*> cores; // non-standard, maintains cores between entries
      Good const* rgo;
      Province::life_rating_t life_rating;
      TerrainType const* terrain_type;
      building_level_map_t buildings;
      decimal_map_t<Ideology const*> party_loyalties;

      ProvinceHistory(
         Country const* new_owner, Country const* new_controller, Province::colony_status_t new_colonial, bool new_slave,
         std::vector<Country const*>&& new_cores, Good const* new_rgo, Province::life_rating_t new_life_rating,
         TerrainType const* new_terrain_type, building_level_map_t&& new_buildings,
         decimal_map_t<Ideology const*>&& new_party_loyalties
      );

   public:
      Country const* get_owner() const;
      Country const* get_controller() const;
      Province::colony_status_t get_colony_status() const; // 0 = state, 1 = protectorate, 2 = colony
      bool is_slave() const;
      std::vector<Country const*> const& get_cores() const;
      bool is_core_of(Country const* country) const;
      Good const* get_rgo() const;
      Province::life_rating_t get_life_rating() const;
      TerrainType const* get_terrain_type() const;
      building_level_map_t const& get_buildings() const;
      decimal_map_t<Ideology const*> const& get_party_loyalties() const;
   };

   struct ProvinceHistoryManager {
   private:
      std::map<Province const*, std::map<Date, ProvinceHistory>> province_histories;
      bool locked = false;

      inline bool _load_province_history_entry(
         GameManager const& game_manager, Province const& province, Date date, ast::NodeCPtr root,
         bool is_base_entry
      );

   public:
      ProvinceHistoryManager() {}

      bool add_province_history_entry(
         Province const* province, Date date, Country const* owner, Country const* controller,
         std::optional<Province::colony_status_t>&& colonial, std::optional<bool>&& slave,
         std::vector<Country const*>&& cores, // additive to existing entries
         std::vector<Country const*>&& remove_cores, // existing cores that need to be removed
         Good const* rgo, std::optional<Province::life_rating_t>&& life_rating, TerrainType const* terrain_type,
         std::optional<ProvinceHistory::building_level_map_t>&& buildings,
         std::optional<decimal_map_t<Ideology const*>>&& party_loyalties
      );

      void lock_province_histories();
      bool is_locked() const;

      /* Returns history of province at date, if date doesn't have an entry returns closest entry before date.
       * Return can be nullptr if an error occurs. */
      ProvinceHistory const* get_province_history(Province const* province, Date entry) const;
      /* Returns history of province at bookmark date. Return can be nullptr if an error occurs. */
      inline ProvinceHistory const* get_province_history(Province const* province, Bookmark const* bookmark) const;

      bool load_province_history_file(
         GameManager const& game_manager, Province const& province, ast::NodeCPtr root
      );
   };
} // namespace OpenVic