decisions = {

	hold_a_epic_tournament  = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			NOR = {
				has_character_modifier = epic_tournament
				has_character_flag = epic_tournament
			}
			OR = {
				religion_group = christian
				religion_group = jewish_group
				religion_group = zoroastrian_group
			}
			independent = yes
			NOT = { is_nomadic = yes }
			OR = {
				gender_equality_trigger = yes
				NOT = { is_female = yes	}
			}
			OR = {
				tier = king
				tier = emperor 
			}
			location = {
				owner = { character = ROOT }
			}
		}
		allow = {
			war = no
			prisoner = no
			in_command = no
			NOT = { is_inaccessible_trigger = yes }
			age = 16
			prestige = 500
			wealth = 200
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
		}
		effect = {
			add_character_modifier = {
				name = epic_tournament
				years = 100
				hidden = yes
			}
			set_character_flag = do_not_disturb
			clr_character_flag = tournament_has_ended
			hidden_tooltip = { character_event = { id = 70999 days = 300 } } # Safety catch flag clearing
			wealth = -200
			prestige = 100
			character_event = { id = 70033 tooltip = "tournament_invite" }
			hidden_tooltip = {
				clr_character_flag = tournament_has_ended
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = {
					OR = {
						wealth = 1000
						scaled_wealth = 3.0
					}
				}
			}
		}
	}
	
	buy_indulgence_for_sins = {
		only_playable = yes
		potential = {
			religion = catholic
			age = 16
			demesne_size = 1
			NOT = { has_character_flag = ask_for_indulgence }
		}
		allow = {
			prisoner = no
			NOT = { trait = incapable }
			NOT = { is_inaccessible_trigger = yes }
			scaled_wealth = 1.0
			wealth = 25
			is_heretic = no
		}
		effect = {
			set_character_flag = ask_for_indulgence
			rightful_religious_head_scope = {
				character_event = { id = 39250 days = 5 random = 12 tooltip = "indulgence_ask" }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					NOT = { scaled_wealth = 10.0 }
					piety = 0
				}
			}
		}
	}

	issue_declaration_of_repentance = {
		only_playable = yes
		potential = {
			is_playable = yes
			religion = catholic
			age = 16
			demesne_size = 1
			NOT = { has_character_flag = ask_for_repentance }
			rightful_religious_head_scope = {
				ROOT = {
					excommunicated_for = PREV
				}
			}
		}
		allow = {
			scaled_wealth = 2.0
			is_heretic = no
		}
		effect = {
			set_character_flag = ask_for_repentance
			rightful_religious_head_scope = {
				character_event = { id = 39252 days = 5 random = 12 tooltip = "repentance_ask" }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = {
					scaled_wealth = 10.0
				}
			}
		}
	}
	
	demand_liege_title = {
		only_playable = yes
		is_high_prio = yes
		potential = {
			ai = no
			is_playable = yes
			has_ambition = obj_gain_any_title
			liege = {
				NOT = { character = ROOT }
			}
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
		}
		allow = {
			prestige = 60
			liege = {
				has_regent = no
				NOT = { has_opinion_modifier = { who = ROOT modifier = requested_land } }
				demesne_size = 3
				any_demesne_title = {
					can_be_given_away = yes
					tier = COUNT
					NOT = { location = { is_capital = yes } }
				}
			}
		}
		effect = {
			prestige = -60
			liege = {
				opinion = {
					who = ROOT
					years = 2
					modifier = requested_land
				}
				random_demesne_title = {
					limit = {
						can_be_given_away = yes
						tier = COUNT
						NOT = { location = { is_capital = yes } }
					}
					save_event_target_as = vassal_wanted_title
				}
			}
			custom_tooltip = {
				text = demand_liege_title_tooltip
				hidden_tooltip = { liege = { letter_event = { id = 63041 days = 4 } } } # "vassal_request_events.txt"
			}
		}
		ai_will_do = {
			factor = 0 # The AI is limited to the similar event 63040
		}
	}
	
	sadaqah_saddka  = {
		only_playable = yes
		potential = {
			is_playable = yes
			ai = no
			religion_group = muslim
			is_adult = yes
			demesne_size = 1
			NOT = { has_character_flag = voluntary_charity }
			rightful_religious_head_scope = {	
				NOT = {
					character = ROOT
				}
				NOT = {
					has_opinion_modifier = { who = ROOT modifier = opinion_sadaqah }
				}
			}
		}
		allow = {
			scaled_wealth = 1.0
			is_heretic = no
		}
		effect = {
			set_character_flag = voluntary_charity
			scaled_wealth = -0.25
			piety = 25
			rightful_religious_head_scope = {
				character_event = { id = 31000 days = 5 random = 12 tooltip = "sadaqah_voluntary_charity" }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				ai = yes
				OR = {
					NOT = { scaled_wealth = 10.0 }
					piety = 0
				}
			}
		}
	}

	hold_a_furusiyya  = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			independent = yes
			NOR = {
				has_character_flag = epic_tournament_furusiyya
				has_character_modifier = epic_tournament_furusiyya
			}
			religion_group = muslim
			OR = {
				gender_equality_trigger = yes
				NOT = { is_female = yes	}
			}
			OR = {
				tier = king
				tier = emperor 
			}
			location = {
				owner = { character = ROOT }
			}
		}
		allow = {
			war = no
			in_command = no
			prisoner = no
			NOT = { is_inaccessible_trigger = yes }
			age = 16
			prestige = 500
			wealth = 200
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
		}
		effect = {
			set_character_flag = do_not_disturb
			add_character_modifier = {
				name = epic_tournament_furusiyya
				years = 100
				hidden = yes
			}
			clr_character_flag = tournament_has_ended_furusiyya
			hidden_tooltip = { character_event = { id = 88999 days = 300 } } # Safety catch flag clearing
			wealth = -200
			prestige = 100
			decadence = -5
			character_event = { id = 88283 tooltip = "furusiyya_invite" }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = {
					OR = {
						wealth = 1000
						scaled_wealth = 3.0
					}
				}
			}
		}
	}
	
	restore_roman_empire = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			has_dlc = "Legacy of Rome"
			has_landed_title = e_byzantium
			religion_group = christian
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			NOT = { has_global_flag = rome_restored }
		}
		allow = {
			primary_title = { title = e_byzantium }
			prestige = 3000
			completely_controls = d_latium
			completely_controls = d_venice
			completely_controls = d_ferrara
			completely_controls = d_sicily
			completely_controls = d_genoa
			completely_controls = d_capua
			completely_controls = d_apulia
			completely_controls = d_thrace
			completely_controls = d_antioch
			completely_controls = d_jerusalem
			completely_controls = d_alexandria
			completely_controls = d_athens
			completely_controls = d_tunis
			completely_controls = d_croatia
		}
		effect = {
			set_global_flag = rome_restored
			narrative_event = { id = LoR.20 tooltip = EVTTOOLTIPLoR.20 }
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	mend_great_schism = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			has_dlc = "Legacy of Rome"
			is_playable = yes
			is_adult = yes
			prisoner = no
			independent = yes
			NOT = { trait = incapable }
			OR = {
				religion = orthodox
				religion = paulician
				religion = monothelite
				religion = iconoclast
			}
			OR = {
				has_landed_title = e_byzantium
				has_landed_title = e_roman_empire
			}
			is_heretic = no
			NOT = { has_global_flag = schism_mended }
			k_papal_state = {
				holder_scope = {
					is_heretic = no # If the Pope (and thus Catholicism) is heretical, mending the schism is no longer possible
				}
			}
		}
		allow = {
			piety = 2000
			religion_authority = 0.9
			completely_controls = c_byzantion
			b_hagiasophia = {
				custom_tooltip = { # Custom tooltip to shorten the in-game tooltip
					text = mend_the_schism_holder_religion
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = paulician
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_antiocheia
			b_antiocheia = {
				custom_tooltip = {
					text = mend_the_schism_holder_religion
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = paulician
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_jerusalem
			b_jerusalem = {
				custom_tooltip = {
					text = mend_the_schism_holder_religion
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = paulician
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_alexandria
			b_alexandria = {
				custom_tooltip = {
					text = mend_the_schism_holder_religion
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = paulician
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_roma
			b_roma = {
				custom_tooltip = {
					text = mend_the_schism_holder_religion
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = paulician
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
		}
		effect = {
			narrative_event = { id = LoR.210 tooltip = EVTTOOLTIPLoR.210}
			set_global_flag = schism_mended
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	claim_constantinople = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_nomadic = no
			is_playable = yes
			has_dlc = "Legacy of Rome"
			has_landed_title = e_byzantium
			NOT = { has_landed_title = c_byzantion }
			any_realm_lord = { 
				ai = yes
				has_landed_title = c_byzantion 
			}
		}
		allow = {
			NOT = { has_landed_title = c_byzantion }
			any_realm_lord = { 
				has_landed_title = c_byzantion 
			}
		}
		effect = {
			ROOT = {
				c_byzantion = {
					usurp_title_plus_barony_if_unlanded_and_vassals = PREV
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	make_rome_capital = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			ai = no
			has_dlc = "Legacy of Rome"
			has_landed_title = e_roman_empire
			capital_scope = {
				NOT = { province_id = 333 }
			}
			any_realm_lord = { 
				ai = yes
				has_landed_title = c_roma 
			}
			any_realm_lord = { 
				ai = yes
				has_landed_title = b_tivoli
			}
		}
		allow = {
			has_landed_title = e_roman_empire
			any_realm_lord = { has_landed_title = c_roma }
		}
		effect = {
			custom_tooltip = {
				text = rome_capital
				hidden_tooltip = {
					b_tivoli = { province_capital = yes }
					ROOT = {
						b_tivoli = {
							usurp_title = PREV
						}
					}
					#b_roma = { set_name = Lateran }
					b_tivoli = { 
						set_name = Rome 
						ROOT = { capital = PREV }
					}
				}
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	petition_doge_for_tp = {
		only_playable = yes
		is_high_prio = yes
		potential = {
			is_playable = yes
			is_merchant_republic = no
			is_patrician = yes
			liege = { is_merchant_republic = yes }
			NOT = { has_character_flag = petition_doge_for_tp_taken }
			OR = {
				liege = {
					any_vassal = {
						is_patrician = yes
						num_of_trade_post_diff = {
							character = ROOT
							value = 10
						}
					}
				}
				AND = {
					NOT = { num_of_trade_posts = 1 }
					liege = {
						any_vassal = {
							is_patrician = yes
							num_of_trade_posts = 10
						}
					}
				}
			}
		}
		allow = {
			liege = {
				opinion = {
					who = ROOT
					value = 25
				}
			}
		}
		effect = {
			set_character_flag = petition_doge_for_tp_taken
			liege = {
				letter_event = { id = REP.500 days = 5 tooltip = EVTTOOLTIP_REP_500 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	usurp_tp = {
		only_playable = yes
		is_high_prio = yes
		potential = {
			is_playable = yes
			is_merchant_republic = yes
			is_patrician = yes
			NOT = { has_character_flag = usurp_tp_taken }
			OR = {
				any_vassal = {
					is_patrician = yes
					num_of_trade_post_diff = {
						character = ROOT
						value = 10
					}
				}
				AND = {
					NOT = { num_of_trade_posts = 1 }
					any_vassal = {
						is_patrician = yes
						num_of_trade_posts = 10
					}
				}
			}
		}
		allow = {
			is_merchant_republic = yes
		}
		effect = {
			set_character_flag = usurp_tp_taken
			if = {
				limit = {
					num_of_trade_posts = 1
					any_vassal = {
						is_patrician = yes
						num_of_trade_post_diff = {
							character = ROOT
							value = 10
						}
					}
				}
				random_vassal = {
					limit = {
						is_patrician = yes
						num_of_trade_post_diff = {
							character = ROOT
							value = 10
						}
					}
					set_character_flag = target_patrician_doge
					letter_event = { id = REP.510 days = 5 tooltip = EVTTOOLTIP_REP_510 }
				}
			}
			if = {
				limit = {
					NOT = { num_of_trade_posts = 1 }
					any_vassal = {
						is_patrician = yes
						num_of_trade_posts = 10
					}
				}
				random_vassal = {
					limit = {
						is_patrician = yes
						num_of_trade_posts = 10
					}
					set_character_flag = target_patrician_doge
					letter_event = { id = REP.510 days = 5 tooltip = EVTTOOLTIP_REP_510 }
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	organize_varangian_guard = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			independent = yes
			is_female = no
			prisoner = no
			is_adult = yes
			NOT = { trait = incapable }
			OR = {
				has_landed_title = e_byzantium
				has_landed_title = e_roman_empire
			}
			has_global_flag = viking_age_started
			NOT = { has_global_flag = varangian_guard_founded }
			any_playable_ruler = {
				religion = norse_pagan
				capital_scope = {
					distance = {
						where = 496	# Constantinople
						value = 400	# Not too far away
					}
				}
			}
		}
		allow = {
			prestige = 300
			wealth = 300
		}
		effect = {
			set_global_flag = varangian_guard_founded
			prestige = -300
			wealth = -300
			activate_title = { title = d_varangian_guard status = yes }
			hidden_tooltip = {
				narrative_event = { id = TOG.3100 }
				create_character = {
					random_traits = yes
					religion = norse_pagan
					culture = norse
					dynasty = NONE
					female = no
					age = 34
					trait = skilled_tactician
				}
				new_character = {
					d_varangian_guard = {
						grant_title = PREV
					}
					set_defacto_liege = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	create_hungary = {
		only_playable = yes
		is_high_prio = yes
		potential = {
			is_playable = yes
			culture = hungarian
			has_landed_title = k_magyar
			k_hungary = {
				has_holder = no
			}
			k_magyar = {
				is_vice_royalty = no
			}
		}
		allow = {
			war = no
			completely_controls = d_pest
			OR = {
				completely_controls = d_transylvania
				completely_controls = d_ungvar
				completely_controls = d_nyitra
			}
		}
		effect = {
			set_global_flag = avar_khaganate_renamed
			k_hungary = {
				reset_coa = THIS
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			set_government_type = feudal_government
			spawn_unit = {
				province = 522 # Pest
				owner = ROOT
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 180 180 }
					light_cavalry = { 420 420 }
					archers = { 600 600 }
				}
				attrition = 0.5
			}
			spawn_unit = {
				province = 522 # Pest
				owner = ROOT
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 180 180 }
					light_cavalry = { 420 420 }
					archers = { 600 600 }
				}
				attrition = 0.5
			}
			spawn_unit = {
				province = 522 # Pest
				owner = ROOT
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 180 180 }
					light_cavalry = { 420 420 }
					archers = { 600 600 }
				}
				attrition = 0.5
			}
			custom_tooltip = {
				text = EVTOPTA62910_CUSTOM
			}
			prestige = 1000
			wealth = 1000
			narrative_event = { id = 62910 tooltip = EVTTOOLTIP62910 }
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	become_saoshyant = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			has_dlc = "The Old Gods"
			is_playable = yes
			religion_group = zoroastrian_group
			NOT ={ religion = manichean }
			NOT = { has_global_flag = saoshyant_appears }
		}
		allow = {
			has_landed_title = e_persia	
			completely_controls = d_fars
			completely_controls = d_khiva
			completely_controls = d_merv
			completely_controls = d_esfahan
			completely_controls = d_hamadan
			completely_controls = d_mazandaran
			completely_controls = d_kermanshah
			completely_controls = d_tigris
			completely_controls = d_basra
			completely_controls = d_baghdad
			completely_controls = d_mosul
			completely_controls = d_jazira			
			completely_controls = d_kerman
			completely_controls = d_khorasan
			completely_controls = d_tabriz
			completely_controls = d_azerbaijan
			completely_controls = d_baluchistan
			completely_controls = d_sistan
			completely_controls = d_kabul
			completely_controls = d_zabulistan
			completely_controls = d_samarkand
			completely_controls = d_dihistan
			piety = 1500
		}
		effect = {
			set_global_flag = saoshyant_appears
			give_nickname = nick_the_saoshyant
			add_trait = saoshyant
			prestige = 500
			piety = 500
			
			hidden_tooltip = {
				narrative_event = { id = TOG.6000 }
				any_child = {
					character_event = { id = TOG.6001 }
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	create_leon = {
		only_playable = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			tier = KING
			has_landed_title = k_asturias
			k_leon = { has_holder = no }
		}

		allow = {
			war = no
			NOT = { trait = incapable }
			primary_title = { title = k_asturias }
			completely_controls = d_leon
			completely_controls = d_asturias
			is_vice_royalty = no
		}
		effect = {
			activate_title = { title = k_leon status = yes }
			k_asturias = {
				k_leon = {
					grant_title = ROOT
					hidden_tooltip = { make_primary_title = yes }
					copy_title_laws = PREV
					copy_title_history = PREV
				}
				hidden_tooltip = {
					any_direct_de_jure_vassal_title = {
						de_jure_liege = k_leon
					}
					destroy_landed_title = THIS
				}
			}
			if = {
				limit = {
					has_landed_title = c_leon
					NOT = { capital_scope = { province_id = 190 } }

				}
				c_leon = { ROOT = { capital = PREV } }
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			activate_title = { title = k_asturias status = no }
			
			hidden_tooltip = {
				character_event = { id = 62920 }
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62921 }
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	create_castille = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			has_landed_title = d_castilla
			independent = yes
			NOT = { higher_tier_than = DUKE }
			k_castille = {
				has_holder = no
			}
			year = 1000
		}
		allow = {
			war = no
			NOT = { trait = incapable }
			completely_controls = d_castilla
			prestige = 1000
			wealth = 100
		}
		effect = {
			wealth = -100
			prestige = 500
			activate_title = { title = k_castille status = yes }
			k_castille = {
				grant_title = ROOT
				copy_title_laws = d_castilla
			}
			d_castilla = {
				de_jure_liege = k_castille
			}
			if = {
				limit = { completely_controls = d_toledo }
				d_toledo = {
					de_jure_liege = k_castille
				}
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			hidden_tooltip = {
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62923 }
				}
			}
			if = {
				limit = {
					has_landed_title = c_burgos
					NOT = { capital_scope = { province_id = 199 } }

				}
				c_burgos = { ROOT = { capital = PREV } }
			}
			hidden_tooltip = { character_event = { id = 62922 } }
		}
		ai_will_do = {
			factor = 1
		}
	}

	create_portugal = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			has_landed_title = d_porto
			independent = yes
			NOT = { higher_tier_than = DUKE }
			k_portugal = {
				has_holder = no
			}
			year = 1000
		}
		allow = {
			war = no
			NOT = { trait = incapable }
			completely_controls = d_porto
			prestige = 1000
			wealth = 100
		}
		effect = {
			wealth = -100
			prestige = 500
			k_portugal = {
				grant_title = ROOT
				copy_title_laws = d_porto
			}
			d_porto = {
				de_jure_liege = k_portugal
			}
			if = {
				limit = { completely_controls = d_beja }
				d_beja = {
					de_jure_liege = k_portugal
				}
			}
			if = {
				limit = {
					has_landed_title = c_porto
					NOT = { capital_scope = { province_id = 158 } }

				}
				c_porto = { ROOT = { capital = PREV } }
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			hidden_tooltip = {
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62925 }
				}
			}
			hidden_tooltip = { character_event = { id = 62924 } }
		}
		ai_will_do = {
			factor = 1
		}
	}

	create_aragon = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			has_landed_title = d_aragon
			independent = yes
			NOT = { higher_tier_than = DUKE }
			k_aragon = {
				has_holder = no
			}
			year = 1000
		}
		allow = {
			war = no
			NOT = { trait = incapable }
			completely_controls = d_aragon
			prestige = 1000
			wealth = 100
		}
		effect = {
			wealth = -100
			prestige = 500
			k_aragon = {
				grant_title = ROOT
				copy_title_laws = d_aragon
			}
			d_aragon = {
				de_jure_liege = k_aragon
			}
			if = {
				limit = { completely_controls = d_barcelona }
				d_barcelona = {
					de_jure_liege = k_aragon
				}
			}
			hidden_tooltip = {
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62927 }
				}
			}
			hidden_tooltip = { character_event = { id = 62926 } }
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	restore_priesthood = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			has_dlc = "The Old Gods"
			is_playable = yes
			religion = zoroastrian
			NOT = { has_global_flag = zoroastrian_priesthood_founded }
		}
		allow = {
			has_landed_title = e_persia
			piety = 300
		}
		effect = {
			set_global_flag = zoroastrian_priesthood_founded
			piety = -300
			activate_title = { title = d_zoroastrian status = yes }
			hidden_tooltip = {
				create_random_priest = {
					random_traits = yes
					religion = zoroastrian
					culture = persian
					dynasty = random
					female = no
					age = 41
				}
				new_character = {
					d_zoroastrian = {
						grant_title = PREV
					}
					narrative_event = { id = TOG.6004 days = 2 }
				}
			}
			d_zoroastrian = {
				holder_scope = {
					e_persia = {
						holder_scope = {
							set_defacto_vassal = PREVPREV
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	build_third_temple = {
		only_playable = yes
		is_high_prio = yes
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion_group = jewish_group
			NOT = { has_global_flag = third_temple_built }
			NOT = { has_global_flag = building_third_temple }
		}
		allow = {
			completely_controls = c_jerusalem
			774 = {
				religion = ROOT
			}
			wealth = 1500
			piety = 1500
		}
		effect = {
			hidden_tooltip = {
				character_event = { id = SoA.100 }
				774 = {	province_event = { id = SoA.10199 days = 1460 random = 50 }	}
			}
			set_global_flag = building_third_temple
			wealth = -1500
			prestige = 500
			piety = 500
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	restore_high_priesthood = {
		only_playable = yes
		is_high_prio = yes
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion = jewish
			has_landed_title = k_israel
			has_global_flag = third_temple_built
			NOT = { has_global_flag = jewish_priesthood_founded }
		}
		allow = {
			completely_controls = c_jerusalem
			774 = {
				religion = jewish
			}
			piety = 1000
		}
		effect = {
			set_global_flag = jewish_priesthood_founded
			activate_title = { title = d_jewish status = yes }
			hidden_tooltip = {
				create_random_priest = {
					random_traits = yes
					religion = ROOT
					culture = ROOT
					dynasty = random
					female = no
					age = 41
				}
				new_character = {
					d_jewish = {
						grant_title = PREV
					}
					narrative_event = { id = SoA.550 }
				}
			}
			d_jewish = {
				holder_scope = {
					k_israel = {
						holder_scope = {
							set_defacto_vassal = PREVPREV
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	create_israel = {
		only_playable = yes
		is_high_prio = yes
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion_group = jewish_group
			k_israel = {
				has_holder = no
			}
		}
		allow = {
			completely_controls = d_jerusalem
			completely_controls = d_ascalon
			completely_controls = d_galilee
			completely_controls = d_oultrejourdain
			774 = {
				religion = ROOT
			}
			piety = 500
			prestige = 500
		}
		effect = {
			narrative_event = { id = SoA.102 tooltip = EVTTOOLTIP_SoA_102 }
			prestige = 1000
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	welcome_jews = {
		only_playable = yes
		
		potential = {
			#has_dlc = "Sons of Abraham"
			is_playable = yes
			NOR = {
				religion_group = jewish_group 
				has_character_modifier = expelled_jews_timer
			}
			has_character_modifier = expelled_jewish
		}
		allow = {
			has_character_modifier = expelled_jewish
		}
		effect = {
			scaled_wealth = -1
			prestige = 50
			remove_character_modifier = expelled_jewish
			if = {
				limit = {
					NOT = { trait = zealous }
					NOT = { trait = sympathy_judaism }
				}
				random = {
					chance = 50
					add_trait = sympathy_judaism
				}
			}
			custom_tooltip = {
				text = jews_are_welcome
			}
			hidden_tooltip = {
				character_event = { id = SoA.106 }
			}
		}
		ai_will_do = {
			factor = 1
			
			modifier = {
				factor = 0.1 # Less likely to do it
			}
			modifier = {
				factor = 0
				trait = zealous
			}
		}
	}
	
	expel_jews = {
		only_independent = yes
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			OR = {
				AND = {
					independent = yes
					primary_title = { higher_tier_than = DUKE }
				}
				ai = no            # So that it shows on player's list anyway
			}
			OR = {
				religion_group = christian
				religion_group = muslim
				religion_group = zoroastrian_group
			}	
			NOR = {
				religion_group = jewish_group
				religion = manichean
				has_character_modifier = expelled_jewish
				is_nomadic = yes
				secret_religion = jewish
				secret_religion = samaritan
				secret_religion = karaite
			}
			age = 16
		}
		allow = {
			independent = yes
			primary_title = { higher_tier_than = DUKE }
			OR = {
				religion_group = christian
				religion_group = muslim
				religion_group = zoroastrian_group
			}
			NOT = { any_realm_province = { religion_group = jewish_group } }
			prisoner = no
			NOT = { trait = incapable }
		}
		effect = {
			prestige = -100
			scaled_wealth = 2
			banish_religion = jewish
			if = {
				limit = { trait = sympathy_judaism }
				remove_trait = sympathy_judaism
			}
			if = {
				limit = {
					NOT = { trait = arbitrary }
					has_character_modifier = borrowed_from_jews
				}
				add_trait = arbitrary
			}
			if = {
				limit = { has_character_modifier = borrowed_from_jews }
				remove_character_modifier = borrowed_from_jews
			}
			add_character_modifier = {
				name = expelled_jewish
				duration = -1
				inherit = yes
			}
			custom_tooltip = {
				text = jews_are_expelled
			}
			hidden_tooltip = {
				character_event = { id = SoA.105 }
				add_character_modifier = {
					name = expelled_jews_timer
					duration = 7300
					hidden = yes
				}
			}
			any_friend = {
				limit = { religion_group = jewish_group }
				remove_friend = ROOT
			}
		}
		ai_will_do = {
			factor = 1
			
			modifier = {
				factor = 0.001 # Less likely to do it
			}
			modifier = {
				factor = 0
				any_courtier = {
					religion_group = jewish_group
					reverse_opinion = { who = ROOT value = 20 }
				}
			}
			modifier = {
				factor = 0
				any_friend = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				any_spouse = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				any_child = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				trait = kind
			}
			modifier = {
				factor = 0
				trait = just
				has_character_modifier = borrowed_from_jews
			}
			modifier = {
				factor = 1.2
				trait = zealous
				trait = arbitrary
			}
			modifier = {
				factor = 2
				has_character_modifier = borrowed_from_jews
				trait = greedy
			}
		}
	}
	
	become_samrat_chakravartin = {
		only_independent = yes
		
		is_high_prio = yes
		potential = {
			has_dlc = "Rajas of India"
			is_playable = yes
			is_feudal = yes
			has_dharmic_religion_trigger = yes
			primary_title = {
				higher_tier_than = DUKE
			}
			capital_scope = {
				region = world_india
			}
			e_india = {
				has_holder = no
			}
		}
		allow = {
			independent = yes
			is_adult = yes
			prisoner = no
			NOT = {	trait = incapable }
			war = no
			prestige = 1000
			wealth = 500
			OR = {
				has_landed_title = e_rajastan
				e_rajastan = { has_holder = no }
			}
			OR = {
				has_landed_title = e_bengal
				e_bengal = { has_holder = no }
			}
			OR = {
				has_landed_title = e_deccan
				e_deccan = { has_holder = no }
			}
			completely_controls_region = world_india
		}
		effect = {
			wealth = -500
			prestige = 500
			activate_title = { title = e_india status = yes }
			hidden_tooltip = {
				any_title = {
					limit = {
						tier = KING
						region = world_india
					}
					de_jure_liege = e_india
				}
			}
			primary_title = {
				e_india = {
					grant_title = ROOT
					copy_title_laws = PREV
					copy_title_history = PREV
				}
			}
			hidden_tooltip = { e_india = { make_primary_title = yes } }
			if = {
				limit = {
					OR = {
						has_landed_title = e_rajastan
						e_rajastan = { has_holder = no }
					}
				}
				e_rajastan = { destroy_landed_title = THIS }
				activate_title = { title = e_rajastan status = no }
			}
			if = {
				limit = {
					OR = {
						has_landed_title = e_bengal
						e_bengal = { has_holder = no }
					}
				}
				e_bengal = { destroy_landed_title = THIS }
				activate_title = { title = e_bengal status = no }
			}
			if = {
				limit = {
					OR = {
						has_landed_title = e_deccan
						e_deccan = { has_holder = no }
					}
				}
				e_deccan = { destroy_landed_title = THIS }
				activate_title = { title = e_deccan status = no }
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_magnificent
			}
			if = {
				limit = { ai = no }
				set_character_flag = achievement_my_very_own_subcontinent
			}
			chronicle = {
				entry = CHRONICLE_UNITED_INDIA
				picture = GFX_evt_throne_room
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}

	form_the_hre = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			has_global_flag = charlemagne_hre
			independent = yes
			OR = {
				religion = catholic
				religion = fraticelli
			}
			OR = {
				culture = german
				culture = dutch
			}
			e_hre = {
				has_holder = no
			}
			e_france = {
				has_holder = no
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			prestige = 1000
			realm_size = 180
			has_landed_title = k_germany
			any_demesne_title = {
				tier = KING
				NOT = {
					title = k_germany
				}
			}
			scaled_wealth = 2
		}
		effect = {
			scaled_wealth = -2
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			primary_title = {
				e_hre = {
					grant_title = ROOT
					copy_title_laws = PREV
					add_law = succ_feudal_elective
				}
			}
			any_demesne_title = {
				limit = {
					tier = KING
					NOT = {
						title = k_germany
					}
				}
				destroy_landed_title = THIS
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}

	form_the_hre_early = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			NOT = { has_global_flag = charlemagne_hre }
			NOT = { has_global_flag = rome_restored }
			independent = yes
			OR = {
				religion = catholic
				religion = fraticelli
			}
			NOT = { has_landed_title = e_byzantium }
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			prestige = 1000
			realm_size = 220
			custom_tooltip = {
				text = form_the_hre_early_tooltip_1
				hidden_tooltip = {
					OR = {
						has_landed_title = k_italy
						has_landed_title = e_italy
					}
				}
			}
			custom_tooltip = {
				text = form_the_hre_early_tooltip_2
				hidden_tooltip = {
					any_demesne_title = {
						OR = {
							title = e_france
							title = e_germany
							title = e_britannia
							title = e_spain
							AND = {
								tier = KING
								NOT = {	title = k_italy	}
								OR = {
									empire = { title = e_france }
									empire = { title = e_germany }
									empire = { title = e_britannia }
									empire = { title = e_spain }
								}
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = form_the_hre_early_tooltip_3
				hidden_tooltip = {
					OR = {
						has_landed_title = e_italy
						e_italy = {	has_holder = no	}
						e_italy = { holder_scope = { NOT = { religion_group = christian } } }
					}
					OR = {
						has_landed_title = e_germany
						e_germany = {	has_holder = no	}
						e_germany = { holder_scope = { NOT = { religion_group = christian } } }
					}
					OR = {
						has_landed_title = e_france
						e_france = { has_holder = no	}
						e_france = { holder_scope = { NOT = { religion_group = christian } } }
					}
					OR = {
						has_landed_title = e_spain
						e_spain = {	has_holder = no	}
						e_spain = { holder_scope = { NOT = { religion_group = christian } } }
					}
					OR = {
						has_landed_title = e_britannia
						e_britannia = {	has_holder = no	}
						e_britannia = { holder_scope = { NOT = { religion_group = christian } } }
					} 
				}
			}
			OR = {
				ai = yes
				AND = {
					religion_head = {
						opinion = { who = ROOT value = 25 }
					}
					scaled_wealth = 2
				}
			}
		}
		effect = {
			set_global_flag = charlemagne_hre
			activate_title = { title = e_hre status = yes }
			scaled_wealth = -2
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			any_demesne_title = {
				limit = { tier = KING }
				de_jure_liege = e_hre
			}
			hidden_tooltip = {
				primary_title = {
					if = {
						limit = { tier = EMPEROR }
						any_direct_de_jure_vassal_title = {
							de_jure_liege = e_hre
						}
					}
				}
			}
			primary_title = {
				e_hre = {
					grant_title = ROOT
					copy_title_laws = PREV
					set_coa = PREV
				}
			}
			any_demesne_title = {
				limit = {
					tier = EMPEROR
					NOT = { title = e_hre }
				}
				destroy_landed_title = THIS
				hidden_tooltip = { activate_title = { title = THIS status = no } }
			}
#			any_demesne_title = {
#				limit = { tier = KING }
#				destroy_landed_title = THIS
#			}
			# Give lands to the Pope
			if = {
				limit = {
					any_realm_title = {
						title = c_roma
						holder_scope = {
							OR = {
								ai = yes
								any_demesne_title = {
									tier = COUNT
									NOT = { title = c_roma }
								}
							}
						}
					}
				}
				c_roma = {
					ROOT = {
						religion_head = {
							grant_title = PREVPREV
						}
					}
				}
			}
			if = {
				limit = {
					any_realm_title = {
						title = c_ravenna
						holder_scope = {
							OR = {
								ai = yes
								any_demesne_title = {
									tier = COUNT
									NOT = { title = c_ravenna }
								}
							}
						}
					}
				}
				c_ravenna = {
					ROOT = {
						religion_head = {
							grant_title = PREVPREV
						}
					}
				}
			}
			if = {
				limit = {
					any_realm_title = {
						title = c_ferrara
						holder_scope = {
							OR = {
								ai = yes
								any_demesne_title = {
									tier = COUNT
									NOT = { title = c_ferrara }
								}
							}
						}
					}
				}
				c_ferrara = {
					ROOT = {
						religion_head = {
							grant_title = PREVPREV
						}
					}
				}
			}
			if = {
				limit = {
					any_realm_title = {
						title = c_urbino
						holder_scope = {
							OR = {
								ai = yes
								any_demesne_title = {
									tier = COUNT
									NOT = { title = c_urbino }
								}
							}
						}
					}
				}
				c_urbino = {
					ROOT = {
						religion_head = {
							grant_title = PREVPREV
						}
					}
				}
			}
			if = {
				limit = {
					any_realm_title = {
						title = c_spoleto
						holder_scope = {
							OR = {
								ai = yes
								any_demesne_title = {
									tier = COUNT
									NOT = { title = c_spoleto }
								}
							}
						}
					}
				}
				c_spoleto = {
					ROOT = {
						religion_head = {
							grant_title = PREVPREV
						}
					}
				}
			}
			e_byzantium = {
				holder_scope = {
					opinion = {
						who = ROOT
						modifier = opinion_unhappy
						months = 1200
					}
					hidden_tooltip = {
						k_papal_state = {
							holder_scope = {
								reverse_opinion = {
									who = PREVPREV
									modifier = opinion_unhappy
									months = 1200
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					OR = {
						NOT = {	has_character_flag = is_charlemagne }
						has_character_flag = charlemagne_coronation
					}
				}
				hidden_tooltip = { narrative_event = { id = CM.510 } }        # Spread the news
			}
			if = {
				limit = {
					has_character_flag = is_charlemagne
					NOT = { has_character_flag = charlemagne_coronation }
				}
				hidden_tooltip = { narrative_event = { id = CM.1500 } }        # Charlemagne coronation
			}
			if = {
				limit = { ai = no }
				set_character_flag = achievement_holy_and_roman
			}
			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE
				picture = GFX_evt_coronation
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	form_new_kingdom = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			tier = DUKE
			NOT = { tier = KING }
			
			has_dlc = "Charlemagne"
			
			holy_order = no
			
			NOT = {
				has_game_rule = {
					name = dynamic_realms
					value = off
				}
			}
			
			OR = {
				ai = no
				AND = {
					trait = proud
					prestige = 5000
				}
				AND = {
					trait = ambitious
					prestige = 5000
				}
				AND = {
					realm_size = 70
					any_demesne_title = {
						count = 4
						tier = DUKE
					}
				}
				prestige = 15000
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			independent = yes
			prestige = 1000
			OR = {
				realm_size = 35
				custom_tooltip = {
					text = form_new_kingdom_requirement_tooltip
					hidden_tooltip = {
						any_demesne_title = {
							count = 3
							tier = DUKE
						}
					}
				}
			}
			wealth = 300
		}
		effect = {
			primary_title = {
				create_title = {
					tier = KING
					landless = no
					temporary = no
					custom_created = yes
					culture = ROOT
					holder = ROOT
					base_title = THIS
					copy_title_laws = yes
				}

				hidden_tooltip = {
					empire = {
						ROOT = {
							primary_title = {
								de_jure_liege = PREVPREV
							}
						}
					}

					ROOT = {
						primary_title = {
							holder_scope = {
								any_title_under = {
									limit = {
										tier = DUKE
										kingdom = {
											has_holder = no
										}
									}
									de_jure_liege = PREVPREV
								}
								any_title_under = {
									limit = {
										tier = COUNT
										location = {
											duchy = {
												kingdom = {
													has_holder = no
												}
												
												NOT = { de_jure_liege_or_above = PREVPREVPREVPREV }
												ROOT = {
													completely_controls = PREV
												}
											}
										}
									}
									location = {
										duchy = {
											de_jure_liege = PREVPREVPREVPREV
										}
									}
								}
							}
						}
					}
				}

			}
			wealth = -300
			custom_tooltip = { text = form_new_kingdom_tooltip }
			chronicle = {
				entry = CHRONICLE_FOUNDED_NEW_KINGDOM_OR_EMPIRE
				portrait = [Root.GetID]
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}

	form_new_empire = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			tier = KING
			is_nomadic = no
			has_dlc = "Charlemagne"
			
			holy_order = no
			
			NOT = { tier = EMPEROR }
			OR = {
				ai = no
				AND = {
					trait = proud
					prestige = 40000
				}
				AND = {
					trait = ambitious
					prestige = 40000
				}
				prestige = 120000
			}
			
			NOT = {
				has_game_rule = {
					name = dynamic_realms
					value = off
				}
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			independent = yes
			prestige = 8000
			OR = {
				realm_size = 180
				custom_tooltip = {
					text = form_new_empire_requirement_tooltip
					hidden_tooltip = {
						any_demesne_title = {
							count = 3
							tier = KING
						}
					}
				}
			}
			wealth = 1000
		}
		effect = {
			primary_title = {
				create_title = {
					tier = EMPEROR
					landless = no
					temporary = no
					custom_created = yes
					culture = ROOT
					holder = ROOT
					base_title = THIS
					copy_title_laws = yes
				}

				hidden_tooltip = {
					ROOT = {
						primary_title = {
							holder_scope = {
								any_title_under = {
									limit = {
										tier = KING
										NOT = {
											empire = { has_holder = yes }
										}
									}
									de_jure_liege = PREVPREV
								}
								any_title_under = {
									limit = {
										tier = DUKE
										location = {
											kingdom = {
												NOT = {
													empire = { has_holder = yes }
												}
												
												NOT = { de_jure_liege_or_above = PREVPREVPREVPREV }
												ROOT = {
													completely_controls = PREV
												}
											}
										}
									}
									location = {
										kingdom = {
											de_jure_liege = PREVPREVPREVPREV
										}
									}
								}
							}
						}
					}
				}
			}
			wealth = -1000
			custom_tooltip = { text = form_new_empire_tooltip }
			chronicle = {
				entry = CHRONICLE_FOUNDED_NEW_KINGDOM_OR_EMPIRE
				portrait = [Root.GetID]
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}

	# Hold Wargames - for nomads
	hold_nomad_wargames = {
		only_playable = yes
		
		potential = {
			is_playable = yes
			is_nomadic = yes
			NOT = { has_character_modifier = holding_nomad_wargames }
			NOT = { has_character_modifier = held_nomad_wargames }
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			NOT = { is_inaccessible_trigger = yes }
			war = no
			any_demesne_title = {
				NOT = { higher_tier_than = count }
				is_occupied = no
			}
			wealth = 20
			prestige = 100
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
		}
		effect = {
			wealth = -30
			add_character_modifier = {
				name = holding_nomad_wargames
				duration = -1
			}
			set_character_flag = recent_minor_decision
			set_character_flag = do_not_disturb
			hidden_tooltip = { character_event = { id = HL.7000 } }
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0.1
			modifier = {
				factor = 0
				NOT = {
					wealth = 200
				}
			}
			modifier = {
				factor = 2
				current_heir = {
					dynasty = ROOT
					combat_rating = 8
				}
			}
			modifier = {
				factor = 0.5
				NOT = { martial = 10 }
			}	
			modifier = {
				factor = 0
				has_character_flag = recent_minor_decision
				NOT = {
					had_character_flag = {
						flag = recent_minor_decision
						days = 730
					}
				}
			}	
		}
	}
	
	convert_to_feudalism_indep  = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			is_tribal = yes
			independent = yes
		}
		allow = {
			war = no
			custom_tooltip = {
				text = TT_NOT_UNREFORMED_PAGAN
				hidden_tooltip = {
					OR = {
						NOT = { religion_group = pagan_group }
						is_reformed_religion = yes
						religion = bon
					}
				}
			}
			primary_title = { has_law = tribal_organization_4 }
			capital_holding = {
				OR = {
					AND = {
						holding_type = tribal
						has_building = tb_hillfort_4
					}
					holding_type = castle
				}
			}
		}
		
		effect = {
			if = {
				limit = { ai = no }
				set_character_flag = achievement_not_a_tribe
			}
			
			if = {
				limit = {
					NOT = { religion_group = muslim }
					NAND = {
						culture_group = tibetan_group
						OR = {
							religion = bon
							religion = buddhist
						}
						higher_tier_than = BARON
					}
				}
				
				if = {
					limit = {
						ai = no
					}
					chronicle = {
						entry = CHRONICLE_ADOPTED_FEUDALISM
						picture = GFX_evt_castle_construction
					}
				}
				set_government_type = feudal_government
			}
			
			if = {
				limit = {
					religion_group = muslim
				}
				
				if = {
					limit = {
						ai = no
					}
					chronicle = {
						entry = CHRONICLE_ADOPTED_IQTA
						picture = GFX_evt_castle_construction
					}
				}
				set_government_type = muslim_government
			}
			
			if = {
				limit = {
					culture_group = tibetan_group
					OR = {
						religion = bon
						religion = buddhist
					}
					higher_tier_than = BARON
				}
				
				if = {
					limit = {
						ai = no
					}
					chronicle = {
						entry = CHRONICLE_ADOPTED_FEUDALISM
						picture = GFX_evt_castle_construction
					}
				}
				set_government_type = theocratic_feudal_government
			}
			
			if = {
				limit = {
					higher_tier_than = king
				}
				primary_title = {
					add_law = feudal_administration
				}
			}
			
			hidden_tooltip = {
				any_demesne_title = {
					limit = {
						tier = baron
						holding_type = tribal
					}
					convert_to = CASTLE
					refill_holding_levy = yes
					
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									num_of_empty_holdings = 2
								}
								NOT = {
									any_direct_de_jure_vassal_title = {
										holding_type = city
									}
								}
							}
						}
						location = {
							build_holding = {
								type = city
							}
						}
					}
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									num_of_empty_holdings = 2
								}
								NOT = {
									any_direct_de_jure_vassal_title = {
										holding_type = temple
									}
								}
							}
						}
						location = {
							build_holding  ={
								type = temple
							}
						}
					}
				}
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	convert_to_feudalism_vassal = {
		only_rulers = yes
		is_high_prio = yes
		
		potential = {
			is_ruler = yes
			is_tribal = yes
			independent = no
		}
		allow = {
			war = no
			custom_tooltip = {
				text = TT_NOT_UNREFORMED_PAGAN
				hidden_tooltip = {
					OR = {
						NOT = { religion_group = pagan_group }
						is_reformed_religion = yes
						religion = bon
					}
				}
			}
			liege = {
				OR = {
					is_feudal = yes
					is_republic = yes
					AND = {
						is_theocracy = yes
						custom_tooltip = {
							text = TT_NOT_UNREFORMED_PAGAN
							hidden_tooltip = {
								OR = {
									NOT = { religion_group = pagan_group }
									is_reformed_religion = yes
									religion = bon
								}
							}
						}
					}
				}
			}
			OR = {
				capital_holding = {
					OR = {
						AND = {
							holding_type = tribal
							has_building = tb_hillfort_4
						}
						holding_type = castle
					}
				}
				AND = {
					NOT = { tier = BARON }
					capital_scope = {
						any_province_holding = {
							holding_type = castle
							holder_scope = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
								}
							}
						}
					}
				}
			}
		}
		
		effect = {
			set_character_flag = achievement_not_a_tribe
			
			if = {
				limit = {
					NOT = { religion_group = muslim }
					NAND = {
						culture_group = tibetan_group
						OR = {
							religion = bon
							religion = buddhist
						}
						higher_tier_than = BARON
					}
				}
				
				if = {
					limit = {
						ai = no
					}
					chronicle = {
						entry = CHRONICLE_ADOPTED_FEUDALISM
						picture = GFX_evt_castle_construction
					}
				}
				set_government_type = feudal_government
			}
			
			if = {
				limit = {
					religion_group = muslim
				}
				
				if = {
					limit = {
						ai = no
					}
					chronicle = {
						entry = CHRONICLE_ADOPTED_IQTA
						picture = GFX_evt_castle_construction
					}
				}
				set_government_type = muslim_government
			}
			
			if = {
				limit = {
					culture_group = tibetan_group
					OR = {
						religion = bon
						religion = buddhist
					}
					higher_tier_than = BARON
				}
				
				if = {
					limit = {
						ai = no
					}
					chronicle = {
						entry = CHRONICLE_ADOPTED_FEUDALISM
						picture = GFX_evt_castle_construction
					}
				}
				set_government_type = theocratic_feudal_government
			}
			
			hidden_tooltip = {
				if = {
					limit = {
						capital_holding = {
							holding_type = tribal
							ROOT = { NOT = { tier = BARON } }
						}
						capital_scope = {
							any_province_holding = {
								holding_type = castle
								holder_scope = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
						}
					}
					
					capital_scope = {
						random_province_holding = {
							limit = {
								holding_type = castle
								holder_scope = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
							if = {
								limit = {
									NOT = { holder = ROOT }
								}
								usurp_title = ROOT
							}
							make_capital_holding = yes
							ROOT = { set_character_flag = feudalize_handled_capital }
						}
					}
				}
				
				any_demesne_title = {
					limit = {
						tier = baron
						holding_type = tribal
						location = {
							capital_holding = {
								NOT = { holding_type = castle }
							}
						}
					}
					convert_to = CASTLE
					refill_holding_levy = yes
					
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									num_of_empty_holdings = 2
								}
								NOT = {
									any_direct_de_jure_vassal_title = {
										holding_type = city
									}
								}
							}
						}
						location = {
							build_holding = {
								type = city
							}
						}
					}
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									num_of_empty_holdings = 2
								}
								NOT = {
									any_direct_de_jure_vassal_title = {
										holding_type = temple
									}
								}
							}
						}
						location = {
							build_holding = {
								type = temple
							}
						}
					}
				}
				
				liege = {
					character_event = { id = 55100 } # Notify Liege
				}
			}
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.001
				liege = {
					OR = {
						NOT = { religion_group = ROOT }
						AND = {
							religion_group = pagan_group
							NOT = { religion = ROOT }
						}
					}
				}
			}
			modifier = {
				factor = 0.01
				liege = {
					NOT = { culture_group = ROOT }
				}
			}
			
			modifier = {
				factor = 0.01
				liege = {
					religion_group = ROOT
					NOT = { religion_group = pagan_group }
					NOT = { religion = ROOT }
				}
			}
			modifier = {
				factor = 0.1
				liege = {
					culture_group = ROOT
					NOT = { culture = ROOT }
				}
			}
		}
	}
	
	convert_to_republic_indep  = {
		only_independent = yes
		is_high_prio = yes
		
		potential = {
			is_playable = yes
			is_tribal = yes
			independent = yes
			has_dlc = "The Republic"
		}
		allow = {
			war = no
			is_female = no
			higher_tier_than = COUNT
			custom_tooltip = {
				text = TT_NOT_UNREFORMED_PAGAN
				hidden_tooltip = {
					OR = {
						NOT = { religion_group = pagan_group }
						is_reformed_religion = yes
						religion = bon
					}
				}
			}
			primary_title = { has_law = tribal_organization_4 }
			capital_scope = {
				port = yes
			}
			capital_holding = {
				OR = {
					AND = {
						holding_type = tribal
						has_building = tb_market_town_4
					}
					holding_type = city
				}
			}
		}
		
		effect = {
			hidden_tooltip = {
				create_family_palace = yes
				
				set_government_type = merchant_republic_government
				
				if = {
					limit = {
						NOT = {
							num_of_government_vassals = {
								government = merchant_republic_government
								value = 1
							}
						}
					}
					
					any_unique_dynasty_vassal = { # gives random vassals a family palace
						count = 4
						limit = {
							is_female = no
							OR = {
								is_republic = yes
								is_tribal = yes
							}
							is_patrician = no
							prisoner = no
							NOT = { trait = incapable }
							is_adult = yes
							NOT = { 
								dynasty = none 
							}
						}
						
						if = {
							limit = { is_tribal = yes }
							
							hidden_tooltip = {
								any_demesne_title = {
									limit = {
										tier = baron
										holding_type = tribal
									}
									convert_to = CITY
									refill_holding_levy = yes
									
									if = {
										limit = {
											dejure_liege_title = {
												holder = PREVPREV
												location = {
													num_of_empty_holdings = 2
												}
												NOT = {
													any_direct_de_jure_vassal_title = {
														holding_type = castle
													}
												}
											}
										}
										location = {
											build_holding = {
												type = castle
											}
										}
									}
									if = {
										limit = {
											dejure_liege_title = {
												holder = PREVPREV
												location = {
													num_of_empty_holdings = 2
												}
												NOT = {
													any_direct_de_jure_vassal_title = {
														holding_type = temple
													}
												}
											}
										}
										location = {
											build_holding = {
												type = temple
											}
										}
									}
								}
							}
						}
						
						create_family_palace = yes
					}
				}
				
				any_demesne_title = {
					limit = {
						tier = baron
						holding_type = tribal
					}
					convert_to = CITY
					refill_holding_levy = yes
					
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									num_of_empty_holdings = 2
								}
								NOT = {
									any_direct_de_jure_vassal_title = {
										holding_type = castle
									}
								}
							}
						}
						location = {
							build_holding = {
								type = castle
							}
						}
					}
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									num_of_empty_holdings = 2
								}
								NOT = {
									any_direct_de_jure_vassal_title = {
										holding_type = temple
									}
								}
							}
						}
						location = {
							build_holding  ={
								type = temple
							}
						}
					}
				}
			}
			
			if = {
				limit = { ai = no }
				set_character_flag = achievement_res_publica
			}
			
			if = {
				limit = {
					ai = no
				}
				chronicle = {
					entry = CHRONICLE_FOUNDED_MERCHANT_REPUBLIC
					picture = GFX_evt_busy_trading_dock_republic
				}
			}
			
			set_government_type = merchant_republic_government
		}
		
		ai_will_do = {
			factor = 0
		}
	}
}

targetted_decisions = {
	embrace_mutazila = {
		only_playable = yes
		
		filter = self
		ai_target_filter = self
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion = sunni
			NOT = { 
				OR = {
					trait = mutazilite
					trait = ashari
				}
			}
			is_adult = yes
			prisoner = no
		}
		
		allow = {
			piety = 50
		}
		
		effect = {
			add_trait = mutazilite
			character_event = { id = SoA.600 tooltip = EVTTOOLTIP_SoA_600 }
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
			
			modifier = {
				factor = 0
				trait = zealous
			}
			modifier = {
				factor = 1.2
				trait = cynical
			}
			modifier = {
				factor = 1.2
				liege = { trait = mutazilite }
			}
			modifier = {
				factor = 0.005 # Slow it down
			}
		}
	}
	embrace_ashari = {
		only_playable = yes
		
		filter = self
		ai_target_filter = self
		
		potential = {	
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion = sunni
			NOT = { 
				OR = {
					trait = mutazilite
					trait = ashari
				}
			}
			is_adult = yes
			prisoner = no
		}
		
		allow = {
			piety = 50
		}
		
		effect = {
			add_trait = ashari
			character_event = { id = SoA.601 tooltip = EVTTOOLTIP_SoA_601 }
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
			
			modifier = {
				factor = 0
				trait = cynical
			}
			modifier = {
				factor = 1.2
				trait = zealous
			}
			modifier = {
				factor = 1.2
				liege = { trait = ashari }
			}
			modifier = {
				factor = 1.2
				decadence = 40
			}
			modifier = {
				factor = 1.2
				decadence = 60
			}
			modifier = {
				factor = 1.2
				decadence = 80
			}
			modifier = {
				factor = 0.005 # Slow it down
			}
		}
	}
}

