##Note: flavor_sel.2 event: Provinces could get ceded to Seljuks, depending on Oghuz development growth. Areas: Transcaspia, Khiva, Kylylkum possibly

namespace = flavor_sel

# Rise of the Seljuks
country_event = {
	id = flavor_sel.1
	title = "flavor_sel.EVTNAME1"
	desc = "flavor_sel.EVTDESC1"
	picture = COLONIZATION_eventPicture
	
	fire_only_once = yes
	
	major = yes
	trigger = {
		is_subject = no
		is_at_war = no        
		num_of_cities = 10
		NOT = { started_in = 1035.1.1 }
		NOT = { has_global_flag = seljuk_rose_up }
		OR = {
			is_year = 1035 
			OGH = { mission_completed = pontic_steppe_ogh }
		}
		OR = {
			NOT = { exists = SEL }
			overlord_of = SEL
		}
		NOT = { tag = OGH }
		num_of_owned_provinces_with = {
			value = 5
			OR = {
				area = transcaspia_area
				area = mashhad_area
				area = merv_area
				province_id = 2214
				province_id = 4325
			}
			is_capital = no
		}
	}
	
	mean_time_to_happen = {
		months = 12
		modifier = {
			factor = 1
		}
	}
	
	immediate = {
		hidden_effect = { 
			set_global_flag = seljuk_rose_up
			# add cores to SEL
			every_owned_province = {
				limit = {
					is_capital = no
					NOT = { is_core = SEL }
					OR = {
						area = transcaspia_area
						area = mashhad_area
						area = merv_area
						province_id = 2214
						province_id = 4325
					}
				}
				add_core = SEL
			}
		}
	}

	option = { # Go to war
		name = "flavor_sel.1.a"
		ai_chance = {
			factor = 100
			modifier = {
				factor = 0
				OR = {
					is_bankrupt = yes
					war_exhaustion = 10
				}
			}
			 
		}
		
		if = {
			limit = { NOT = { exists = SEL } }
			release = SEL
			hidden_effect = { SEL = { adopt_reform_progress = ROOT } }
		} else = {
			every_owned_province = {
				limit = { is_core = SEL }
				cede_province = SEL
			}
		}
		add_stability = -1
		declare_war_with_cb = {
			who = SEL
			casus_belli = cb_core
			war_goal_province = 4326
		}
		custom_tooltip = flavor_sel.1.tooltip
		hidden_effect = {
			SEL = {
				add_manpower = 75
				add_treasury = 1500
				add_country_modifier = {
					name = rise_of_an_empire_ai_et
					duration = 18250
				}
				capital_scope = {
					build_to_forcelimit = {
						infantry = 0.6
						cavalry = 0.3
					}
				}
				add_adm_power = 250
				add_dip_power = 250
				add_mil_power = 250
				add_army_tradition = 50
				define_general = {
					shock = 5
					fire = 3
					manuever = 4
					siege = 2
				}
			}
			if = { 
				limit = { exists = OGH }
				OGH = { country_event = { id = flavor_sel.2 } }
			}
		}
	}
	option = { # Let them go
		name = "flavor_sel.1.b"
		ai_chance = { 
			factor = 100 
			modifier = {
				factor = 0
				OR = {
					is_bankrupt = no
					NOT = { war_exhaustion = 10 }
				}
			}
		}
		
		if = {
			limit = { NOT = { exists = SEL } }
			release = SEL
			hidden_effect = { SEL = { adopt_reform_progress = ROOT } }
		} else = {
			every_owned_province = {
				limit = { is_core = SEL }
				cede_province = SEL
			}
		}
		add_prestige = -50
		add_stability = -1
		SEL = {
			add_opinion = {
				who = ROOT
				modifier = released_in_peace
			}
			every_owned_province = {
				remove_core = ROOT
			}
		}
		hidden_effect = {
			SEL = {
				add_manpower = 75
				add_treasury = 1500
				add_country_modifier = {
					name = rise_of_an_empire_ai_et
					duration = 18250
				}
				capital_scope = {
					build_to_forcelimit = {
						infantry = 0.6
						cavalry = 0.3
					}
				}
				add_adm_power = 250
				add_dip_power = 250
				add_mil_power = 250
				add_army_tradition = 50
				define_general = {
					shock = 5
					fire = 3
					manuever = 4
					siege = 2
				}
			}
		}
	}
}

