namespace = FEE_Poland_Events

#The Union of Brest
country_event = {
	id = FEE_Poland_Events.1
	title = FEE_Poland_Events.1.T
	desc = FEE_Poland_Events.1.D
	picture = RELIGIOUS_TURMOIL_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			tag = POL
			tag = PLC
		}
		religion = catholic
		current_age = age_of_reformation
		NOT = { is_defender_of_faith = yes }
	}

	mean_time_to_happen = {
		months = 120
		modifier = {
			factor = 0.8
			num_of_owned_provinces_with = {
				value = 5
				religion = orthodox
			}
		}
		modifier = {
			factor = 0.5
			num_of_owned_provinces_with = {
				value = 10
				religion = orthodox
			}
		}
		modifier = {
			factor = 2
			tag = POL
			exists = PLC
		}
		modifier = {
			factor = 0.8
			tag = PLC
		}
	}

	option = {
		name = FEE_Poland_Events.1.OPT1
		ai_chance = {
			factor = 50
		}

		add_stability_or_adm_power = yes
		add_country_modifier = {
			name = fee_pol_uniate_church
			duration = -1
		}
		custom_tooltip = POLAND_RUTHENIA_TRUE_BELIEVERS_TT
		tooltip = {
			random_owned_province = {
				limit = { culture = ruthenian }
				add_province_modifier = {
					name = fee_pol_true_believers
					duration = -1
				}
			}
		}
		hidden_effect = {
			every_owned_province = {
				limit = { culture = ruthenian }
				change_religion = orthodox
				add_province_modifier = {
					name = fee_pol_true_believers
					duration = -1
				}
			}
		}
	}

	option = {
		name = FEE_Poland_Events.1.OPT2
		ai_chance = {
			factor = 50
		}

		add_stability = -1
		add_country_modifier = {
			name = fee_pol_catholicism_entrenched
			duration = -1
		}
		random_owned_province = {
			limit = { culture = ruthenian }
			spawn_rebels = {
				size = 3
				religion = orthodox
				type = orthodox_rebels
			}
		}
		random_owned_province = {
			limit = { culture = ruthenian }
			spawn_rebels = {
				size = 3
				religion = orthodox
				type = orthodox_rebels
			}
		}
	}
}

# Przywilej cerekwicko-nieszawski
country_event = {
	id = FEE_Poland_Events.9
	title = FEE_Poland_Events.9.T
	desc = FEE_Poland_Events.9.D
	picture = LIBERUM_VETO_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_year = 1450
		NOT = { is_year = 1480 }
		is_at_war = yes
	}

	mean_time_to_happen = {
		months = 6
	}

	option = {
		name = FEE_Poland_Events.9.OPT1 # Accept the Conventions (Road to nobility)

		add_country_modifier = {
			name = fee_pol_statuty_nieszawskie
			duration = -1
		}
		every_owned_province = {
			add_local_autonomy = 15
		}
	}

	option = {
		name = FEE_Poland_Events.9.OPT2 # Refuse to sign it and defy the Magnates (Road to absolutism)

		add_manpower = -2.5
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
	}
}

# Konstytucje piotrkowskie
country_event = {
	id = FEE_Poland_Events.10
	title = FEE_Poland_Events.10.T
	desc = FEE_Poland_Events.10.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_year = 1490
		NOT = { is_year = 1520 }
		is_at_war = yes
	}

	mean_time_to_happen = {
		months = 6
	}

	option = {
		name = FEE_Poland_Events.10.OPT1 # Enact

		add_stability_or_adm_power_per_stab = { amount = 1 }
		add_mercantilism_or_monarch_power = { amount = 2 }
		add_country_modifier = {
			name = fee_pol_statut_piotrkowski
			duration = -1
		}
	}

	option = {
		name = FEE_Poland_Events.10.OPT2 # Refuse to enact

		add_stability = -3
		add_manpower = -2.5
	}
}

# Unia krakowsko-wileńska
country_event = {
	id = FEE_Poland_Events.11
	title = FEE_Poland_Events.11.T
	desc = FEE_Poland_Events.11.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		tag = POL
		NOT = { is_year = 1540 }
		is_year = 1490
		exists = LIT
		NOT = { exists = PLC }
		NOT = { senior_union_with = LIT }
		LIT = {
			ai = yes
			has_opinion = {
				who = POL
				value = 100
			}
		}
	}

	mean_time_to_happen = {
		months = 50
	}

	option = {
		name = FEE_Poland_Events.11.OPT1 # Our countries should cooperate
		trigger = {
			valid_for_personal_unions_trigger = yes
			LIT = { valid_for_personal_unions_trigger = yes }
		}
		ai_chance = {
			factor = 70
		}

		create_union = LIT
	}

	option = {
		name = FEE_Poland_Events.11.OPT2
		ai_chance = {
			factor = 30
		}

		add_prestige_or_monarch_power = { amount = 5 }
	}
}

