
# Set dynamic modifier defaults

JUNO_set_shared_military_branch_defaults = {
	# Army modifiers
	set_variable = { ROOT.JUNO_army_modifier_experience_gain_army_factor = 0.0 }
	set_variable = { ROOT.JUNO_army_modifier_experience_loss_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_experience_gain_army = 0.05 }
	set_variable = { ROOT.JUNO_army_production_speed_arms_factory_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_org_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_operative_slot = 0 }
	set_variable = { ROOT.JUNO_supply_combat_penalties_on_core_factor = 0.00 }
	set_variable = { ROOT.JUNO_modifier_production_speed_supply_node_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_core_defence_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_armor_defence_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_armor_attack_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_attack_speed_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_artillery_attack_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_artillery_defence_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_production_speed_anti_air_building_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_conscription = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_training_time_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_conscription_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_defence_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_army_attack_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_special_forces_cap = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_industrial_capacity_factory = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_special_forces_out_of_supply_factor = 0.00 }
	set_variable = { ROOT.JUNO_army_modifier_extra_marine_supply_grace = 0 }
	set_variable = { ROOT.JUNO_army_modifier_max_planning_factor = 0 }
	set_variable = { ROOT.JUNO_army_modifier_planning_speed_factor = 0 }
	set_variable = { ROOT.JUNO_army_modifier_max_command_power_mult = 0 }
	set_variable = { ROOT.JUNO_army_modifier_command_power_gain_mult = 0 }
	set_variable = { ROOT.JUNO_army_modifier_acclimatization_cold_climate_gain_factor = 0 }
	set_variable = { ROOT.JUNO_army_modifier_acclimatization_hot_climate_gain_factor = 0 }
	
	# Navy Modifiers
	set_variable = { ROOT.JUNO_navy_experience_gain_navy_factor = 0.05 }
	set_variable = { ROOT.JUNO_navy_mines_planting_by_fleets_factor = 0.0 }
	set_variable = { ROOT.JUNO_navy_navy_anti_air_attack_factor = 0.0 }
	set_variable = { ROOT.JUNO_navy_navy_spirit_category_type_cost_factor = 0 }
	set_variable = { ROOT.JUNO_navy_convoy_retreat_speed = 0 }
	set_variable = { ROOT.JUNO_navy_refit_speed = 0 }
	set_variable = { ROOT.JUNO_navy_spotting_chance = 0 }
	set_variable = { ROOT.JUNO_navy_repair_speed_factor = 0 }
	set_variable = { ROOT.JUNO_navy_production_speed_dockyard_factor = 0 }
	set_variable = { ROOT.JUNO_navy_industrial_capacity_dockyard = 0 }
	set_variable = { ROOT.JUNO_navy_extra_marine_supply_grace = 0 }
	set_variable = { ROOT.JUNO_navy_naval_invasion_capacity = 0 }
	set_variable = { ROOT.JUNO_navy_naval_mines_effect_reduction = 0 }
	set_variable = { ROOT.JUNO_navy_experience_gain_navy_unit_factor = 0 }
	set_variable = { ROOT.JUNO_navy_naval_coordination = 0 }
	set_variable = { ROOT.JUNO_navy_naval_equipment_upgrade_xp_cost = 0 }
	set_variable = { ROOT.JUNO_naval_morale_factor = 0 }
	set_variable = { ROOT.JUNO_screening_efficiency = 0 }
	set_variable = { ROOT.JUNO_convoy_escort_efficiency = 0 }
	set_variable = { ROOT.JUNO_navy_capital_ship_defence_factor = 0 }
	set_variable = { ROOT.JUNO_naval_accidents_chance = 0 }
	set_variable = { ROOT.JUNO_navy_screen_defence_factor = 0 }
	#set_variable = { ROOT.JUNO_modifier_production_speed_bunker_factor = 0 }
	set_variable = { ROOT.JUNO_modifier_production_speed_coastal_bunker_factor = 0 }

	# Air modifier
	set_variable = { ROOT.JUNO_airforce_modifier_air_doctrine_cost_factor = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_ace_generation_chance_factor = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_range_factor = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_superiority_efficiency = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_intercept_efficiency = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_mission_xp_gain_factor = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_agility_factor = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_ground_attack_factor = 0.0 }
	set_variable = { ROOT.JUNO_airforce_modifier_experience_gain_air = 0.05 }
	set_variable = { ROOT.JUNO_army_modifier_industrial_capacity_factory_airfoce = 0.00 }
	set_variable = { ROOT.JUNO_airforce_modifier_conscription_factor = 0.00 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_strategic_bomber_bombing_factor = 0.00 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_cas_present_factor = 0.00 }
	#set_variable = { ROOT.JUNO_airforce_modifier_ground_attack_factor = 0.00 }
	set_variable = { ROOT.JUNO_airforce_modifier_air_defence_factor = 0 }

}

