aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/DiplomaticHistory.hpp
blob: 3ed253f63876b246fb104cf4734c71df96b7ca86 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once

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

#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/military/Wargoal.hpp"
#include "openvic-simulation/map/Province.hpp"

namespace OpenVic {
   struct DiplomaticHistoryManager;

   struct WarHistory {
      friend struct DiplomaticHistoryManager;

      struct added_wargoal_t {
         friend struct DiplomaticHistoryManager;

      private:
         Date PROPERTY_CUSTOM_NAME(added, get_date_added);
         Country const* PROPERTY(actor);
         Country const* PROPERTY(receiver);
         WargoalType const* PROPERTY(wargoal);
         std::optional<Country const*> PROPERTY(third_party);
         std::optional<Province const*> PROPERTY(target);

         added_wargoal_t(Date new_added, Country const* new_actor, Country const* new_receiver, WargoalType const* new_wargoal, std::optional<Country const*> new_third_party, std::optional<Province const*> new_target);
      };

      struct war_participant_t {
         friend struct DiplomaticHistoryManager;

      private:
         Country const* PROPERTY(country);
         Date PROPERTY_CUSTOM_NAME(joined, get_date_joined);
         std::optional<Date> PROPERTY_CUSTOM_NAME(exited, get_date_exited);

         war_participant_t(Country const* new_country, Date new_joined, std::optional<Date> new_exited);
      };

   private:
      std::string PROPERTY(war_name); // edge cases where this is empty/undef for some reason, probably need to just generate war names like usual for that.
      std::vector<war_participant_t> PROPERTY(attackers);
      std::vector<war_participant_t> PROPERTY(defenders);
      std::vector<added_wargoal_t> PROPERTY(wargoals);

      WarHistory(std::string_view new_war_name, std::vector<war_participant_t>&& new_attackers, std::vector<war_participant_t>&& new_defenders, std::vector<added_wargoal_t>&& new_wargoals);
   };

   struct AllianceHistory {
      friend struct DiplomaticHistoryManager;

   private:
      Country const* PROPERTY(first);
      Country const* PROPERTY(second);
      const Date start;
      const Date end;

      AllianceHistory(Country const* new_first, Country const* new_second, const Date new_start, const Date new_end);
   };

   struct SubjectHistory {
      friend struct DiplomaticHistoryManager;

      enum class type_t {
         VASSAL,
         UNION,
         SUBSTATE
      };

   private:
      Country const* PROPERTY(overlord);
      Country const* PROPERTY(subject);
      const type_t PROPERTY_CUSTOM_NAME(type, get_subject_type);
      const Date start;
      const Date end;

      SubjectHistory(Country const* new_overlord, Country const* new_subject, const type_t new_type, const Date new_start, const Date new_end);
   };

   struct DiplomaticHistoryManager {
   private:
      std::vector<AllianceHistory> alliances;
      std::vector<SubjectHistory> subjects;
      std::vector<WarHistory> wars;
      bool locked = false;

   public:
      DiplomaticHistoryManager() {}

      void lock_diplomatic_history();
      bool is_locked() const;

      std::vector<AllianceHistory const*> get_alliances(Date date) const;
      std::vector<SubjectHistory const*> get_subjects(Date date) const;
      /* Returns all wars that begin before date. NOTE: Some wargoals may be added or countries may join after date, should be checked for by functions that use get_wars() */
      std::vector<WarHistory const*> get_wars(Date date) const;

      bool load_diplomacy_history_file(GameManager& game_manager, ast::NodeCPtr root);
      bool load_war_history_file(GameManager& game_manager, ast::NodeCPtr root);
   };
} // namespace OpenVic