decisions = {

	hold_a_epic_tournament  = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		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
		ai_check_interval = 6
		potential = {
			religion = catholic
			age = 16
			demesne_size = 1
			NOT = { has_character_flag = ask_for_indulgence }
			NOT = { trait = excommunicated }
		}
		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
		ai_check_interval = 80
		is_high_prio = yes
		potential = {
			age = 16
			is_playable = yes
			is_landed = yes
			higher_tier_than = BARON #Low nobility requires somebody else to ask the Papacy to Lift the Excommunication on their behalf.
			#religion = catholic #Fraticelli, Reformed Pagans, etc.
			rightful_religious_head_scope = {
				ROOT = {
					excommunicated_for = PREV
				}
			}
		}
		allow = {
			is_heretic = no
			custom_tooltip = { 
				text = tooltip_issued_decla_repentance_recently
				hidden_tooltip = { NOT = { has_character_modifier = asked_repentance_from_sins_cooldown } } 
			}
		}
		effect = {
			hidden_tooltip = {
				add_character_modifier = {
					name = asked_repentance_from_sins_cooldown
					months = 48
					hidden = yes
				}
			}
			rightful_religious_head_scope = {
				character_event = { id = HFP.23003 days = 5 random = 12 tooltip = "repentance_ask" }
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.25
				NOT = {
					scaled_wealth = 2.0
				}
			}
			modifier = {
				factor = 0
				trait = stubborn
			}
			modifier = {
				factor = 0
				trait = cynical
			}
			modifier = {
				factor = 2
				trait = zealous
			}
		}
	}
	
	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
		ai_check_interval = 24
		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
		ai_check_interval = 24
		
		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
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			has_dlc = "Legacy of Rome"
			has_landed_title = e_byzantium
			OR = { 
				religion_group = christian 
				religion = hellenic_pagan 
				religion = hellenic_pagan_reformed
			}
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			NOT = { has_global_flag = rome_restored }
			NOR = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
		ai_check_interval = 24
		
		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
				}
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
		ai_check_interval = 6
		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
		ai_check_interval = 6
		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
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			independent = yes
			OR = {
				is_female = no
				gender_equality_trigger = yes
			}
			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 }
				if = {
					limit = {
						gender_equality_trigger = yes
					}
					create_character = {
						random_traits = yes
						religion = norse_pagan
						culture = norse
						dynasty = NONE
						female = 50
						age = 34
						trait = skilled_tactician
					}
				}
				else = {
					create_character = {
						random_traits = yes
						religion = norse_pagan
						culture = norse
						dynasty = NONE
						female = no
						age = 34
						trait = skilled_tactician
					}
				}
				new_character = {
					add_trait = varangian
					set_character_flag = is_chosen_varangian_leader
					d_varangian_guard = {
						grant_title = PREV
					}
					set_defacto_liege = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	create_hungary = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 24
		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
		ai_check_interval = 24
		
		potential = {
			has_dlc = "The Old Gods"
			is_playable = yes
			is_random_world = no
			religion_group = zoroastrian_group
			NOT = { religion = manichean }
			NOT = { has_global_flag = saoshyant_appears }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		allow = {
			has_landed_title = e_persia	
			completely_controls = d_fars
			completely_controls = d_khiva
			completely_controls = d_merv
			completely_controls = d_mazandaran
			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
			completely_controls = d_mafaza
			completely_controls = d_khozistan
			completely_controls = d_jibal
			completely_controls = d_kurdistan
			completely_controls = d_khuttal
			completely_controls = d_ferghana
			completely_controls = d_mudar
			completely_controls = d_samarra
			completely_controls = d_gilan
			completely_controls = d_herat
			completely_controls = d_balkh
			piety = 1500
		}
		effect = {
			set_global_flag = saoshyant_appears
			give_nickname = nick_the_saoshyant
			save_event_target_as = pahlavi_creator
			add_trait = saoshyant
			custom_tooltip = { text = tooltip_forge_pahalavi_crown }
			hidden_tooltip = {
				add_artifact = crown_pahlavi
				new_artifact = {
					set_name = crown_pahlavi_name
				}
			}
			prestige = 500
			piety = 500
			if = {
				limit = {
					is_female = yes
					has_dlc = "Holy Fury"
				}
				create_bloodline = {
					type = saoshyant_female
				}
				new_bloodline = {
					set_description = "bloodline_desc_saoshyant"
				}
			}
			if = {
				limit = {
					is_female = no
					has_dlc = "Holy Fury"
				}
				create_bloodline = {
					type = saoshyant_male
				}
				new_bloodline = {
					set_description = "bloodline_desc_saoshyant"
				}
			}
			hidden_tooltip = {
				narrative_event = { id = TOG.6000 }
				any_child = {
					character_event = { id = TOG.6001 }
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	restore_priesthood = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		potential = {
			has_dlc = "The Old Gods"
			is_playable = yes
			is_random_world = no
			religion = zoroastrian
			NOT = { has_global_flag = zoroastrian_priesthood_founded }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
		ai_check_interval = 24
		
		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 }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
		ai_check_interval = 24
		
		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 }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
		ai_check_interval = 24
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion_group = jewish_group
			k_israel = {
				has_holder = no
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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 }
			if = {
				limit = {
					is_female = yes
					has_dlc = "Holy Fury"
				}
				create_bloodline = {
					type = israel_female
				}
				new_bloodline = {
					set_description = "bloodline_desc_israel"
				}
			}
			if = {
				limit = {
					is_female = no
					has_dlc = "Holy Fury"
				}
				create_bloodline = {
					type = israel_male
				}
				new_bloodline = {
					set_description = "bloodline_desc_israel"
				}
			}
			prestige = 1000
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	welcome_jews = {
		only_playable = yes
		ai_check_interval = 6
		
		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
			NOT = {
				government = order_government
			}
		}
		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.5 # Less likely to do it
			}
			modifier = {
				factor = 0
				trait = zealous
			}
		}
	}
	
	expel_jews = {
		only_independent = yes
		ai_check_interval = 60
		
		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
			NOT = {
				has_character_flag = currently_considering_expelling_jews
			}
			NOT = {
				government = order_government
			}
		}
		allow = {
			independent = yes
			primary_title = { higher_tier_than = DUKE }
			OR = {
				religion_group = christian
				religion_group = muslim
				religion_group = zoroastrian_group
			}
			conditional_tooltip = {
				trigger = {
					any_realm_province = {
						religion_group = jewish_group
					}
				}
				NOT = { 
					any_realm_province = { 
						religion_group = jewish_group 
					} 
				}
			}
			conditional_tooltip = {
				trigger = {
					any_realm_lord = {
						religion_group = jewish_group
					}
				}
				NOT = { 
					any_realm_lord = { 
						religion_group = jewish_group 
					} 
				}
			}
			conditional_tooltip = {
				trigger = {
					has_character_flag = epidemic_blame_game
				}

				custom_tooltip = {
					text = cannot_expel_jews_during_blame_game_chain_TT

					always = no
				}
			}
			prisoner = no
			NOT = { trait = incapable }
			custom_tooltip = {
				text = NOT_DESCENDANT_OF_A_JEWISH_SAINT	
				hidden_trigger = {
					NOT = { 
						any_owned_bloodline = {
							has_bloodline_flag = jewish_saintly_bloodline
						}
					}
				}
			}
		}
		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.05 # 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
		ai_check_interval = 24
		
		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
			}
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		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
			}
			if = {
				limit = {
					is_female = yes
					has_dlc = "Holy Fury"
				}
				create_bloodline = {
					type = samrat_chakravartin_female
				}
				new_bloodline = {
					set_description = "bloodline_desc_samrat_chakravartin"
				}
			}
			if = {
				limit = {
					is_female = no
					has_dlc = "Holy Fury"
				}
				create_bloodline = {
					type = samrat_chakravartin_male
				}
				new_bloodline = {
					set_description = "bloodline_desc_samrat_chakravartin"
				}
			}
			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
		ai_check_interval = 24
		
		potential = {
			NOT = { has_global_flag = hre_removed }
			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
			}
			is_alternate_start = no
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			prestige = 1000
			realm_size = 180
			has_landed_title = k_germany
			conditional_tooltip = {
				limit = {
					start_date = 936.8.7
				}
				has_landed_title = k_italy
			}
			conditional_tooltip = {
				limit = {
					NOT = { start_date = 936.8.7 }
				}
				custom_tooltip = {
					text = FORM_THE_HRE_TT
					any_demesne_title = {
						tier = KING
						NOT = {
							title = k_germany
						}
					}
				}
			}
			conditional_tooltip = {
				trigger = {
					ai = no
				}

				scaled_wealth = 2
			}
		}
		effect = {
			if = {
				limit = {
					ai = no
				}
				scaled_wealth = -2
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			if = {
				limit = {
					has_character_flag = is_otto
				}
				narrative_event = { id = LT.40015 }
		        any_playable_ruler = {
		            limit = {
		                is_within_diplo_range = ROOT
		            }
		            narrative_event = { id = LT.40015 }
		        }
				create_bloodline = {
					type = otto
				}
			}
			add_artifact = crown_hre
			primary_title = {
				show_scope_change = no
				e_hre = {
					show_scope_change = no
					grant_title = ROOT
					copy_title_laws = PREV
					add_law = succ_hre_elective
				}
			}

			hidden_tooltip = {
				princely_elective_german_elector_setup_effect = yes
			}
			any_demesne_title = {
				limit = {
					OR = {
						tier = KING
						AND = {
							tier = EMPEROR
							NOT = {
								title = e_hre
							}
						}
					}
				}
				destroy_landed_title = THIS
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}

	form_the_hre_early = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			conditional_tooltip = {
				trigger = {
					is_alternate_start = no
				}
				NOR = { 
					has_global_flag = charlemagne_hre 
					is_title_active = e_hre 
				}
			}
			NOT = { has_global_flag = rome_restored }
			independent = yes
			OR = {
				religion = catholic
				religion = fraticelli
			}
			NOT = { has_landed_title = e_byzantium }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
			e_hre = {
				has_holder = no
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			prestige = 1000
			realm_size = 220
			conditional_tooltip = {
				trigger = {
					is_alternate_start = no
				}
				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 } } }
						} 
					}
				}
			}
			conditional_tooltip = {
				trigger = {
					ai = no
				}
				AND = {
					religion_head = {
						opinion = { who = ROOT value = 25 }
					}
					scaled_wealth = 2
				}
			}
		}
		effect = {
			set_global_flag = charlemagne_hre
			activate_title = { title = e_hre status = yes }
			if = {
				limit = {
					ai = no
				}
				scaled_wealth = -2
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			#Create Electors, depending on capital location:
			princely_elective_apply_elector_setup_effect = yes
			primary_title = {
				show_scope_change = no
				e_hre = {
					show_scope_change = no
					grant_title = ROOT
					copy_title_laws = PREV
					set_coa = PREV
					add_law = succ_hre_elective
				}
			}
			any_demesne_title = {
				limit = { tier = KING }
				de_jure_liege = e_hre
			}
			hidden_tooltip = {
				any_demesne_title = {
					if = {
						limit = { tier = EMPEROR }
						any_direct_de_jure_vassal_title = {
							de_jure_liege = e_hre
						}
					}
				}
			}
			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
						}
					}
				}
			}
			if = {
				limit = {
					any_realm_title = {
						title = c_perugia
						holder_scope = {
							OR = {
								ai = yes
								any_demesne_title = {
									tier = COUNT
									NOT = { title = c_perugia }
								}
							}
						}
					}
				}
				c_perugia = {
					ROOT = {
						religion_head = {
							grant_title = PREVPREV
						}
					}
				}
			}
			e_byzantium = {
				show_scope_change = no
				holder_scope = {
					show_scope_change = no
					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
					}
				}
				add_artifact = crown_hre
				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
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			tier = DUKE
			NOT = { tier = KING }
			
			OR = {
				has_dlc = "Charlemagne"
				AND = {
					is_alternate_start = yes
					has_alternate_start_parameter = {
						key = dejure_kingdoms
						value = none
					}
				}
			}
			
			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
				AND = {
					is_alternate_start = yes
					has_alternate_start_parameter = {
						key = dejure_kingdoms
						value = none
					}
				}
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			independent = yes
			
			conditional_tooltip = {
				trigger = {
					AND = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_kingdoms
							value = none
						}
					}
				}
				prestige = 250
				wealth = 50
			}
			
			conditional_tooltip = {
				trigger = {
					NOT = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_kingdoms
							value = none
						}
					}
				}
				prestige = 1000
				wealth = 300
			}

			OR = {
				realm_size = 35
				custom_tooltip = {
					text = form_new_kingdom_requirement_tooltip
					hidden_tooltip = {
						any_demesne_title = {
							count = 3
							tier = DUKE
						}
					}
				}
			}
		}
		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
				}

				new_title = {
					copy_title_history = PREV
				}

				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
								}
								if = {
									limit = {
										has_alternate_start_parameter = {
											key = dejure_kingdoms
											value = none
										}
									}
									any_title_under = {
										limit = {
											tier = DUKE
										}
										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
										}
									}
								}
								if = {
									limit = {
										has_alternate_start_parameter = {
											key = dejure_kingdoms
											value = none
										}
									}
									any_title_under = {
										limit = {
											tier = COUNT
											location = {
												duchy = {
													NOT = { de_jure_liege_or_above = PREVPREVPREVPREV }
													ROOT = {
														completely_controls = PREV
													}
												}
											}
										}
										location = {
											duchy = {
												de_jure_liege = PREVPREVPREVPREV
											}
										}
									}
								}
							}
						}
					}
				}

			}
			if = {
				limit = {
					AND = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_kingdoms
							value = none
						}
					}
				}
				wealth = -50
			}
			if = {
				limit = {
					NOT = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_kingdoms
							value = none
						}
					}
				}
				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
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			tier = KING
			
			OR = {
				has_dlc = "Charlemagne"
				AND = {
					is_alternate_start = yes
					OR = {
						has_alternate_start_parameter = {
							key = dejure_kingdoms
							value = none
						}
						has_alternate_start_parameter = {
							key = dejure_empires
							value = none
						}
					}
				}
			}
			
			holy_order = no
			
			NOT = { tier = EMPEROR }
			OR = {
				ai = no
				AND = {
					trait = proud
					prestige = 40000
				}
				AND = {
					trait = ambitious
					prestige = 40000
				}
				prestige = 120000
				AND = {
					is_alternate_start = yes
					OR = {
						has_alternate_start_parameter = {
							key = dejure_kingdoms
							value = none
						}
						has_alternate_start_parameter = {
							key = dejure_empires
							value = none
						}
					}
				}
			}
			
			NOT = {
				has_game_rule = {
					name = dynamic_realms
					value = off
				}
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			independent = yes
			
			conditional_tooltip = {
				trigger = {
					AND = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_empires
							value = none
						}
					}
				}
				prestige = 2000
				wealth = 200
			}
			
			conditional_tooltip = {
				trigger = {
					NOT = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_empires
							value = none
						}
					}
				}
				prestige = 8000
				wealth = 1000
			}
			
			OR = {
				realm_size = 180
				custom_tooltip = {
					text = form_new_empire_requirement_tooltip
					hidden_tooltip = {
						any_demesne_title = {
							count = 3
							tier = KING
						}
					}
				}
			}
		}
		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
				}

				new_title = {
					copy_title_history = PREV
				}

				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
										}
									}
								}
							}
						}
					}
				}
			}
			
			if = {
				limit = {
					AND = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_empires
							value = none
						}
					}
				}
				wealth = -200
			}
			if = {
				limit = {
					NOT = {
						is_alternate_start = yes
						has_alternate_start_parameter = {
							key = dejure_empires
							value = none
						}
					}
				}
				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
		ai_check_interval = 4
		
		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.4
			modifier = {
				factor = 0
				NOT = {
					wealth = 200
				}
			}
			modifier = {
				factor = 2
				current_heir = {
					dynasty = ROOT
					combat_rating = 70
				}
			}
			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
		ai_check_interval = 12
		
		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
					}
				}
			}
			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 = bon_reformed
							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 = bon_reformed
						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
					location = { #Clear Tribal Great Pillars
						clr_province_flag = flag_great_pillar_norse
						clr_province_flag = flag_great_pillar_tengri
						clr_province_flag = flag_great_pillar_slavic
						clr_province_flag = flag_great_pillar_baltic
						clr_province_flag = flag_great_pillar_finnish
						clr_province_flag = flag_great_pillar_west_african
						clr_province_flag = flag_great_pillar_aztec
						clr_province_flag = flag_great_pillar_bon
						clr_province_flag = flag_great_pillar_zun
						clr_province_flag = flag_great_pillar_hellenic
					}
					
					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_playable = yes
		is_high_prio = yes
		ai_check_interval = 12
		
		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
					}
				}
			}
			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
								}
							}
						}
					}
				}
			}
			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 = bon_reformed
							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 = bon_reformed
						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
					location = { #Clear Tribal Great Pillars
						clr_province_flag = flag_great_pillar_norse
						clr_province_flag = flag_great_pillar_tengri
						clr_province_flag = flag_great_pillar_slavic
						clr_province_flag = flag_great_pillar_baltic
						clr_province_flag = flag_great_pillar_finnish
						clr_province_flag = flag_great_pillar_west_african
						clr_province_flag = flag_great_pillar_aztec
						clr_province_flag = flag_great_pillar_bon
						clr_province_flag = flag_great_pillar_zun
						clr_province_flag = flag_great_pillar_hellenic
					}
					
					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.01
				liege = {
					OR = {
						NOT = { religion_group = ROOT }
						AND = {
							religion_group = pagan_group
							NOT = { religion = ROOT }
						}
					}
				}
			}
			modifier = {
				factor = 0.1
				liege = {
					NOT = { culture_group = ROOT }
				}
			}
			
			modifier = {
				factor = 0.1
				liege = {
					religion_group = ROOT
					NOT = { religion_group = pagan_group }
					NOT = { religion = 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
					}
				}
			}
			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
									location = { #Clear Tribal Great Pillars
										clr_province_flag = flag_great_pillar_norse
										clr_province_flag = flag_great_pillar_tengri
										clr_province_flag = flag_great_pillar_slavic
										clr_province_flag = flag_great_pillar_baltic
										clr_province_flag = flag_great_pillar_finnish
										clr_province_flag = flag_great_pillar_west_african
										clr_province_flag = flag_great_pillar_aztec
										clr_province_flag = flag_great_pillar_bon
										clr_province_flag = flag_great_pillar_zun
										clr_province_flag = flag_great_pillar_hellenic
									}
									
									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
					location = { #Clear Tribal Great Pillars
						clr_province_flag = flag_great_pillar_norse
						clr_province_flag = flag_great_pillar_tengri
						clr_province_flag = flag_great_pillar_slavic
						clr_province_flag = flag_great_pillar_baltic
						clr_province_flag = flag_great_pillar_finnish
						clr_province_flag = flag_great_pillar_west_african
						clr_province_flag = flag_great_pillar_aztec
						clr_province_flag = flag_great_pillar_bon
						clr_province_flag = flag_great_pillar_zun
						clr_province_flag = flag_great_pillar_hellenic
					}
					
					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
		ai_check_interval = 60
		
		potential = {
			has_dlc = "Sons of Abraham"
			is_playable = yes
			religion = sunni
			NOT = { 
				OR = {
					trait = mutazilite
					trait = ashari
				}
			}
			is_adult = yes
			prisoner = no
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		
		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.5 # Slow it down
			}
		}
	}
	embrace_ashari = {
		only_playable = yes
		ai_check_interval = 60
		
		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
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
		}
		
		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.5 # Slow it down
			}
		}
	}
}

