aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics/Issue.hpp
blob: a0349591db60be830792e936a816c558e78a3cce (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once

#include "openvic-simulation/politics/Rule.hpp"
#include "openvic-simulation/misc/Modifier.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"

namespace OpenVic {
   struct IssueManager;

   // Issue group (i.e. trade_policy)
   struct IssueGroup : HasIdentifier {
      friend struct IssueManager;

   protected:
      IssueGroup(std::string_view identifier);

   public:
      IssueGroup(IssueGroup&&) = default;
   };

   // Issue (i.e. protectionism)
   struct Issue : Modifier {
      friend struct IssueManager;

   private:
      IssueGroup const& PROPERTY(group);
      const RuleSet PROPERTY(rules);
      const bool PROPERTY_CUSTOM_PREFIX(jingoism, is);

   protected:
      Issue(
         std::string_view new_identifier, ModifierValue&& new_values, IssueGroup const& new_group,
         RuleSet&& new_rules, bool new_jingoism
      );

   public:
      Issue(Issue&&) = default;
   };

   // Reform type (i.e. political_issues)
   struct ReformType : HasIdentifier {
      friend struct IssueManager;

   private:
      bool PROPERTY_CUSTOM_PREFIX(uncivilised, is); // whether this group is available to non-westernised countries
      // in vanilla education, military and economic reforms are hardcoded to true and the rest to false

      ReformType(std::string_view new_identifier, bool new_uncivilised);

   public:
      ReformType(ReformType&&) = default;
   };

   // Reform group (i.e. slavery)
   struct ReformGroup : IssueGroup {
      friend struct IssueManager;

   private:
      ReformType const& PROPERTY(type);
      const bool PROPERTY_CUSTOM_PREFIX(ordered, is); // next_step_only
      const bool PROPERTY_CUSTOM_PREFIX(administrative, is);

      ReformGroup(std::string_view new_identifier, ReformType const& new_type, bool new_ordered, bool new_administrative);

   public:
      ReformGroup(ReformGroup&&) = default;
   };

   // Reform (i.e. yes_slavery)
   struct Reform : Issue {
      friend struct IssueManager;
      using tech_cost_t = uint32_t;

   private:
      ReformGroup const& PROPERTY(reform_group); // stores an already casted reference
      const size_t PROPERTY(ordinal); // assigned by the parser to allow policy sorting
      const tech_cost_t PROPERTY(technology_cost);

      Reform(
         std::string_view new_identifier, ModifierValue&& new_values, ReformGroup const& new_group, size_t new_ordinal,
         RuleSet&& new_rules, tech_cost_t new_technology_cost
      );

   public:
      Reform(Reform&&) = default;
   };

   // Issue manager - holds the registries
   struct IssueManager {
   private:
      IdentifierRegistry<IssueGroup> IDENTIFIER_REGISTRY(issue_group);
      IdentifierRegistry<Issue> IDENTIFIER_REGISTRY(issue);
      IdentifierRegistry<ReformType> IDENTIFIER_REGISTRY(reform_type);
      IdentifierRegistry<ReformGroup> IDENTIFIER_REGISTRY(reform_group);
      IdentifierRegistry<Reform> IDENTIFIER_REGISTRY(reform);

      bool _load_issue_group(size_t& expected_issues, std::string_view identifier, ast::NodeCPtr node);
      bool _load_issue(
         ModifierManager const& modifier_manager, RuleManager const& rule_manager, std::string_view identifier,
         IssueGroup const* group, ast::NodeCPtr node
      );
      bool _load_reform_group(
         size_t& expected_reforms, std::string_view identifier, ReformType const* type, ast::NodeCPtr node
      );
      bool _load_reform(
         ModifierManager const& modifier_manager, RuleManager const& rule_manager, size_t ordinal, std::string_view identifier,
         ReformGroup const* group, ast::NodeCPtr node
      );

   public:
      bool add_issue_group(std::string_view identifier);
      bool add_issue(std::string_view identifier, ModifierValue&& values, IssueGroup const* group, RuleSet&& rules, bool jingoism);
      bool add_reform_type(std::string_view identifier, bool uncivilised);
      bool add_reform_group(std::string_view identifier, ReformType const* type, bool ordered, bool administrative);
      bool add_reform(std::string_view identifier, ModifierValue&& values, ReformGroup const* group, size_t ordinal, RuleSet&& rules, Reform::tech_cost_t technology_cost);
      bool load_issues_file(ModifierManager const& modifier_manager, RuleManager const& rule_manager, ast::NodeCPtr root);
   };
}