JUNO_pick_navy_modifier_tt = {
	IF = {
		limit = {
			original_tag = CHL
		}
		custom_effect_tooltip = CHL_modify_chilean_navy_ns_intro
	}
	ELSE_IF = {
		limit = {
			original_tag = BRA
		}
		custom_effect_tooltip = BRA_modify_brazilian_navy_ns_intro
	}
	ELSE_IF = {
		limit = {
			original_tag = ARG
		}
		custom_effect_tooltip = ARG_modify_argentine_navy_ns_intro			
	}
	ELSE = {
		custom_effect_tooltip = JUNO_modify_south_american_navy_ns_intro			
	}
}

SMB_get_dreadnoughts_from_country = {
	IF = {
		limit = {
			 FROM = {
			 	tag = USA
			 }
		}
		IF = {
			limit = {
				has_dlc =  "Man the Guns"
			}
			create_equipment_variant = {
				name = "New York Class E"					# represents Wyoming (Arkansas) and New York classes
				type = ship_hull_heavy_1
				name_group = USA_BB_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_heavy_battery_1
					fixed_ship_anti_air_slot = ship_anti_air_2
					fixed_ship_fire_control_system_slot = ship_fire_control_system_0
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = heavy_ship_engine_2
					fixed_ship_secondaries_slot = ship_secondaries_1
					fixed_ship_armor_slot = ship_armor_bb_2
					front_1_custom_slot = empty
					mid_1_custom_slot = ship_airplane_launcher_1
					mid_2_custom_slot = ship_secondaries_2
					rear_1_custom_slot = ship_heavy_battery_1
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "New York Class E"
				creator = USA
				name = "New York Class I"
			}
	
			create_equipment_variant = {
				name = "Pensacola Class E"			# Pensacola and Northampton classes
				type = ship_hull_cruiser_1
				name_group = USA_CA_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_medium_battery_1
					fixed_ship_anti_air_slot = ship_anti_air_2
					fixed_ship_fire_control_system_slot = ship_fire_control_system_0
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = cruiser_ship_engine_2
					fixed_ship_secondaries_slot = ship_secondaries_2
					fixed_ship_armor_slot = ship_armor_cruiser_2
					mid_1_custom_slot = ship_medium_battery_1
					mid_2_custom_slot = empty
					rear_1_custom_slot = ship_airplane_launcher_1
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_cruiser_1
				equipment_variant = "Pensacola Class E"
				creator = USA
				name = "Pensacola Class I"
			}
		}
		ELSE = {
			create_equipment_variant = {
				name = "Portland Class E"
				type = heavy_cruiser_1
				upgrades = {
					ship_reliability_upgrade = 2
					ship_engine_upgrade = 2
					ship_armor_upgrade = 2
					ship_gun_upgrade = 2
				}
			}
			create_ship = {
				type = heavy_cruiser_1
				equipment_variant = "Portland Class E"
				creator = USA
				name = "Portland Class I"
			}
			create_ship = {
				type = heavy_cruiser_1
				equipment_variant = "Portland Class E"
				creator = USA
				name = "Portland Class II"
			}
		}
		USA = { 
			set_country_flag = sold_dreadnoughts_to_us@ROOT 
			add_timed_idea = {
				idea = SMB_dreadnought_payments
				days = 365
			}
		}
		ROOT = {
			add_timed_idea = {
				idea = SMB_dreadnought_debt_usa
				days = 365
			}
		}
	}
	ELSE_IF = {
		limit = {
			 FROM = {
			 	tag = ENG
			 }
		}
		IF = {
			limit = {
				has_dlc =  "Man the Guns"
			}
			create_equipment_variant = {
				name = "Renown Class E"
				type = ship_hull_heavy_1
				name_group = ENG_BC_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_heavy_battery_2
					fixed_ship_anti_air_slot = ship_anti_air_2
					fixed_ship_fire_control_system_slot = ship_fire_control_system_1
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = heavy_ship_engine_2
					fixed_ship_secondaries_slot = dp_ship_secondaries_2
					fixed_ship_armor_slot = ship_armor_bc_1
					front_1_custom_slot = ship_anti_air_1
					mid_1_custom_slot = ship_airplane_launcher_1
					mid_2_custom_slot = ship_secondaries_1
					rear_1_custom_slot = empty
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "Renown Class E"
				creator = ENG
				name = "Renown Class I"
			}
			create_equipment_variant = {
				name = "Nelson Clas E"
				type = ship_hull_heavy_1
				name_group = ENG_BB_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_heavy_battery_2
					fixed_ship_anti_air_slot = ship_anti_air_1
					fixed_ship_fire_control_system_slot = ship_fire_control_system_1
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = heavy_ship_engine_1
					fixed_ship_secondaries_slot = ship_secondaries_2
					fixed_ship_armor_slot = ship_armor_bb_2
					front_1_custom_slot = ship_heavy_battery_2
					mid_1_custom_slot = dp_ship_secondaries_1
					mid_2_custom_slot = empty
					rear_1_custom_slot = empty
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "Nelson Class E"
				creator = ENG
				name = "Nelson Class I"
			}	
		}
		ELSE = {
			create_equipment_variant = {
				name = "Nelson Class E"
				type = battleship_1
				parent_version = 0
				upgrades = {
					ship_reliability_upgrade = 3
					ship_engine_upgrade = 2
					ship_armor_upgrade = 3
					ship_gun_upgrade = 3
				}
			}
			create_ship = {
				type = battleship_1
				equipment_variant = "Nelson Class E"
				creator = ENG
				name = "Nelson Class I"
			}	
			create_ship = {
				type = battleship_1
				equipment_variant = "Nelson Class E"
				creator = ENG
				name = "Nelson Class II"
			}	
		}
		ENG = { 
			set_country_flag = sold_dreadnoughts_to_us@ROOT 
			add_timed_idea = {
				idea = SMB_dreadnought_payments
				days = 365
			}
		}
		ROOT = {
			add_timed_idea = {
				idea = SMB_dreadnought_debt_eng
				days = 365
			}
		}
	}
	ELSE_IF = {
		limit = {
			 FROM = {
			 	tag = FRA
			 }
		}
		IF = {
			limit = {
				has_dlc =  "Man the Guns"
			}
			create_equipment_variant = {
				name = "Courbet Class E"
				type = ship_hull_heavy_1
				name_group = FRA_BB_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_heavy_battery_1
					fixed_ship_anti_air_slot = ship_anti_air_1
					fixed_ship_fire_control_system_slot = ship_fire_control_system_0
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = heavy_ship_engine_1
					fixed_ship_secondaries_slot = ship_secondaries_1
					fixed_ship_armor_slot = ship_armor_bb_2
					front_1_custom_slot = ship_heavy_battery_1
					mid_1_custom_slot = ship_secondaries_2
					mid_2_custom_slot = ship_secondaries_2
					rear_1_custom_slot = empty
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "Courbet Class E"
				creator = FRA
				name = "Courbet Class I"
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "Courbet Class E"
				creator = FRA
				name = "Courbet Class II"
			}	
		}
		ELSE = {
			create_equipment_variant = {
				name = "Bretagne Class E"
				type = battleship_1
				upgrades = {
					ship_reliability_upgrade = 1
					ship_armor_upgrade = 1
					ship_gun_upgrade = 1
				}
			}
			create_ship = {
				type = battleship_1
				equipment_variant = "Bretagne Class E"
				creator = FRA
				name = "Bretagne Class I"
			}	
			create_ship = {
				type = battleship_1
				equipment_variant = "Bretagne Class E"
				creator = FRA
				name = "Bretagne Class II"
			}
		}
		FRA = { 
			set_country_flag = sold_dreadnoughts_to_us@ROOT 
			add_timed_idea = {
				idea = SMB_dreadnought_payments
				days = 365
			}	
		}
		ROOT = {
			add_timed_idea = {
				idea = SMB_dreadnought_debt_fra
				days = 365
			}
		}
	}
	ELSE_IF = {
		limit = {
			 FROM = {
			 	tag = ITA
			 }
		}	
		IF = {
			limit = {
				has_dlc =  "Man the Guns"
			}
			create_equipment_variant = {
				name = "Giussano Class E"
				type = ship_hull_cruiser_1
				name_group = ITA_CL_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_light_medium_battery_2
					fixed_ship_anti_air_slot = ship_anti_air_2
					fixed_ship_fire_control_system_slot = ship_fire_control_system_0
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = cruiser_ship_engine_2
					fixed_ship_armor_slot = empty
					mid_1_custom_slot = ship_torpedo_1
					mid_2_custom_slot = ship_airplane_launcher_1
					rear_1_custom_slot = ship_light_medium_battery_2
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_cruiser_1
				equipment_variant = "Giussano Class E"
				creator = ITA
				name = "Giussano Class I"
			}
			create_ship = {
				type = ship_hull_cruiser_1
				equipment_variant = "Giussano Class E"
				creator = ITA
				name = "Giussano Class II"
			}
		}
		ELSE = {
			create_equipment_variant = {
				name = "Giussano Class E"
				type = light_cruiser_1
				upgrades = {
					ship_reliability_upgrade = 1
					ship_engine_upgrade = 1
					ship_gun_upgrade = 1
					ship_anti_air_upgrade = 1
				}
				obsolete = yes
			}
			create_ship = {
				type = light_cruiser_1
				equipment_variant = "Giussano Class E"
				creator = ITA
				name = "Giussano Class I"
			}
			create_ship = {
				type = light_cruiser_1
				equipment_variant = "Giussano Class E"
				creator = ITA
				name = "Giussano Class II"
			}
		}
		ITA = { 
			set_country_flag = sold_dreadnoughts_to_us@ROOT 
			add_timed_idea = {
				idea = SMB_dreadnought_payments
				days = 365
			}
		}
		ROOT = {
			add_timed_idea = {
				idea = SMB_dreadnought_debt_ita
				days = 365
			}
		}
	}
	ELSE_IF = {
		limit = {
			 FROM = {
			 	tag = JAP
			 }
		}
		IF = {
			limit = {
				has_dlc =  "Man the Guns"
			}
			create_equipment_variant = {
				name = "Fuso/Ise Class"
				type = ship_hull_heavy_1
				name_group = JAP_BB_HISTORICAL
				parent_version = 0
				modules = {
					fixed_ship_battery_slot = ship_heavy_battery_1
					fixed_ship_anti_air_slot = ship_anti_air_1
					fixed_ship_fire_control_system_slot = ship_fire_control_system_0
					fixed_ship_radar_slot = empty
					fixed_ship_engine_slot = heavy_ship_engine_1
					fixed_ship_secondaries_slot = ship_secondaries_1
					fixed_ship_armor_slot = ship_armor_bb_1
					front_1_custom_slot = empty
					mid_1_custom_slot = dp_ship_secondaries_1
					mid_2_custom_slot = ship_airplane_launcher_1
					rear_1_custom_slot = ship_heavy_battery_1
				}
				obsolete = yes
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "Fuso/Ise Class"
				creator = JAP
				name = "Fuso/Ise Class I"
			}
			create_ship = {
				type = ship_hull_heavy_1
				equipment_variant = "Fuso/Ise Class"
				creator = JAP
				name = "Fuso/Ise Class II"
			}
		}
		ELSE = {
			create_equipment_variant = {
				name = "Ise Class"
				type = battleship_1
				parent_version = 0
				upgrades = {
					ship_reliability_upgrade = 2
					ship_engine_upgrade = 3
					ship_armor_upgrade = 1
					ship_gun_upgrade = 1
				}
				obsolete = yes
			}
			create_ship = {
				type = battleship_1
				equipment_variant = "Ise Class"
				creator = JAP
				name = "Ise Class I"
			}
			create_ship = {
				type = battleship_1
				equipment_variant = "Ise Class"
				creator = JAP
				name = "Ise Class II"
			}
		}
		JAP = { 
			set_country_flag = sold_dreadnoughts_to_us@ROOT
			add_timed_idea = {
				idea = SMB_dreadnought_payments
				days = 365
			}
		}
		ROOT = {
			add_timed_idea = {
				idea = SMB_dreadnought_debt_jap
				days = 365
			}
		}
	}
	ELSE_IF = {
		limit = {
			 FROM = {
			 	tag = GER
			 }
		}	
		IF = {
			limit = {
				has_dlc =  "Man the Guns"
			}
			create_equipment_variant = {
				name = "Deutschland Class"
				type = ship_hull_cruiser_panzerschiff
				name_group = GER_CA_HISTORICAL
				parent_version = 0
				modules = {
			       	fixed_ship_anti_air_slot = ship_anti_air_1
					fixed_ship_battery_slot = ship_heavy_battery_2
					fixed_ship_secondaries_slot = ship_secondaries_1
					fixed_ship_armor_slot = ship_armor_cruiser_1
					fixed_ship_fire_control_system_slot = ship_fire_control_system_0
					fixed_ship_engine_slot = cruiser_ship_engine_2
					rear_1_custom_slot = ship_torpedo_1
					mid_1_custom_slot = ship_airplane_launcher_1
			   	}
			   	obsolete = yes
			}	
			create_ship = {
				type = ship_hull_cruiser_panzerschiff
				equipment_variant = "Deutschland Class"
				creator = GER
				name = "Deutschland Class I"
			}
			create_ship = {
				type = ship_hull_cruiser_panzerschiff
				equipment_variant = "Deutschland Class"
				creator = GER
				name = "Deutschland Class II"
			}
		}
		ELSE = {
			create_equipment_variant = {
				name = "Deutschland Class"
				type = heavy_cruiser_1
				parent_version = 0
				upgrades = {
					ship_reliability_upgrade = 1
					ship_engine_upgrade = 1
					ship_armor_upgrade = 1
					ship_gun_upgrade = 2
				}
			}
			create_ship = {
				type = heavy_cruiser_1
				equipment_variant = "Deutschland Class"
				creator = GER
				name = "Deutschland Class I"
			}
			create_ship = {
				type = heavy_cruiser_1
				equipment_variant = "Deutschland Class"
				creator = GER
				name = "Deutschland Class II"
			}
		}
		GER = { 
			set_country_flag = sold_dreadnoughts_to_us@ROOT 
			add_timed_idea = {
				idea = SMB_dreadnought_payments
				days = 365
			}
		}
		ROOT = {
			add_timed_idea = {
				idea = SMB_dreadnought_debt_ger
				days = 365
			}
		}
	}
}

