###########################################
# Events for Russian Principalities
# Written by Henrik Lohmander
###########################################

namespace = russian_principality_events

#Plot of the Prince of [appanage_province.GetName]
country_event = {
	id = russian_principality_events.1
	title = russian_principality_events.1.t
	desc = russian_principality_events.1.d
	picture = OPRICHINA_eventPicture

	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		num_of_cities = 3
		any_owned_province = {
			has_owner_culture = yes
			is_capital = no
			is_city = yes
		}
	}
	
	is_triggered_only = yes
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
				}
				save_event_target_as = appanage_province
			}
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
					development = 8
				}
				save_event_target_as = appanage_province
			}
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
					development = 10
				}
				save_event_target_as = appanage_province
			}
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
					development = 13
				}
				save_event_target_as = appanage_province
			}
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
					development = 15
				}
				save_event_target_as = appanage_province
			}
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
					development = 18
				}
				save_event_target_as = appanage_province
			}
			random_owned_province = {
				limit = {
					has_owner_culture = yes
					is_capital = no
					is_city = yes
					development = 20
				}
				save_event_target_as = appanage_province
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.1.a #
		goto = appanage_province
		if = {
			limit = {
				dynasty = "00000000"
			}
			event_target:appanage_province = {
				spawn_rebels = {
					type = pretender_rebels
					size = 1
					leader_dynasty = "Rurikovich"
				}
			}
		}
		else = {
			event_target:appanage_province = {
				spawn_rebels = {
					type = pretender_rebels
					size = 1
				}
			}
		}
	}
	option = {
		name = russian_principality_events.1.b #
		trigger = {
			NOT = { legitimacy = 50 }
			legitimacy = 30
			has_government_attribute = heir
		}
		define_heir = {
			dynasty = ROOT
			change_dip = 4
			claim = 50
		}
	}
	option = {
		name = russian_principality_events.1.c #
		trigger = {
			NOT = { legitimacy = 30 }
		}
		define_ruler = {
			dynasty = ROOT
			change_dip = 4
			claim = 50
		}
	}
}

#Agricultural Intensification

country_event = {
	id = russian_principality_events.2
	title = russian_principality_events.2.t
	desc = russian_principality_events.2.d
	picture = PEASANTS_ON_STEPPES_eventPicture
	goto = agricultural_intensification_province
	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		num_of_cities = 2
	}
	
	is_triggered_only = yes
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					is_capital = no
				}
				save_event_target_as = agricultural_intensification_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					NOT = { development = 15 }
				}
				save_event_target_as = agricultural_intensification_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					NOT = { development = 10 }
				}
				save_event_target_as = agricultural_intensification_province
			}
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.2.a #
		event_target:agricultural_intensification_province = {
			add_base_production = 1
		}
	}
}

country_event = {
	id = russian_principality_events.3
	title = russian_principality_events.3.t
	desc = russian_principality_events.3.d
	picture = PRINCE_AND_BOYARS_eventPicture

	trigger = {
		has_dlc = "Third Rome"
		OR = {
			has_reform = principality
			has_reform = tsardom
		}
		num_of_cities = 5
		is_subject = no #Includes being a tributary
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.3.a #Let us grant more land to the Boyars.
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_adm_power
			value = 35
		}
	}
	option = {
		name = russian_principality_events.3.b #We do not need the Boyar's for this.
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_mil_power
			value = 35
		}
	}
}

#Land Acquisition

