aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/ProvinceHistory.hpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-11-06 21:39:40 +0100
committer hop311 <hop3114@gmail.com>2023-11-07 19:35:38 +0100
commitd30421fa7d7f6ad87d3f90cc0ab491742f0d2548 (patch)
tree601591215af0c6724766019ebb577141ea5807c5 /src/openvic-simulation/history/ProvinceHistory.hpp
parentb5bbeb47febc823517a5baba4eca66f32fb3609c (diff)
History loading generalisation
Diffstat (limited to 'src/openvic-simulation/history/ProvinceHistory.hpp')
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp98
1 files changed, 39 insertions, 59 deletions
diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp
index fb90cc4..5a18723 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -8,84 +8,64 @@
#include "openvic-simulation/economy/Building.hpp"
#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
+#include "openvic-simulation/history/HistoryMap.hpp"
#include "openvic-simulation/map/Province.hpp"
#include "openvic-simulation/map/TerrainType.hpp"
namespace OpenVic {
- struct ProvinceHistoryManager;
+ struct ProvinceHistoryMap;
- struct ProvinceHistory {
- friend struct ProvinceHistoryManager;
+ struct ProvinceHistoryEntry : HistoryEntry {
+ friend struct ProvinceHistoryMap;
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
- );
+ Province const& PROPERTY(province);
- 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;
+ std::optional<Country const*> PROPERTY(owner);
+ std::optional<Country const*> PROPERTY(controller);
+ std::optional<Province::colony_status_t> PROPERTY(colonial);
+ std::optional<bool> PROPERTY(slave);
+ std::vector<Country const*> PROPERTY(add_cores);
+ std::vector<Country const*> PROPERTY(remove_cores);
+ std::optional<Good const*> PROPERTY(rgo);
+ std::optional<Province::life_rating_t> PROPERTY(life_rating);
+ std::optional<TerrainType const*> PROPERTY(terrain_type);
+ building_level_map_t PROPERTY(buildings);
+ decimal_map_t<Ideology const*> PROPERTY(party_loyalties);
+
+ ProvinceHistoryEntry(Province const& new_province, Date new_date);
+ };
+
+ struct ProvinceHistoryManager;
+
+ struct ProvinceHistoryMap : HistoryMap<ProvinceHistoryEntry> {
+ friend struct ProvinceHistoryManager;
+
+ private:
+ Province const& PROPERTY(province);
+
+ protected:
+ ProvinceHistoryMap(Province const& new_province);
+
+ std::unique_ptr<ProvinceHistoryEntry> _make_entry(Date date) const override;
+ bool _load_history_entry(GameManager const& game_manager, ProvinceHistoryEntry& entry, ast::NodeCPtr root) override;
};
struct ProvinceHistoryManager {
private:
- std::map<Province const*, std::map<Date, ProvinceHistory>> province_histories;
+ std::map<Province const*, ProvinceHistoryMap> PROPERTY(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();
+ ProvinceHistoryManager() = default;
+
+ void lock_province_histories(Map const& map, bool detailed_errors);
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;
+ ProvinceHistoryMap const* get_province_history(Province const* province) const;
- bool load_province_history_file(
- GameManager const& game_manager, Province const& province, ast::NodeCPtr root
- );
+ bool load_province_history_file(GameManager const& game_manager, Province const& province, ast::NodeCPtr root);
};
} // namespace OpenVic