targeted_decisions = {

	recruit_faction_member = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			pf_leader_trigger = yes
		}

		potential = {
			same_liege = FROM
			is_playable = yes
			is_adult = yes
			independent = no
			prisoner = no
			pf_leader_trigger = no
			is_incapable = no

			NOR = {
				is_primary_heir = liege

				has_opinion_modifier = {
					name = opinion_coerced_into_leaving_faction
					who = liege
				}
			}

			trigger_if = {
				limit = { FROM = { leads_faction = faction_court } }
				NOT = { in_faction = faction_court }
			}
			trigger_else_if = {
				limit = { FROM = { leads_faction = faction_prosperity } }
				NOT = { in_faction = faction_prosperity }
			}
			trigger_else_if = {
				limit = { FROM = { leads_faction = faction_glory } }
				NOT = { in_faction = faction_glory }
			}
			trigger_else = {
				FROM = { leads_faction = faction_tradition }

				religion = FROM

				NOR = {
					in_faction = faction_tradition
					trait = cynical
					trait = excommunicated
				}
			}
		}

		allow = {
			NOT = { is_rival = FROM }
			is_ill = no

			custom_tooltip = {
				text = IS_NOT_BUSY

				war = no
				in_command_trigger = no
				is_inaccessible_trigger = no
			}

			custom_tooltip = {
				text = NOT_RECENTLY_RECRUITED
				NOT = { has_character_modifier = recruit_faction_target_timer }
			}

			custom_tooltip = {
				text = NOT_REBUFFED_RECRUIT

				NOT = {
					reverse_has_opinion_modifier = {
						name = opinion_rebuffed_recruitment
						who = FROM
					}
				}
			}

			FROM = {
				is_ill = no

				custom_tooltip = {
					text = IS_NOT_BUSY

					war = no
					in_command_trigger = no
					is_inaccessible_trigger = no
				}

				custom_tooltip = {
					text = NOT_RECENTLY_RECRUIT
					NOT = { has_character_modifier = recruit_faction_timer }
				}
			}
		}

		effect = {
			character_event = {
				id = PlusFaction.111
				days = 15
				tooltip = ATTEMPT_RECRUIT_FACTION
			}

			add_character_modifier = {
				name = recruit_faction_target_timer
				years = 1
				hidden = yes
			}

			FROM = {
				character_event = { id = PlusFaction.110 }

				add_character_modifier = {
					name = do_not_disturb
					days = 15
					hidden = yes
				}

				add_character_modifier = {
					name = recruit_faction_timer
					years = 1
					hidden = yes
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				opinion = {
					who = FROM
					value >= 0
				}

				reverse_opinion = {
					who = FROM
					value >= 0
				}
			}

			mult_modifier = {
				factor = 0.5

				pf_member_trigger = yes

				FROM = {
					NOR = {
						trait = ambitious
						trait = brave
						trait = diligent
					}
				}
			}

			mult_modifier = {
				factor = 0.1

				FROM = {
					OR = {
						trait = content
						trait = craven
						trait = humble
					}
				}
			}

			mult_modifier = {
				factor = 10

				OR = {
					is_close_relative = FROM

					opinion = {
						who = FROM
						value >= 50
					}
				}
			}
		}
	}

	court_faction_member = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			pf_member_trigger = yes
		}

		potential = {
			same_liege = FROM
			pf_from_faction_backer_trigger = yes
			is_playable = yes
			is_adult = yes
			ai = yes
			independent = no
			prisoner = no
			is_incapable = no
		}

		allow = {
			NOT = { is_rival = FROM }
			is_ill = no

			custom_tooltip = {
				text = IS_NOT_BUSY

				war = no
				in_command_trigger = no
				is_inaccessible_trigger = no
			}

			custom_tooltip = {
				text = NOT_RECENTLY_COURTED
				NOT = { has_character_modifier = court_faction_target_timer }
			}

			custom_tooltip = {
				text = NOT_BAD_COURT_RECENT

				opinion = {
					who = FROM
					value >= -50
				}

				NOT = {
					has_opinion_modifier = {
						name = unpleasant_meeting
						who = ROOT
					}
				}
			}

			FROM = {
				is_ill = no

				custom_tooltip = {
					text = IS_NOT_BUSY

					war = no
					in_command_trigger = no
					is_inaccessible_trigger = no
				}

				custom_tooltip = {
					text = NOT_RECENTLY_COURT
					NOT = { has_character_modifier = court_faction_timer }
				}
			}
		}

		effect = {
			add_character_modifier = {
				name = court_faction_target_timer
				years = 1
				hidden = yes
			}

			FROM = {
				show_scope_change = no

				character_event = {
					id = PlusFaction.125
					tooltip = ATTEMPT_COURT_FACTION
				}

				add_character_modifier = {
					name = do_not_disturb
					days = 15
					hidden = yes
				}

				add_character_modifier = {
					name = court_faction_timer
					years = 1
					hidden = yes
				}
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				FROM = {
					NOR = {
						trait = shy
						trait = paranoid
						trait = slothful
					}
				}

				pf_leader_trigger = no

				opinion = {
					who = FROM
					value < 50
				}
			}

			mult_modifier = {
				factor = 10
				FROM = { trait = gregarious }
			}

			mult_modifier = {
				factor = 2

				FROM = {
					OR = {
						trait = ambitious
						trait = diligent
						diplomacy >= 15
					}
				}
			}

			mult_modifier = {
				factor = 2
				higher_real_tier_than = COUNT
			}

			mult_modifier = {
				factor = 2
				higher_real_tier_than = DUKE
			}

			mult_modifier = {
				factor = 0.5
				lower_real_tier_than = COUNT
			}

			mult_modifier = {
				factor = 0.5
				FROM = { diplomacy < 8 }
			}

			mult_modifier = {
				factor = 0.5

				opinion = {
					who = FROM
					value < -25
				}
			}
		}
	}

	ask_claimant_support = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			leads_faction = faction_pretender
		}

		potential = {
			same_liege = FROM
			is_ruler = yes
			is_adult = yes
			is_landed = yes
			ai = yes
			independent = no
			prisoner = no
			is_incapable = no

			FROM = {
				supported_claimant = {
					NOT = { character = ROOT }
				}

				NOT = {
					any_faction_backer = {
						in_faction = faction_pretender
						character = ROOT
					}
				}
			}

			NOT = {
				has_opinion_modifier = {
					name = opinion_coerced_into_leaving_faction
					who = liege
				}
			}
		}

		allow = {
			ROOT = {
				is_ill = no

				custom_tooltip = {
					text = IS_NOT_BUSY

					war = no
					in_command_trigger = no
					is_inaccessible_trigger = no
				}

				custom_tooltip = {
					text = NOT_HEIR_CLAIMED_TITLE

					NOT = {
						FROM = {
							supported_claimant_title = {
								current_heir = { character = ROOT }
							}
						}
					}
				}

				NOT = { is_rival = FROM }

				custom_tooltip = {
					text = NOT_RIVAL_SUPPORTED_CLAIMANT
					FROM = { supported_claimant = { NOT = { is_rival = PREVPREV } } }
				}

				custom_tooltip = {
					text = SAME_CULTURE_GROUP_SUPPORTED_CLAIMANT
					FROM = { supported_claimant = { culture_group = PREVPREV } }
				}

				custom_tooltip = {
					text = SAME_RELIGION_SUPPORTED_CLAIMANT
					FROM = { supported_claimant = { religion = PREVPREV } }
				}
			}

			FROM = {
				is_ill = no

				custom_tooltip = {
					text = IS_NOT_BUSY

					war = no
					in_command_trigger = no
					is_inaccessible_trigger = no
				}

				custom_tooltip = {
					text = NOT_RECENTLY_ASK_SUPPORT
					NOT = { has_character_modifier = ask_claimant_support_timer }
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				character_event = {
					id = PlusFaction.130
					tooltip = ASK_SUPPORT_CLAIMANT
				}

				add_character_modifier = {
					name = do_not_disturb
					days = 15
					hidden = yes
				}

				add_character_modifier = {
					name = ask_claimant_support_timer
					months = 1
					hidden = yes
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				NOR = {
					leads_faction = faction_pretender
					in_faction = faction_pretender
				}

				opinion = {
					who = FROM
					value >= 0
				}
			}

			mult_modifier = {
				factor = 5
				higher_tier_than = COUNT
			}

			mult_modifier = {
				factor = 0
				lower_tier_than = COUNT
			}

			mult_modifier = {
				factor = 5

				OR = {
					is_close_relative = FROM

					opinion = {
						who = FROM
						value >= 50
					}
				}
			}
		}
	}

	invite_claimant_to_court = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			leads_faction = faction_pretender
			ai = yes
			war = no
		}

		potential = {
			FROM = {
				supported_claimant = { character = ROOT }
				same_liege = ROOT
			}

			ai = yes
			is_ruler = no
			is_adult = yes

			OR = {
				trait = ambitious
				trait = proud
				trait = greedy
				trait = envious
				trait = wroth
				trait = deceitful
			}

			NOR = {
				trait = content
				trait = humble
			}

			opinion = {
				who = liege
				value < 0
			}
		}

		allow = {
			war = no
			prisoner = no

			opinion = {
				who = FROM
				value >= 0
			}
		}

		effect = {
			any_spouse = {
				limit = {
					prisoner = no
					is_ruler = no
				}

				move_character = FROM
			}

			any_consort = {
				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

			trigger = {
				FROM = {
					faction_power = {
						faction = faction_pretender
						power >= 0.3
					}
				}
			}
		}
	}

	vet_faction_claimant = {
		ai_target_filter = realm
		filter = realm
		ai_check_interval = 12

		only_playable = yes

		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
			is_incapable = no
		}

		effect = {
			set_character_flag = supported_pretender_faction
			letter_event = { id = PlusFaction.155 }
		}

		ai_will_do = {
			factor = 1
		}
	}
}