# Przywilej mielnicki
country_event = {
	id = FEE_Poland_Events.12
	title = FEE_Poland_Events.12.T
	desc = FEE_Poland_Events.12.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_year = 1495
		NOT = { is_year = 1530 }
	}

	mean_time_to_happen = {
		months = 6
	}

	option = {
		name = FEE_Poland_Events.12.OPT1 # Sign
		ai_chance = {
			factor = 90
		}

		add_country_modifier = {
			name = fee_pol_przywilej_mielnicki
			duration = -1
		}
		every_owned_province = {
			add_local_autonomy = 15
		}
	}

	option = {
		name = FEE_Poland_Events.12.OPT2 # Reject
		ai_chance = {
			factor = 10
		}

		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
	}
}

# Unia mielnicka
country_event = {
	id = FEE_Poland_Events.13
	title = FEE_Poland_Events.13.T
	desc = FEE_Poland_Events.13.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		tag = POL
		senior_union_with = LIT
		has_country_modifier = fee_pol_przywilej_mielnicki
	}

	mean_time_to_happen = {
		months = 48
	}

	option = {
		name = FEE_Poland_Events.13.OPT1 # Unite our countries under Poland(This will create massive rebellion in Lithuania)
		ai_chance = {
			factor = 5
		}

		inherit = LIT
		add_stability_or_adm_power = yes
		hidden_effect = {
			set_country_flag = fee_pol_unia_mielnicka
		}
	}

	option = {
		name = FEE_Poland_Events.13.OPT2 # Do not push them to sign it
		ai_chance = {
			factor = 95
		}

		add_stability = -1
	}
}

# Lithuanian reaction to incorporation
country_event = {
	id = FEE_Poland_Events.14
	title = FEE_Poland_Events.14.T
	desc = FEE_Poland_Events.14.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		tag = POL
		has_country_flag = fee_pol_unia_mielnicka
		lithuania_area = {
			owned_by = ROOT
		}
		ruthenia_region = {
			owned_by = ROOT
		}
	}

	mean_time_to_happen = {
		months = 24
	}

	option = {
		name = FEE_Poland_Events.14.OPT1 # I told you so

		random_owned_province = {
			limit = {
				area = lithuania_area
			}
			nationalist_rebels = 3
		}
		random_owned_province = {
			limit = {
				region = ruthenia_region
			}
			nationalist_rebels = 3
		}
		random_owned_province = {
			limit = {
				region = ruthenia_region
			}
			nationalist_rebels = 3
		}
		random_owned_province = {
			limit = {
				region = ruthenia_region
			}
			nationalist_rebels = 3
		}
	}
}

#Sejm piotrkowski
country_event = {
	id = FEE_Poland_Events.15
	title = FEE_Poland_Events.15.T
	desc = FEE_Poland_Events.15.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_year = 1500
		NOT = { is_year = 1520 }
		has_country_modifier = fee_pol_przywilej_mielnicki
	}

	mean_time_to_happen = {
		months = 60
	}

	option = {
		name = FEE_Poland_Events.15.OPT1 # Well, accept it

		add_adm_power = 150
	}
}

# Przywilej cerekwicko-nieszawski
country_event = {
	id = FEE_Poland_Events.16
	title = FEE_Poland_Events.16.T
	desc = FEE_Poland_Events.16.D
	picture = LIBERUM_VETO_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_year = 1505
		NOT = { is_year = 1515 }
		has_country_modifier = fee_pol_przywilej_mielnicki
	}

	mean_time_to_happen = {
		months = 60
	}

	option = {
		name = FEE_Poland_Events.16.OPT1 # The beginning of noble rules

		remove_country_modifier = fee_pol_przywilej_mielnicki
		every_owned_province = {
			add_local_autonomy = 15
		}
	}

	option = {
		name = FEE_Poland_Events.16.OPT2 # NO power to nobles!

		remove_country_modifier = fee_pol_przywilej_mielnicki
		remove_country_modifier = fee_pol_statut_piotrkowski
		remove_country_modifier = fee_pol_statuty_nieszawskie
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 2
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 1
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 1
		}
		random_owned_province = {
			limit = {
				continent = europe
			}
			polish_noble_rebels = 1
		}
	}
}