# Seljuks seeks for Oghuz support
country_event = {
	id = flavor_sel.2
	title = "flavor_sel.EVTNAME2"
	desc = "flavor_sel.EVTDESC2"
	picture = HORDE_ON_HORSEBACK_eventPicture
	
	is_triggered_only = yes
	
	option = { # help Seljuks
		name = "flavor_sel.2.a"
		ai_chance = {
			factor = 100
			modifier = {
				factor = 0
				OR = {
					is_bankrupt = yes
					war_exhaustion = 10
				}
			}
		}
		add_opinion = {
			who = SEL
			modifier = helped_support_rebels
		}
		SEL = {
			add_opinion = {
				who = ROOT
				modifier = helped_support_rebels
			}
		}
		create_alliance = SEL
		join_all_defensive_wars_of = SEL
		switch_tag = SEL
		OGH = {
			custom_tooltip = flavor_sel.2.tooltip
			hidden_effect = {
				every_owned_province = { 
					limit = { 
						any_neighbor_province = { owned_by = SEL } 
						is_capital = no
					} 
					remove_core = OGH
					add_core = SEL
				}
				every_owned_province = { 
					limit = { 
						is_core = SEL
					} 
					cede_province = SEL
				}
			}
			add_manpower = -10
			add_treasury = -200
		}
		SEL = {
			hidden_effect = {
				if = {
					limit = { ai = no }
					remove_country_modifier = rise_of_an_empire_ai_et
				}
			}
		}
	}
	option = { # stay out of this
		name = "flavor_sel.2.b"
		ai_chance = { 
			factor = 100
			modifier = {
				factor = 0
				OR = {
					is_bankrupt = no
					NOT = { war_exhaustion = 10 }
				}
			}
		}
		every_owned_province = { 
			limit = { 
				any_neighbor_province = { owned_by = SEL } 
			}
			add_core = SEL
		}
		add_prestige = -10
		add_manpower = -5
		SEL = { add_manpower = 5 }
	}
}

# Form Seljuks as Oghuz 
country_event = {
	id = flavor_sel.3
	title = "flavor_sel.EVTNAME3"
	desc = "flavor_sel.EVTDESC3"
	picture = COLONIZATION_eventPicture
	
	fire_only_once = yes
	
	is_triggered_only = yes
	
	trigger = {  
		NOT = { exists = SEL }
	}
	
	option = {
		name = "flavor_sel.3.a"
		ai_chance = {
			factor = 100
		}
		
		change_tag = SEL
		if = {
			limit = {
				NOT = { government_rank = 3 }
			}
			set_government_rank = 3
		}
		set_country_flag = formed_seljuk_flag
		set_global_flag = seljuk_rose_up
		change_government = monarchy
		country_event = { id = ideagroups.1 } #Swap Ideas
		
		4326 = {
			move_capital_effect = yes
			add_core = ROOT
			if = {
				limit = {
					province_has_center_of_trade_of_level = 1
					NOT = { province_has_center_of_trade_of_level = 3 }
				}
				add_center_of_trade_level = 1
			}
			else = {
				limit = {
					NOT = { province_has_center_of_trade_of_level = 1 }
				}
				center_of_trade = 2
			}
		}
		2221 = { add_center_of_trade_level = -1 }
	}
	option = {
		name = "flavor_sel.3.b"
		ai_chance = { 
			factor = 0
		}
		add_prestige = 10
		add_stability = 1
	}
}