# Author(s): AngriestBird, Alexander Markelov, Niko Holkko, WiggeW # Effect: update_nato_dirty_variable # Purpose: Bumps the dirty flag used to signal that NATO-dependent UI/state needs a refresh, rolling over at 10000 to avoid unbounded growth. update_nato_dirty_variable = { if = { limit = { check_variable = { global.NATO_dirty_update_var < 10000 } } add_to_variable = { global.NATO_dirty_update_var = 1 } } else = { set_variable = { global.NATO_dirty_update_var = 1 } } } NATO_auto_ratify_accession = { if = { limit = { has_country_flag = NATO_Accession_Voting } for_each_scope_loop = { array = global.nato_members if = { limit = { exists = yes has_idea = NATO_member # The AI cannot toggle the automation GUI, so without this it could # only ratify by winning a political-power contest for the decision, # and accession needs every living member to succeed at that. OR = { is_ai = yes has_country_flag = MD_auto_ratify_nato_accession } NOT = { has_country_flag = NATO_Ratified_@ROOT } } set_temp_variable = { automation_available_pp = { value = political_power subtract = automation_pp_reserve } } if = { limit = { OR = { is_ai = yes check_variable = { var = automation_available_pp value = 20 compare = greater_than_or_equals } } } log = "[GetDateText]: [THIS.GetName]: Automatic NATO accession ratification target: [ROOT.GetName]" add_political_power = -20 set_country_flag = NATO_Ratified_@ROOT # Unconditional: the dirty variable is global and drives the # ratification tracker, so a human watching it has to see an AI # member's ratification too. The decision path already does this. update_nato_dirty_variable = yes } } } } } # Effect: NATO_join # Purpose: Admits ROOT to NATO full membership (mutual opinion boost, military access, NATO_member idea, tech sharing, faction join) when can_join_NATO passes; otherwise routes eligible non-members to Major Non-NATO Ally status. NATO_join = { if = { limit = { can_join_NATO = yes } for_each_scope_loop = { array = global.nato_members # Mutual opinion boost. add_opinion_modifier = { target = PREV modifier = NATO_member_modifier } reverse_add_opinion_modifier = { target = PREV modifier = NATO_member_modifier } # Add military access. if = { limit = { NOT = { has_military_access_to = PREV } } diplomatic_relation = { country = PREV relation = military_access active = yes } } PREV = { if = { limit = { NOT = { has_military_access_to = PREV } } diplomatic_relation = { country = PREV relation = military_access active = yes } } } } add_ideas = NATO_member add_to_tech_sharing_group = NATO_Tech_Share random_scope_in_array = { array = global.nato_members limit = { is_faction_leader = yes } add_to_faction = ROOT } if = { limit = { has_idea = Major_Non_NATO_Ally } remove_ideas = Major_Non_NATO_Ally } custom_effect_tooltip = NATO_join_tt hidden_effect = { news_event = { id = NATO.8 hours = 6 } } if = { limit = { original_tag = SOV } set_global_flag = NATO_CSTO_treaty_adandoned clear_variable = global.var_nato_inf_count clear_variable = global.var_csto_inf_count clear_variable = global.var_nato_tank_count clear_variable = global.var_csto_tank_count } } else = { # Only Europe, North America and the Caucasus (plus scripted exceptions) join NATO. # Everyone else gets Major Non-NATO Ally status instead. if = { limit = { NOT = { has_idea = Major_Non_NATO_Ally } } NATO_major_non_nato_ally_join = yes } } } # Effect: NATO_join_via_event # Purpose: Fires the NATO.14 join event from the USA faction leader (or any NATO faction leader if USA is ineligible) rather than applying membership directly, so a USA that has left NATO cannot grant membership it no longer holds. Ineligible applicants fall through to Major Non-NATO Ally. NATO_join_via_event = { if = { limit = { can_join_NATO = yes } if = { limit = { USA = { has_idea = NATO_member is_faction_leader = yes } } USA = { country_event = NATO.14 } } else = { random_scope_in_array = { array = global.nato_members limit = { is_faction_leader = yes } country_event = NATO.14 } } } else = { # Ineligible applicants are routed to Major Non-NATO Ally instead of full membership. if = { limit = { NOT = { has_idea = Major_Non_NATO_Ally } } NATO_major_non_nato_ally_join = yes } } } # Effect: NATO_leave # Purpose: Strips NATO membership and tech sharing, transfers faction leadership to another member if ROOT is the leader, tears down the mutual opinion/access web, and fires the departure news event. NATO_leave = { set_temp_variable = { faction_goal_refresh_transferred_leader = 0 } if = { limit = { has_idea = NATO_member } remove_ideas = NATO_member remove_from_tech_sharing_group = NATO_Tech_Share # If we are the faction leader, transfer leadership before leaving if = { limit = { is_faction_leader = yes } # Find another NATO member to transfer leadership to random_other_country = { limit = { has_idea = NATO_member is_in_faction_with = ROOT } # Transfer faction leadership set_faction_leader = yes save_event_target_as = faction_goal_transferred_leader set_temp_variable = { ROOT.faction_goal_refresh_transferred_leader = 1 } } } leave_faction = yes if = { limit = { check_variable = { faction_goal_refresh_transferred_leader = 1 } } hidden_effect = { event_target:faction_goal_transferred_leader = { faction_goal_refresh_all_caches = yes } } } for_each_scope_loop = { array = global.nato_members if = { limit = { has_idea = NATO_member } # Nato members are mad you left. add_opinion_modifier = { target = PREV modifier = left_nato } # Remove nato opinion boost. remove_opinion_modifier = { target = PREV modifier = NATO_aspirant } remove_opinion_modifier = { target = PREV modifier = NATO_member_modifier } PREV = { remove_opinion_modifier = { target = PREV modifier = NATO_member_modifier } remove_opinion_modifier = { target = PREV modifier = NATO_aspirant } } # Remove military access. diplomatic_relation = { country = PREV relation = military_access active = no } PREV = { diplomatic_relation = { country = PREV relation = military_access active = no } } } } custom_effect_tooltip = NATO_leave_tt hidden_effect = { news_event = { id = NATO.6 hours = 6 } } } } # Effect: NATO_promote_new_leader # Purpose: Hands NATO leadership to a surviving member when the current leader can no longer lead (the USA collapsing). Prefers a non-collapsed major member, falls back to any eligible member, then announces the transition via NATO.20. NATO_promote_new_leader = { if = { limit = { any_of_scopes = { array = global.nato_members is_subject = no is_major = yes NOT = { has_country_flag = collapsed_nation } is_faction_leader = no } } random_scope_in_array = { array = global.nato_members limit = { is_subject = no is_major = yes NOT = { has_country_flag = collapsed_nation } is_faction_leader = no } set_faction_leader = yes save_event_target_as = new_nato_leader } } else = { random_scope_in_array = { array = global.nato_members limit = { is_subject = no NOT = { has_country_flag = collapsed_nation } is_faction_leader = no } set_faction_leader = yes save_event_target_as = new_nato_leader } } if = { limit = { country_exists = event_target:new_nato_leader } hidden_effect = { event_target:new_nato_leader = { faction_goal_refresh_all_caches = yes } news_event = { id = NATO.20 hours = 6 } } } } # Effect: NATO_CSTO_calculate_number_of_batallions # Purpose: Tallies European-based infantry and tank battalions across both global.nato_members and global.CSTO_member; when either side exceeds the 1000-infantry / 400-tank limits it flags the European members as in breach and activates NATO_CSTO_breach_mission on the faction leader. NATO_CSTO_calculate_number_of_batallions = { set_variable = { global.var_nato_inf_count = 0 } set_variable = { global.var_csto_inf_count = 0 } set_variable = { global.var_nato_tank_count = 0 } set_variable = { global.var_csto_tank_count = 0 } for_each_loop = { array = global.nato_members var:v = { if = { limit = { capital_scope = { is_on_continent = europe } } add_to_variable = { var = global.var_nato_inf_count value = { value = 0 add = num_battalions_with_type@Mech_Air_Inf_Bat add = num_battalions_with_type@Mech_Marine_Bat add = num_battalions_with_type@Arm_Air_Inf_Bat add = num_battalions_with_type@Arm_Marine_Bat add = num_battalions_with_type@Mech_Inf_Bat add = num_battalions_with_type@Arm_Inf_Bat } } add_to_variable = { var = global.var_nato_tank_count value = { value = 0 add = num_battalions_with_type@armor_Bat add = num_battalions_with_type@L_arm_Bat } } } } } if = { limit = { OR = { check_variable = { global.var_nato_inf_count > 1000 } check_variable = { global.var_nato_tank_count > 400 } } } for_each_loop = { array = global.nato_members value = v var:v = { if = { limit = { capital_scope = { is_on_continent = europe } } set_country_flag = NATO_CSTO_agreement_breach_warning } } } random_scope_in_array = { array = global.nato_members limit = { is_faction_leader = yes } activate_mission = NATO_CSTO_breach_mission } } for_each_loop = { array = global.CSTO_member value = v var:v = { add_to_variable = { var = global.var_csto_inf_count value = { value = 0 add = num_battalions_with_type@Mech_Air_Inf_Bat add = num_battalions_with_type@Mech_Marine_Bat add = num_battalions_with_type@Arm_Air_Inf_Bat add = num_battalions_with_type@Arm_Marine_Bat add = num_battalions_with_type@Mech_Inf_Bat add = num_battalions_with_type@Arm_Inf_Bat } } add_to_variable = { var = global.var_csto_tank_count value = { value = 0 add = num_battalions_with_type@armor_Bat add = num_battalions_with_type@L_arm_Bat } } } } if = { limit = { OR = { check_variable = { global.var_csto_inf_count > 1000 } check_variable = { global.var_csto_tank_count > 400 } } } for_each_loop = { array = global.CSTO_member value = v var:v = { if = { limit = { capital_scope = { is_on_continent = europe } } set_country_flag = NATO_CSTO_agreement_breach_warning } } } random_scope_in_array = { array = global.CSTO_member limit = { is_faction_leader = yes } activate_mission = NATO_CSTO_breach_mission } } } # Effect: NATO_major_non_nato_ally_join # Purpose: Grants Major Non-NATO Ally status (idea, flag, Major_Non_NATO_Ally_Share tech group) and applies the matching opinion modifier mutually with all current NATO members. NATO_major_non_nato_ally_join = { add_ideas = Major_Non_NATO_Ally set_country_flag = Major_Non_NATO_Ally add_to_tech_sharing_group = Major_Non_NATO_Ally_Share for_each_scope_loop = { array = global.nato_members tooltip = TT_ALL_NATO_MEMBER_NATIONS_GAIN add_opinion_modifier = { target = PREV modifier = Major_Non_NATO_Ally } reverse_add_opinion_modifier = { target = PREV modifier = Major_Non_NATO_Ally } } } # Effect: NATO_major_non_nato_ally_leave # Purpose: Mirror of NATO_major_non_nato_ally_join — revokes the idea, flag and Major_Non_NATO_Ally_Share tech group, and clears the mutual opinion modifiers the join granted. Sweeps every country rather than global.nato_members so members that have since left NATO are cleaned up too. NATO_major_non_nato_ally_leave = { remove_ideas = Major_Non_NATO_Ally clr_country_flag = Major_Non_NATO_Ally remove_from_tech_sharing_group = Major_Non_NATO_Ally_Share every_other_country = { limit = { has_opinion_modifier = Major_Non_NATO_Ally } remove_opinion_modifier = { target = PREV modifier = Major_Non_NATO_Ally } hidden_effect = { PREV = { remove_opinion_modifier = { target = PREV modifier = Major_Non_NATO_Ally } } } } } # Effect: NATO_coup_response_pulse # Purpose: Fires the NATO-coup dilemma (department_of_state.233) on the current NATO faction leader when ROOT (the coup mastermind) successfully overthrows a NATO member (FROM). Picks the first eligible leader from global.nato_members so the content works whether the USA still leads NATO or another member has taken over. Sets a 365-day per-leader cooldown so the same leader isn't spammed by repeated coups. Skips ROOT if it is democratic, is the USA itself, or is not one of the designated hostile sponsors (CHI / SOV / PER). Skips entirely when NATO is disabled by game rule or has no members yet. NATO_coup_response_pulse = { if = { limit = { NOT = { has_global_flag = GAME_RULE_nato_disabled } check_variable = { global.nato_members^num > 0 } FROM = { has_idea = NATO_member NOT = { original_tag = USA } } NOT = { has_government = democratic } NOT = { original_tag = USA } OR = { original_tag = CHI original_tag = SOV original_tag = PER } any_of_scopes = { array = global.nato_members is_faction_leader = yes exists = yes has_idea = NATO_member NOT = { has_country_flag = collapsed_nation } NOT = { has_country_flag = nato_coup_cooldown } } } FROM = { save_event_target_as = nato_coup_victim } save_event_target_as = nato_coup_aggressor random_scope_in_array = { array = global.nato_members limit = { is_faction_leader = yes exists = yes has_idea = NATO_member NOT = { has_country_flag = collapsed_nation } NOT = { has_country_flag = nato_coup_cooldown } } set_country_flag = { flag = nato_coup_cooldown days = 365 value = 1 } country_event = { id = department_of_state.233 days = 3 } } } }