SMB_purchase_dreadnoughts_tt_gen = {
	custom_effect_tooltip = SMB_purchase_dreadnought_tt
	custom_effect_tooltip = SMB_purchase_dreadnought_tt_2
	effect_tooltip = {
		add_timed_idea = {
			idea = SMB_dreadnought_debt_usa
			days = 365
		}
	}
}

SMB_naval_jap_advisors_effect = {
	add_to_variable = { JUNO_navy_spotting_chance = 0.05 tooltip = spotting_chance_tt }
	add_to_variable = { JUNO_naval_morale_factor = 0.05 tooltip = naval_morale_factor_tt }
}

SMB_naval_usa_advisors_effect = {
	add_to_variable = { JUNO_navy_navy_anti_air_attack_factor = 0.05 tooltip = navy_anti_air_attack_factor_tt }
	add_to_variable = { JUNO_convoy_escort_efficiency = 0.05 tooltip = convoy_escort_efficiency_tt }
}

SMB_naval_eng_advisors_effect = {
	add_to_variable = { JUNO_navy_capital_ship_defence_factor = 0.05 tooltip = navy_capital_ship_defense_factor_tt }
	add_to_variable = { JUNO_navy_industrial_capacity_dockyard = 0.05 tooltip = industrial_capacity_dockyard_tt }
}