country_event = {
	id = russian_principality_events.4
	title = russian_principality_events.4.t
	desc = russian_principality_events.4.d
	picture = PEASANTS_ON_STEPPES_eventPicture
	goto = random_province
	trigger = {
		has_dlc = "Third Rome"
		OR = {
			has_reform = principality
			AND = {
				has_reform = tsardom
				NOT = { num_of_cities = 40 }
			}
		}
		num_of_cities = 5
		is_subject = no #Includes being a tributary
		any_owned_province = {
			is_capital = no
			has_owner_culture = yes
		}
	}
	
	immediate = {
		hidden_effect = {
			random_list = {
				33 = { set_country_flag = land_tax }
				33 = { set_country_flag = land_production }
				33 = { set_country_flag = land_manpower }
			}
			random_owned_province = {
				limit = {
					is_capital = no
					has_owner_culture = yes
				}
				save_event_target_as = random_province
			}
		}
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.4.a #"Land is true wealth."
		trigger_switch = {
			on_trigger = has_country_flag
			land_tax = {
				clr_country_flag = land_tax
				event_target:random_province = {
					add_base_tax = 1
				}
			}
			land_production = {
				clr_country_flag = land_production
				event_target:random_province = {
					add_base_production = 1
				}
			}
			land_manpower = {
				clr_country_flag = land_manpower
				event_target:random_province = {
					add_base_manpower = 1
				}
			}
		}
	}
	option = {
		name = russian_principality_events.4.b #"We need gold for the royal treasury."
		add_years_of_income = 0.15
	}
	option = {
		name = russian_principality_events.4.c #"We must use this as leverage in state affairs."
		trigger_switch = {
			on_trigger = has_country_flag
			land_tax = {
				clr_country_flag = land_tax
				add_government_power = {
					mechanic_type = russian_mechanic
					power_type = russian_adm_power
					value = 35
				}
			}
			land_production = {
				clr_country_flag = land_production
				add_government_power = {
					mechanic_type = russian_mechanic
					power_type = russian_dip_power
					value = 35
				}
			}
			land_manpower = {
				clr_country_flag = land_manpower
				add_government_power = {
					mechanic_type = russian_mechanic
					power_type = russian_mil_power
					value = 35
				}
			}
		}
	}
}

#Famine

country_event = {
	id = russian_principality_events.5
	title = russian_principality_events.5.t
	desc = russian_principality_events.5.d
	picture = TR_FAMINE_eventPicture
	goto = famine_province
	trigger = {
		has_dlc = "Third Rome"
		OR = {
			has_reform = principality
			has_reform = tsardom
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				save_event_target_as = famine_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					has_owner_culture = yes
				}
				save_event_target_as = famine_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					has_owner_culture = yes
					trade_goods = grain
				}
				save_event_target_as = famine_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					has_owner_culture = yes
					trade_goods = grain
					is_in_capital_area = yes
				}
				save_event_target_as = famine_province
			}
		}
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.5.a #We will leave this to the Boyars.
		ai_chance = {
			factor = 33
		}
		reduce_estate_nobles_loyalty_effect = yes
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_mil_power
			value = -25
		}
		add_legitimacy = -5		
		event_target:famine_province = {
			add_province_modifier = {
				name = "russian_famine"
				duration = 3650
			}
		}
	}
	option = {
		name = russian_principality_events.5.b #We will let the Church handle this.
		ai_chance = {
			factor = 33
		}
		reduce_estate_church_loyalty_effect = yes
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_adm_power
			value = -25
		}
		add_prestige = -10
		event_target:famine_province = {
			add_province_modifier = {
				name = "russian_famine"
				duration = 3650
			}
		}
		
	}
	option = {
		name = russian_principality_events.5.c #The [Root.Monarch.GetTitle] [Root.Monarch.GetHerselfHimself] will help them.
		ai_chance = {
			factor = 33
		}
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_dip_power
			value = -25
		}
		add_years_of_income = -0.25
		event_target:famine_province = {
			add_province_modifier = {
				name = "russian_famine"
				duration = 3650
			}
		}
	}
	option = {
		name = russian_principality_events.5.dd #They can join the free Cossacks.
		ai_chance = {
			factor = 0
		}
		trigger = {
			event_target:famine_province = {
				base_production = 2
			}
		}
		add_estate_cossacks_loyalty_effect = yes
		event_target:famine_province = {
			add_base_production = -1
			add_province_modifier = {
				name = "russian_famine"
				duration = 3650
			}
		}
	}
}