# Przywilej toruński
country_event = {
	id = FEE_Poland_Events.17
	title = FEE_Poland_Events.17.T
	desc = FEE_Poland_Events.17.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_year = 1520
		NOT = { is_year = 1550 }
	}

	mean_time_to_happen = {
		months = 240
	}

	option = {
		name = FEE_Poland_Events.17.OPT1 # Enact

		add_stability_or_adm_power = yes
		add_mercantilism_or_monarch_power = { amount = 3 }
		add_country_modifier = {
			name = fee_pol_przywilej_torunski
			duration = -1
		}
	}

	option = {
		name = FEE_Poland_Events.17.OPT2 # Refuse to enact

		add_stability = -3
	}
}

#Hołd Pruski.1
country_event = {
	id = FEE_Poland_Events.18
	title = FEE_Poland_Events.18.T
	desc = FEE_Poland_Events.18.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		exists = TEU
		TEU = {
			ai = yes
			is_subject_of = ROOT
		}
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		NOT = { exists = PRU }
		is_year = 1520
		NOT = { is_year = 1540 }
		is_religion_enabled = protestant
	}

	mean_time_to_happen = {
		months = 120
	}

	option = {
		name = FEE_Poland_Events.18.OPT1 # Force them to create Prussia

		TEU = { country_event = { id = FEE_Poland_Events.22 } }
	}

	option = {
		name = FEE_Poland_Events.18.OPT2 # Do nothing

		add_prestige_or_monarch_power = { amount = 5 }
		TEU = {
			add_prestige_or_monarch_power = { amount = 5 }
		}
	}
}

# Tumult gdański
country_event = {
	id = FEE_Poland_Events.19
	title = FEE_Poland_Events.19.T
	desc = FEE_Poland_Events.19.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		is_religion_enabled = protestant
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		owns = 43
		is_neighbor_of = PRU
		religion = catholic
	}

	mean_time_to_happen = {
		months = 12
	}

	option = {
		name = FEE_Poland_Events.19.OPT1 # Catholicism is our main religion

		43 = {
			spawn_rebels = {
				type = protestant_rebels
				size = 2
			}
		}
	}

	option = {
		name = FEE_Poland_Events.19.OPT2 # Let them live

		43 = { change_religion = protestant }
	}
}

# Pakt wileński
country_event = {
	id = FEE_Poland_Events.20
	title = FEE_Poland_Events.20.T
	desc = FEE_Poland_Events.20.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		is_neighbor_of = LIV
		1842 = {
			owner = {
				OR = {
					tag = MOS
					tag = RUS
				}
			}
		}
		1834 = {
			owner = {
				OR = {
					tag = MOS
					tag = RUS
				}
			}
		}
	}

	mean_time_to_happen = {
		months = 12
	}

	option = {
		name = FEE_Poland_Events.20.OPT1 # Incoroporate Livonia

		LIV = { country_event = { id = FEE_Poland_Events.23 } }
	}

	option = {
		name = FEE_Poland_Events.20.OPT2 # Do nothing
	}
}

# Statut karnkowskiego
country_event = {
	id = FEE_Poland_Events.21
	title = FEE_Poland_Events.21.T
	desc = FEE_Poland_Events.21.D
	picture = COURT_eventPicture

	fire_only_once = yes

	trigger = {
		OR = {
			AND = {
				tag = POL
				NOT = { exists = PLC }
			}
			tag = PLC
		}
		owns = 43
		is_year = 1560
		NOT = { is_year = 1580 }
	}

	mean_time_to_happen = {
		months = 120
	}

	option = {
		name = FEE_Poland_Events.21.OPT1 # Sign

		add_dip_power = -150
		43 = {
			add_province_modifier = {
				name = fee_pol_statut_karnkowskiego
				duration = -1
			}
		}
	}

	option = {
		name = FEE_Poland_Events.21.OPT2 # It is unnecessary

		add_mercantilism = -5
	}
}

