country_decisions = {

	moroccan_nation = {
		major = yes
		potential = {
			normal_or_historical_nations = yes
			was_never_end_game_tag_trigger = yes
			NOT = { has_country_flag = formed_morocco_flag }
			OR = {
				ai = no
				is_playing_custom_nation = no
			}
			OR = {
				is_free_or_tributary_trigger = yes
				ai = no
			}
			NOT = { tag = MOR }
			NOT = { tag = TUN }
			NOT = { tag = ALG }
			NOT = { tag = PAP }
			NOT = { tag = HLR }
			
			NOT = { tag = AMH }		#New added in MMETR, prevents Almohads forming Morocco in a cycle for free prestige
			
			OR = {
				primary_culture = moroccan
				primary_culture = berber
			}
			OR = {
				ai = no
				AND = {
					ai = yes
					num_of_cities = 5	#Any big Moroccan tag will try to usurp the title
				}
			}
			is_colonial_nation = no
			OR = {
				is_former_colonial_nation = no
				AND = {
					is_former_colonial_nation = yes
					ai = no
				}
			}
		}
		provinces_to_highlight = {
			OR = {
				province_id = 343 #Fez
				province_id = 344 #Marrekech
				AND = {
                    province_id = 348
                    ROOT = { NOT = { owns_core_province = 346 } }
                }
                AND = {
                    province_id = 346
                    ROOT = { NOT = { owns_core_province = 348 } }
                }
			}
			OR = {
				NOT = { owned_by = ROOT }
				NOT = { is_core = ROOT }
			}
		}
		allow = {
			NOT = { exists = MOR }
			is_at_war = no
			is_free_or_tributary_trigger = yes
			is_nomad = no
			owns_core_province = 343 	#Fez
			owns_core_province = 344 	#Marrekech
			344 = {						#Marrekech
				is_state = yes
			}
			OR = {
				owns_core_province = 348 #Sus
				owns_core_province = 346 #Tafilalt
			}
		}
		effect = {
			344 = {
				move_capital_effect = yes
			}
			change_tag = MOR
			swap_non_generic_missions = yes
			remove_non_electors_emperors_from_empire_effect = yes
			if = {
				limit = {
					NOT = { government_rank = 2 }
				}
				set_government_rank = 2
			}
			tafilalt_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = MOR
			}
			sus_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = MOR
			}
			marrekesh_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = MOR
			}
			western_morocco_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = MOR
			}
			southern_morocco_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = MOR
			}
			northern_morocco_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = MOR
			}
			add_prestige = 25
			if = {
				limit = { NOT = { has_reform = celestial_empire } }
				change_government_to_monarchy = yes #Desert tribes settling down, theocracies become monarchies.
				#set_legacy_government = despotic_monarchy
			}
			change_primary_culture = moroccan
			set_country_flag = formed_morocco_flag
			if = {
				limit = { 
					has_custom_ideas = no
					NOT = { has_idea_group = MOR_ideas }
				}
				country_event = { id = ideagroups.1 } #Swap Ideas
			}
		}
		ai_will_do = {
			factor = 1
		}
		ai_importance = 400
	}
	
	algiers_nation = {
		major = yes
		potential = {
			normal_or_historical_nations = yes
			was_never_end_game_tag_trigger = yes
			NOT = { has_country_flag = formed_algiers_flag }
			OR = {
				ai = no
				is_playing_custom_nation = no
			}
			OR = {
				is_free_or_tributary_trigger = yes
				ai = no
			}
			NOT = { tag = MOR }
			NOT = { tag = TUN }
			NOT = { tag = TLC }
			NOT = { tag = ALG }
			NOT = { tag = PAP }
			NOT = { tag = HLR }
			OR = {
				primary_culture = algerian
				AND = {
					primary_culture = berber
					capital_scope = { area = algiers_area }
				}
				AND = {
					primary_culture = berber
					capital_scope = { area = hautes_plaines_area }
				}
				AND = {
					primary_culture = berber
					capital_scope = { area = ouled_nail_area }
				}
				AND = {
					primary_culture = berber
					capital_scope = { area = kabylia_area }
				}
				AND = {
					primary_culture = berber
					capital_scope = { area = north_saharan_area }
				}
			}
			OR = {
				ai = no
				AND = {
					NOT = { exists = ALG }
					ai = yes
					num_of_cities = 5
				}
			}
			is_colonial_nation = no
			OR = {
				is_former_colonial_nation = no
				AND = {
					is_former_colonial_nation = yes
					ai = no
				}
			}
		}
		provinces_to_highlight = {
			OR = {
				province_id = 338
				province_id = 2461
				AND = {
                    province_id = 336
                    ROOT = { NOT = { owns_core_province = 339 } }
                }
                AND = {
                    province_id = 339
                    ROOT = { NOT = { owns_core_province = 336 } }
                }
			}
			OR = {
				NOT = { owned_by = ROOT }
				NOT = { is_core = ROOT }
			}
		}
		allow = {
			NOT = { exists = ALG }
			is_at_war = no
			is_free_or_tributary_trigger = yes
			is_nomad = no
			owns_core_province = 2461 	#Dahra
			owns_core_province = 338 	#Algiers
			338 = {						#Algiers
				is_state = yes
			}
			OR = {
				owns_core_province = 336 #Tlemcen
				owns_core_province = 339 #Kabylia
			}
		}
		effect = {
			338 = {
				move_capital_effect = yes
			}
			change_tag = ALG
			remove_non_electors_emperors_from_empire_effect = yes
			if = {
				limit = {
					NOT = { government_rank = 2 }
				}
				set_government_rank = 2
			}
			change_primary_culture = algerian
			algiers_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = ALG
			}
			north_saharan_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = ALG
			}
			hautes_plaines_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = ALG
			}
			ouled_nail_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = ALG
			}
			kabylia_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = ALG
			}
			if = {
				limit = {
					is_tribal = yes	#Desert tribes settling down.
				}
				change_government_to_monarchy = yes
				#set_legacy_government = despotic_monarchy
			}
			add_prestige = 25
			set_country_flag = formed_algiers_flag
			if = {
				limit = {
					has_custom_ideas = no
					NOT = { has_idea_group = berber_ideas }
				}
				country_event = { id = ideagroups.1 } #Swap Ideas
			}
		}
		ai_will_do = {
			factor = 1
		}
		ai_importance = 400
	}
	
	tunisian_nation = {
		major = yes
		potential = {
			normal_or_historical_nations = yes
			was_never_end_game_tag_trigger = yes
			NOT = { has_country_flag = formed_tunisia_flag }
			OR = {
				ai = no
				is_playing_custom_nation = no
			}
			OR = {
				is_free_or_tributary_trigger = yes
				ai = no
			}
			NOT = { tag = MOR }
			NOT = { tag = TUN }
			NOT = { tag = ALG }
			NOT = { tag = PAP }
			NOT = { tag = HLR }
			OR = {
				primary_culture = tunisian
				primary_culture = berber
			}
			OR = {
				ai = no
				AND = {
					NOT = { exists = TUN }
					ai = yes
					num_of_cities = 5
				}
			}
			is_colonial_nation = no
			OR = {
				is_former_colonial_nation = no
				AND = {
					is_former_colonial_nation = yes
					ai = no
				}
			}
		}
		provinces_to_highlight = {
			OR = {
				province_id = 341
				province_id = 2473
				AND = {
                    province_id = 2454
                    ROOT = { NOT = { owns_core_province = 354 } }
                }
                AND = {
                    province_id = 354
                    ROOT = { NOT = { owns_core_province = 2454 } }
                }
			}
			OR = {
				NOT = { owned_by = ROOT }
				NOT = { is_core = ROOT }
			}
		}
		allow = {
			NOT = { exists = TUN }
			is_at_war = no
			is_free_or_tributary_trigger = yes
			is_nomad = no
			owns_core_province = 2473	#Souss
			owns_core_province = 341 	#Tunis
			341 = {						#Tunis
				is_state = yes
			}
			OR = {
				owns_core_province = 2454 #Kef
				owns_core_province = 354 #Tripoli
			}
		}
		effect = {
			341 = {
				move_capital_effect = yes
			}
			change_tag = TUN
			swap_non_generic_missions = yes
			remove_non_electors_emperors_from_empire_effect = yes
			if = {
				limit = {
					NOT = { government_rank = 2 }
				}
				set_government_rank = 2
			}
			change_primary_culture = tunisian
			tunisia_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = TUN
			}
			if = {
				limit = {
					is_tribal = yes
				}
				change_government_to_monarchy = yes #Desert tribes settling down.
				#set_legacy_government = despotic_monarchy
			}
			add_prestige = 25
			set_country_flag = formed_tunisia_flag
			if = {
				limit = {
					has_custom_ideas = no
					NOT = { has_idea_group = TUN_ideas }
				}
				country_event = { id = ideagroups.1 } #Swap Ideas
			}
		}
		ai_will_do = {
			factor = 1
		}
		ai_importance = 400
	}
	
	tripoli_nation = {
		major = yes
		potential = {
			normal_or_historical_nations = yes
			was_never_end_game_tag_trigger = yes
			NOT = { has_country_flag = formed_tripoli_flag }
			OR = {
				ai = no
				is_playing_custom_nation = no
			}
			OR = {
				is_free_or_tributary_trigger = yes
				ai = no
			}
			NOT = { tag = MOR }
			NOT = { tag = TUN }
			NOT = { tag = TLC }
			NOT = { tag = ALG }
			NOT = { tag = TRP }
			NOT = { tag = PAP }
			NOT = { tag = HLR }
			NOT = { tag = LBY }
			OR = {
				primary_culture = tunisian
				primary_culture = berber
			}
			capital_scope = {
				OR = {
					area = tripolitania_area
					area = fezzan_area
				}
			}
			is_colonial_nation = no
			OR = {
				is_former_colonial_nation = no
				AND = {
					is_former_colonial_nation = yes
					ai = no
				}
			}
		}
		provinces_to_highlight = {
			OR = {
				province_id = 354
				province_id = 2451
				AND = {
                    province_id = 355
                    ROOT = { NOT = { owns_core_province = 353 } }
                }
                AND = {
                    province_id = 353
                    ROOT = { NOT = { owns_core_province = 355 } }
                }
			}
			OR = {
				NOT = { owned_by = ROOT }
				NOT = { is_core = ROOT }
			}
		}
		allow = {
			NOT = { exists = TRP }
			is_at_war = no
			is_free_or_tributary_trigger = yes
			is_nomad = no
			owns_core_province = 2451 	#Thubaqt
			owns_core_province = 354	#Tripoli
			354 = {						#Tripoli
				is_state = yes
			}
			OR = {
				owns_core_province = 355 #Sirt
				owns_core_province = 353 #Djerba
			}
		}
		effect = {
			354 = {
				move_capital_effect = yes
			}
			change_tag = TRP
			remove_non_electors_emperors_from_empire_effect = yes
			if = {
				limit = {
					NOT = { government_rank = 2 }
				}
				set_government_rank = 2
			}
			change_primary_culture = tunisian
			tripolitania_area = {
				limit = {
					NOT = { owned_by = ROOT }
				}
				add_permanent_claim = TRP
			}
			if = {
				limit = {
					is_tribal = yes #Desert tribes settling down.
				}
				change_government_to_monarchy = yes
				#set_legacy_government = despotic_monarchy
			}
			add_prestige = 25
			set_country_flag = formed_tripoli_flag
			if = {
				limit = {
					has_custom_ideas = no
					NOT = { has_idea_group = berber_ideas }
				}
				country_event = { id = ideagroups.1 } #Swap Ideas
			}
		}
		ai_will_do = {
			factor = 1
		}
		#ai_importance = 400
	}
	
}
