aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Event.hpp
blob: 37f9270fbff6b25e96f715c1ef2ce489de99ab22 (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
#pragma once

#include "openvic-simulation/scripts/ConditionalWeight.hpp"
#include "openvic-simulation/scripts/EffectScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"

namespace OpenVic {
   struct EventManager;
   struct IssueGroup;
   struct IssueManager;

   struct Event : HasIdentifier {
      friend struct EventManager;

      enum struct event_type_t : uint8_t { COUNTRY, PROVINCE };

      struct EventOption {
         friend struct EventManager;
         friend struct Event;

      private:
         std::string PROPERTY(title);
         EffectScript PROPERTY(effect);
         ConditionalWeight PROPERTY(ai_chance);

         EventOption(std::string_view new_title, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance);

         bool parse_scripts(GameManager& game_manager);

      public:
         EventOption(EventOption const&) = delete;
         EventOption(EventOption&&) = default;
         EventOption& operator=(EventOption const&) = delete;
         EventOption& operator=(EventOption&&) = delete;
      };

   private:
      std::string PROPERTY(title);
      std::string PROPERTY(description);
      std::string PROPERTY(image);
      event_type_t PROPERTY(type);
      bool PROPERTY_CUSTOM_PREFIX(triggered_only, is);
      bool PROPERTY_CUSTOM_PREFIX(major, is);
      bool PROPERTY(fire_only_once);
      bool PROPERTY(allows_multiple_instances);

      bool PROPERTY_CUSTOM_PREFIX(news, is);
      std::string PROPERTY(news_title);
      std::string PROPERTY(news_desc_long);
      std::string PROPERTY(news_desc_medium);
      std::string PROPERTY(news_desc_short);

      bool PROPERTY_CUSTOM_PREFIX(election, is);
      IssueGroup const* PROPERTY(election_issue_group);

      ConditionScript PROPERTY(trigger);
      ConditionalWeight PROPERTY(mean_time_to_happen);
      EffectScript PROPERTY(immediate);

      std::vector<EventOption> PROPERTY(options);

      Event(
         std::string_view new_identifier, std::string_view new_title, std::string_view new_description,
         std::string_view new_image, event_type_t new_type, bool new_triggered_only, bool new_major,
         bool new_fire_only_once, bool new_allows_multiple_instances, bool new_news, std::string_view new_news_title,
         std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
         bool new_election, IssueGroup const* new_election_issue_group, ConditionScript&& new_trigger,
         ConditionalWeight&& new_mean_time_to_happen, EffectScript&& new_immediate, std::vector<EventOption>&& new_options
      );

      bool parse_scripts(GameManager& game_manager);

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

   struct OnAction : HasIdentifier {
      friend struct EventManager;

      using weight_map_t = ordered_map<Event const*, uint64_t>;

   private:
      weight_map_t PROPERTY(weighted_events);

      OnAction(std::string_view new_identifier, weight_map_t&& new_weighted_events);

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

   struct EventManager {
   private:
      IdentifierRegistry<Event> IDENTIFIER_REGISTRY(event);
      IdentifierRegistry<OnAction> IDENTIFIER_REGISTRY(on_action);

   public:
      bool register_event(
         std::string_view identifier, std::string_view title, std::string_view description, std::string_view image,
         Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances,
         bool news, std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium,
         std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group, ConditionScript&& trigger,
         ConditionalWeight&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
      );

      bool add_on_action(std::string_view identifier, OnAction::weight_map_t&& new_weighted_events);

      bool load_event_file(IssueManager const& issue_manager, ast::NodeCPtr root);
      bool load_on_action_file(ast::NodeCPtr root);

      bool parse_scripts(GameManager& game_manager);
   };
} // namespace OpenVic