namespace = colonial_nation_cn

colonial_nation_cn.1 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		#transfer states

		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200	
			limit ={
				OR = {
					region = sr:region_indonesia
					region = sr:region_oceania
					region = sr:region_indochina
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SIS }
				}
				create_country = {
					tag = SIS
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = { 
					create_diplomatic_pact = {
						country = c:SIS
						type = chartered_company
					}
				}
				c:SIS = { 
					trigger_event = { id = colonial_nation_cn.93 } 
				}
			}
			set_state_owner = c:SIS			
		}

		c:SIS = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}

	}
}

colonial_nation_cn.2 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
		
			limit ={
				OR = {
					region = sr:region_north_china
					region = sr:region_south_china
					region = sr:region_japan
					region = sr:region_manchuria
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SCI }
				}
				create_country = {
					tag = SCI
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SCI
						type = chartered_company
					}
				}
				c:SCI = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SCI
		}

		c:SCI = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.3 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
		
			limit ={
				OR = {
					region = sr:region_east_siberia
					region = sr:region_west_siberia
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SSB }
				}
				create_country = {
					tag = SSB
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SSB
						type = chartered_company
					}
				}
				c:SSB = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SSB
		}
		c:SSB = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.4 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
		
			limit ={
				OR = {
					region = sr:region_anatolia
					region = sr:region_arabic
					region = sr:region_persia
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SAB }
				}
				create_country = {
					tag = SAB
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SAB
						type = chartered_company
					}
				}
				c:SAB = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SAB
		}
		c:SAB = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.5 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
		
			limit ={
				OR = {
					region = sr:region_madras
					region = sr:region_bengal
					region = sr:region_bombay
					region = sr:region_punjab
					region = sr:region_central_india
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SID }
				}
				create_country = {
					tag = SID
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SID
						type = chartered_company
					}
				}
				c:SID = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SID
			
		}
		c:SID = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.6 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
			limit ={
				OR = {
					region = sr:region_senegal
					region = sr:region_niger
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SWF }
				}
				create_country = {
					tag = SWF
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SWF
						type = chartered_company
					}
				}
				c:SWF = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SWF
		}
		c:SWF = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.7 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
		
			limit ={
				OR = {
					region = sr:region_congo
					region = sr:region_southern_africa
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SSF }
				}
				create_country = {
					tag = SSF
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SSF
						type = chartered_company
					}
				}
				c:SSF = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SSF
		}
		c:SSF = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.8 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
			limit ={
				OR = {
					region = sr:region_zanj
					region = sr:region_ethiopia
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SEF }
				}
				create_country = {
					tag = SEF
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SEF
						type = chartered_company
					}
				}
				c:SEF = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SEF
		}
		c:SEF = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.9 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
			limit ={
				OR = {
					region = sr:region_nile_basin
					region = sr:region_north_africa
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SNF }
				}
				create_country = {
					tag = SNF
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SNF
						type = chartered_company
					}
				}
				c:SNF = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SNF
		}
		c:SNF = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.10 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
			limit ={
				OR = { 
					region = sr:region_north_germany
					region = sr:region_south_germany
					region = sr:region_england
					region = sr:region_iberia
					region = sr:region_france
					region = sr:region_occitania
					region = sr:region_rhine
					region = sr:region_italy	
					region = sr:region_poland
					region = sr:region_danubia
					region = sr:region_balkans
					region = sr:region_baltic	
					region = sr:region_russia
					region = sr:region_dnieper
					region = sr:region_north_sea_coast
					region = sr:region_caucasus
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SRP }
				}
				create_country = {
					tag = SRP
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SRP
						type = chartered_company
					}
				}
				c:SRP = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SRP
		}
		c:SRP = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.11 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
	
			limit ={
				OR = { 
					region = sr:region_canada
					region = sr:region_new_england
					region = sr:region_pacific_coast
					region = sr:region_great_plains
					region = sr:region_the_midwest
					region = sr:region_dixie
					region = sr:region_mexico
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SNM }
				}
				create_country = {
					tag = SNM
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SNM
						type = chartered_company
					}
				}
				c:SNM = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SNM
		}
		c:SNM = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.12 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
			limit ={
				OR = { 
					region = sr:region_brazil	
					region = sr:region_la_plata
					region = sr:region_andes	
					region = sr:region_gran_colombia	
					region = sr:region_central_america
					region = sr:region_caribbean
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SSM }
				}
				create_country = {
					tag = SSM
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SSM
						type = chartered_company
					}
				}
				c:SSM = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SSM
		}
		c:SSM = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.13 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		ordered_scope_state = {
			order_by = gdp
			check_range_bounds = no
			max = 200
			limit ={
				OR = { 
					region = sr:region_central_asia
					region = sr:region_himalayas
				}
				NOT = {
					any_scope_building = {
						is_building_group = bg_canals
						is_under_construction = yes
					}
				}
			}
			if = {
				limit = {
					NOT = { exists = c:SCE }
				}
				create_country = {
					tag = SCE
					origin = root
					state = this
					on_created = {
						set_country_type = colonial
						activate_law = law_type:law_presidential_republic
					}
				}
				root = {
					create_diplomatic_pact = {
						country = c:SCE
						type = chartered_company
					}
				}
				c:SCE = { trigger_event = { id = colonial_nation_cn.93 } }
			}
			set_state_owner = c:SCE	
		}
		c:SCE = {
			set_variable = cn_nations
			every_scope_state = {
				limit = {
					is_incorporated = no
					is_treaty_port = no
					is_split_state = no
				}
				set_state_type = incorporated
			}
		}
	}
}

