
namespace = emf_faction


character_event = {
	id = emf_faction.1000
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		if = {
			limit = { is_ruler = yes }
			log = "PF STATE DUMP: [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID]):"
		}
		if = {
			limit = { is_ruler = no }
			log = "PF STATE DUMP: courtier: [This.GetTitledName] ([This.GetID]):"
		}
		log = "<<<<<"
		if = {
			limit = {
				pf_war_trait_trigger = no
				pf_in_revolt_trigger = no
			}
			log = "no civil war trait (and not revolting in a PF civil war)"
		}
		if = {
			limit = {
				pf_war_trait_trigger = no
				pf_in_revolt_trigger = yes
			}
			log = "no civil war trait but nevertheless in a PF civil war (likely WAD)"
		}
		if = {
			limit = { trait = pf_rebel }
			if = {
				limit = {
					has_any_opinion_modifier = revolting_against
					pf_in_revolt_trigger = yes
					is_ruler = yes
				}
				log = "trait = pf_rebel"
			}
			if = {
				limit = {
					NOR = {
						has_any_opinion_modifier = revolting_against
						pf_in_revolt_trigger = yes
					}
				}
				log = "WARNING: trait = pf_rebel but neither in revolt nor assigned a revolting_against TOM!"
			}
			if = {
				limit = {
					NOT = { has_any_opinion_modifier = revolting_against }
					pf_in_revolt_trigger = yes
				}
				log = "WARNING: trait = pf_rebel but lacking revolting_against TOM!"
			}
			if = {
				limit = {
					has_any_opinion_modifier = revolting_against
					NOT = { pf_in_revolt_trigger = yes }
				}
				log = "WARNING: trait = pf_rebel but not in revolt!"
			}
			if = {
				limit = { is_ruler = no }
				log = "WARNING: trait = pf_rebel but not a ruler!"
			}
		}
		if = {
			limit = {
				trait = pf_loyalist
				is_ruler = yes
				liege = {
					has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
					any_war = {
						defender = { character = PREV }
						OR = {
							using_cb = cb_faction_overthrow_ruler
							using_cb = claim_on_liege_plot
							using_cb = other_claim_on_liege_plot
							using_cb = religious_overthrow_ruler
							using_cb = cb_faction_independence
						}
					}
				}
			}
			log = "trait = pf_loyalist"
		}
		if = {
			limit = {
				trait = pf_loyalist
				liege = {
					NOT = { has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me } }
					any_war = {
						defender = { character = PREV }
						OR = {
							using_cb = cb_faction_overthrow_ruler
							using_cb = claim_on_liege_plot
							using_cb = other_claim_on_liege_plot
							using_cb = religious_overthrow_ruler
							using_cb = cb_faction_independence
						}
					}
				}
			}
			log = "WARNING: trait = pf_loyalist w/ liege defending against civil war BUT w/o pf_loyal_to_me TOM!"
		}
		if = {
			limit = {
				trait = pf_loyalist
				liege = {
					has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
					NOT = {
						any_war = {
							defender = { character = PREV }
							OR = {
								using_cb = cb_faction_overthrow_ruler
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = religious_overthrow_ruler
								using_cb = cb_faction_independence
							}
						}
					}
				}
			}
			log = "WARNING: trait = pf_loyalist w/ pf_loyal_to_me TOM, BUT liege isn't defending against a civil war!"
		}
		if = {
			limit = {
				trait = pf_loyalist
				liege = {
					NOR = {
						has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
						any_war = {
							defender = { character = PREV }
							OR = {
								using_cb = cb_faction_overthrow_ruler
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = religious_overthrow_ruler
								using_cb = cb_faction_independence
							}
						}
					}
				}
			}
			log = "WARNING: trait = pf_loyalist w/o liege defending against civil war AND w/o pf_loyal_to_me TOM!"
		}
		if = {
			limit = {
				trait = pf_loyalist
				is_ruler = no
			}
			log = "WARNING: trait = pf_loyalist but not a ruler!"
		}
		if = {
			limit = {
				trait = pf_neutral
				is_ruler = yes
				liege = {
					has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
					any_war = {
						defender = { character = PREV }
						OR = {
							using_cb = cb_faction_overthrow_ruler
							using_cb = claim_on_liege_plot
							using_cb = other_claim_on_liege_plot
							using_cb = religious_overthrow_ruler
							using_cb = cb_faction_independence
						}
					}
				}
			}
			log = "trait = pf_neutral"
		}
		if = {
			limit = {
				trait = pf_neutral
				liege = {
					NOT = { has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me } }
					any_war = {
						defender = { character = PREV }
						OR = {
							using_cb = cb_faction_overthrow_ruler
							using_cb = claim_on_liege_plot
							using_cb = other_claim_on_liege_plot
							using_cb = religious_overthrow_ruler
							using_cb = cb_faction_independence
						}
					}
				}
			}
			log = "WARNING: trait = pf_neutral w/ liege defending against civil war BUT w/o pf_neutral_to_me TOM!"
		}
		if = {
			limit = {
				trait = pf_neutral
				liege = {
					has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me }
					NOT = {
						any_war = {
							defender = { character = PREV }
							OR = {
								using_cb = cb_faction_overthrow_ruler
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = religious_overthrow_ruler
								using_cb = cb_faction_independence
							}
						}
					}
				}
			}
			log = "WARNING: trait = pf_neutral w/ pf_neutral_to_me TOM, BUT liege isn't defending against a civil war!"
		}
		if = {
			limit = {
				trait = pf_neutral
				liege = {
					NOR = {
						has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me }
						any_war = {
							defender = { character = PREV }
							OR = {
								using_cb = cb_faction_overthrow_ruler
								using_cb = claim_on_liege_plot
								using_cb = other_claim_on_liege_plot
								using_cb = religious_overthrow_ruler
								using_cb = cb_faction_independence
							}
						}
					}
				}
			}
			log = "WARNING: trait = pf_neutral w/o liege defending against civil war AND w/o pf_neutral_to_me TOM!"
		}
		if = {
			limit = {
				trait = pf_neutral
				is_ruler = no
			}
			log = "WARNING: trait = pf_neutral but not a ruler!"
		}
		if = {
			limit = { in_revolt = no }
			log = "in_revolt = no"
		}
		if = {
			limit = { in_revolt = yes }
			log = "in_revolt = yes"
		}
		liege = {
			if = {
				limit = { character = PREV }
				log = "liege: <self>"
			}
			if = {
				limit = { NOT = { character = PREV } }
				log = "liege: [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
			}
			save_event_target_as = pf_log_liege
		}
		liege_before_war = {
			if = {
				limit = { character = event_target:pf_log_liege }
				log = "liege_before_war: <same as liege>"
			}
			if = {
				limit = { NOT = { character = event_target:pf_log_liege } }
				log = "liege_before_war: [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
			}
		}
		clear_event_target = pf_log_liege
		if = {
			limit = {
				any_opinion_modifier_target = {
					count = 2
					is_alive = yes
					reverse_has_opinion_modifier = { who = PREV modifier = revolting_against }
				}
			}
			log = "WARNING: revolting_against more than 1 character!"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = revolting_against }
				has_opinion_modifier = { who = PREV modifier = revolting_against_me }
			}
			log = "revolting_against -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = revolting_against }
				NOT = { has_opinion_modifier = { who = PREV modifier = revolting_against_me } }
			}
			log = "WARNING: revolting_against w/o [reverse] revolting_against_me -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = revolting_against_me }
				has_opinion_modifier = { who = PREV modifier = revolting_against }
			}
			log = "revolting_against_me -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = revolting_against_me }
				NOT = { has_opinion_modifier = { who = PREV modifier = revolting_against } }
			}
			log = "WARNING: revolting_against_me w/o [reverse] revolting_against -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		if = {
			limit = {
				any_opinion_modifier_target = {
					count = 2
					is_alive = yes
					reverse_has_opinion_modifier = { who = PREV modifier = pf_loyal_toward }
				}
			}
			log = "WARNING: pf_loyal_toward more than 1 character!"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_loyal_toward }
				has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
			}
			log = "pf_loyal_toward -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_loyal_toward }
				NOT = { has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me } }
			}
			log = "WARNING: pf_loyal_toward w/o [reverse] pf_loyal_to_me -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
				has_opinion_modifier = { who = PREV modifier = pf_loyal_toward }
			}
			log = "pf_loyal_to_me -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
				NOT = { has_opinion_modifier = { who = PREV modifier = pf_loyal_toward } }
			}
			log = "WARNING: pf_loyal_to_me w/o [reverse] pf_loyal_toward -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		if = {
			limit = {
				any_opinion_modifier_target = {
					count = 2
					is_alive = yes
					reverse_has_opinion_modifier = { who = PREV modifier = pf_neutral_toward }
				}
			}
			log = "WARNING: pf_neutral_toward more than 1 character!"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_neutral_toward }
				has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me }
			}
			log = "pf_neutral_toward -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_neutral_toward }
				NOT = { has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me } }
			}
			log = "WARNING: pf_neutral_toward w/o [reverse] pf_neutral_to_me -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me }
				has_opinion_modifier = { who = PREV modifier = pf_neutral_toward }
			}
			log = "pf_neutral_to_me -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me }
				NOT = { has_opinion_modifier = { who = PREV modifier = pf_neutral_toward } }
			}
			log = "WARNING: pf_neutral_to_me w/o [reverse] pf_neutral_toward -> [This.GetTitledFirstName] of the [This.PrimaryTitle.GetFullBaseName] ([This.GetID])"
		}
		if = {
			limit = {
				any_war = {
					defender = { character = ROOT }
					OR = {
						using_cb = cb_faction_overthrow_ruler
						using_cb = claim_on_liege_plot
						using_cb = other_claim_on_liege_plot
						using_cb = religious_overthrow_ruler
						using_cb = cb_faction_independence
					}
				}
			}
			if = {
				limit = { has_character_flag = faction_court_war }
				log = "war flag: faction_court_war"
			}
			if = {
				limit = { has_character_flag = faction_prosperity_war }
				log = "war flag: faction_prosperity_war"
			}
			if = {
				limit = { has_character_flag = faction_glory_war }
				log = "war flag: faction_glory_war"
			}
			if = {
				limit = { has_character_flag = faction_tradition_war }
				log = "war flag: faction_tradition_war"
			}
			if = {
				limit = { has_character_flag = faction_pretender_war }
				log = "war flag: faction_pretender_war"
			}
			if = {
				limit = { has_character_flag = faction_separatist_war }
				log = "war flag: faction_separatist_war"
			}
			if = {
				limit = { has_character_flag = faction_religious_war }
				log = "war flag: faction_religious_war"
			}
			if = {
				limit = { has_character_flag = faction_succession_war }
				log = "war flag: faction_succession_war"
			}
			if = {
				limit = { has_character_flag = faction_authority_war }
				log = "war flag: faction_authority_war"
			}
		}
		if = {
			limit = {
				NOT = {
					any_war = {
						defender = { character = ROOT }
						OR = {
							using_cb = cb_faction_overthrow_ruler
							using_cb = claim_on_liege_plot
							using_cb = other_claim_on_liege_plot
							using_cb = religious_overthrow_ruler
							using_cb = cb_faction_independence
						}
					}
				}
			}
			if = {
				limit = { has_character_flag = faction_court_war }
				log = "WARNING: stale war flag: faction_court_war"
			}
			if = {
				limit = { has_character_flag = faction_prosperity_war }
				log = "WARNING: stale war flag: faction_prosperity_war"
			}
			if = {
				limit = { has_character_flag = faction_glory_war }
				log = "WARNING: stale war flag: faction_glory_war"
			}
			if = {
				limit = { has_character_flag = faction_tradition_war }
				log = "WARNING: stale war flag: faction_tradition_war"
			}
			if = {
				limit = { has_character_flag = faction_pretender_war }
				log = "WARNING: stale war flag: faction_pretender_war"
			}
			if = {
				limit = { has_character_flag = faction_separatist_war }
				log = "WARNING: stale war flag: faction_separatist_war"
			}
			if = {
				limit = { has_character_flag = faction_religious_war }
				log = "WARNING: stale war flag: faction_religious_war"
			}
			if = {
				limit = { has_character_flag = faction_succession_war }
				log = "WARNING: stale war flag: faction_succession_war"
			}
			if = {
				limit = { has_character_flag = faction_authority_war }
				log = "WARNING: stale war flag: faction_authority_war"
			}
		}
		if = {
			limit = {
				any_war = {
					attacker = { character = ROOT }
					OR = {
						using_cb = cb_faction_overthrow_ruler
						using_cb = claim_on_liege_plot
						using_cb = other_claim_on_liege_plot
						using_cb = religious_overthrow_ruler
						using_cb = cb_faction_independence
					}
				}
			}
			if = {
				limit = { has_character_flag = demands_lower_CA }
				log = "demands flag: demands_lower_CA"
			}
			if = {
				limit = { has_character_flag = demands_lower_TO }
				log = "demands flag: demands_lower_TO"
			}
			if = {
				limit = { has_character_flag = demands_surrender_title }
				log = "demands flag: demands_surrender_title"
			}
			if = {
				limit = { has_character_flag = demands_share_wealth }
				log = "demands flag: demands_share_wealth"
			}
			if = {
				limit = { has_character_flag = demands_revert_succession }
				log = "demands flag: demands_revert_succession"
			}
			if = {
				limit = { has_character_flag = demands_council_life_terms }
				log = "demands flag: demands_council_life_terms"
			}
			if = {
				limit = { has_character_flag = demands_lower_feudal_obligations }
				log = "demands flag: demands_lower_feudal_obligations"
			}
			if = {
				limit = { has_character_flag = demands_lower_tribal_obligations }
				log = "demands flag: demands_lower_tribal_obligations"
			}
			if = {
				limit = { has_character_flag = demands_lower_city_obligations }
				log = "demands flag: demands_lower_city_obligations"
			}
			if = {
				limit = { has_character_flag = demands_lower_temple_obligations }
				log = "demands flag: demands_lower_temple_obligations"
			}
			if = {
				limit = { has_character_flag = demands_seniority }
				log = "demands flag: demands_seniority"
				liege_before_war = {
					if = {
						limit = { any_demesne_title = { has_title_flag = change_seniority } }
						any_demesne_title = {
							limit = { has_title_flag = change_seniority }
							log = "disputed succession law title: [This.GetFullBaseName]"
						}
					}
					if = {
						limit = { NOT = { any_demesne_title = { has_title_flag = change_seniority } } }
						log = "WARNING: demands a succession law change, but defender has no title marked for such a demand"
					}
				}
			}
			if = {
				limit = { has_character_flag = demands_primogeniture }
				log = "demands flag: demands_primogeniture"
				liege_before_war = {
					if = {
						limit = { any_demesne_title = { has_title_flag = change_primogeniture } }
						any_demesne_title = {
							limit = { has_title_flag = change_primogeniture }
							log = "disputed succession law title: [This.GetFullBaseName]"
						}
					}
					if = {
						limit = { NOT = { any_demesne_title = { has_title_flag = change_primogeniture } } }
						log = "WARNING: demands a succession law change, but defender has no title marked for such a demand"
					}
				}
			}
			if = {
				limit = { has_character_flag = demands_gavelkind }
				log = "demands flag: demands_gavelkind"
				liege_before_war = {
					if = {
						limit = { any_demesne_title = { has_title_flag = change_gavelkind } }
						any_demesne_title = {
							limit = { has_title_flag = change_gavelkind }
							log = "disputed succession law title: [This.GetFullBaseName]"
						}
					}
					if = {
						limit = { NOT = { any_demesne_title = { has_title_flag = change_gavelkind } } }
						log = "WARNING: demands a succession law change, but defender has no title marked for such a demand"
					}
				}
			}
			if = {
				limit = { has_character_flag = demands_feudal_elective }
				log = "demands flag: demands_feudal_elective"
				liege_before_war = {
					if = {
						limit = { any_demesne_title = { has_title_flag = change_feudal_elective } }
						any_demesne_title = {
							limit = { has_title_flag = change_feudal_elective }
							log = "disputed succession law title: [This.GetFullBaseName]"
						}
					}
					if = {
						limit = { NOT = { any_demesne_title = { has_title_flag = change_feudal_elective } } }
						log = "WARNING: demands a succession law change, but defender has no title marked for such a demand"
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					any_war = {
						attacker = { character = ROOT }
						OR = {
							using_cb = cb_faction_overthrow_ruler
							using_cb = claim_on_liege_plot
							using_cb = other_claim_on_liege_plot
							using_cb = religious_overthrow_ruler
							using_cb = cb_faction_independence
						}
					}
				}
			}
			if = {
				limit = { has_character_flag = demands_lower_CA }
				log = "WARNING: stale demands flag: demands_lower_CA"
			}
			if = {
				limit = { has_character_flag = demands_lower_TO }
				log = "WARNING: stale demands flag: demands_lower_TO"
			}
			if = {
				limit = { has_character_flag = demands_surrender_title }
				log = "WARNING: stale demands flag: demands_surrender_title"
			}
			if = {
				limit = { has_character_flag = demands_share_wealth }
				log = "WARNING: stale demands flag: demands_share_wealth"
			}
			if = {
				limit = { has_character_flag = demands_revert_succession }
				log = "WARNING: stale demands flag: demands_revert_succession"
			}
			if = {
				limit = { has_character_flag = demands_council_life_terms }
				log = "WARNING: stale demands flag: demands_council_life_terms"
			}
			if = {
				limit = { has_character_flag = demands_lower_feudal_obligations }
				log = "WARNING: stale demands flag: demands_lower_feudal_obligations"
			}
			if = {
				limit = { has_character_flag = demands_lower_tribal_obligations }
				log = "WARNING: stale demands flag: demands_lower_tribal_obligations"
			}
			if = {
				limit = { has_character_flag = demands_lower_city_obligations }
				log = "WARNING: stale demands flag: demands_lower_city_obligations"
			}
			if = {
				limit = { has_character_flag = demands_lower_temple_obligations }
				log = "WARNING: stale demands flag: demands_lower_temple_obligations"
			}
			if = {
				limit = { has_character_flag = demands_seniority }
				log = "WARNING: stale demands flag: demands_seniority"
			}
			if = {
				limit = { has_character_flag = demands_primogeniture }
				log = "WARNING: stale demands flag: demands_primogeniture"
			}
			if = {
				limit = { has_character_flag = demands_gavelkind }
				log = "WARNING: stale demands flag: demands_gavelkind"
			}
			if = {
				limit = { has_character_flag = demands_feudal_elective }
				log = "WARNING: stale demands flag: demands_feudal_elective"
			}
		}
		log = ">>>>>"
	}
}


