namespace = government_conversion
character_event = {
	#Select which government type you want to convert
	id = government_conversion.1
	title = EVTNAMEgovernment_conversion.0001
	desc = EVTDESCgovernment_conversion.0001
	picture = GFX_evt_war_planning
	border = GFX_event_normal_frame_diplomacy
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTAgovernment_conversion.0001
		#Select feudals
		set_global_flag = selected_feudals
		character_event = { id = government_conversion.2 }
	}
	option = {
		name = EVTOPTBgovernment_conversion.0001
		#Select tribals
		set_global_flag = selected_tribals
		character_event = { id = government_conversion.2 }
	}
	option = {
		name = EVTOPTCgovernment_conversion.0001
		#Select nomads
		set_global_flag = selected_nomads
		character_event = { id = government_conversion.2 }
	}
	option = {
		name = EVTOPTDgovernment_conversion.0001
		#Select all rulers
		set_global_flag = selected_all
		character_event = { id = government_conversion.2 }
	}
}
character_event = {
	#Select which government type you want to convert the selected one into
	id = government_conversion.2
	title = EVTNAMEgovernment_conversion.0002
	desc = EVTDESCgovernment_conversion.0002
	picture = GFX_evt_war_planning
	border = GFX_event_normal_frame_diplomacy
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTAgovernment_conversion.0002
		#Convert rulers into feudals
		if = {
		#Only tribals
			limit = {
				has_global_flag = selected_tribals
			}
			any_playable_ruler = {
				limit = { is_tribal = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
						capital_holding = {
							convert_to = CASTLE
						}
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = castle holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = feudal_government
			}
			any_player = {
				limit = { is_tribal = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
						capital_holding = {
							convert_to = CASTLE
						}
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = castle holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = feudal_government
			}
			clr_global_flag = selected_tribals
		}
		else_if = {
		#Only nomads
			limit = {
				has_global_flag = selected_nomads
			}
			any_playable_ruler = {
				limit = { is_nomadic = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
						capital_holding = {
							convert_to = CASTLE
						}
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = castle holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = feudal_government
			}
			any_player = {
				limit = { is_nomadic = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
						capital_holding = {
							convert_to = CASTLE
						}
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = castle holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = feudal_government
			}
			character_event = { id = government_conversion.3 days = 2 }
			clr_global_flag = selected_nomads
		}
		else_if = {
		#All rulers
			limit = {
				has_global_flag = selected_all
			}
			any_playable_ruler = {
				limit = { government = merchant_republic_government }
				any_demesne_title = {
					destroy_landed_title = THIS
				}
			}
			any_playable_ruler = {
				limit = { is_feudal = no }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
						capital_holding = {
							convert_to = CASTLE
						}
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = castle holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = feudal_government
			}
			any_player = {
				limit = { is_feudal = no }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
						capital_holding = {
							convert_to = CASTLE
						}
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = castle holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = feudal_government
			}
			character_event = { id = government_conversion.3 days = 2 }
			clr_global_flag = selected_all
		}
	}
	option = {
		name = EVTOPTBgovernment_conversion.0002
		#Convert rulers into tribals
		if = {
		#Only feudals
			limit = {
				has_global_flag = selected_feudals
			}
			any_playable_ruler = {
				limit = { is_feudal = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
						capital_holding = {
							convert_to = TRIBAL
						}
					}
					any_province_holding = {
						limit = { NOT = { holding_type = TRIBAL } }
						destroy_settlement = THIS
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = TRIBAL holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = tribal_government
			}
			any_player = {
				limit = { is_feudal = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
						capital_holding = {
							convert_to = TRIBAL
						}
					}
					any_province_holding = {
						limit = { NOT = { holding_type = TRIBAL } }
						destroy_settlement = THIS
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = TRIBAL holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = tribal_government
			}
			clr_global_flag = selected_feudals
		}
		else_if = {
		#Only nomads
			limit = {
				has_global_flag = selected_nomads
			}
			any_playable_ruler = {
				limit = { is_nomadic = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
						capital_holding = {
							convert_to = TRIBAL
						}
					}
					any_province_holding = {
						limit = { NOT = { holding_type = TRIBAL } }
						destroy_settlement = THIS
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = TRIBAL holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = tribal_government
			}
			any_player = {
				limit = { is_nomadic = yes }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
						capital_holding = {
							convert_to = TRIBAL
						}
					}
					any_province_holding = {
						limit = { NOT = { holding_type = TRIBAL } }
						destroy_settlement = THIS
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = TRIBAL holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = tribal_government
			}
			clr_global_flag = selected_nomads
			character_event = { id = government_conversion.6 days = 2 }
		}
		else_if = {
		#All rulers
			limit = {
				has_global_flag = selected_all
			}
			any_playable_ruler = {
				limit = { is_tribal = no }
				if = {
					limit = { government = merchant_republic_government }
					any_demesne_title = {
						destroy_landed_title = THIS
					}
				}
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
						capital_holding = {
							convert_to = TRIBAL
						}
					}
					any_province_holding = {
						limit = { NOT = { holding_type = TRIBAL } }
						destroy_settlement = THIS
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = TRIBAL holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = tribal_government
			}
			any_player = {
				limit = { is_tribal = no }
				any_demesne_province = {
					if = {
						limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
						capital_holding = {
							convert_to = TRIBAL
						}
					}
					any_province_holding = {
						limit = { NOT = { holding_type = TRIBAL } }
						destroy_settlement = THIS
					}
					if = {
						limit = { has_capital = no }
						build_holding = { type = TRIBAL holder = PREV }
						random_province_holding = {
							make_capital_holding = yes
						}
					}
				}
				set_government_type = tribal_government
			}
			clr_global_flag = selected_all
			character_event = { id = government_conversion.6 days = 2 }
		}
	}
	option = {
		name = EVTOPTCgovernment_conversion.0002
		#Convert rulers into nomads
		if = {
		#Only feudals
			limit = {
				has_global_flag = selected_feudals
			}
			any_playable_ruler = {
				limit = { is_feudal = yes }
				capital_holding = {
					convert_to = NOMAD
				}
				any_demesne_province = {
					any_province_holding = { 
						limit = { is_nomadic = no }
						destroy_settlement = THIS 
					}
				}
				set_government_type = nomadic_government
				any_demesne_title = {
					limit = {
						tier = EMPEROR
					}
					destroy_landed_title = THIS
				}
			}
			any_player = {
				limit = { is_nomadic = no }
				capital_holding = {
					convert_to = NOMAD
				}
				any_demesne_province = {
					any_province_holding = { 
						limit = { is_feudal = yes }
						destroy_settlement = THIS 
					}
				}
				set_government_type = nomadic_government
				any_demesne_title = {
					limit = {
						tier = EMPEROR
					}
					destroy_landed_title = THIS
				}
			}
			clr_global_flag = selected_feudals
		}
		else_if = {
		#Only tribals
			limit = {
				has_global_flag = selected_tribals
			}
			any_playable_ruler = {
				limit = { is_tribal = yes }
				capital_holding = {
					convert_to = NOMAD
				}
				any_demesne_province = {
					any_province_holding = { 
						limit = { is_nomadic = no }
						destroy_settlement = THIS 
					}
				}
				set_government_type = nomadic_government
				any_demesne_title = {
					limit = {
						tier = EMPEROR
					}
					destroy_landed_title = THIS
				}
			}
			any_player = {
				limit = { is_tribal = yes }
				capital_holding = {
					convert_to = NOMAD
				}
				any_demesne_province = {
					any_province_holding = { 
						limit = { is_nomadic = no }
						destroy_settlement = THIS 
					}
				}
				set_government_type = nomadic_government
				any_demesne_title = {
					limit = {
						tier = EMPEROR
					}
					destroy_landed_title = THIS
				}
			}
			clr_global_flag = selected_tribals
		}
		else_if = {
		#All rulers
			limit = {
				has_global_flag = selected_all
			}
			any_playable_ruler = {
				limit = { is_nomadic = no }
				capital_holding = {
					convert_to = NOMAD
				}
				any_demesne_province = {
					any_province_holding = { 
						limit = { is_nomadic = no }
						destroy_settlement = THIS 
					}
				}
				set_government_type = nomadic_government
				any_demesne_title = {
					limit = {
						tier = EMPEROR
					}
					destroy_landed_title = THIS
				}
			}
			any_player = {
				limit = { is_nomadic = no }
				capital_holding = {
					convert_to = NOMAD
				}
				any_demesne_province = {
					any_province_holding = { 
						limit = { is_nomadic = no }
						destroy_settlement = THIS 
					}
				}
				set_government_type = nomadic_government
				any_demesne_title = {
					limit = {
						tier = EMPEROR
					}
					destroy_landed_title = THIS
				}
			}
			clr_global_flag = selected_all
		}
	}
	option = {
		name = EVTOPTDgovernment_conversion.0002
	}
}
character_event = {
	id = government_conversion.3
	hide_window = yes

	is_triggered_only = yes
	
	immediate = {
	#Converts anyone who is stubborn, always merchants, some nomads
		any_playable_ruler = {
			if = {
				limit = { government = nomadic_government }
				capital_holding = {
					convert_to = CASTLE
				}
			}
			set_government_type = feudal_government
		}
	}
	option = { name = OK }
}
character_event = {
	id = government_conversion.4
	hide_window = yes

	is_triggered_only = yes
	#Receives event FROM himself and proceeds to send one to player in order to make himself FROM
	immediate = {
		#First FROM is the target himself, since he sent himself an event 
		#Second FROM is the player since they're the one who initiated the targetted decision
		FROMFROM = {
			letter_event = { id = government_conversion.5 }
		}
	}
	option = { name = OK }
}
#Event that player receives
letter_event = {
	id = government_conversion.5
	title = EVTNAMEgovernment_conversion.0005
	desc = EVTDESCgovernment_conversion.0005
	picture = GFX_evt_war_planning
	border = GFX_event_letter_frame_diplomacy

	is_triggered_only = yes
	
	option = {
		name = EVTOPTAgovernment_conversion.0005
		#Convert ruler into feudal
		FROM = {
			if = {
				limit = { government = merchant_republic_government }
				any_demesne_title = {
					destroy_landed_title = THIS
				}
			}
			any_demesne_province = {
				if = {
					limit = { NOT = { capital_holding = { holding_type = CASTLE } } }
					capital_holding = {
						convert_to = CASTLE
					}
				}
				if = {
					limit = { has_capital = no }
					build_holding = { type = castle holder = PREV }
					random_province_holding = {
						make_capital_holding = yes
					}
				}
			}
			set_government_type = feudal_government
		}
	}
	option = {
		name = EVTOPTBgovernment_conversion.0005
		#Convert ruler into tribal
		FROM = {
			if = {
				limit = { government = merchant_republic_government }
				any_demesne_title = {
					destroy_landed_title = THIS
				}
			}
			any_demesne_province = {
				if = {
					limit = { NOT = { capital_holding = { holding_type = TRIBAL } } }
					capital_holding = {
						convert_to = TRIBAL
					}
				}
				any_province_holding = {
					limit = { NOT = { holding_type = TRIBAL } }
					destroy_settlement = THIS
				}
				if = {
					limit = { has_capital = no }
					build_holding = { type = TRIBAL holder = PREV }
					random_province_holding = {
						make_capital_holding = yes
					}
				}
			}
			set_government_type = tribal_government
		}
	}
	option = {
		name = EVTOPTCgovernment_conversion.0005
		#Convert ruler into nomad
		FROM = {
			capital_holding = {
				convert_to = NOMAD
			}
			any_demesne_province = {
				any_province_holding = { 
					limit = { is_nomadic = no }
					destroy_settlement = THIS 
				}
			}
			set_government_type = nomadic_government
		}
	}
	option = {
		name = EVTOPTDgovernment_conversion.0005
	}
}
character_event = {
	id = government_conversion.6
	hide_window = yes

	is_triggered_only = yes
	
	immediate = {
	#Converts anyone who is stubborn, always merchants, some nomads
		any_playable_ruler = {
			limit = { government = nomadic_government }
			any_demesne_province = {
				any_province_holding = { 
					limit = { is_tribal = no }
					destroy_settlement = THIS 
				}
			}
			capital_holding = {
				convert_to = TRIBAL
			}
			set_government_type = tribal_government
		}
	}
	option = { name = OK }
}
character_event = {
	id = government_conversion.7
	hide_window = yes

	is_triggered_only = yes
	
	immediate = {
		any_demesne_province = {
			limit = { has_capital = no }
			build_holding = { type = TRIBAL holder = ROOT }
			any_province_holding = {
				limit = { holding_type = tribal }
				refill_holding_levy = yes
			}
		}
	}
	option = { name = OK }
}