﻿je_south_america_migration = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"

	group = je_group_foreign_affairs

	is_shown_when_inactive = {
		country_is_in_south_america = yes
		any_primary_culture = {
			has_discrimination_trait = european_heritage
		}
	}

	possible = {
		has_technology_researched = civilizing_mission
		country_rank >= rank_value:minor_power
		average_sol >= 10
		is_at_war = no
		is_subject = no
		OR = {
			has_law = law_type:law_racial_segregation
			has_law = law_type:law_cultural_exclusion
			has_law = law_type:law_multicultural
		}
		NOR = {
			has_law = law_type:law_closed_borders
			has_law = law_type:law_isolationism
		}
	}

	immediate = {
		set_variable = {
			name = south_america_incorporated_population
			value = 0
		}
		set_variable = {
			name = south_america_incorporated_states
			value = 0
		}
		every_scope_state = {
			limit = {
				is_incorporated = yes
				state_is_in_south_america = yes
			}
			ROOT = {
				change_variable = {
					name = south_america_incorporated_population
					add = PREV.state_population
				}
				change_variable = {
					name = south_america_incorporated_states
					add = 1
				}
			}
		}
		set_variable = {
			name = south_america_migration_goal
			value = var:south_america_incorporated_states
		}
		change_variable = {
			name = south_america_migration_goal
			multiply = 1500000
		}
		trigger_event = { id = sa_migration.2 popup = yes }
	}

	on_weekly_pulse = {
		effect = {
			set_variable = {
				name = south_america_incorporated_population
				value = 0
			}
			every_scope_state = {
				limit = {
					is_incorporated = yes
					state_is_in_south_america = yes
				}
				ROOT = {
					change_variable = {
						name = south_america_incorporated_population
						add = PREV.state_population
					}
				}
			}
			set_variable = {
				name = south_america_incorporated_states
				value = 0
			}
			every_scope_state = {
				limit = {
					is_incorporated = yes
					state_is_in_south_america = yes
				}
				ROOT = {
					change_variable = {
						name = south_america_incorporated_states
						add = 1
					}
				}
			}
			set_variable = {
				name = south_america_migration_goal
				value = var:south_america_incorporated_states
			}
			change_variable = {
				name = south_america_migration_goal
				multiply = 1500000
			}
		}
	}

	complete = {
		custom_tooltip = {
			text = sa_migration_completion_tt
			trigger_if = {
				limit = { exists = var:south_america_incorporated_population }
				var:south_america_incorporated_population >= var:south_america_migration_goal 
				var:south_america_incorporated_population > 0
				var:south_america_migration_goal > 0
			}
			trigger_else = {
				always = no
			}
		}
	}

	on_complete = {
		trigger_event = { id = sa_migration.3 popup = yes }
		show_as_tooltip = {
			add_modifier = {
				name = populated_southamerica
			}
		}
	}

	invalid = {
		has_variable = cancel_sa_migration_var
	}

	scripted_button = southamerica_migration_button

	weight = 100

	should_be_pinned_by_default = yes
}

je_central_america_migration = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"

	group = je_group_foreign_affairs

	is_shown_when_inactive = {
		capital = {
			OR = {
				region = sr:region_mexico
				region = sr:region_central_america
			}
		}
		any_primary_culture = {
			has_discrimination_trait = european_heritage
		}
	}

	possible = {
		has_technology_researched = civilizing_mission
		country_rank >= rank_value:minor_power
		average_sol >= 10
		is_at_war = no
		is_subject = no
		OR = {
			has_law = law_type:law_racial_segregation
			has_law = law_type:law_cultural_exclusion
			has_law = law_type:law_multicultural
		}
		NOR = {
			has_law = law_type:law_closed_borders
			has_law = law_type:law_isolationism
		}
	}

	immediate = {
		set_variable = {
			name = central_america_incorporated_population
			value = 0
		}
		set_variable = {
			name = central_america_incorporated_states
			value = 0
		}
		every_scope_state = {
			limit = {
				is_incorporated = yes
				OR = {
					region = sr:region_mexico
					region = sr:region_central_america
				}
			}
			ROOT = {
				change_variable = {
					name = central_america_incorporated_population
					add = PREV.state_population
				}
				change_variable = {
					name = central_america_incorporated_states
					add = 1
				}
			}
		}
		set_variable = {
			name = central_america_migration_goal
			value = var:central_america_incorporated_states
		}
		change_variable = {
			name = central_america_migration_goal
			multiply = 1500000
		}
		trigger_event = { id = sa_migration.2 popup = yes }
	}

	on_weekly_pulse = {
		effect = {
			set_variable = {
				name = central_america_incorporated_population
				value = 0
			}
			every_scope_state = {
				limit = {
					is_incorporated = yes
					OR = {
						region = sr:region_mexico
						region = sr:region_central_america
					}
				}
				ROOT = {
					change_variable = {
						name = central_america_incorporated_population
						add = PREV.state_population
					}
				}
			}
			set_variable = {
				name = central_america_incorporated_states
				value = 0
			}
			every_scope_state = {
				limit = {
					is_incorporated = yes
					OR = {
						region = sr:region_mexico
						region = sr:region_central_america
					}
				}
				ROOT = {
					change_variable = {
						name = central_america_incorporated_states
						add = 1
					}
				}
			}
			set_variable = {
				name = central_america_migration_goal
				value = var:central_america_incorporated_states
			}
			change_variable = {
				name = central_america_migration_goal
				multiply = 1000000
			}
		}
	}

	complete = {
		custom_tooltip = {
			text = ca_migration_completion_tt
			var:central_america_incorporated_population >= var:central_america_migration_goal
			var:central_america_incorporated_population > 0
			var:central_america_migration_goal > 0
		}
	}

	on_complete = {
		trigger_event = { id = sa_migration.3 popup = yes }
		show_as_tooltip = {
			add_modifier = {
				name = populated_southamerica
			}
		}
	}

	invalid = {
		has_variable = cancel_sa_migration_var
	}

	scripted_button = southamerica_migration_button

	weight = 100

	should_be_pinned_by_default = yes
}

