|
2 | 2 |
|
3 | 3 | #include <string_view> |
4 | 4 |
|
5 | | -#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp> |
6 | | - |
7 | | -#include "openvic-simulation/dataloader/Dataloader.hpp" |
8 | | -#include "openvic-simulation/dataloader/NodeTools.hpp" |
9 | | -#include "openvic-simulation/DefinitionManager.hpp" |
10 | | -#include "openvic-simulation/politics/Government.hpp" |
11 | | -#include "openvic-simulation/politics/Ideology.hpp" |
12 | | -#include "openvic-simulation/politics/PartyPolicy.hpp" |
13 | 5 | #include "openvic-simulation/population/Culture.hpp" |
14 | 6 | #include "openvic-simulation/types/Colour.hpp" |
15 | 7 | #include "openvic-simulation/types/IdentifierRegistry.hpp" |
@@ -72,167 +64,4 @@ bool CountryDefinitionManager::add_country( |
72 | 64 | ); |
73 | 65 | } |
74 | 66 |
|
75 | | -bool CountryDefinitionManager::load_countries( |
76 | | - DefinitionManager const& definition_manager, Dataloader const& dataloader, ast::NodeCPtr root |
77 | | -) { |
78 | | - static constexpr std::string_view common_dir = "common/"; |
79 | | - bool is_dynamic = false; |
80 | | - |
81 | | - const bool ret = expect_dictionary_reserve_length( |
82 | | - country_definitions, |
83 | | - [this, &definition_manager, &is_dynamic, &dataloader](std::string_view key, ast::NodeCPtr value) -> bool { |
84 | | - if (key == "dynamic_tags") { |
85 | | - return expect_bool([&is_dynamic](bool val) -> bool { |
86 | | - if (val == is_dynamic) { |
87 | | - spdlog::warn_s("Redundant \"is_dynamic\", already {}", val ? "true" : "false"); |
88 | | - } else { |
89 | | - if (is_dynamic) { |
90 | | - spdlog::warn_s("Changing \"is_dynamic\" back to false"); |
91 | | - } |
92 | | - is_dynamic = val; |
93 | | - } |
94 | | - return true; |
95 | | - })(value); |
96 | | - } |
97 | | - if (expect_string( |
98 | | - [this, &definition_manager, is_dynamic, &dataloader, &key](std::string_view filepath) -> bool { |
99 | | - if (load_country_data_file( |
100 | | - definition_manager, key, is_dynamic, |
101 | | - Dataloader::parse_defines( |
102 | | - dataloader.lookup_file(StringUtils::append_string_views(common_dir, filepath)) |
103 | | - ).get_file_node() |
104 | | - )) { |
105 | | - return true; |
106 | | - } |
107 | | - spdlog::critical_s("Failed to load country data file: {}", filepath); |
108 | | - return false; |
109 | | - } |
110 | | - )(value)) { |
111 | | - return true; |
112 | | - } |
113 | | - spdlog::critical_s("Failed to load country: {}", key); |
114 | | - return false; |
115 | | - } |
116 | | - )(root); |
117 | | - lock_country_definitions(); |
118 | | - return ret; |
119 | | -} |
120 | | - |
121 | | -bool CountryDefinitionManager::load_country_colours(ast::NodeCPtr root) { |
122 | | - return country_definitions.expect_item_dictionary_and_default( |
123 | | - [](std::string_view key, ast::NodeCPtr value) -> bool { |
124 | | - spdlog::warn_s("country_colors.txt references country tag {} which is not defined!", key); |
125 | | - return true; |
126 | | - }, |
127 | | - [](CountryDefinition& country, ast::NodeCPtr colour_node) -> bool { |
128 | | - return expect_dictionary_keys( |
129 | | - "color1", ONE_EXACTLY, expect_colour(assign_variable_callback(country.primary_unit_colour)), |
130 | | - "color2", ONE_EXACTLY, expect_colour(assign_variable_callback(country.secondary_unit_colour)), |
131 | | - "color3", ONE_EXACTLY, expect_colour(assign_variable_callback(country.tertiary_unit_colour)) |
132 | | - )(colour_node); |
133 | | - } |
134 | | - )(root); |
135 | | -} |
136 | | - |
137 | | -node_callback_t CountryDefinitionManager::load_country_party( |
138 | | - PoliticsManager const& politics_manager, IdentifierRegistry<CountryParty>& country_parties |
139 | | -) const { |
140 | | - return [&politics_manager, &country_parties](ast::NodeCPtr value) -> bool { |
141 | | - std::string_view party_name; |
142 | | - Date start_date, end_date; |
143 | | - Ideology const* ideology = nullptr; |
144 | | - IndexedFlatMap<PartyPolicyGroup, PartyPolicy const*> policies { politics_manager.get_issue_manager().get_party_policy_groups() }; |
145 | | - |
146 | | - bool ret = expect_dictionary_keys_and_default( |
147 | | - [&politics_manager, &policies, &party_name](std::string_view key, ast::NodeCPtr value) -> bool { |
148 | | - return politics_manager.get_issue_manager().expect_party_policy_group_str( |
149 | | - [&politics_manager, &policies, value, &party_name](PartyPolicyGroup const& party_policy_group) -> bool { |
150 | | - PartyPolicy const*& policy = policies.at(party_policy_group); |
151 | | - |
152 | | - if (policy != nullptr) { |
153 | | - spdlog::error_s( |
154 | | - "Country party \"{}\" has duplicate entry for party policy group \"{}\"", |
155 | | - party_name, party_policy_group |
156 | | - ); |
157 | | - return false; |
158 | | - } |
159 | | - |
160 | | - return politics_manager.get_issue_manager().expect_party_policy_identifier( |
161 | | - [&party_policy_group, &policy](PartyPolicy const& party_policy) -> bool { |
162 | | - if (&party_policy.get_issue_group() == &party_policy_group) { |
163 | | - policy = &party_policy; |
164 | | - return true; |
165 | | - } |
166 | | - |
167 | | - // TODO - change this back to error/false once TGC no longer has this issue |
168 | | - spdlog::warn_s( |
169 | | - "Invalid party policy \"{}\", group is \"{}\" when \"{}\" was expected.", |
170 | | - party_policy, |
171 | | - party_policy.get_issue_group(), |
172 | | - party_policy_group |
173 | | - ); |
174 | | - return true; |
175 | | - } |
176 | | - )(value); |
177 | | - } |
178 | | - )(key); |
179 | | - }, |
180 | | - "name", ONE_EXACTLY, expect_string(assign_variable_callback(party_name)), |
181 | | - "start_date", ONE_EXACTLY, expect_date(assign_variable_callback(start_date)), |
182 | | - "end_date", ONE_EXACTLY, expect_date(assign_variable_callback(end_date)), |
183 | | - "ideology", ONE_EXACTLY, |
184 | | - politics_manager.get_ideology_manager().expect_ideology_identifier(assign_variable_callback_pointer(ideology)) |
185 | | - )(value); |
186 | | - |
187 | | - if (ideology == nullptr) { |
188 | | - spdlog::warn_s("Country party {} has no ideology, defaulting to nullptr / no ideology", party_name); |
189 | | - } |
190 | | - |
191 | | - ret &= country_parties.emplace_item( |
192 | | - party_name, |
193 | | - duplicate_warning_callback, |
194 | | - party_name, start_date, end_date, ideology, std::move(policies) |
195 | | - ); |
196 | | - |
197 | | - return ret; |
198 | | - }; |
199 | | -} |
200 | | - |
201 | | -bool CountryDefinitionManager::load_country_data_file( |
202 | | - DefinitionManager const& definition_manager, std::string_view name, bool is_dynamic, ast::NodeCPtr root |
203 | | -) { |
204 | | - colour_t colour; |
205 | | - GraphicalCultureType const* graphical_culture; |
206 | | - IdentifierRegistry<CountryParty> parties { "country parties" }; |
207 | | - CountryDefinition::unit_names_map_t unit_names; |
208 | | - CountryDefinition::government_colour_map_t alternative_colours; |
209 | | - bool ret = expect_dictionary_keys_and_default( |
210 | | - [&definition_manager, &alternative_colours](std::string_view key, ast::NodeCPtr value) -> bool { |
211 | | - return definition_manager.get_politics_manager().get_government_type_manager().expect_government_type_str( |
212 | | - [&alternative_colours, value](GovernmentType const& government_type) -> bool { |
213 | | - return expect_colour(map_callback(alternative_colours, &government_type))(value); |
214 | | - } |
215 | | - )(key); |
216 | | - }, |
217 | | - "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), |
218 | | - "graphical_culture", ONE_EXACTLY, |
219 | | - definition_manager.get_pop_manager().get_culture_manager().expect_graphical_culture_type_identifier( |
220 | | - assign_variable_callback_pointer(graphical_culture) |
221 | | - ), |
222 | | - "party", ZERO_OR_MORE, load_country_party(definition_manager.get_politics_manager(), parties), |
223 | | - "unit_names", ZERO_OR_ONE, |
224 | | - definition_manager.get_military_manager().get_unit_type_manager().expect_unit_type_dictionary_reserve_length( |
225 | | - unit_names, |
226 | | - [&unit_names](UnitType const& unit, ast::NodeCPtr value) -> bool { |
227 | | - return name_list_callback(map_callback(unit_names, &unit))(value); |
228 | | - } |
229 | | - ) |
230 | | - )(root); |
231 | | - |
232 | | - ret &= add_country( |
233 | | - name, colour, graphical_culture, std::move(parties), std::move(unit_names), is_dynamic, std::move(alternative_colours) |
234 | | - ); |
235 | | - return ret; |
236 | | -} |
237 | | - |
238 | 67 | template struct fmt::formatter<OpenVic::CountryDefinition>; |
0 commit comments