######################################################################
# Throne Pretender rebels.
######################################################################

#To find what's been added by the mod, search #Byz_resurgence added
pretender_rebels = {
	
	color = { 179 51 51 }
	
	area = nation
	government = monarchy
	defection = none
	independence = none
	unit_transfer = yes
	gfx_type = culture_province	
	
	resilient = yes					# Will not disband on defeat.
	reinforcing = yes				# Will reinforce (double rate in rebel controlled provinces)
	general = yes					# Does use generals. The 'define_ruler' effect with 'rebel' argument will pick the rebel leader as new King.
	smart = yes
	disband_on_leader_death = no	# Pretender rebels live forever!
	will_relocate = yes				# Units will relocate if they have sieged all provinces nearby and has to move over sea.
	dynasty = yes	#same dynasty for rebel uprising
	
	
	artillery = 0.1
	infantry = 0.6 #From 0.5
	cavalry = 0.3 #From 0.4 to account for Misc's cav rebalance.
	
	morale = 1.25
	
	# Possible handle actions
	handle_action_negotiate = no
	handle_action_stability = yes
	handle_action_build_core = yes
	handle_action_send_missionary = yes		
	
	spawn_chance = {
		factor = 1
		#Byz_resurgence added: If the Military Coup disaster fires, adjust so there's plenty of chance for pretenders to rise.
		modifier = {
			factor = 20
			owner = {
				has_disaster = estate_generals_disaster
			}
		}
		#Byz_resurgence added: If the Succession Crisis disaster fires, adjust so there's plenty of chance for pretenders to rise.
		modifier = {
			factor = 20
			owner = {
				has_disaster = succession_crisis
			}
		}
		modifier = {
			factor = 0
			owner = {
				has_reform = papacy_reform
			}
		}
		modifier = {
			factor = 0
			owner = {
				is_colonial_nation = yes
			}
		}
		modifier = {
			factor = 0
			owner = {
				NOT = { num_of_cities = 3 }
			}
		}
		modifier = {
			factor = 0
			is_overseas = yes
		}
		modifier = {
			factor = 0.05
			owner = {
				OR = {
					has_country_modifier = the_mandate_of_heaven_lost
					has_country_modifier = lost_mandate_of_heaven
				}
			}
		}
		modifier = {
			factor = 2
			owner = {
				government = republic
				aristocracy_ideas = 1
			}
		}
		modifier = {
			factor = 20
			owner = {
				has_disaster = civil_war
				#has_disaster = counts_feud
			}
		}
		modifier = {
			factor = 20
			owner = {
				has_disaster = english_civil_war
			}
		}
		modifier = {
			factor = 10
			owner = {
				has_disaster = granada_succession_war
			}
		}
		modifier = {
			factor = 20
			owner = {
				has_disaster = counts_feud
				has_country_flag = monarch_flag
			}
		}
		modifier = {
			factor = 20
			owner = {
				has_disaster = castilian_civil_war
			}
		}
		modifier = {
			factor = 5
			owner = {
				has_disaster = time_of_troubles
			}
		}
		modifier = {
			factor = 5.0
			owner = {
				government = republic
				NOT = { republican_tradition = 40 }
			}
		}	
		modifier = {
			factor = 50.0
			owner = { has_disaster = war_of_the_roses }
		}
		modifier = {
			factor = 2
			owner = { religion = inti }
		}
		modifier = {
			factor = 30
			owner = {
				government = monarchy
				has_regency = yes
				has_heir = no
			}
		}
		modifier = {
			factor = 5
			owner = {
				government = monarchy
				has_regency = yes
				has_heir = yes
				NOT = { heir_claim = 33 }
			}
		}
		modifier = {
			factor = 5
			owner = {
				government = monarchy
				has_regency = yes
				has_heir = yes
				NOT = { heir_claim = 66 }
			}
		}
		modifier = {
			factor = 2
			owner = {
				government = monarchy
				has_regency = yes
				has_heir = yes
				NOT = { heir_claim = 85 }
			}
		}
		modifier = {
			factor = 4.5
			owner = {
				is_lesser_in_union = yes
			}
		}
		modifier = {
			factor = 3
			owner = {
				is_lesser_in_union = yes
				NOT = { legitimacy = 75 }
			}
		}
		modifier = {
			factor = 3
			owner = {
				is_lesser_in_union = yes
				NOT = { legitimacy = 50 }
			}
		}
		modifier = {
			factor = 3
			owner = {
				is_lesser_in_union = yes
				NOT = { legitimacy = 25 }
			}
		}
		modifier = {
			factor = 0.25
			owner = {
				NOT = { primary_culture = ROOT }
			}
		}
		modifier = {
			factor = 0.1
			NOT = { is_core = ROOT }
			any_core_country = {
				primary_culture = ROOT
	 		}
		}
		modifier = {
			factor = 0.75
			owner = {
				government = monarchy
				legitimacy = 66
			}
		}
		modifier = {
			factor = 0.5
			owner = {
				government = monarchy
				legitimacy = 75
			}
		}
		modifier = {
			factor = 10
			owner = { has_country_modifier = "tribal_succession_crisis" }
		}
		modifier = {
			factor = 2.5
			owner = {
				government = tribal
			}
		}
	}
 
 	# This is checked for EACH province in the Area of Operations
	movement_evaluation = {
		factor = 1
		modifier = {
			factor = 0.1
			units_in_province = 1
		}
		modifier = {
			factor = 0.001
			controlled_by = REB
		}
		modifier = {
			factor = 4.0
			is_capital = yes
		}
		modifier = {
			factor = 1.5
			unrest = 2
		}
		modifier = {
			factor = 1.5
			unrest = 4
		}
		modifier = {
			factor = 1.5
			unrest = 6
		}
	}
 
 	# Province Scope
 	siege_won_trigger = {
 	}
	siege_won_effect = {
	}
	
	# Country scope
	can_negotiate_trigger = {
		always = no
	}
	
	# Country scope
	can_enforce_trigger = {
		always = yes
	}
	
	# Localisation for their demands
	demands_description = "pretender_rebels_demand"
	
	# Country Scope	
	demands_enforced_effect = {
		hidden_effect = {
			add_country_modifier = {
				name = just_lost_to_rebels
				duration = 10
				hidden = yes
			}
		}
		if = {
			limit = {
				has_states_general_mechanic = yes
			}
			change_statists_vs_orangists = 1
		}
		if = {
			limit = { religion = inti }
			remove_religious_reforms = 2
		}
		if = {
			limit = { has_disaster = civil_war }
			add_prestige = -200
			add_legitimacy = 25
		}
		if = {
			limit = {
				NOT = {
					OR = {
						government = theocracy
						has_reform = steppe_horde
						has_reform = celestial_empire
						has_reform = iqta
						has_reform = indep_daimyo
						has_reform = principality
						has_reform = daimyo
						has_reform = appanage_reform
						has_reform = shogunate
						has_reform = colonial_government
						has_reform = siberian_tribe
						government = native
						has_reform = elective_monarchy
						has_reform = english_monarchy
						has_reform = ottoman_government
						has_reform = modernized_ottoman_government
						has_reform = reorganized_ottoman_government
						has_reform = sultanate_of_rum_reform
						has_reform = eyalet_government
						has_reform = barbary_eyalet_government
						has_reform = kalmar_union
						has_reform = danish_archkingdom
						has_reform = tribal_federation
						has_reform = feudal_theocracy
						has_reform = mamluk_government
						government = tribal
					}
				}
			}
			change_government = REB
			#set_legacy_government = despotic_monarchy
		}
		if = {
			limit = { has_heir = yes }
			kill_heir = { allow_new_heir = no }
		}
		if = {
			limit = { has_consort = yes }
			kill_consort = yes
		}
		set_country_flag = no_new_succession_crisis_if_pretender_rebels #This is used in the event that triggers from the on_action to ensure that you don't get new pretenders if these pretenders are happening because of a succession crisis.
		define_ruler = {
			rebel = yes
		}
		clr_country_flag = no_new_succession_crisis_if_pretender_rebels
		if = {
			limit = { has_disaster = counts_feud }
			end_disaster = counts_feud
			clr_country_flag = pretender_flag
			clr_country_flag = monarch_flag
		}
		if = {
			limit = { has_disaster = civil_war }
			end_disaster = civil_war
			clr_country_flag = civilwar_on_capital
		}
		if = {
			limit = { has_disaster = internal_conflicts }
			country_event = { id = internal_conflicts.8 }
			end_disaster = internal_conflicts
		}
		if = {
			limit = { has_disaster = castilian_civil_war }
			set_country_flag = cas_civil_war_rebels_won
			country_event = { id = castilian_civil_war.100 }
			end_disaster = castilian_civil_war
		}
		if = {
			limit = { has_disaster = time_of_troubles }
			country_event = { id = time_of_troubles.10 }
			end_disaster = time_of_troubles
		}
		if = {
			limit = { has_disaster = english_civil_war }
			country_event = { id = english_civil_war.100 }
			end_disaster = english_civil_war
		}
		if = {
			limit = { is_revolution_target = yes }
			set_revolution_target = ---
		}
		#Byz_resurgence added: Clears Succession Crisis upon enforcing demands.
		if = {
			limit = { has_disaster = succession_crisis }
			end_disaster = succession_crisis
			clr_country_flag = had_byz_succ_crisis
			custom_tooltip = byz_pretender_rebels_disaster_tooltip
			country_event = { id = succession_crisis.36 }
		}
		#Byz_resurgence added: Clears Military Coup upon enforcing demands.
		if = {
			limit = { has_disaster = estate_generals_disaster }
			end_disaster = estate_generals_disaster
			clr_country_flag = byz_current_ruler_is_not_deposed
			country_event = { id = strategoi_estate_events.22 }
		}
		#Byz_resurgence added: If one of the nobility privileges are the cause of the rebels, restore the latifundia.
		if = {
			limit = { 
				had_country_flag = {
					flag = byz_revoked_latifundia_kantakouzenos
					days = 3650
				}
			}
			set_estate_privilege = estate_nobles_latifundia_kantakouzenos
		}
		if = {
			limit = { 
				had_country_flag = {
					flag = byz_revoked_latifundia_philantropenos
					days = 3650
				}
			}
			set_estate_privilege = estate_nobles_latifundia_philantropenos
		}
		if = {
			limit = { 
				had_country_flag = {
					flag = byz_revoked_latifundia_metochites
					days = 3650
				}
			}
			set_estate_privilege = estate_nobles_latifundia_metochites
		}
		if = {
			limit = { 
				had_country_flag = {
					flag = byz_revoked_latifundia_choumnos
					days = 3650
				}
			}
			set_estate_privilege = estate_nobles_latifundia_choumnos
		}
		if = {
			limit = { 
				had_country_flag = {
					flag = byz_revoked_latifundia_melissenos
					days = 3650
				}
			}
			set_estate_privilege = estate_nobles_latifundia_melissenos
		}
		if = {
			limit = { 
				had_country_flag = {
					flag = byz_revoked_latifundia_tornikes
					days = 3650
				}
			}
			set_estate_privilege = estate_nobles_latifundia_tornikes
		}
		
	}
}
