#########################################################
#
# Rebel Events for The Old Gods DLC
# ( TOG.1000 to TOG.1199)
#
# NOTE: The Old Gods DLC disables the old rebel system
#
#########################################################

# Written by Henrik Fåhraeus

namespace = TOG

### PEASANT REBELS

# Peasant Rebels rise up (temporary rebel title created, with a leader and a war)
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1000
	desc = EVTDESC_TOG_1000
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		OR = {
			has_province_flag = force_peasant_revolt
			e_placeholder = { had_title_flag = { flag = startup days = 730 } }
		}
		
		# Will get clan rebels instead
		NAND = {
			has_empty_holding = yes
			owner = {
				is_nomadic = yes
				independent = yes
				culture = ROOT
				risks_minor_clan_rising = yes
				in_revolt = no
				capital_scope = { 
					NOT = { province = ROOT }
				}
			}
		}
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		# Heretic revolts have prio
		OR = {
			is_heretic = no
			owner = {
				top_liege = {
					NOT = { is_parent_religion = ROOT }
				}
			}
			has_province_flag = force_peasant_revolt
		}
		
		# Religious revolts have prio
		OR = {
			owner = {
				top_liege = {
					religion_group = ROOT
				}
			}
			has_province_flag = force_peasant_revolt
		}
		
		# Nationalist revolts have prio
		OR = {
			owner = { top_liege = { culture = ROOT } }
			owner = { top_liege = { any_demesne_title = { temporary = yes } } }
			owner = {
				top_liege = {
					OR = {
						controls_religion = yes
						has_landed_title = k_papal_chalcedon
						has_landed_title = d_pentarch_constantinople
					}
					religion = ROOT
				}
			}
			kingdom = { NOT = { culture = ROOT } }
			kingdom = {
				holder_scope = {
					culture = ROOT
					top_liege = { any_realm_province = { province_id = ROOT } }
				}
			}
			has_province_flag = force_peasant_revolt
		}
		
		# Decadence revolts have prio
		OR = {
			has_province_flag = force_peasant_revolt
			NOT = { has_province_modifier = decadence_unrest }
			owner = { top_liege = { NOT = { religion_group = muslim } } }
			owner = { top_liege = { NOT = { trait = dynasty_decadence_high } } }
		}
		
		# Not if there is already an ongoing peasant revolt for this province
		# or another rebellion that the county could potentially be part of
		NOT = {
			owner = {
				top_liege = {
					war = yes
					
					any_war = {
						defender = { character = PREV }
						OR = {
							AND = {
								using_cb = peasant_revolt
								war_title = ROOT # The county
							}
							AND = {
								using_cb = heretic_revolt
								attacker = { religion = ROOT }
							}
							AND = {
								using_cb = religious_revolt
								attacker = { religion = ROOT }
							}
							AND = {
								using_cb = decadence_revolt
								attacker = { religion = ROOT }
							}
							AND = {
								using_cb = decadence_revolt
								attacker = { religion = ROOT }
							}
							AND = {
								using_cb = cb_minor_clan_revolt
								attacker = { culture = ROOT }
							}
							AND = {
								using_cb = liberation_revolt
								thirdparty_title_scope = {
									ROOT = {
										kingdom = {
											title = PREVPREV
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	immediate = {
		remove_province_modifier = rumors_of_witchcraft
	
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 25
			attributes = {
				martial = 5
			}
			trait = peasant_leader
			trait = tough_soldier
		}
		owner = { primary_title = { save_event_target_as = rebellion_base_title } }
		new_character = {
			save_event_target_as = rebel_leader
			event_target:rebellion_base_title = {
				create_title = {
					tier = DUKE
					landless = yes
					temporary = yes
					rebel = yes
					culture = ROOT
					name = "PEASANT_REVOLT"
					holder = event_target:rebel_leader
					ruler = ""
					ruler_female = ""
					base_title = event_target:rebellion_base_title
				}
			}
			
			clear_event_target = rebel_leader
			clear_event_target = rebellion_base_title
			wealth = 100
			
			spawn_peasant_army_effect = yes
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = powerful
					}
				}
				spawn_peasant_army_effect = yes
				wealth = 150
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = very_powerful
					}
				}
				spawn_peasant_army_effect = yes
				spawn_peasant_army_effect = yes
				spawn_peasant_army_effect = yes
				wealth = 250
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = extremely_powerful
					}
				}
				spawn_peasant_army_effect = yes
				spawn_peasant_army_effect = yes
				spawn_peasant_army_effect = yes
				spawn_peasant_army_effect = yes
				spawn_peasant_army_effect = yes
				wealth = 350
			}
			
			# DoW on the province top liege
			ROOT = {
				owner = {
					top_liege = {
						set_character_flag = has_current_revolt
						reverse_war = {
							target = PREVPREVPREV
							casus_belli = peasant_revolt
							thirdparty_title = ROOT # The county
						}
						reverse_opinion = {
							who = PREVPREVPREV
							modifier = opinion_evil_tyrant
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1001
				}
			}
		}
		if = {
			limit = { has_province_modifier = peasant_unrest }
			remove_province_modifier = peasant_unrest
		}		
		add_province_modifier = {
			name = recent_county_uprising
			duration = 3650 # Ten years of -100% revolt risk in this county
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1000"
	}
}

character_event = {
	id = TOG.1001
	desc = EVTDESC_TOG_1001
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_TOG_1000"
	}
}

# Peasants seize a holding. Fired from 'on_siege_over_winner'.
character_event = {
	id = TOG.1005
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		trait = peasant_leader
		rebel = yes
		FROM = {
			location = {
				is_capital = yes # The capital holding
			}
		}
	}
	
	immediate = {
		FROM = {
			location = {
				if = {
					limit = {
						NOT = { has_province_modifier = peasant_unrest }
					}
					add_province_modifier = {
						name = peasant_unrest
						duration = 730
					}
				}
			}
		}
	}
}

# Peasant Rebels rise up to reinforce an ongoing provincial peasant revolt
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1010
	desc = EVTDESC_TOG_1010
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		# There is already an ongoing peasant revolt for this province
		owner = {
			top_liege = {
				war = yes
				any_war = {
					defender = { character = PREV }
					using_cb = peasant_revolt
					war_title = ROOT # The county
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = { has_province_modifier = peasant_unrest }
			remove_province_modifier = peasant_unrest
		}
		add_province_modifier = {
			name = recent_county_uprising
			duration = 3650 # Ten years of -100% revolt risk in this county
		}
		
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = peasant_revolt
						war_title = ROOT # The county
					}
					attacker = {
						spawn_peasant_reinforcements_effect = yes
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = powerful
								}
							}
							spawn_peasant_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = very_powerful
								}
							}
							spawn_peasant_reinforcements_effect = yes
							spawn_peasant_reinforcements_effect = yes
							spawn_peasant_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = extremely_powerful
								}
							}
							spawn_peasant_reinforcements_effect = yes
							spawn_peasant_reinforcements_effect = yes
							spawn_peasant_reinforcements_effect = yes
							spawn_peasant_reinforcements_effect = yes
							spawn_peasant_reinforcements_effect = yes
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1011
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1010"
	}
}

character_event = {
	id = TOG.1011
	desc = EVTDESC_TOG_1011
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_TOG_1010"
	}
}


### HERETIC REBELS

# Heretic Rebels rise up (temporary rebel title created, with a leader and a war)
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1020
	desc = EVTDESC_TOG_1020
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		e_placeholder = { had_title_flag = { flag = startup days = 730 } }
		
		is_heretic = yes
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		owner = {
			top_liege = {
				is_parent_religion = ROOT
			}
		}
		
		#not if there is already an ongoing revolt
		NOT = {
			owner = {
				top_liege = {
					has_character_flag = has_current_revolt
					war = yes
				}
			}
		}
	}
	
	immediate = {
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 32
			attributes = {
				martial = 7
				learning = 7
			}
			trait = heresiarch
			trait = zealous
			trait = scholar
			trait = skilled_tactician
		}
		
		new_character = {
			set_character_flag = heretic_revolter
			
			create_title = {
				tier = DUKE
				landless = yes
				temporary = yes
				rebel = yes
				culture = ROOT
				name = "HERETIC_REVOLT"
				holder = THIS
				ruler = "HERESIARCH"
			}
			
			wealth = 100
			
			spawn_heretic_army_effect = yes
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = powerful
					}
				}
				spawn_heretic_army_effect = yes
				wealth = 150
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = very_powerful
					}
				}
				spawn_heretic_army_effect = yes
				spawn_heretic_army_effect = yes
				spawn_heretic_army_effect = yes
				wealth = 250
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = extremely_powerful
					}
				}
				spawn_heretic_army_effect = yes
				spawn_heretic_army_effect = yes
				spawn_heretic_army_effect = yes
				spawn_heretic_army_effect = yes
				spawn_heretic_army_effect = yes
				wealth = 350
			}
			
			# DoW on the province top liege
			ROOT = {
				owner = {
					top_liege = {
						set_character_flag = has_current_revolt
						reverse_war = {
							target = PREVPREVPREV
							casus_belli = heretic_revolt
							thirdparty_title = ROOT # The county...
							tier = DUKE # ... but really the de jure duchy
						}
						reverse_opinion = {
							who = PREVPREVPREV
							modifier = opinion_evil_tyrant
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1021
				}
			}
		}
		if = {
			limit = { has_province_modifier = religious_unrest }
			remove_province_modifier = religious_unrest
		}		
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1020"
	}
}