#Forcible Resettling Merchants
country_event = {
	id = russian_principality_events.6
	title = russian_principality_events.6.t
	desc = russian_principality_events.6.d
	picture = ENTERING_MOSCOW_eventPicture
	goto = province_to_rob
	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		num_of_cities = 8
		any_owned_province = {
			has_owner_culture = no
			development = 15
			is_state = no
			NOT = { has_province_flag = resettled_province }
		}
	}
	
	immediate = {
		hidden_effect = {
			#Taken From:
			random_owned_province = {
				limit = {
					has_owner_culture = no
					development = 15
					is_state = no
					NOT = { has_province_flag = resettled_province }
				}
				save_event_target_as = province_to_rob
			}
			random_owned_province = {
				limit = {
					has_owner_culture = no
					development = 18
					is_state = no
					NOT = { has_province_flag = resettled_province }
				}
				save_event_target_as = province_to_rob
			}
			random_owned_province = {
				limit = {
					has_owner_culture = no
					development = 20
					is_state = no
					NOT = { has_province_flag = resettled_province }
				}
				save_event_target_as = province_to_rob
			}
			random_owned_province = {
				limit = {
					has_owner_culture = no
					development = 24
					is_state = no
					NOT = { has_province_flag = resettled_province }
				}
				save_event_target_as = province_to_rob
			}
			random_owned_province = {
				limit = {
					has_owner_culture = no
					development = 26
					is_state = no
					NOT = { has_province_flag = resettled_province }
				}
				save_event_target_as = province_to_rob
			}
			#Taken To:
			random_owned_province = {
				limit = {
					is_state = yes
					OR = {
						has_owner_culture = yes
						is_capital = yes #Always valid
					}
					OR = {
						is_capital = yes
						development = 12
						province_has_center_of_trade_of_level = 1
					}
				}
				save_event_target_as = province_to_grow
			}
			random_owned_province = {
				limit = {
					is_state = yes
					OR = {
						has_owner_culture = yes
						is_capital = yes #Always valid
					}
					OR = {
						is_capital = yes
						development = 15
						province_has_center_of_trade_of_level = 1
					}
				}
				save_event_target_as = province_to_grow
			}
			random_owned_province = {
				limit = {
					is_state = yes
					OR = {
						has_owner_culture = yes
						is_capital = yes #Always valid
					}
					OR = {
						is_capital = yes
						development = 20
						province_has_center_of_trade_of_level = 1
					}
				}
				save_event_target_as = province_to_grow
			}
			random_list = {
				33 = { set_country_flag = will_move_tax }
				33 = { set_country_flag = will_move_prod }
				33 = { set_country_flag = will_move_mp }
			}
		}
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.6.a #
		ai_chance = {
			factor = 50
		}
		trigger_switch = {
			on_trigger = has_country_flag
			will_move_mp = {
				clr_country_flag = will_move_mp
				event_target:province_to_grow = {
					add_base_manpower = 1
				}
			}
			will_move_prod = {
				clr_country_flag = will_move_prod
				event_target:province_to_grow = {
					add_base_production = 1
				}
			}
			will_move_tax = {
				clr_country_flag = will_move_tax
				event_target:province_to_grow = {
					add_base_tax = 1
				}
			}
		}
		trigger_switch = {
			on_trigger = has_country_flag
			will_move_mp = {
				clr_country_flag = will_move_mp
				event_target:province_to_rob = {
					add_base_manpower = -2
					set_province_flag = resettled_province
				}
			}
			will_move_prod = {
				clr_country_flag = will_move_prod
				event_target:province_to_rob = {
					add_base_production = -2
					set_province_flag = resettled_province
				}
			}
			will_move_tax = {
				clr_country_flag = will_move_tax
				event_target:province_to_rob = { 
					add_base_tax = -2
					set_province_flag = resettled_province
				}
			}
		}
		reduce_estate_burghers_loyalty_effect = yes
	}
	option = {
		name = russian_principality_events.6.b #
		ai_chance = {
			factor = 50
		}
		add_estate_burghers_loyalty_effect = yes
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_dip_power
			value = 30
		}
		trigger_switch = {
			on_trigger = has_country_flag
			will_move_mp = {
				clr_country_flag = will_move_mp
			}
			will_move_prod = {
				clr_country_flag = will_move_prod
			}
			will_move_tax = {
				clr_country_flag = will_move_tax
			}
		}
	}
}

