#########################################################
#
# 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 # on_rebel_revolt via TOG.999, oldgods_rebel_events.txt

	immediate = {
		owner = {
			save_event_target_as = province_top_liege
		}

		county = {
			save_event_target_as = province_county
		}

		create_character = {
			random_traits = yes
			dynasty = random
			religion = ROOT
			culture = ROOT
			female = no
			age = 35
			health = 7
			fertility = 0.7
			add_trait = brave
			add_trait = ambitious
			add_trait = skilled_tactician

			attributes = {
				martial = 8
				diplomacy = 9
			}
		}

		new_character = {
			diplomatic_immunity = yes
			save_event_target_as = minor_clan_revolt_leader
			wealth = 500
			prestige = 500
			population = 3000
			manpower = 500
		}
	}

	option = {
		name = EVTOPTA_HL_2000 # Give him the land

		owner = {
			show_scope_change = no

			prestige = -100

			hidden_effect = {
				add_population_scaled = -0.1
			}
		}

		event_target:minor_clan_revolt_leader = {
			show_scope_change = no

			grant_title = event_target:province_county
			set_defacto_liege = event_target:province_top_liege

			hidden_effect = {
				set_government_type = nomadic_government
				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
					attrition = 0.25
					cannot_inherit = yes

					troops = {
						light_cavalry = { 200 200 }
						horse_archers = { 800 800 }
					}
				}

				create_character = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					age = 16
					add_trait = skilled_tactician

					attributes = {
						martial = 7
					}
				}

				new_character = {
					dynasty = event_target:minor_clan_revolt_leader
					set_father = event_target:minor_clan_revolt_leader

					spawn_unit = {
						province = ROOT
						home = ROOT
						owner = PREV
						scaled_with_population_of = event_target:province_top_liege
						for_population = 10000
						attrition = 0.25
						disband_on_peace = yes
						cannot_inherit = yes

						troops = {
							light_cavalry = { 200 200 }
							horse_archers = { 800 800 }
						}
					}
				}

				create_character = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					age = 17
					add_trait = skilled_tactician

					attributes = {
						martial = 7
					}
				}

				new_character = {
					dynasty = event_target:minor_clan_revolt_leader
					set_father = event_target:minor_clan_revolt_leader

					spawn_unit = {
						province = ROOT
						home = ROOT
						owner = PREV
						scaled_with_population_of = event_target:province_top_liege
						for_population = 10000
						attrition = 0.25
						disband_on_peace = yes
						cannot_inherit = yes

						troops = {
							light_cavalry = { 200 200 }
							horse_archers = { 800 800 }
						}
					}
				}
			}
		}

		ai_chance = {
			factor = 25

			mult_modifier = {
				factor = 2
				owner = { trait = craven }
			}

			mult_modifier = {
				factor = 2
				owner = { trait = humble }
			}

			mult_modifier = {
				factor = 1.5
				owner = { trait = kind }
			}

			mult_modifier = {
				factor = 1.5
				owner = { trait = content }
			}

			mult_modifier = {
				factor = 2
				owner = { realm_levies < 1000 }
			}

			mult_modifier = {
				factor = 2
				owner = { realm_levies < 500 }
			}

			mult_modifier = {
				factor = 2

				owner = {
					NOT = {
						any_vassal = {
							is_nomadic = yes
							real_tier = KING
							count >= 3
						}
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTB_HL_2000 # Never!

		event_target:minor_clan_revolt_leader = {
			show_scope_change = no

			tooltip = {
				war = {
					target = event_target:province_top_liege
					casus_belli = cb_minor_clan_revolt
					thirdparty_title = ROOT
				}
			}

			opinion = {
				name = opinion_evil_tyrant
				who = event_target:province_top_liege
			}
		}

		hidden_effect = {
			add_province_modifier = {
				name = recent_county_uprising
				years = 10 # -100% revolt risk in this county
			}

			owner = {
				add_population_scaled = -0.1
				set_character_flag = has_current_revolt
			}

			event_target:minor_clan_revolt_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
							scaled_with_population_of = event_target:province_top_liege
							for_population = 10000
							attrition = 0.25
							cannot_inherit = yes

							troops = {
								light_cavalry = { 200 200 }
								horse_archers = { 800 800 }
							}
						}

						while = {
							count = 2

							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = THIS
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								attrition = 0.25
								disband_on_peace = yes
								cannot_inherit = yes

								troops = {
									light_cavalry = { 200 200 }
									horse_archers = { 800 800 }
								}
							}
						}
					}

					33 = {
						spawn_unit = {
							province = ROOT
							home = ROOT
							owner = THIS
							scaled_with_population_of = event_target:province_top_liege
							for_population = 10000
							attrition = 0.25
							cannot_inherit = yes

							troops = {
								light_cavalry = { 150 150 }
								horse_archers = { 600 600 }
							}
						}

						while = {
							count = 2

							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = THIS
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								attrition = 0.25
								disband_on_peace = yes
								cannot_inherit = yes

								troops = {
									light_cavalry = { 150 150 }
									horse_archers = { 600 600 }
								}
							}
						}
					}

					33 = {
						spawn_unit = {
							province = ROOT
							home = ROOT
							owner = THIS
							scaled_with_population_of = event_target:province_top_liege
							for_population = 10000
							attrition = 0.25
							cannot_inherit = yes

							troops = {
								light_cavalry = { 100 100 }
								horse_archers = { 400 400 }
							}
						}

						while = {
							count = 2

							spawn_unit = {
								province = ROOT
								home = ROOT
								owner = THIS
								scaled_with_population_of = event_target:province_top_liege
								for_population = 10000
								attrition = 0.25
								disband_on_peace = yes
								cannot_inherit = yes

								troops = {
									light_cavalry = { 100 100 }
									horse_archers = { 400 400 }
								}
							}
						}
					}
				}

				# Create two sons, able commanders
				create_character = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					age = 16
					add_trait = skilled_tactician

					attributes = {
						martial = 7
					}
				}

				new_character = {
					dynasty = event_target:minor_clan_revolt_leader
					set_father = event_target:minor_clan_revolt_leader
				}

				create_character = {
					random_traits = yes
					dynasty = none
					religion = THIS
					culture = THIS
					female = no
					age = 17
					add_trait = skilled_tactician

					attributes = {
						martial = 7
					}
				}

				new_character = {
					dynasty = event_target:minor_clan_revolt_leader
					set_father = event_target:minor_clan_revolt_leader
				}

				# DoW on the province top liege
				war = {
					target = event_target:province_top_liege
					casus_belli = cb_minor_clan_revolt
					thirdparty_title = ROOT # The county
				}
			}
		}

		ai_chance = {
			factor = 75

			trigger = {
				owner = {
					is_adult = yes
					prisoner = no
					is_incapable = no
				}
			}

			mult_modifier = {
				factor = 1.5
				owner = { trait = ambitious }
			}

			mult_modifier = {
				factor = 1.5
				owner = { trait = brave }
			}

			mult_modifier = {
				factor = 1.5
				owner = { trait = proud }
			}

			mult_modifier = {
				factor = 1.5
				owner = { trait = wroth }
			}
		}
	}
}