character_event = {
	id = TOG.1021
	desc = EVTDESC_TOG_1021
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_TOG_1020
	}
}

# Heretics seize a holding. Fired from 'on_siege_over_winner'.
character_event = {
	id = TOG.1025
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		trait = heresiarch
		rebel = yes
		FROM = {
			location = {
				is_capital = yes # The capital holding
			}
		}
	}
	
	immediate = {
		FROM = {
			location = {
				if = {
					limit = {
						NOT = { religion = ROOT }
					}
					random = {
						chance = 50
						religion = ROOT
					}
				}
				if = {
					limit = {
						NOT = { has_province_modifier = religious_unrest }
					}
					add_province_modifier = {
						name = religious_unrest
						duration = 730
					}
				}
			}
		}
	}
}

# Heretic Rebels rise up to reinforce an ongoing heretic uprising
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1030
	desc = EVTDESC_TOG_1030
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		
		is_heretic = yes
		
		owner = {
			top_liege = {
				is_parent_religion = ROOT
			}
		}
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		owner = {
			top_liege = {
				war = yes
				any_war = {
					defender = { character = PREV }
					using_cb = heretic_revolt
					attacker = { religion = ROOT }
				}
			}
		}
	}
	
	immediate = {	
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
		if = {
			limit = { has_province_modifier = religious_unrest }
			remove_province_modifier = religious_unrest
		}
		
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = heretic_revolt
						attacker = { religion = ROOT }
					}
					attacker = {
						spawn_heretic_reinforcements_effect = yes
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = powerful
								}
							}
							spawn_heretic_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = very_powerful
								}
							}
							spawn_heretic_reinforcements_effect = yes
							spawn_heretic_reinforcements_effect = yes
							spawn_heretic_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = extremely_powerful
								}
							}
							spawn_heretic_reinforcements_effect = yes
							spawn_heretic_reinforcements_effect = yes
							spawn_heretic_reinforcements_effect = yes
							spawn_heretic_reinforcements_effect = yes
							spawn_heretic_reinforcements_effect = yes
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1031
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1030"
	}
}

character_event = {
	id = TOG.1031
	desc = EVTDESC_TOG_1031
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_TOG_1030"
	}
}

# Dealing with the province where the rebellion started
province_event = {
	id = TOG.1032

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_province_modifier = rebellion_heretic_province
	}
	
	immediate = {
		remove_province_modifier = rebellion_heretic_province
		if = {
			limit = {
				is_heretic = yes
				owner = { top_liege = { is_parent_religion = ROOT } }
			}
			remove_province_modifier = recent_county_uprising
			owner = {
				top_liege = {
					character_event = { id = TOG.1033 }
				}
			}
		}
	}
}

character_event = {
	id = TOG.1033
	desc = EVTDESC_TOG_1033
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	immediate = {
		log = "[Root.GetTitledName] receives option to deal with [From.GetName], where Heretic rebellion began"
	}
	
	option = {
		name = EVTOPTA_TOG_1033 # Teach them a lesson
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				OR = {
					trait = patient
					trait = kind
				}
			}
			modifier = {
				factor = 0.25
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
				}
			}
			modifier = {
				factor = 0
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
		}
		tyrant_plus_1_effect = yes
		if = {
			limit = {
				NOT = { trait = patient }
				NOT = { trait = wroth }
			}
			random = {
				chance = 50
				add_trait = wroth
			}
		}
		if = {
			limit = { trait = patient }
			random = {
				chance = 50
				remove_trait = patient
			}
		}
		if = {
			limit = { trait = kind }
			random = {
				chance = 25
				remove_trait = kind
			}
		}
		FROM = {
			add_province_modifier = {
				name = rebellion_lesson
				duration = 1825
			}
			random_list = {
				25 = {
					religion = ROOT
				}
				75 = {
					add_province_modifier = {
						name = recent_county_uprising
						duration = 3650
					}
				}
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_HERETIC
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							religion = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 730
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTB_TOG_1033 # Do whatever it takes
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				OR = {
					trait = patient
					trait = kind
				}
			}
			modifier = {
				factor = 2
				trait = cruel
			}
			modifier = {
				factor = 0
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
		}
		tyrant_plus_2_effect = yes
		if = {
			limit = {
				NOT = { trait = patient }
				NOT = { trait = wroth }
			}
			random = {
				chance = 50
				add_trait = wroth
			}
		}
		if = {
			limit = { trait = patient }
			remove_trait = patient
		}
		if = {
			limit = {
				NOT = { trait = kind }
				NOT = { trait = cruel }
			}
			random = {
				chance = 50
				add_trait = cruel
			}
		}
		if = {
			limit = { trait = kind }
			remove_trait = kind
		}
		FROM = {
			add_province_modifier = {
				name = rebellion_reprisal
				duration = 1825
			}
			random_list = {
				50 = {
					religion = ROOT
				}
				50 = {
					add_province_modifier = {
						name = recent_county_uprising
						duration = 7300
					}
				}
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_HERETIC
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							religion = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 1095
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTC_TOG_1033 # We will find another way
		ai_chance = {
			factor = 60
			modifier = {
				factor = 0.5
				trait = cruel
			}
			modifier = {
				factor = 0.5
				trait = wroth
			}
			modifier = {
				factor = 0.5
				trait = zealous
			}
			modifier = {
				factor = 1.5
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant1
					trait = tyrant2
					trait = tyrant3
					trait = tyrant4
				}
			}
			modifier = {
				factor = 2
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant5
					trait = tyrant6
					trait = tyrant7
				}
			}
			modifier = {
				factor = 3
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant8
					trait = tyrant9
					trait = tyrant10
				}
			}
		}
		FROM = {
			add_province_modifier = {
				name = recent_county_uprising
				duration = 1825
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_HERETIC
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							religion = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 365
						}
					}
				}
			}
		}
	}
}

### NATIONALIST REBELS

# Nationalist Rebels rise up to free their kingdom
# Written by Rylock
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1040
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		has_dlc = "The Old Gods"
		e_placeholder = { had_title_flag = { flag = startup days = 730 } }
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		owner = {
			top_liege = {
				NOR = {
					compare_cultures_ROOT_trigger = yes
					any_demesne_title = { temporary = yes }
					AND = {
						OR = {
							controls_religion = yes
							has_landed_title = k_papal_chalcedon
							has_landed_title = d_pentarch_constantinople
						}
						religion = ROOT
					}
				}
			}
		}
		kingdom = {
			compare_cultures_ROOT_trigger = yes
			OR = {
				has_holder = no
				AND = {
					has_holder = yes
					holder_scope = { NOT = { compare_cultures_ROOT_trigger = yes} }
				}
				AND = {
					has_holder = yes
					holder_scope = { top_liege = { NOT = { any_realm_province = { province_id = ROOT } } } }
				}
			}
		}
		
		# Heretic revolts have priority
		OR = { 
			is_heretic = no
			owner = {
				top_liege = { NOT = { is_parent_religion = ROOT } }
			}
		}
		# Not if there is already an ongoing revolt
		NOT = {
			owner = {
				top_liege = {
					has_character_flag = has_current_revolt
					war = yes
				}
			}
		}
	}
	
	weight_multiplier = {
		days = 1
		modifier = {
			factor = 2
			owner = {
				top_liege = {
					has_law = culture_conversion_2
				}
			}
		}
		modifier = {
			factor = 0.1
			owner = {
				top_liege = {
					has_law = culture_conversion_0
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = { has_province_modifier = cultural_unrest }
			remove_province_modifier = cultural_unrest
		}
		save_event_target_as = revolt_location
		kingdom = { save_event_target_as = revolt_kingdom }
		owner = { top_liege = { save_event_target_as = revolt_top_liege } }
		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 20
			health = 7
			fertility = 0.7
			attributes = {
				martial = 8
				diplomacy = 9
			}
			trait = just
			trait = brave
			trait = gregarious
			trait = ambitious
			trait = brilliant_strategist
			trait = inspiring_leader
		}
		new_character = {
			save_event_target_as = nationalist_revolt_leader
			set_character_flag = began_revolt
			opinion = {
				who = event_target:revolt_top_liege
				modifier = opinion_evil_tyrant
			}
			character_event = { id = TOG.1041 }
		}
		
		if = {
			limit = { has_province_modifier = cultural_unrest }
			remove_province_modifier = cultural_unrest
		}
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
		add_province_modifier = {
			name = rebellion_nationalist_province
			duration = 1825
		}
	}
}