plot_decisions = {

	hold_court_faction_meeting = {
		is_high_prio = yes

		ai = no

		potential = {
			leads_faction = faction_court

			num_of_faction_backers = {
				faction = faction_court
				value >= 1
			}

			pf_war_trait_trigger = no
			total_years_played > 2

			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

				pf_pending_civil_war_trigger = no

				trigger_if = {
					limit = { has_character_flag = faction_meeting }

					OR = {
						had_character_flag = {
							flag = faction_meeting
							years >= 3
						}

						AND = {
							had_character_flag = {
								flag = faction_meeting
								years >= 2
							}

							liege = { has_character_flag = faction_court_angry }
						}
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = CUSTOMTOOLTIP51

				set_character_flag = faction_meeting_called
				clr_character_flag = faction_meeting_postponed
				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

		ai = no

		potential = {
			leads_faction = faction_prosperity

			num_of_faction_backers = {
				faction = faction_prosperity
				value >= 1
			}

			pf_war_trait_trigger = no
			total_years_played > 2

			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

				pf_pending_civil_war_trigger = no

				trigger_if = {
					limit = { has_character_flag = faction_meeting }

					OR = {
						had_character_flag = {
							flag = faction_meeting
							years >= 3
						}

						AND = {
							had_character_flag = {
								flag = faction_meeting
								years >= 2
							}

							liege = { has_character_flag = faction_prosperity_angry }
						}
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = CUSTOMTOOLTIP52

				set_character_flag = faction_meeting_called
				clr_character_flag = faction_meeting_postponed
				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

		ai = no

		potential = {
			leads_faction = faction_glory

			num_of_faction_backers = {
				faction = faction_glory
				value >= 1
			}

			pf_war_trait_trigger = no
			total_years_played > 2

			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

				pf_pending_civil_war_trigger = no

				trigger_if = {
					limit = { has_character_flag = faction_meeting }

					OR = {
						had_character_flag = {
							flag = faction_meeting
							years >= 3
						}

						AND = {
							had_character_flag = {
								flag = faction_meeting
								years >= 2
							}

							liege = { has_character_flag = faction_glory_angry }
						}
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = CUSTOMTOOLTIP53

				set_character_flag = faction_meeting_called
				clr_character_flag = faction_meeting_postponed
				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

		ai = no

		potential = {
			leads_faction = faction_tradition

			num_of_faction_backers = {
				faction = faction_tradition
				value >= 1
			}

			pf_war_trait_trigger = no
			total_years_played > 2

			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

				pf_pending_civil_war_trigger = no

				trigger_if = {
					limit = { has_character_flag = faction_meeting }

					OR = {
						had_character_flag = {
							flag = faction_meeting
							years >= 3
						}

						AND = {
							had_character_flag = {
								flag = faction_meeting
								years >= 2
							}

							liege = { has_character_flag = faction_tradition_angry }
						}
					}
				}
			}
		}

		effect = {
			custom_tooltip = {
				text = CUSTOMTOOLTIP54

				set_character_flag = faction_meeting_called
				clr_character_flag = faction_meeting_postponed
				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 = no

		potential = {
			always = no # Replaced by follow-up event to preparation decision

			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

			trigger_if = {
				limit = { has_character_flag = faction_regular_ultimatum_taken }

				had_character_flag = {
					flag = faction_regular_ultimatum_taken
					days >= 7
				}
			}
		}

		allow = {
			NOT = { war_with = liege }

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					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 = {
					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 = {
					show_scope_change = no

					letter_event = {
						id = PlusFaction.470
						tooltip = SEND_REGULAR_ULTIMATUM
					}
				}
			}
			else = {
				log = "[Root.GetTitledName] has issued a regular faction ultimatum to [Root.Liege.GetTitledName]"

				liege = {
					show_scope_change = no

					letter_event = {
						id = PlusFaction.400
						tooltip = SEND_REGULAR_ULTIMATUM
					}
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Still has the power to have the revolt
				trigger_if = {
					limit = { leads_faction = faction_court }

					pf_not_regular_faction_war_trigger = no
					faction_power = { faction = faction_court power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_prosperity }

					pf_not_regular_faction_war_trigger = no
					faction_power = { faction = faction_prosperity power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_glory }

					pf_not_regular_faction_war_trigger = no
					faction_power = { faction = faction_glory power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_tradition }

					pf_not_regular_faction_war_trigger = no
					faction_power = { faction = faction_tradition power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_succ_seniority }

					has_character_flag = demands_seniority
					faction_power = { faction = faction_succ_seniority power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_succ_primogeniture }

					has_character_flag = demands_primogeniture
					faction_power = { faction = faction_succ_primogeniture power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_succ_gavelkind }

					has_character_flag = demands_gavelkind
					faction_power = { faction = faction_succ_gavelkind power >= 0.75 }
				}
				trigger_else = {
					leads_faction = faction_succ_feudal_elective
					has_character_flag = demands_feudal_elective
					faction_power = { faction = faction_succ_feudal_elective power >= 0.75 }
				}

				# AI will not take war while 30-day timer lasts
				# unless there are no vassals left to join the faction
				trigger_if = {
					limit = { has_character_modifier = declare_civil_war_timer }

					liege = {
						NOT = {
							any_vassal = {
								pf_root_faction_backer_trigger = no
								has_character_flag = will_join_civil_war
							}
						}
					}
				}
			}
		}
	}

	faction_begin_civil_war = {
		is_high_prio = yes

		ai = no

		potential = {
			always = no # Replaced by follow-up event to preparation decision
			independent = no
			pf_leader_trigger = yes
			pf_has_demands_trigger = no
			has_character_flag = civil_war_faction_leader

			NOR = {
				has_character_flag = preparing_claimant_faction_war
				has_character_flag = preparing_religious_faction_war
			}
		}

		allow = {
			NOT = { war_with = liege }

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

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

				letter_event = { id = PlusFaction.406 }
			}

			character_event = {
				id = PlusFaction.399 # Clear flags
				days = 1
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				# Still has the power to have the revolt
				trigger_if = {
					limit = { leads_faction = faction_court }
					faction_power = { faction = faction_court power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_prosperity }
					faction_power = { faction = faction_prosperity power >= 0.75 }
				}
				trigger_else_if = {
					limit = { leads_faction = faction_glory }
					faction_power = { faction = faction_glory power >= 0.75 }
				}
				trigger_else = {
					leads_faction = faction_tradition
					faction_power = { faction = faction_tradition power >= 0.75 }
				}

				# AI will not take war while 30-day timer lasts
				# unless there are no vassals left to join the faction
				trigger_if = {
					limit = { has_character_modifier = declare_civil_war_timer }

					liege = {
						NOT = {
							any_vassal = {
								pf_root_faction_backer_trigger = no
								has_character_flag = will_join_civil_war
							}
						}
					}
				}
			}
		}
	}

	faction_claimant_prepare = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_pretender

			NOR = {
				has_character_flag = civil_war_faction_leader
				has_character_flag = civil_war_faction_member
			}
		}

		allow = {
			faction_power = {
				faction = faction_pretender
				power >= 0.5
			}

			war = no
			has_regent = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			capital_holding = {
				is_occupied = no
			}
		}

		effect = {
			set_character_flag = preparing_claimant_faction_war
			set_character_flag = civil_war_faction_leader

			character_event = {
				id = PlusFaction.463 # preparing_claimant_faction_war flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.461 # civil_war_faction_leader flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.417 # Follow-up event to present ultimatum
				days = 7
			}

			# Invite all other vassals to join the coming civil war
			custom_tooltip = {
				text = INVITE_TO_JOIN_CIVIL_WAR

				liege = {
					any_vassal = {
						limit = { NOT = { in_faction = faction_pretender } }
						letter_event = { id = PlusFaction.422 }
					}
				}
			}

			any_faction_backer = {
				faction = faction_pretender

				set_character_flag = civil_war_faction_member

				character_event = {
					id = PlusFaction.461 # civil_war_faction_leader flag removal
					days = 1
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				total_years_played >= 2
				supported_claimant_title = { is_contested = no }

				trigger_if = {
					limit = {
						faction_power = {
							faction = faction_pretender
							power < 1.0
						}
					}

					faction_power = {
						faction = faction_pretender
						power >= 0.75
					}

					OR = {
						martial >= 15
						trait = brave
						trait = lunatic
						trait = possessed
						trait = wroth
					}
				}

				liege = {
					any_war = {
						trigger_if = {
							limit = {
								defender = { character = PREVPREV }
							}

							OR = {
								using_cb = depose_liege
								using_cb = overthrow_ruler
								using_cb = overthrow_ruler_no_calls
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = cb_faction_overthrow_ruler
							}
						}
						trigger_else_if = {
							limit = {
								attacker = { character = PREVPREV }
							}

							NOR = {
								using_cb = invasion
								using_cb = holy_war
								using_cb = tribal_invasion
								using_cb = manifest_destiny_invasion
								using_cb = viking_invasion
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_pretender
					power < 1
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_pretender
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_pretender
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_pretender
					power >= 2.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_pretender
					power >= 3.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_pretender
					power = 4.0
				}
			}
		}
	}

	faction_religious_prepare = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_religious

			NOR = {
				has_character_flag = civil_war_faction_leader
				has_character_flag = civil_war_faction_member
			}
		}

		allow = {
			faction_power = {
				faction = faction_religious
				power >= 0.5
			}

			war = no
			has_regent = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					hidden_tooltip = { pf_war_flag_trigger = no }
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			capital_holding = {
				is_occupied = no
			}
		}

		effect = {
			set_character_flag = preparing_religious_faction_war

			character_event = {
				id = PlusFaction.464 # preparing_religious_faction_war flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.418 # Follow-up event to present ultimatum
				days = 7
			}

			# Invite all other vassals to join the coming civil war
			custom_tooltip = {
				text = INVITE_TO_JOIN_CIVIL_WAR

				liege = {
					any_vassal = {
						limit = {
							religion = ROOT
							NOT = { in_faction = faction_religious }
						}

						letter_event = { id = Plus.255 }
					}
				}
			}

			any_faction_backer = {
				faction = faction_religious

				set_character_flag = civil_war_faction_member

				character_event = {
					id = PlusFaction.461 # civil_war_faction_leader flag removal
					days = 1
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				total_years_played >= 2

				trigger_if = {
					limit = {
						faction_power = {
							faction = faction_religious
							power < 1.0
						}
					}

					faction_power = {
						faction = faction_religious
						power >= 0.75
					}

					OR = {
						martial >= 15
						trait = brave
						trait = lunatic
						trait = possessed
						trait = wroth
					}
				}

				liege = {
					any_war = {
						trigger_if = {
							limit = {
								defender = { character = PREVPREV }
							}

							OR = {
								using_cb = depose_liege
								using_cb = overthrow_ruler
								using_cb = overthrow_ruler_no_calls
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = cb_faction_overthrow_ruler
							}
						}
						trigger_else_if = {
							limit = {
								attacker = { character = PREVPREV }
							}

							NOR = {
								using_cb = invasion
								using_cb = holy_war
								using_cb = tribal_invasion
								using_cb = manifest_destiny_invasion
								using_cb = viking_invasion
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_religious
					power < 1
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_religious
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_religious
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_religious
					power >= 2.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_religious
					power >= 3.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_religious
					power >= 4.0
				}
			}
		}
	}

	faction_religious_ultimatum = {
		is_high_prio = yes

		ai = no

		potential = {
			always = no # Replaced with follow-up event to preparation decision
			leads_faction = faction_religious
			has_character_flag = preparing_religious_faction_war
			has_character_flag = civil_war_faction_leader

			trigger_if = {
				limit = { has_character_flag = faction_religious_ultimatum_taken }

				had_character_flag = {
					flag = faction_religious_ultimatum_taken
					days >= 7
				}
			}
		}

		allow = {
			NOT = { war_with = liege }

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					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_religious_faction_war
			set_character_flag = faction_religious_ultimatum_taken

			liege = {
				show_scope_change = no

				letter_event = {
					id = Plus.250
					tooltip = SEND_RELIGIOUS_ULTIMATUM
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				# Still has the power to have the revolt
				faction_power = {
					faction = faction_religious
					power >= 0.75
				}

				# AI will not take war while 30-day timer lasts
				# unless there are no vassals left to join the faction
				trigger_if = {
					limit = { has_character_modifier = declare_civil_war_timer }

					liege = {
						NOT = {
							any_vassal = {
								religion = ROOT
								NOT = { in_faction = faction_religious }
								has_character_flag = will_join_civil_war
							}
						}
					}
				}
			}
		}
	}

	faction_separatist_war = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_separatist
			NOT = { has_character_modifier = faction_independence_ultimatum_timer }
		}

		allow = {
			faction_power = {
				faction = faction_separatist
				power >= 0.5
			}

			war = no
			has_regent = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			NOT = {
				any_realm_title = {
					hidden_trigger = { lower_real_tier_than = DUKE }
					is_occupied = yes
				}
			}
		}

		effect = {
			# TODO: Send ultimatum
			hidden_effect = {
				set_character_flag = original_war_liege
				pf_setup_rebel_effect = yes

				any_faction_backer = {
					faction = faction_separatist
					pf_setup_rebel_effect = yes
				}
			}

			liege = {
				show_scope_change = no

				set_character_flag = faction_separatist_war

				reverse_war = {
					target = ROOT
					casus_belli = cb_faction_independence
					faction = faction_separatist
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				total_years_played >= 2

				trigger_if = {
					limit = {
						faction_power = {
							faction = faction_separatist
							power < 1.0
						}
					}

					faction_power = {
						faction = faction_separatist
						power >= 0.75
					}

					OR = {
						martial >= 15
						trait = brave
						trait = lunatic
						trait = possessed
						trait = wroth
					}
				}

				liege = {
					any_war = {
						trigger_if = {
							limit = {
								defender = { character = PREVPREV }
							}

							OR = {
								using_cb = depose_liege
								using_cb = overthrow_ruler
								using_cb = overthrow_ruler_no_calls
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = cb_faction_overthrow_ruler
							}
						}
						trigger_else_if = {
							limit = {
								attacker = { character = PREVPREV }
							}

							NOR = {
								using_cb = invasion
								using_cb = holy_war
								using_cb = tribal_invasion
								using_cb = manifest_destiny_invasion
								using_cb = viking_invasion
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_separatist
					power < 1
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_separatist
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_separatist
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_separatist
					power >= 2.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_separatist
					power >= 3.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_separatist
					power >= 4.0
				}
			}
		}
	}

	faction_succ_seniority_prepare = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_succ_seniority

			NOR = {
				has_character_flag = civil_war_faction_leader
				has_character_flag = civil_war_faction_member
			}
		}

		allow = {
			faction_power = {
				faction = faction_succ_seniority
				power >= 0.5
			}

			war = no
			prisoner = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			NOT = {
				any_realm_title = {
					hidden_trigger = { lower_real_tier_than = DUKE }
					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
			set_character_flag = civil_war_faction_leader

			character_event = {
				id = PlusFaction.461 # civil_war_faction_leader flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.417 # Follow-up event to present ultimatum
				days = 7
			}

			# Invite all other vassals to join the coming civil war
			custom_tooltip = {
				text = INVITE_TO_JOIN_CIVIL_WAR

				liege = {
					any_vassal = {
						limit = { is_playable = yes }

						if = {
							limit = { in_faction = faction_succ_seniority }

							set_character_flag = civil_war_faction_member

							character_event = {
								id = PlusFaction.461 # civil_war_faction_leader flag removal
								days = 1
							}
						}
						else = {
							letter_event = { id = PlusFaction.415 }
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				total_years_played >= 2

				faction_power = {
					faction = faction_succ_seniority
					power > 0.75
				}

				liege = {
					NAND = {
						war = yes
						has_character_flag = has_current_revolt
					}

					any_war = {
						trigger_if = {
							limit = {
								OR = {
									any_defender = { character = PREVPREV }
									any_attacker = { character = PREVPREV }
								}
							}

							NOR = {
								using_cb = crusade
								using_cb = new_crusade
							}
						}

						trigger_if = {
							limit = {
								defender = { character = PREVPREV }
							}

							attacker = {
								NOT = { same_realm = ROOT }
							}
						}
						trigger_else_if = {
							limit = {
								attacker = { character = PREVPREV }
							}

							NOR = {
								using_cb = invasion
								using_cb = holy_war
								using_cb = tribal_invasion
								using_cb = viking_invasion
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_seniority
					power < 1.0
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_seniority
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_seniority
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_seniority
					power >= 2.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_seniority
					power >= 3.0
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_seniority
					power >= 4.0
				}
			}
		}
	}

	faction_succ_primogeniture_prepare = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_succ_primogeniture

			NOR = {
				has_character_flag = civil_war_faction_leader
				has_character_flag = civil_war_faction_member
			}
		}

		allow = {
			faction_power = {
				faction = faction_succ_primogeniture
				power >= 0.5
			}

			war = no
			prisoner = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			NOT = {
				any_realm_title = {
					hidden_trigger = { lower_real_tier_than = DUKE }
					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
			set_character_flag = civil_war_faction_leader

			character_event = {
				id = PlusFaction.461 # civil_war_faction_leader flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.417 # Follow-up event to present ultimatum
				days = 7
			}

			# Invite all other vassals to join the coming civil war
			custom_tooltip = {
				text = INVITE_TO_JOIN_CIVIL_WAR

				liege = {
					any_vassal = {
						limit = { is_playable = yes }

						if = {
							limit = { in_faction = faction_succ_primogeniture }

							set_character_flag = civil_war_faction_member

							character_event = {
								id = PlusFaction.461 # civil_war_faction_leader flag removal
								days = 1
							}
						}
						else = {
							letter_event = { id = PlusFaction.415 }
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				is_inaccessible_trigger = no
				total_years_played >= 2

				faction_power = {
					faction = faction_succ_primogeniture
					power >= 0.75
				}

				liege = {
					NAND = {
						war = yes
						has_character_flag = has_current_revolt
					}
				}

				any_war = {
					trigger_if = {
						limit = {
							OR = {
								any_defender = { character = PREVPREV }
								any_attacker = { character = PREVPREV }
							}
						}

						NOR = {
							using_cb = crusade
							using_cb = new_crusade
						}
					}

					trigger_if = {
						limit = {
							defender = { character = PREVPREV }
						}

						attacker = {
							NOT = { same_realm = ROOT }
						}
					}
					trigger_else_if = {
						limit = {
							attacker = { character = PREVPREV }
						}

						NOR = {
							using_cb = invasion
							using_cb = holy_war
							using_cb = tribal_invasion
							using_cb = viking_invasion
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_primogeniture
					power < 1
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_primogeniture
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_primogeniture
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_primogeniture
					power >= 2
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_primogeniture
					power >= 3
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_primogeniture
					power >= 4
				}
			}
		}
	}

	faction_succ_gavelkind_prepare = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_succ_gavelkind

			NOR = {
				has_character_flag = civil_war_faction_leader
				has_character_flag = civil_war_faction_member
			}
		}

		allow = {
			faction_power = {
				faction = faction_succ_gavelkind
				power >= 0.5
			}

			war = no
			prisoner = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			NOT = {
				any_realm_title = {
					hidden_trigger = { lower_real_tier_than = DUKE }
					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
			set_character_flag = civil_war_faction_leader

			character_event = {
				id = PlusFaction.461 # civil_war_faction_leader flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.417 # Follow-up event to present ultimatum
				days = 7
			}

			# Invite all other vassals to join the coming civil war
			custom_tooltip = {
				text = INVITE_TO_JOIN_CIVIL_WAR

				liege = {
					any_vassal = {
						limit = { is_playable = yes }

						if = {
							limit = { in_faction = faction_succ_gavelkind }

							set_character_flag = civil_war_faction_member

							character_event = {
								id = PlusFaction.461 # civil_war_faction_leader flag removal
								days = 1
							}
						}
						else = {
							letter_event = { id = PlusFaction.415 }
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				total_years_played >= 2

				faction_power = {
					faction = faction_succ_gavelkind
					power >= 0.75
				}

				liege = {
					NAND = {
						war = yes
						has_character_flag = has_current_revolt
					}

					any_war = {
						trigger_if = {
							limit = {
								OR = {
									any_defender = { character = PREVPREV }
									any_attacker = { character = PREVPREV }
								}
							}

							NOR = {
								using_cb = crusade
								using_cb = new_crusade
							}
						}

						trigger_if = {
							limit = {
								defender = { character = PREVPREV }
							}

							attacker = {
								NOT = { same_realm = ROOT }
							}
						}
						trigger_else_if = {
							limit = {
								attacker = { character = PREVPREV }
							}

							NOR = {
								using_cb = invasion
								using_cb = holy_war
								using_cb = tribal_invasion
								using_cb = viking_invasion
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_gavelkind
					power < 1
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_gavelkind
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_gavelkind
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_gavelkind
					power >= 2
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_gavelkind
					power >= 3
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_gavelkind
					power >= 4
				}
			}
		}
	}

	faction_succ_feudal_elective_prepare = {
		is_high_prio = yes
		ai_check_interval = 3

		only_playable = yes

		potential = {
			leads_faction = faction_succ_feudal_elective

			NOR = {
				has_character_flag = civil_war_faction_leader
				has_character_flag = civil_war_faction_member
			}
		}

		allow = {
			faction_power = {
				faction = faction_succ_feudal_elective
				power >= 0.5
			}

			war = no
			prisoner = no
			NOT = { war_with = liege }
			NOT = { has_truce = liege }
			is_inaccessible_trigger = no

			liege = {
				custom_tooltip = {
					text = HAS_NO_CIVIL_WAR
					pf_war_flag_trigger = no
				}

				trigger_if = {
					limit = { independent = no }

					will_liege_enforce_peace = no
					has_liege_enforced_peace = no
				}
			}

			custom_tooltip = {
				text = NO_PENDING_CIVIL_WAR
				pf_pending_civil_war_trigger = no
			}

			liege_before_war = {
				custom_tooltip = {
					text = emf_faction_ctt_no_liege_in_revolt

					in_revolt = no

					liege_before_war = {
						in_revolt = no

						liege_before_war = {
							in_revolt = no
						}
					}
				}
			}

			NOT = {
				any_realm_title = {
					hidden_trigger = { lower_real_tier_than = DUKE }
					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
			set_character_flag = civil_war_faction_leader

			character_event = {
				id = PlusFaction.461 # civil_war_faction_leader flag removal
				days = 1
			}

			character_event = {
				id = PlusFaction.417 # Follow-up event to present ultimatum
				days = 7
			}

			# Invite all other vassals to join the coming civil war
			custom_tooltip = {
				text = INVITE_TO_JOIN_CIVIL_WAR

				liege = {
					any_vassal = {
						limit = { is_playable = yes }

						if = {
							limit = { in_faction = faction_succ_feudal_elective }

							set_character_flag = civil_war_faction_member

							character_event = {
								id = PlusFaction.461 # civil_war_faction_leader flag removal
								days = 1
							}
						}
						else = {
							letter_event = { id = PlusFaction.415 }
						}
					}
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				total_years_played >= 2

				faction_power = {
					faction = faction_succ_feudal_elective
					power >= 0.75
				}

				liege = {
					NAND = {
						war = yes
						has_character_flag = has_current_revolt
					}

					any_war = {
						trigger_if = {
							limit = {
								OR = {
									any_defender = { character = PREVPREV }
									any_attacker = { character = PREVPREV }
								}
							}

							NOR = {
								using_cb = crusade
								using_cb = new_crusade
							}
						}

						trigger_if = {
							limit = {
								defender = { character = PREVPREV }
							}

							attacker = {
								NOT = { same_realm = ROOT }
							}
						}
						trigger_else_if = {
							limit = {
								attacker = { character = PREVPREV }
							}

							NOR = {
								using_cb = invasion
								using_cb = holy_war
								using_cb = tribal_invasion
								using_cb = viking_invasion
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_feudal_elective
					power < 1
				}
			}

			mult_modifier = {
				factor = 0.5

				faction_power = {
					faction = faction_succ_feudal_elective
					power < 1.25
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_feudal_elective
					power >= 1.5
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_feudal_elective
					power >= 2
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_feudal_elective
					power >= 3
				}
			}

			mult_modifier = {
				factor = 2

				faction_power = {
					faction = faction_succ_feudal_elective
					power >= 4
				}
			}
		}
	}
}