#########################################################
#
# Rebel Events for the Horse Lords expansion
# ( HL.2000 to HL.2499)
#
#########################################################

# Written by Henrik Fhraeus

namespace = HL

# Minor Clan leader appears, demands province from nomad ruler
# Triggered from "on_rebel_revolt"
province_event = {
	id = HL.2000
	desc = EVTDESC_HL_2000
	picture = GFX_evt_steppe_mercenaries
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "Horse Lords"
		e_placeholder = { had_title_flag = { flag = startup days = 730 } }
		
		has_empty_holding = yes # To allow a Clan capital
		
		owner = {
			is_nomadic = yes
			independent = yes
			culture = ROOT
			risks_minor_clan_rising = yes
			in_revolt = no
			capital_scope = { 
				NOT = { province = ROOT }
			}
		}
		
		# 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 } }
				}
			}
		}
		
		# Decadence revolts have prio
		OR = {
			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 revolt
		NOT = {
			owner = {
				top_liege = {
					has_character_flag = has_current_revolt
					war = yes
				}
			}
		}
	}	

	immediate = {
		owner = { save_event_target_as = province_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 = brave
			trait = ambitious
			trait = skilled_tactician
		}
		new_character = {
			prestige = 100
			diplomatic_immunity = yes
			save_event_target_as = minor_clan_leader
		}
	}
	
	option = {
		name = EVTOPTA_HL_2000 # Give him the land
		ai_chance = {
			factor = 25
			modifier = {
				factor = 2
				owner = { trait = craven }
			}
			modifier = {
				factor = 2
				owner = { trait = humble }
			}
			modifier = {
				factor = 1.5
				owner = { trait = kind }
			}
			modifier = {
				factor = 1.5
				owner = { trait = content }
			}
			modifier = {
				factor = 2
				owner = { NOT = { realm_levies = 1000 } }
			}
			modifier = {
				factor = 2
				owner = { NOT = { realm_levies = 500 } }
			}
			modifier = {
				factor = 2
				owner = {
					NOT = {
						any_vassal = {
							tier = KING
							is_nomadic = yes
							count = 3
						}
					}
				}
			}
		}
		owner = { prestige = -100 }
		event_target:minor_clan_leader = {
			ROOT = { county = { grant_title = PREVPREV } }
			hidden_tooltip = { set_government_type = nomadic_government }
			set_defacto_liege = event_target:province_top_liege
			hidden_tooltip = {
				wealth = 100
				diplomatic_immunity = no
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = THIS
					scaled_with_population_of = event_target:province_top_liege
					for_population = 10000
					troops = {
						light_cavalry = { 200 200 }
						horse_archers = { 800 800 }
					}
					attrition = 0.25
				}
				create_character = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					age = 30
					attributes = {
						martial = 7
					}
					trait = skilled_tactician
				}
				create_character = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					age = 31
					attributes = {
						martial = 7
					}
					trait = skilled_tactician
				}
			}
		}
		hidden_tooltip = {
			owner = { add_population_scaled = -0.1 }
		}
	}
	option = {
		name = EVTOPTB_HL_2000 # Never!
		ai_chance = {
			factor = 75
			modifier = {
				factor = 0
				owner = {
					OR = {
						is_adult = no
						prisoner = yes
						trait = incapable
					}
				}
			}
			modifier = {
				factor = 1.5
				owner = { trait = ambitious }
			}
			modifier = {
				factor = 1.5
				owner = { trait = brave }
			}
			modifier = {
				factor = 1.5
				owner = { trait = proud }
			}
			modifier = {
				factor = 1.5
				owner = { trait = wroth }
			}
		}
		event_target:minor_clan_leader = {
			ROOT = {
				owner = {
					tooltip = {
						reverse_war = {
							target = PREVPREV
							casus_belli = cb_minor_clan_revolt
							thirdparty_title = ROOT # The county
						}
					}
					reverse_opinion = {
						who = PREVPREV
						modifier = opinion_evil_tyrant
					}
				}
			}
		}
		hidden_tooltip = {
			add_province_modifier = {
				name = recent_county_uprising
				duration = 3650 # ten years of -100% revolt risk in this county
			}
			event_target:minor_clan_leader = {
				create_title = {
					tier = KING
					landless = yes
					temporary = yes
					rebel = yes
					culture = ROOT
					name = "MINOR_CLAN_REVOLT"
					holder = THIS
					nomad = yes
				}
				
				set_government_type = nomadic_government
				diplomatic_immunity = no
				
				random_list = {
					34 = {
						spawn_unit = {
							province = ROOT
							home = ROOT
							owner = THIS
							#leader = THIS
							scaled_with_population_of = event_target:province_top_liege
							for_population = 10000
							troops = {
								light_cavalry = { 200 200 }
								horse_archers = { 800 800 }
							}
							attrition = 0.25
						}
						create_character = {
							random_traits = yes
							dynasty = none
							religion = THIS
							culture = THIS
							female = no
							age = 30
							attributes = {
								martial = 7
							}
							trait = skilled_tactician
						}
						new_character = {
							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = PREV
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								troops = {
									light_cavalry = { 200 200 }
									horse_archers = { 800 800 }
								}
								attrition = 0.25
								disband_on_peace = yes
							}
						}
						create_character = {
							random_traits = yes
							dynasty = none
							religion = THIS
							culture = THIS
							female = no
							age = 31
							attributes = {
								martial = 7
							}
							trait = skilled_tactician
						}
						new_character = {
							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = PREV
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								troops = {
									light_cavalry = { 200 200 }
									horse_archers = { 800 800 }
								}
								attrition = 0.25
								disband_on_peace = yes
							}
						}
					}
					33 = {
						spawn_unit = {
							province = ROOT
							home = ROOT
							owner = THIS
							#leader = THIS
							scaled_with_population_of = event_target:province_top_liege
							for_population = 10000
							troops = {
								light_cavalry = { 150 150 }
								horse_archers = { 600 600 }
							}
							attrition = 0.25
						}
						create_character = {
							random_traits = yes
							dynasty = none
							religion = THIS
							culture = THIS
							female = no
							age = 30
							attributes = {
								martial = 7
							}
							trait = skilled_tactician
						}
						new_character = {
							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = PREV
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								troops = {
									light_cavalry = { 150 150 }
									horse_archers = { 600 600 }
								}
								attrition = 0.25
								disband_on_peace = yes
							}
						}
						create_character = {
							random_traits = yes
							dynasty = none
							religion = THIS
							culture = THIS
							female = no
							age = 31
							attributes = {
								martial = 7
							}
							trait = skilled_tactician
						}
						new_character = {
							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = PREV
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								troops = {
									light_cavalry = { 150 150 }
									horse_archers = { 600 600 }
								}
								attrition = 0.25
								disband_on_peace = yes
							}
						}
					}
					33 = {
						spawn_unit = {
							province = ROOT
							home = ROOT
							owner = THIS
							#leader = THIS
							scaled_with_population_of = event_target:province_top_liege
							for_population = 10000
							troops = {
								light_cavalry = { 100 100 }
								horse_archers = { 400 400 }
							}
							attrition = 0.25
						}
						create_character = {
							random_traits = yes
							dynasty = none
							religion = THIS
							culture = THIS
							female = no
							age = 30
							attributes = {
								martial = 7
							}
							trait = skilled_tactician
						}
						new_character = {
							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = PREV
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								troops = {
									light_cavalry = { 100 100 }
									horse_archers = { 400 400 }
								}
								attrition = 0.25
								disband_on_peace = yes
							}
						}
						create_character = {
							random_traits = yes
							dynasty = none
							religion = THIS
							culture = THIS
							female = no
							age = 31
							attributes = {
								martial = 7
							}
							trait = skilled_tactician
						}
						new_character = {
							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = PREV
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								troops = {
									light_cavalry = { 100 100 }
									horse_archers = { 400 400 }
								}
								attrition = 0.25
								disband_on_peace = yes
							}
						}
					}
				}
				
				# DoW on the province top liege
				ROOT = {
					owner = {
						add_population_scaled = -0.1
						set_character_flag = has_current_revolt
						reverse_war = {
							target = PREVPREV
							casus_belli = cb_minor_clan_revolt
							thirdparty_title = ROOT # The county
						}
					}
				}
			}	
		}
	}
}