#Hold pruski.2
#From FEE_Poland_Events.18
country_event = {
	id = FEE_Poland_Events.22
	title = FEE_Poland_Events.22.T
	desc = FEE_Poland_Events.22.D
	picture = COURT_eventPicture

	is_triggered_only = yes

	option = {	# Humble before Poland
		name = FEE_Poland_Events.22.OPT1

		change_tag = PRU
		add_prestige_or_monarch_power = { amount = 25 }
		change_religion = protestant
		capital_scope = {
			change_religion = protestant
		}
		restore_country_name_effect = yes
		swap_non_generic_missions = yes
		if = {
			limit = {
				is_revolutionary = no
				NOT = {
					government = republic
				}
			}
			change_government_to_monarchy = yes
			add_government_reform = prussian_monarchy
		}
		else_if = {
			limit = {
				is_revolutionary = no
			}
			add_government_reform = prussian_republic_reform
		}
		if = {
			limit = {
				has_reform = states_general_reform
			}
			remove_government_reform = states_general_reform
		}
		every_neighbor_country = {
			limit = { government = monarchy }
			add_opinion = { who = ROOT modifier = secularized_monastic_order }
		}
		if = {
			limit = {
				has_custom_ideas = no
				NOT = { has_idea_group = PRU_ideas }
			}
			country_event = { id = ideagroups.1 } #Swap Ideas
		}
		add_country_modifier = {
			name = "centralization_modifier"
			duration = 3650
		}
		east_prussia_area = { add_permanent_claim = PRU }
		west_prussia_area = { add_permanent_claim = PRU }
		set_country_flag = formed_prussia_flag
	}
}

#From FEE_Poland_Events.20
country_event = {
	id = FEE_Poland_Events.23
	title = FEE_Poland_Events.23.T
	desc = FEE_Poland_Events.23.D
	picture = COURT_eventPicture

	is_triggered_only = yes

	option = {	# Humble before Poland
		name = FEE_Poland_Events.23.OPT1

		FROM = { inherit = LIV}
	}

	option = {	# We are too strong
		name = FEE_Poland_Events.23.OPT2

		FROM = {
			declare_war_with_cb = {
				who = LIV
				casus_belli = cb_annex
			}
		}
	}
}
##########################################################
# Lumisentius' second attempt in making Cossack Revolts.
# Date: 11.07.2020
# Latest update: 09.08.2020
# Finished event chains:
# 	- Cossack Raids Against Ottomans
# 	- Kosinski Uprising
# 	- Nalyvaiko Uprising
#
# Total amount of events: 25
##########################################################

# [COSSACK RAIDS AGAINST OTTOMANS CHAIN]
# Cossack Raids
country_event = {
	id = FEE_Poland_Events.24
	title = FEE_Poland_Events.24.T
	desc = FEE_Poland_Events.24.D
	picture = BARBARY_PIRATES_eventPicture
	fire_only_once = yes

	trigger = {
		is_year = 1580
		tag = TUR
		exists = PLC
		is_neighbor_of = PLC
		PLC = {
			has_estate = estate_cossacks
			NOT = { truce_with = TUR }
		}
		OR = {
			is_rival = PLC
			is_enemy = PLC
		}
	}

	mean_time_to_happen = { months = 60 }

	option = {
		name = FEE_Poland_Events.24.OPT1
		ai_chance = { factor = 85 }

		hidden_effect = {
			PLC = {
				country_event = {
					id = FEE_Poland_Events.25
					days = 30
					random = 15
				}
			}
		}
	}

	option = {
		name = FEE_Poland_Events.24.OPT2
		ai_chance = { factor = 15 }

		add_prestige = -15
		add_legitimacy_equivalent = { amount = -20 republican_tradition = -12 }
		add_stability = -1
	}
}

# Threatened by Sultan
country_event = {
	id = FEE_Poland_Events.25
	title = FEE_Poland_Events.25.T
	desc = FEE_Poland_Events.25.D
	picture = DIPLOMACY_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.25.OPT1
		ai_chance = { factor = 90 }

		add_country_modifier = {
			name = "fee_pol_order_in_ukraine"
			duration = 3652
		}

		TUR = {
			country_event = {
				id = FEE_Poland_Events.26
				days = 30
				random = 15
				tooltip = "cr_2_a_tooltip"
			}
		}
	}

	option = {
		name = FEE_Poland_Events.25.OPT2
		ai_chance = { factor = 10 }

		add_prestige_or_monarch_power = { amount = 15 }

		TUR = {
			country_event = {
				id = FEE_Poland_Events.27
				days = 30
				random = 15
				tooltip = "cr_2_b_tooltip"
			}
		}
	}
}

# Commonwealth accepts our demands
country_event = {
	id = FEE_Poland_Events.26
	title = FEE_Poland_Events.26.T
	desc = FEE_Poland_Events.26.D
	picture = DIPLOMACY_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.26.OPT1

		add_stability_or_adm_power = yes
		add_prestige_or_monarch_power = { amount = 15 }
	}
}

# Commonwealth rejects our demands
country_event = {
	id = FEE_Poland_Events.27
	title = FEE_Poland_Events.27.T
	desc = FEE_Poland_Events.27.D
	picture = BORDER_TENSION_eventPicture
	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			PLC = {
				declare_war_with_cb = {
					who = TUR
					casus_belli = cb_insult
				}
			}
		}
	}

	option = {
		name = FEE_Poland_Events.27.OPT1
	}
}

