targeted_decisions = {

	recruit_faction_member = {
		ai_target_filter = realm
		filter = realm
		only_playable = yes
		ai_check_interval = 12
		
		from_potential = {
			is_playable = yes
			pf_leader_trigger = yes
		}
		potential = {
			is_playable = yes
			is_adult = yes
			independent = no
			prisoner = no
			same_liege = FROM
			NOR = {
				character = FROM
				pf_leader_trigger = yes
				trait = incapable
				liege = { current_heir = { character = ROOT } }
				has_opinion_modifier = { who = liege modifier = opinion_coerced_into_leaving_faction }
			}
			OR = {
				FROM = { NOT = { leads_faction = faction_court } }
				NOR = {
					in_faction = faction_court
					has_character_flag = faction_court_supporter
				}
			}
			OR = {
				FROM = { NOT = { leads_faction = faction_prosperity } }
				NOR = {
					in_faction = faction_prosperity
					has_character_flag = faction_prosperity_supporter
				}
			}
			OR = {
				FROM = { NOT = { leads_faction = faction_glory } }
				NOR = {
					in_faction = faction_glory
					has_character_flag = faction_glory_supporter
				}
			}
			OR = {
				FROM = { NOT = { leads_faction = faction_tradition } }
				NOR = {
					in_faction = faction_tradition
					has_character_flag = faction_tradition_supporter
					trait = cynical
					trait = excommunicated
					NOT = { liege = { religion = ROOT } }
				}
			}
		}
		allow = {
			NOT = { is_rival = FROM }
			is_ill = no
			custom_tooltip = {
				text = IS_NOT_BUSY
				hidden_tooltip = {
					war = no
					in_command_trigger = no
					NOT = { is_inaccessible_trigger = yes }
					is_not_busy_trigger = yes
				}
			}
			custom_tooltip = {
				text = NOT_RECENTLY_RECRUITED
				hidden_tooltip = {
					NOT = { has_character_modifier = recruit_faction_target_timer }
				}
			}
			custom_tooltip = {
				text = NOT_REBUFFED_RECRUIT
				hidden_tooltip = {
					FROM = {
						NOT = { has_opinion_modifier = { who = ROOT modifier = opinion_rebuffed_recruitment } }
					}
				}
			}
			FROM = {
				is_ill = no
				custom_tooltip = {
					text = IS_NOT_BUSY
					hidden_tooltip = {
						war = no
						in_command_trigger = no
						NOT = { is_inaccessible_trigger = yes }
						is_not_busy_trigger = yes
					}
				}
				custom_tooltip = {
					text = NOT_RECENTLY_RECRUIT
					hidden_tooltip = {
						NOT = { has_character_modifier = recruit_faction_timer }
					}
				}
			}
		}
		effect = {
			character_event = { id = PlusFaction.111 days = 15 tooltip = ATTEMPT_RECRUIT_FACTION }
			hidden_tooltip = {
				add_character_modifier = {
					name = recruit_faction_target_timer
					duration = 365
					hidden = yes
				}
				FROM = {
					character_event = { id = PlusFaction.110 }
					add_character_modifier = {
						name = do_not_disturb
						duration = 15
						hidden = yes
					}
					add_character_modifier = {
						name = recruit_faction_timer
						duration = 365
						hidden = yes
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5
				pf_member_trigger = yes
				FROM = {
					NOR = {
						trait = ambitious
						trait = brave
						trait = diligent
					}
				}
			}
			modifier = {
				factor = 0.1
				FROM = {
					OR = {
						trait = content
						trait = craven
						trait = humble
					}
				}
			}
			modifier = {
				factor = 10
				OR = {
					is_close_relative = FROM
					opinion = { who = FROM value = 50 }
				}
			}
			modifier = {
				factor = 0
				NOT = { opinion = { who = FROM value = 0 } }
			}
			modifier = {
				factor = 0
				NOT = { reverse_opinion = { who = FROM value = 0 } }
			}
		}
	}
	
	court_faction_member = {
		ai_target_filter = realm
		filter = realm
		only_playable = yes
		ai_check_interval = 12
		
		from_potential = {
			is_playable = yes
			pf_member_trigger = yes
		}
		potential = {
			ai = yes
			is_adult = yes
			is_playable = yes
			independent = no
			prisoner = no
			same_liege = FROM
			NOR = {
				character = FROM
				trait = incapable
			}
			OR = {
				AND = {
					in_faction = faction_court
					FROM = { in_faction = faction_court }
				}
				AND = {
					in_faction = faction_prosperity
					FROM = { in_faction = faction_prosperity }
				}
				AND = {
					in_faction = faction_glory
					FROM = { in_faction = faction_glory }
				}
				AND = {
					in_faction = faction_tradition
					FROM = { in_faction = faction_tradition }
				}
			}
		}
		allow = {
			NOT = { is_rival = FROM }
			is_ill = no
			custom_tooltip = {
				text = IS_NOT_BUSY
				hidden_tooltip = {
					war = no
					in_command_trigger = no
					NOT = { is_inaccessible_trigger = yes }
					is_not_busy_trigger = yes
				}
			}
			custom_tooltip = {
				text = NOT_RECENTLY_COURTED
				hidden_tooltip = {
					NOT = { has_character_modifier = court_faction_target_timer }
				}
			}
			custom_tooltip = {
				text = NOT_BAD_COURT_RECENT
				hidden_tooltip = {
					opinion = { who = FROM value = -50 }
					NOT = { has_opinion_modifier = { who = ROOT modifier = unpleasant_meeting } }
				}
			}
			FROM = {
				is_ill = no
				custom_tooltip = {
					text = IS_NOT_BUSY
					hidden_tooltip = {
						war = no
						in_command_trigger = no
						NOT = { is_inaccessible_trigger = yes }
						is_not_busy_trigger = yes
					}
				}
				custom_tooltip = {
					text = NOT_RECENTLY_COURT
					hidden_tooltip = {
						NOT = { has_character_modifier = court_faction_timer }
					}
				}
			}
		}
		effect = {
			FROM = { character_event = { id = PlusFaction.125 tooltip = ATTEMPT_COURT_FACTION } }
			hidden_tooltip = {
				add_character_modifier = {
					name = court_faction_target_timer
					duration = 365
					hidden = yes
				}
				FROM = {
					add_character_modifier = {
						name = do_not_disturb
						duration = 15
						hidden = yes
					}
					add_character_modifier = {
						name = court_faction_timer
						duration = 365
						hidden = yes
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5
				always = yes
			}
			modifier = {
				factor = 10
				FROM = { trait = gregarious }
			}
			modifier = {
				factor = 2
				FROM = {
					OR = {
						trait = ambitious
						trait = diligent
						diplomacy = 15
					}
				}
			}
			modifier = {
				factor = 2
				higher_tier_than = COUNT
			}
			modifier = {
				factor = 2
				higher_tier_than = DUKE
			}
			modifier = {
				factor = 0.5
				lower_tier_than = COUNT
			}
			modifier = {
				factor = 0.5
				FROM = { NOT = { diplomacy = 8 } }
			}
			modifier = {
				factor = 0.5
				NOT = { opinion = { who = FROM value = -25 } }
			}
			modifier = {
				factor = 0
				opinion = { who = FROM value = 50 }
			}
			modifier = {
				factor = 0
				pf_leader_trigger = yes
			}
			modifier = {
				factor = 0
				FROM = {
					OR = {
						trait = shy
						trait = paranoid
						trait = slothful
					}
				}
			}
		}
	}

	ask_claimant_support = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12
		
		from_potential = {
			leads_faction = faction_pretender
		}
		potential = {
			ai = yes
			is_adult = yes
			is_ruler = yes
			is_landed = yes
			independent = no
			prisoner = no
			same_liege = FROM
			NOT = {
				character = FROM
				is_liege_of = FROM
				vassal_of = FROM
				trait = incapable
				FROM = {
					supported_claimant = { character = ROOT }
				}
				FROM = {
					any_faction_backer = {
						in_faction = faction_pretender
						character = ROOT
					}
				}
				has_opinion_modifier = { who = liege modifier = opinion_coerced_into_leaving_faction }
			}
		}
		allow = {
			ROOT = {
				is_ill = no
				custom_tooltip = {
					text = IS_NOT_BUSY
					hidden_tooltip = {
						war = no
						in_command_trigger = no
						NOT = { is_inaccessible_trigger = yes }
						is_not_busy_trigger = yes
					}
				}
				custom_tooltip = {
					text = NOT_HEIR_CLAIMED_TITLE
					hidden_tooltip = {
						NOT = {
							FROM = {
								supported_claimant_title = {
									current_heir = { character = ROOT }
								}
							}
						}
					}
				}
				NOT = { is_rival = FROM }
				custom_tooltip = {
					text = NOT_RIVAL_SUPPORTED_CLAIMANT
					hidden_tooltip = {
						FROM = { supported_claimant = { NOT = { is_rival = PREVPREV } } }
					}
				}
				custom_tooltip = {
					text = SAME_CULTURE_GROUP_SUPPORTED_CLAIMANT
					hidden_tooltip = {
						FROM = { supported_claimant = { culture_group = PREVPREV } }
					}
				}
				custom_tooltip = {
					text = SAME_RELIGION_SUPPORTED_CLAIMANT
					hidden_tooltip = {
						FROM = { supported_claimant = { religion = PREVPREV } }
					}
				}
			}
			FROM = {
				is_ill = no
				custom_tooltip = {
					text = IS_NOT_BUSY
					hidden_tooltip = {
						war = no
						in_command_trigger = no
						NOT = { is_inaccessible_trigger = yes }
						is_not_busy_trigger = yes
					}
				}
				custom_tooltip = {
					text = NOT_RECENTLY_ASK_SUPPORT
					hidden_tooltip = {
						NOT = { has_character_modifier = ask_claimant_support_timer }
					}
				}
			}
		}
		effect = {
			FROM = { character_event = { id = PlusFaction.130 tooltip = ASK_SUPPORT_CLAIMANT } }
			hidden_tooltip = {
				FROM = {
					add_character_modifier = {
						name = do_not_disturb
						duration = 15
						hidden = yes
					}
					add_character_modifier = {
						name = ask_claimant_support_timer
						duration = 30
						hidden = yes
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 5
				higher_tier_than = COUNT
			}
			modifier = {
				factor = 0
				lower_tier_than = COUNT
			}
			modifier = {
				factor = 0
				OR = {
					leads_faction = faction_pretender
					in_faction = faction_pretender
				}
			}
			modifier = {
				factor = 5
				OR = {
					opinion = { who = FROM value = 50 }
					is_close_relative = FROM
				}
			}
			modifier = {
				factor = 0
				NOT = { opinion = { who = FROM value = 0 } }
			}
		}
	}

	invite_claimant_to_court = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12
		
		from_potential = {
			leads_faction = faction_pretender
			ai = yes
			war = no
		}
		potential = {
			ai = yes
			is_ruler = no
			is_adult = yes
			FROM = {
				supported_claimant = { character = ROOT }
				same_liege = ROOT
			}
			NOT = {
				trait = content
				trait = humble
				liege = { reverse_opinion = { who = ROOT value = 0 } }
			}
			OR = {
				trait = ambitious
				trait = proud
				trait = greedy
				trait = envious
				trait = wroth
				trait = deceitful
			}
		}
		allow = {
			war = no
			prisoner = no
			opinion = { who = FROM value = 0 }
		}
		effect = {
			any_spouse = {
				limit = {
					prisoner = no
					is_ruler = no
				}
				move_character = FROM
			}
			any_child = {
				limit = {
					prisoner = no
					is_adult = no
					is_ruler = no
				}
				move_character = FROM
			}
			move_character = FROM
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				FROM = {
					NOT = {
						faction_power = {
							faction = faction_pretender
							power = 0.3
						}
					}
				}
			}
		}
	}

	vet_faction_claimant = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12
		
		from_potential = {
			leads_faction = faction_pretender
			ai = yes
			war = no
		}
		potential = {
			ai = no
			is_ruler = yes
			FROM = {
				supported_claimant = { character = ROOT }
				same_realm = ROOT
			}
			NOR = {
				has_character_flag = refused_pretender_faction
				has_character_flag = supported_pretender_faction
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
		}
		effect = {
			set_character_flag = supported_pretender_faction
			letter_event = { id = PlusFaction.155 }
		}
		ai_will_do = {
			factor = 1
		}
	}
}

decisions = {

	hold_court_faction_meeting = {
		is_high_prio = yes
		
		potential = {
			ai = no
			leads_faction = faction_court
			pf_war_trait_trigger = no
			any_faction_backer = { in_faction = faction_court }
			e_placeholder = { had_title_flag = { flag = startup days = 730 } }
			NOR = {
				has_character_flag = faction_meeting_called
				has_character_flag = faction_meeting_begun
				has_character_flag = faction_leadership_challenge
			}
		}
		allow = {
			custom_tooltip = {
				text = CAN_HOLD_FACTION_MEETING
				hidden_tooltip = {
					pf_pending_civil_war_trigger = no
					OR = {
						NOT = { has_character_flag = faction_meeting }
						had_character_flag = { flag = faction_meeting days = 1095 }
						AND = {
							had_character_flag = { flag = faction_meeting days = 730 }
							liege = { has_character_flag = faction_court_angry }
						}
					}
				}
			}
		}
		effect = {
			custom_tooltip = { text = CUSTOMTOOLTIP51 }
			set_character_flag = faction_meeting_called
			clr_character_flag = faction_meeting_postponed
			hidden_tooltip = {
				set_variable = { which = "faction_votes" value = 0 }
				set_variable = { which = "faction_meeting_delay" value = 0 }
				liege = {
					any_vassal = {
						limit = { pf_root_faction_backer_trigger = yes }
						character_event = { id = PlusFaction.302 }
					}
				}
				character_event = { id = PlusFaction.303 days = 15 } #meeting postponed
				character_event = { id = PlusFaction.304 days = 15 } #start the meeting
				character_event = { id = PlusFaction.350 days = 15 } #leadership challenged
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	hold_prosperity_faction_meeting = {
		is_high_prio = yes
		
		potential = {
			ai = no
			leads_faction = faction_prosperity
			pf_war_trait_trigger = no
			any_faction_backer = { in_faction = faction_prosperity }
			e_placeholder = { had_title_flag = { flag = startup days = 730 } }
			NOR = {
				has_character_flag = faction_meeting_called
				has_character_flag = faction_meeting_begun
				has_character_flag = faction_leadership_challenge
			}
		}
		allow = {
			custom_tooltip = {
				text = CAN_HOLD_FACTION_MEETING
				hidden_tooltip = {
					pf_pending_civil_war_trigger = no
					OR = {
						NOT = { has_character_flag = faction_meeting }
						had_character_flag = { flag = faction_meeting days = 1095 }
						AND = {
							had_character_flag = { flag = faction_meeting days = 730 }
							liege = { has_character_flag = faction_prosperity_angry }
						}
					}
				}
			}
		}
		effect = {
			custom_tooltip = { text = CUSTOMTOOLTIP52 }
			set_character_flag = faction_meeting_called
			clr_character_flag = faction_meeting_postponed
			hidden_tooltip = {
				set_variable = { which = "faction_votes" value = 0 }
				set_variable = { which = "faction_meeting_delay" value = 0 }
				liege = {
					any_vassal = {
						limit = { pf_root_faction_backer_trigger = yes }
						character_event = { id = PlusFaction.302 }
					}
				}
				character_event = { id = PlusFaction.303 days = 15 } #meeting postponed
				character_event = { id = PlusFaction.304 days = 15 } #start the meeting
				character_event = { id = PlusFaction.350 days = 15 } #leadership challenged
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	hold_glory_faction_meeting = {
		is_high_prio = yes
		
		potential = {
			ai = no
			leads_faction = faction_glory
			pf_war_trait_trigger = no
			any_faction_backer = { in_faction = faction_glory }
			e_placeholder = { had_title_flag = { flag = startup days = 730 } }
			NOR = {
				has_character_flag = faction_meeting_called
				has_character_flag = faction_meeting_begun
				has_character_flag = faction_leadership_challenge
			}
		}
		allow = {
			custom_tooltip = {
				text = CAN_HOLD_FACTION_MEETING
				hidden_tooltip = {
					pf_pending_civil_war_trigger = no
					OR = {
						NOT = { has_character_flag = faction_meeting }
						had_character_flag = { flag = faction_meeting days = 1095 }
						AND = {
							had_character_flag = { flag = faction_meeting days = 730 }
							liege = { has_character_flag = faction_glory_angry }
						}
					}
				}
			}
		}
		effect = {
			custom_tooltip = { text = CUSTOMTOOLTIP53 }
			set_character_flag = faction_meeting_called
			clr_character_flag = faction_meeting_postponed
			hidden_tooltip = {
				set_variable = { which = "faction_votes" value = 0 }
				set_variable = { which = "faction_meeting_delay" value = 0 }
				liege = {
					any_vassal = {
						limit = { pf_root_faction_backer_trigger = yes }
						character_event = { id = PlusFaction.302 }
					}
				}
				character_event = { id = PlusFaction.303 days = 15 } #meeting postponed
				character_event = { id = PlusFaction.304 days = 15 } #start the meeting
				character_event = { id = PlusFaction.350 days = 15 } #leadership challenged
			}
		}
		ai_will_do = {
			factor = 0
		}
	}

	hold_tradition_faction_meeting = {
		is_high_prio = yes
		
		potential = {
			ai = no
			leads_faction = faction_tradition
			pf_war_trait_trigger = no
			any_faction_backer = { in_faction = faction_tradition }
			e_placeholder = { had_title_flag = { flag = startup days = 730 } }
			NOR = {
				has_character_flag = faction_meeting_called
				has_character_flag = faction_meeting_begun
				has_character_flag = faction_leadership_challenge
			}
		}
		allow = {
			custom_tooltip = {
				text = CAN_HOLD_FACTION_MEETING
				hidden_tooltip = {
					pf_pending_civil_war_trigger = no
					OR = {
						NOT = { has_character_flag = faction_meeting }
						had_character_flag = { flag = faction_meeting days = 1095 }
						AND = {
							had_character_flag = { flag = faction_meeting days = 730 }
							liege = { has_character_flag = faction_tradition_angry }
						}
					}
				}
			}
		}
		effect = {
			custom_tooltip = { text = CUSTOMTOOLTIP54 }
			set_character_flag = faction_meeting_called
			clr_character_flag = faction_meeting_postponed
			hidden_tooltip = {
				set_variable = { which = "faction_votes" value = 0 }
				set_variable = { which = "faction_meeting_delay" value = 0 }
				liege = {
					any_vassal = {
						limit = { pf_root_faction_backer_trigger = yes }
						character_event = { id = PlusFaction.302 }
					}
				}
				character_event = { id = PlusFaction.303 days = 15 } #meeting postponed
				character_event = { id = PlusFaction.304 days = 15 } #start the meeting
				character_event = { id = PlusFaction.350 days = 15 } #leadership challenged
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	faction_send_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			independent = no
			OR = {
				pf_leader_trigger = yes
				leads_faction = faction_succ_seniority
				leads_faction = faction_succ_primogeniture
				leads_faction = faction_succ_gavelkind
				leads_faction = faction_succ_feudal_elective
			}
			pf_has_demands_trigger = yes
			has_character_flag = civil_war_faction_leader
			OR = {
				NOT = { has_character_flag = faction_regular_ultimatum_taken }
				had_character_flag = { flag = faction_regular_ultimatum_taken days = 7 }
			}
		}
		allow = {
			liege = {
				NOT = { war_with = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
		}
		effect = {
			set_character_flag = faction_regular_ultimatum_taken
			pf_punish_deceitful_player_effect = yes
			if = {
				limit = {
					ROOT = {
						NOR = {
							has_character_flag = demands_seniority
							has_character_flag = demands_primogeniture
							has_character_flag = demands_gavelkind
							has_character_flag = demands_feudal_elective
						}
					}
				}
				log = "[Root.GetTitledName] has issued a regular faction ultimatum to [Root.Liege.GetTitledName]"
				liege = {
					letter_event = { id = PlusFaction.400 tooltip = SEND_REGULAR_ULTIMATUM }
				}
			}
			if = {
				limit = {
					ROOT = {
						OR = {
							has_character_flag = demands_seniority
							has_character_flag = demands_primogeniture
							has_character_flag = demands_gavelkind
							has_character_flag = demands_feudal_elective
						}
					}
				}
				log = "[Root.GetTitledName] has issued a succession faction ultimatum to [Root.Liege.GetTitledName]"
				liege = {
					letter_event = { id = PlusFaction.470 tooltip = SEND_REGULAR_ULTIMATUM }
				}
			}
		}
		ai_will_do = {
			factor = 1
			# AI will not take war while 30-day timer lasts
			# unless there are no vassals left to join the faction
			modifier = {
				factor = 0
				has_character_modifier = declare_civil_war_timer
				liege = {
					any_vassal = {
						pf_root_faction_backer_trigger = no
						has_character_flag = will_join_civil_war
					}
				}
			}
			# Still has the power to have the revolt
			modifier = {
				factor = 0
				NOR = {
					AND = {
						leads_faction = faction_court
						pf_not_regular_faction_war_trigger = no
						faction_power = { faction = faction_court power = 0.75 }
					}
					AND = {
						leads_faction = faction_prosperity
						pf_not_regular_faction_war_trigger = no
						faction_power = { faction = faction_prosperity power = 0.75 }
					}
					AND = {
						leads_faction = faction_glory
						pf_not_regular_faction_war_trigger = no
						faction_power = { faction = faction_glory power = 0.75 }
					}
					AND = {
						leads_faction = faction_tradition
						pf_not_regular_faction_war_trigger = no
						faction_power = { faction = faction_tradition power = 0.75 }
					}
					AND = {
						leads_faction = faction_succ_seniority
						has_character_flag = demands_seniority
						faction_power = { faction = faction_succ_seniority power = 0.75 }
					}
					AND = {
						leads_faction = faction_succ_primogeniture
						has_character_flag = demands_primogeniture
						faction_power = { faction = faction_succ_primogeniture power = 0.75 }
					}
					AND = {
						leads_faction = faction_succ_gavelkind
						has_character_flag = demands_gavelkind
						faction_power = { faction = faction_succ_gavelkind power = 0.75 }
					}
					AND = {
						leads_faction = faction_succ_feudal_elective
						has_character_flag = demands_feudal_elective
						faction_power = { faction = faction_succ_feudal_elective power = 0.75 }
					}
				}
			}
		}
	}
	
	faction_begin_civil_war = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			independent = no
			pf_leader_trigger = yes
			pf_has_demands_trigger = no
			has_character_flag = civil_war_faction_leader
			NOT = { has_character_flag = preparing_claimant_faction_war }
			NOT = { has_character_flag = preparing_religious_faction_war }
		}
		allow = {
			liege = {
				NOT = { war_with = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
		}
		effect = {
			log = "[Root.GetTitledName] started a civil war to overthrow [Root.Liege.GetTitledName]"
			pf_punish_deceitful_player_effect = yes
			liege = {
				tooltip = {
					reverse_war = {
						target = ROOT
						casus_belli = cb_faction_overthrow_ruler
					}
				}
				hidden_tooltip = {
					letter_event = { id = PlusFaction.406 }
				}
			}
			hidden_tooltip = {
				character_event = { id = PlusFaction.399 days = 1 } #clear flags
			}
		}
		ai_will_do = {
			factor = 1
			# AI will not take war while 30-day timer lasts
			# unless there are no vassals left to join the faction
			modifier = {
				factor = 0
				has_character_modifier = declare_civil_war_timer
				liege = {
					any_vassal = {
						pf_root_faction_backer_trigger = no
						has_character_flag = will_join_civil_war
					}
				}
			}
			# Still has the power to have the revolt
			modifier = {
				factor = 0
				NOR = {
					AND = {
						leads_faction = faction_court
						faction_power = { faction = faction_court power = 0.75 }
					}
					AND = {
						leads_faction = faction_prosperity
						faction_power = { faction = faction_prosperity power = 0.75 }
					}
					AND = {
						leads_faction = faction_glory
						faction_power = { faction = faction_glory power = 0.75 }
					}
					AND = {
						leads_faction = faction_tradition
						faction_power = { faction = faction_tradition power = 0.75 }
					}
				}
			}
		}
	}
	
	faction_antiking_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			leads_faction = faction_antiking
			OR = {
				NOT = { has_character_flag = faction_install_antiking_ultimatum_taken }
				had_character_flag = { flag = faction_install_antiking_ultimatum_taken days = 7 }
			}
		}
		allow = {
			war = no
			has_regent = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			log = "[Root.GetTitledName] has issued an Antiking ultimatum to [Root.Liege.GetTitledName]"
			liege = {
				letter_event = { id = 8200 days = 3 tooltip = EVTTOOLTIP8005 }
			}
			hidden_tooltip = {
				set_character_flag = faction_install_antiking_ultimatum_taken
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { faction_power = { faction = faction_antiking power = 0.75 } }
			}		
			modifier = {
				factor = 0.5 # Slow it down a bit
				always = yes
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREVPREV }
								NOT = { using_cb = depose_liege }
								NOT = { using_cb = overthrow_ruler }
								NOT = { using_cb = overthrow_ruler_no_calls }
								NOT = { using_cb = claim_on_liege_plot }
								NOT = { using_cb = other_claim_on_liege_plot }
								NOT = { using_cb = cb_faction_overthrow_ruler }
							}
							AND = {
								attacker = { character = PREVPREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = manifest_destiny_invasion
									using_cb = viking_invasion
								}
							}
						}
					}
				}
			}
		}
	}

	faction_claimant_prepare = {
		is_high_prio = yes
		
		potential = {
			ai = no
			leads_faction = faction_pretender
			NOT = { has_character_flag = civil_war_faction_leader }
			NOT = { has_character_flag = civil_war_faction_member }
		}
		allow = {
			war = no
			has_regent = no
			faction_power = {
				faction = faction_pretender
				power = 0.5
			}
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			capital_holding = {
				controller = {
					character = ROOT
				}
			}
		}
		effect = {
			set_character_flag = preparing_claimant_faction_war
			# allow the faction leader to now take the 'Make Ultimatum to Liege' decision
			# and set the timer so the AI doesn't use the decision for 30 days (unless everyone has joined)
			custom_tooltip = {
				text = MAY_TAKE_ULTIMATUM_DECISION
				hidden_tooltip = {
					set_character_flag = civil_war_faction_leader
					add_character_modifier = {
						name = declare_civil_war_timer
						duration = 30
						hidden = yes
					}
				}
			}
			# invite all other vassals to join the coming civil war
			liege = {
				custom_tooltip = { text = INVITE_TO_JOIN_CIVIL_WAR }
				hidden_tooltip = {
					any_vassal = {
						limit = { NOT = { in_faction = faction_pretender } }
						letter_event = { id = PlusFaction.422 }
					}
				}
			}
			hidden_tooltip = {
				any_faction_backer = {
					faction = faction_pretender
					set_character_flag = civil_war_faction_member
				}
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	faction_claimant_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			independent = no
			leads_faction = faction_pretender
			has_character_flag = preparing_claimant_faction_war
			has_character_flag = civil_war_faction_leader
			OR = {
				NOT = { has_character_flag = faction_claimant_ultimatum_taken }
				had_character_flag = { flag = faction_claimant_ultimatum_taken days = 7 }
			}
		}
		allow = {
			liege = {
				NOT = { war_with = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			supported_claimant = {
				is_alive = yes
			}
		}
		effect = {
			pf_punish_deceitful_player_effect = yes
			clr_character_flag = preparing_claimant_faction_war
			log = "[Root.GetTitledName] has issued a claimant faction ultimatum to [Root.Liege.GetTitledName]"
			liege = {
				letter_event = { id = 8036 days = 7 tooltip = "EVTTOOLTIP8005" }
			}
			if = {
				limit = {
					supported_claimant = {
						NOT = { character = ROOT }
						OR = {
							NOT = { same_liege = ROOT }
							NOT = { in_faction = faction_pretender }
							NOT = { supported_claimant = { character = PREV } }
						}
					}
				}
				supported_claimant = {
					letter_event = { id = 8037 days = 1 }
				}
			}
			hidden_tooltip = {
				set_character_flag = faction_claimant_ultimatum_taken
			}
		}
		ai_will_do = {
			factor = 1
			# AI will not take war while 30-day timer lasts
			# unless there are no vassals left to join the faction
			modifier = {
				factor = 0
				has_character_modifier = declare_civil_war_timer
				liege = {
					any_vassal = {
						NOT = { in_faction = faction_pretender }
						has_character_flag = will_join_civil_war
					}
				}
			}
			# Still has the power to have the revolt
			modifier = {
				factor = 0
				NOT = { faction_power = { faction = faction_pretender power = 0.75 } }
			}
		}
	}

	faction_religious_prepare = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			ai = no
			leads_faction = faction_religious
			NOT = { has_character_flag = civil_war_faction_leader }
			NOT = { has_character_flag = civil_war_faction_member }
		}
		allow = {
			war = no
			has_regent = no
			faction_power = {
				faction = faction_religious
				power = 0.5
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			capital_holding = {
				controller = {
					character = ROOT
				}
			}
		}
		effect = {
			set_character_flag = preparing_religious_faction_war
			# allow the faction leader to now take the 'Make Ultimatum to Liege' decision
			# and set the timer so the AI doesn't use the decision for 30 days (unless everyone has joined)
			custom_tooltip = {
				text = MAY_TAKE_ULTIMATUM_DECISION
				hidden_tooltip = {
					set_character_flag = civil_war_faction_leader
					add_character_modifier = {
						name = declare_civil_war_timer
						duration = 30
						hidden = yes
					}
				}
			}
			# invite all other vassals to join the coming civil war
			liege = {
				custom_tooltip = { text = INVITE_TO_JOIN_CIVIL_WAR }
				hidden_tooltip = {
					any_vassal = {
						limit = {
							religion = ROOT
							NOT = { in_faction = faction_religious }
						}
						letter_event = { id = Plus.255 }
					}
				}
			}
			hidden_tooltip = {
				any_faction_backer = {
					faction = faction_religious
					set_character_flag = civil_war_faction_member
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				NOT = { faction_power = { faction = faction_religious power = 0.75 } }
			}
			modifier = {
				factor = 0
				NOT = { faction_power = { faction = faction_religious power = 1.0 } }
				NOR = {
					martial = 15
					trait = lunatic
					trait = possessed
					trait = wroth
					trait = brave
				}
			}
			modifier = {
				factor = 0.5 # Slow it down a bit
				always = yes
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREVPREV }
								NOT = { using_cb = depose_liege }
								NOT = { using_cb = overthrow_ruler }
								NOT = { using_cb = overthrow_ruler_no_calls }
								NOT = { using_cb = claim_on_liege_plot }
								NOT = { using_cb = other_claim_on_liege_plot }
								NOT = { using_cb = cb_faction_overthrow_ruler }
							}
							AND = {
								attacker = { character = PREVPREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = manifest_destiny_invasion
									using_cb = viking_invasion
								}
							}
						}
					}
				}
			}
		}
	}	
	
	faction_religious_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			independent = no
			leads_faction = faction_religious
			has_character_flag = preparing_religious_faction_war
			has_character_flag = civil_war_faction_leader
			OR = {
				NOT = { has_character_flag = faction_religious_ultimatum_taken }
				had_character_flag = { flag = faction_religious_ultimatum_taken days = 7 }
			}
		}
		allow = {
			liege = {
				NOT = { war_with = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
		}
		effect = {
			log = "[Root.GetTitledName] has issued a religious faction ultimatum to [Root.Liege.GetTitledName]"
			pf_punish_deceitful_player_effect = yes
			clr_character_flag = preparing_claimant_faction_war
			liege = {
				letter_event = { id = Plus.250 tooltip = SEND_RELIGIOUS_ULTIMATUM }
			}
			hidden_tooltip = {
				set_character_flag = faction_religious_ultimatum_taken
			}
		}
		ai_will_do = {
			factor = 1
			# AI will not take war while 30-day timer lasts
			# unless there are no vassals left to join the faction
			modifier = {
				factor = 0
				has_character_modifier = declare_civil_war_timer
				liege = {
					any_vassal = {
						religion = ROOT
						NOT = { in_faction = faction_religious }
						has_character_flag = will_join_civil_war
					}
				}
			}
			# Still has the power to have the revolt
			modifier = {
				factor = 0
				NOT = { faction_power = { faction = faction_religious power = 0.75 } }
			}
		}
	}
	
	faction_separatist_war = {
		is_high_prio = yes

		potential = {
			ai = no
			leads_faction = faction_separatist
			NOT = { has_character_modifier = faction_independence_ultimatum_timer }
			liege = { NOT = { character = ROOT } }
		}
		allow = {
			war = no
			has_regent = no
			faction_power = {
				faction = faction_separatist
				power = 0.5
			}
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			hidden_tooltip = {
				set_character_flag = original_war_liege
				pf_setup_rebel_effect = yes
				any_faction_backer = {
					faction = faction_separatist
					pf_setup_rebel_effect = yes
				}
			}
			liege = {
				set_character_flag = faction_separatist_war
				reverse_war = {
					target = ROOT
					casus_belli = cb_faction_independence
					faction = faction_separatist
				}
			}
		}
		ai_will_do = {
			factor = 0
		}
	}
	
	faction_overthrow_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_overthrow
			OR = {
				NOT = { has_character_flag = faction_overthrow_ultimatum_taken }
				had_character_flag = { flag = faction_overthrow_ultimatum_taken days = 7 }
			}
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			log = "[Root.GetTitledName] has issued a nomadic Overthrow ultimatum to [Root.Liege.GetTitledName]"
			liege = {
				letter_event = { id = 8210 days = 3 tooltip = EVTTOOLTIP8005 }
			}
			hidden_tooltip = {
				set_character_flag = faction_overthrow_ultimatum_taken
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				NOT = { faction_power = { faction = faction_overthrow power = 0.75 } }
			}
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0
				liege = {
					war = yes
					has_character_flag = has_current_revolt
				}
			}		
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								NOT = { using_cb = depose_liege }
								NOT = { using_cb = overthrow_ruler }
								NOT = { using_cb = overthrow_ruler_no_calls }
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
									using_cb = claim_all
									using_cb = claim
									using_cb = other_claim
								}
							}
						}
					}
				}
			}
		}
	}

	faction_increase_council_power_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_increase_council_power
			OR = {
				NOT = { has_character_flag = faction_council_power_ultimatum_taken }
				had_character_flag = { flag = faction_council_power_ultimatum_taken days = 7 }
			}
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
		}
		
		effect = {
			liege = {
				letter_event = { id = 8215 days = 3 tooltip = EVTTOOLTIP8005 }
			}
			hidden_tooltip = {
				set_character_flag = faction_council_power_ultimatum_taken
			}
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				NOT = { 
					faction_power = {
						faction = faction_increase_council_power
						power = 0.75
					}
				}
			}			
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_increase_council_power
						power = 1.0
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_increase_council_power
						power = 1.5
					}
				}
			}			
			
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								NOT = { using_cb = depose_liege }
								NOT = { using_cb = overthrow_ruler }
								NOT = { using_cb = overthrow_ruler_no_calls }
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
									using_cb = claim_all
									using_cb = claim
									using_cb = other_claim
								}
							}
						}
					}
				}
			}
		}
	}
	
	faction_succ_seniority_prepare = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_succ_seniority
			NOT = { has_character_flag = civil_war_faction_leader }
			NOT = { has_character_flag = civil_war_faction_member }
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			set_character_flag = demands_seniority
			clr_character_flag = demands_primogeniture
			clr_character_flag = demands_gavelkind
			clr_character_flag = demands_feudal_elective
			# allow the faction leader to now take the 'Make Ultimatum to Liege' decision
			# and set the timer so the AI doesn't use the decision for 30 days (unless everyone has joined)
			custom_tooltip = {
				text = MAY_TAKE_ULTIMATUM_DECISION
				hidden_tooltip = {
					set_character_flag = civil_war_faction_leader
					add_character_modifier = {
						name = declare_civil_war_timer
						duration = 30
						hidden = yes
					}
				}
			}
			# invite all other vassals to join the coming civil war
			liege = {
				custom_tooltip = { text = INVITE_TO_JOIN_CIVIL_WAR }
				hidden_tooltip = {
					any_vassal = {
						limit = { NOT = { in_faction = faction_succ_seniority } }
						letter_event = { id = PlusFaction.415 }
					}
					any_vassal = {
						limit = { in_faction = faction_succ_seniority }
						set_character_flag = civil_war_faction_member
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}			
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0
				NOT = { 
					faction_power = {
						faction = faction_succ_seniority
						power = 0.75
					}
				}
			}			
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_seniority
						power = 1.0
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_seniority
						power = 1.5
					}
				}
			}
			modifier = {
				factor = 0
				liege = {
					war = yes
					has_character_flag = has_current_revolt
				}
			}
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								attacker = { NOT = { same_realm = ROOT } }
							}
							AND = {
								any_defender = { character = PREV }
								using_cb = crusade
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
								}
							}
							AND = {
								any_attacker = { character = PREV }
								using_cb = crusade
							}
						}
					}
				}
			}
		}
	}
	
	faction_succ_primogeniture_prepare = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_succ_primogeniture
			NOT = { has_character_flag = civil_war_faction_leader }
			NOT = { has_character_flag = civil_war_faction_member }
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			clr_character_flag = demands_seniority
			set_character_flag = demands_primogeniture
			clr_character_flag = demands_gavelkind
			clr_character_flag = demands_feudal_elective
			# allow the faction leader to now take the 'Make Ultimatum to Liege' decision
			# and set the timer so the AI doesn't use the decision for 30 days (unless everyone has joined)
			custom_tooltip = {
				text = MAY_TAKE_ULTIMATUM_DECISION
				hidden_tooltip = {
					set_character_flag = civil_war_faction_leader
					add_character_modifier = {
						name = declare_civil_war_timer
						duration = 30
						hidden = yes
					}
				}
			}
			# invite all other vassals to join the coming civil war
			liege = {
				custom_tooltip = { text = INVITE_TO_JOIN_CIVIL_WAR }
				hidden_tooltip = {
					any_vassal = {
						limit = { NOT = { in_faction = faction_succ_primogeniture } }
						letter_event = { id = PlusFaction.415 }
					}
					any_vassal = {
						limit = { in_faction = faction_succ_primogeniture }
						set_character_flag = civil_war_faction_member
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			modifier = {
				factor = 0
				NOT = { 
					faction_power = {
						faction = faction_succ_primogeniture
						power = 0.75
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_primogeniture
						power = 1.0
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_primogeniture
						power = 1.5
					}
				}
			}
			modifier = {
				factor = 0
				liege = {
					war = yes
					has_character_flag = has_current_revolt
				}
			}
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								attacker = { NOT = { same_realm = ROOT } }
							}
							AND = {
								any_defender = { character = PREV }
								using_cb = crusade
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
								}
							}
							AND = {
								any_attacker = { character = PREV }
								using_cb = crusade
							}
						}
					}
				}
			}
		}
	}
	
	faction_succ_gavelkind_prepare = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_succ_gavelkind
			NOT = { has_character_flag = civil_war_faction_leader }
			NOT = { has_character_flag = civil_war_faction_member }
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			clr_character_flag = demands_seniority
			clr_character_flag = demands_primogeniture
			set_character_flag = demands_gavelkind
			clr_character_flag = demands_feudal_elective
			# allow the faction leader to now take the 'Make Ultimatum to Liege' decision
			# and set the timer so the AI doesn't use the decision for 30 days (unless everyone has joined)
			custom_tooltip = {
				text = MAY_TAKE_ULTIMATUM_DECISION
				hidden_tooltip = {
					set_character_flag = civil_war_faction_leader
					add_character_modifier = {
						name = declare_civil_war_timer
						duration = 30
						hidden = yes
					}
				}
			}
			# invite all other vassals to join the coming civil war
			liege = {
				custom_tooltip = { text = INVITE_TO_JOIN_CIVIL_WAR }
				hidden_tooltip = {
					any_vassal = {
						limit = { NOT = { in_faction = faction_succ_gavelkind } }
						letter_event = { id = PlusFaction.415 }
					}
					any_vassal = {
						limit = { in_faction = faction_succ_gavelkind }
						set_character_flag = civil_war_faction_member
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			modifier = {
				factor = 0
				NOT = { 
					faction_power = {
						faction = faction_succ_gavelkind
						power = 0.75
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_gavelkind
						power = 1.0
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_gavelkind
						power = 1.5
					}
				}
			}
			modifier = {
				factor = 0
				liege = {
					war = yes
					has_character_flag = has_current_revolt
				}
			}
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								attacker = { NOT = { same_realm = ROOT } }
							}
							AND = {
								any_defender = { character = PREV }
								using_cb = crusade
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
								}
							}
							AND = {
								any_attacker = { character = PREV }
								using_cb = crusade
							}
						}
					}
				}
			}
		}
	}

	faction_succ_feudal_elective_prepare = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_succ_feudal_elective	
			NOT = { has_character_flag = civil_war_faction_leader }
			NOT = { has_character_flag = civil_war_faction_member }
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				hidden_tooltip = { pf_pending_civil_war_trigger = no }
			}
			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt
					hidden_tooltip = {
						in_revolt = no
						liege_before_war = {
							in_revolt = no
							liege_before_war = {
								in_revolt = no
							}
						}
					}
				}
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
		}
		effect = {
			clr_character_flag = demands_seniority
			clr_character_flag = demands_primogeniture
			clr_character_flag = demands_gavelkind
			set_character_flag = demands_feudal_elective
			# allow the faction leader to now take the 'Make Ultimatum to Liege' decision
			# and set the timer so the AI doesn't use the decision for 30 days (unless everyone has joined)
			custom_tooltip = {
				text = MAY_TAKE_ULTIMATUM_DECISION
				hidden_tooltip = {
					set_character_flag = civil_war_faction_leader
					add_character_modifier = {
						name = declare_civil_war_timer
						duration = 30
						hidden = yes
					}
				}
			}
			# invite all other vassals to join the coming civil war
			liege = {
				custom_tooltip = { text = INVITE_TO_JOIN_CIVIL_WAR }
				hidden_tooltip = {
					any_vassal = {
						limit = { NOT = { in_faction = faction_succ_feudal_elective } }
						letter_event = { id = PlusFaction.415 }
					}
					any_vassal = {
						limit = { in_faction = faction_succ_feudal_elective }
						set_character_flag = civil_war_faction_member
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				ai_not_busy_trigger = no
			}
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			modifier = {
				factor = 0
				NOT = { 
					faction_power = {
						faction = faction_succ_feudal_elective
						power = 0.75
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_feudal_elective
						power = 1.0
					}
				}
			}	
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_succ_feudal_elective
						power = 1.5
					}
				}
			}
			modifier = {
				factor = 0
				liege = {
					war = yes
					has_character_flag = has_current_revolt
				}
			}
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								attacker = { NOT = { same_realm = ROOT } }
							}
							AND = {
								any_defender = { character = PREV }
								using_cb = crusade
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
								}
							}
							AND = {
								any_attacker = { character = PREV }
								using_cb = crusade
							}
						}
					}
				}
			}
		}
	}

	faction_powerful_vassal_takeover_ultimatum = {
		is_high_prio = yes
		ai_check_interval = 3
		potential = {
			leads_faction = faction_powerful_vassal_takeover
			OR = {
				NOT = { has_character_flag = faction_powerful_vassal_takeover_ultimatum_taken }
				had_character_flag = { flag = faction_powerful_vassal_takeover_ultimatum_taken days = 7 }
			}
		}
		allow = {
			war = no
			prisoner = no
			liege = {
				NOT = { war_with = ROOT }
				NOT = { reverse_has_truce = ROOT }
			}
			NOT = {
				any_realm_title = {
					NOT = { higher_tier_than = count }
					is_occupied = yes
				}
			}
			liege = {
				OR = {
					independent = yes
					AND = {
						will_liege_enforce_peace = no
						has_liege_enforced_peace = no
					}
				}
			}
		}
		
		effect = {
			liege = {
				letter_event = { id = 8220 days = 3 tooltip = EVTTOOLTIP8005 }
			}
			hidden_tooltip = {
				set_character_flag = faction_powerful_vassal_takeover_ultimatum_taken
			}
		}
		
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				e_placeholder = {
					NOT = { had_title_flag = { flag = startup days = 730 } }
				}
			}
			modifier = {
				factor = 0
				NOT = { 
					faction_power = {
						faction = faction_powerful_vassal_takeover
						power = 0.75
					}
				}
			}			
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_powerful_vassal_takeover
						power = 1.0
					}
				}
			}
			modifier = {
				factor = 0.1
				NOT = { 
					faction_power = {
						faction = faction_powerful_vassal_takeover
						power = 1.5
					}
				}
			}			
			
			modifier = {
				factor = 0.5 # Slow it down a bit
			}
			
			modifier = {
				factor = 0
				liege = {
					any_war = {
						OR = {
							AND = {
								defender = { character = PREV }
								NOT = { using_cb = depose_liege }
								NOT = { using_cb = overthrow_ruler }
								NOT = { using_cb = overthrow_ruler_no_calls }
							}
							AND = {
								attacker = { character = PREV }
								OR = {
									using_cb = invasion
									using_cb = holy_war
									using_cb = tribal_invasion
									using_cb = viking_invasion
									using_cb = claim_all
									using_cb = claim
									using_cb = other_claim
								}
							}
						}
					}
				}
			}
		}
	}
}