SMB_naval_fra_advisors_effect = {
	add_to_variable = { JUNO_navy_screen_defence_factor = 0.05 tooltip = navy_screen_defence_factor_tt }
}

SMB_naval_ita_advisors_effect = {
	add_to_variable = { JUNO_navy_convoy_retreat_speed = 0.05 tooltip = convoy_retreat_speed_tt }
}

SMB_naval_ger_advisors_effect = {
	add_to_variable = { JUNO_navy_naval_coordination = 0.05 tooltip = naval_coordination_tt }
}

SMB_naval_sov_advisors_effect = {
	add_to_variable = { production_speed_dockyard_factor_tt = 0.05 tooltip = spotting_chance_tt }
}

### Chile

#Important to put HIGHEST first
CHL_mapuche_conflict_level_up = {
	# level 5 not relevant. Cannot go above.
	custom_effect_tooltip = CHL_mapuche_conflict_up_tt
	IF = {
		limit = { 
			has_idea = CHL_the_mapuche_conflict_much_worse 
			NOT = {
				has_country_flag = CHL_no_more_mapuche_conflict
			}
		}
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_much_worse
			add_idea = CHL_the_mapuche_conflict_rebellion
		}
	}
	ELSE_IF = {
		limit = { 
			has_idea = CHL_the_mapuche_conflict_worse 
			NOT = {
				has_country_flag = CHL_no_more_mapuche_conflict
			}
		}
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_worse
			add_idea = CHL_the_mapuche_conflict_much_worse
		}
	}
	ELSE_IF = {
		limit = { 
			has_idea = CHL_the_mapuche_conflict 
			NOT = {
				has_country_flag = CHL_no_more_mapuche_conflict
			}
		}
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict
			add_idea = CHL_the_mapuche_conflict_worse
		}
	}
	ELSE_IF = {
		limit = { 
			has_idea = CHL_the_mapuche_conflict_calmed 
			NOT = {
				has_country_flag = CHL_no_more_mapuche_conflict
			}
		}
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_calmed
			add_idea = CHL_the_mapuche_conflict
		}
	}
	ELSE_IF = {
		limit = { 
			has_idea = CHL_the_mapuche_conflict_near_gone 
			NOT = {
				has_country_flag = CHL_no_more_mapuche_conflict
			}
		}
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_near_gone
			add_idea = CHL_the_mapuche_conflict_calmed
		}		
	}
	ELSE_IF = {
		limit = { 
			NOT = { 
				has_idea = CHL_the_mapuche_conflict_near_gone 
			} 
			NOT = {
				has_country_flag = CHL_no_more_mapuche_conflict
			}
		}
		add_ideas = CHL_the_mapuche_conflict_near_gone
	}
}