# [KOSINSKI UPRISING EVENT CHAIN]
# A Conflict between Ruthenian Nobility
country_event = {
	id = FEE_Poland_Events.28
	title = FEE_Poland_Events.28.T
	desc = FEE_Poland_Events.28.D
	picture = BORDER_TENSION_eventPicture
	fire_only_once = yes

	trigger = {
		is_year = 1591
		tag = PLC
		has_estate = estate_cossacks
		owns_core_province = 280
		owns_core_province = 292
		owns_core_province = 1944
		owns_core_province = 2962
		owns_core_province = 4539
		owns_core_province = 4540
	}

	mean_time_to_happen = { months = 12 }

	option = {
		name = FEE_Poland_Events.28.OPT1

		280 = { add_devastation = 2 }

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.29
				days = 60
				random = 15
			}
		}
	}
}

# Ruthenian Noble names himself a Hetman
country_event = {
	id = FEE_Poland_Events.29
	title = FEE_Poland_Events.29.T
	desc = FEE_Poland_Events.29.D
	picture = ANGRY_MOB_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.29.OPT1

		hidden_effect = {
			random_list = {
				90 = {
					country_event = {
						id = FEE_Poland_Events.30
						days = 120
						random = 10
					}
				}
				10 = {
					country_event = {
						id = FEE_Poland_Events.31
						days = 120
						random = 10
					}
				}
			}
		}
	}
}

# End of Kosinski Uprising (Success)
country_event = {
	id = FEE_Poland_Events.30
	title = FEE_Poland_Events.30.T
	desc = FEE_Poland_Events.30.D
	picture = CONQUEST_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.30.OPT1

		# +Mission for ME and a mechanism preventing next event chain from firing before this one is over.
		set_country_flag = PLC_dealt_with_kosinski_uprising
	}
}

# Embarrassing Failure
country_event = {
	id = FEE_Poland_Events.31
	title = FEE_Poland_Events.31.T
	desc = FEE_Poland_Events.31.D
	picture = BATTLE_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.31.OPT1

		add_prestige = -10
		280 = {
			spawn_rebels = {
				type = cossack_rebels
				size = 2
				win = yes
			}
		}
		1944 = {
			spawn_rebels = {
				type = cossack_rebels
				size = 1
				win = yes
			}
		}
		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.1001
				days = 120
				random = 30
			}
		}
	}
}

# Kosinski Uprising [Phase 1]
country_event = {
	id = FEE_Poland_Events.1001
	title = FEE_Poland_Events.1001.T
	desc = FEE_Poland_Events.1001.D
	picture = BATTLE_eventPicture

	is_triggered_only = yes
	hidden = yes

	immediate = {
		country_event = {
			id = FEE_Poland_Events.1002
			days = 120
			random = 30
		}
		2962 = {
			spawn_rebels = {
				type = cossack_rebels
				size = 1
				win = yes
			}
		}
		4540 = {
			spawn_rebels = {
				type = cossack_rebels
				size = 1
				win = yes
			}
		}

		country_event = {
			id = FEE_Poland_Events.1002
			days = 120
			random = 30
		}
	}

	option = {
		name = FEE_Poland_Events.1001.OPT1
	}
}

# Kosinski Uprising [Phase 2]
country_event = {
	id = FEE_Poland_Events.1002
	title = FEE_Poland_Events.1002.T
	desc = FEE_Poland_Events.1002.D
	picture = BATTLE_eventPicture
	is_triggered_only = yes
	hidden = yes

	immediate = {
		292 = {
			spawn_rebels = {
				type = cossack_rebels
				size = 1
				win = yes
			}
		}

		4539 = {
			spawn_rebels = {
				type = cossack_rebels
				size = 1
				win = yes
			}
		}

		country_event = {
			id = FEE_Poland_Events.1003
			days = 90
		}
	}

	option = {
		name = FEE_Poland_Events.1002.OPT1
	}
}

# Kosinski Uprising [Final Phase (Loop)]
country_event = {
	id = FEE_Poland_Events.1003
	title = FEE_Poland_Events.1003.T
	desc = FEE_Poland_Events.1003.D
	picture = BATTLE_eventPicture

	is_triggered_only = yes

	hidden = yes

	immediate = {
		if = {
			limit = { has_spawned_rebels = cossack_rebels }
			country_event = {
				id = FEE_Poland_Events.1003
				days = 90
			}
		}
		else = {
			country_event = { id = FEE_Poland_Events.32 }
		}
	}

	option = {
		name = FEE_Poland_Events.1003.OPT1
	}
}