je_american_west_migration = {
	icon = "gfx/interface/icons/event_icons/event_map.dds"

	group = je_group_foreign_affairs

	is_shown_when_inactive = {
		OR = {
			country_is_in_north_america = yes
			country_is_in_central_america = yes
		}
		any_primary_culture = {
			has_discrimination_trait = european_heritage
		}
		any_scope_state = {
			OR = {
				region = sr:region_pacific_coast
				region = sr:region_great_plains
			}
		}
	}

	possible = {
		has_technology_researched = civilizing_mission
		country_rank >= rank_value:minor_power
		any_scope_state = {
			is_incorporated = yes
			OR = {
				region = sr:region_pacific_coast
				region = sr:region_great_plains
			}
			count >= 3
		}
		average_sol >= 10
		is_at_war = no
		is_subject = no
		OR = {
			has_law = law_type:law_racial_segregation
			has_law = law_type:law_cultural_exclusion
			has_law = law_type:law_multicultural
		}
		NOR = {
			has_law = law_type:law_closed_borders
			has_law = law_type:law_isolationism
		}
	}

	immediate = {
		set_variable = {
			name = american_west_incorporated_population
			value = 0
		}
		set_variable = {
			name = american_west_incorporated_states
			value = 0
		}
		every_scope_state = {
			limit = {
				is_incorporated = yes
				OR = {
					region = sr:region_pacific_coast
					region = sr:region_great_plains
				}
			}
			ROOT = {
				change_variable = {
					name = american_west_incorporated_population
					add = PREV.state_population
				}
				change_variable = {
					name = american_west_incorporated_states
					add = 1
				}
			}
		}
		set_variable = {
			name = american_west_migration_goal
			value = var:american_west_incorporated_states
		}
		change_variable = {
			name = american_west_migration_goal
			multiply = 1500000
		}
		trigger_event = { id = sa_migration.2 popup = yes }
	}

	on_weekly_pulse = {
		effect = {
			set_variable = {
				name = american_west_incorporated_population
				value = 0
			}
			every_scope_state = {
				limit = {
					is_incorporated = yes
					OR = {
						region = sr:region_pacific_coast
						region = sr:region_great_plains
					}
				}
				ROOT = {
					change_variable = {
						name = american_west_incorporated_population
						add = PREV.state_population
					}
				}
			}
			set_variable = {
				name = american_west_incorporated_states
				value = 0
			}
			every_scope_state = {
				limit = {
					is_incorporated = yes
					OR = {
						region = sr:region_pacific_coast
						region = sr:region_great_plains
					}
				}
				ROOT = {
					change_variable = {
						name = american_west_incorporated_states
						add = 1
					}
				}
			}
			set_variable = {
				name = american_west_migration_goal
				value = var:american_west_incorporated_states
			}
			change_variable = {
				name = american_west_migration_goal
				multiply = 1000000
			}
		}
	}

	complete = {
		custom_tooltip = {
			text = wa_migration_completion_tt
			var:american_west_incorporated_population >= var:american_west_migration_goal
			var:american_west_incorporated_population > 0
			var:american_west_migration_goal > 0
		}
	}

	on_complete = {
		trigger_event = { id = sa_migration.3 popup = yes }
		show_as_tooltip = {
			add_modifier = {
				name = populated_southamerica
			}
		}
	}

	invalid = {
		OR = { 
			has_variable = cancel_sa_migration_var
			NOT = {
				any_scope_state = {
					OR = {
						region = sr:region_pacific_coast
						region = sr:region_great_plains
					}
				}
			}
		}
	}

	scripted_button = southamerica_migration_button

	weight = 100

	should_be_pinned_by_default = yes
}