#St George's day
country_event = {
	id = russian_principality_events.7
	title = russian_principality_events.7.t
	desc = russian_principality_events.7.d
	picture = PEASANTS_ON_STEPPES_eventPicture
	goto = serfdom_province
	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		any_owned_province = {
			NOT = { has_province_modifier = restricted_movement }
			is_capital = no
			is_colony = no
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					NOT = { has_province_modifier = restricted_movement }
					is_capital = no
					is_colony = no
				}
				save_event_target_as = serfdom_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					is_colony = no
					has_owner_culture = yes
					NOT = { has_province_modifier = restricted_movement }
				}
				save_event_target_as = serfdom_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					is_colony = no
					has_owner_culture = yes
					trade_goods = grain
					NOT = { has_province_modifier = restricted_movement }
				}
				save_event_target_as = serfdom_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					is_colony = no
					has_owner_culture = yes
					trade_goods = grain
					NOT = { has_province_modifier = restricted_movement }
				}
				save_event_target_as = serfdom_province
			}
			random_owned_province = {
				limit = {
					is_capital = no
					is_colony = no
					has_owner_culture = yes
					trade_goods = grain
					is_in_capital_area = yes
					NOT = { has_province_modifier = restricted_movement }
				}
				save_event_target_as = serfdom_province
			}
		}
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.7.a #We will do as they ask.
		ai_chance = {
			factor = 50
		}
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_adm_power
			value = 25
		}
		event_target:serfdom_province = {
			area = {
				limit = {
					owned_by = ROOT
					NOT = { has_province_modifier = restricted_movement }
					is_capital = no
					is_colony = no
				}
				add_province_modifier = {
					name = "restricted_movement"
					duration = 3650
				}
			}
		}
		add_estate_nobles_loyalty_effect = yes
		reduce_estate_burghers_loyalty_effect = yes
	}
	option = {
		name = russian_principality_events.7.b #We will not do as they ask.
		ai_chance = {
			factor = 50
		}
		add_stability_or_adm_power = yes
		event_target:serfdom_province = {
			area = {
				limit = {
					owned_by = ROOT
					NOT = { has_province_modifier = serfs_moving_away }
					is_capital = no
					is_colony = no
				}
				add_province_modifier = {
					name = "serfs_moving_away"
					duration = 3650
				}
			}
		}
		reduce_estate_nobles_loyalty_effect = yes
		add_estate_burghers_loyalty_effect = yes
	}
}


#Death of a Brother
country_event = {
	id = russian_principality_events.8
	title = russian_principality_events.8.t
	picture = OPRICHINA_eventPicture

	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		any_owned_province = {
			NOT = { has_province_modifier = confiscated_appanage }
		}
	}
	
	desc = {
		trigger = { NOT = { num_of_cities = 2 } }
		desc = russian_principality_events.8.da
	}
	
	desc = {
		trigger = { num_of_cities = 2 }
		desc = russian_principality_events.8.db
	}
	
	immediate = {
		hidden_effect = {
			capital_scope = {
				save_event_target_as = brothers_appanage
			}
			random_owned_province = {
				limit = {
					is_capital = no
					is_city = yes
					NOT = {
						has_province_modifier = confiscated_appanage
					}
				}
				save_event_target_as = brothers_appanage
			}
		}
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.8.a #Confiscate to state
		ai_chance = {
			factor = 50
		}
		trigger = {
			NOT = { num_of_cities = 2 }
		}
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_adm_power
			value = 15
		}
		add_years_of_income = 0.2
		reduce_estate_nobles_loyalty_effect = yes
	}
	option = {
		name = russian_principality_events.8.b #Confiscate to State
		trigger = { num_of_cities = 2 }
		goto = brothers_appanage
		ai_chance = {
			factor = 50
		}
		add_legitimacy = -5
		event_target:brothers_appanage = {
			add_province_modifier = {
				name = "confiscated_appanage"
				duration = 3650
			}
		}
		reduce_estate_nobles_loyalty_effect = yes
	}
	option = {
		name = russian_principality_events.8.c #Distribute among siblings
		ai_chance = {
			factor = 50
		}
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_dip_power
			value = 15
		}
		add_legitimacy = 5
		add_estate_nobles_loyalty_effect = yes
	}
}