# End of Kosinski Uprising (Intervention)
country_event = {
	id = FEE_Poland_Events.32
	title = FEE_Poland_Events.32.T
	desc = FEE_Poland_Events.32.D
	picture = CONQUEST_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.32.OPT1

		set_country_flag = PLC_dealt_with_kosinski_uprising
	}
}

# [NALYVAIKO UPRISING EVENT CHAIN]
# An influental Cossack demands changes
country_event = {
	id = FEE_Poland_Events.33
	title = FEE_Poland_Events.33.T
	desc = FEE_Poland_Events.33.D
	picture = SEJM_eventPicture
	fire_only_once = yes

	trigger = {
		tag = PLC
		has_estate = estate_cossacks
		has_country_flag = PLC_dealt_with_kosinski_uprising
		is_at_war = no
		owns_core_province = 280
		owns_core_province = 281
		owns_core_province = 292
		owns_core_province = 1942
		owns_core_province = 1943
		owns_core_province = 1944
		owns_core_province = 2407
		owns_core_province = 4247
		owns_core_province = 4539
		owns_core_province = 4540
		owns_core_province = 4542
	}

	mean_time_to_happen = { months = 64 }

	option = {
		name = FEE_Poland_Events.33.OPT1

		trigger = {
			NOT = {
				OR = {
					ruler_has_personality = just_personality
					ruler_has_personality = righteous_personality
					ruler_has_personality = kind_hearted_personality
					ruler_has_personality = secretive_personality
					ruler_has_personality = intricate_web_weaver_personality
					ruler_has_personality = charismatic_negotiator_personality
					ruler_has_personality = fierce_negotiator_personality
					ruler_has_personality = silver_tongue_personality
					ruler_has_personality = embezzler_personality
					ruler_has_personality = greedy_personality
					ruler_has_personality = cruel_personality
					ruler_has_personality = malevolent_personality
				}
			}
		}

		hidden_effect = {
			random_list = {
				90 = {
					country_event = {
						id = FEE_Poland_Events.35
						days = 120
						random = 30
					}
				}
				10 = {
					country_event = {
						id = FEE_Poland_Events.34
						days = 60
						random = 15
					}
				}
			}
		}
	}

	option = {
		name = FEE_Poland_Events.33.OPT2
		
		trigger = {
			OR = {
				ruler_has_personality = just_personality
				ruler_has_personality = righteous_personality
			}
		}

		add_estate_loyalty = {
			estate = estate_cossacks
			loyalty = 10
		}
		add_country_modifier = {
			name = fee_pol_grateful_cossacks
			duration = 3650
		}

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.34
				days = 60
				random = 15
			}
		}
	}

	option = {
		name = FEE_Poland_Events.33.OPT3

		trigger = { ruler_has_personality = kind_hearted_personality }

		add_years_of_income = -0.5
		add_country_modifier = {
			name = fee_pol_grateful_cossacks
			duration = 3650
		}

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.34
				days = 60
				random = 15
			}
		}
	}

	option = {
		name = FEE_Poland_Events.33.OPT4

		trigger = {
			OR = {
				ruler_has_personality = secretive_personality
				ruler_has_personality = intricate_web_weaver_personality
			}
		}

		add_years_of_income = -0.25
		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = -5
		}

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.34
				days = 60
				random = 15
			}
		}
	}

	option = {
		name = FEE_Poland_Events.33.OPT5

		trigger = {
			OR = {
				ruler_has_personality = charismatic_negotiator_personality
				ruler_has_personality = fierce_negotiator_personality
				ruler_has_personality = silver_tongue_personality
			}
		}

		add_country_modifier = {
			name = fee_pol_grateful_cossacks
			duration = 3650
		}

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.34
				days = 60
				random = 15
			}
		}
	}

	option = {
		name = FEE_Poland_Events.33.OPT6

		trigger = {
			OR = {
				ruler_has_personality = embezzler_personality
				ruler_has_personality = greedy_personality
			}
		}

		add_years_of_income = 0.5
		add_country_modifier = {
			name = fee_pol_despised_by_the_cossacks
			duration = 3650
		}

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.35
				days = 120
				random = 30
			}
		}
	}

	option = {
		name = FEE_Poland_Events.33.OPT7

		trigger = {
			OR = {
				ruler_has_personality = cruel_personality
				ruler_has_personality = malevolent_personality
			}
		}

		add_stability = -1
		add_country_modifier = {
			name = fee_pol_despised_by_the_cossacks
			duration = 3650
		}

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.35
				days = 120
				random = 30
			}
		}
	}
}