# The revolt leader will attempt to find a ruler to lead the charge, or lead it himself
character_event = {
	id = TOG.1041
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		#start with kingdom level vassal
		if = {
			limit = {
				event_target:revolt_kingdom = {
					has_holder = yes
					holder_scope = {
						culture = ROOT
						religion = ROOT
						capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
						top_liege = { character = event_target:revolt_top_liege }
						NOR = {
							any_liege = { pf_war_flag_trigger = yes }
							pf_war_trait_trigger = yes
							character = event_target:revolt_top_liege
							has_truce = event_target:revolt_top_liege
							has_non_aggression_pact_with = event_target:revolt_top_liege
							prisoner = yes
							trait = incapable
							is_adult = no
							reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
						}
					}
				}
			}
			event_target:revolt_kingdom = {
				holder_scope = { character_event = { id = TOG.1042 } }
			}
			break = yes
		}
		#move onto duke level vassal
		if = {
			limit = {
				event_target:revolt_location = {
					duchy = {
						has_holder = yes
						holder_scope = {
							culture = ROOT
							religion = ROOT
							capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
							top_liege = { character = event_target:revolt_top_liege }
							NOR = {
								any_liege = { pf_war_flag_trigger = yes }
								pf_war_trait_trigger = yes
								character = event_target:revolt_top_liege
								has_truce = event_target:revolt_top_liege
								has_non_aggression_pact_with = event_target:revolt_top_liege
								prisoner = yes
								trait = incapable
								is_adult = no
								reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
							}
						}
					}
				}
			}
			event_target:revolt_location = {
				duchy = {
					holder_scope = { character_event = { id = TOG.1042 } }
				}
			}
			break = yes
		}
		#move onto county owner
		if = {
			limit = {
				event_target:revolt_location = {
					owner = {
						culture = ROOT
						religion = ROOT
						top_liege = { character = event_target:revolt_top_liege }
						capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
						NOR = {
							any_liege = { pf_war_flag_trigger = yes }
							pf_war_trait_trigger = yes
							character = event_target:revolt_top_liege
							has_truce = event_target:revolt_top_liege
							has_non_aggression_pact_with = event_target:revolt_top_liege
							prisoner = yes
							trait = incapable
							is_adult = no
							reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
						}
					}
				}
			}
			event_target:revolt_location = {
				owner = { character_event = { id = TOG.1042 } }
			}
			break = yes
		}
		#move onto other dukes/counts
		if = {
			limit = {
				NOT = { any_liege = { pf_war_flag_trigger = yes } }
			}
			#check dukes
			event_target:revolt_location = {
				owner = {
					top_liege = {
						random_realm_lord = {
							limit = {
								tier = DUKE
								culture = ROOT
								religion = ROOT
								capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
								NOR = {
									any_liege = { pf_war_flag_trigger = yes }
									pf_war_trait_trigger = yes
									character = event_target:revolt_top_liege
									has_truce = event_target:revolt_top_liege
									has_non_aggression_pact_with = event_target:revolt_top_liege
									prisoner = yes
									trait = incapable
									is_adult = no
									reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
								}
							}
							character_event = { id = TOG.1042 }
							break = yes
						}
					}
				}
			}
			#check counts
			event_target:revolt_location = {
				owner = {
					top_liege = {
						random_realm_lord = {
							limit = {
								tier = COUNT
								culture = ROOT
								religion = ROOT
								capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
								NOR = {
									any_liege = { pf_war_flag_trigger = yes }
									pf_war_trait_trigger = yes
									character = event_target:revolt_top_liege
									has_truce = event_target:revolt_top_liege
									has_non_aggression_pact_with = event_target:revolt_top_liege
									prisoner = yes
									trait = incapable
									is_adult = no
									reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
								}
							}
							character_event = { id = TOG.1042 }
							break = yes
						}
					}
				}
			}
		}
		#failing that, the revolt leader will do it himself
		set_character_flag = nationalist_rebel
		event_target:revolt_kingdom = {
			create_title = {
				tier = KING
				landless = yes
				temporary = yes
				culture = ROOT
				holder = ROOT
				base_title = THIS
				copy_title_laws = yes
				name = "NATIONALIST_REVOLT"
				ruler = "LORD"
				ruler_female = "LADY"
			}
		}
		event_target:revolt_location = {
			event_target:nationalist_revolt_leader = {
				hidden_tooltip = {
					spawn_nationalist_army_effect = yes
					
					if = {
						limit = {
							has_game_rule = {
								name = provincial_revolt_strength
								value = powerful
							}
						}
						spawn_nationalist_army_effect = yes
					}
					
					if = {
						limit = {
							has_game_rule = {
								name = provincial_revolt_strength
								value = very_powerful
							}
						}
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
					}
					
					if = {
						limit = {
							has_game_rule = {
								name = provincial_revolt_strength
								value = extremely_powerful
							}
						}
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
					}
				}
			}
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 34
			attributes = {
				martial = 7
			}
			trait = skilled_tactician
		}
		event_target:revolt_location = {
			new_character = {
				opinion = { who = ROOT modifier = opinion_loyal_servant years = 20 }
				spawn_nationalist_army_effect = yes
						
				if = {
					limit = {
						has_game_rule = {
							name = provincial_revolt_strength
							value = powerful
						}
					}
					spawn_nationalist_army_effect = yes
				}
				
				if = {
					limit = {
						has_game_rule = {
							name = provincial_revolt_strength
							value = very_powerful
						}
					}
					spawn_nationalist_army_effect = yes
					spawn_nationalist_army_effect = yes
					spawn_nationalist_army_effect = yes
				}
				
				if = {
					limit = {
						has_game_rule = {
							name = provincial_revolt_strength
							value = extremely_powerful
						}
					}
					spawn_nationalist_army_effect = yes
					spawn_nationalist_army_effect = yes
					spawn_nationalist_army_effect = yes
					spawn_nationalist_army_effect = yes
					spawn_nationalist_army_effect = yes
				}
			}
		}
		random = {
			chance = 50
			create_character = {
				random_traits = yes
				dynasty = none
				religion = ROOT
				culture = ROOT
				female = no
				age = 23
				attributes = {
					martial = 7
				}
				trait = skilled_tactician
			}
			event_target:revolt_location = {
				new_character = {
					opinion = { who = ROOT modifier = opinion_loyal_servant years = 20 }
					spawn_nationalist_army_effect = yes
						
					if = {
						limit = {
							has_game_rule = {
								name = provincial_revolt_strength
								value = powerful
							}
						}
						spawn_nationalist_army_effect = yes
					}
					
					if = {
						limit = {
							has_game_rule = {
								name = provincial_revolt_strength
								value = very_powerful
							}
						}
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
					}
					
					if = {
						limit = {
							has_game_rule = {
								name = provincial_revolt_strength
								value = extremely_powerful
							}
						}
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
						spawn_nationalist_army_effect = yes
					}
				}
			}
		}
		event_target:revolt_location = {
			event_target:revolt_top_liege = {
				set_character_flag = has_current_revolt
				reverse_war = {
					target = ROOT
					casus_belli = liberation_revolt
					thirdparty_title = PREV # The county...
					tier = KING # ... but really the de jure kingdom
				}
			}
		}
		hidden_tooltip = {
			event_target:revolt_top_liege = {
				character_event = { id = TOG.1044 }
				any_realm_lord = {
					limit = {
						higher_tier_than = BARON
						OR = {
							culture = ROOT
							AND = {
								culture_group = ROOT
								PREV = { NOT = { culture_group = ROOT } }
							}
						}
						religion = ROOT
						capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
						NOR = {
							character = PREV
							has_truce = PREV
							has_non_aggression_pact_with = PREV
							prisoner = yes
							trait = incapable
							is_adult = no
							reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
							any_liege = { pf_war_flag_trigger = yes }
							pf_war_trait_trigger = yes
							any_liege = {
								OR = {
									culture = ROOT
									AND = {
										culture_group = ROOT
										PREVPREV = { NOT = { culture_group = ROOT } }
									}
								}
								religion = ROOT
								capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
								NOR = {
									character = PREVPREV
									has_truce = PREVPREV
									has_non_aggression_pact_with = PREVPREV
									prisoner = yes
									trait = incapable
									is_adult = no
									reverse_has_opinion_modifier = { who = ROOT modifier = refused_revolt_call }
									pf_war_trait_trigger = yes
								}
							}
						}
					}
					character_event = { id = TOG.1043 } #Ask to join the war
				}
			}
		}
	}
}

