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); });
56 state.world.for_each_commodity([&](dcon::commodity_id c_id) {
57 state.world.nation_set_unlocked_commodities(target_nation, c_id,
false);
60 state.world.for_each_technology([&](dcon::technology_id t_id) {
61 auto tech_id = fatten(state.world, t_id);
63 if(!state.world.nation_get_active_technologies(target_nation, tech_id)) {
67 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
68 if(tech_id.get_activate_building(
id)) {
69 state.world.nation_set_active_building(target_nation, id, true);
71 auto output = state.world.factory_type_get_output(id);
73 state.world.nation_set_unlocked_commodities(target_nation, output, true);
77 state.world.for_each_invention([&](dcon::invention_id i_id) {
78 auto inv_id = fatten(state.world, i_id);
80 if(!state.world.nation_get_active_inventions(target_nation, inv_id)) {
84 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
85 if(inv_id.get_activate_building(
id)) {
86 state.world.nation_set_active_building(target_nation, id, true);
87 auto output = state.world.factory_type_get_output(id);
88 state.world.nation_set_unlocked_commodities(target_nation, output, true);
96 state.world.execute_serial_over_nation([&](
auto nation_indices) {
97 state.world.nation_set_max_building_level(nation_indices,
uint8_t(t), 0);
101 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
102 state.world.execute_serial_over_nation([&](
auto nation_indices) {
103 state.world.nation_set_active_building(nation_indices,
id, ve::vbitfield_type{0});
106 state.world.for_each_commodity([&](dcon::commodity_id
id) {
107 state.world.execute_serial_over_nation([&](
auto nation_indices) {
108 state.world.nation_set_unlocked_commodities(nation_indices,
id, ve::vbitfield_type{ 0 });
111 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
112 dcon::unit_type_id uid = dcon::unit_type_id{ dcon::unit_type_id::value_base_t(i) };
113 state.world.execute_serial_over_nation([&](
auto nation_indices) {
114 state.world.nation_set_active_unit(nation_indices, uid, ve::vbitfield_type{ 0 });
117 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
118 dcon::crime_id uid = dcon::crime_id{ dcon::crime_id::value_base_t(i) };
119 state.world.execute_serial_over_nation([&](
auto nation_indices) {
120 state.world.nation_set_active_crime(nation_indices, uid, ve::vbitfield_type{ 0 });
124 for(
auto cmod : state.world.in_commodity) {
125 state.world.execute_serial_over_nation([&](
auto nation_indices) {
126 state.world.nation_set_rgo_goods_output(nation_indices, cmod, 0.0f);
129 for(
auto cmod : state.world.in_commodity) {
130 state.world.execute_serial_over_nation([&](
auto nation_indices) {
131 state.world.nation_set_factory_goods_output(nation_indices, cmod, 0.0f);
134 for(
auto cmod : state.world.in_commodity) {
135 state.world.execute_serial_over_nation([&](
auto nation_indices) {
136 state.world.nation_set_rgo_size(nation_indices, cmod, 0.0f);
139 for(
auto cmod : state.world.in_commodity) {
140 state.world.execute_serial_over_nation([&](
auto nation_indices) {
141 state.world.nation_set_factory_goods_throughput(nation_indices, cmod, 0.0f);
144 for(
auto cmod : state.world.in_rebel_type) {
145 state.world.execute_serial_over_nation([&](
auto nation_indices) {
146 state.world.nation_set_rebel_org_modifier(nation_indices, cmod, 0.0f);
149 state.world.execute_serial_over_nation([&](
auto nation_indices) {
150 state.world.nation_set_has_gas_attack(nation_indices, ve::vbitfield_type{ 0 });
152 state.world.execute_serial_over_nation([&](
auto nation_indices) {
153 state.world.nation_set_has_gas_defense(nation_indices, ve::vbitfield_type{ 0 });
159 state.world.for_each_technology([&](dcon::technology_id t_id) {
160 auto tech_id = fatten(state.world, t_id);
185 if(tech_id.get_increase_building(t)) {
186 state.world.execute_serial_over_nation([&](
auto nation_indices) {
187 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
188 auto old_rr_value = state.world.nation_get_max_building_level(nation_indices,
uint8_t(t));
189 state.world.nation_set_max_building_level(nation_indices,
uint8_t(t),
ve::select(has_tech_mask, old_rr_value + 1, old_rr_value));
203 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
204 if(tech_id.get_activate_building(
id)) {
205 state.world.execute_serial_over_nation([&](
auto nation_indices) {
206 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
207 auto old_value = state.world.nation_get_active_building(nation_indices,
id);
208 state.world.nation_set_active_building(nation_indices,
id, old_value | has_tech_mask);
212 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
213 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
214 if(tech_id.get_activate_unit(uid)) {
215 state.world.execute_serial_over_nation([&](
auto nation_indices) {
216 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
217 auto old_value = state.world.nation_get_active_unit(nation_indices, uid);
218 state.world.nation_set_active_unit(nation_indices, uid, old_value | has_tech_mask);
223 for(
auto cmod : tech_id.get_rgo_goods_output()) {
224 state.world.execute_serial_over_nation([&](
auto nation_indices) {
225 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
226 auto old_value = state.world.nation_get_rgo_goods_output(nation_indices, cmod.type);
227 state.world.nation_set_rgo_goods_output(nation_indices, cmod.type,
228 ve::select(has_tech_mask, old_value + cmod.amount, old_value));
231 for(
auto cmod : tech_id.get_factory_goods_output()) {
232 state.world.execute_serial_over_nation([&](
auto nation_indices) {
233 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
234 auto old_value = state.world.nation_get_factory_goods_output(nation_indices, cmod.type);
235 state.world.nation_set_factory_goods_output(nation_indices, cmod.type,
236 ve::select(has_tech_mask, old_value + cmod.amount, old_value));
239 for(
auto cmod : tech_id.get_rgo_size()) {
240 state.world.execute_serial_over_nation([&](
auto nation_indices) {
241 auto has_tech_mask = state.world.nation_get_active_technologies(nation_indices, t_id);
242 auto old_value = state.world.nation_get_rgo_size(nation_indices, cmod.type);
243 state.world.nation_set_rgo_size(nation_indices, cmod.type,
ve::select(has_tech_mask, old_value + cmod.amount, old_value));
246 for(
auto& umod : tech_id.get_modified_units()) {
247 state.world.for_each_nation([&](dcon::nation_id nid) {
248 if(state.world.nation_get_active_technologies(nid, t_id)) {
249 state.world.nation_get_unit_stats(nid, umod.type) += umod;
255 for(
auto n : state.world.in_nation) {
261 state.world.for_each_invention([&](dcon::invention_id i_id) {
262 auto inv_id = fatten(state.world, i_id);
287 if(inv_id.get_increase_building(t)) {
288 state.world.execute_serial_over_nation([&](
auto nation_indices) {
289 auto has_tech_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
290 auto old_rr_value = state.world.nation_get_max_building_level(nation_indices,
uint8_t(t));
291 state.world.nation_set_max_building_level(nation_indices,
uint8_t(t),
ve::select(has_tech_mask, old_rr_value + 1, old_rr_value));
296 if(inv_id.get_enable_gas_attack()) {
297 state.world.execute_serial_over_nation([&](
auto nation_indices) {
298 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
299 auto old_value = state.world.nation_get_has_gas_attack(nation_indices);
300 state.world.nation_set_has_gas_attack(nation_indices, old_value | has_inv_mask);
303 if(inv_id.get_enable_gas_defense()) {
304 state.world.execute_serial_over_nation([&](
auto nation_indices) {
305 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
306 auto old_value = state.world.nation_get_has_gas_defense(nation_indices);
307 state.world.nation_set_has_gas_defense(nation_indices, old_value | has_inv_mask);
320 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
321 if(inv_id.get_activate_building(
id)) {
322 state.world.execute_serial_over_nation([&](
auto nation_indices) {
323 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
324 auto old_value = state.world.nation_get_active_building(nation_indices,
id);
325 state.world.nation_set_active_building(nation_indices,
id, old_value | has_inv_mask);
329 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
330 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
331 if(inv_id.get_activate_unit(uid)) {
332 state.world.execute_serial_over_nation([&](
auto nation_indices) {
333 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
334 auto old_value = state.world.nation_get_active_unit(nation_indices, uid);
335 state.world.nation_set_active_unit(nation_indices, uid, old_value | has_inv_mask);
339 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
340 dcon::crime_id uid = dcon::crime_id{dcon::crime_id::value_base_t(i)};
341 if(inv_id.get_activate_crime(uid)) {
342 state.world.execute_serial_over_nation([&](
auto nation_indices) {
343 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
344 auto old_value = state.world.nation_get_active_crime(nation_indices, uid);
345 state.world.nation_set_active_crime(nation_indices, uid, old_value | has_inv_mask);
350 for(
auto cmod : inv_id.get_rgo_goods_output()) {
351 state.world.execute_serial_over_nation([&](
auto nation_indices) {
352 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
353 auto old_value = state.world.nation_get_rgo_goods_output(nation_indices, cmod.type);
354 state.world.nation_set_rgo_goods_output(nation_indices, cmod.type,
355 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
358 for(
auto cmod : inv_id.get_rgo_size()) {
359 state.world.execute_serial_over_nation([&](
auto nation_indices) {
360 auto has_tech_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
361 auto old_value = state.world.nation_get_rgo_size(nation_indices, cmod.type);
362 state.world.nation_set_rgo_size(nation_indices, cmod.type,
ve::select(has_tech_mask, old_value + cmod.amount, old_value));
365 for(
auto cmod : inv_id.get_factory_goods_output()) {
366 state.world.execute_serial_over_nation([&](
auto nation_indices) {
367 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
368 auto old_value = state.world.nation_get_factory_goods_output(nation_indices, cmod.type);
369 state.world.nation_set_factory_goods_output(nation_indices, cmod.type,
370 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
373 for(
auto cmod : inv_id.get_factory_goods_throughput()) {
374 state.world.execute_serial_over_nation([&](
auto nation_indices) {
375 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
376 auto old_value = state.world.nation_get_factory_goods_throughput(nation_indices, cmod.type);
377 state.world.nation_set_factory_goods_throughput(nation_indices, cmod.type,
378 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
381 for(
auto cmod : inv_id.get_rebel_org()) {
382 state.world.execute_serial_over_nation([&](
auto nation_indices) {
383 auto has_inv_mask = state.world.nation_get_active_inventions(nation_indices, i_id);
385 auto old_value = state.world.nation_get_rebel_org_modifier(nation_indices, cmod.type);
386 state.world.nation_set_rebel_org_modifier(nation_indices, cmod.type,
387 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
388 }
else if(has_inv_mask.v != 0) {
389 state.world.for_each_rebel_type([&](dcon::rebel_type_id rt) {
390 auto old_value = state.world.nation_get_rebel_org_modifier(nation_indices, rt);
391 state.world.nation_set_rebel_org_modifier(nation_indices, rt,
392 ve::select(has_inv_mask, old_value + cmod.amount, old_value));
397 for(
auto& umod : inv_id.get_modified_units()) {
398 state.world.for_each_nation([&](dcon::nation_id nid) {
399 if(state.world.nation_get_active_inventions(nid, i_id)) {
400 auto& existing_stats = state.world.nation_get_unit_stats(nid, umod.type);
401 existing_stats += umod;
407 for(
auto n : state.world.in_nation) {
413 auto tech_id = fatten(state.world, t_id);
415 state.world.nation_set_active_technologies(target_nation, t_id,
true);
417 auto tech_mod = tech_id.get_modifier();
419 auto& tech_nat_values = tech_mod.get_national_values();
421 if(!(tech_nat_values.offsets[i]))
424 auto fixed_offset = tech_nat_values.offsets[i];
425 auto modifier_amount = tech_nat_values.values[i];
427 state.world.nation_get_modifier_values(target_nation, fixed_offset) += modifier_amount;
431 auto& plur = state.world.nation_get_plurality(target_nation);
432 plur = std::clamp(plur + tech_id.get_plurality() * 100.0f, 0.0f, 100.0f);
435 if(tech_id.get_increase_building(t)) {
436 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) += 1;
439 state.world.nation_get_permanent_colonial_points(target_nation) += tech_id.get_colonial_points();
440 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
441 if(tech_id.get_activate_building(
id)) {
442 state.world.nation_set_active_building(target_nation,
id,
true);
444 auto output = state.world.factory_type_get_output(
id);
446 state.world.nation_set_unlocked_commodities(target_nation, output,
true);
449 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
450 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
451 if(tech_id.get_activate_unit(uid)) {
452 state.world.nation_set_active_unit(target_nation, uid,
true);
456 for(
auto cmod : tech_id.get_rgo_goods_output()) {
457 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) += cmod.amount;
459 for(
auto cmod : tech_id.get_factory_goods_output()) {
460 state.world.nation_get_factory_goods_output(target_nation, cmod.type) += cmod.amount;
462 for(
auto cmod : tech_id.get_rgo_size()) {
463 state.world.nation_get_rgo_size(target_nation, cmod.type) += cmod.amount;
465 for(
auto& umod : tech_id.get_modified_units()) {
466 if(umod.type == state.military_definitions.base_army_unit) {
467 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
468 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
469 if(state.military_definitions.unit_base_definitions[uid].is_land) {
470 state.world.nation_get_unit_stats(target_nation, uid) += umod;
473 }
else if(umod.type == state.military_definitions.base_naval_unit) {
474 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
475 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
476 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
477 state.world.nation_get_unit_stats(target_nation, uid) += umod;
481 state.world.nation_get_unit_stats(target_nation, umod.type) += umod;
487 auto tech_id = fatten(state.world, t_id);
489 state.world.nation_set_active_technologies(target_nation, t_id,
false);
491 auto tech_mod = tech_id.get_modifier();
493 auto& tech_nat_values = tech_mod.get_national_values();
495 if(!(tech_nat_values.offsets[i]))
498 auto fixed_offset = tech_nat_values.offsets[i];
499 auto modifier_amount = tech_nat_values.values[i];
501 state.world.nation_get_modifier_values(target_nation, fixed_offset) -= modifier_amount;
505 auto& plur = state.world.nation_get_plurality(target_nation);
506 plur = std::clamp(plur - tech_id.get_plurality() * 100.0f, 0.0f, 100.0f);
509 if(tech_id.get_increase_building(t)) {
510 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) -= 1;
513 state.world.nation_get_permanent_colonial_points(target_nation) -= tech_id.get_colonial_points();
515 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
516 if(tech_id.get_activate_building(
id)) {
517 state.world.nation_set_active_building(target_nation,
id,
false);
523 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
524 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
525 if(tech_id.get_activate_unit(uid)) {
526 state.world.nation_set_active_unit(target_nation, uid,
false);
530 for(
auto cmod : tech_id.get_rgo_goods_output()) {
531 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) -= cmod.amount;
533 for(
auto cmod : tech_id.get_factory_goods_output()) {
534 state.world.nation_get_factory_goods_output(target_nation, cmod.type) -= cmod.amount;
536 for(
auto cmod : tech_id.get_rgo_size()) {
537 state.world.nation_get_rgo_size(target_nation, cmod.type) -= cmod.amount;
539 for(
auto& umod : tech_id.get_modified_units()) {
540 if(umod.type == state.military_definitions.base_army_unit) {
541 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
542 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
543 if(state.military_definitions.unit_base_definitions[uid].is_land) {
544 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
547 }
else if(umod.type == state.military_definitions.base_naval_unit) {
548 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
549 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
550 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
551 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
555 state.world.nation_get_unit_stats(target_nation, umod.type) -= umod;
561 auto inv_id = fatten(state.world, i_id);
563 state.world.nation_set_active_inventions(target_nation, i_id,
true);
566 auto inv_mod = inv_id.get_modifier();
568 auto& inv_nat_values = inv_mod.get_national_values();
570 if(!(inv_nat_values.offsets[i]))
573 auto fixed_offset = inv_nat_values.offsets[i];
574 auto modifier_amount = inv_nat_values.values[i];
576 state.world.nation_get_modifier_values(target_nation, fixed_offset) += modifier_amount;
581 if(inv_id.get_increase_building(t)) {
582 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) += 1;
586 state.world.nation_get_permanent_colonial_points(target_nation) += inv_id.get_colonial_points();
587 if(inv_id.get_enable_gas_attack()) {
588 state.world.nation_set_has_gas_attack(target_nation,
true);
590 if(inv_id.get_enable_gas_defense()) {
591 state.world.nation_set_has_gas_defense(target_nation,
true);
594 auto& plur = state.world.nation_get_plurality(target_nation);
595 plur = std::clamp(plur + inv_id.get_plurality() * 100.0f, 0.0f, 100.0f);
597 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
598 if(inv_id.get_activate_building(
id)) {
599 state.world.nation_set_active_building(target_nation, id, true);
600 auto output = state.world.factory_type_get_output(id);
601 state.world.nation_set_unlocked_commodities(target_nation, output, true);
604 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
605 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
606 if(inv_id.get_activate_unit(uid)) {
607 state.world.nation_set_active_unit(target_nation, uid,
true);
610 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
611 dcon::crime_id uid = dcon::crime_id{dcon::crime_id::value_base_t(i)};
612 if(inv_id.get_activate_crime(uid)) {
613 state.world.nation_set_active_crime(target_nation, uid,
true);
617 for(
auto cmod : inv_id.get_rgo_goods_output()) {
618 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) += cmod.amount;
620 for(
auto cmod : inv_id.get_rgo_size()) {
621 state.world.nation_get_rgo_size(target_nation, cmod.type) += cmod.amount;
623 for(
auto cmod : inv_id.get_factory_goods_output()) {
624 state.world.nation_get_factory_goods_output(target_nation, cmod.type) += cmod.amount;
626 for(
auto cmod : inv_id.get_factory_goods_throughput()) {
627 state.world.nation_get_factory_goods_throughput(target_nation, cmod.type) += cmod.amount;
629 for(
auto cmod : inv_id.get_rebel_org()) {
631 state.world.nation_get_rebel_org_modifier(target_nation, cmod.type) += cmod.amount;
633 state.world.for_each_rebel_type(
634 [&](dcon::rebel_type_id rt) { state.world.nation_get_rebel_org_modifier(target_nation, rt) += cmod.amount; });
637 for(
auto& umod : inv_id.get_modified_units()) {
638 if(umod.type == state.military_definitions.base_army_unit) {
639 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
640 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
641 if(state.military_definitions.unit_base_definitions[uid].is_land) {
642 state.world.nation_get_unit_stats(target_nation, uid) += umod;
645 }
else if(umod.type == state.military_definitions.base_naval_unit) {
646 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
647 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
648 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
649 state.world.nation_get_unit_stats(target_nation, uid) += umod;
653 state.world.nation_get_unit_stats(target_nation, umod.type) += umod;
657 if(
auto p = inv_id.get_shared_prestige(); p > 0) {
659 for(
auto n : state.world.in_nation) {
660 if(n.get_active_inventions(i_id)) {
669 dcon::invention_id i_id) {
670 auto inv_id = fatten(state.world, i_id);
672 state.world.nation_set_active_inventions(target_nation, i_id,
false);
675 auto inv_mod = inv_id.get_modifier();
677 auto& inv_nat_values = inv_mod.get_national_values();
679 if(!(inv_nat_values.offsets[i]))
682 auto fixed_offset = inv_nat_values.offsets[i];
683 auto modifier_amount = inv_nat_values.values[i];
685 state.world.nation_get_modifier_values(target_nation, fixed_offset) -= modifier_amount;
690 if(inv_id.get_increase_building(t)) {
691 state.world.nation_get_max_building_level(target_nation,
uint8_t(t)) -= 1;
695 state.world.nation_get_permanent_colonial_points(target_nation) -= inv_id.get_colonial_points();
696 if(inv_id.get_enable_gas_attack()) {
697 state.world.nation_set_has_gas_attack(target_nation,
false);
699 if(inv_id.get_enable_gas_defense()) {
700 state.world.nation_set_has_gas_defense(target_nation,
false);
703 auto& plur = state.world.nation_get_plurality(target_nation);
704 plur = std::clamp(plur - inv_id.get_plurality() * 100.0f, 0.0f, 100.0f);
706 state.world.for_each_factory_type([&](dcon::factory_type_id
id) {
707 if(inv_id.get_activate_building(
id)) {
708 state.world.nation_set_active_building(target_nation, id, false);
714 for(
uint32_t i = 0; i < state.military_definitions.unit_base_definitions.size(); ++i) {
715 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
716 if(inv_id.get_activate_unit(uid)) {
717 state.world.nation_set_active_unit(target_nation, uid,
false);
720 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
721 dcon::crime_id uid = dcon::crime_id{dcon::crime_id::value_base_t(i)};
722 if(inv_id.get_activate_crime(uid)) {
723 state.world.nation_set_active_crime(target_nation, uid,
false);
727 for(
auto cmod : inv_id.get_rgo_goods_output()) {
728 state.world.nation_get_rgo_goods_output(target_nation, cmod.type) -= cmod.amount;
730 for(
auto cmod : inv_id.get_rgo_size()) {
731 state.world.nation_get_rgo_size(target_nation, cmod.type) -= cmod.amount;
733 for(
auto cmod : inv_id.get_factory_goods_output()) {
734 state.world.nation_get_factory_goods_output(target_nation, cmod.type) -= cmod.amount;
736 for(
auto cmod : inv_id.get_factory_goods_throughput()) {
737 state.world.nation_get_factory_goods_throughput(target_nation, cmod.type) -= cmod.amount;
739 for(
auto cmod : inv_id.get_rebel_org()) {
741 state.world.nation_get_rebel_org_modifier(target_nation, cmod.type) -= cmod.amount;
743 state.world.for_each_rebel_type(
744 [&](dcon::rebel_type_id rt) { state.world.nation_get_rebel_org_modifier(target_nation, rt) -= cmod.amount; });
747 for(
auto& umod : inv_id.get_modified_units()) {
748 if(umod.type == state.military_definitions.base_army_unit) {
749 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
750 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
751 if(state.military_definitions.unit_base_definitions[uid].is_land) {
752 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
755 }
else if(umod.type == state.military_definitions.base_naval_unit) {
756 for(
uint32_t i = 2; i < state.military_definitions.unit_base_definitions.size(); ++i) {
757 dcon::unit_type_id uid = dcon::unit_type_id{dcon::unit_type_id::value_base_t(i)};
758 if(!state.military_definitions.unit_base_definitions[uid].is_land) {
759 state.world.nation_get_unit_stats(target_nation, uid) -= umod;
763 state.world.nation_get_unit_stats(target_nation, umod.type) -= umod;
767 if(
auto p = inv_id.get_shared_prestige(); p > 0) {
769 for(
auto n : state.world.in_nation) {
770 if(n.get_active_inventions(i_id)) {
779 return state.flag_type_map[
static_cast<size_t>(type)];
783 if(state.world.nation_get_owned_province_count(target_nation) == 0)
784 return flag_type::default_flag;
786 auto gov_type = state.world.nation_get_government_type(target_nation);
788 return flag_type::default_flag;
790 auto id = state.world.national_identity_get_government_flag_type(state.world.nation_get_identity_from_identity_holder(target_nation), gov_type);
794 return flag_type(state.world.government_type_get_flag(gov_type));
798 auto holder = state.world.national_identity_get_nation_from_identity_holder(identity);
802 return flag_type::default_flag;
806 auto rules = state.world.nation_get_combined_issue_rules(owner);
808 state.world.province_set_is_slave(p,
false);
809 bool mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
810 for(
auto pop : state.world.province_get_pop_location(p)) {
811 if(pop.get_pop().get_poptype() == state.culture_definitions.slaves) {
812 pop.get_pop().set_poptype(mine ? state.culture_definitions.laborers : state.culture_definitions.farmers);
815 }
else if(state.world.province_get_is_slave(p) ==
false) {
816 bool found_slave =
false;
817 for(
auto pop : state.world.province_get_pop_location(p)) {
818 if(pop.get_pop().get_poptype() == state.culture_definitions.slaves) {
825 state.world.province_set_is_slave(p2, true);
832 auto old_rules = state.world.nation_get_combined_issue_rules(n_id);
834 state.world.for_each_issue([&](dcon::issue_id i_id) {
835 auto current_opt = state.world.nation_get_issues(n_id, i_id);
836 auto rules_for_opt = state.world.issue_option_get_rules(current_opt);
837 combined |= rules_for_opt;
839 state.world.for_each_reform([&](dcon::reform_id i_id) {
840 auto current_opt = state.world.nation_get_reforms(n_id, i_id);
841 auto rules_for_opt = state.world.reform_option_get_rules(current_opt);
842 combined |= rules_for_opt;
844 state.world.nation_set_combined_issue_rules(n_id, combined);
848 for(
auto p : state.world.nation_get_province_ownership(n_id)) {
849 state.world.province_set_is_slave(p.get_province(),
false);
850 bool mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p.get_province()));
851 for(
auto pop : state.world.province_get_pop_location(p.get_province())) {
852 if(pop.get_pop().get_poptype() == state.culture_definitions.slaves) {
853 pop.get_pop().set_poptype(mine ? state.culture_definitions.laborers : state.culture_definitions.farmers);
859 for(
auto p : state.world.nation_get_province_ownership(n_id)) {
860 for(
auto f : p.get_province().get_factory_location()) {
861 f.get_factory().set_subsidized(
false);
867 state.world.execute_serial_over_nation([&](
auto n_id) {
868 ve::int_vector combined;
869 state.world.for_each_issue([&](dcon::issue_id i_id) {
870 auto current_opt = state.world.nation_get_issues(n_id, i_id);
871 auto rules_for_opt = state.world.issue_option_get_rules(current_opt);
872 combined = combined | rules_for_opt;
874 state.world.for_each_reform([&](dcon::reform_id i_id) {
875 auto current_opt = state.world.nation_get_reforms(n_id, i_id);
876 auto rules_for_opt = state.world.reform_option_get_rules(current_opt);
877 combined = combined | rules_for_opt;
879 state.world.nation_set_combined_issue_rules(n_id, combined);
884 state.world.for_each_pop([&state](dcon::pop_id pid) {
886 float pol_sup = 0.0f;
887 float soc_sup = 0.0f;
888 state.world.for_each_issue_option([&](dcon::issue_option_id i) {
892 auto par = state.world.issue_option_get_parent_issue(i);
907 state.world.for_each_pop([&state](dcon::pop_id pid) {
908 auto ptype = state.world.pop_get_poptype(pid);
910 auto psize = state.world.pop_get_size(pid);
915 static auto buf = state.world.ideology_make_vectorizable_float_buffer();
917 state.world.for_each_ideology([&](dcon::ideology_id iid) {
919 if(state.world.ideology_get_enabled(iid) &&
920 (!state.world.ideology_get_is_civilized_only(iid) || state.world.nation_get_is_civilized(owner))) {
921 auto ptrigger = state.world.pop_type_get_ideology(ptype, iid);
923 auto amount = trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(pid),
924 trigger::to_generic(pid), 0);
925 buf.set(iid, amount);
931 float adjustment_factor = 1.0f / total;
932 state.world.for_each_ideology([&state, pid, adjustment_factor](dcon::ideology_id iid) {
933 auto normalized_amount = buf.get(iid) * adjustment_factor;
939 static auto buf = state.world.issue_option_make_vectorizable_float_buffer();
941 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
942 auto opt = fatten(state.world, iid);
943 auto allow = opt.get_allow();
944 auto parent_issue = opt.get_parent_issue();
945 auto co = state.world.nation_get_issues(owner, parent_issue);
947 if((state.world.nation_get_is_civilized(owner) || state.world.issue_get_issue_type(parent_issue) ==
uint8_t(issue_type::party))
948 && (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())) {
950 if(
auto mtrigger = state.world.pop_type_get_issues(ptype, iid); mtrigger) {
953 buf.set(iid, amount);
959 float adjustment_factor = 1.0f / total;
960 state.world.for_each_issue_option([&state, pid, adjustment_factor](dcon::issue_option_id iid) {
961 auto normalized_amount = buf.get(iid) * adjustment_factor;
970 dcon::technology_id tech_id) {
975 auto base_cost = state.world.technology_get_cost(tech_id);
976 auto availability_year = state.world.technology_get_year(tech_id);
977 auto folder = state.world.technology_get_folder_index(tech_id);
978 auto category = state.culture_definitions.tech_folders[folder].category;
979 auto research_mod = [&]() {
981 case tech_category::army:
982 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::army_tech_research_bonus) + 1.0f;
983 case tech_category::navy:
984 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::navy_tech_research_bonus) + 1.0f;
985 case tech_category::commerce:
986 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::commerce_tech_research_bonus) + 1.0f;
987 case tech_category::culture:
988 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::culture_tech_research_bonus) + 1.0f;
989 case tech_category::industry:
990 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::industry_tech_research_bonus) + 1.0f;
992 case tech_category::military_theory:
993 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::military_theory_tech_research_bonus) + 1.0f;
994 case tech_category::population:
995 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::population_tech_research_bonus) + 1.0f;
996 case tech_category::diplomacy:
997 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::diplomacy_tech_research_bonus) + 1.0f;
998 case tech_category::flavor:
999 return state.world.nation_get_modifier_values(target_nation, sys::national_mod_offsets::flavor_tech_research_bonus) + 1.0f;
1004 auto ol_mod = state.world.nation_get_active_technologies(
1005 state.world.overlord_get_ruler(state.world.nation_get_overlord_as_subject(target_nation)), tech_id)
1006 ? state.defines.tech_factor_vassal
1008 return float(base_cost) * ol_mod * (1.0f / research_mod) *
1009 (1.0f - std::max(0.0f,
float(int32_t(current_year) - availability_year) / state.defines.tech_year_span));
1013 for(
auto n : state.world.in_nation) {
1014 if(n.get_owned_province_count() != 0 && n.get_current_research()) {
1015 if(n.get_active_technologies(n.get_current_research())) {
1016 n.set_current_research(dcon::technology_id{});
1019 if(n.get_research_points() >= cost) {
1020 n.get_research_points() -= cost;
1029 n, dcon::nation_id{}, dcon::nation_id{},
1033 n.set_current_research(dcon::technology_id{});
1047 for(
auto inv : state.world.in_invention) {
1048 auto lim = inv.get_limit();
1049 auto odds = inv.get_chance();
1051 ve::execute_serial_fast<dcon::nation_id>(state.world.nation_size(), [&](
auto nids) {
1052 auto may_discover = !state.world.nation_get_active_inventions(nids, inv)
1053 && (state.world.nation_get_owned_province_count(nids) != 0)
1054 && trigger::evaluate(state, lim, trigger::to_generic(nids), trigger::to_generic(nids), 0);
1056 if(ve::compress_mask(may_discover).v != 0) {
1058 ? trigger::evaluate_additive_modifier(state, odds, trigger::to_generic(nids), trigger::to_generic(nids), 0)
1060 ve::apply([&](dcon::nation_id n, float chance, bool allow_discovery) {
1061 if(allow_discovery) {
1062 auto random = rng::get_random(state, uint32_t(inv.id.index()) << 5 ^ uint32_t(n.index()));
1063 if(int32_t(random % 100) < int32_t(chance)) {
1064 apply_invention(state, n, inv);
1066 notification::post(state, notification::message{
1067 [inv](sys::state& state, text::layout_base& contents) {
1068 text::add_line(state, contents,
"msg_inv_1", text::variable_type::x, state.world.invention_get_name(inv));
1069 ui::invention_description(state, contents, inv, 0);
1072 n, dcon::nation_id{}, dcon::nation_id{},
1073 sys::message_base_type::invention
1077 }, nids, chances, may_discover);
1081 ve::execute_serial_fast<dcon::nation_id>(state.world.nation_size(), [&](
auto nids) {
1082 auto may_not_discover =
1083 state.world.nation_get_active_inventions(nids, inv) || (state.world.nation_get_owned_province_count(nids) == 0);
1084 if(ve::compress_mask(may_not_discover).v != 0) {
1086 ? trigger::evaluate_additive_modifier(state, odds, trigger::to_generic(nids), trigger::to_generic(nids), 0)
1088 ve::apply([&](dcon::nation_id n, float chance, bool block_discovery) {
1089 if(!block_discovery) {
1090 auto random = rng::get_random(state, uint32_t(inv.id.index()) << 5 ^ uint32_t(n.index()));
1091 if(int32_t(random % 100) < int32_t(chance)) {
1092 apply_invention(state, n, inv);
1094 notification::post(state, notification::message{
1095 [inv](sys::state& state, text::layout_base& contents) {
1096 text::add_line(state, contents,
"msg_inv_1", text::variable_type::x, state.world.invention_get_name(inv));
1097 ui::invention_description(state, contents, inv, 0);
1100 n, dcon::nation_id{}, dcon::nation_id{},
1101 sys::message_base_type::invention
1105 }, nids, chances, may_not_discover);
1114 for(
auto cores_of : state.world.national_identity_get_core(old_tag)) {
1115 state.world.try_create_core(cores_of.get_province(), new_tag);
1118 auto core_list = state.world.national_identity_get_core(old_tag);
1119 while(core_list.begin() != core_list.end()) {
1120 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 reload_unlocked_commodities(sys::state &state, dcon::nation_id target_nation)
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
Holds important data about the game world, state, and other data regarding windowing,...