# Szlachta Agrees
country_event = {
	id = FEE_Poland_Events.34
	title = FEE_Poland_Events.34.T
	desc = FEE_Poland_Events.34.D
	picture = SEJM_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.34.OPT1

		set_country_flag = PLC_dealt_with_nalyvaiko_uprising
		set_country_flag = PLC_dealt_with_nalyvaiko_uprising_peacefully
	}
}

# Szlachta Refuses
country_event = {
	id = FEE_Poland_Events.35
	title = FEE_Poland_Events.35.T
	desc = FEE_Poland_Events.35.D
	picture = SEJM_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.35.OPT1

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.36
				days = 150
				random = 30
			}
		}
	}
}

# Szlachta Requests our Help
country_event = {
	id = FEE_Poland_Events.36
	title = FEE_Poland_Events.36.T
	desc = FEE_Poland_Events.36.D
	picture = NOBLE_ESTATE_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.36.OPT1

		define_general = {
			shock = 4
			fire = 4
			manuever = 3
			name = "Stanislaw Zolkiewski"
		}

		# Mohilew
		292 = {
			add_devastation = 20
			spawn_rebels = {
				type = cossack_rebels
				size = 3
				win = yes
				leader = "Severyn Nalyvaiko"
			}
		}

		hidden_effect = {
			# Bratslaw
			1943 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}
			# Bar
			4540 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}
			# Lutsk
			279 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}
			# Ternopil
			281 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}
			# Kaniv
			1944 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}
			# Slutsk
			4545 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}
			# Bobrujsk
			4544 = {
				add_devastation = 10
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }
			}

			country_event = {
				id = FEE_Poland_Events.1004
				days = 240
			}
		}
	}

	option = {
		name = FEE_Poland_Events.36.OPT2

		hidden_effect = {
			country_event = {
				id = FEE_Poland_Events.37
				days = 30
			}
		}
	}
}

# End of Nalyvaiko Uprising (Peacefully)
country_event = {
	id = FEE_Poland_Events.37
	title = FEE_Poland_Events.37.T
	desc = FEE_Poland_Events.37.D
	picture = FAMINE_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.37.OPT1

		set_country_flag = PLC_dealt_with_nalyvaiko_uprising
		set_country_flag = PLC_dealt_with_nalyvaiko_uprising_peacefully_2

		disband_rebels = cossack_rebels
		capital_scope = {
			spawn_rebels = {
				type = noble_rebels
				size = 3
			}
		}

		add_country_modifier = {
			name = fee_pol_nalyvaiko_peace_offer
			duration = 3650
		}

		292 = { add_devastation = 20 }
		1943 = { add_devastation = 10 }
		4540 = { add_devastation = 10 }
		279 = { add_devastation = 10 }
		281 = { add_devastation = 10 }
		1944 = { add_devastation = 10 }
		4545 = { add_devastation = 10 }
		4544 = { add_devastation = 10 }
	}
}

# Loop to check if there's any Cossack rebels in the country.
country_event = {
	id = FEE_Poland_Events.1004
	title = FEE_Poland_Events.1004.T
	desc = FEE_Poland_Events.1004.D
	picture = BATTLE_eventPicture

	is_triggered_only = yes
	hidden = yes

	immediate = {
		hidden_effect = {
			if = {
				limit = { has_spawned_rebels = cossack_rebels }

				country_event = {
					id = FEE_Poland_Events.1004
					days = 120
				}
			}
			else_if = {
				limit = { NOT = { has_spawned_rebels = cossack_rebels } }

				country_event = {
					id = FEE_Poland_Events.38
				}
			}
		}
	}

	option = {
		name = FEE_Poland_Events.1004.OPT1
	}
}

# Rebels Were Forced to Retreat
country_event = {
	id = FEE_Poland_Events.38
	title = FEE_Poland_Events.38.T
	desc = FEE_Poland_Events.38.D

	picture = BATTLE_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.38.OPT1

		hidden_effect = {
			4542 = {
				spawn_rebels = {
					type = cossack_rebels
					size = 0
					win = yes
				}
				kill_units = { who = controller }

				set_province_flag = PLC_tabor_lubnie
				add_or_upgrade_fort_building = yes
			}

			set_country_flag = fee_pol_nalyvaiko_lubnie

			country_event = {
				id = FEE_Poland_Events.1005
				days = 180
			}
		}
	}
}