# character_event = {
# 	id = HL.2001
# 	desc = EVTDESC_HL_2001
# 	picture = GFX_evt_steppe_mercenaries
# 	border = GFX_event_normal_frame_war
#
# 	is_triggered_only = yes
#
# 	ai = no
#
# 	option = {
# 		name = EVTOPTA_HL_2000
# 	}
# }

# Minor Clan rebels seize a holding. Fired from 'on_siege_over_winner'.
character_event = {
	id = HL.2005

	is_triggered_only = yes # on_siege_over_winner
	hide_window = 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
						years = 2
					}
				}
			}
		}
	}
}

# 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 # on_rebel_revolt via TOG.999, oldgods_rebel_events.txt

	immediate = {
		add_province_modifier = {
			name = recent_county_uprising
			years = 10 # -100% revolt risk in this county
		}

		owner = {
			top_liege = {
				any_war = {
					limit = {
						defender = { character = PREVPREV }
						using_cb = cb_minor_clan_revolt
					}

					attacker = {
						random_list = {
							34 = {
								spawn_unit = {
									province = ROOT
									home = ROOT
									owner = THIS
									attrition = 0.25

									troops = {
										light_cavalry = { 200 200 }
										horse_archers = { 800 800 }
									}
								}

								while = {
									count = 2

									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = THIS
										attrition = 0.25
										disband_on_peace = yes

										troops = {
											light_cavalry = { 200 200 }
											horse_archers = { 800 800 }
										}
									}
								}
							}

							33 = {
								spawn_unit = {
									province = ROOT
									home = ROOT
									owner = THIS
									attrition = 0.25

									troops = {
										light_cavalry = { 150 150 }
										horse_archers = { 600 600 }
									}
								}

								while = {
									count = 2

									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = THIS
										attrition = 0.25
										disband_on_peace = yes

										troops = {
											light_cavalry = { 150 150 }
											horse_archers = { 600 600 }
										}
									}
								}
							}

							33 = {
								spawn_unit = {
									province = ROOT
									home = ROOT
									owner = THIS
									attrition = 0.25

									troops = {
										light_cavalry = { 100 100 }
										horse_archers = { 400 400 }
									}
								}

								while = {
									count = 2

									spawn_unit = {
										province = ROOT
										home = ROOT
										owner = THIS
										attrition = 0.25
										disband_on_peace = yes

										troops = {
											light_cavalry = { 100 100 }
											horse_archers = { 400 400 }
										}
									}
								}
							}
						}

						# Spawn commanders if below the limit
						while = {
							limit = { can_grant_title = title_commander }

							create_character = {
								random_traits = yes
								dynasty = none
								religion = THIS
								culture = THIS
								female = no
								age = 25
								add_trait = skilled_tactician

								attributes = {
									martial = 7
								}
							}

							new_character = {
								give_minor_title = title_commander

								random_list = {
									1 = { }
									1 = { add_age = 1 }
									1 = { add_age = 2 }
									1 = { add_age = 3 }
									1 = { add_age = 4 }
									1 = { add_age = 5 }
									1 = { add_age = 6 }
								}
							}
						}
					}
				}
			}

			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

	ai = no

	option = {
		name = EVTOPTA_HL_2000
	}
}