# Same-culture ruler is approached to lead the revolt
character_event = {
	id = TOG.1042
	desc = EVTDESC_TOG_1042
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_TOG_1042 # We will lead the revolt
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0
				opinion = { who = event_target:revolt_top_liege value = 35 }
			}
			modifier = {
				factor = 0.25
				event_target:revolt_top_liege = { dynasty = ROOT }
			}
			modifier = {
				factor = 0.25
				event_target:revolt_top_liege = { is_close_relative = ROOT }
			}
			modifier = {
				factor = 0.1
				vassal_of = event_target:revolt_top_liege
				NOR = {
					in_faction = faction_separatist
					leads_faction = faction_separatist
				}
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:revolt_top_liege value = -25 } }
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:revolt_top_liege value = -50 } }
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:revolt_top_liege value = -75 } }
			}
			modifier = {
				factor = 1.25
				trait = brave
			}
			modifier = {
				factor = 1.25
				trait = wroth
			}
			modifier = {
				factor = 1.25
				trait = proud
			}
			modifier = {
				factor = 2.0
				trait = ambitious
			}
			modifier = {
				factor = 3.0
				OR = {
					trait = lunatic
					trait = possessed
				}
			}
			modifier = {
				factor = 1.5
				event_target:revolt_top_liege = { NOT = { culture_group = ROOT } }
			}
		}

		log = "[Root.GetBestName] has agreed to lead the liberation revolt of [From.GetBestName] against [Root.TopLiege.GetBestName]"

		save_event_target_as = leading_revolt
		set_character_flag = nationalist_rebel
		clr_character_flag = wants_to_lead_revolt
		clr_character_flag = civil_war_faction_leader
		clr_character_flag = civil_war_faction_member
		clr_character_flag = will_join_civil_war
		
		#mark original liege
		liege = {
			reverse_opinion = { who = ROOT modifier = liberation_revolt_against }
		}
		
		#move the original revolter to the new leader's court
		event_target:revolt_location = {
			event_target:nationalist_revolt_leader = {
				move_character = ROOT
				add_friend = ROOT
				hidden_tooltip = {
					random_list = {
						30 = {
							spawn_unit = {
								province = PREV
								home = PREV
								owner = ROOT
								scaled_by_biggest_garrison = 1.6
								troops = {
									archers = { 6 6 }
									light_cavalry = { 3 3 }
									knights = { 1 1 }
									light_infantry = { 7 7 }
									heavy_infantry = { 3 3 }
								}
								cannot_inherit = yes
								attrition = 0.5
								maintenance_multiplier = 0
								earmark = nationalist_rebels_1
							}
						}
						30 = {
							spawn_unit = {
								province = PREV
								home = PREV
								owner = ROOT
								scaled_by_biggest_garrison = 1.3
								troops = {
									archers = { 6 6 }
									light_cavalry = { 3 3 }
									knights = { 1 1 }
									light_infantry = { 7 7 }
									heavy_infantry = { 3 3 }
								}
								cannot_inherit = yes
								attrition = 0.5
								maintenance_multiplier = 0
								earmark = nationalist_rebels_1
							}
						}
						30 = {
							spawn_unit = {
								province = PREV
								home = PREV
								owner = ROOT
								scaled_by_biggest_garrison = 1
								troops = {
									archers = { 6 6 }
									light_cavalry = { 3 3 }
									knights = { 1 1 }
									light_infantry = { 7 7 }
									heavy_infantry = { 3 3 }
								}
								cannot_inherit = yes
								attrition = 0.5
								maintenance_multiplier = 0
								earmark = nationalist_rebels_1
							}
						}
					}
				}
			}
		}
		
		#create additional rebel commanders
		hidden_tooltip = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = ROOT
				culture = ROOT
				female = no
				age = 34
				attributes = {
					martial = 7
				}
				trait = skilled_tactician
			}
			event_target:revolt_location = {
				new_character = {
					opinion = { who = ROOT modifier = opinion_loyal_servant years = 20 }
					random_list = {
						30 = {
							spawn_unit = {
								province = PREV
								home = PREV
								owner = ROOT
								#leader = THIS
								scaled_by_biggest_garrison = 1.6
								troops = {
									archers = { 6 6 }
									light_cavalry = { 3 3 }
									knights = { 1 1 }
									light_infantry = { 7 7 }
									heavy_infantry = { 3 3 }
								}
								disband_on_peace = yes
								attrition = 0.5
								maintenance_multiplier = 0
								earmark = nationalist_rebels
							}
						}
						30 = {
							spawn_unit = {
								province = PREV
								home = PREV
								owner = ROOT
								#leader = THIS
								scaled_by_biggest_garrison = 1.3
								troops = {
									archers = { 6 6 }
									light_cavalry = { 3 3 }
									knights = { 1 1 }
									light_infantry = { 7 7 }
									heavy_infantry = { 3 3 }
								}
								disband_on_peace = yes
								attrition = 0.5
								maintenance_multiplier = 0
								earmark = nationalist_rebels
							}
						}
						30 = {
							spawn_unit = {
								province = PREV
								home = PREV
								owner = ROOT
								#leader = THIS
								scaled_by_biggest_garrison = 1
								troops = {
									archers = { 6 6 }
									light_cavalry = { 3 3 }
									knights = { 1 1 }
									light_infantry = { 7 7 }
									heavy_infantry = { 3 3 }
								}
								disband_on_peace = yes
								attrition = 0.5
								maintenance_multiplier = 0
								earmark = nationalist_rebels
							}
						}
					}
				}
			}
			random = {
				chance = 50
				create_character = {
					random_traits = yes
					dynasty = none
					religion = ROOT
					culture = ROOT
					female = no
					age = 23
					attributes = {
						martial = 7
					}
					trait = skilled_tactician
				}
				event_target:revolt_location = {
					new_character = {
						opinion = { who = ROOT modifier = opinion_loyal_servant years = 20 }
						random_list = {
							30 = {
								spawn_unit = {
									province = PREV
									home = PREV
									owner = ROOT
									#leader = THIS
									scaled_by_biggest_garrison = 1.6
									troops = {
										archers = { 6 6 }
										light_cavalry = { 3 3 }
										knights = { 1 1 }
										light_infantry = { 7 7 }
										heavy_infantry = { 3 3 }
									}
									disband_on_peace = yes
									attrition = 0.5
									maintenance_multiplier = 0
									earmark = nationalist_rebels
								}
							}
							30 = {
								spawn_unit = {
									province = PREV
									home = PREV
									owner = ROOT
									#leader = THIS
									scaled_by_biggest_garrison = 1.3
									troops = {
										archers = { 6 6 }
										light_cavalry = { 3 3 }
										knights = { 1 1 }
										light_infantry = { 7 7 }
										heavy_infantry = { 3 3 }
									}
									disband_on_peace = yes
									attrition = 0.5
									maintenance_multiplier = 0
									earmark = nationalist_rebels
								}
							}
							30 = {
								spawn_unit = {
									province = PREV
									home = PREV
									owner = ROOT
									#leader = THIS
									scaled_by_biggest_garrison = 1
									troops = {
										archers = { 6 6 }
										light_cavalry = { 3 3 }
										knights = { 1 1 }
										light_infantry = { 7 7 }
										heavy_infantry = { 3 3 }
									}
									disband_on_peace = yes
									attrition = 0.5
									maintenance_multiplier = 0
									earmark = nationalist_rebels
								}
							}
						}
					}
				}
			}
			any_liege = { character_event = { id = TOG.1044 } } #inform lieges
		}
		
		#create revolter title
		if = {
			limit = { top_liege = { tier = EMPEROR } }
			primary_title = {
				create_title = {
					tier = EMPEROR
					landless = yes
					temporary = yes
					culture = ROOT
					holder = ROOT
					base_title = THIS
					copy_title_laws = yes
					name = "NATIONALIST_REVOLT"
				}
			}
		}
		if = {
			limit = { top_liege = { NOT = { tier = EMPEROR } } }
			primary_title = {
				create_title = {
					tier = KING
					landless = yes
					temporary = yes
					culture = ROOT
					holder = ROOT
					base_title = THIS
					copy_title_laws = yes
					name = "NATIONALIST_REVOLT"
				}
			}
		}
		
		#start the actual war
		event_target:revolt_location = {
			ROOT = {
				event_target:revolt_top_liege = {
					set_character_flag = has_current_revolt
					reverse_war = {
						target = ROOT
						casus_belli = liberation_revolt
						thirdparty_title = PREVPREV # The county...
						tier = KING # ... but really the de jure kingdom
					}
				}
			}
		}
		
		#attempt to recruit additional revolters
		hidden_tooltip = {
			event_target:revolt_top_liege = {
				any_realm_lord = {
					limit = {
						higher_tier_than = BARON
						OR = {
							culture = ROOT
							AND = {
								culture_group = ROOT
								PREV = { NOT = { culture_group = ROOT } }
							}
						}
						religion = ROOT
						capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
						NOR = {
							has_truce = PREV
							has_non_aggression_pact_with = PREV
							prisoner = yes
							trait = incapable
							is_adult = no
							reverse_has_opinion_modifier = { who = event_target:nationalist_revolt_leader modifier = refused_revolt_call }
							any_liege = { pf_war_flag_trigger = yes }
							pf_war_trait_trigger = yes
							any_liege = {
								OR = {
									culture = ROOT
									AND = {
										culture_group = ROOT
										event_target:revolt_top_liege = { NOT = { culture_group = ROOT } }
									}
								}
								religion = ROOT
								capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
								NOR = {
									character = PREVPREV
									has_truce = PREVPREV
									has_non_aggression_pact_with = PREVPREV
									prisoner = yes
									trait = incapable
									is_adult = no
									reverse_has_opinion_modifier = { who = event_target:nationalist_revolt_leader modifier = refused_revolt_call }
									pf_war_trait_trigger = yes
								}
							}
						}
					}
					character_event = { id = TOG.1043 } #Ask to join the war
				}
			}
		}
	}
	option = {
		name = EVTOPTB_TOG_1042 # No, this man cannot be trusted
		ai_chance = {
			factor = 70
			modifier = {
				factor = 0
				has_character_flag = wants_to_lead_revolt
			}
			modifier = {
				factor = 0.1
				vassal_of = event_target:revolt_top_liege
				OR = {
					in_faction = faction_separatist
					leads_faction = faction_separatist
				}
			}
			modifier = {
				factor = 1.5
				opinion = { who = event_target:revolt_top_liege value = 0 }
			}
			modifier = {
				factor = 1.5
				opinion = { who = event_target:revolt_top_liege value = 25 }
			}
			modifier = {
				factor = 1.5
				trait = craven
			}
			modifier = {
				factor = 1.5
				trait = humble
			}
			modifier = {
				factor = 2.0
				trait = content
			}
		}
		event_target:nationalist_revolt_leader = {
			opinion = { who = ROOT modifier = refused_revolt_call years = 20 }
			hidden_tooltip = {
				character_event = { id = TOG.1041 }
			}
		}
	}
}