# Another loop to check what player had decided.
country_event = {
	id = FEE_Poland_Events.1005
	title = FEE_Poland_Events.1005.T
	desc = FEE_Poland_Events.1005.D
	picture = BATTLE_eventPicture
	hidden = yes
	is_triggered_only = yes

	immediate = {
		# Default outcome: Player sieges down Lubnie
		if = {
			limit = {
				has_country_flag = fee_pol_nalyvaiko_lubnie
				4542 = {
					NOT = {
						controlled_by = REB
					}
				}
			}

			country_event = {
				id = FEE_Poland_Events.39
			}

			if = {
				limit = {
					4542 = { has_province_flag = PLC_tabor_lubnie }
				}

				4542 = {
					remove_building = fort_15th
					clr_province_flag = PLC_tabor_lubnie
				}
			}
		}
		else = {
			country_event = {
				id = FEE_Poland_Events.1005
				days = 120
			}
		}
	}

	option = {
		name = FEE_Poland_Events.1005.OPT1
	}
}

# End of Nalyvaiko Uprising (Default)
country_event = {
	id = FEE_Poland_Events.39
	title = FEE_Poland_Events.39.T
	desc = FEE_Poland_Events.39.D
	picture = VILLAGE_BURNING_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.39.OPT1

		hidden_effect = {
			if = {
				limit = {
					4542 = { has_province_flag = PLC_tabor_lubnie }
				}
				4542 = {
					remove_building = fort_15th
					clr_province_flag = PLC_tabor_lubnie
				}
			}
		}

		add_country_modifier = {
			name = fee_pol_nalyvaiko_cossack_lands_confiscated
			duration = 3650
		}

		clr_country_flag = fee_pol_nalyvaiko_lubnie
		set_country_flag = PLC_dealt_with_nalyvaiko_uprising_default
	}
}

# Negotiations with Rebels â„–1
country_event = {
	id = FEE_Poland_Events.40
	title = FEE_Poland_Events.40.T
	desc = FEE_Poland_Events.40.D
	picture = GENERALS_DISCUSSING_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.40.OPT1

		hidden_effect = {
			random_list = {
				60 = { country_event = { id = FEE_Poland_Events.42 } }
				40 = { country_event = { id = FEE_Poland_Events.41 } }
			}
		}
	}
}

# Negotiations with Rebels (Failure)
country_event = {
	id = FEE_Poland_Events.41
	title = FEE_Poland_Events.41.T
	desc = FEE_Poland_Events.41.D
	picture = GENERALS_DISCUSSING_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.41.OPT1
	}
}

# Negotiations with Rebels â„–2
country_event = {
	id = FEE_Poland_Events.42
	title = FEE_Poland_Events.42.T
	desc = FEE_Poland_Events.42.D
	picture = GENERALS_DISCUSSING_eventPicture
	is_triggered_only = yes

	option = {
		name = FEE_Poland_Events.42.OPT1

		hidden_effect = { country_event = { id = FEE_Poland_Events.43 } }
	}

	option = {
		name = FEE_Poland_Events.42.OPT2

		hidden_effect = { country_event = { id = FEE_Poland_Events.44 } }
	}
}

# Negotiations with Rebels (Peacefully)
country_event = {
	id = FEE_Poland_Events.43
	title = FEE_Poland_Events.43.T
	desc = FEE_Poland_Events.43.D
	picture = MILITARY_CAMP_eventPicture
	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			if = {
			limit = {
				4542 = { has_province_flag = PLC_tabor_lubnie }
			}
			4542 = {
				remove_building = fort_15th
				clr_province_flag = PLC_tabor_lubnie
			}
		}

		4542 = { change_controller = ROOT }

		set_country_flag = PLC_dealt_with_nalyvaiko_uprising_peacefully_3
		}
	}

	option = {
		name = FEE_Poland_Events.43.OPT1

		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = -10
		}
		add_estate_loyalty = {
			estate = estate_cossacks
			loyalty = 10
		}
		add_stability = -1
	}
}

# Negotiations with Rebels (Bloody)
country_event = {
	id = FEE_Poland_Events.44
	title = FEE_Poland_Events.44.T
	desc = FEE_Poland_Events.44.D
	picture = VILLAGE_RAIDED_eventPicture
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				4542 = { has_province_flag = PLC_tabor_lubnie }
			}
			4542 = {
				remove_building = fort_15th
				clr_province_flag = PLC_tabor_lubnie
			}
		}

		4542 = { change_controller = ROOT }

		set_country_flag = PLC_dealt_with_nalyvaiko_uprising_bloody
	}

	option = {
		name = FEE_Poland_Events.44.OPT1

		add_estate_loyalty = {
			estate = estate_nobles
			loyalty = 10
		}
		add_estate_loyalty = {
			estate = estate_cossacks
			loyalty = -10
		}

		add_country_modifier = {
			name = fee_pol_nalyvaiko_cossack_lands_confiscated
			duration = 3650
		}
	}
}
