From 88ea845bb56b96db20f4722a98149b18631cd1a1 Mon Sep 17 00:00:00 2001 From: wxwisiasdf <39974089+wxwisiasdf@users.noreply.github.com> Date: Mon, 8 Jan 2024 04:57:01 +0000 Subject: [PATCH 1/3] opt: is_core bitfield optimization --- src/gamestate/dcon_generated.txt | 5 ++++ src/gamestate/system_state.cpp | 7 +++++ src/military/military.cpp | 27 ++++++++++---------- src/nations/nations.cpp | 14 +++++----- src/provinces/province.cpp | 6 +++-- src/scripting/triggers.cpp | 44 ++++++++++---------------------- 6 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/gamestate/dcon_generated.txt b/src/gamestate/dcon_generated.txt index a3f880487..5b33e324e 100644 --- a/src/gamestate/dcon_generated.txt +++ b/src/gamestate/dcon_generated.txt @@ -1350,6 +1350,11 @@ object { tag{ save } } + property{ + name{ is_core } + type{array{national_identity_id}{bitfield}} + } + property{ name{ is_colonial } type{ bitfield } diff --git a/src/gamestate/system_state.cpp b/src/gamestate/system_state.cpp index c762cee7c..b044cf0e4 100644 --- a/src/gamestate/system_state.cpp +++ b/src/gamestate/system_state.cpp @@ -3485,6 +3485,13 @@ void state::fill_unsaved_data() { // reconstructs derived values that are not di world.nation_resize_max_building_level(economy::max_building_types); world.province_resize_modifier_values(provincial_mod_offsets::count); + world.province_resize_is_core(world.national_identity_size()); + for(auto p : world.in_province) { + for(auto ni : world.in_national_identity) { + p.set_is_core(ni, false); + } + } + world.for_each_core([&](dcon::core_id id) { world.province_set_is_core(world.core_get_province(id), world.core_get_identity(id), true); }); world.nation_resize_demographics(demographics::size(*this)); world.state_instance_resize_demographics(demographics::size(*this)); diff --git a/src/military/military.cpp b/src/military/military.cpp index b968abc0b..90b724d5c 100644 --- a/src/military/military.cpp +++ b/src/military/military.cpp @@ -630,7 +630,7 @@ int32_t supply_limit_in_province(sys::state& state, dcon::nation_id n, dcon::pro } else if(auto uni_rel = state.world.get_unilateral_relationship_by_unilateral_pair(prov_controller, n); state.world.unilateral_relationship_get_military_access(uni_rel)) { modifier = 2.0f; - } else if(bool(state.world.get_core_by_prov_tag_key(p, state.world.nation_get_identity_from_identity_holder(n)))) { + } else if(state.world.nation_get_identity_from_identity_holder(n) && bool(state.world.province_get_is_core(p, state.world.nation_get_identity_from_identity_holder(n)))) { modifier = 2.0f; } else if(state.world.province_get_siege_progress(p) > 0.0f) { modifier = 2.0f; @@ -2924,8 +2924,8 @@ void implement_war_goal(sys::state& state, dcon::war_id war, dcon::cb_type_id wa if(prov.get_province().get_nation_from_province_ownership() == target) { province::conquer_province(state, prov.get_province(), holder); if((bits & cb_flag::po_remove_cores) != 0) { - auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); - if(find_core) { + state.world.province_set_is_core(prov.get_province(), target_tag, false); + if(auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); find_core) { state.world.delete_core(find_core); } } @@ -2945,8 +2945,8 @@ void implement_war_goal(sys::state& state, dcon::war_id war, dcon::cb_type_id wa if(prov.get_province().get_nation_from_province_ownership() == target) { province::conquer_province(state, prov.get_province(), holder); if((bits & cb_flag::po_remove_cores) != 0) { - auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); - if(find_core) { + state.world.province_set_is_core(prov.get_province(), target_tag, false); + if(auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); find_core) { state.world.delete_core(find_core); } } @@ -2965,8 +2965,8 @@ void implement_war_goal(sys::state& state, dcon::war_id war, dcon::cb_type_id wa if(prov.get_province().get_nation_from_province_ownership() == target) { province::conquer_province(state, prov.get_province(), from); if((bits & cb_flag::po_remove_cores) != 0) { - auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); - if(find_core) { + state.world.province_set_is_core(prov.get_province(), target_tag, false); + if(auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); find_core) { state.world.delete_core(find_core); } } @@ -2986,8 +2986,8 @@ void implement_war_goal(sys::state& state, dcon::war_id war, dcon::cb_type_id wa if(prov.get_province().get_nation_from_province_ownership() == target) { province::conquer_province(state, prov.get_province(), from); if((bits & cb_flag::po_remove_cores) != 0) { - auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); - if(find_core) { + state.world.province_set_is_core(prov.get_province(), target_tag, false); + if(auto find_core = state.world.get_core_by_prov_tag_key(prov.get_province(), target_tag); find_core) { state.world.delete_core(find_core); } } @@ -3018,8 +3018,8 @@ void implement_war_goal(sys::state& state, dcon::war_id war, dcon::cb_type_id wa auto prov = (*target_owns.begin()).get_province(); province::conquer_province(state, prov, from); if((bits & cb_flag::po_remove_cores) != 0) { - auto find_core = state.world.get_core_by_prov_tag_key(prov, target_tag); - if(find_core) { + state.world.province_set_is_core(prov, target_tag, false); + if(auto find_core = state.world.get_core_by_prov_tag_key(prov, target_tag); find_core) { state.world.delete_core(find_core); } } @@ -6395,8 +6395,9 @@ void update_siege_progress(sys::state& state) { auto army_stats = army_controller ? army_controller : ar.get_army().get_army_rebel_control().get_controller().get_ruler_from_rebellion_within(); owner_involved = owner_involved || owner == army_controller; - core_owner_involved = - core_owner_involved || bool(state.world.get_core_by_prov_tag_key(prov, state.world.nation_get_identity_from_identity_holder(army_controller))); + core_owner_involved = core_owner_involved + || (state.world.nation_get_identity_from_identity_holder(army_controller) + && bool(state.world.province_get_is_core(prov, state.world.nation_get_identity_from_identity_holder(army_controller)))); for(auto r : ar.get_army().get_army_membership()) { auto reg_str = r.get_regiment().get_strength(); diff --git a/src/nations/nations.cpp b/src/nations/nations.cpp index ce5c508bb..31e698fa7 100644 --- a/src/nations/nations.cpp +++ b/src/nations/nations.cpp @@ -1691,10 +1691,9 @@ bool can_put_flashpoint_focus_in_state(sys::state& state, dcon::state_instance_i if(fp_focus_nation.get_rank() > uint16_t(state.defines.colonial_rank)) { auto d = si.get_definition(); for(auto p : state.world.state_definition_get_abstract_state_membership(d)) { - if(p.get_province().get_nation_from_province_ownership() == owner) { - if(state.world.get_core_by_prov_tag_key(p.get_province(), fp_ident)) - return true; - } + if(p.get_province().get_nation_from_province_ownership() == owner + && state.world.province_get_is_core(p.get_province(), fp_ident)) + return true; } } @@ -2610,6 +2609,7 @@ void update_pop_acceptance(sys::state& state, dcon::nation_id n) { } } + void liberate_nation_from(sys::state& state, dcon::national_identity_id liberated, dcon::nation_id from) { if(!liberated) return; @@ -2648,8 +2648,8 @@ void release_nation_from(sys::state& state, dcon::national_identity_id liberated nations::create_nation_based_on_template(state, holder, from); } for(auto c : state.world.national_identity_get_core(liberated)) { - if(c.get_province().get_nation_from_province_ownership() == from && - !(state.world.get_core_by_prov_tag_key(c.get_province(), source_tag))) { + if(c.get_province().get_nation_from_province_ownership() == from + && !(state.world.get_core_by_prov_tag_key(c.get_province(), source_tag))) { province::change_province_owner(state, c.get_province(), holder); } } @@ -2661,7 +2661,9 @@ void release_nation_from(sys::state& state, dcon::national_identity_id liberated void remove_cores_from_owned(sys::state& state, dcon::nation_id n, dcon::national_identity_id tag) { for(auto prov : state.world.nation_get_province_ownership(n)) { if(auto core = state.world.get_core_by_prov_tag_key(prov.get_province(), tag); core) { + assert(state.world.province_get_is_core(prov.get_province(), tag)); state.world.delete_core(core); + state.world.province_set_is_core(prov.get_province(), tag, false); } } } diff --git a/src/provinces/province.cpp b/src/provinces/province.cpp index 733062921..1326c4474 100644 --- a/src/provinces/province.cpp +++ b/src/provinces/province.cpp @@ -873,8 +873,7 @@ void change_province_owner(sys::state& state, dcon::province_id id, dcon::nation military::eject_ships(state, id); military::update_blackflag_status(state, id); - state.world.province_set_is_owner_core(id, - bool(state.world.get_core_by_prov_tag_key(id, state.world.nation_get_identity_from_identity_holder(new_owner)))); + state.world.province_set_is_owner_core(id, bool(state.world.province_get_is_core(id, state.world.nation_get_identity_from_identity_holder(new_owner)))); if(old_si) { dcon::province_id a_province; @@ -1528,6 +1527,7 @@ bool state_is_coastal_non_core_nb(sys::state& state, dcon::state_instance_id s) void add_core(sys::state& state, dcon::province_id prov, dcon::national_identity_id tag) { if(tag && prov) { state.world.try_create_core(prov, tag); + state.world.province_set_is_core(prov, tag, true); if(state.world.province_get_nation_from_province_ownership(prov) == state.world.national_identity_get_nation_from_identity_holder(tag)) { state.world.province_set_is_owner_core(prov, true); @@ -1538,7 +1538,9 @@ void add_core(sys::state& state, dcon::province_id prov, dcon::national_identity void remove_core(sys::state& state, dcon::province_id prov, dcon::national_identity_id tag) { auto core_rel = state.world.get_core_by_prov_tag_key(prov, tag); if(core_rel) { + assert(state.world.province_get_is_core(prov, tag)); //in sync state.world.delete_core(core_rel); + state.world.province_set_is_core(prov, tag, false); if(state.world.province_get_nation_from_province_ownership(prov) == state.world.national_identity_get_nation_from_identity_holder(tag)) { state.world.province_set_is_owner_core(prov, false); diff --git a/src/scripting/triggers.cpp b/src/scripting/triggers.cpp index 7b819982e..63c86c45e 100644 --- a/src/scripting/triggers.cpp +++ b/src/scripting/triggers.cpp @@ -1642,7 +1642,7 @@ TRIGGER_FUNCTION(tf_have_core_in_nation_tag) { auto h = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id); return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n) { for(auto p : ws.world.nation_get_province_ownership(h)) { - if(ws.world.get_core_by_prov_tag_key(p.get_province(), n)) + if(ws.world.province_get_is_core(p.get_province(), n)) return true; } return false; @@ -1651,7 +1651,7 @@ TRIGGER_FUNCTION(tf_have_core_in_nation_tag) { TRIGGER_FUNCTION(tf_have_core_in_nation_this) { return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n, dcon::nation_id h) { for(auto p : ws.world.nation_get_province_ownership(h)) { - if(ws.world.get_core_by_prov_tag_key(p.get_province(), n)) + if(ws.world.province_get_is_core(p.get_province(), n)) return true; } return false; @@ -1660,7 +1660,7 @@ TRIGGER_FUNCTION(tf_have_core_in_nation_this) { TRIGGER_FUNCTION(tf_have_core_in_nation_from) { return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n, dcon::nation_id h) { for(auto p : ws.world.nation_get_province_ownership(h)) { - if(ws.world.get_core_by_prov_tag_key(p.get_province(), n)) + if(ws.world.province_get_is_core(p.get_province(), n)) return true; } return false; @@ -1856,11 +1856,7 @@ TRIGGER_FUNCTION(tf_is_core_integer) { auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot)); auto result = ve::apply( [&ws, pid](dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return ws.world.province_get_is_core(pid, t); }, tag); return compare_to_true(tval[0], result); @@ -1869,11 +1865,7 @@ TRIGGER_FUNCTION(tf_is_core_this_nation) { auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot)); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1883,11 +1875,7 @@ TRIGGER_FUNCTION(tf_is_core_this_state) { auto tag = ws.world.nation_get_identity_from_identity_holder(owner); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1911,11 +1899,7 @@ TRIGGER_FUNCTION(tf_is_core_this_pop) { auto tag = ws.world.nation_get_identity_from_identity_holder(owner); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1951,7 +1935,7 @@ TRIGGER_FUNCTION(tf_is_core_state_from_nation) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t))) + if(!(ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1964,7 +1948,7 @@ TRIGGER_FUNCTION(tf_is_core_state_this_nation) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t))) + if(!(ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1977,7 +1961,7 @@ TRIGGER_FUNCTION(tf_is_core_state_this_province) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t))) + if(!(ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1990,7 +1974,7 @@ TRIGGER_FUNCTION(tf_is_core_state_this_pop) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t))) + if(!(ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -2004,7 +1988,7 @@ TRIGGER_FUNCTION(tf_is_core_boolean) { TRIGGER_FUNCTION(tf_is_core_tag) { auto result = ve::apply( [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) { - return bool(ws.world.get_core_by_prov_tag_key(pid, t)); + return bool(ws.world.province_get_is_core(pid, t)); }, to_prov(primary_slot)); return compare_to_true(tval[0], result); @@ -2012,7 +1996,7 @@ TRIGGER_FUNCTION(tf_is_core_tag) { TRIGGER_FUNCTION(tf_is_core_pop_tag) { auto result = ve::apply( [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) { - return bool(ws.world.get_core_by_prov_tag_key(pid, t)); + return bool(ws.world.province_get_is_core(pid, t)); }, ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))); return compare_to_true(tval[0], result); @@ -2021,7 +2005,7 @@ TRIGGER_FUNCTION(tf_is_core_state_tag) { auto result = ve::apply( [&ws, t = trigger::payload(tval[1]).tag_id](dcon::state_instance_id sid) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t))) + if(!(ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; From 39f7cf900ac78c2be8203c92c4238b294604b442 Mon Sep 17 00:00:00 2001 From: wxwisiasdf <39974089+wxwisiasdf@users.noreply.github.com> Date: Mon, 8 Jan 2024 05:28:47 +0000 Subject: [PATCH 2/3] opt fix --- src/gamestate/dcon_generated.txt | 10 +++++----- src/scripting/triggers.cpp | 12 ++---------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/gamestate/dcon_generated.txt b/src/gamestate/dcon_generated.txt index 5b33e324e..66d51e0f3 100644 --- a/src/gamestate/dcon_generated.txt +++ b/src/gamestate/dcon_generated.txt @@ -1350,11 +1350,6 @@ object { tag{ save } } - property{ - name{ is_core } - type{array{national_identity_id}{bitfield}} - } - property{ name{ is_colonial } type{ bitfield } @@ -1502,6 +1497,11 @@ object { name{ former_rebel_controller } type{ dcon::rebel_faction_id } } + + property{ + name{ is_core } + type{array{national_identity_id}{bitfield}} + } } relationship{ diff --git a/src/scripting/triggers.cpp b/src/scripting/triggers.cpp index 63c86c45e..e1ec5e3c2 100644 --- a/src/scripting/triggers.cpp +++ b/src/scripting/triggers.cpp @@ -1908,11 +1908,7 @@ TRIGGER_FUNCTION(tf_is_core_from_nation) { auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot)); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1921,11 +1917,7 @@ TRIGGER_FUNCTION(tf_is_core_reb) { auto rtags = ws.world.rebel_faction_get_defection_target(to_rebel(from_slot)); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), rtags); return compare_to_true(tval[0], result); From 490f6b2245a1de2a5107001176eee70fcfe3610b Mon Sep 17 00:00:00 2001 From: wxwisiasdf <39974089+wxwisiasdf@users.noreply.github.com> Date: Mon, 8 Jan 2024 06:33:35 +0000 Subject: [PATCH 3/3] fix --- src/nations/nations.cpp | 3 ++- src/scripting/triggers.cpp | 38 +++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/nations/nations.cpp b/src/nations/nations.cpp index 31e698fa7..483594258 100644 --- a/src/nations/nations.cpp +++ b/src/nations/nations.cpp @@ -918,6 +918,8 @@ bool has_reform_available(sys::state& state, dcon::nation_id n) { } bool has_decision_available(sys::state& state, dcon::nation_id n) { + if(!n) + return false; for(uint32_t i = state.world.decision_size(); i-- > 0;) { dcon::decision_id did{dcon::decision_id::value_base_t(i)}; if(n != state.local_player_nation || !state.world.decision_get_hide_notification(did)) { @@ -930,7 +932,6 @@ bool has_decision_available(sys::state& state, dcon::nation_id n) { } } } - return false; } diff --git a/src/scripting/triggers.cpp b/src/scripting/triggers.cpp index e1ec5e3c2..2f9a84e57 100644 --- a/src/scripting/triggers.cpp +++ b/src/scripting/triggers.cpp @@ -1642,7 +1642,7 @@ TRIGGER_FUNCTION(tf_have_core_in_nation_tag) { auto h = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id); return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n) { for(auto p : ws.world.nation_get_province_ownership(h)) { - if(ws.world.province_get_is_core(p.get_province(), n)) + if(n && ws.world.province_get_is_core(p.get_province(), n)) return true; } return false; @@ -1651,7 +1651,7 @@ TRIGGER_FUNCTION(tf_have_core_in_nation_tag) { TRIGGER_FUNCTION(tf_have_core_in_nation_this) { return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n, dcon::nation_id h) { for(auto p : ws.world.nation_get_province_ownership(h)) { - if(ws.world.province_get_is_core(p.get_province(), n)) + if(n && ws.world.province_get_is_core(p.get_province(), n)) return true; } return false; @@ -1660,7 +1660,7 @@ TRIGGER_FUNCTION(tf_have_core_in_nation_this) { TRIGGER_FUNCTION(tf_have_core_in_nation_from) { return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n, dcon::nation_id h) { for(auto p : ws.world.nation_get_province_ownership(h)) { - if(ws.world.province_get_is_core(p.get_province(), n)) + if(n && ws.world.province_get_is_core(p.get_province(), n)) return true; } return false; @@ -1856,7 +1856,7 @@ TRIGGER_FUNCTION(tf_is_core_integer) { auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot)); auto result = ve::apply( [&ws, pid](dcon::national_identity_id t) { - return ws.world.province_get_is_core(pid, t); + return t && ws.world.province_get_is_core(pid, t); }, tag); return compare_to_true(tval[0], result); @@ -1865,7 +1865,7 @@ TRIGGER_FUNCTION(tf_is_core_this_nation) { auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot)); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - return ws.world.province_get_is_core(pid, t); + return t && ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1875,7 +1875,7 @@ TRIGGER_FUNCTION(tf_is_core_this_state) { auto tag = ws.world.nation_get_identity_from_identity_holder(owner); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - return ws.world.province_get_is_core(pid, t); + return t && ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1885,11 +1885,7 @@ TRIGGER_FUNCTION(tf_is_core_this_province) { auto tag = ws.world.nation_get_identity_from_identity_holder(owner); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - for(auto c : ws.world.province_get_core(pid)) { - if(c.get_identity() == t) - return true; - } - return false; + return t && ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1899,7 +1895,7 @@ TRIGGER_FUNCTION(tf_is_core_this_pop) { auto tag = ws.world.nation_get_identity_from_identity_holder(owner); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - return ws.world.province_get_is_core(pid, t); + return t && ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1908,7 +1904,7 @@ TRIGGER_FUNCTION(tf_is_core_from_nation) { auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot)); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - return ws.world.province_get_is_core(pid, t); + return t && ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), tag); return compare_to_true(tval[0], result); @@ -1917,7 +1913,7 @@ TRIGGER_FUNCTION(tf_is_core_reb) { auto rtags = ws.world.rebel_faction_get_defection_target(to_rebel(from_slot)); auto result = ve::apply( [&ws](dcon::province_id pid, dcon::national_identity_id t) { - return ws.world.province_get_is_core(pid, t); + return t && ws.world.province_get_is_core(pid, t); }, to_prov(primary_slot), rtags); return compare_to_true(tval[0], result); @@ -1927,7 +1923,7 @@ TRIGGER_FUNCTION(tf_is_core_state_from_nation) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.province_get_is_core(p.get_province(), t))) + if(!(t && ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1940,7 +1936,7 @@ TRIGGER_FUNCTION(tf_is_core_state_this_nation) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.province_get_is_core(p.get_province(), t))) + if(!(t && ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1953,7 +1949,7 @@ TRIGGER_FUNCTION(tf_is_core_state_this_province) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.province_get_is_core(p.get_province(), t))) + if(!(t && ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1966,7 +1962,7 @@ TRIGGER_FUNCTION(tf_is_core_state_this_pop) { auto result = ve::apply( [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.province_get_is_core(p.get_province(), t))) + if(!(t && ws.world.province_get_is_core(p.get_province(), t))) return false; } return true; @@ -1980,7 +1976,7 @@ TRIGGER_FUNCTION(tf_is_core_boolean) { TRIGGER_FUNCTION(tf_is_core_tag) { auto result = ve::apply( [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) { - return bool(ws.world.province_get_is_core(pid, t)); + return t && bool(ws.world.province_get_is_core(pid, t)); }, to_prov(primary_slot)); return compare_to_true(tval[0], result); @@ -1988,7 +1984,7 @@ TRIGGER_FUNCTION(tf_is_core_tag) { TRIGGER_FUNCTION(tf_is_core_pop_tag) { auto result = ve::apply( [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) { - return bool(ws.world.province_get_is_core(pid, t)); + return t && bool(ws.world.province_get_is_core(pid, t)); }, ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))); return compare_to_true(tval[0], result); @@ -1997,7 +1993,7 @@ TRIGGER_FUNCTION(tf_is_core_state_tag) { auto result = ve::apply( [&ws, t = trigger::payload(tval[1]).tag_id](dcon::state_instance_id sid) { for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) { - if(!(ws.world.province_get_is_core(p.get_province(), t))) + if(!(t && ws.world.province_get_is_core(p.get_province(), t))) return false; } return true;