character_event = {
	id = emf_faction.1001
	
	hide_window = yes

	only_rulers = yes
	
	trigger = {
		OR = {
			AND = {
				OR = {
					trait = pf_rebel
					has_any_opinion_modifier = revolting_against
				}
				OR = {
					is_ruler = no
					pf_in_revolt_trigger = no
				}
			}
			AND = {
				trait = pf_loyalist
				OR = {
					is_ruler = no
					NOT = { has_opinion_modifier = { who = LIEGE modifier = pf_loyal_toward } }
					NOT = { reverse_has_opinion_modifier = { who = LIEGE modifier = pf_loyal_to_me } }
				}
			}
			AND = {
				trait = pf_neutral
				OR = {
					is_ruler = no
					NOT = { has_opinion_modifier = { who = LIEGE modifier = pf_neutral_toward } }
					NOT = { reverse_has_opinion_modifier = { who = LIEGE modifier = pf_neutral_to_me } }
				}
			}
			AND = {
				OR = {
					trait = pf_neutral
					trait = pf_loyalist
					has_any_opinion_modifier = pf_loyal_toward
					has_any_opinion_modifier = pf_neutral_toward
				}
				liege = {
					OR = {
						character = PREV
						NOT = {
							any_war = {
								defender = { character = PREV }
								OR = {
									using_cb = cb_faction_overthrow_ruler
									using_cb = claim_on_liege_plot
									using_cb = other_claim_on_liege_plot
									using_cb = religious_overthrow_ruler
									using_cb = cb_faction_independence
								}
							}
						}
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}

	immediate = {
		log = "ERROR: stray rebel/neutral/loyalist state (checked periodically, so more info needed); dump follows:"
		pf_log_state_effect = yes
		
		if = {
			limit = {
				has_global_flag = emf_debug
				multiplayer = no
			}
			random_playable_ruler = {
				limit = { ai = no }
				character_event = { id = emf_faction.1003 }
			}
		}
		
		pf_teardown_rebel_effect = yes
		pf_teardown_neutral_effect = yes
		pf_teardown_loyalist_effect = yes
	}
}

character_event = {
	id = emf_faction.1002
	
	hide_window = yes
	
	only_rulers = yes

	trigger = {
		NOT = {
			any_war = {
				defender = { character = ROOT }
				OR = {
					using_cb = cb_faction_overthrow_ruler
					using_cb = claim_on_liege_plot
					using_cb = other_claim_on_liege_plot
					using_cb = religious_overthrow_ruler
					using_cb = cb_faction_independence
				}
			}
		}
		OR = {
			has_any_opinion_modifier = revolting_against_me
			has_any_opinion_modifier = pf_loyal_to_me
			has_any_opinion_modifier = pf_neutral_to_me
			pf_war_flag_trigger = yes
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	immediate = {
		log = "ERROR: stray civil war liege state (checked periodically, so more info needed); dump follows:"
		pf_log_state_effect = yes
		
		if = {
			limit = {
				has_global_flag = emf_debug
				multiplayer = no
			}
			random_playable_ruler = {
				limit = { ai = no }
				character_event = { id = emf_faction.1003 }
			}
		}
		
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = revolting_against_me }
			}
			reverse_remove_opinion = { who = PREV modifier = revolting_against_me }
			remove_opinion = { who = PREV modifier = revolting_against }
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_loyal_to_me }
			}
			reverse_remove_opinion = { who = PREV modifier = pf_loyal_to_me }
			remove_opinion = { who = PREV modifier = pf_loyal_toward }
		}
		any_opinion_modifier_target = {
			limit = {
				is_alive = yes
				reverse_has_opinion_modifier = { who = PREV modifier = pf_neutral_to_me }
			}
			reverse_remove_opinion = { who = PREV modifier = pf_neutral_to_me }
			remove_opinion = { who = PREV modifier = pf_neutral_toward }
		}
		pf_clear_war_flags_effect = yes
	}
}


character_event = {
	id = emf_faction.1003
	picture = GFX_evt_bloody_man
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	desc = {
		text = emf_faction.1003.desc_courtier
		trigger = { FROM = { is_ruler = no } }
	}
	
	desc = {
		text = emf_faction.1003.desc_ruler
		trigger = { FROM = { is_ruler = yes } }
	}
	
	option = { name = ALAS }
}