# Other same-culture rulers in the kingdom are approached to join the revolt
character_event = {
	id = TOG.1043
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war

	desc = {
		trigger = {
			event_target:nationalist_revolt_leader = { has_character_flag = nationalist_rebel }
		}
		text = EVTDESC_TOG_1043A
	}
	desc = {
		trigger = {
			event_target:nationalist_revolt_leader = { NOT = { has_character_flag = nationalist_rebel } }
		}
		text = EVTDESC_TOG_1043B
	}
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_TOG_1043 #Agree
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.6
				FROM = { has_character_flag = began_revolt }
			}
			modifier = {
				factor = 0
				opinion = { who = event_target:revolt_top_liege value = 35 }
			}
			modifier = {
				factor = 0.25
				event_target:revolt_top_liege = { dynasty = ROOT }
			}
			modifier = {
				factor = 0.25
				event_target:revolt_top_liege = { is_close_relative = ROOT }
			}
			modifier = {
				factor = 0.1
				vassal_of = event_target:revolt_top_liege
				NOR = {
					in_faction = faction_separatist
					leads_faction = faction_separatist
				}
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:revolt_top_liege value = -25 } }
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:revolt_top_liege value = -50 } }
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:revolt_top_liege value = -75 } }
			}
			modifier = {
				factor = 1.25
				trait = brave
			}
			modifier = {
				factor = 1.25
				trait = wroth
			}
			modifier = {
				factor = 1.25
				trait = proud
			}
			modifier = {
				factor = 2.0
				trait = ambitious
			}
			modifier = {
				factor = 3.0
				OR = {
					trait = lunatic
					trait = possessed
				}
			}
			modifier = {
				factor = 1.5
				event_target:revolt_top_liege = { NOT = { culture_group = ROOT } }
			}
			modifier = {
				factor = 0.75
				event_target:nationalist_revolt_leader = { NOT = { culture = ROOT } }
			}
		}
		set_character_flag = nationalist_rebel
		clr_character_flag = wants_to_lead_revolt
		clr_character_flag = civil_war_faction_leader
		clr_character_flag = civil_war_faction_member
		clr_character_flag = will_join_civil_war
		
		log = "[Root.GetBestName] has agreed to join the liberation revolt of [From.GetBestName]."
		
		#mark original liege
		liege = {
			reverse_opinion = { who = ROOT modifier = liberation_revolt_against }
		}
	
		#join the war
		if = {
			limit = { event_target:nationalist_revolt_leader = { has_character_flag = nationalist_rebel } }
			hidden_tooltip = { set_defacto_liege = ROOT }
			join_attacker_wars = event_target:nationalist_revolt_leader
		}
		if = {
			limit = { event_target:leading_revolt = { has_character_flag = nationalist_rebel } }
			opinion = { who = event_target:leading_revolt modifier = loyal_vassal years = 5 }
			set_defacto_liege = event_target:leading_revolt
		}
	}
	option = {
		name = EVTOPTB_TOG_1042 #Refuse
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0
				has_character_flag = wants_to_lead_revolt
			}
			modifier = {
				factor = 1.4
				FROM = { has_character_flag = began_revolt }
			}
			modifier = {
				factor = 0.1
				vassal_of = event_target:revolt_top_liege
				OR = {
					in_faction = faction_separatist
					leads_faction = faction_separatist
				}
			}
			modifier = {
				factor = 1.5
				opinion = { who = event_target:revolt_top_liege value = 0 }
			}
			modifier = {
				factor = 1.5
				opinion = { who = event_target:revolt_top_liege value = 25 }
			}
			modifier = {
				factor = 1.5
				trait = craven
			}
			modifier = {
				factor = 1.5
				trait = humble
			}
			modifier = {
				factor = 2.0
				trait = content
			}
		}
		if = {
			limit = { FROM = { NOT = { has_character_flag = began_revolt } } }
			reverse_opinion = { who = FROM modifier = refused_revolt_call years = 20 }
		}
		reverse_opinion = { who = event_target:nationalist_revolt_leader modifier = refused_revolt_call years = 20 }
		hidden_tooltip = {
			if = {
				limit = { FROM = { has_character_flag = nationalist_rebel } }
				any_vassal = {
					limit = {
						higher_tier_than = BARON
						OR = {
							culture = event_target:nationalist_revolt_leader
							AND = {
								culture_group = event_target:nationalist_revolt_leader
								event_target:revolt_top_liege = { NOT = { culture_group = event_target:nationalist_revolt_leader } }
							}
						}
						religion = ROOT
						capital_scope = { kingdom = { title = event_target:revolt_kingdom } }
						NOR = {
							any_liege = { pf_war_flag_trigger = yes }
							has_truce = event_target:revolt_top_liege
							has_non_aggression_pact_with = event_target:revolt_top_liege
							prisoner = yes
							trait = incapable
							is_adult = no
							reverse_has_opinion_modifier = { who = event_target:nationalist_revolt_leader modifier = refused_revolt_call }
						}
					}
					character_event = { id = TOG.1043 } #Ask to join the war
				}
			}
		}
	}
}	

# Inform lieges of revolt
character_event = {
	id = TOG.1044
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war
	
	desc = {
		trigger = { FROM = { has_character_flag = began_revolt } }
		text = EVTDESC_TOG_1044A
	}
	desc = {
		trigger = { FROM = { NOT = { has_character_flag = began_revolt } } }
		text = EVTDESC_TOG_1044B
	}
	
	is_triggered_only = yes
	
	option = {
		name = CURSES
	}
}

# Nationalists seize a holding. Fired from 'on_siege_over_winner'.
character_event = {
	id = TOG.1045
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = {
			location = {
				is_capital = yes # The capital holding
			}
		}
		any_war = {
			any_attacker = {
				OR = {
					character = ROOT
					is_liege_of = ROOT
				}
			}
			using_cb = liberation_revolt
		}
	}
	
	immediate = {
		FROM = {
			location = {
				if = {
					limit = {
						NOT = { culture = ROOT }
						kingdom = { culture = ROOT }
					}
					random = {
						chance = 20
						culture = ROOT
					}
				}
				if = {
					limit = {
						culture = ROOT
						kingdom = { culture = ROOT }
						NOT = { has_province_modifier = cultural_unrest }
					}
					add_province_modifier = {
						name = cultural_unrest
						duration = 730
					}
				}
			}
		}
	}
}

# Nationalist Rebels rise up to reinforce an ongoing revolt
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1050
	desc = EVTDESC_TOG_1050
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		# There is already an ongoing nationalist revolt for the same kingdom
		owner = {
			top_liege = {
				war = yes
				any_war = {
					defender = { character = PREV }
					using_cb = liberation_revolt
					thirdparty_title_scope = {
						ROOT = {
							kingdom = {
								title = PREVPREV
								culture = PREV
							}
						}
					}
				}
			}
		}
	}
	
	immediate = {
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
		
		if = {
			limit = { has_province_modifier = cultural_unrest }
			remove_province_modifier = cultural_unrest
		}
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = liberation_revolt
						thirdparty_title_scope = {
							ROOT = {
								kingdom = {
									title = PREVPREV
								}
							}
						}
					}
					attacker = {
						spawn_nationalist_reinforcements_effect = yes
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = powerful
								}
							}
							spawn_nationalist_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = very_powerful
								}
							}
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = extremely_powerful
								}
							}
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
							spawn_nationalist_reinforcements_effect = yes
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1051
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1000"
	}
}