#Important to put LOWEST first
CHL_mapuche_conflict_level_down = {
custom_effect_tooltip = CHL_mapuche_conflict_down_tt
	IF = {
		limit = { has_idea = CHL_the_mapuche_conflict_near_gone }
		#Makes the tooltip clearer if player looks at the effect early in the game
		effect_tooltip = {
			swap_ideas = {
				remove_idea = CHL_the_mapuche_conflict_near_gone
				add_idea = CHL_mapuche_conflict_done
			}
		}
		hidden_effect = { remove_ideas = CHL_the_mapuche_conflict_near_gone }
	}
	IF = {
		limit = { has_idea = CHL_the_mapuche_conflict_calmed }
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_calmed
			add_idea = CHL_the_mapuche_conflict_near_gone
		}
	}
	IF = {
		limit = { has_idea = CHL_the_mapuche_conflict }
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict
			add_idea = CHL_the_mapuche_conflict_calmed
		}
	}
	IF = {
		limit = { has_idea = CHL_the_mapuche_conflict_worse }
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_worse
			add_idea = CHL_the_mapuche_conflict
		}
	}
	IF = {
		limit = { has_idea = CHL_the_mapuche_conflict_much_worse }
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_much_worse
			add_idea = CHL_the_mapuche_conflict_worse
		}
	}
	IF = {
		limit = { has_idea = CHL_the_mapuche_conflict_rebellion }
		swap_ideas = {
			remove_idea = CHL_the_mapuche_conflict_rebellion
			add_idea = CHL_the_mapuche_conflict_much_worse
		}
	}
}