# Minor Clan rebels seize a holding. Fired from 'on_siege_over_winner'.
character_event = {
	id = HL.2005
	
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
		rebel = yes
		any_war = {
			attacker = { character = ROOT }
			using_cb = cb_minor_clan_revolt
		}
	}
	
	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 = HL.2010
	desc = EVTDESC_HL_2010
	picture = GFX_evt_steppe_mercenaries
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes

	trigger = {
		has_dlc = "Horse Lords"
		
		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 = cb_minor_clan_revolt
#					war_title = ROOT # The county
				}
			}
		}
	}
	
	immediate = {
	
		add_province_modifier = {
			name = recent_county_uprising
			duration = 3650 # Five years of -100% revolt risk in this county
		}
		
		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREV }
						using_cb = cb_minor_clan_revolt
#						war_title = ROOT # The county
					}
					attacker = {
						random_list = {
							34 = {
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 25
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 200 200 }
											horse_archers = { 800 800 }
										}
										attrition = 0.25
									}
								}
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 30
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 200 200 }
											horse_archers = { 800 800 }
										}
										attrition = 0.25
										disband_on_peace = yes
									}
								}
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 31
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 200 200 }
											horse_archers = { 800 800 }
										}
										attrition = 0.25
										disband_on_peace = yes
									}
								}
							}
							33 = {
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 25
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 150 150 }
											horse_archers = { 600 600 }
										}
										attrition = 0.25
									}
								}
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 30
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 150 150 }
											horse_archers = { 600 600 }
										}
										attrition = 0.25
										disband_on_peace = yes
									}
								}
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 31
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 150 150 }
											horse_archers = { 600 600 }
										}
										attrition = 0.25
										disband_on_peace = yes
									}
								}
							}
							33 = {
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 25
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 100 100 }
											horse_archers = { 400 400 }
										}
										attrition = 0.25
									}
								}
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 30
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 100 100 }
											horse_archers = { 400 400 }
										}
										attrition = 0.25
										disband_on_peace = yes
									}
								}
								create_character = {
									random_traits = yes
									dynasty = none
									religion = THIS
									culture = THIS
									female = no
									age = 31
									attributes = {
										martial = 7
									}
									trait = skilled_tactician
								}
								new_character = {
									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = PREV
										troops = {
											light_cavalry = { 100 100 }
											horse_archers = { 400 400 }
										}
										attrition = 0.25
										disband_on_peace = yes
									}
								}
							}
						}
					}
				}
			}
		}
		
		owner = {
			any_liege = { # Inform the lieges
				character_event = {
					id = HL.2011
				}
			}
		}
	}
	
	option = {
		name = EVTOPTA_HL_2000
	}
}

character_event = {
	id = HL.2011
	desc = EVTDESC_HL_2011
	picture = GFX_evt_steppe_mercenaries
	border = GFX_event_normal_frame_war
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_HL_2000
	}
}

