Project Alice
Loading...
Searching...
No Matches
military_parsing.cpp
Go to the documentation of this file.
2#include "military.hpp"
3
4namespace parsers {
5
6void register_cb_type(std::string_view name, token_generator& gen, error_handler& err, scenario_building_context& context) {
7 auto existing_it = context.map_of_cb_types.find(std::string(name));
8
9 auto id = [&]() {
10 if(existing_it != context.map_of_cb_types.end()) {
11 existing_it->second.generator_state = gen;
12 return existing_it->second.id;
13 }
14 auto new_id = context.state.world.create_cb_type();
15 context.map_of_cb_types.insert_or_assign(std::string(name), pending_cb_content{gen, new_id});
16 return new_id;
17 }();
18
19 auto name_id = text::find_or_add_key(context.state, name, false);
20 auto name_desc = std::string(name) + "_desc";
21 auto name_setup = std::string(name) + "_setup";
22 auto name_cond = std::string(name) + "_short";
23 context.state.world.cb_type_set_name(id, name_id);
24 context.state.world.cb_type_set_short_desc(id, text::find_or_add_key(context.state, name_desc, false));
25 context.state.world.cb_type_set_long_desc(id, text::find_or_add_key(context.state, name_setup, false));
26 context.state.world.cb_type_set_shortest_desc(id, text::find_or_add_key(context.state, name_cond, false));
27 context.state.world.cb_type_set_construction_speed(id, 1.0f);
28
29 uint32_t special_flags = 0;
30 if(is_fixed_token_ci(name.data(), name.data() + name.length(), "uninstall_communist_gov_cb"))
32 else if(is_fixed_token_ci(name.data(), name.data() + name.length(), "liberate_country"))
34 else if(is_fixed_token_ci(name.data(), name.data() + name.length(), "status_quo"))
36
37 context.state.world.cb_type_set_type_bits(id, special_flags);
38
39 gen.discard_group();
40}
41
42void make_trait(std::string_view name, token_generator& gen, error_handler& err, scenario_building_context& context) {
43
44 dcon::leader_trait_id new_id = context.state.world.create_leader_trait();
45 auto name_id = text::find_or_add_key(context.state, name, false);
46
47 context.state.world.leader_trait_set_name(new_id, name_id);
48 context.map_of_leader_traits.insert_or_assign(std::string(name), new_id);
49
50 trait_context new_context{context, new_id};
51 parse_trait(gen, err, new_context);
52}
54 parse_traits_set(gen, err, context);
55}
58 dcon::leader_trait_id(dcon::leader_trait_id::value_base_t(context.state.world.leader_trait_size()));
59 parse_traits_set(gen, err, context);
60}
61
63 {
64 dcon::unit_type_id army_base_id =
65 dcon::unit_type_id(dcon::unit_type_id::value_base_t(context.state.military_definitions.unit_base_definitions.size()));
67
68 auto name_id = text::find_or_add_key(context.state, "army_base", false);
69 context.state.military_definitions.unit_base_definitions.back().name = name_id;
70 context.state.military_definitions.unit_base_definitions.back().is_land = true;
71 context.state.military_definitions.unit_base_definitions.back().active = false;
72 context.map_of_unit_types.insert_or_assign(std::string("army_base"), army_base_id);
73 context.state.military_definitions.base_army_unit = army_base_id;
74 }
75 {
76 dcon::unit_type_id navy_base_id =
77 dcon::unit_type_id(dcon::unit_type_id::value_base_t(context.state.military_definitions.unit_base_definitions.size()));
79
80 auto name_id = text::find_or_add_key(context.state, "navy_base", false);
81 context.state.military_definitions.unit_base_definitions.back().name = name_id;
82 context.state.military_definitions.unit_base_definitions.back().is_land = false;
83 context.state.military_definitions.unit_base_definitions.back().active = false;
84 context.map_of_unit_types.insert_or_assign(std::string("navy_base"), navy_base_id);
85 context.state.military_definitions.base_naval_unit = navy_base_id;
86 }
87}
88
89void make_unit(std::string_view name, token_generator& gen, error_handler& err, scenario_building_context& context) {
90 dcon::unit_type_id new_id =
91 dcon::unit_type_id(dcon::unit_type_id::value_base_t(context.state.military_definitions.unit_base_definitions.size()));
93
94 auto name_id = text::find_or_add_key(context.state, name, false);
95
96 context.state.military_definitions.unit_base_definitions.back() = parsers::parse_unit_definition(gen, err, context);
97 context.state.military_definitions.unit_base_definitions.back().name = name_id;
98
99 context.map_of_unit_types.insert_or_assign(std::string(name), new_id);
100
101 if(name == "infantry") {
102 context.state.military_definitions.infantry = new_id;
103 }
104 if(context.state.military_definitions.unit_base_definitions.back().active
105 && context.state.military_definitions.unit_base_definitions.back().primary_culture == false
107 context.state.military_definitions.irregular = new_id;
108 }
109 if(context.state.military_definitions.unit_base_definitions.back().active
112 context.state.military_definitions.artillery = new_id;
113 }
114
115 // by name
116 if(!bool(context.state.military_definitions.irregular) && name == "irregular") {
117 context.state.military_definitions.irregular = new_id;
118 err.accumulated_warnings += "Fallbacking to detecting an irregular from name " + err.file_name + "\n";
119 }
120 if(!bool(context.state.military_definitions.artillery) && name == "artillery") {
121 context.state.military_definitions.artillery = new_id;
122 err.accumulated_warnings += "Fallbacking to detecting an artillery from name " + err.file_name + "\n";
123 }
124}
125
129 return make_trigger(gen, err, t_context);
130}
134 return make_trigger(gen, err, t_context);
135}
139 return make_trigger(gen, err, t_context);
140}
144 return make_trigger(gen, err, t_context);
145}
146dcon::trigger_key cb_can_use(token_generator& gen, error_handler& err, individual_cb_context& context) {
149 return make_trigger(gen, err, t_context);
150}
151dcon::effect_key cb_on_add(token_generator& gen, error_handler& err, individual_cb_context& context) {
154 return make_effect(gen, err, t_context);
155}
159 return make_effect(gen, err, t_context);
160}
161
163 auto id = context.outer_context.state.world.create_army();
164 context.outer_context.state.world.force_create_army_control(id, context.nation_for);
165 oob_file_army_context new_context{context.outer_context, id, context.nation_for};
166 parse_oob_army(gen, err, new_context);
167
168 // and check they have correct unit types
169 auto p = context.outer_context.state.world.army_get_location_from_army_location(id);
170 for(auto m : context.outer_context.state.world.army_get_army_membership(id)) {
171 if(!bool(m.get_regiment().get_type())) {
172 auto name = context.outer_context.state.world.province_get_name(p);
173 err.accumulated_errors += "Army defined in " + text::produce_simple_string(context.outer_context.state, name) + " has a regiment, that does not have a valid type (" + err.file_name + ")\n";
174 }
175 }
176}
178 auto id = context.outer_context.state.world.create_navy();
179 context.outer_context.state.world.force_create_navy_control(id, context.nation_for);
180 oob_file_navy_context new_context{context.outer_context, id, context.nation_for};
181 parse_oob_navy(gen, err, new_context);
182
183 // and check they have correct unit types
184 auto p = context.outer_context.state.world.navy_get_location_from_navy_location(id);
185 for(auto m : context.outer_context.state.world.navy_get_navy_membership(id)) {
186 if(!bool(m.get_ship().get_type())) {
187 auto name = context.outer_context.state.world.province_get_name(p);
188 err.accumulated_errors += "Navy defined in " + text::produce_simple_string(context.outer_context.state, name) + " has a ship, that does not have a valid type (" + err.file_name + ")\n";
189 }
190 }
191}
193 auto id = context.outer_context.state.world.create_regiment();
194 context.outer_context.state.world.regiment_set_strength(id, 1.0f);
195 context.outer_context.state.world.regiment_set_org(id, 1.0f);
196 context.outer_context.state.world.force_create_army_membership(id, context.id);
197 oob_file_regiment_context new_context{context.outer_context, id};
198 parse_oob_regiment(gen, err, new_context);
199 if(!context.outer_context.state.world.regiment_get_type(id)) {
200 context.outer_context.state.world.delete_regiment(id);
201 }
202}
204 auto id = context.outer_context.state.world.create_ship();
205 context.outer_context.state.world.ship_set_strength(id, 1.0f);
206 context.outer_context.state.world.ship_set_org(id, 1.0f);
207 context.outer_context.state.world.force_create_navy_membership(id, context.id);
208 oob_file_ship_context new_context{context.outer_context, id};
209 parse_oob_ship(gen, err, new_context);
210 if(!context.outer_context.state.world.ship_get_type(id)) {
211 context.outer_context.state.world.delete_ship(id);
212 }
213}
215 oob_file_context new_context{context.outer_context, context.nation_for};
216 return parse_oob_leader(gen, err, new_context);
217}
219 oob_file_context new_context{ context.outer_context, context.nation_for };
220 return parse_oob_leader(gen, err, new_context);
221}
222
223} // namespace parsers
std::string accumulated_errors
Definition: parsers.hpp:62
std::string accumulated_warnings
Definition: parsers.hpp:63
std::string file_name
Definition: parsers.hpp:61
dcon::trigger_key cb_allowed_substates(token_generator &gen, error_handler &err, individual_cb_context &context)
void personality_traits_set(token_generator &gen, error_handler &err, scenario_building_context &context)
dcon::effect_key cb_on_add(token_generator &gen, error_handler &err, individual_cb_context &context)
dcon::trigger_key make_trigger(token_generator &gen, error_handler &err, trigger_building_context &context)
dcon::effect_key cb_on_po_accepted(token_generator &gen, error_handler &err, individual_cb_context &context)
dcon::trigger_key cb_allowed_states(token_generator &gen, error_handler &err, individual_cb_context &context)
oob_leader make_army_leader(token_generator &gen, error_handler &err, oob_file_army_context &context)
void make_oob_ship(token_generator &gen, error_handler &err, oob_file_navy_context &context)
oob_leader make_navy_leader(token_generator &gen, error_handler &err, oob_file_navy_context &context)
dcon::trigger_key cb_can_use(token_generator &gen, error_handler &err, individual_cb_context &context)
void make_oob_navy(token_generator &gen, error_handler &err, oob_file_context &context)
void make_trait(std::string_view name, token_generator &gen, error_handler &err, scenario_building_context &context)
void make_oob_regiment(token_generator &gen, error_handler &err, oob_file_army_context &context)
void make_oob_army(token_generator &gen, error_handler &err, oob_file_context &context)
void background_traits_set(token_generator &gen, error_handler &err, scenario_building_context &context)
bool is_fixed_token_ci(char const *start, char const *end, char const (&t)[N])
Definition: parsers.hpp:275
void register_cb_type(std::string_view name, token_generator &gen, error_handler &err, scenario_building_context &context)
dcon::effect_key make_effect(token_generator &gen, error_handler &err, effect_building_context &context)
dcon::trigger_key cb_allowed_countries(token_generator &gen, error_handler &err, individual_cb_context &context)
void make_unit(std::string_view name, token_generator &gen, error_handler &err, scenario_building_context &context)
dcon::trigger_key cb_allowed_crisis_states(token_generator &gen, error_handler &err, individual_cb_context &context)
void make_base_units(scenario_building_context &context)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
dcon::text_key find_or_add_key(sys::state &state, std::string_view key, bool as_unicode)
Definition: text.cpp:695
uint uint32_t
dcon::cb_type_id uninstall_communist_gov
Definition: military.hpp:156
dcon::unit_type_id base_army_unit
Definition: military.hpp:147
dcon::unit_type_id irregular
Definition: military.hpp:161
tagged_vector< unit_definition, dcon::unit_type_id > unit_base_definitions
Definition: military.hpp:140
dcon::unit_type_id infantry
Definition: military.hpp:162
dcon::cb_type_id standard_status_quo
Definition: military.hpp:153
dcon::unit_type_id base_naval_unit
Definition: military.hpp:148
dcon::unit_type_id artillery
Definition: military.hpp:163
dcon::leader_trait_id first_background_trait
Definition: military.hpp:142
scenario_building_context & outer_context
scenario_building_context & outer_context
scenario_building_context & outer_context
scenario_building_context & outer_context
ankerl::unordered_dense::map< std::string, dcon::unit_type_id > map_of_unit_types
ankerl::unordered_dense::map< std::string, dcon::leader_trait_id > map_of_leader_traits
ankerl::unordered_dense::map< std::string, pending_cb_content > map_of_cb_types
dcon::data_container world
military::global_military_state military_definitions