character_event = {
	id = TOG.1051
	desc = EVTDESC_TOG_1051
	picture = GFX_evt_siege
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_TOG_1000
	}
}

# Dealing with the province where the rebellion started
province_event = {
	id = TOG.1052

	hide_window = yes

	trigger = {
		has_province_modifier = rebellion_nationalist_province
		owner = {
			top_liege = {
				NOT = {
					any_war = {
						defender = { character = PREV }
						using_cb = liberation_revolt
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		remove_province_modifier = rebellion_nationalist_province
		if = {
			limit = {
				kingdom = { culture = ROOT }
				owner = {
					top_liege = {
						NOT = { culture = ROOT }
					}
				}
			}
			remove_province_modifier = recent_county_uprising
			owner = {
				top_liege = {
					character_event = { id = TOG.1053 }
				}
			}
		}
	}
}

character_event = {
	id = TOG.1053
	desc = EVTDESC_TOG_1053
	picture = GFX_evt_riots_byzantine
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	immediate = {
		log = "[Root.GetTitledName] receives option to deal with [From.GetName], where Nationalist rebellion began"
	}
	
	option = {
		name = EVTOPTA_TOG_1053 # Teach them a lesson
		trigger = {
			NOT = { has_law = culture_conversion_0 }
		}
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				OR = {
					trait = patient
					trait = kind
				}
			}
			modifier = {
				factor = 0.25
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
				}
			}
			modifier = {
				factor = 0
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
		}
		tyrant_plus_1_effect = yes
		if = {
			limit = {
				NOT = { trait = patient }
				NOT = { trait = wroth }
			}
			random = {
				chance = 50
				add_trait = wroth
			}
		}
		if = {
			limit = { trait = patient }
			random = {
				chance = 50
				remove_trait = patient
			}
		}
		if = {
			limit = { trait = kind }
			random = {
				chance = 25
				remove_trait = kind
			}
		}
		FROM = {
			add_province_modifier = {
				name = rebellion_lesson
				duration = 1825
			}
			random_list = {
				25 = {
					culture = ROOT
				}
				75 = {
					add_province_modifier = {
						name = recent_county_uprising
						duration = 3650
					}
				}
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_CULTURE
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						has_holder = yes
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							culture = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 730
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTB_TOG_1053 # Do whatever it takes
		trigger = {
			NOT = { has_law = culture_conversion_0 }
		}
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				OR = {
					trait = patient
					trait = kind
				}
			}
			modifier = {
				factor = 2
				trait = cruel
			}
			modifier = {
				factor = 0
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
		}
		tyrant_plus_2_effect = yes
		if = {
			limit = {
				NOT = { trait = patient }
				NOT = { trait = wroth }
			}
			random = {
				chance = 50
				add_trait = wroth
			}
		}
		if = {
			limit = { trait = patient }
			remove_trait = patient
		}
		if = {
			limit = {
				NOT = { trait = kind }
				NOT = { trait = cruel }
			}
			random = {
				chance = 50
				add_trait = cruel
			}
		}
		if = {
			limit = { trait = kind }
			remove_trait = kind
		}
		FROM = {
			add_province_modifier = {
				name = rebellion_reprisal
				duration = 1825
			}
			random_list = {
				50 = {
					culture = ROOT
				}
				50 = {
					add_province_modifier = {
						name = recent_county_uprising
						duration = 7300
					}
				}
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_CULTURE
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							culture = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 1095
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTC_TOG_1053 # We will find another way
		ai_chance = {
			factor = 60
			modifier = {
				factor = 0.5
				trait = cruel
			}
			modifier = {
				factor = 0.5
				trait = wroth
			}
			modifier = {
				factor = 1.5
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant1
					trait = tyrant2
					trait = tyrant3
					trait = tyrant4
				}
			}
			modifier = {
				factor = 2
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant5
					trait = tyrant6
					trait = tyrant7
				}
			}
			modifier = {
				factor = 3
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant8
					trait = tyrant9
					trait = tyrant10
				}
			}
		}
		FROM = {
			add_province_modifier = {
				name = recent_county_uprising
				duration = 1825
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_CULTURE
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						has_holder = yes
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							culture = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 365
						}
					}
				}
			}
		}
	}
}

# Nationalist revolter is no longer part of the war
character_event = {
	id = TOG.1054
	
	hide_window = yes
	has_character_flag = nationalist_rebel
	
	trigger = {
		OR = {
			is_ruler = no
			AND = {
				independent = yes
				NOT = {
					any_war = {
						using_cb = liberation_revolt
						any_attacker = { character = ROOT }
					}
				}
			}
			AND = {
				independent = no
				liege = {
					NOT = {
						any_war = {
							using_cb = liberation_revolt
							attacker = {
								is_liege_of = ROOT
								culture_group = ROOT
							}
						}
					}
				}
			}
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		log = "WARNING: [Root.GetBestName] is no longer part of a nationalist revolt -- reverting status"
		clr_character_flag = nationalist_rebel
		
		if = {
			limit = { has_any_opinion_modifier = liberation_revolt_against }
			random_opinion_modifier_target = {
				limit = { reverse_has_opinion_modifier = { who = ROOT modifier = liberation_revolt_against } }
				reverse_remove_opinion = { who = ROOT modifier = liberation_revolt_against }
				if = {
					limit = { higher_tier_than = ROOT }
					set_defacto_vassal = ROOT
				}
			}
		}
	}
}

# Nationalist revolter dies
character_event = {
	id = TOG.1055

	is_triggered_only = yes
	hide_window = yes

	only_playable = yes
	
	trigger = {
		OR = {
			has_character_flag = nationalist_rebel
			has_any_opinion_modifier = liberation_revolt_against
		}
	}
	
	immediate = {
		if = {
			limit = { primary_title = { is_vice_royalty = yes } }
			capital_scope = {
				county = {
					current_heir = {
						save_event_target_as = liberation_heir
					}
				}
			}
		}
		if = {
			limit = { primary_title = { is_vice_royalty = no } }
			primary_title = {
				current_heir = {
					save_event_target_as = liberation_heir
				}
			}
		}
		
		#check if heir should inherit revolt status
		event_target:liberation_heir = {
			if = {
				limit = {
					culture = ROOT
					in_revolt = no
					OR = {
						is_ruler = no
						has_character_flag = nationalist_rebel
						any_liege = { has_character_flag = nationalist_rebel }
					}
				}
				set_character_flag = nationalist_rebel
				if = {
					limit = {
						NOT = { has_any_opinion_modifier = liberation_revolt_against }
						ROOT = { has_any_opinion_modifier = liberation_revolt_against }
					}
					ROOT = {
						random_opinion_modifier_target = {
							limit = { reverse_has_opinion_modifier = { who = PREV modifier = liberation_revolt_against } }
							reverse_opinion = { who = PREVPREV modifier = liberation_revolt_against }
						}
					}
				}
				break = yes
			}
		}
		
		#failing that, end the war or re-vassalize to former liege
		any_war = {
			limit = {
				using_cb = liberation_revolt
				attacker = { character = ROOT }
			}
			end_war = invalid
			break = yes
		}
		if = {
			limit = { has_any_opinion_modifier = liberation_revolt_against }
			random_opinion_modifier_target = {
				limit = { reverse_has_opinion_modifier = { who = ROOT modifier = liberation_revolt_against } }
				reverse_remove_opinion = { who = ROOT modifier = liberation_revolt_against }
				set_defacto_vassal = ROOT
			}
			break = yes
		}
		if = {
			limit = {
				independent = no
				liege = {
					any_war = {
						using_cb = liberation_revolt
						attacker = { character = PREVPREV }
					}
				}
			}
			liege = {
				any_war = {
					limit = {
						using_cb = liberation_revolt
						attacker = { character = PREVPREV }
					}
					defender = {
						set_defacto_vassal = ROOT
					}
				}
			}
		}						
	}
}

### RELIGIOUS REBELS

# Religious Rebels rise up (temporary rebel title created, with a leader and a war)
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1060
	desc = EVTDESC_TOG_1060
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		e_placeholder = { had_title_flag = { flag = startup days = 730 } }
		
		is_heretic = no
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		owner = {
			top_liege = {
				OR = {
					NOT = { religion_group = ROOT }
					AND = {
						OR = {
							religion = bon
							religion = buddhist
						}
						ROOT = { has_province_modifier = recent_bon_conversion }
					}
				}
			}
		}
		
		# Nationalist revolts have prio
		OR = {
			owner = { top_liege = { culture = ROOT } }
			owner = { top_liege = { any_demesne_title = { temporary = yes } } }
			owner = {
				top_liege = {
					OR = {
						controls_religion = yes
						has_landed_title = k_papal_chalcedon
						has_landed_title = d_pentarch_constantinople
					}
					religion = ROOT
				}
			}
			kingdom = { NOT = { culture = ROOT } }
			kingdom = {
				holder_scope = {
					culture = ROOT
					top_liege = { any_realm_province = { province_id = ROOT } }
				}
			}
		}
		
		# not if there is already an ongoing revolt
		NOT = {
			owner = {
				top_liege = {
					has_character_flag = has_current_revolt
					war = yes
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				has_province_modifier = recent_bon_conversion
				owner = {
					top_liege = {
						OR = {
							religion = bon
							religion = buddhist
						}
					}
				}
			}
			religion = tibetan_pagan
			remove_province_modifier = recent_bon_conversion
		}
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 32
			attributes = {
				martial = 7
				learning = 7
			}
			trait = zealous
			trait = scholar
			trait = skilled_tactician
		}
		
		new_character = {
			set_character_flag = religious_revolter
			
			create_title = {
				tier = DUKE
				landless = yes
				temporary = yes
				rebel = yes
				culture = ROOT
				name = "HERETIC_REVOLT"
				holder = THIS
				ruler = ""
				ruler_female = ""
			}
			
			wealth = 100
			
			spawn_religious_army_effect = yes
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = powerful
					}
				}
				spawn_religious_army_effect = yes
				wealth = 150
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = very_powerful
					}
				}
				spawn_religious_army_effect = yes
				spawn_religious_army_effect = yes
				spawn_religious_army_effect = yes
				wealth = 250
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = extremely_powerful
					}
				}
				spawn_religious_army_effect = yes
				spawn_religious_army_effect = yes
				spawn_religious_army_effect = yes
				spawn_religious_army_effect = yes
				spawn_religious_army_effect = yes
				wealth = 350
			}
			
			# DoW on the province top liege
			ROOT = {
				owner = {
					top_liege = {
						set_character_flag = has_current_revolt
						reverse_war = {
							target = PREVPREVPREV
							casus_belli = religious_revolt
							thirdparty_title = ROOT # The county...
							tier = DUKE # ... but really the de jure duchy
						}
						reverse_opinion = {
							who = PREVPREVPREV
							modifier = opinion_evil_tyrant
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1061
				}
			}
		}
		
		if = {
			limit = { has_province_modifier = religious_unrest }
			remove_province_modifier = religious_unrest
		}		
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
	}
	
	option = {
		name = EVTOPTA_TOG_1060
		trigger = {
			owner = { religion_group = ROOT }
		}
	}
	option = {
		name = EVTOPTB_TOG_1060
		trigger = {
			owner = { NOT = { religion_group = ROOT	} }
		}
	}
}

