# -*- ck2.decisions -*-

decisions = {
	hold_a_epic_tournament = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24

		potential = {
			independent = yes
			is_playable = yes
			higher_real_tier_than = COUNT
			is_nomadic = no
			OR = {
				religion_group = christian
				religion_group = jewish_group
				religion_group = zoroastrian_group
			}
			NOT = {
				any_demesne_title = {
					lower_tier_than = DUKE
					is_occupied = yes
				}
			}
			OR = {
				NOT = { has_flag = emf_tournament_cooldown }
				had_flag = { flag = emf_tournament_cooldown days = 3650 }
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			war = no
			prisoner = no
			in_command = no
			NOT = { is_inaccessible_trigger = yes }
			is_adult = yes
			prestige = 500
			custom_tooltip = {
				text = CAN_AFFORD_TOURNAMENT
				hidden_tooltip = {
					wealth = 200
					scaled_wealth = 0.5
				}
			}
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_flag = do_not_disturb } }
			}
		}
		effect = {
			set_flag = emf_tournament_cooldown
			scaled_wealth = { value = -0.5 min = -200 }
			prestige = 100
			long_character_event = { id = emf_tournament.100 tooltip = "tournament_invite" }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOR = {
					wealth = 1000
					scaled_wealth = 3.0
				}
			}
		}
	}

	buy_indulgence_for_sins = {
		only_playable = yes
		ai_check_interval = 6
		potential = {
			rtp_is_landless = no
			religion = catholic
			is_adult = yes
			NOT = { has_flag = ask_for_indulgence }
			NOT = { trait = excommunicated }
		}
		allow = {
			prisoner = no
			is_incapable = no
			NOT = { is_inaccessible_trigger = yes }
			scaled_wealth = 1.0
			wealth = 25
			is_heretic = no
		}
		effect = {
			set_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 = {
			rtp_is_landless = no
			age = 16
			is_playable = yes
			is_landed = yes
			OR = {
				higher_tier_than = BARON #Low nobility requires somebody else to ask the Papacy to Lift the Excommunication on their behalf.
				is_patrician = yes
			}
			#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
			}
		}
	}

	sadaqah_saddka  = {
		only_playable = yes
		ai_check_interval = 24
		potential = {
			rtp_is_landless = no
			is_playable = yes
			ai = no
			religion_group = muslim
			is_adult = yes
			demesne_size = 1
			NOT = { has_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_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 = {
			rtp_is_landless = no
			is_playable = yes
			independent = yes
			religion_group = muslim
			higher_real_tier_than = COUNT
			is_nomadic = no
			NOT = {
				any_demesne_title = {
					lower_tier_than = DUKE
					is_occupied = yes
				}
			}
			OR = {
				NOT = { has_flag = emf_tournament_cooldown }
				had_flag = { flag = emf_tournament_cooldown days = 3650 }
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			war = no
			in_command = no
			prisoner = no
			NOT = { is_inaccessible_trigger = yes }
			is_adult = yes
			prestige = 500
			custom_tooltip = {
				text = CAN_AFFORD_TOURNAMENT
				hidden_tooltip = {
					wealth = 200
					scaled_wealth = 0.5
				}
			}
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_flag = do_not_disturb } }
			}
		}
		effect = {
			set_flag = emf_tournament_cooldown
			scaled_wealth = { value = -0.5 min = -200 }
			prestige = 100
			long_character_event = { id = emf_tournament.100 tooltip = "furusiyya_invite" }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOR = {
					wealth = 1000
					scaled_wealth = 3.0
				}
			}
		}
	}

	restore_roman_empire = {
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 120
		
		potential = {
			rtp_is_landless = no
			has_dlc = "Legacy of Rome"
			primary_title = {
				OR = {
					title = e_byzantium
					title = e_latin_empire
				}
			}
			OR = { 
				religion_group = christian
				religion = hellenic_pagan
				religion = hellenic_pagan_reformed
			}
			NOT = { has_global_flag = rome_restored }
			has_random_religion_names = no
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			is_adult = yes
			prisoner = no
			is_incapable = no
			has_regent = no
			NOT = { is_inaccessible_trigger = yes }
			ruled_years = 5
			prestige >= 3000
			trigger_if = {
				limit = { primary_title = { is_de_jure_title = no } }
				primary_title = { is_de_jure_title = yes }
			}
			custom_tooltip = {
				text = TT_IR_CONTROL_TIER_1
				NOT = {
					any_province = {
						region = emf_region_ir_tier_1
						owner_under_ROOT = no
					}
				}
			}
			custom_tooltip = {
				text = TT_IR_CONTROL_TIER_2
				NOT = {
					any_province = {
						region = emf_region_ir_tier_2
						owner_under_ROOT = no
					}
				}
			}
			custom_tooltip = {
				text = TT_IR_CONTROL_TIER_3
				NOT = {
					any_province = {
						region = emf_region_ir_tier_3
						owner_under_ROOT = no
					}
				}
			}
		}
		effect = {
			narrative_event = { id = emf_empires.60 tooltip = EVTTOOLTIPLoR.20 }
		}
		ai_will_do = {
			factor = 2
		}
	}

	mend_great_schism = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		potential = {
			rtp_is_landless = no
			emf_hiprio_decision_basic_potential = yes
			has_dlc = "Legacy of Rome"
			independent = yes
			is_adult = yes
			prisoner = no
			is_incapable = no
			is_heretic = no
			OR = {
				religion = orthodox
				religion = bogomilist
				religion = monothelite
				religion = iconoclast
			}
			primary_title = { emf_is_roman_empire = yes }
			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.75 #Consistent with nerf to controlled holy sites bonus to religious authority
			completely_controls = c_byzantion
			b_hagiasophia = {
				custom_tooltip = { # Custom tooltip to shorten the in-game tooltip
					text = MEND_SCHISM_PENTARCHY_HOLDER_RELIGION
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = bogomilist
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_antiocheia
			b_antiocheia = {
				custom_tooltip = { # Custom tooltip to shorten the in-game tooltip
					text = MEND_SCHISM_PENTARCHY_HOLDER_RELIGION
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = bogomilist
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_jerusalem
			b_jerusalem = {
				custom_tooltip = { # Custom tooltip to shorten the in-game tooltip
					text = MEND_SCHISM_PENTARCHY_HOLDER_RELIGION
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = bogomilist
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_alexandria
			b_alexandria = {
				custom_tooltip = { # Custom tooltip to shorten the in-game tooltip
					text = MEND_SCHISM_PENTARCHY_HOLDER_RELIGION
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = bogomilist
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
			completely_controls = c_roma
			b_roma = {
				custom_tooltip = { # Custom tooltip to shorten the in-game tooltip
					text = MEND_SCHISM_PENTARCHY_HOLDER_RELIGION
					hidden_tooltip = {
						holder_scope = {
							OR = {
								religion = orthodox
								religion = bogomilist
								religion = monothelite
								religion = iconoclast
							}
							is_heretic = no
						}
					}
				}
			}
		}
		effect = {
			set_flag = emf_context_mended_schism_orthodox
			set_flag = schism_mender
			narrative_event = { id = LoR.210 tooltip = EVTTOOLTIPLoR.210}
			set_global_flag = schism_mended
		}
		ai_will_do = {
			factor = 1
		}
	}

	claim_constantinople = {
		is_high_prio = yes
		only_independent = yes

		potential = {
			rtp_is_landless = no
			primary_title = {
				title = e_byzantium
				# Could be an alternate Byzantium, or something like that:
				capital_scope = { county = { title = c_byzantion } }
			}
			is_nomadic = no
			NOT = { has_landed_title = c_byzantion }
			any_realm_lord = {
				has_landed_title = c_byzantion
				ai = yes
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			NOT = { has_landed_title = c_byzantion }
			any_realm_lord = {
				has_landed_title = c_byzantion
				ai = yes
			}
		}
		effect = {
			clr_flag = emf_context_claimed_constantinople
			set_flag = emf_context_claimed_constantinople
			capital_scope = {
				county = {
					c_byzantion = {
						owner = { save_event_target_as = emf_byzantion_owner }
						usurp_title_plus_barony_if_unlanded = { target = ROOT type = revoke }
						any_direct_de_jure_vassal_title = {
							limit = {
								owner_under_ROOT = yes
								is_preferred_holding_type = ROOT
							}
							usurp_title = ROOT
						}
					}
					grant_title = event_target:emf_byzantion_owner
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	###
	# 'make_rome_capital' moved to emf_rome_capital_decision.txt (so EMF+SWMH can override it)
	###

	petition_doge_for_tp = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 6
		potential = {
			rtp_is_landless = no
			is_patrician = yes
			is_merchant_republic = no
			liege = { is_merchant_republic = yes }
			NOT = { has_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
						}
					}
				}
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			liege = {
				opinion = {
					who = ROOT
					value = 25
				}
			}
		}
		effect = {
			set_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 = {
		rtp_is_landless = no
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 6
		potential = {
			is_merchant_republic = yes
			is_patrician = yes
			NOT = { has_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
					}
				}
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			is_merchant_republic = yes
		}
		effect = {
			set_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_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_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 = {
			rtp_is_landless = no
			primary_title = { emf_is_roman_empire = yes }
			is_adult = yes
			prisoner = no
			is_incapable = no
			OR = {
				is_female = no
				gender_equality_trigger = yes
			}
			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
					}
				}
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			custom_tooltip = {
				text = NEEDS_300_PRESTIGE_COST
				prestige = 300
			}
			custom_tooltip = {
				text = NEEDS_300_GOLD_COST
				wealth = 300
			}
		}
		effect = {
			set_global_flag = varangian_guard_founded
			set_flag = emf_context_founded_varangian_guard
			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_flag = is_chosen_varangian_leader
					d_varangian_guard = {
						grant_title = PREV
					}
					emf_create_courtiers = yes
					set_defacto_liege = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	become_saoshyant = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24

		potential = {
			rtp_is_landless = no
			has_dlc = "The Old Gods"
			independent = yes
			OR = {
				religion = zoroastrian
				religion = mazdaki
				religion = zurvanist
			}
			NOT = { has_global_flag = saoshyant_appears }
			is_random_world = no
			has_random_religion_names = no
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			has_landed_title = e_persia
			custom_tooltip = {
				text = emf_ctt_controls_persia_and_mesopotamia
				hidden_tooltip = {
					NOT = {
						any_province = {
							region = emf_region_saoshyant
							owner_under_ROOT = no
						}
					}
				}
			}
			piety = 1500
		}
		effect = {
			set_global_flag = saoshyant_appears
			set_flag = emf_context_became_saoshyant
			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 = {
			rtp_is_landless = no
			has_dlc = "The Old Gods"
			OR = {
				religion = zoroastrian
				religion = zurvanist
				religion = khurmazta						
			}
			is_heretic = no
			NOT = { has_global_flag = zoroastrian_priesthood_founded }
			is_random_world = no
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			has_landed_title = e_persia
			custom_tooltip = {
				text = NEEDS_300_PIETY_COST
				piety = 300
			}
		}
		effect = {
			set_global_flag = zoroastrian_priesthood_founded
			set_flag = emf_context_restored_zoro_priesthood
			piety = -300
			activate_title = { title = d_zoroastrian status = yes }
			hidden_tooltip = {
				create_random_priest = {
					random_traits = yes
					religion = zoroastrian
					culture = ROOT
					dynasty = random
					female = no
					age = 41
				}
				new_character = {
					d_zoroastrian = {
						grant_title = PREV
					}
					emf_new_character = yes
					narrative_event = { id = TOG.6004 days = 2 }
				}
			}
			d_zoroastrian = {
				holder_scope = {
					set_defacto_liege = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	build_third_temple = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 24

		potential = {
			rtp_is_landless = no
			has_dlc = "Sons of Abraham"
			religion_group = jewish_group
			NOT = { has_global_flag = third_temple_built }
			NOT = { has_global_flag = building_third_temple }
			has_random_religion_names = no
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			completely_controls = c_jerusalem
			774 = {
				religion = ROOT
			}
			custom_tooltip = {
				text = NEEDS_1500_GOLD_COST
				wealth = 1500
			}
			piety = 1500
		}
		effect = {
			set_flag = emf_context_started_third_temple
			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 = {
			rtp_is_landless = no
			has_dlc = "Sons of Abraham"
			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 }
			}
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			completely_controls = c_jerusalem
			774 = {
				religion = jewish
			}
			piety = 1000
		}
		effect = {
			set_global_flag = jewish_priesthood_founded
			set_flag = emf_context_restored_jewish_priesthood
			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
					}
					emf_new_character = yes
					narrative_event = { id = SoA.550 }
				}
			}
			d_jewish = {
				holder_scope = {
					set_defacto_liege = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	create_israel = {
		only_playable = yes
		is_high_prio = yes
		ai_check_interval = 24

		potential = {
			rtp_is_landless = no
			has_dlc = "Sons of Abraham"
			religion_group = jewish_group
			k_israel = {
				has_holder = no
			}
			has_random_religion_names = no
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			k_jerusalem = { emf_ROOT_completely_controls_counties = yes }
			774 = {
				religion = ROOT
			}
			piety = 500
			prestige = 500
		}
		effect = {
			hidden_effect = {
				if = {
					limit = { NOT = { is_title_active = k_israel } }
					activate_title = { title = k_israel status = yes }
				}
			}
			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 = {
			rtp_is_landless = no
			#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 = {
			clr_flag = emf_context_welcomed_jews
			set_flag = emf_context_welcomed_jews
			scaled_wealth = -2.5
			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 = 240

		potential = {
			rtp_is_landless = no
			has_dlc = "Sons of Abraham"
			is_adult = yes
			holy_order = no
			OR = {
				AND = {
					independent = yes
					higher_real_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
				secret_religion_group = jewish_group
				has_character_modifier = expelled_jewish
				is_nomadic = yes
			}
			NOT = {
				has_flag = currently_considering_expelling_jews
			}
		}
		allow = {
			independent = yes
			higher_real_tier_than = DUKE
			prisoner = no
			has_regent = no
			is_incapable = no
			trigger_if = {
				limit = { real_tier = EMPEROR }
				custom_tooltip = {
					text = NEEDS_400_PRESTIGE_COST
					prestige = 400
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = NEEDS_300_PRESTIGE_COST
					prestige = 300
				}
			}
			OR = {
				religion_group = christian
				religion_group = muslim
				religion_group = zoroastrian_group
			}
			trigger_if = {
				limit = { any_realm_province = { religion_group = jewish_group } }
				NOT = { any_realm_province = { religion_group = jewish_group } }
			}
			trigger_if = {
				limit = { any_realm_lord = { religion_group = jewish_group } }
				NOT = { any_realm_lord = { religion_group = jewish_group } }
			}
			trigger_if = {
				limit = { has_flag = epidemic_blame_game }
				custom_tooltip = {
					text = cannot_expel_jews_during_blame_game_chain_TT
					always = no
				}
			}
			custom_tooltip = {
				text = NOT_DESCENDANT_OF_A_JEWISH_SAINT	
				hidden_trigger = { NOT = { any_owned_bloodline = { has_bloodline_flag = jewish_saintly_bloodline } } }
			}
		}
		effect = {
			set_flag = emf_context_expelled_jews
			# Prestige cost:
			if = {
				limit = { real_tier = EMPEROR }
				prestige = -400
			}
			else = {
				prestige = -300
			}
			# Seizure of whatever assets we can get our hands on:
			if = {
				limit = { num_of_count_titles_in_realm >= 50 }
				scaled_wealth = { value = 3.0 max = 1400 }
			}
			else_if = {
				limit = { num_of_count_titles_in_realm >= 40 }
				scaled_wealth = { value = 2.6 max = 1200 }
			}
			else_if = {
				limit = { num_of_count_titles_in_realm >= 30 }
				scaled_wealth = { value = 2.2 max = 1000 }
			}
			else_if = {
				limit = { num_of_count_titles_in_realm >= 20 }
				scaled_wealth = { value = 1.8 max = 800 }
			}
			else_if = {
				limit = { num_of_count_titles_in_realm >= 10 }
				scaled_wealth = { value = 1.4 max = 600 }
			}
			else = {
				scaled_wealth = { value = 1.0 max = 400 }
			}
			if = {
				limit = { trait = sympathy_judaism }
				remove_trait = sympathy_judaism
			}
			if = {
				limit = { NOT = { trait = arbitrary } }
				random = { chance = 50 emf_notify_add_arbitrary = yes }
			}
			if = {
				limit = {
					any_realm_lord = {
						is_playable = yes
						OR = {
							trait = sympathy_judaism
							educator = { religion_group = jewish_group }
							betrothed = { religion_group = jewish_group }
							any_spouse = { religion_group = jewish_group }
							any_consort = { religion_group = jewish_group }
							any_lover = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_friend = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_close_relative = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_dynasty_member = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_courtier = {
								religion_group = jewish_group
								OR = {
									has_job_title = yes
									has_minor_title = yes
									reverse_opinion = { who = PREV value = 20 }
									any_pupil = {
										OR = {
											is_close_relative = PREVPREV
											dynasty = PREVPREV
											is_friend = PREVPREV
											is_lover = PREVPREV
											any_spouse = {
												OR = {
													character = PREVPREVPREV
													is_close_relative = PREVPREVPREV
													dynasty = PREVPREVPREV
												}
											}
											any_consort = {
												OR = {
													character = PREVPREVPREV
													is_close_relative = PREVPREVPREV
													dynasty = PREVPREVPREV
												}
											}
											betrothed = {
												OR = {
													character = PREVPREVPREV
													is_close_relative = PREVPREVPREV
													dynasty = PREVPREVPREV
												}
											}
										}
									}
								}
							}
						}
					}
				}
				custom_tooltip = {
					text = WILL_ANGER_REALM_LORDS_WITH_JEWISH_SYMPATHIES_HEADER
				}
				any_realm_lord = {
					show_scope_change = no
					limit = {
						is_playable = yes
						OR = {
							trait = sympathy_judaism
							educator = { religion_group = jewish_group }
							betrothed = { religion_group = jewish_group }
							any_spouse = { religion_group = jewish_group }
							any_consort = { religion_group = jewish_group }
							any_lover = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_friend = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_close_relative = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_dynasty_member = {
								religion_group = jewish_group
								same_realm = ROOT
							}
							any_courtier = {
								religion_group = jewish_group
								OR = {
									has_job_title = yes
									has_minor_title = yes
									reverse_opinion = { who = PREV value = 20 }
									any_pupil = {
										OR = {
											is_close_relative = PREVPREV
											dynasty = PREVPREV
											is_friend = PREVPREV
											is_lover = PREVPREV
											any_spouse = {
												OR = {
													character = PREVPREVPREV
													is_close_relative = PREVPREVPREV
													dynasty = PREVPREVPREV
												}
											}
											any_consort = {
												OR = {
													character = PREVPREVPREV
													is_close_relative = PREVPREVPREV
													dynasty = PREVPREVPREV
												}
											}
											betrothed = {
												OR = {
													character = PREVPREVPREV
													is_close_relative = PREVPREVPREV
													dynasty = PREVPREVPREV
												}
											}
										}
									}
								}
							}
						}
					}
					opinion = { who = ROOT modifier = opinion_expelled_my_jews }
				}
			}
			banish_religion = jewish
			add_character_modifier = {
				name = expelled_jewish
				duration = -1
				inherit = yes
			}
			custom_tooltip = {
				text = jews_are_expelled
				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
				random = { chance = 50 add_rival = ROOT }
			}
			any_lover = {
				limit = { religion_group = jewish_group }
				remove_lover = ROOT
				random = { chance = 50 add_rival = ROOT }
			}
			any_dynasty_member = {
				limit = { religion_group = jewish_group }
				random = { chance = 50 add_rival = ROOT }
			}
			any_close_relative = {
				limit = { religion_group = jewish_group }
				random = { chance = 60 add_rival = ROOT }
			}
			any_consort = {
				limit = { religion_group = jewish_group }
				random = { chance = 70 add_rival = ROOT }
			}
			any_spouse = {
				limit = { religion_group = jewish_group }
				random = { chance = 70 add_rival = ROOT }
			}
			betrothed = {
				if = {
					limit = { religion_group = jewish_group }
					random = { chance = 70 add_rival = ROOT }
				}
			}
		}
		ai_will_do = {
			factor = 1
			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_lover = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				any_spouse = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				any_consort = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				any_child = {
					religion_group = jewish_group
				}
			}
			modifier = {
				factor = 0
				trait = kind
			}
			modifier = {
				factor = 0
				trait = just
			}
			modifier = {
				factor = 1.2
				trait = zealous
				trait = arbitrary
			}
			modifier = {
				factor = 2
				trait = greedy
			}
		}
	}

	# Decision 'become_samrat_chakravartin' moved to:
	# emf_indian_empire_decision.txt

	# Decision form_the_hre not used in favor of emf_create_hre/emf_create_french_hre in emf_hre_decisions.txt

	form_the_hre_early = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		potential = {
			rtp_is_landless = no
			conditional_tooltip = {
				trigger = {
					is_alternate_start = no
				}
				NOR = { 
					has_global_flag = charlemagne_hre 
					is_title_active = e_hre
				}
			}
			NOT = { has_global_flag = rome_restored }
			OR = {
				religion = catholic
				religion = fraticelli
			}
			emf_has_roman_empire = no
			emf_hre_has_holder = no
			has_random_religion_names = no
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			is_adult = yes
			prisoner = no
			is_incapable = no
			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 = {
										title = k_france
										title = k_aquitaine
										title = k_brittany
										title = k_burgundy
										title = k_lotharingia
										title = k_germany
										title = k_bavaria
										title = k_england
										title = k_scotland
										title = k_ireland
										title = k_wales
										title = k_aragon
										title = k_castille
										title = k_leon
										title = k_portugal
										title = k_asturias
										title = k_valencia
										title = k_badajoz
										title = k_andalusia
										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
			set_flag = emf_context_hre_original_founder
			set_flag = emf_context_hre_founder
			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 = { law = succ_hre_elective opinion_effect = no }
				}
			}
			any_demesne_title = {
				show_scope_change = no
				limit = { tier = KING }
				de_jure_liege = e_hre
			}
			hidden_tooltip = {
				any_demesne_title = {
					limit = { tier = EMPEROR }
					any_direct_de_jure_vassal_title = {
						de_jure_liege = e_hre
					}
				}
			}
			any_demesne_title = {
				show_scope_change = no
				limit = {
					tier = EMPEROR
					NOT = { title = e_hre }
				}
				emf_destroy_title = yes
				hidden_tooltip = { activate_title = { title = THIS status = no } }
			}
			any_demesne_title = {
				show_scope_change = no
				limit = { tier = KING }
				emf_destroy_title = yes
			}
			if = {
				limit = { ai = yes }
				# Adjust the HRE title's preferred capital based upon owner demesne
				character_event = { id = emf_empires.71 }
			}
			e_byzantium = {
				show_scope_change = no
				owner = {
					show_scope_change = no
					opinion = { who = ROOT modifier = opinion_unhappy months = 1200 }
				}
			}
			k_papal_state = {
				show_scope_change = no
				owner = {
					show_scope_change = no
					reverse_opinion = { who = e_byzantium modifier = opinion_unhappy months = 1200 }
				}
			}
			if = {
				limit = {
					OR = {
						NOT = {	has_flag = is_charlemagne }
						has_flag = charlemagne_coronation
					}
				}
				add_artifact = crown_hre
				hidden_tooltip = { narrative_event = { id = CM.510 } }		# Spread the news
			}
			if = {
				limit = {
					has_flag = is_charlemagne
					NOT = { has_flag = charlemagne_coronation }
				}
				hidden_tooltip = { narrative_event = { id = CM.1500 } }		# Charlemagne coronation
			}
			if = {
				limit = { ai = no }
				set_flag = achievement_holy_and_roman
			}
			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE
				picture = GFX_evt_coronation
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	# form_new_kingdom & form_new_empire replaced w/ emf_create_custom_kingdom & emf_create_custom_empire
	# See: emf_formation_decisions.txt

	# Hold Wargames - for nomads
	hold_nomad_wargames = {
		only_playable = yes
		ai_check_interval = 4
		
		potential = {
			rtp_is_landless = no
			is_playable = yes
			independent = yes
			is_nomadic = yes
			NOT = { has_character_modifier = holding_nomad_wargames }
			OR = {
				NOT = { has_flag = emf_tournament_cooldown }
				had_flag = { flag = emf_tournament_cooldown days = 3650 }
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			is_incapable = no
			NOT = { is_inaccessible_trigger = yes }
			war = no
			custom_tooltip = {
				text = CAN_AFFORD_TOURNAMENT
				hidden_tooltip = {
					wealth = 50
					scaled_wealth = 0.5
				}
			}
			prestige = 100
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_flag = do_not_disturb } }
			}
			NOT = {
				any_demesne_title = {
					lower_tier_than = DUKE
					is_occupied = yes
				}
			}
		}
		effect = {
			set_flag = emf_tournament_cooldown
			scaled_wealth = { value = -0.5 min = -50 }
			add_character_modifier = {
				name = holding_nomad_wargames
				duration = -1
			}
			hidden_tooltip = { long_character_event = { id = emf_tournament.100 } }
		}
		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 }
			}
		}
	}

	convert_to_feudalism_indep = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 12
		
		potential = {
			rtp_is_landless = no
			is_tribal = yes
			independent = yes
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			war = no
			primary_title = { has_law = tribal_organization_4 }
			capital_holding = {
				OR = {
					AND = {
						holding_type = tribal
						has_building = tb_hillfort_4
					}
					holding_type = castle
				}
			}
		}
		effect = {
			log = "DEBUG: convert_to_feudalism_indep: [This.EMF_GetDebugName]"
			log = "-> primary title: [This.PrimaryTitle.EMF_GetDebugTitleNameWithDeJureLieges]"
			capital_holding = {
				log = "-> capital: [This.EMF_GetDebugTitleNameWithDeJureLieges]"
				log = "---> holding type: [This.EMF_GetHoldingType]"
			}
			clr_flag = emf_context_tribal_to_feudal
			set_flag = emf_context_tribal_to_feudal
			clr_flag = emf_context_tribal_to_feudal_indep
			set_flag = emf_context_tribal_to_feudal_indep
			if = {
				limit = { ai = no }
				set_flag = achievement_not_a_tribe
				if = {
					limit = { religion_group = muslim }
					chronicle = { entry = CHRONICLE_ADOPTED_IQTA picture = GFX_evt_castle_construction }
				}
				else_if = {
					limit = {
						culture_group = tibetan_group
						OR = {
							religion = bon
							religion = buddhist
						}
						higher_tier_than = BARON
					}
					chronicle = { entry = CHRONICLE_ADOPTED_FEUDALISM picture = GFX_evt_castle_construction }
				}
				else_if = {
					limit = { religion = bogomilist }
					chronicle = { entry = CHRONICLE_ADOPTED_BOGOMILIST picture = GFX_evt_castle_construction }
				}
				else = {
					chronicle = { entry = CHRONICLE_ADOPTED_FEUDALISM picture = GFX_evt_castle_construction }
				}
			}
			emf_switch_to_feudal_gov = yes
			log = "-> switched to a [This.EMF_GetGovernmentGroupName] government (should be feudal)"
			hidden_effect = {
				set_flag = emf_no_law_penalties
				primary_title = {
					if = {
						limit = {
							is_law_potential = administration_0
							NOT = { has_law = administration_0 }
						}
						log = "-> added law to [This.GetID] (primary): administration_0"
						add_law = administration_0
					}
				}
				any_demesne_title = {
					limit = { higher_tier_than = DUKE }
					if = {
						limit = { is_law_potential = crown_authority_0 }
						add_law = { law = crown_authority_0 cooldown = no opinion_effect = no }
						log = "-> added law to [This.GetID]: crown_authority_0"
					}
					if = {
						limit = {
							is_law_potential = investiture_law_1
							is_law_allowed = investiture_law_1
							NAND = {
								is_law_potential = investiture_law_0
								is_law_allowed = investiture_law_0
							}
							NOR = {
								has_law = investiture_law_0
								has_law = investiture_law_1
							}
						}
						add_law = investiture_law_1
						log = "-> added law to [This.GetID]: investiture_law_1"
					}
					else_if = {
						limit = {
							is_law_potential = investiture_law_0
							is_law_allowed = investiture_law_0
							NOR = {
								has_law = investiture_law_0
								has_law = investiture_law_1
							}
						}
						add_law = investiture_law_0
						log = "-> added law to [This.GetID]: investiture_law_0"
					}
				}
				clr_flag = emf_no_law_penalties
				set_variable = { which = local_units_spawned value = 0 }
				any_demesne_province = {
					if = {
						limit = { num_of_empty_holdings > 0 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 1 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 2 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 3 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 4 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 5 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 6 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
				}
				log = "-> spawned [local_units_spawned.GetValue] regiments from abandoned empty holdings in demesne"
				any_demesne_title = {
					limit = {
						tier = BARON
						holding_type = tribal
						has_building = tb_hillfort_4
					}
					convert_to = castle
					refill_holding_levy = yes
					set_flag = emf_refill_levy
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									has_empty_holding = yes
									OR = {
										NOT = { any_province_holding = { holding_type = temple } }
										NOT = { any_province_holding = { holding_type = city } }
									}
								}
							}
						}
						location = {
							log = "-> building a random temple or city settlement in [This.County.EMF_GetDebugTitleNameWithDeJureLieges]:"
							random_list = {
								50 = {
									trigger = { NOT = { any_province_holding = { holding_type = temple } } }
									build_holding = { type = temple holder = ROOT }
									random_province_holding = {
										limit = { holding_type = temple }
										emf_distribute_barony = yes
										log = "---> built [This.GetID] as a [This.EMF_GetHoldingType]"
										log = "-----> distributed barony to [This.Holder.EMF_GetDebugName] with a [This.Holder.EMF_GetGovernmentGroupName] government"
										refill_holding_levy = yes
										set_flag = emf_refill_levy
										owner = { character_event = { id = emf_core.40 days = 3 } }
									}
								}
								50 = {
									trigger = { NOT = { any_province_holding = { holding_type = city } } }
									build_holding = { type = city holder = ROOT }
									random_province_holding = {
										limit = { holding_type = city }
										emf_distribute_barony = yes
										log = "---> built [This.GetID] as a [This.EMF_GetHoldingType]"
										log = "-----> distributed barony to [This.Holder.EMF_GetDebugName] with a [This.Holder.EMF_GetGovernmentGroupName] government"
										refill_holding_levy = yes
										set_flag = emf_refill_levy
										owner = { character_event = { id = emf_core.40 days = 3 } }
									}
								}
							}
						}
					}
					location = { #Clear Tribal Great Pillars
						clr_flag = flag_great_pillar_norse
						clr_flag = flag_great_pillar_tengri
						clr_flag = flag_great_pillar_slavic
						clr_flag = flag_great_pillar_baltic
						clr_flag = flag_great_pillar_finnish
						clr_flag = flag_great_pillar_west_african
						clr_flag = flag_great_pillar_aztec
						clr_flag = flag_great_pillar_bon
						clr_flag = flag_great_pillar_zun
						clr_flag = flag_great_pillar_hellenic
					}
				}
				character_event = { id = emf_core.40 days = 3 } # Refill levies
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	convert_to_feudalism_vassal = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 6
		
		potential = {
			rtp_is_landless = no
			is_tribal = yes
			independent = no
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			war = no
			liege = {
				OR = {
					is_feudal = yes
					is_republic = yes
					is_theocracy = 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
							owner = {
								under_ROOT = yes
								OR = {
									ai = yes
									character = ROOT
								}
							}
						}
					}
				}
			}
		}
		effect = {
			log = "DEBUG: convert_to_feudalism_vassal: [This.EMF_GetDebugName]"
			log = "-> primary title: [This.PrimaryTitle.EMF_GetDebugTitleNameWithDeJureLieges]"
			capital_holding = {
				log = "-> capital: [This.EMF_GetDebugTitleNameWithDeJureLieges]"
				log = "---> holding type: [This.EMF_GetHoldingType]"
			}
			clr_flag = emf_context_tribal_to_feudal
			set_flag = emf_context_tribal_to_feudal
			clr_flag = emf_context_tribal_to_feudal_vassal
			set_flag = emf_context_tribal_to_feudal_vassal
			if = {
				limit = { ai = no }
				set_flag = achievement_not_a_tribe
				if = {
					limit = { religion_group = muslim }
					chronicle = { entry = CHRONICLE_ADOPTED_IQTA picture = GFX_evt_castle_construction }
				}
				else_if = {
					limit = {
						culture_group = tibetan_group
						OR = {
							religion = bon
							religion = buddhist
						}
						higher_tier_than = BARON
					}
					chronicle = { entry = CHRONICLE_ADOPTED_FEUDALISM picture = GFX_evt_castle_construction }
				}
				else_if = {
					limit = { religion = bogomilist }
					chronicle = { entry = CHRONICLE_ADOPTED_BOGOMILIST picture = GFX_evt_castle_construction }
				}
				else = {
					chronicle = { entry = CHRONICLE_ADOPTED_FEUDALISM picture = GFX_evt_castle_construction }
				}
			}
			emf_switch_to_feudal_gov = yes
			log = "-> switched to a [This.EMF_GetGovernmentGroupName] government (should be feudal)"
			hidden_effect = {
				set_flag = emf_no_law_penalties
				primary_title = {
					if = {
						limit = {
							is_law_potential = administration_0
							NOT = { has_law = administration_0 }
						}
						log = "-> added law to [This.GetID] (primary): administration_0"
						add_law = administration_0
					}
				}
				any_demesne_title = {
					limit = { higher_tier_than = DUKE }
					if = {
						limit = { is_law_potential = crown_authority_0 }
						add_law = { law = crown_authority_0 cooldown = no opinion_effect = no }
						log = "-> added law to [This.GetID]: crown_authority_0"
					}
					if = {
						limit = {
							is_law_potential = investiture_law_1
							is_law_allowed = investiture_law_1
							NAND = {
								is_law_potential = investiture_law_0
								is_law_allowed = investiture_law_0
							}
							NOR = {
								has_law = investiture_law_0
								has_law = investiture_law_1
							}
						}
						add_law = investiture_law_1
						log = "-> added law to [This.GetID]: investiture_law_1"
					}
					else_if = {
						limit = {
							is_law_potential = investiture_law_0
							is_law_allowed = investiture_law_0
							NOR = {
								has_law = investiture_law_0
								has_law = investiture_law_1
							}
						}
						add_law = investiture_law_0
						log = "-> added law to [This.GetID]: investiture_law_0"
					}
				}
				clr_flag = emf_no_law_penalties
				if = {
					limit = {
						capital_holding = {
							holding_type = tribal
							ROOT = { NOT = { tier = BARON } }
						}
						capital_scope = {
							any_province_holding = {
								holding_type = castle
								owner = {
									under_ROOT = yes
									OR = {
										ai = yes
										character = ROOT
									}
								}
							}
						}
					}
					capital_scope = {
						random_province_holding = {
							limit = {
								holding_type = castle
								owner = {
									under_ROOT = yes
									OR = {
										ai = yes
										character = ROOT
									}
								}
							}
							if = {
								limit = {
									NOT = { holder = ROOT }
								}
								usurp_title = ROOT
							}
							make_capital_holding = yes
							ROOT = { set_flag = feudalize_handled_capital }
						}
					}
				}
				set_variable = { which = local_units_spawned value = 0 }
				any_demesne_province = {
					if = {
						limit = { num_of_empty_holdings > 0 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 1 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 2 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 3 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 4 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 5 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
					if = {
						limit = { num_of_empty_holdings > 6 }
						emf_tribal_settlement_spawn_unit = yes
						change_variable = { which = local_units_spawned value = 1 }
					}
				}
				log = "-> spawned [local_units_spawned.GetValue] regiments from abandoned empty holdings in demesne"
				any_demesne_title = {
					limit = {
						tier = BARON
						holding_type = tribal
						has_building = tb_hillfort_4
					}
					convert_to = castle
					refill_holding_levy = yes
					set_flag = emf_refill_levy
					location = { #Clear Tribal Great Pillars
						clr_flag = flag_great_pillar_norse
						clr_flag = flag_great_pillar_tengri
						clr_flag = flag_great_pillar_slavic
						clr_flag = flag_great_pillar_baltic
						clr_flag = flag_great_pillar_finnish
						clr_flag = flag_great_pillar_west_african
						clr_flag = flag_great_pillar_aztec
						clr_flag = flag_great_pillar_bon
						clr_flag = flag_great_pillar_zun
						clr_flag = flag_great_pillar_hellenic
					}
					if = {
						limit = {
							dejure_liege_title = {
								holder = ROOT
								location = {
									has_empty_holding = yes
									OR = {
										NOT = { any_province_holding = { holding_type = temple } }
										NOT = { any_province_holding = { holding_type = city } }
									}
								}
							}
						}
						location = {
							log = "-> building a random temple or city settlement in [This.County.EMF_GetDebugTitleNameWithDeJureLieges]:"
							random_list = {
								50 = {
									trigger = { NOT = { any_province_holding = { holding_type = temple } } }
									build_holding = { type = temple holder = ROOT }
									random_province_holding = {
										limit = { holding_type = temple }
										emf_distribute_barony = yes
										log = "---> built [This.GetID] as a [This.EMF_GetHoldingType]"
										log = "-----> distributed barony to [This.Holder.EMF_GetDebugName] with a [This.Holder.EMF_GetGovernmentGroupName] government"
										refill_holding_levy = yes
										set_flag = emf_refill_levy
										owner = { character_event = { id = emf_core.40 days = 3 } }
									}
								}
								50 = {
									trigger = { NOT = { any_province_holding = { holding_type = city } } }
									build_holding = { type = city holder = ROOT }
									random_province_holding = {
										limit = { holding_type = city }
										emf_distribute_barony = yes
										log = "---> built [This.GetID] as a [This.EMF_GetHoldingType]"
										log = "-----> distributed barony to [This.Holder.EMF_GetDebugName] with a [This.Holder.EMF_GetGovernmentGroupName] government"
										refill_holding_levy = yes
										set_flag = emf_refill_levy
										owner = { character_event = { id = emf_core.40 days = 3 } }
									}
								}
							}
						}
					}
				}
				# Refill levies
				character_event = { id = emf_core.40 days = 3 }
				liege = {
					character_event = { id = 55100 } # Notify Liege
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.05
				liege = {
					OR = {
						emf_hostile_religion_to_ROOT = yes
						ROOT = { emf_hostile_religion_to_PREV = yes }
					}
				}
			}
			modifier = {
				factor = 0.25
				liege = {
					NOT = { culture_group = ROOT }
				}
			}
		}
	}

	convert_to_republic_indep  = {
		only_independent = yes
		is_high_prio = yes
		potential = {
			rtp_is_landless = no
			is_tribal = yes
			has_dlc = "The Republic"
			emf_hiprio_decision_basic_potential = yes
		}
		allow = {
			war = no
			is_female = no
			higher_tier_than = COUNT
			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
							is_incapable = no
							is_adult = yes
							NOT = {
								dynasty = none
							}
						}
						any_demesne_title = {
							limit = {
								tier = BARON
								holding_type = tribal
							}
							convert_to = city
							refill_holding_levy = yes
							set_flag = emf_refill_levy
							location = { #Clear Tribal Great Pillars
								clr_flag = flag_great_pillar_norse
								clr_flag = flag_great_pillar_tengri
								clr_flag = flag_great_pillar_slavic
								clr_flag = flag_great_pillar_baltic
								clr_flag = flag_great_pillar_finnish
								clr_flag = flag_great_pillar_west_african
								clr_flag = flag_great_pillar_aztec
								clr_flag = flag_great_pillar_bon
								clr_flag = flag_great_pillar_zun
								clr_flag = flag_great_pillar_hellenic
							}
						}
						character_event = { id = emf_core.40 days = 3 } # Refill levies
						create_family_palace = yes
					}
				}
				any_demesne_title = {
					limit = {
						tier = BARON
						holding_type = tribal
						has_building = tb_market_town_4
					}
					convert_to = city
					refill_holding_levy = yes
					set_flag = emf_refill_levy
					location = { #Clear Tribal Great Pillars
						clr_flag = flag_great_pillar_norse
						clr_flag = flag_great_pillar_tengri
						clr_flag = flag_great_pillar_slavic
						clr_flag = flag_great_pillar_baltic
						clr_flag = flag_great_pillar_finnish
						clr_flag = flag_great_pillar_west_african
						clr_flag = flag_great_pillar_aztec
						clr_flag = flag_great_pillar_bon
						clr_flag = flag_great_pillar_zun
						clr_flag = flag_great_pillar_hellenic
					}
				}
				character_event = { id = emf_core.40 days = 3 } # Refill levies
			}

			set_government_type = merchant_republic_government

			set_flag = emf_context_tribal_to_republic
			if = {
				limit = { ai = no }
				chronicle = {
					entry = CHRONICLE_FOUNDED_MERCHANT_REPUBLIC
					picture = GFX_evt_busy_trading_dock_republic
				}
				set_flag = achievement_res_publica
			}

			hidden_effect = {
				set_flag = emf_no_law_penalties
				any_demesne_title = {
					limit = { higher_tier_than = DUKE }
					if = {
						limit = { is_law_potential = crown_authority_0 }
						add_law = crown_authority_0
					}
					if = {
						limit = {
							is_law_potential = investiture_law_1
							is_law_allowed = investiture_law_1
							NAND = {
								is_law_potential = investiture_law_0
								is_law_allowed = investiture_law_0
							}
						}
						add_law = investiture_law_1
					}
					if = {
						limit = {
							is_law_potential = investiture_law_0
							is_law_allowed = investiture_law_0
						}
						add_law = investiture_law_0
					}
				}
				clr_flag = emf_no_law_penalties
			}
		}

		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 = {
					is_incapable = yes
					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 }
		}

		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 = {
					is_incapable = yes
					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 }
		}

		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
			}
		}
	}
}
