2#include "dcon_generated.hpp"
19 return "commerce_tech";
21 return "culture_tech";
23 return "industry_tech";
26 return "military_theory_tech";
28 return "population_tech";
30 return "diplomacy_tech";
40 state.world.nation_resize_issues(state.world.issue_size());
42 state.world.for_each_issue([&](dcon::issue_id i) {
43 auto def_option = state.world.issue_get_options(i)[0];
44 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_issues(ids, i, def_option); });
47 state.world.nation_resize_reforms(state.world.reform_size());
49 state.world.for_each_reform([&](dcon::reform_id i) {
50 auto def_option = state.world.reform_get_options(i)[0];
51 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_reforms(ids, i, def_option); });
57 state.world.execute_serial_over_nation([&](
auto nation_indices) {
58 state.world.nation_set_max_building_level(nation_indices,
uint8_t(t), 0);
62 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
63 state.world.execute_serial_over_nation([&](
auto nation_indices) {
64 state.world.nation_set_active_building(nation_indices,
id, ve::vbitfield_type{0});
67 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
68 dcon::unit_type_id uid = dcon::unit_type_id{ dcon::unit_type_id::value_base_t(i) };
69 state.world.execute_serial_over_nation([&](
auto nation_indices) {
70 state.world.nation_set_active_unit(nation_indices, uid, ve::vbitfield_type{ 0 });
73 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
74 dcon::crime_id uid = dcon::crime_id{ dcon::crime_id::value_base_t(i) };
75 state.world.execute_serial_over_nation([&](
auto nation_indices) {
76 state.world.nation_set_active_crime(nation_indices, uid, ve::vbitfield_type{ 0 });
80 for(
auto cmod : state.world.in_commodity) {
81 state.world.execute_serial_over_nation([&](
auto nation_indices) {
82 state.world.nation_set_rgo_goods_output(nation_indices, cmod, 0.0f);
85 for(
auto cmod : state.world.in_commodity) {
86 state.world.execute_serial_over_nation([&](
auto nation_indices) {
87 state.world.nation_set_factory_goods_output(nation_indices, cmod, 0.0f);
90 for(
auto cmod : state.world.in_commodity) {
91 state.world.execute_serial_over_nation([&](
auto nation_indices) {
92 state.world.nation_set_rgo_size(nation_indices, cmod, 0.0f);
95 for(
auto cmod : state.world.in_commodity) {
96 state.world.execute_serial_over_nation([&](
auto nation_indices) {
97 state.world.nation_set_factory_goods_throughput(nation_indices, cmod, 0.0f);
100 for(
auto cmod : state.world.in_rebel_type) {
101 state.world.execute_serial_over_nation([&](
auto nation_indices) {
102 state.world.nation_set_rebel_org_modifier(nation_indices, cmod, 0.0f);
105 state.world.execute_serial_over_nation([&](
auto nation_indices) {
106 state.world.nation_set_has_gas_attack(nation_indices, ve::vbitfield_type{ 0 });
108 state.world.execute_serial_over_nation([&](
auto nation_indices) {
109 state.world.nation_set_has_gas_defense(nation_indices, ve::vbitfield_type{ 0 });
115 state.world.for_each_technology([&](dcon::technology_id t_id) {
116 auto tech_id = fatten(state.world, t_id);
141 if(tech_id.get_increase_building(t)) {
142 state.world.execute_serial_over_nation([&](
auto nation_indices) {
143 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
144 auto old_rr_value = state.world.nation_get_max_building_level(nation_indices,
uint8_t(t));
145 state.world.nation_set_max_building_level(nation_indices,
uint8_t(t),
ve::select(has_tech_mask, old_rr_value + 1, old_rr_value));
159 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
160 if(tech_id.get_activate_building(
id)) {
161 state.world.execute_serial_over_nation([&](
auto nation_indices) {
162 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
163 auto old_value = state.world.nation_get_active_building(nation_indices,
id);
164 state.world.nation_set_active_building(nation_indices,
id, old_value | has_tech_mask);
168 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
169 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
170 if(tech_id.get_activate_unit(uid)) {
171 state.world.execute_serial_over_nation([&](
auto nation_indices) {
172 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
173 auto old_value = state.world.nation_get_active_unit(nation_indices, uid);
174 state.world.nation_set_active_unit(nation_indices, uid, old_value | has_tech_mask);
179 for(
auto cmod : tech_id.get_rgo_goods_output()) {
180 state.world.execute_serial_over_nation([&](
auto nation_indices) {
181 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
182 auto old_value = state.world.nation_get_rgo_goods_output(nation_indices, cmod.type);
183 state.world.nation_set_rgo_goods_output(nation_indices, cmod.type,
184 ve::select(has_tech_mask, old_value + cmod.amount, old_value));
187 for(
auto cmod : tech_id.get_factory_goods_output()) {
188 state.world.execute_serial_over_nation([&](
auto nation_indices) {
189 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
190 auto old_value = state.world.nation_get_factory_goods_output(nation_indices, cmod.type);
191 state.world.nation_set_factory_goods_output(nation_indices, cmod.type,
192 ve::select(has_tech_mask, old_value + cmod.amount, old_value));
195 for(
auto cmod : tech_id.get_rgo_size()) {
196 state.world.execute_serial_over_nation([&](
auto nation_indices) {
197 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
198 auto old_value = state.world.nation_get_rgo_size(nation_indices, cmod.type);
199 state.world.nation_set_rgo_size(nation_indices, cmod.type,
ve::select(has_tech_mask, old_value + cmod.amount, old_value));
202 for(
auto& umod : tech_id.get_modified_units()) {
203 state.world.for_each_nation([&](dcon::nation_id nid) {
204 if(state.world.nation_get_active_technologies(nid, t_id)) {
205 state.world.nation_get_unit_stats(nid, umod.type) += umod;
213 state.world.for_each_invention([&](dcon::invention_id i_id) {
214 auto inv_id = fatten(state.world, i_id);
239 if(inv_id.get_increase_building(t)) {
240 state.world.execute_serial_over_nation([&](
auto nation_indices) {
241 auto has_tech_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
242 auto old_rr_value = state.world.nation_get_max_building_level(nation_indices,
uint8_t(t));
243 state.world.nation_set_max_building_level(nation_indices,
uint8_t(t),
ve::select(has_tech_mask, old_rr_value + 1, old_rr_value));
248 if(inv_id.get_enable_gas_attack()) {
249 state.world.execute_serial_over_nation([&](
auto nation_indices) {
250 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
251 auto old_value = state.world.nation_get_has_gas_attack(nation_indices);
252 state.world.nation_set_has_gas_attack(nation_indices, old_value | has_inv_mask);
255 if(inv_id.get_enable_gas_defense()) {
256 state.world.execute_serial_over_nation([&](
auto nation_indices) {
257 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
258 auto old_value = state.world.nation_get_has_gas_defense(nation_indices);
259 state.world.nation_set_has_gas_defense(nation_indices, old_value | has_inv_mask);
272 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
273 if(inv_id.get_activate_building(
id)) {
274 state.world.execute_serial_over_nation([&](
auto nation_indices) {
275 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
276 auto old_value = state.world.nation_get_active_building(nation_indices,
id);
277 state.world.nation_set_active_building(nation_indices,
id, old_value | has_inv_mask);
281 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
282 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
283 if(inv_id.get_activate_unit(uid)) {
284 state.world.execute_serial_over_nation([&](
auto nation_indices) {
285 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
286 auto old_value = state.world.nation_get_active_unit(nation_indices, uid);
287 state.world.nation_set_active_unit(nation_indices, uid, old_value | has_inv_mask);
291 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
292 dcon::crime_id uid = dcon::crime_id{dcon::crime_id::value_base_t(i)};
293 if(inv_id.get_activate_crime(uid)) {
294 state.world.execute_serial_over_nation([&](
auto nation_indices) {
295 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
296 auto old_value = state.world.nation_get_active_crime(nation_indices, uid);
297 state.world.nation_set_active_crime(nation_indices, uid, old_value | has_inv_mask);
302 for(
auto cmod : inv_id.get_rgo_goods_output()) {
303 state.world.execute_serial_over_nation([&](
auto nation_indices) {
304 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
305 auto old_value = state.world.nation_get_rgo_goods_output(nation_indices, cmod.type);
306 state.world.nation_set_rgo_goods_output(nation_indices, cmod.type,
307 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
310 for(
auto cmod : inv_id.get_rgo_size()) {
311 state.world.execute_serial_over_nation([&](
auto nation_indices) {
312 auto has_tech_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
313 auto old_value = state.world.nation_get_rgo_size(nation_indices, cmod.type);
314 state.world.nation_set_rgo_size(nation_indices, cmod.type,
ve::select(has_tech_mask, old_value + cmod.amount, old_value));
317 for(
auto cmod : inv_id.get_factory_goods_output()) {
318 state.world.execute_serial_over_nation([&](
auto nation_indices) {
319 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
320 auto old_value = state.world.nation_get_factory_goods_output(nation_indices, cmod.type);
321 state.world.nation_set_factory_goods_output(nation_indices, cmod.type,
322 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
325 for(
auto cmod : inv_id.get_factory_goods_throughput()) {
326 state.world.execute_serial_over_nation([&](
auto nation_indices) {
327 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
328 auto old_value = state.world.nation_get_factory_goods_throughput(nation_indices, cmod.type);
329 state.world.nation_set_factory_goods_throughput(nation_indices, cmod.type,
330 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
333 for(
auto cmod : inv_id.get_rebel_org()) {
334 state.world.execute_serial_over_nation([&](
auto nation_indices) {
335 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
337 auto old_value = state.world.nation_get_rebel_org_modifier(nation_indices, cmod.type);
338 state.world.nation_set_rebel_org_modifier(nation_indices, cmod.type,
339 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
340 }
else if(has_inv_mask.v != 0) {
341 state.world.for_each_rebel_type([&](dcon::rebel_type_id rt) {
342 auto old_value = state.world.nation_get_rebel_org_modifier(nation_indices, rt);
343 state.world.nation_set_rebel_org_modifier(nation_indices, rt,
344 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
349 for(
auto& umod : inv_id.get_modified_units()) {
350 state.world.for_each_nation([&](dcon::nation_id nid) {
351 if(state.world.nation_get_active_inventions(nid, i_id)) {
352 auto& existing_stats = state.world.nation_get_unit_stats(nid, umod.type);
353 existing_stats += umod;
361 auto tech_id = fatten(state.world, t_id);
363 state.world.nation_set_active_technologies(target_nation, t_id,
true);
365 auto tech_mod = tech_id.get_modifier();
367 auto& tech_nat_values = tech_mod.get_national_values();
369 if(!(tech_nat_values.offsets[i]))
372 auto fixed_offset = tech_nat_values.offsets[i];
373 auto modifier_amount = tech_nat_values.values[i];
375 state.world.nation_get_modifier_values(target_nation, fixed_offset) += modifier_amount;
379 auto& plur = state.world.nation_get_plurality(target_nation);
380 plur = std::clamp(plur + tech_id.get_plurality() * 100.0f, 0.0f, 100.0f);
383 if(tech_id.get_increase_building(t)) {
384 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) += 1;
387 state.world.nation_get_permanent_colonial_points(target_nation) += tech_id.get_colonial_points();
388 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
389 if(tech_id.get_activate_building(
id)) {
390 state.world.nation_set_active_building(target_nation,
id,
true);
393 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
394 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
395 if(tech_id.get_activate_unit(uid)) {
396 state.world.nation_set_active_unit(target_nation, uid,
true);
400 for(
auto cmod : tech_id.get_rgo_goods_output()) {
401 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) += cmod.amount;
403 for(
auto cmod : tech_id.get_factory_goods_output()) {
404 state.world.nation_get_factory_goods_output(target_nation, cmod.type) += cmod.amount;
406 for(
auto cmod : tech_id.get_rgo_size()) {
407 state.world.nation_get_rgo_size(target_nation, cmod.type) += cmod.amount;
409 for(
auto& umod : tech_id.get_modified_units()) {
410 if(umod.type == state.military_definitions.base_army_unit) {
411 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
412 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
413 if(state.military_definitions.unit_base_definitions[uid].is_land) {
414 state.world.nation_get_unit_stats(target_nation, uid) += umod;
417 }
else if(umod.type == state.military_definitions.base_naval_unit) {
418 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
419 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
420 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
421 state.world.nation_get_unit_stats(target_nation, uid) += umod;
425 state.world.nation_get_unit_stats(target_nation, umod.type) += umod;
431 auto tech_id = fatten(state.world, t_id);
433 state.world.nation_set_active_technologies(target_nation, t_id,
false);
435 auto tech_mod = tech_id.get_modifier();
437 auto& tech_nat_values = tech_mod.get_national_values();
439 if(!(tech_nat_values.offsets[i]))
442 auto fixed_offset = tech_nat_values.offsets[i];
443 auto modifier_amount = tech_nat_values.values[i];
445 state.world.nation_get_modifier_values(target_nation, fixed_offset) -= modifier_amount;
449 auto& plur = state.world.nation_get_plurality(target_nation);
450 plur = std::clamp(plur - tech_id.get_plurality() * 100.0f, 0.0f, 100.0f);
453 if(tech_id.get_increase_building(t)) {
454 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) -= 1;
457 state.world.nation_get_permanent_colonial_points(target_nation) -= tech_id.get_colonial_points();
458 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
459 if(tech_id.get_activate_building(
id)) {
460 state.world.nation_set_active_building(target_nation,
id,
false);
463 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
464 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
465 if(tech_id.get_activate_unit(uid)) {
466 state.world.nation_set_active_unit(target_nation, uid,
false);
470 for(
auto cmod : tech_id.get_rgo_goods_output()) {
471 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) -= cmod.amount;
473 for(
auto cmod : tech_id.get_factory_goods_output()) {
474 state.world.nation_get_factory_goods_output(target_nation, cmod.type) -= cmod.amount;
476 for(
auto cmod : tech_id.get_rgo_size()) {
477 state.world.nation_get_rgo_size(target_nation, cmod.type) -= cmod.amount;
479 for(
auto& umod : tech_id.get_modified_units()) {
480 if(umod.type == state.military_definitions.base_army_unit) {
481 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
482 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
483 if(state.military_definitions.unit_base_definitions[uid].is_land) {
484 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
487 }
else if(umod.type == state.military_definitions.base_naval_unit) {
488 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
489 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
490 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
491 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
495 state.world.nation_get_unit_stats(target_nation, umod.type) -= umod;
501 auto inv_id = fatten(state.world, i_id);
503 state.world.nation_set_active_inventions(target_nation, i_id,
true);
506 auto inv_mod = inv_id.get_modifier();
508 auto& inv_nat_values = inv_mod.get_national_values();
510 if(!(inv_nat_values.offsets[i]))
513 auto fixed_offset = inv_nat_values.offsets[i];
514 auto modifier_amount = inv_nat_values.values[i];
516 state.world.nation_get_modifier_values(target_nation, fixed_offset) += modifier_amount;
521 if(inv_id.get_increase_building(t)) {
522 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) += 1;
526 state.world.nation_get_permanent_colonial_points(target_nation) += inv_id.get_colonial_points();
527 if(inv_id.get_enable_gas_attack()) {
528 state.world.nation_set_has_gas_attack(target_nation,
true);
530 if(inv_id.get_enable_gas_defense()) {
531 state.world.nation_set_has_gas_defense(target_nation,
true);
534 auto& plur = state.world.nation_get_plurality(target_nation);
535 plur = std::clamp(plur + inv_id.get_plurality() * 100.0f, 0.0f, 100.0f);
537 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
538 if(inv_id.get_activate_building(
id)) {
539 state.world.nation_set_active_building(target_nation, id, true);
542 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
543 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
544 if(inv_id.get_activate_unit(uid)) {
545 state.world.nation_set_active_unit(target_nation, uid,
true);
548 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
549 dcon::crime_id uid = dcon::crime_id{dcon::crime_id::value_base_t(i)};
550 if(inv_id.get_activate_crime(uid)) {
551 state.world.nation_set_active_crime(target_nation, uid,
true);
555 for(
auto cmod : inv_id.get_rgo_goods_output()) {
556 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) += cmod.amount;
558 for(
auto cmod : inv_id.get_rgo_size()) {
559 state.world.nation_get_rgo_size(target_nation, cmod.type) += cmod.amount;
561 for(
auto cmod : inv_id.get_factory_goods_output()) {
562 state.world.nation_get_factory_goods_output(target_nation, cmod.type) += cmod.amount;
564 for(
auto cmod : inv_id.get_factory_goods_throughput()) {
565 state.world.nation_get_factory_goods_throughput(target_nation, cmod.type) += cmod.amount;
567 for(
auto cmod : inv_id.get_rebel_org()) {
569 state.world.nation_get_rebel_org_modifier(target_nation, cmod.type) += cmod.amount;
571 state.world.for_each_rebel_type(
572 [&](dcon::rebel_type_id rt) { state.world.nation_get_rebel_org_modifier(target_nation, rt) += cmod.amount; });
575 for(
auto& umod : inv_id.get_modified_units()) {
576 if(umod.type == state.military_definitions.base_army_unit) {
577 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
578 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
579 if(state.military_definitions.unit_base_definitions[uid].is_land) {
580 state.world.nation_get_unit_stats(target_nation, uid) += umod;
583 }
else if(umod.type == state.military_definitions.base_naval_unit) {
584 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
585 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
586 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
587 state.world.nation_get_unit_stats(target_nation, uid) += umod;
591 state.world.nation_get_unit_stats(target_nation, umod.type) += umod;
595 if(
auto p = inv_id.get_shared_prestige(); p > 0) {
597 for(
auto n : state.world.in_nation) {
598 if(n.get_active_inventions(i_id)) {
607 dcon::invention_id i_id) {
608 auto inv_id = fatten(state.world, i_id);
610 state.world.nation_set_active_inventions(target_nation, i_id,
false);
613 auto inv_mod = inv_id.get_modifier();
615 auto& inv_nat_values = inv_mod.get_national_values();
617 if(!(inv_nat_values.offsets[i]))
620 auto fixed_offset = inv_nat_values.offsets[i];
621 auto modifier_amount = inv_nat_values.values[i];
623 state.world.nation_get_modifier_values(target_nation, fixed_offset) -= modifier_amount;
628 if(inv_id.get_increase_building(t)) {
629 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) -= 1;
633 state.world.nation_get_permanent_colonial_points(target_nation) -= inv_id.get_colonial_points();
634 if(inv_id.get_enable_gas_attack()) {
635 state.world.nation_set_has_gas_attack(target_nation,
false);
637 if(inv_id.get_enable_gas_defense()) {
638 state.world.nation_set_has_gas_defense(target_nation,
false);
641 auto& plur = state.world.nation_get_plurality(target_nation);
642 plur = std::clamp(plur - inv_id.get_plurality() * 100.0f, 0.0f, 100.0f);
644 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
645 if(inv_id.get_activate_building(
id)) {
646 state.world.nation_set_active_building(target_nation, id, false);
649 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
650 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
651 if(inv_id.get_activate_unit(uid)) {
652 state.world.nation_set_active_unit(target_nation, uid,
false);
655 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
656 dcon::crime_id uid = dcon::crime_id{dcon::crime_id::value_base_t(i)};
657 if(inv_id.get_activate_crime(uid)) {
658 state.world.nation_set_active_crime(target_nation, uid,
false);
662 for(
auto cmod : inv_id.get_rgo_goods_output()) {
663 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) -= cmod.amount;
665 for(
auto cmod : inv_id.get_rgo_size()) {
666 state.world.nation_get_rgo_size(target_nation, cmod.type) -= cmod.amount;
668 for(
auto cmod : inv_id.get_factory_goods_output()) {
669 state.world.nation_get_factory_goods_output(target_nation, cmod.type) -= cmod.amount;
671 for(
auto cmod : inv_id.get_factory_goods_throughput()) {
672 state.world.nation_get_factory_goods_throughput(target_nation, cmod.type) -= cmod.amount;
674 for(
auto cmod : inv_id.get_rebel_org()) {
676 state.world.nation_get_rebel_org_modifier(target_nation, cmod.type) -= cmod.amount;
678 state.world.for_each_rebel_type(
679 [&](dcon::rebel_type_id rt) { state.world.nation_get_rebel_org_modifier(target_nation, rt) -= cmod.amount; });
682 for(
auto& umod : inv_id.get_modified_units()) {
683 if(umod.type == state.military_definitions.base_army_unit) {
684 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
685 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
686 if(state.military_definitions.unit_base_definitions[uid].is_land) {
687 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
690 }
else if(umod.type == state.military_definitions.base_naval_unit) {
691 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
692 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
693 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
694 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
698 state.world.nation_get_unit_stats(target_nation, umod.type) -= umod;
702 if(
auto p = inv_id.get_shared_prestige(); p > 0) {
704 for(
auto n : state.world.in_nation) {
705 if(n.get_active_inventions(i_id)) {
714 return state.flag_type_map[
static_cast<size_t>(type)];
718 if(state.world.nation_get_owned_province_count(target_nation) == 0)
719 return flag_type::default_flag;
721 auto gov_type = state.world.nation_get_government_type(target_nation);
723 return flag_type::default_flag;
725 auto id = state.world.national_identity_get_government_flag_type(state.world.nation_get_identity_from_identity_holder(target_nation), gov_type);
729 return flag_type(state.world.government_type_get_flag(gov_type));
733 auto holder = state.world.national_identity_get_nation_from_identity_holder(identity);
737 return flag_type::default_flag;
741 auto rules = state.world.nation_get_combined_issue_rules(owner);
743 state.world.province_set_is_slave(p,
false);
744 bool mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
745 for(
auto pop : state.world.province_get_pop_location(p)) {
746 if(pop.get_pop().get_poptype() == state.culture_definitions.slaves) {
747 pop.get_pop().set_poptype(mine ? state.culture_definitions.laborers : state.culture_definitions.farmers);
750 }
else if(state.world.province_get_is_slave(p) ==
false) {
751 bool found_slave =
false;
752 for(
auto pop : state.world.province_get_pop_location(p)) {
753 if(pop.get_pop().get_poptype() == state.culture_definitions.slaves) {
760 state.world.province_set_is_slave(p2, true);
767 auto old_rules = state.world.nation_get_combined_issue_rules(n_id);
769 state.world.for_each_issue([&](dcon::issue_id i_id) {
770 auto current_opt = state.world.nation_get_issues(n_id, i_id);
771 auto rules_for_opt = state.world.issue_option_get_rules(current_opt);
772 combined |= rules_for_opt;
774 state.world.for_each_reform([&](dcon::reform_id i_id) {
775 auto current_opt = state.world.nation_get_reforms(n_id, i_id);
776 auto rules_for_opt = state.world.reform_option_get_rules(current_opt);
777 combined |= rules_for_opt;
779 state.world.nation_set_combined_issue_rules(n_id, combined);
783 for(
auto p : state.world.nation_get_province_ownership(n_id)) {
784 state.world.province_set_is_slave(p.get_province(),
false);
785 bool mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p.get_province()));
786 for(
auto pop : state.world.province_get_pop_location(p.get_province())) {
787 if(pop.get_pop().get_poptype() == state.culture_definitions.slaves) {
788 pop.get_pop().set_poptype(mine ? state.culture_definitions.laborers : state.culture_definitions.farmers);
794 for(
auto p : state.world.nation_get_province_ownership(n_id)) {
795 for(
auto f : p.get_province().get_factory_location()) {
796 f.get_factory().set_subsidized(
false);
802 state.world.execute_serial_over_nation([&](
auto n_id) {
803 ve::int_vector combined;
804 state.world.for_each_issue([&](dcon::issue_id i_id) {
805 auto current_opt = state.world.nation_get_issues(n_id, i_id);
806 auto rules_for_opt = state.world.issue_option_get_rules(current_opt);
807 combined = combined | rules_for_opt;
809 state.world.for_each_reform([&](dcon::reform_id i_id) {
810 auto current_opt = state.world.nation_get_reforms(n_id, i_id);
811 auto rules_for_opt = state.world.reform_option_get_rules(current_opt);
812 combined = combined | rules_for_opt;
814 state.world.nation_set_combined_issue_rules(n_id, combined);
819 state.world.for_each_pop([&state](dcon::pop_id pid) {
821 float pol_sup = 0.0f;
822 float soc_sup = 0.0f;
823 state.world.for_each_issue_option([&](dcon::issue_option_id i) {
827 auto par = state.world.issue_option_get_parent_issue(i);
842 state.world.for_each_pop([&state](dcon::pop_id pid) {
843 auto ptype = state.world.pop_get_poptype(pid);
845 auto psize = state.world.pop_get_size(pid);
850 static auto buf = state.world.ideology_make_vectorizable_float_buffer();
852 state.world.for_each_ideology([&](dcon::ideology_id iid) {
854 if(state.world.ideology_get_enabled(iid) &&
855 (!state.world.ideology_get_is_civilized_only(iid) || state.world.nation_get_is_civilized(owner))) {
856 auto ptrigger = state.world.pop_type_get_ideology(ptype, iid);
858 auto amount = trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(pid),
859 trigger::to_generic(pid), 0);
860 buf.set(iid, amount);
866 float adjustment_factor = 1.0f / total;
867 state.world.for_each_ideology([&state, pid, adjustment_factor](dcon::ideology_id iid) {
868 auto normalized_amount = buf.get(iid) * adjustment_factor;
874 static auto buf = state.world.issue_option_make_vectorizable_float_buffer();
876 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
877 auto opt = fatten(state.world, iid);
878 auto allow = opt.get_allow();
879 auto parent_issue = opt.get_parent_issue();
880 auto co = state.world.nation_get_issues(owner, parent_issue);
882 if((state.world.nation_get_is_civilized(owner) || state.world.issue_get_issue_type(parent_issue) ==
uint8_t(issue_type::party))
883 && (state.world.issue_get_is_next_step_only(parent_issue) ==
false || co.id.index() == iid.index() || co.id.index() + 1 == iid.index() || co.id.index() - 1 == iid.index())) {
885 if(
auto mtrigger = state.world.pop_type_get_issues(ptype, iid); mtrigger) {
888 buf.set(iid, amount);
894 float adjustment_factor = 1.0f / total;
895 state.world.for_each_issue_option([&state, pid, adjustment_factor](dcon::issue_option_id iid) {
896 auto normalized_amount = buf.get(iid) * adjustment_factor;
905 dcon::technology_id tech_id) {
910 auto base_cost = state.world.technology_get_cost(tech_id);
911 auto availability_year = state.world.technology_get_year(tech_id);
912 auto folder = state.world.technology_get_folder_index(tech_id);
913 auto category = state.culture_definitions.tech_folders[folder].category;
914 auto research_mod = [&]() {
916 case tech_category::army:
917 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::army_tech_research_bonus) + 1.0f;
918 case tech_category::navy:
919 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::navy_tech_research_bonus) + 1.0f;
920 case tech_category::commerce:
921 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::commerce_tech_research_bonus) + 1.0f;
922 case tech_category::culture:
923 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::culture_tech_research_bonus) + 1.0f;
924 case tech_category::industry:
925 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::industry_tech_research_bonus) + 1.0f;
927 case tech_category::military_theory:
928 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::military_theory_tech_research_bonus) + 1.0f;
929 case tech_category::population:
930 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::population_tech_research_bonus) + 1.0f;
931 case tech_category::diplomacy:
932 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::diplomacy_tech_research_bonus) + 1.0f;
933 case tech_category::flavor:
934 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::flavor_tech_research_bonus) + 1.0f;
939 auto ol_mod = state.world.nation_get_active_technologies(
940 state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(target_nation)), tech_id)
941 ? state.defines.tech_factor_vassal
943 return float(base_cost) * ol_mod * (1.0f / research_mod) *
944 (1.0f - std::max(0.0f,
float(int32_t(current_year) - availability_year) / state.defines.tech_year_span));
948 for(
auto n : state.world.in_nation) {
949 if(n.get_owned_province_count() != 0 && n.get_current_research()) {
950 if(n.get_active_technologies(n.get_current_research())) {
951 n.set_current_research(dcon::technology_id{});
954 if(n.get_research_points() >= cost) {
955 n.get_research_points() -= cost;
964 n, dcon::nation_id{}, dcon::nation_id{},
968 n.set_current_research(dcon::technology_id{});
982 for(
auto inv : state.world.in_invention) {
983 auto lim = inv.get_limit();
984 auto odds = inv.get_chance();
986 ve::execute_serial_fast<dcon::nation_id>(state.world.nation_size(), [&](
auto nids) {
987 auto may_discover = !state.world.nation_get_active_inventions(nids, inv)
988 && (state.world.nation_get_owned_province_count(nids) != 0)
989 && trigger::evaluate(state, lim, trigger::to_generic(nids), trigger::to_generic(nids), 0);
991 if(ve::compress_mask(may_discover).v != 0) {
993 ? trigger::evaluate_additive_modifier(state, odds, trigger::to_generic(nids), trigger::to_generic(nids), 0)
995 ve::apply([&](dcon::nation_id n, float chance, bool allow_discovery) {
996 if(allow_discovery) {
997 auto random = rng::get_random(state, uint32_t(inv.id.index()) << 5 ^ uint32_t(n.index()));
998 if(int32_t(random % 100) < int32_t(chance)) {
999 apply_invention(state, n, inv);
1001 notification::post(state, notification::message{
1002 [inv](sys::state& state, text::layout_base& contents) {
1003 text::add_line(state, contents,
"msg_inv_1", text::variable_type::x, state.world.invention_get_name(inv));
1004 ui::invention_description(state, contents, inv, 0);
1007 n, dcon::nation_id{}, dcon::nation_id{},
1008 sys::message_base_type::invention
1012 }, nids, chances, may_discover);
1016 ve::execute_serial_fast<dcon::nation_id>(state.world.nation_size(), [&](
auto nids) {
1017 auto may_not_discover =
1018 state.world.nation_get_active_inventions(nids, inv) || (state.world.nation_get_owned_province_count(nids) == 0);
1019 if(ve::compress_mask(may_not_discover).v != 0) {
1021 ? trigger::evaluate_additive_modifier(state, odds, trigger::to_generic(nids), trigger::to_generic(nids), 0)
1023 ve::apply([&](dcon::nation_id n, float chance, bool block_discovery) {
1024 if(!block_discovery) {
1025 auto random = rng::get_random(state, uint32_t(inv.id.index()) << 5 ^ uint32_t(n.index()));
1026 if(int32_t(random % 100) < int32_t(chance)) {
1027 apply_invention(state, n, inv);
1029 notification::post(state, notification::message{
1030 [inv](sys::state& state, text::layout_base& contents) {
1031 text::add_line(state, contents,
"msg_inv_1", text::variable_type::x, state.world.invention_get_name(inv));
1032 ui::invention_description(state, contents, inv, 0);
1035 n, dcon::nation_id{}, dcon::nation_id{},
1036 sys::message_base_type::invention
1040 }, nids, chances, may_not_discover);
1049 for(
auto cores_of : state.world.national_identity_get_core(old_tag)) {
1050 state.world.try_create_core(cores_of.get_province(), new_tag);
1053 auto core_list = state.world.national_identity_get_core(old_tag);
1054 while(core_list.begin() != core_list.end()) {
1055 state.world.delete_core((*core_list.begin()).id);
uint32_t get_remapped_flag_type(sys::state const &state, flag_type type)
void discover_inventions(sys::state &state)
void apply_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
float effective_technology_cost(sys::state &state, uint32_t current_year, dcon::nation_id target_nation, dcon::technology_id tech_id)
void fix_slaves_in_province(sys::state &state, dcon::nation_id owner, dcon::province_id p)
void replace_cores(sys::state &state, dcon::national_identity_id old_tag, dcon::national_identity_id new_tag)
void clear_existing_tech_effects(sys::state &state)
void repopulate_technology_effects(sys::state &state)
void update_all_nations_issue_rules(sys::state &state)
void set_default_issue_and_reform_options(sys::state &state)
void remove_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
void repopulate_invention_effects(sys::state &state)
void update_research(sys::state &state, uint32_t current_year)
flag_type get_current_flag_type(sys::state const &state, dcon::nation_id target_nation)
void restore_unsaved_values(sys::state &state)
void remove_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
void create_initial_ideology_and_issues_distribution(sys::state &state)
void apply_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
std::string get_tech_category_name(tech_category t)
void update_nation_issue_rules(sys::state &state, dcon::nation_id n_id)
constexpr uint32_t can_subsidise
constexpr uint32_t slavery_allowed
void reset_unit_stats(sys::state &state)
void adjust_prestige(sys::state &state, dcon::nation_id n, float delta)
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
void post(sys::state &state, message &&m)
void set_political_reform_desire(sys::state &state, dcon::pop_id p, float v)
void set_social_reform_desire(sys::state &state, dcon::pop_id p, float v)
void set_demo(sys::state &state, dcon::pop_id p, dcon::pop_demographics_key k, float v)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
int32_t to_generic(dcon::province_id v)
float evaluate_multiplicative_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
void technology_description(sys::state &state, text::layout_base &contents, dcon::technology_id tech_id) noexcept
T select(bool v, T a, T b)
static constexpr uint32_t modifier_definition_size