character_event = {
	id = TOG.1061
	desc = EVTDESC_TOG_1061
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_TOG_1060
		trigger = {
			religion_group = FROM
		}
	}
	option = {
		name = EVTOPTB_TOG_1060
		trigger = {
			NOT = { religion_group = FROM }
		}
	}
}

# Religious Rebels seize a holding. Fired from 'on_siege_over_winner'. Owner of the winning unit is ROOT. The taken Holding title is in FROM.
character_event = {
	id = TOG.1065
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		has_character_flag = religious_revolter
		rebel = yes
		FROM = {
			location = {
				is_capital = yes # The capital holding
			}
		}
	}
	
	immediate = {
		FROM = {
			location = {
				if = {
					limit = {
						NOT = { religion = ROOT }
					}
					random = {
						chance = 5
						religion = ROOT
					}
				}
				if = {
					limit = {
						NOT = { has_province_modifier = religious_unrest }
					}
					add_province_modifier = {
						name = religious_unrest
						duration = 730
					}
				}
			}
		}
	}
}

# Religious Rebels rise up to reinforce an ongoing heretic uprising
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1070
	desc = EVTDESC_TOG_1070
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		
		is_heretic = no
		
		any_province_holding = {
			NOT = { holding_type = nomad }
		}
		
		owner = {
			top_liege = {
				NOT = { religion_group = ROOT }
			}
		}
		
		owner = {
			top_liege = {
				war = yes
				any_war = {
					defender = { character = PREV }
					using_cb = religious_revolt
					attacker = { religion = ROOT }
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = { has_province_modifier = religious_unrest }
			remove_province_modifier = religious_unrest
		}		
		add_province_modifier = {
			name = recent_county_uprising
			duration = 1825 # Five years of -100% revolt risk in this county
		}
		
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = religious_revolt
						attacker = { religion = ROOT }
					}
					attacker = {
						spawn_religious_reinforcements_effect = yes
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = powerful
								}
							}
							spawn_religious_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = very_powerful
								}
							}
							spawn_religious_reinforcements_effect = yes
							spawn_religious_reinforcements_effect = yes
							spawn_religious_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = extremely_powerful
								}
							}
							spawn_religious_reinforcements_effect = yes
							spawn_religious_reinforcements_effect = yes
							spawn_religious_reinforcements_effect = yes
							spawn_religious_reinforcements_effect = yes
							spawn_religious_reinforcements_effect = yes
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1071
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA_TOG_1070"
	}
}

character_event = {
	id = TOG.1071
	desc = EVTDESC_TOG_1071
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA_TOG_1070"
	}
}

# Dealing with the province where the rebellion started
province_event = {
	id = TOG.1072

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_province_modifier = rebellion_religion_province
	}
	
	immediate = {
		remove_province_modifier = rebellion_religion_province
		if = {
			limit = {
				is_heretic = no
				owner = { top_liege = { NOT = { religion_group = ROOT } } }
			}
			remove_province_modifier = recent_county_uprising
			owner = {
				top_liege = {
					character_event = { id = TOG.1073 }
				}
			}
		}
	}
}

character_event = {
	id = TOG.1073
	desc = EVTDESC_TOG_1073
	picture = GFX_evt_peasants
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes

	immediate = {
		log = "[Root.GetTitledName] receives option to deal with [From.GetName], where Religious rebellion began"
	}
	
	option = {
		name = EVTOPTA_TOG_1073 # Teach them a lesson
		ai_chance = {
			factor = 30
			modifier = {
				factor = 0.1
				OR = {
					trait = patient
					trait = kind
				}
			}
			modifier = {
				factor = 0.25
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
				}
			}
			modifier = {
				factor = 0
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
		}
		tyrant_plus_1_effect = yes
		if = {
			limit = {
				NOT = { trait = patient }
				NOT = { trait = wroth }
			}
			random = {
				chance = 50
				add_trait = wroth
			}
		}
		if = {
			limit = { trait = patient }
			random = {
				chance = 50
				remove_trait = patient
			}
		}
		if = {
			limit = { trait = kind }
			random = {
				chance = 25
				remove_trait = kind
			}
		}
		FROM = {
			add_province_modifier = {
				name = rebellion_lesson
				duration = 1825
			}
			random_list = {
				25 = {
					religion = ROOT
				}
				75 = {
					add_province_modifier = {
						name = recent_county_uprising
						duration = 3650
					}
				}
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_RELIGION
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						has_holder = yes
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							religion = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 730
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTB_TOG_1073 # Do whatever it takes
		ai_chance = {
			factor = 10
			modifier = {
				factor = 0
				OR = {
					trait = patient
					trait = kind
				}
			}
			modifier = {
				factor = 2
				trait = cruel
			}
			modifier = {
				factor = 0
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant11
					trait = tyrant12
					trait = tyrant13
					trait = tyrant14
					trait = tyrant15
					trait = tyrant16
					trait = tyrant17
					trait = tyrant18
					trait = tyrant19
					trait = tyrant20
				}
			}
		}
		tyrant_plus_2_effect = yes
		if = {
			limit = {
				NOT = { trait = patient }
				NOT = { trait = wroth }
			}
			random = {
				chance = 50
				add_trait = wroth
			}
		}
		if = {
			limit = { trait = patient }
			remove_trait = patient
		}
		if = {
			limit = {
				NOT = { trait = kind }
				NOT = { trait = cruel }
			}
			random = {
				chance = 50
				add_trait = cruel
			}
		}
		if = {
			limit = { trait = kind }
			remove_trait = kind
		}
		FROM = {
			add_province_modifier = {
				name = rebellion_reprisal
				duration = 1825
			}
			random_list = {
				50 = {
					religion = ROOT
				}
				50 = {
					add_province_modifier = {
						name = recent_county_uprising
						duration = 7300
					}
				}
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_RELIGION
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						has_holder = yes
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							religion = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 1095
						}
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTC_TOG_1073 # We will find another way
		ai_chance = {
			factor = 60
			modifier = {
				factor = 0.5
				trait = cruel
			}
			modifier = {
				factor = 0.5
				trait = wroth
			}
			modifier = {
				factor = 0.5
				trait = zealous
			}
			modifier = {
				factor = 1.5
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant1
					trait = tyrant2
					trait = tyrant3
					trait = tyrant4
				}
			}
			modifier = {
				factor = 2
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant5
					trait = tyrant6
					trait = tyrant7
				}
			}
			modifier = {
				factor = 3
				NOR = {
					trait = lunatic
					trait = possessed
				}
				OR = {
					trait = tyrant8
					trait = tyrant9
					trait = tyrant10
				}
			}
		}
		FROM = {
			add_province_modifier = {
				name = recent_county_uprising
				duration = 1825
			}
		}
		custom_tooltip = {
			text = TOOLTIP_RECENT_COUNTY_UPRISING_RELIGION
			hidden_tooltip = {
				any_landed_title = {
					limit = {
						has_holder = yes
						tier = COUNT
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
						location = {
							religion = FROM
							NOT = { province_id = FROM }
							NOT = { has_province_modifier = recent_county_uprising }
						}
					}
					location = {
						add_province_modifier = {
							name = recent_county_uprising
							duration = 365
						}
					}
				}
			}
		}
	}
}