#Important to put LOWEST first
CHL_anarchic_society_level_down = {
	IF = {
		limit = {
			OR = {
				has_idea = idea_CHL_near_anarchic_society
				has_idea = idea_CHL_near_anarchic_society_2
				has_idea = idea_CHL_near_anarchic_society_3
				has_idea = idea_CHL_near_anarchic_society_4
			}
		}
		custom_effect_tooltip = CHL_anarchic_society_level_down_tt
	}
	
	IF = {
		limit = {
			has_idea = idea_CHL_near_anarchic_society
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		swap_ideas = {
			remove_idea = idea_CHL_near_anarchic_society
			add_idea = idea_CHL_near_anarchic_society_2
		}	
	}
	ELSE_IF = {
		limit = {
			has_idea = idea_CHL_near_anarchic_society_2
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		swap_ideas = {
			remove_idea = idea_CHL_near_anarchic_society_2
			add_idea = idea_CHL_near_anarchic_society_3
		}
	}
	ELSE_IF = {
		limit = {
			has_idea = idea_CHL_near_anarchic_society_3
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		swap_ideas = {
			remove_idea = idea_CHL_near_anarchic_society_3
			add_idea = idea_CHL_near_anarchic_society_4
		}
	}
	ELSE_IF = {
		limit = {
			has_idea = idea_CHL_near_anarchic_society_4
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		remove_ideas = idea_CHL_near_anarchic_society_4
	}
}

#Important to put HIGHEST first
CHL_anarchic_society_level_up = {
	IF = {
		limit = {
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		custom_effect_tooltip = CHL_anarchic_society_up_tt
	}
	
	IF = {
		limit = {
			has_idea = idea_CHL_near_anarchic_society
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		add_war_support = -0.05
		add_stability = -0.05
		add_political_power = -50
	}
	ELSE_IF = {
		limit = { 
			has_idea = idea_CHL_near_anarchic_society_2 
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		swap_ideas = {
			remove_idea = idea_CHL_near_anarchic_society_2
			add_idea = idea_CHL_near_anarchic_society
		}
	}
	ELSE_IF = {
		limit = { 
			has_idea = idea_CHL_near_anarchic_society_3 
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		swap_ideas = {
			remove_idea = idea_CHL_near_anarchic_society_3
			add_idea = idea_CHL_near_anarchic_society_2
		}
	}
	ELSE_IF = {
		limit = { 
			has_idea = idea_CHL_near_anarchic_society_4 
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		swap_ideas = {
			remove_idea = idea_CHL_near_anarchic_society_4
			add_idea = idea_CHL_near_anarchic_society_3
		}
	}
	ELSE_IF = {
		limit = { 
			NOT = { 
				OR = {
					has_idea = idea_CHL_near_anarchic_society_4 
					has_idea = idea_CHL_near_anarchic_society
				}
			} 
			NOT = {
				has_country_flag = CHL_no_more_anarchy_flag
			}
		}
		add_ideas = idea_CHL_near_anarchic_society_4
	}
}

CHL_one_more_fascist_focus_done = {
	custom_effect_tooltip = CHL_one_more_fascist_focus_done_tt

	IF = {
		limit = {
			has_country_flag = CHL_no_fascist_focuses_done
		}
		clr_country_flag = CHL_no_fascist_focuses_done
		set_country_flag = CHL_1_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_1_fascist_focus_done
		}
		clr_country_flag = CHL_1_fascist_focus_done
		set_country_flag = CHL_2_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_2_fascist_focus_done
		}
		clr_country_flag = CHL_2_fascist_focus_done
		set_country_flag = CHL_3_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_3_fascist_focus_done
		}
		clr_country_flag = CHL_3_fascist_focus_done
		set_country_flag = CHL_4_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_4_fascist_focus_done
		}
		clr_country_flag = CHL_4_fascist_focus_done
		set_country_flag = CHL_5_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_5_fascist_focus_done
		}
		clr_country_flag = CHL_5_fascist_focus_done
		set_country_flag = CHL_6_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_6_fascist_focus_done
		}
		clr_country_flag = CHL_6_fascist_focus_done
		set_country_flag = CHL_7_fascist_focus_done
	}
	ELSE_IF = {
		limit = {
			has_country_flag = CHL_7_fascist_focus_done
		}
		clr_country_flag = CHL_7_fascist_focus_done
		set_country_flag = CHL_8_fascist_focus_done
	}

}

# Anti-Colonialist Resistance (Fascist and Communist CHL)
CHL_set_up_american_resistance_states = {
	#hidden_effect = {
		for_each_scope_loop = {
			array = global.countries 
			IF = {
				limit = {
					# Find countries with cores in america that do not already exist as free or puppeted nations
					exists = no 
					any_core_state = { 
						OR = {
							is_on_continent = south_america 
							is_on_continent = north_america
						} 
						OWNER = {
							NOT = { is_in_faction_with = ROOT }
							NOT = { tag = ROOT }
						}
					}
				}
			
				# add American state of theirs to the array
				every_core_state = {
					limit = {  
						OR = {
							is_on_continent = south_america 
							is_on_continent = north_america
						}	
						has_resistance = yes
						NOT = { # no point adding if already in there
							is_in_array = {
								array = CHL.american_colonial_states_array
								value = THIS 
							}
						}
					}
					add_to_array = { CHL.american_colonial_states_array = THIS }
				}
			}
			
		}
	#}
}

### OPERATIVES
JUNO_create_rosita_serrano_operative = { #INITIAL
	create_operative_leader = {
		name = CHL_rosita_serrano
		GFX = GFX_portrait_CHL_rosita_serrano
		traits = { operative_linguist operative_seducer operative_well_groomed }
		bypass_recruitment = no
		available_to_spy_master = yes
		nationalities = { CHL SPR GER }
	}
}

JUNO_create_osmar_hellmuth_operative = { #INITIAL
	create_operative_leader = {
		name = "Osmar Hellmuth"
		GFX = GFX_portrait_ARG_osmar_hellmuth
		traits = { operative_infiltrator operative_natural_orator operative_well_groomed }
		bypass_recruitment = no
		available_to_spy_master = yes
		nationalities = { ARG GER }
	}
}

### Brazil

BRA_remove_economy_modifier = {
	IF = {
		limit = {
			AND = {
				has_dynamic_modifier = { modifier = BRA_undiversified_economy_modifier }
				check_variable = {
					var = BRA_economy_industrial_capacity_factor
					value = -0.1
					compare = greater_than
				}
				check_variable = {
					var = BRA_economy_production_efficiency_gain_factor
					value = -0.1
					compare = greater_than
				}
				check_variable = {
					var = BRA_economy_production_max_efficiency_factor
					value = -0.1
					compare = greater_than
				}				 						
			}
		}
		remove_dynamic_modifier = { modifier = BRA_undiversified_economy_modifier }
	}
}

BRA_setup_colonized_countries_to_liberate_array = {
	hidden_effect = {
		for_each_scope_loop = {
			array = global.countries
			IF = {
				limit = {
					exists = no #the country does not exist
					any_state = {
						is_core_of = PREV #the state is a core of the non-existing country
						is_on_continent = south_america #the state is in south america
						OWNER = { #the country owning the state
							NOT = { is_in_faction_with = ROOT }
							NOT = { tag = ROOT }
							NOT = { #don't add multiple times
								is_in_array = {
									array = BRA.anti_colonialist_countries_to_liberate
									value = THIS
								}
							}
						}
					}

				}
				add_to_array = { BRA.anti_colonialist_countries_to_liberate = THIS }
			}
		}
		
	}
}


BRA_communist_cw_transfer_chars = {
		BRA = {
			BRA_eurico_gaspar_dutra = {
				set_character_flag = BRA_loyal_to_gov_char
			}
			BRA_mascarenhas_de_morais = {
				set_character_flag = BRA_loyal_to_gov_char
			}
			every_character = {
				limit = {
					has_character_flag = BRA_loyal_to_gov_char
				}
				set_nationality = PREV.PREV
			}
		}
}

BRA_mio_military_factory = {
	random_core_state = {
		limit = {
			free_building_slots = {
				building = arms_factory
				size > 0
				include_locked = yes
			}
			is_owned_and_controlled_by = ROOT
			NOT = {
				has_dynamic_modifier = {
					modifier = BRA_neglected_state_dynamic_modifier
				} 
				OR = {
					state = 961
					state = 962
					state = 963
					state = 964
					state = 965
					state = 966
					state = 967
					state = 968
				}
			}
		}
		add_extra_state_shared_building_slots = 1
		add_building_construction = {
			type = arms_factory
			level = 1
			instant_build = yes
		}
	}
}

USA_add_monroe_doctrine_to_target = {
	IF = {
		limit = {
			USA = {
				exists = yes
				has_idea = USA_monroe_doctrine_enforcer
			}
			has_dlc = "Trial of Allegiance"
			ROOT = {
				NOT = { 
					OR = {
						tag = USA 
						has_idea = USA_monroe_doctrine_idea
					}
				}
				OR = {
					capital_scope = { is_on_continent = south_america }
					capital_scope = { is_on_continent = north_america }
					tag = CUB
					tag = DOM
					tag = HAI
				}
			}
		}
		add_ideas = USA_monroe_doctrine_idea
	}
}

VEN_blockade_countries = {

	if = {
		limit = {

			event_target:blockade_target = {
				NOT = { original_tag = ROOT }
				NOT = { has_government = ROOT }
				NOT = { has_non_aggression_pact_with = ROOT }
				NOT = { has_guaranteed = ROOT }
				ROOT = { NOT = { has_guaranteed = PREV } }
				NOT = { is_embargoed_by = VEN }
				
			}
			
		}
		event_target:blockade_target = {
			VEN = {
				if = {
					limit = { has_dlc = "By Blood Alone"}
					send_embargo = PREV
				}
				add_opinion_modifier = {
					target = PREV
					modifier = VEN_embargoed
				}
				hidden_effect = {
					add_opinion_modifier = {
						target = PREV
						modifier = VEN_embargoed_2
					}
				}
				country_event = {
					id = TOA_ven_blockade.1
					hours = 1
				}
			}
			news_event = {
				id = TOA_ven_blockade.2
				hours = 1
			}
			ROOT = {
				add_to_array = {
					array = ven_countries_that_are_under_embargo
					value = PREV
				}
			}
		} 
		hidden_effect = {
			if = {
				limit = {
					event_target:blockade_target = { is_in_faction = yes }
				}
				every_country = {
					limit = {
						NOT = { is_embargoed_by = VEN }
						event_target:blockade_target = {
							OR = {
								PREV = { is_in_faction_with = PREV }
								PREV = { is_subject_of = PREV }
							}
						}
					}
					ROOT = {
						add_to_array = {
							array = ven_countries_that_are_under_embargo
							value = PREV
						}
					}
					news_event = {
						id = TOA_ven_blockade.2
						hours = 1
					}
					VEN = { 
						if = {
							limit = { has_dlc = "By Blood Alone"}
							send_embargo = PREV
						}
						add_opinion_modifier = {
							target = PREV
							modifier = VEN_embargoed
						}
						add_opinion_modifier = {
							target = PREV
							modifier = VEN_embargoed_2
						}
					}
				}
			}
		}
	}
}

BRA_select_leader_flag = {
	IF = {
		limit = {
			has_country_leader = {
				ruling_only = yes
				character = BRA_armando_de_sales_oliveira
			}
		}
		set_country_flag = BRA_adso_president_flag
	}
	ELSE_IF = {
		IF = {
			limit = {
				has_country_leader = {
					ruling_only = yes
					character = BRA_anisio_teixeira
				}
			}
			set_country_flag = BRA_ansio_president_flag
		}
	}
	ELSE_IF = {
		IF = {
			limit = {
				has_country_leader = {
					ruling_only = yes
					character = BRA_minervino_de_oliveira
				}
			}
			set_country_flag = BRA_mdo_president_flag
		}
	}
	ELSE_IF = {
		IF = {
			limit = {
				has_country_leader = {
					ruling_only = yes
					character = BRA_lindolfo_collor
				}
			}
			set_country_flag = BRA_collor_president_flag
		}
	}
	ELSE_IF = {
		IF = {
			limit = {
				has_country_leader = {
					ruling_only = yes
					character = BRA_eurico_gaspar_dutra
				}
			}
			set_country_flag = BRA_dutra_president_flag
		}
	}
}

BRA_clear_leader_flags = {
	clr_country_flag = BRA_adso_president_flag
	clr_country_flag = BRA_ansio_president_flag
	clr_country_flag = BRA_mdo_president_flag
	clr_country_flag = BRA_collor_president_flag
	clr_country_flag = BRA_dutra_president_flag
}

BRA_clr_country_leader_role = {
	IF = {
		limit = {
			has_country_flag = BRA_adso_president_flag
		}
		remove_country_leader_role = {
			character = BRA_armando_de_sales_oliveira
			ideology = liberalism
		}
	}
	ELSE_IF = {
		limit = {
			has_country_flag = BRA_ansio_president_flag
		}
		remove_country_leader_role = {
			character = BRA_anisio_teixeira
			ideology = liberalism
		}
	}
	ELSE_IF = {
		limit = {
			has_country_flag = BRA_mdo_president_flag
		}
		remove_country_leader_role = {
			character = BRA_minervino_de_oliveira
			ideology = liberalism
		}
	}
	ELSE_IF = {
		limit = {
			has_country_flag = BRA_collor_president_flag
		}
		remove_country_leader_role = {
			character = BRA_lindolfo_collor
			ideology = liberalism
		}
	}
	ELSE_IF = {
		limit = {
			has_country_flag = BRA_dutra_president_flag
		}
		remove_country_leader_role = {
			character = BRA_eurico_gaspar_dutra
			ideology = conservatism
		}
	}
}