#Tartar Feudatories?
country_event = {
	id = russian_principality_events.9
	title = russian_principality_events.9.t
	desc = russian_principality_events.9.d
	picture = TRIBUTE_TO_TATARS_eventPicture

	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		religion_group = christian
		num_of_cities = 5
		NOT = { has_country_modifier = tatar_feudatories }
		any_owned_province = {
			OR = {
				culture_group = tartar
				religion_group = muslim
			}
			NOT = { has_province_flag = tatar_province_asked }
		}
	}
	
	immediate = {
		hidden_effect = {
			random_owned_province = {
				limit = {
					OR = {
						culture_group = tartar
						religion_group = muslim
					}
					NOT = { has_province_flag = tatar_province_asked }
				}
				set_province_flag = tatar_province_asked
				save_event_target_as = tatar_province
			}
		}
	}

	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.9.a #
		goto = tatar_province
		ai_chance = {
			factor = 25
			modifier = {
				factor = 0
				num_of_owned_provinces_with = {
					value = 10
					religion_group = muslim
				}
			}
		}
		reduce_estate_cossacks_loyalty_effect = yes
		reduce_estate_church_loyalty_effect = yes
		add_patriarch_authority = -0.05
		add_yearly_manpower = 1.5
		add_country_modifier = {
			name = "tatar_feudatories"
			duration = 5475
		}
		event_target:tatar_province = {
			if = {
				limit = {
					NOT = { religion_group = muslim }
				}
				change_religion = sunni
			}
			add_province_modifier = {
				name = "tatar_feudatory_province"
				duration = 5475
			}
		}
	}
	option = {
		name = russian_principality_events.9.b #
		ai_chance = {
			factor = 75
			modifier = {
				factor = 0
				NOT = {
					num_of_owned_provinces_with = {
						value = 5
						religion_group = muslim
					}
				}
			}
		}
		add_patriarch_authority = 0.05
		add_legitimacy = 5
	}
}


#The X Kremlin

country_event = {
	id = russian_principality_events.10
	title = russian_principality_events.10.t
	desc = russian_principality_events.10.d
	picture = KREMLIN_eventPicture
	goto = kremlin_here
	trigger = {
		has_dlc = "Third Rome"
		has_reform = principality
		num_of_cities = 3
		capital_scope = {
			NOT = { has_province_modifier = tr_kremlin_improvements }
			fort_level = 2
		}
	}
	
	immediate = {
		hidden_effect = {
			capital_scope = {
				save_event_target_as = kremlin_here
			}
		}
	}
	
	is_triggered_only = yes
	
	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = russian_principality_events.10.a #
		reduce_estate_nobles_loyalty_effect = yes
		add_yearly_manpower = -2.5
		add_prestige = 5
		event_target:kremlin_here = {
			add_province_modifier = {
				name = "tr_kremlin_improvements"
				duration = 3650
			}
		}
	}
	option = {
		name = russian_principality_events.10.b
		reduce_estate_burghers_loyalty_effect = yes
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_dip_power
			value = -35
		}
		add_prestige = 5
		event_target:kremlin_here = {
			add_province_modifier = {
				name = "tr_kremlin_improvements"
				duration = 3650
			}
		}
	}
	option = {
		name = russian_principality_events.10.c
		add_government_power = {
			mechanic_type = russian_mechanic
			power_type = russian_adm_power
			value = -20
		}
		reduce_estate_church_loyalty_effect = yes
		add_patriarch_authority = -0.20
		add_prestige = 5
		event_target:kremlin_here = {
			add_province_modifier = {
				name = "tr_kremlin_improvements"
				duration = 3650
			}
		}
	}
	option = {
		name = russian_principality_events.10.dd
		add_prestige = -5
	}
}