### DECADENCE REBELS

# Decadence Rebels rise up (temporary rebel title created, with a leader and a war)
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1080
	desc = EVTDESC_TOG_1080
	picture = GFX_evt_bishop_muslim
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		e_placeholder = { had_title_flag = { flag = startup days = 730 } }
		
		has_province_modifier = decadence_unrest
		
		owner = {
			top_liege = {
				religion_group = muslim
				trait = dynasty_decadence_high
			}
		}
		
		# Heretic revolts have prio
		OR = {
			is_heretic = no
			owner = {
				top_liege = {
					NOT = { is_parent_religion = ROOT }
				}
			}
		}
		
		# Religious revolts have prio
		owner = {
			top_liege = {
				religion_group = ROOT
			}
		}
		
		# Nationalist revolts have prio
		OR = {
			owner = { top_liege = { culture = ROOT } }
			owner = { top_liege = { any_demesne_title = { temporary = yes } } }
			owner = {
				top_liege = {
					OR = {
						controls_religion = yes
						has_landed_title = k_papal_chalcedon
						has_landed_title = d_pentarch_constantinople
					}
					religion = ROOT
				}
			}
			kingdom = { NOT = { culture = ROOT } }
			kingdom = {
				holder_scope = {
					culture = ROOT
					top_liege = { any_realm_province = { province_id = ROOT } }
				}
			}
		}
		
		# not if there is already an ongoing revolt
		NOT = {
			owner = {
				top_liege = {
					has_character_flag = has_current_revolt
					war = yes
				}
			}
		}
	}
	
	immediate = {
		remove_province_modifier = decadence_unrest
		create_character = {
			random_traits = yes
			dynasty = none
			religion = ROOT
			culture = ROOT
			female = no
			age = 32
			health = 7
			attributes = {
				martial = 8
				diplomacy = 8
			}
			trait = just
			trait = brave
			trait = ambitious
			trait = brilliant_strategist
		}
		
		new_character = {
			set_character_flag = decadence_revolter
			save_event_target_as = revolt_leader
			create_title = {
				tier = DUKE
				landless = yes
				temporary = yes
				rebel = yes
				culture = ROOT
				name = "DECADENCE_REVOLT"
				holder = THIS
				ruler = ""
				ruler_female = ""
			}
			
			wealth = 100
			
			spawn_decadence_army_effect = yes
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = powerful
					}
				}
				spawn_decadence_army_effect = yes
				wealth = 150
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = very_powerful
					}
				}
				spawn_decadence_army_effect = yes
				spawn_decadence_army_effect = yes
				spawn_decadence_army_effect = yes
				wealth = 250
			}
			
			if = {
				limit = {
					has_game_rule = {
						name = provincial_revolt_strength
						value = extremely_powerful
					}
				}
				spawn_decadence_army_effect = yes
				spawn_decadence_army_effect = yes
				spawn_decadence_army_effect = yes
				spawn_decadence_army_effect = yes
				spawn_decadence_army_effect = yes
				wealth = 350
			}
			
			# DoW on the province top liege
			ROOT = {
				owner = {
					top_liege = {
						set_character_flag = has_current_revolt
						reverse_war = {
							target = PREVPREVPREV
							casus_belli = decadence_revolt
							thirdparty_title = ROOT # The county
						}
						reverse_opinion = {
							who = PREVPREVPREV
							modifier = opinion_evil_tyrant
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1081
				}
			}
		}
		
		add_province_modifier = {
			name = recent_county_uprising
			duration = 3650 # Ten years of -100% revolt risk in this county
		}
	}
	
	option = {
		name = CURSES
	}
}

character_event = {
	id = TOG.1081
	desc = EVTDESC_TOG_1081
	picture = GFX_evt_bishop_muslim
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = CURSES
	}
}

# Decadence rebels seize a holding. Fired from 'on_siege_won_leader'.
character_event = {
	id = TOG.1085
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		FROM = { 
			location = {
				is_capital = yes # The capital holding
			}
		}
		religion_group = muslim
		any_war = {
			any_attacker = {
				OR = {
					character = ROOT
					is_liege_of = ROOT
				}
				religion_group = ROOT
			}
			using_cb = decadence_revolt
		}
	}
	
	immediate = {
		FROM = {
			location = {
				if = {
					limit = {
						religion_group = ROOT
						NOT = { has_province_modifier = decadence_unrest }
					}
					add_province_modifier = {
						name = decadence_unrest
						duration = 730
					}
				}
			}
		}
	}
}

# Decadence Rebels rise up to reinforce an ongoing revolt
# Triggered from "on_rebel_revolt"
province_event = {
	id = TOG.1090
	desc = EVTDESC_TOG_1090
	picture = GFX_evt_bishop_muslim
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "The Old Gods"
		
		# There is already an ongoing decadence revolt
		owner = {
			top_liege = {
				war = yes
				religion_group = muslim
				any_war = {
					defender = { character = PREV }
					using_cb = decadence_revolt
					attacker = {
						religion_group = muslim
						religion_group = ROOT
					}
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = { has_province_modifier = decadence_unrest }
			remove_province_modifier = decadence_unrest
		}
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = decadence_revolt
						attacker = {
							religion_group = muslim
							religion_group = ROOT
						}
					}
					attacker = {
						spawn_decadence_reinforcements_effect = yes
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = powerful
								}
							}
							spawn_decadence_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = very_powerful
								}
							}
							spawn_decadence_reinforcements_effect = yes
							spawn_decadence_reinforcements_effect = yes
							spawn_decadence_reinforcements_effect = yes
						}
						
						if = {
							limit = {
								has_game_rule = {
									name = provincial_revolt_strength
									value = extremely_powerful
								}
							}
							spawn_decadence_reinforcements_effect = yes
							spawn_decadence_reinforcements_effect = yes
							spawn_decadence_reinforcements_effect = yes
							spawn_decadence_reinforcements_effect = yes
							spawn_decadence_reinforcements_effect = yes
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = TOG.1091
				}
			}
		}
		
		add_province_modifier = {
			name = recent_county_uprising
			duration = 3650 # Five years of -100% revolt risk in this county
		}
	}
	
	option = {
		name = CURSES
	}
}

character_event = {
	id = TOG.1091
	desc = EVTDESC_TOG_1091
	picture = GFX_evt_bishop_muslim
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = CURSES
	}
}


### REBELS KILL CHARACTER AFTER SIEGE

# Rebels kill a local character. Fired from 'on_siege_over_loc_chars'.
# Siege winner unit owner in the 'new_character' scope, lost holding title in FROM, local character in ROOT.
character_event = {
	id = TOG.1190
	desc = EVTDESC_TOG_1190
	picture = GFX_evt_beheading
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	trigger = {
		new_character = {
			rebel = yes
			
			OR = {
				NOT = { religion = ROOT }
				AND = {
					NOT = { has_character_flag = heretic_revolter }
					NOT = { has_character_flag = religious_revolter }
					NOT = { has_character_flag = shepherds_crusade_leader }
				}
			}
		}
	}
	
	weight_multiplier = {
		days = 1
		modifier = {
			factor = 0.5
			is_female = yes
		}
		modifier = {
			factor = 0.5
			is_adult = no
		}
		modifier = {
			factor = 0.9
			intrigue = 10
		}
		modifier = {
			factor = 0.9
			intrigue = 12
		}
		modifier = {
			factor = 0.9
			intrigue = 14
		}
		modifier = {
			factor = 0.9
			intrigue = 16
		}
		modifier = {
			factor = 0.9
			intrigue = 18
		}
		modifier = {
			factor = 0.9
			intrigue = 20
		}
	}
	
	immediate = {
		any_liege = { # Inform the victim's lieges
			character_event = {
				id = TOG.1191
			}
		}
		new_character = {
			ROOT = {
				death = {
					death_reason = death_rabble
					killer = PREV
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_TOG_1190
	}
}

# Lieges informed
character_event = {
	id = TOG.1191
	picture = GFX_evt_beheading
	desc = EVTDESC_TOG_1191
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	notification = yes
	
	ai = no
	
	option = {
		name = EVTOPTA_TOG_1191
	}
}

