decisions = {
	make_anticaliphate = {
		only_playable = yes
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 60
		potential = {
			is_playable = yes
			religion_group = muslim
			independent = yes
			religion_head = { # a CALIPH already exsists
				is_alive = yes
			}
			NOT = { # already controls your CALIPH
				religion_head = {
					OR = {
						is_vassal_or_below_of = ROOT
						character = ROOT
					}
				}
			}
			higher_real_tier_than = COUNT
		}

		allow = {
			prestige = 500
			OR = {
				custom_tooltip = {
					text = controls_mecca_medina
					hidden_tooltip = {
						719 = { # Mecca
							owner = {
								OR = {
									is_liege_or_above = ROOT
									character = ROOT
								}
							}
						}
						718 = { # Medina
							owner = {
								OR = {
									is_liege_or_above = ROOT
									character = ROOT
								}
							}
						}
					}
				}
				custom_tooltip = {
					text = controls_jerusalem_damascus_baghdad
					hidden_tooltip = {
						774 = { # Jerusalem
							owner = {
								OR = {
									is_liege_or_above = ROOT
									character = ROOT
								}
							}
						}
						728 = { # Damascus
							owner = {
								OR = {
									is_liege_or_above = ROOT
									character = ROOT
								}
							}
						}
						693 = { # Baghdad
							owner = {
								OR = {
									is_liege_or_above = ROOT
									character = ROOT
								}
							}
						}
					}
				}
				trait = mirza
				trait = sayyid
				piety = 1000
			}
			is_adult = yes
			prisoner = no
			war = no
			custom_tooltip = {
				text = claimed_caliph
				hidden_tooltip = {
					NOT = { has_character_flag = anti_caliph }
				}
			}
			NOT = {
				trait = incapable 
				religion_authority = 1
			}
		}
		effect = {
			prestige = -500
			religion_head = {
				random_demesne_title = {
					limit = {
						NOT = { tier = KING } # exp
						controls_religion = yes
					}
					
					ROOT = {
						save_persistent_event_target = { name = base_caliphate scope = PREV }
					}
				}
				hidden_effect = {
					opinion = {
						modifier = opinion_claimed_my_title
						who = ROOT
					}
				}
			}
			add_claim = persistent_event_target:base_caliphate
			set_character_flag = anti_caliph
			hidden_effect = {
				religion_scope = {
					set_can_have_antipopes = yes
				}
			}
			#character_event = { id = ICA.100 }
		}
		ai_will_do = {
			factor = 1
			
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			modifier = {
				factor = 0.2
				NOT = { trait = sayyid }
			}
			modifier = {
				factor = 0
				NOT = { trait = ambitious }
			}
			modifier = {
				factor = 10
				dynasty = 7 # Ottoman
			}
			modifier = {
				factor = 2
				dynasty = 589 # Fatimid
			}
			modifier = {
				factor = 2
				dynasty = 597 # Umayyid
			}
			modifier = {
				factor = 2
				dynasty = 101875 # Almohad
			}
			modifier = {
				factor = 1.1
				event_target:base_caliphate = {
					holder_scope = {
						trait = bad_priest_muslim
					}
				}
			}
		}
	}
}