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
120
121
122
123
124
125
126
|
#include "Ideology.hpp"
#include "openvic-simulation/types/Colour.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
IdeologyGroup::IdeologyGroup(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
Ideology::Ideology(
std::string_view new_identifier, colour_t new_colour, IdeologyGroup const& new_group, bool new_uncivilised,
bool new_can_reduce_militancy, Date new_spawn_date, ConditionalWeight&& new_add_political_reform,
ConditionalWeight&& new_remove_political_reform, ConditionalWeight&& new_add_social_reform,
ConditionalWeight&& new_remove_social_reform, ConditionalWeight&& new_add_military_reform,
ConditionalWeight&& new_add_economic_reform
) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, uncivilised { new_uncivilised },
can_reduce_militancy { new_can_reduce_militancy }, spawn_date { new_spawn_date },
add_political_reform { std::move(new_add_political_reform) },
remove_political_reform { std::move(new_remove_political_reform) },
add_social_reform { std::move(new_add_social_reform) }, remove_social_reform { std::move(new_remove_social_reform) },
add_military_reform { std::move(new_add_military_reform) }, add_economic_reform { std::move(new_add_economic_reform) } {}
bool Ideology::parse_scripts(GameManager const& game_manager) {
bool ret = true;
ret &= add_political_reform.parse_scripts(game_manager);
ret &= remove_political_reform.parse_scripts(game_manager);
ret &= add_social_reform.parse_scripts(game_manager);
ret &= remove_social_reform.parse_scripts(game_manager);
ret &= add_military_reform.parse_scripts(game_manager);
ret &= add_economic_reform.parse_scripts(game_manager);
return ret;
}
bool IdeologyManager::add_ideology_group(std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid ideology group identifier - empty!");
return false;
}
return ideology_groups.add_item({ identifier });
}
bool IdeologyManager::add_ideology(
std::string_view identifier, colour_t colour, IdeologyGroup const* group, bool uncivilised, bool can_reduce_militancy,
Date spawn_date, ConditionalWeight&& add_political_reform, ConditionalWeight&& remove_political_reform,
ConditionalWeight&& add_social_reform, ConditionalWeight&& remove_social_reform, ConditionalWeight&& add_military_reform,
ConditionalWeight&& add_economic_reform
) {
if (identifier.empty()) {
Logger::error("Invalid ideology identifier - empty!");
return false;
}
if (group == nullptr) {
Logger::error("Null ideology group for ", identifier);
return false;
}
return ideologies.add_item({
identifier, colour, *group, uncivilised, can_reduce_militancy, spawn_date, std::move(add_political_reform),
std::move(remove_political_reform), std::move(add_social_reform), std::move(remove_social_reform),
std::move(add_military_reform), std::move(add_economic_reform)
});
}
/* REQUIREMENTS:
* POL-9, POL-10, POL-11, POL-12, POL-13, POL-14, POL-15
*/
bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) {
size_t expected_ideologies = 0;
bool ret = expect_dictionary_reserve_length(ideology_groups,
[this, &expected_ideologies](std::string_view key, ast::NodeCPtr value) -> bool {
bool ret = expect_length(add_variable_callback(expected_ideologies))(value);
ret &= add_ideology_group(key);
return ret;
}
)(root);
lock_ideology_groups();
ideologies.reserve(ideologies.size() + expected_ideologies);
ret &= expect_dictionary([this](std::string_view ideology_group_key, ast::NodeCPtr ideology_group_value) -> bool {
IdeologyGroup const* ideology_group = get_ideology_group_by_identifier(ideology_group_key);
return expect_dictionary([this, ideology_group](std::string_view key, ast::NodeCPtr value) -> bool {
colour_t colour = colour_t::null();
bool uncivilised = true, can_reduce_militancy = false;
Date spawn_date;
ConditionalWeight add_political_reform { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
ConditionalWeight remove_political_reform { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
ConditionalWeight add_social_reform { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
ConditionalWeight remove_social_reform { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
ConditionalWeight add_military_reform { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
ConditionalWeight add_economic_reform { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
bool ret = expect_dictionary_keys(
"uncivilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(uncivilised)),
"color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)),
"date", ZERO_OR_ONE, expect_date(assign_variable_callback(spawn_date)),
"can_reduce_militancy", ZERO_OR_ONE, expect_bool(assign_variable_callback(can_reduce_militancy)),
"add_political_reform", ONE_EXACTLY, add_political_reform.expect_conditional_weight(ConditionalWeight::BASE),
"remove_political_reform", ONE_EXACTLY, remove_political_reform.expect_conditional_weight(ConditionalWeight::BASE),
"add_social_reform", ONE_EXACTLY, add_social_reform.expect_conditional_weight(ConditionalWeight::BASE),
"remove_social_reform", ONE_EXACTLY, remove_social_reform.expect_conditional_weight(ConditionalWeight::BASE),
"add_military_reform", ZERO_OR_ONE, add_military_reform.expect_conditional_weight(ConditionalWeight::BASE),
"add_economic_reform", ZERO_OR_ONE, add_economic_reform.expect_conditional_weight(ConditionalWeight::BASE)
)(value);
ret &= add_ideology(
key, colour, ideology_group, uncivilised, can_reduce_militancy, spawn_date, std::move(add_political_reform),
std::move(remove_political_reform), std::move(add_social_reform), std::move(remove_social_reform),
std::move(add_military_reform), std::move(add_economic_reform)
);
return ret;
})(ideology_group_value);
})(root);
lock_ideologies();
return ret;
}
bool IdeologyManager::parse_scripts(GameManager const& game_manager) {
bool ret = true;
for (Ideology& ideology : ideologies.get_items()) {
ideology.parse_scripts(game_manager);
}
return ret;
}
|