colonial_nation_cn.89 = {
	type = country_event
	hidden = yes

	trigger = {
		is_player = yes
	}

	immediate = {
		if = {
			limit = {
				exists = c:SIS
				c:SIS = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SIS }
				}
				trigger_event = { id = colonial_nation_cn.1 }
			}
			trigger_event = { id = colonial_nation_cn.1 }
		}
		if = {
			limit = {
				exists = c:SCI
				c:SCI = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SCI }
				}
				trigger_event = { id = colonial_nation_cn.2 }
			}
			trigger_event = { id = colonial_nation_cn.2 }
		}
		if = {
			limit = {
				exists = c:SSB
				c:SSB = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SSB }
				}
				trigger_event = { id = colonial_nation_cn.3 }
			}
			trigger_event = { id = colonial_nation_cn.3 }
		}
		if = {
			limit = {
				exists = c:SAB
				c:SAB = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SAB }
				}
				trigger_event = { id = colonial_nation_cn.4 }
			}
			trigger_event = { id = colonial_nation_cn.4 }
		}
		if = {
			limit = {
				exists = c:SID
				c:SID = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SID }
				}
				trigger_event = { id = colonial_nation_cn.5 }
			}
			trigger_event = { id = colonial_nation_cn.5 }
		}
		if = {
			limit = {
				exists = c:SWF
				c:SWF = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SWF }
				}
				trigger_event = { id = colonial_nation_cn.6 }
			}
			trigger_event = { id = colonial_nation_cn.6 }
		}
		if = {
			limit = {
				exists = c:SSF
				c:SSF = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SSF }
				}
				trigger_event = { id = colonial_nation_cn.7 }
			}
			trigger_event = { id = colonial_nation_cn.7 }
		}
		if = {
			limit = {
				exists = c:SEF
				c:SEF = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SEF }
				}
				trigger_event = { id = colonial_nation_cn.8 }
			}
			trigger_event = { id = colonial_nation_cn.8 }
		}
		if = {
			limit = {
				exists = c:SNF
				c:SNF = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SNF }
				}
				trigger_event = { id = colonial_nation_cn.9 }
			}
			trigger_event = { id = colonial_nation_cn.9 }
		}
		if = {
			limit = {
				exists = c:SRP
				c:SRP = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SRP }
				}
				trigger_event = { id = colonial_nation_cn.10 }
			}
			trigger_event = { id = colonial_nation_cn.10 }
		}
		if = {
			limit = {
				exists = c:SNM
				c:SNM = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SNM }
				}
				trigger_event = { id = colonial_nation_cn.11 }
			}
			trigger_event = { id = colonial_nation_cn.11 }
		}
		if = {
			limit = {
				exists = c:SSM
				c:SSM = {
					is_subject_of = root
				}
			}
			every_country = {
				limit = {
					has_variable = cn_nations
					NOT = { this = c:SSM }
				}
				trigger_event = { id = colonial_nation_cn.12 }
			}
			trigger_event = { id = colonial_nation_cn.12 }
		}
	}
}

colonial_nation_cn.93 = {
	type = country_event
	hidden = yes

	trigger = {
	}

	immediate = {
		remove_primary_culture = cu:korean
		root.overlord = {
			every_primary_culture ={
				root = {
					add_primary_culture = prev
				}
			}					
		}
		set_state_religion = root.overlord.religion
		activate_law = law_type:law_colonial_resettlement
		activate_law = law_type:law_no_schools
		activate_law = law_type:law_no_health_system 
		activate_law = law_type:law_no_home_affairs
		activate_law = law_type:law_no_police
		activate_law = law_type:law_no_social_security
		if = {
			limit = {
				NOT = {
					any_scope_pop ={
						pop_has_primary_culture = yes
					}
				}
			}
			random_primary_culture ={
				save_temporary_scope_as = target_culture
			}
			every_scope_pop = {
				limit = {
					is_pop_type = aristocrats
				}
				change_pop_culture = { target = scope:target_culture value = 0.01 }
			}
		}
		every_scope_character = {
			kill_character = yes
		}
		
	}
}

colonial_nation_cn.99 = {
	type = state_event
	hidden = yes

	trigger = {
		owner = { 
			is_ai = yes
			is_subject = yes
			overlord = { is_player = yes }
		}
		is_incorporated = no
		is_treaty_port = no
		is_split_state = no
	}

	immediate = {
		set_state_type = incorporated
	}
}