#Estate Privilege on_action effects are in 01_scripted_effects_for_estates.txt

initialize_schools_effect = { #Used in on_startup on_action
	if = {
		limit = { NOT = { has_global_flag = schools_initiated } }
		set_global_flag = schools_initiated
		random_country = { #Ismailis are disliked by all Sunnis at start.
			limit = {
				religious_school = {
					group = muslim
					school = ismaili_school
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = hanafi_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = shafii_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = maliki_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
		}
		random_country = { #Jafaris are disliked by all Sunnis at start.
			limit = {
				religious_school = {
					group = muslim
					school = jafari_school
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = hanafi_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = shafii_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = maliki_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
		}
		random_country = { #Zaidis are disliked by all Sunnis at start.
			limit = {
				religious_school = {
					group = muslim
					school = zaidi_school
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = hanafi_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = hanbali_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = shafii_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			random_country = {
				limit = {
					religious_school = {
						group = muslim
						school = maliki_school
					}
				}
				set_school_opinion = {
					who = PREV
					opinion = -1
				}
			}
			
		}
	}
}

on_new_monarch_effect = {
	if = {
		limit = {
			has_government_attribute = orangist_cause
		}
		set_variable = {
			which = NEDOrangistCauseVar
			value = 0
		}
	}
	if = {
		limit = {
			has_consort_regency = no
			any_owned_province = {
				has_province_modifier = domain_of_spouses_family
			}
		}
		every_owned_province = {
			limit = { has_province_modifier = domain_of_spouses_family }
			remove_province_modifier = domain_of_spouses_family
		}
	}
	if = {
		limit = {
			has_consort_regency = no
			any_owned_province = {
				has_province_modifier = home_of_consort
			}
		}
		every_owned_province = {
			limit = { has_province_modifier = home_of_consort }
			remove_province_modifier = home_of_consort
		}
	}
	if = {
		limit = {
			NOT = { has_dlc = "Mandate of Heaven" }
			has_country_modifier = the_mandate_of_heaven
			NOT = { legitimacy = 80 }
		}
		country_event = { id = china_events.32 }	# History of last ruler
	}
	if = {
		limit = {
			religion = jewish
		}
		clr_country_flag = ruler_is_messiah
	}
	if = {
		limit = {
			is_or_was_tag = {
				tag = TEU
			}
			is_emperor = no
			NOT = { tag = HLR }
			has_country_modifier = teu_pru_imperial_crown
		}
		remove_country_modifier = teu_pru_imperial_crown
	}
	if = {
		limit = { has_any_heir_cult_active = yes }
		remove_heir_cult = yes
	}
	if = {
		limit = { 
			has_government_attribute = kalmar_union_succession
			has_regency = no
			has_consort_regency = no
		}
		if = {
			limit = { has_country_flag = dan_new_elected_ruler }
			clr_country_flag = dan_new_elected_ruler
		}
		else = {
			country_event = {
				id = kalmar_union_events.1	# A new king of the Kalmar Union
			}
		}
	}
	if = {
		limit = { has_government_attribute = absolutism_reduction_on_ruler_death }
		add_absolutism = -60
	}
	if = {
		limit = {
			has_country_modifier = eng_the_age_of_reformation
			is_religion_enabled = protestant
		}
		if = {
			limit = {
				religion = catholic
			}
			random = {
				chance = 50
				if = {
					limit = { is_religion_enabled = anglican }
					set_ruler_religion = anglican
				}
				else = {
					set_ruler_religion = protestant
				}
			}
		}
		if = {
			limit = {
				OR = {
					religion = protestant
					religion = reformed
					religion = anglican
					religion = hussite
				}
			}
			set_ruler_religion = catholic
		}
	}
	if = {
		limit = {
			has_government_attribute = civil_war_on_every_new_ruler 
			NOT = { has_ruler_flag = civil_war_exempt } #Konstantinos
		}
		if = {
			limit = {
				NOT = { total_development = 100 }
			}
			capital_scope = {
				spawn_rebels = {
					type = pretender_rebels
					size = 1
				}
			}
		}
	}
	if = {
		limit = {
			has_government_mechanic = russian_rule_mechanic
		}
		add_government_power = { mechanic_type = russian_rule_mechanic power_type = russian_administrative_rule value = -50 }
		add_government_power = { mechanic_type = russian_rule_mechanic power_type = russian_diplomatic_rule value = -50 }
		add_government_power = { mechanic_type = russian_rule_mechanic power_type = russian_military_rule value = -50 }
	}
	if = {
		limit = {
			has_government_attribute = theocratic_monarchy_mechanic
		}
		#Setting it to 0
		change_statists_vs_orangists = -10
		change_statists_vs_orangists = 1
		if = {
			limit = { has_ruler_flag = monarchistic_heir }
			change_statists_vs_orangists = 0.25
		}
		if = {
			limit = { has_ruler_flag = theocratic_heir }
			change_statists_vs_orangists = -0.25
		}
		if = {
			limit = {
				has_government_attribute = theocratic_monarchy_mechanic
			}
			country_event = {
				id = flavor_sca.2
			}
			country_event = {
				id = theocracy.1
				days = 3
			}
		}
	}
	if = {
		limit = {
			OR = {
				has_government_attribute = absolutism_reduction_on_ruler_death
				has_government_attribute = has_limited_terms
			}
		}
		set_variable = {
			which = election_term
			value = 1
		}
	}
}

battle_cult_spreading_effect = {
	#Yemoya
	if = {
		limit = {
			ROOT = {
				religion = shamanism
				NOT = { has_unlocked_cult = yemoja_cult }
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = yemoja_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.1 } }
	}
	if = {
		limit = {
			FROM = {
				religion = shamanism
				NOT = { has_unlocked_cult = yemoja_cult }
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = yemoja_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.1 } }
	}
	#Roog
	if = {
		limit = {
			ROOT = {
				religion = shamanism
				NOT = { has_unlocked_cult = roog_cult }
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = roog_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.2 } }
	}
	if = {
		limit = {
			FROM = {
				religion = shamanism
				NOT = { has_unlocked_cult = roog_cult }
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = roog_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.2 } }
	}
	#Nyame
	if = {
		limit = {
			ROOT = {
				religion = shamanism
				NOT = { has_unlocked_cult = nyame_cult }
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = nyame_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.3 } }
	}
	if = {
		limit = {
			FROM = {
				religion = shamanism
				NOT = { has_unlocked_cult = nyame_cult }
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = nyame_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.3 } }
	}
	
	#Cwezi / Swezi / Kubandwa
	if = {
		limit = {
			ROOT = {
				religion = shamanism
				NOT = { has_unlocked_cult = cwezi_cult }
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = cwezi_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.101 } }
	}
	if = {
		limit = {
			FROM = {
				religion = shamanism
				NOT = { has_unlocked_cult = cwezi_cult }
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = cwezi_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.101 } }
	}
	
	#Mlira and other Nature Spirits and/or ancestral cults of Central Africa
	if = {
		limit = {
			ROOT = {
				religion = shamanism
				NOT = { has_unlocked_cult = central_african_ancestor_cult }
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = central_african_ancestor_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.102 } }
	}
	if = {
		limit = {
			FROM = {
				religion = shamanism
				NOT = { has_unlocked_cult = central_african_ancestor_cult }
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = central_african_ancestor_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.102 } }
	}
	
	#Mwari
	if = {
		limit = {
			ROOT = {
				religion = shamanism
				NOT = { has_unlocked_cult = mwari_cult }
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = mwari_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.103 } }
	}
	if = {
		limit = {
			FROM = {
				religion = shamanism
				NOT = { has_unlocked_cult = mwari_cult }
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = mwari_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.103 } }
	}
	
	#Enkai
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = enkai_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = enkai_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.201 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = enkai_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = enkai_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.201 } }
	}
	#Waaq
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = waaq_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = waaq_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.202 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = waaq_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = waaq_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.202 } }
	}
	#Zanahary
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = zanahary_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				religion = shamanism
				has_unlocked_cult = zanahary_cult
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.203 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = zanahary_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				religion = shamanism
				has_unlocked_cult = zanahary_cult
			}
		}
		FROM = { country_event = { id = fetishist_flavor.203 } }
	}
	#Christianity
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = christianity_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion_group = christian
					has_unlocked_cult = christianity_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.400 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = christianity_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = christianity_cult
					religion_group = christian
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.400 } }
	}
	#Islam
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = islam_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion_group = muslim
					has_unlocked_cult = islam_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.401 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = islam_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = islam_cult
					religion_group = muslim
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.401 } }
	}
	#Buddhism
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = buddhism_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion_group = eastern
					has_unlocked_cult = buddhism_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.402 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = buddhism_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = buddhism_cult
					religion_group = eastern
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.402 } }
	}
	#Dharmic Cult
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = dharmic_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion_group = dharmic
					has_unlocked_cult = dharmic_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.403 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = dharmic_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = dharmic_cult
					religion_group = dharmic
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.403 } }
	}
	#Teotl Cult
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = south_central_american_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion = nahuatl
					religion = inti
					religion = mesoamerican_religion
					has_unlocked_cult = south_central_american_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.404 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = south_central_american_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = south_central_american_cult
					religion = nahuatl
					religion = mesoamerican_religion
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.404 } }
	}
	#Norse Cult
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = norse_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion = norse_pagan_reformed
					has_unlocked_cult = norse_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.405 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = norse_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = norse_cult
					religion = norse_pagan_reformed
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.405 } }
	}
	#Jewish Cult
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = jewish_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion = jewish
					has_unlocked_cult = jewish_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.406 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = jewish_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = jewish_cult
					religion = jewish
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.406 } }
	}
	#Zoroastrian Cult
	if = {
		limit = {
			ROOT = {
				NOT = { has_unlocked_cult = zoroastrian_cult }
				religion = shamanism #Fetishism
			}
			FROM = {
				OR = {
					religion = zoroastrian
					has_unlocked_cult = zoroastrian_cult
				}
			}
		}
		ROOT = { country_event = { id = fetishist_flavor.407 } }
	}
	if = {
		limit = {
			FROM = {
				NOT = { has_unlocked_cult = zoroastrian_cult }
				religion = shamanism #Fetishism
			}
			ROOT = {
				OR = {
					has_unlocked_cult = zoroastrian_cult
					religion = zoroastrian
				}
			}
		}
		FROM = { country_event = { id = fetishist_flavor.407 } }
	}
}

crimean_succession_effect = {
	if = {
		limit = {
			tag = CRI
			NOT = { has_global_flag = death_of_haji_giray } #Also set in history.
			exists = TUR
			is_subject = no
			TUR = {
				num_of_cities = ROOT
				is_subject = no
				num_of_ports = 1
			}
		}
		country_event = { id = flavor_cri.1 } #Death of Haji Giray
	}
	if = {
		limit = {
			tag = CRI
			NOT = { has_global_flag = death_of_haji_giray } #Also set in history.
			OR = {
				NOT = { exists = TUR }
				is_subject = yes
				TUR = { NOT = { num_of_cities = ROOT } }
				TUR = { is_subject = yes }
				TUR = { NOT = { num_of_ports = 1 } }
			}
		}
		set_global_flag = death_of_haji_giray
	}
}

slesvig_question_effect = {
	if = {
		limit = {
			tag = SHL
			NOT = { has_global_flag = death_of_adolf_of_slesvig } #
			is_subject_of = DAN
			ai = yes
		}
		DAN = { country_event = { id = flavor_dan.4 } } # Death of Adolf VIII
		set_global_flag = death_of_adolf_of_slesvig
	}
}

succession_culture_religion_effect = {
	if = {
		limit = {
			NOT = { has_reform = elective_monarchy }
			NOT = { has_reform = polish_elective_monarchy } 
			has_regency = no
			NOT = { has_country_flag = had_culture_religion_reaction_event_flag }
			NOT = { has_reform = mamluk_government }
			OR = {
				NOT = { ruler_culture = ROOT }
				NOT = { ruler_religion = ROOT }
			}
		}
		set_country_flag = had_culture_religion_reaction_event_flag #Note: Cleared in the event below, all future effects from ruler culture/religion are gated behind this flag being cleared.
		country_event = { id = culture_religion_events.2 days = 75 random = 7 }
	}
}

sheik_ul_islam_effect = {
	if = {
		limit = {
			has_dlc = "Cradle of Civilization"
			NOT = { has_country_flag = had_sheikh_ul_islam_event } #Cleared by the event itself. Avoids event spam if multiple quick successions
			uses_piety = yes
			num_of_cities = 20
			government_rank = 2
			has_religious_school = yes
			government = monarchy
			NOT = { has_reform = steppe_horde }
		}
		set_country_flag = had_sheikh_ul_islam_event
		country_event = { id = muslim_school_events.2 days = 45 random = 7 } #New Grand Mufti/Sheik-ul-Islam
	}
}

ambrosian_republic_effect = {
	if = {
		limit = {
			tag = MLO
		}
		country_event = { id = flavor_mlo.1 days = 3 } # The Ambrosian Republic
	}
}

hab_remove_mission_mods_if_not_emperor_effect = {
	if = {
		limit = {
			OR = {
				tag = HAB
				was_tag = HAB
			}
			is_emperor = no
			NOT = { tag = HLR }
			OR = {
				has_country_modifier = hab_empire_united_in_religion_mod_catholic
				has_country_modifier = hab_empire_united_in_religion_mod_protestant
				has_country_modifier = hab_empire_united_in_religion_mod_reformed
				has_country_modifier = hab_empire_united_in_religion_mod_generic
				has_country_modifier = hab_empire_has_rome
				has_country_modifier = hab_aeiou_mod
			}
		}
		if = {
			limit = {
				has_country_modifier = hab_empire_united_in_religion_mod_catholic
			}
			remove_country_modifier = hab_empire_united_in_religion_mod_catholic
		}
		else_if = {
			limit = {
				has_country_modifier = hab_empire_united_in_religion_mod_protestant
			}
			remove_country_modifier = hab_empire_united_in_religion_mod_protestant
		}
		else_if = {
			limit = {
				has_country_modifier = hab_empire_united_in_religion_mod_reformed
			}
			remove_country_modifier = hab_empire_united_in_religion_mod_reformed
		}
		else_if = {
			limit = {
				has_country_modifier = hab_empire_united_in_religion_mod_generic
			}
			remove_country_modifier = hab_empire_united_in_religion_mod_generic
		}
		if = {
			limit = {
				has_country_modifier = hab_empire_has_rome
			}
			remove_country_modifier = hab_empire_has_rome
		}
		if = {
			limit = {
				has_country_modifier = hab_aeiou_mod
			}
			remove_country_modifier = hab_aeiou_mod
		}
	}
}

thu_remain_von_wettin_effect = {
	if = {
		limit = {
			tag = THU
			NOT = { is_year = 1520 }
			NOT = { dynasty = "von Wettin" }
			is_in_war = {
				attacker_leader = root
				defenders = SAX
				casus_belli = cb_independence_war
			}
			SAX = {
				government = monarchy
				dynasty = "von Wettin"
			}
		}
		define_ruler = {
			dynasty = "von Wettin"
		}
	#			country_event = { id = flavor_sax.4 days = 1 }
	}
}

ladislaus_postumus_heir_died_effect = {
	if = {
		limit = {
			tag = HUN
			has_country_flag = hun_ladislaus_postumus_heir
			HAB = {
				has_heir = "Ladislaus Postumus"
				has_country_flag = hab_ladislaus_postumus_heir
			}
		}
		clr_country_flag = hun_ladislaus_postumus_heir
		HAB = {
			kill_heir = {}
			clr_country_flag = hab_ladislaus_postumus_heir
		}
	}
	if = {
		limit = {
			tag = HUN
			has_country_flag = hun_ladislaus_postumus_heir
			HAB = {
				has_ruler = "Ladislaus Postumus"
				has_country_flag = hab_ladislaus_postumus_king
			}
		}
		clr_country_flag = hun_ladislaus_postumus_heir
		HAB = {
			kill_ruler = yes
			clr_country_flag = hab_ladislaus_postumus_king
		}
	}
	if = {
		limit = {
			tag = HAB
			has_country_flag = hab_ladislaus_postumus_heir
			HUN = {
				has_heir = "Ladislaus Postumus"
				has_country_flag = hun_ladislaus_postumus_heir
			}
		}
		clr_country_flag = hab_ladislaus_postumus_heir
		HUN = {
			kill_heir = {}
			clr_country_flag = hun_ladislaus_postumus_heir
		}
	}
	if = {
		limit = {
			tag = HAB
			has_country_flag = hab_ladislaus_postumus_heir
			HUN = {
				has_ruler = "Ladislaus Postumus I"
				has_country_flag = hun_ladislaus_postumus_king
			}
		}
		clr_country_flag = hab_ladislaus_postumus_heir
		HUN = {
			kill_ruler = yes
			clr_country_flag = hun_ladislaus_postumus_king
		}
	}
	if = {
		limit = {
			OR = {
				has_country_flag = hab_ladislaus_postumus_heir
				has_country_flag = hun_ladislaus_postumus_heir
			}
		}
		clr_country_flag = hab_ladislaus_postumus_heir
		clr_country_flag = hun_ladislaus_postumus_heir
	}
}

ladislaus_postumus_king_died_effect = {
	if = {
		limit = {
			tag = HUN
			has_country_flag = hun_ladislaus_postumus_king
			NOT = {
				has_country_flag = hun_keep_ladislaus_alive
			}
			HAB = {
				has_heir = "Ladislaus Postumus"
				has_country_flag = hab_ladislaus_postumus_heir
			}
		}
		HAB = {
			kill_heir = {}
			clr_country_flag = hab_ladislaus_postumus_heir
		}
	}
	if = {
		limit = {
			tag = HAB
			has_country_flag = hab_ladislaus_postumus_king
			HUN = {
				has_heir = "Ladislaus Postumus"
				has_country_flag = hun_ladislaus_postumus_heir
			}
		}
		HUN = {
			kill_heir = {}
			clr_country_flag = hun_ladislaus_postumus_heir
		}
	}
	if = {
		limit = {
			has_country_flag = hun_ladislaus_postumus_king
		}
		clr_country_flag = hun_ladislaus_postumus_king
	}
	if = {
		limit = {
			has_country_flag = hab_ladislaus_postumus_king
		}
		clr_country_flag = hab_ladislaus_postumus_king
	}
	if = {
		limit = { 
			has_country_flag = hun_keep_ladislaus_alive
		}
		clr_country_flag = hun_keep_ladislaus_alive
	}
}

ladislaus_postumus_union_effect = {
	if = {
		limit = {
			tag = HUN
			has_ruler = "Ladislaus Postumus I"
			HAB = {
				has_heir = "Ladislaus Postumus"
			}
		}
		clr_country_flag = hun_ladislaus_postumus_heir
		set_country_flag = hun_ladislaus_postumus_king
	}
	if = {
		limit = {
			tag = HAB
			has_ruler = "Ladislaus Postumus"
			HUN = {
				has_heir = "Ladislaus Postumus"
			}
		}
		clr_country_flag = hab_ladislaus_postumus_heir
		set_country_flag = hab_ladislaus_postumus_king
	}

	if = {
		limit = {
			tag = HAB
			has_ruler = "Ladislaus Postumus"
			has_regency = no
			HUN = {
				has_ruler = "Ladislaus Postumus I"
				OR = {
					has_country_flag = hun_ladislaus_postumus_heir
					has_country_flag = hun_ladislaus_postumus_king
				}
				is_subject = no
			}
		}
		country_event = { id = flavor_hab.21 }
		clr_country_flag = hab_ladislaus_postumus_heir
		HUN = {
			clr_country_flag = hun_ladislaus_postumus_heir
			clr_country_flag = hun_ladislaus_postumus_king
		}
	}
	if = {
		limit = {
			tag = HUN
			has_ruler = "Ladislaus Postumus I"
			has_regency = no
			is_subject = no
			HAB = {
				has_ruler = "Ladislaus Postumus"
			}
			OR = {
				has_country_flag = hun_ladislaus_postumus_heir
				has_country_flag = hun_ladislaus_postumus_king
			}
		}
		clr_country_flag = hun_ladislaus_postumus_heir
		HAB = {
			country_event = { id = flavor_hab.21 }
			clr_country_flag = hab_ladislaus_postumus_heir
			clr_country_flag = hab_ladislaus_postumus_king
		}
	}
}

burgundian_inheritance_start_effect = {
	#Burgundian succession stuff
	if = {
		limit = {
			tag = BUR
			has_country_modifier = burgundian_succession_crisis
			NOT = { has_country_flag = burgundian_succession_has_already_fired }
			is_subject = no
			is_lesser_in_union = no
		}
		#Fire an event which checks on the current state of Burgundy to see if they are already in a normal PU or not
		country_event = {
			id = incidents_bur_inheritance.1000
			days = 1
		}
	}
	else_if = {
		limit = {
			tag = BUR
			has_regency = no
			has_ruler_flag = is_charles_of_burg_flag #this flag is assigned in the history file of Burgundy
			NOT = { has_country_modifier = burgundian_succession_crisis } 
			NOT = { has_country_flag = burgundian_succession_has_already_fired }
		}
		clr_ruler_flag = is_charles_of_burg_flag
		add_country_modifier = { #country modifier used to weaken Charles's fertility, is also used as a trigger for the inheritance event above.
			name = burgundian_succession_crisis
			duration = -1
			hidden = yes
		}
	}
	#Burgundian marriage cleaner
	if = {
		limit = { tag = BUR }
		country_event = {
			id = incidents_bur_inheritance.1001
			days = 3
		}
	}
}

joan_de_trastamara_king_died_effect = {
	if = {
		limit = {
			tag = NAV
			is_lesser_in_union = no
			ARA = {
				exists = yes
				has_heir_flag = joan_trastamara_flag
				is_lesser_in_union = no
			}
		}
		ARA = { kill_heir = {} }
	}
}

joan_de_trastamara_heir_died_effect = {
	if = {
		limit = {
			tag = ARA
			is_lesser_in_union = no
			NAV = {
				exists = yes
				has_ruler_flag = joan_trastamara_flag
				is_lesser_in_union = no
			}
		}
		NAV = { kill_ruler = yes }
	}
}

on_province_owner_change_government_effect = {
	if = {
		limit = {
			OR = {
				has_province_modifier = wine_bonus_prod
				has_province_modifier = grain_bonus_prod
			}
			FROM = { has_reform = monastic_breweries_reform }
			NOT = { owner = { has_reform = monastic_breweries_reform } }
		}
		remove_province_modifier = wine_bonus_prod
		remove_province_modifier = grain_bonus_prod
	}
	if = {
		limit = {
			NOT = {
				OR = {
					has_province_modifier = wine_bonus_prod
					has_province_modifier = grain_bonus_prod
				}
			}
			owner = { has_reform = monastic_breweries_reform }
			NOT = { FROM = { has_reform = monastic_breweries_reform } }
		}
		hidden_effect = {
			if = {
				limit = {
					trade_goods = wine
				}
				add_province_modifier = { 
					name = wine_bonus_prod
					duration = -1
					hidden = yes
				}
			}
			if = {
				limit = {
					trade_goods = grain
				}
				add_province_modifier = { 
					name = grain_bonus_prod
					duration = -1
					hidden = yes
				}
			}
		}
	}
	if = {
		limit = {
			trade_goods = paper
			owner = {
				has_government_attribute = GER_buff_paper_provinces
			}
		}
		add_province_modifier = { 
			name = GER_paper_provinces_franconian
			duration = -1
		}
	}
	if = {
		limit = {
			OR = {
				trade_goods = iron
				trade_goods = copper
				trade_goods = gold
			}
			owner = {
				has_government_attribute = GER_buff_mining_provinces
			}
		}
		add_province_modifier = { 
			name = GER_mining_provinces_saxon
			duration = -1
		}
	}
	if = {
		limit = {
			has_province_modifier = grain_vodka_bonus_prod
			FROM = { has_government_attribute = extra_trade_goods_from_grain }
			NOT = { owner = { has_government_attribute = extra_trade_goods_from_grain } }
		}
		remove_province_modifier = grain_vodka_bonus_prod
	}
	if = {
		limit = {
			NOT = { has_province_modifier = grain_vodka_bonus_prod }
			owner = { has_government_attribute = extra_trade_goods_from_grain }
			NOT = { FROM = { has_government_attribute = extra_trade_goods_from_grain } }
			trade_goods = grain
		}
		hidden_effect = {
			add_province_modifier = { 
				name = grain_vodka_bonus_prod
				duration = -1
				hidden = yes
			}
		}
	}
	if = {
		limit = {
			has_province_modifier = naval_supplies_bonus_prod
			FROM = { has_government_attribute = extra_trade_goods_from_naval_supplies }
			NOT = { owner = { has_government_attribute = extra_trade_goods_from_naval_supplies } }
		}
		remove_province_modifier = naval_supplies_bonus_prod
	}
	if = {
		limit = {
			NOT = { has_province_modifier = naval_supplies_bonus_prod }
			owner = { has_government_attribute = extra_trade_goods_from_naval_supplies }
			NOT = { FROM = { has_government_attribute = extra_trade_goods_from_naval_supplies } }
		}
		hidden_effect = {
			if = {
				limit = {
					trade_goods = naval_supplies
				}
				add_province_modifier = { 
					name = naval_supplies_bonus_prod
					duration = -1
					hidden = yes
				}
			}
		}
	}
	if = {
		limit = {
			has_province_modifier = swe_support_of_the_peasantry_prov
			FROM = { has_country_modifier = swe_support_of_the_peasantry }
			NOT = { owner = { has_country_modifier = swe_support_of_the_peasantry } }
		}
		remove_province_modifier = swe_support_of_the_peasantry_prov
	}
	if = {
		limit = {
			NOT = { has_province_modifier = swe_support_of_the_peasantry_prov }
			owner = { has_country_modifier = swe_support_of_the_peasantry }
			NOT = { FROM = { has_country_modifier = swe_support_of_the_peasantry } }
		}
		hidden_effect = {
			if = {
				limit = {
					OR = {
						trade_goods = grain
						trade_goods = livestock
						trade_goods = fish
					}
				}
				add_province_modifier = { 
					name = swe_support_of_the_peasantry_prov
					duration = -1
					hidden = yes
				}
			}
		}
	}
	if = {
		limit = {
			owner = { has_government_attribute = temples_modifier }
			has_tax_building_trigger = yes
		}
		add_province_modifier = {
			name = gov_expanded_temple_rights_mod
			duration = -1
		}
	}
	if = {
		limit = {
			owner = { has_government_attribute = more_25_tax_in_true_faith_provinces }
			has_owner_religion = yes
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_tax
			duration = -1
		}
	}
	if = {
		limit = {
			owner = { has_government_attribute = more_15_manpower_in_heathen_provinces }
			NOT = { religion_group = owner }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_manpower
			duration = -1
		}
	}
	if = {
		limit = {
			owner = { has_government_attribute = improved_military_buildings }
		}
		if = {
			limit = { has_building = barracks }
			add_province_modifier = {
				name = wei_suo_system_reform_barracks_modifier
				duration = -1
				hidden = yes
			}
		}
		if = {
			limit = { has_building = training_fields }
			add_province_modifier = {
				name = wei_suo_system_reform_training_fields_modifier
				duration = -1
				hidden = yes
			}
		}
		if = {
			limit = { has_building = regimental_camp }
			add_province_modifier = {
				name = wei_suo_system_reform_regimental_camp_modifier
				duration = -1
				hidden = yes
			}
		}
		if = {
			limit = { has_building = conscription_center }
			add_province_modifier = {
				name = wei_suo_system_reform_conscription_center_modifier
				duration = -1
				hidden = yes
			}
		}
		if = {
			limit = { has_building = soldier_households }
			add_province_modifier = {
				name = wei_suo_system_reform_soldier_households_modifier
				duration = -1
				hidden = yes
			}
		}
	}
	if = {
		limit = {
			has_port = yes
			owner = {
				has_government_attribute = cheaper_coastal_province_core
			}
		}
		add_province_modifier = {
			name = gov_coastal_government
			duration = -1
		}
	}
	if = {
		limit = {
			has_owner_culture = yes
			owner = { has_government_attribute = can_recruit_banners_from_primary_culture_provinces }
		}
		add_province_modifier = { name = mongol_banners_location duration = -1 hidden = yes }
	}
}

on_province_religion_changed_effect = {
	on_province_religion_converted_estate_privileges_effect = yes
	if = {
		limit = {
			owner = {
				has_country_modifier = son_fetishism_as_secondary_religion
			}
			religion = shamanism
			NOT = { has_province_modifier = son_fetishism_as_secondary_religion_province }
		}
		add_province_modifier = {
			name = son_fetishism_as_secondary_religion_province
			duration = -1
			desc = son_fetishism_as_secondary_religion_province_desc
		}
	}
	else_if = {
		limit = {
			OR = {
				owner = {
					NOT = { has_country_modifier = son_fetishism_as_secondary_religion }
				}
				NOT = { religion = shamanism }
			}
			has_province_modifier = son_fetishism_as_secondary_religion_province
		}
		remove_province_modifier = son_fetishism_as_secondary_religion_province
	}
	if = {
		limit = {
			OR = {
				religion_group = christian
				religion_group = muslim
			}
			owner = {
				has_church_aspect = jewish_abrahamic_aspect
			}
		}
		add_province_modifier = {
			name = judaism_abrahamic_roots
			duration = -1
		}
	}
	else_if = {
		limit = {
			has_province_modifier = judaism_abrahamic_roots
			OR = {
				AND = {
					NOT = { religion_group = christian }
					NOT = { religion_group = muslim }
				}
				owner = {
					NOT = { has_church_aspect = jewish_abrahamic_aspect }
				}
			}
		}
		remove_province_modifier = judaism_abrahamic_roots
	}
	if = {
		limit = {
			religion = jewish
			owner = {
				has_church_aspect = judaism_communities_aspect
			}
		}
		if = {
			limit = {
				has_owner_accepted_culture = no
				has_owner_culture = no
				owner = { NOT = { culture_group = ROOT } }
			}
			add_province_modifier = {
				name = judaism_community_wrong_culture
				duration = -1
			}
		}
		else_if = {
			limit = {
				owner = {
					culture_group = ROOT
					has_cultural_union = no
				}
				has_owner_accepted_culture = no
			}
			add_province_modifier = {
				name = judaism_community_same_culture_group
				duration = -1
			}
		}
	}
	else_if = {
		limit = {
			OR = {
				NOT = { religion = jewish }
				owner = { NOT = { has_church_aspect = judaism_communities_aspect } }
				has_owner_accepted_culture = yes
				has_owner_culture = yes
			}
			OR = {
				has_province_modifier = judaism_community_wrong_culture
				has_province_modifier = judaism_community_same_culture_group
			}
		}
		if = {
			limit = { has_province_modifier = judaism_community_wrong_culture }
			remove_province_modifier = judaism_community_wrong_culture
		}
		if = {
			limit = { has_province_modifier = judaism_community_same_culture_group }
			remove_province_modifier = judaism_community_same_culture_group
		}
	}
}

on_province_religion_converted_effect = {
	if = {
		limit = { owner = { has_government_attribute = gain_devotion_from_conversions } }
		owner = { add_devotion = 0.2 }
	}
	if = {
		limit = { owner = { has_government_attribute = theocratic_monarchy_mechanic } }
		owner = { change_statists_vs_orangists = -0.01 }
	}
	if = {
		limit = { 
			owner = { 
				has_government_mechanic = the_three_royal_fires_mechanic 
				NOT = { has_country_flag = removed_asha_vahishta_loss_from_missionaries }
			} 
			has_owner_religion = yes 
		}
		export_to_variable = {
			which = province_dev
			value = development
		}
		while = {
			limit = {
				check_variable = {
					which = province_dev
					value = 1
				}
			}
			subtract_variable = {
				which = province_dev
				value = 1
			}
			owner = {
				change_asha_vahishta = { value = -1 }
			}
		}
	}
}

on_trade_good_changed_government_effect = {
	if = {
		limit = {
			owner = { has_reform = monastic_breweries_reform }
		}
		if = {
			limit = {
				trade_goods = grain
			}
			remove_province_modifier = wine_bonus_prod
			add_province_modifier = { 
				name = grain_bonus_prod
				duration = -1
				hidden = yes
			}
		}
		else_if = {
			limit = {
				trade_goods = wine
			}
			remove_province_modifier = wine_bonus_prod
			add_province_modifier = { 
				name = grain_bonus_prod
				duration = -1
				hidden = yes
			}
		}
		else = {
			remove_province_modifier = wine_bonus_prod
			remove_province_modifier = grain_bonus_prod
		}
	}
	else = {
		remove_province_modifier = wine_bonus_prod
		remove_province_modifier = grain_bonus_prod
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = GER_buff_paper_provinces
			}
		}
		if = {
			limit = {
				trade_goods = paper
			}
			add_province_modifier = { 
				name = GER_paper_provinces_franconian
				duration = -1
			}
		}
		else = {
			remove_province_modifier = GER_paper_provinces_franconian
		}
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = GER_buff_mining_provinces
			}
		}
		if = {
			limit = {
				OR = {
					trade_goods = iron
					trade_goods = copper
					trade_goods = gold
				}
			}
			add_province_modifier = { 
				name = GER_mining_provinces_saxon
				duration = -1
			}
		}
		else = {
			remove_province_modifier = GER_mining_provinces_saxon
		}
	}
	if = {
		limit = { owner = { has_government_attribute = extra_trade_goods_from_grain } }
		if = {
			limit = { trade_goods = grain }
			add_province_modifier = { 
				name = grain_vodka_bonus_prod
				duration = -1
				hidden = yes
			}
		}
		else = { remove_province_modifier = grain_vodka_bonus_prod }
	}
	else = { remove_province_modifier = grain_vodka_bonus_prod }
	if = {
		limit = {
			owner = { has_government_attribute = extra_trade_goods_from_naval_supplies }
		}
		if = {
			limit = {
				trade_goods = naval_supplies
			}
			add_province_modifier = { 
				name = naval_supplies_bonus_prod
				duration = -1
				hidden = yes
			}
		}
		else = {
			remove_province_modifier = naval_supplies_bonus_prod
		}
	}
	else = {
		remove_province_modifier = naval_supplies_bonus_prod
	}
	if = {
		limit = {
			owner = { has_country_modifier = swe_support_of_the_peasantry }
		}
		if = {
			limit = {
				OR = {
					trade_goods = grain
					trade_goods = fish
					trade_goods = livestock
				}
			}
			add_province_modifier = { 
				name = swe_support_of_the_peasantry_prov
				duration = -1
				hidden = yes
			}
		}
		else = {
			remove_province_modifier = swe_support_of_the_peasantry_prov
		}
	}
	else = {
		remove_province_modifier = swe_support_of_the_peasantry_prov
	}
}

on_battle_won_unit_effect = {
	if = {
		limit = {
			unit_owner = {
				has_government_mechanic = divine_authority_mechanic
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			set_variable = {
				which = monarch_kill
				which = land_units_killed
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_kill
						value = 100
					}
				}
				change_variable = {
					which = monarch_kill
					value = -100
				}
				add_government_power = { 
					mechanic_type = divine_authority_mechanic 
					power_type = divine_authority
					value = 0.01
				}
			}
		}
	}
	if = {
        limit = {
            unit_owner = {
                has_government_attribute = orangist_cause
				is_orangists_in_power = yes
            }
            is_ruler_commanding_unit = yes
        }
        unit_owner = {
			change_variable = {
				which = NEDOrangistCauseVar
				value = 1
			}
			if = {
				limit = {
					check_variable = {
						which = NEDOrangistCauseVar
						value = 25
					}
				}
				add_ruler_personality = orangist_stadholder_personality
			}
        }
	}
	if = {
		limit = {
			unit_owner = {
				has_government_mechanic = ottoman_decadence_mechanic
				check_variable = {	#Check so overrun will not decrease Decadence
					which = land_units_lost
					value = 1
				}
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			set_variable = {
				which = monarch_kill
				which = land_units_killed
			}
			set_variable = {
				which = monarch_losses
				which = land_units_lost
			}
			divide_variable = {
				which = monarch_kill
				value = 1000
			}
			divide_variable = {
				which = monarch_losses
				value = 1000
			}
			change_variable = {	#in order to avoid division by 0
				which = monarch_losses
				value = 1
			}
			divide_variable = {
				which = monarch_kill
				which = monarch_losses
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_kill
						value = 1
					}
				}
				change_variable = {
					which = monarch_kill
					value = -1
				}
				add_government_power = { 
					mechanic_type = ottoman_decadence_mechanic 
					power_type = ottoman_decadence
					value = -0.1
				}
			}
			multiply_variable = {
				which = monarch_kill
				value = 10
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_kill
						value = 1
					}
				}
				change_variable = {
					which = monarch_kill
					value = -1
				}
				add_government_power = { 
					mechanic_type = ottoman_decadence_mechanic 
					power_type = ottoman_decadence
					value = -0.01
				}
			}
		}
	}
}

on_battle_lost_unit_effect = {
	if = {
		limit = {
			unit_owner = {
				has_government_mechanic = divine_authority_mechanic
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			set_variable = {
				which = monarch_kill
				which = land_units_killed
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_kill
						value = 100
					}
				}
				change_variable = {
					which = monarch_kill
					value = -100
				}
				add_government_power = { 
					mechanic_type = divine_authority_mechanic 
					power_type = divine_authority
					value = 0.01
				}
			}
		}
	}
	if = {
        limit = {
            unit_owner = {
                has_government_attribute = orangist_cause
				is_orangists_in_power = yes
            }
            is_ruler_commanding_unit = yes
        }
	}
	if = {
		limit = {
			unit_owner = {
				has_government_mechanic = ottoman_decadence_mechanic
				check_variable = {	#Check so overrun will not decrease Decadence
					which = land_units_killed
					value = 1
				}
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			set_variable = {
				which = monarch_kill
				which = land_units_killed
			}
			set_variable = {
				which = monarch_losses
				which = land_units_lost
			}
			divide_variable = {
				which = monarch_kill
				value = 1000
			}
			divide_variable = {
				which = monarch_losses
				value = 1000
			}
			change_variable = {	#in order to avoid division by 0
				which = monarch_kill
				value = 1
			}
			divide_variable = {
				which = monarch_losses
				which = monarch_kill
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_losses
						value = 1
					}
				}
				change_variable = {
					which = monarch_losses
					value = -1
				}
				add_government_power = { 
					mechanic_type = ottoman_decadence_mechanic 
					power_type = ottoman_decadence
					value = 0.1
				}
			}
			multiply_variable = {
				which = monarch_losses
				value = 10
			}
			while = {
				limit = {
					check_variable = {
						which = monarch_losses
						value = 1
					}
				}
				change_variable = {
					which = monarch_losses
					value = -1
				}
				add_government_power = { 
					mechanic_type = ottoman_decadence_mechanic 
					power_type = ottoman_decadence
					value = 0.01
				}
			}
		}
	}
}

on_battle_won_country_effect = {
	if = {
		limit = {
			has_dlc = "Winds of Change"
			OR = {
				tag = BOH
				was_tag = BOH
			}
			has_mission = boh_bozi_bojovnici
			NOT = {
				mission_completed = boh_bozi_bojovnici
			}
		}
		change_variable = { which = bohemia_num_of_won_battles value = 1 }
	}
	if = {
		limit = {
			has_dlc = "Winds of Change"
			OR = {
				tag = BOH
				was_tag = BOH
			}
			has_mission = boh_shield_of_the_true_faith
			NOT = {
				mission_completed = boh_shield_of_the_true_faith
			}
			FROM = {
				NOT = {
					religion = ROOT
				}
			}
		}
		change_variable = { which = bohemia_num_of_won_battles_against_heretic_heathen value = 1 }
	}
	change_variable = {
		which = num_of_battles_won_var
		value = 1
	}
	if = {
		limit = {
			tag = NED
		}
		change_variable = {
			which = NEDBattlesWon
			value = 1
		}
	}
	if = {
		limit = {
			ROOT = {
				religion = jewish
				has_church_aspect = judaism_purim_teachings_aspect
			}
		}
		ROOT = {
			add_war_exhaustion = -0.05
		}
	}
	if = {
		limit = {
			ROOT = { has_government_attribute = manpower_from_defeating_armies }
		}
		ROOT = {
			set_variable = {
				which = land_units_killed_var
				which = land_units_killed
			}
			multiply_variable = {
				which = land_units_killed_var
				value = 0.1
			}
			while = {
				limit = {
					check_variable = {
						which = land_units_killed_var
						value = 1000
					}
				}
				subtract_variable = {
					which = land_units_killed_var
					value = 1000
				}
				add_manpower = 1
			}
			multiply_variable = {
				which = land_units_killed_var
				value = 1000
			}
			while = {
				limit = {
					check_variable = {
						which = land_units_killed_var
						value = 1000
					}
				}
				subtract_variable = {
					which = land_units_killed_var
					value = 1000
				}
				add_manpower = 0.001
			}
		}
	}
	if = {
		limit = {
			ROOT = {
				tag = ALB
				NOT = { has_country_flag = albanian_victory }
			}
			FROM = {
				tag = TUR
			}
		}
		ROOT = { set_country_flag = albanian_victory }
	}
	count_won_battles_and_reward_at_end = {
		counting_flag = teu_crusader_battle_counter
		max_value = 20
		effect = "
			country_event = {
				id = flavor_teu.12
			}
		"
	}
	count_won_battles_and_reward_at_end = {
		counting_flag = has_rus_kill_counter
		max_value = 40
		effect = "set_country_flag = rus_finished_kill_mission"
	}
	if = {
		limit = {
			has_country_modifier = geo_bane_khagan
			FROM = {
				has_reform = steppe_horde
			}
		}
		add_army_tradition = 0.5
	}
	if = {
		limit = {
			ROOT = {
				has_country_modifier = turkoman_triumphant_conquest
			}
			FROM = {
				tag = TIM
			}
		}
		random_list = {
			20 = { ROOT = { add_manpower = 2 } }
			80 = { }
		}
	}
}

on_battle_ended_effect = {
	ROOT = {
		change_variable = {
			which = total_land_units_killed
			which = land_units_killed
		}
		change_variable = {
			which = total_land_units_lost
			which = land_units_lost
		}
		change_variable = {
			which = total_naval_units_killed
			which = naval_units_killed
		}
		change_variable = {
			which = total_naval_units_lost
			which = naval_units_lost
		}
	}
}

#Province effect
judaism_on_province_culture_converted_effect = {
	if = {
		limit = { has_province_modifier = judaism_community_wrong_culture }
		remove_province_modifier = judaism_community_wrong_culture
	}
	if = {
		limit = { has_province_modifier = judaism_community_same_culture_group }
		remove_province_modifier = judaism_community_same_culture_group
	}
	if = {
		limit = {
			religion = jewish
			owner = {
				has_church_aspect = judaism_communities_aspect
			}
		}
		if = {
			limit = {
				has_owner_accepted_culture = no
				has_owner_culture = no
				owner = { NOT = { culture_group = ROOT } }
			}
			add_province_modifier = {
				name = judaism_community_wrong_culture
				duration = -1
			}
		}
		if = {
			limit = {
				owner = {
					culture_group = ROOT
					has_cultural_union = yes
				}
				has_owner_accepted_culture = no
			}
			add_province_modifier = {
				name = judaism_community_same_culture_group
				duration = -1
			}
		}
	}
}

on_religion_change_effect = {
	###removes catholic modifiers
		remove_country_modifier = counter_reformation
		remove_country_modifier = the_statue_in_restraint_of_appeals
		remove_country_modifier = revocation_of_restraint_of_appeals
		remove_country_modifier = bavarian_jesuits
		remove_country_modifier = the_societas_jesu
		remove_country_modifier = the_declaration_of_indulgence
		remove_country_modifier = de_heretico_comburendo
		remove_country_modifier = the_conventicle_act
	if = {
		limit = {
			has_reform = indian_sultanate_reform
			NOT = { religion_group = muslim }
		}
		remove_government_reform = indian_sultanate_reform
	}

	if = {
		limit = {
			has_reform = feudal_theocracy
			NOT = { religion_group = muslim }
			NOT = { religion_group = zoroastrian_group }
		}
		remove_government_reform = feudal_theocracy
	}

	if = {
		limit = {
			government = native
			OR = {
				religion = nahuatl
				religion = mesoamerican_religion
				religion = inti
			}
		}
		change_government = monarchy
		add_government_reform = autocracy_reform
	}


	if = {
		limit = {
			has_heir = yes
		}
		set_heir_religion = ROOT
	}
	if = {
		limit = {
			has_regency = no
		}
		set_ruler_religion = ROOT
	}
	if = {
		limit = {
			has_dlc = "Rights of Man"
			has_consort = yes
		}
		set_consort_religion = ROOT
	}
	if = {
		limit = {
			NOT = { religion = orthodox }
		}
		every_known_country = {
			limit = {
				reverse_has_opinion_modifier = {
					who = ROOT
					modifier = closed_down_the_patriarchate
				}
			}
			reverse_remove_opinion = {
				who = ROOT
				modifier = closed_down_the_patriarchate
			}
		}
	}
	if = {
		limit = {
			religion = catholic
			has_ruler_flag = personal_catholic_sympathies
		}
		country_event = { id = protestantism_events.19 }
	}
	if = {
		limit = {
			religion = protestant
		}
		set_country_flag = converted_to_protestantism
	}
	if = {
		limit = {
			religion = hussite
		}
		remove_country_modifier = hussite_persecution
	}
	if = {
		limit = { has_country_modifier = bav_religious_mandate_mod }
		remove_country_modifier = bav_religious_mandate_mod
	}
	add_country_modifier = {
		name = recently_changed_religion_dummy
		duration = 10
		hidden = yes
	}
	if = {
		limit = {
			NOT = { religion_group = muslim }
			any_owned_province = { has_province_modifier = sufi_shrine }
		}
		every_owned_province = {
			limit = { has_province_modifier = sufi_shrine }
			remove_province_modifier = sufi_shrine
		}
	}
	if = {
		limit = {
			religion = shamanism
			has_country_modifier = son_fetishism_as_secondary_religion
		}
		remove_country_modifier = son_fetishism_as_secondary_religion
		every_owned_province = {
			limit = {
				has_province_modifier = son_fetishism_as_secondary_religion_province
			}
			remove_province_modifier = son_fetishism_as_secondary_religion_province
		}
	}
	if = { 
		limit = { 
			has_country_flag = fra_papal_lap_dop_flag 
		}
		clr_country_flag = fra_papal_lap_dop_flag 
		set_country_flag = fra_chose_to_piss_off_pope_flag
		swap_non_generic_missions = yes 
		remove_country_modifier = fra_catholic_head_of_state_modifier 
		remove_country_modifier = fra_fervent_call_to_arms_modifier 
		clr_country_flag = enable_holy_orders_flag 
		if = { 
			limit = { 
				KOJ = { is_subject_of = ROOT } 
			}
			KOJ = { add_liberty_desire = 25 } 
		}
		remove_country_modifier = fra_sword_of_christianity_modifier
		remove_country_modifier = fra_sword_of_christianity_modifier2
		remove_country_modifier = fra_sword_of_christianity_modifier3
		remove_country_modifier = fra_sword_of_christianity_modifier4
		remove_country_modifier = fra_sword_of_christianity_modifier5
		remove_country_modifier = fra_jerusalem_modifier
	}
	if = {
		limit = { 
			has_government_mechanic = persian_influence_mechanic 
			num_of_subjects = 1
			any_subject_country = {
				is_subject_of_type = cultural_sphere_of_influence_subject
				NOT = { religion = root }
			}
		}
		country_event = {
			id = persian_influence_events.2000
		}
	}
	if = {
		limit = { 
			is_subject = yes 
			is_subject_of_type = cultural_sphere_of_influence_subject 
			overlord = { NOT = { religion = root } }
		}
		country_event = {
			id = persian_influence_events.1000
		}
	}
}

#Country effect
judaism_on_religion_change_effect = {
	every_owned_province = {
		limit = {
			OR = {
				has_province_modifier = judaism_abrahamic_roots
				has_province_modifier = judaism_community_same_culture_group
				has_province_modifier = judaism_community_wrong_culture
			}
		}
		remove_province_modifier = judaism_abrahamic_roots
		remove_province_modifier = judaism_community_same_culture_group
		remove_province_modifier = judaism_community_wrong_culture
	}
}

#on_culture_demoted_effect_free_slot_removal = {
#	if = { 
#		limit = { 
#			has_country_modifier = free_slot_for_$culture$ 
#			NOT = { accepted_culture = $culture$ } 
#			NOT = { primary_culture = $culture$ } 
#		} 
#		remove_country_modifier = free_slot_for_$culture$ 
#	}
#}
#
#on_culture_demoted_effect_remove_all_free_slots = {
#	on_culture_demoted_effect_free_slot_removal = { culture = armenian }
#	on_culture_demoted_effect_free_slot_removal = { culture = georgian }
#	on_culture_demoted_effect_free_slot_removal = { culture = turkish }
#	on_culture_demoted_effect_free_slot_removal = { culture = al_iraqiya_arabic }
#	on_culture_demoted_effect_free_slot_removal = { culture = al_suryah_arabic }
#	on_culture_demoted_effect_free_slot_removal = { culture = occitain }
#}

#Country effect
on_culture_demoted_effect = {
	#if = {
	#	limit = {
	#		has_country_flag = boh_czechoslovak_brotherhood_flag
	#		NOT = {
	#			accepted_culture = slovak
	#		}
	#		has_country_modifier = boh_czechoslovak_brotherhood
	#	}
	#	remove_country_modifier = boh_czechoslovak_brotherhood
	#}
	#if = {
	#	limit = {
	#		has_country_flag = hun_polish_culture_bonus
	#		NOT = {
	#			accepted_culture = polish
	#		}
	#		has_country_modifier = hun_polish_brotherhood
	#	}
	#	remove_country_modifier = hun_polish_brotherhood
	#}
	#if = {
	#	limit = {
	#		has_country_modifier = plc_polish_lithuanian_union
	#		OR = {
	#			AND = {
	#				primary_culture = polish
	#				NOT = { accepted_culture = lithuanian }
	#			}
	#			AND = {
	#				primary_culture = lithuanian
	#				NOT = { accepted_culture = polish }
	#			}
	#			AND = {
	#				OR = {
	#					NOT = { accepted_culture = lithuanian }
	#					NOT = { accepted_culture = polish }
	#				}
	#				NOT = { primary_culture = polish }
	#				NOT = { primary_culture = lithuanian }
	#			}
	#		}
	#	}
	#	remove_country_modifier = plc_polish_lithuanian_union
	#}
	#if = {
	#	limit = {
	#		has_country_modifier = teu_pru_integration_of_the_poles
	#		NOT = { accepted_culture = polish }
	#		NOT = { primary_culture = polish }
	#	}
	#	remove_country_modifier = teu_pru_integration_of_the_poles
	#}
	#if = {
	#	limit = {
	#		has_country_modifier = teu_pru_integration_of_the_ruthenians
	#		NOT = { accepted_culture = polish }
	#		NOT = { primary_culture = polish }
	#	}
	#	remove_country_modifier = teu_pru_integration_of_the_ruthenians
	#}
	if = {
		limit = {
			has_country_modifier = tur_legitimate_roman_empire_modifier
			OR = {
				NOT = { accepted_culture = lombard }
				NOT = { accepted_culture = tuscan }
				NOT = { accepted_culture = sardinian }
				NOT = { accepted_culture = romagnan }
				NOT = { accepted_culture = ligurian }
				NOT = { accepted_culture = venetian }
				NOT = { accepted_culture = dalmatian }
				NOT = { accepted_culture = neapolitan }
				NOT = { accepted_culture = piedmontese }
				NOT = { accepted_culture = umbrian }
				NOT = { accepted_culture = sicilian }
				NOT = { accepted_culture = maltese }
			}
		}
		remove_country_modifier = tur_legitimate_roman_empire_modifier
		remove_accepted_culture = lombard
		remove_accepted_culture = tuscan
		remove_accepted_culture = sardinian
		remove_accepted_culture = romagnan
		remove_accepted_culture = ligurian
		remove_accepted_culture = venetian
		remove_accepted_culture = dalmatian
		remove_accepted_culture = neapolitan
		remove_accepted_culture = piedmontese
		remove_accepted_culture = umbrian
		remove_accepted_culture = sicilian
		remove_accepted_culture = maltese
	}
	if = {
		limit = {
			has_country_modifier = tur_turkish_andalusian_relations_gra
			NOT = { accepted_culture = turkish }
		}
		remove_country_modifier = tur_turkish_andalusian_relations_gra
	}
	if = {
		limit = {
			has_country_modifier = tur_turkish_andalusian_relations_tur
			NOT = { accepted_culture = andalucian }
		}
		remove_country_modifier = tur_turkish_andalusian_relations_tur
	}
	if = {
		limit = {
			has_country_modifier = rus_west_slavic_union
			OR = {
				NOT = { accepted_culture = czech }
				NOT = { accepted_culture = sorbian }
				NOT = { accepted_culture = schlesian }
				NOT = { accepted_culture = polish }
				NOT = { accepted_culture = slovak }
			}
		}
		remove_country_modifier = rus_west_slavic_union
	}
	if = {
		limit = {
			has_country_modifier = rus_carpathian_union
			OR = {
				NOT = { accepted_culture = hungarian }
				NOT = { accepted_culture = romanian }
				NOT = { accepted_culture = transylvanian }
			}
		}
		remove_country_modifier = rus_carpathian_union
	}
	if = {
		limit = {
			has_country_modifier = rus_south_slavic_union
			OR = {
				NOT = { accepted_culture = bulgarian }
				NOT = { accepted_culture = serbian }
				NOT = { accepted_culture = bosnian }
				NOT = { accepted_culture = slovene }
				NOT = { accepted_culture = albanian }
				NOT = { accepted_culture = croatian }
			}
		}
		remove_country_modifier = rus_south_slavic_union
	}
	if = {
		limit = {
			has_country_modifier = gbr_unified_british_isles_culture
			OR = {
				NOT = { accepted_culture = irish }
				NOT = { accepted_culture = highland_scottish }
			}
		}
		remove_country_modifier = gbr_unified_british_isles_culture
	}
	if = {
		limit = {
			has_country_modifier = gbr_accepted_lowlands
			OR = {
				NOT = { accepted_culture = dutch }
				NOT = { accepted_culture = flemish }
			}
		}
		remove_country_modifier = gbr_accepted_lowlands
	}
	if = {
		limit = {
			has_country_modifier = BYZ_no_slot_bulgarian
			NOT = { accepted_culture = bulgarian }
			NOT = { primary_culture = bulgarian }
		}
		remove_country_modifier = BYZ_no_slot_bulgarian
	}
	if = {
		limit = {
			has_country_modifier = geo_armenian_union
			NOT = { accepted_culture = armenian }
		}
		remove_country_modifier = geo_armenian_union
	}
	if = {
		limit = {
			has_country_modifier = turkmen_turkic_union
			NOT = { accepted_culture = turkish }
		}
		remove_country_modifier = turkmen_turkic_union
	}
	if = {
		limit = {
			has_country_modifier = feo_russian_tolerance
			NOT = {
				accepted_culture = russian
				accepted_culture = novgorodian
				accepted_culture = ryazanian
				accepted_culture = byelorussian
				accepted_culture = ruthenian
			}
		}
		remove_country_modifier = feo_russian_tolerance
	}
	if = {
		limit = {
			has_government_attribute = negate_unaccepted_levantine_culture
		}
		every_owned_province = {
			limit = {
				culture_group = turko_semitic
				has_owner_accepted_culture = no
				NOT = { has_province_modifier = hsn_ayyubid_tolerance }
			}
			add_province_modifier = {
				name = hsn_ayyubid_tolerance
				duration = -1
			}
		}
	}
}

#Country effect
judaism_on_culture_country_effect = {
	if = {
		limit = {
			has_church_aspect = judaism_communities_aspect
		}
		every_owned_province = {
			remove_province_modifier = judaism_community_wrong_culture
			remove_province_modifier = judaism_community_same_culture_group
		}
		every_owned_province = {
			limit = {
				religion = jewish
			}
			if = {
				limit = {
					NOT = { culture_group = ROOT }
					has_owner_accepted_culture = no
					has_owner_culture = no
				}
				add_province_modifier = {
					name = judaism_community_wrong_culture
					duration = -1
				}
			}
			else_if = {
				limit = {
					owner = {
						has_cultural_union = no
					}
					culture_group = ROOT
					has_owner_accepted_culture = no
				}
				add_province_modifier = {
					name = judaism_community_same_culture_group
					duration = -1
				}
			}
		}
	}
	if = {
        limit = {
            has_government_attribute = negate_unaccepted_levantine_culture
        }
        every_owned_province = {
            limit = {
                culture_group = turko_semitic
                has_owner_accepted_culture = yes
                has_province_modifier = hsn_ayyubid_tolerance
            }
            remove_province_modifier = hsn_ayyubid_tolerance
        }
    }
}

#Province effect
imperial_modifiers_on_province_change_culture_or_change_owner_effect = {
	if = {
		limit = {
			NOT = { has_province_modifier = kon_south_african_hegemony_province }
			owner = {
				has_country_modifier = kon_south_african_hegemony
			}
			has_owner_accepted_culture = no
			OR = {
				culture_group = southern_african
				culture_group = african
				culture_group = great_lakes_group
			}
		}
		add_province_modifier = {
			name = kon_south_african_hegemony_province
			duration = -1
		}
	}
	else_if = {
		limit = {
			has_province_modifier = kon_south_african_hegemony_province
		}
		remove_province_modifier = kon_south_african_hegemony_province
	}
	if = {
		limit = {
			NOT = { has_province_modifier = nor_scandinavian_empire_local }
			owner = {
				has_country_modifier = nor_scandinavian_empire
			}
			culture_group = scandinavian
		}
		add_province_modifier = {
			name = nor_scandinavian_empire_local
			duration = -1
		}
	}
	else_if = {
		limit = {
			has_province_modifier = nor_scandinavian_empire_local
		}
		remove_province_modifier = nor_scandinavian_empire_local
	}
	if = {
		limit = {
			NOT = { has_province_modifier = sca_hegemony_over_germany_province }
			culture_group = germanic
			owner = {
				has_country_modifier = sca_hegemony_over_germany
				NOT = { culture_group = PREV }
				NOT = { primary_culture = PREV }
			}
			has_owner_accepted_culture = no
		}
		add_province_modifier = {
			name = sca_hegemony_over_germany_province
			duration = -1
		}
	}
	else_if = {
		limit = {
			NOT = { has_province_modifier = sca_hegemony_over_germany_province_same_culture }
			culture_group = germanic
			owner = {
				has_country_modifier = sca_hegemony_over_germany
				culture_group = PREV
				NOT = { primary_culture = PREV }
			}
			has_owner_accepted_culture = no
		}
		add_province_modifier = {
			name = sca_hegemony_over_germany_province_same_culture
			duration = -1
		}
	}
	else_if = {
		limit = {
			OR = {
				has_province_modifier = sca_hegemony_over_germany_province
				has_province_modifier = sca_hegemony_over_germany_province_same_culture
			}
		}
		remove_province_modifier = sca_hegemony_over_germany_province
		remove_province_modifier = sca_hegemony_over_germany_province_same_culture
	}
}

#Country effect
imperial_modifiers_on_culture_country_effect = {
	if = {
		limit = {
			any_owned_province = {
				OR = {
					has_province_modifier = kon_south_african_hegemony_province
					has_province_modifier = nor_scandinavian_empire_local
					has_province_modifier = sca_hegemony_over_germany_province
					has_province_modifier = sca_hegemony_over_germany_province_same_culture
				}
			}
		}
		every_owned_province = {
			remove_province_modifier = kon_south_african_hegemony_province
			remove_province_modifier = nor_scandinavian_empire_local
			remove_province_modifier = sca_hegemony_over_germany_province
			remove_province_modifier = sca_hegemony_over_germany_province_same_culture
		}
	}
	if = {
		limit = {
			has_country_modifier = kon_south_african_hegemony
		}
		every_owned_province = {
			limit = {
				OR = {
					culture_group = southern_african
					culture_group = african
					culture_group = great_lakes_group
				}
				NOT = { has_province_modifier = kon_south_african_hegemony_province }
				has_owner_accepted_culture = no
			}
			add_province_modifier = {
				name = kon_south_african_hegemony_province
				duration = -1
			}
		}
	}
	if = {
		limit = {
			has_country_modifier = sca_hegemony_over_germany
		}
		every_owned_province = {
			limit = {
				culture_group = germanic
				NOT = { has_province_modifier = sca_hegemony_over_germany_province }
				has_owner_accepted_culture = no
				owner = {
					NOT = { primary_culture = PREV }
					NOT = { culture_group = PREV }
				}
			}
			add_province_modifier = {
				name = sca_hegemony_over_germany_province
				duration = -1
			}
		}
		every_owned_province = {
			limit = {
				culture_group = germanic
				NOT = { has_province_modifier = sca_hegemony_over_germany_province_same_culture }
				has_owner_accepted_culture = no
				owner = {
					NOT = { primary_culture = PREV }
					culture_group = PREV
				}
			}
			add_province_modifier = {
				name = sca_hegemony_over_germany_province_same_culture
				duration = -1
			}
		}
	}
	if = {
		limit = {
			has_country_modifier = nor_scandinavian_empire
		}
		every_owned_province = {
			limit = {
				culture_group = scandinavian
				NOT = { has_province_modifier = nor_scandinavian_empire_local }
			}
			add_province_modifier = {
				name = nor_scandinavian_empire_local
				duration = -1
			}
		}
	}
}

#Country effect
imperial_modifiers_on_primary_culture_change_effect = {
	if = {
		limit = {
			has_country_modifier = kon_south_african_hegemony
			NOT = { culture_group = kongo_group }
		}
		remove_country_modifier = kon_south_african_hegemony
		every_owned_province = {
			limit = {
				has_province_modifier = kon_south_african_hegemony_province
			}
			remove_province_modifier = kon_south_african_hegemony_province
		}
	}
	every_owned_province = {
		remove_province_modifier = sca_hegemony_over_germany_province
		remove_province_modifier = sca_hegemony_over_germany_province_same_culture
	}
	if = {
		limit = {
			has_country_modifier = sca_hegemony_over_germany
		}
		every_owned_province = {
			limit = {
				culture_group = germanic
				NOT = { has_province_modifier = sca_hegemony_over_germany_province }
				has_owner_accepted_culture = no
				owner = {
					NOT = { primary_culture = PREV }
					NOT = { culture_group = PREV }
				}
			}
			add_province_modifier = {
				name = sca_hegemony_over_germany_province
				duration = -1
			}
		}
		every_owned_province = {
			limit = {
				culture_group = germanic
				NOT = { has_province_modifier = sca_hegemony_over_germany_province_same_culture }
				has_owner_accepted_culture = no
				owner = {
					NOT = { primary_culture = PREV }
					culture_group = PREV
				}
			}
			add_province_modifier = {
				name = sca_hegemony_over_germany_province_same_culture
				duration = -1
			}
		}
	}
	if = {
		limit = {
			has_country_modifier = nor_scandinavian_empire
			NOT = { culture_group = scandinavian }
		}
		remove_country_modifier = nor_scandinavian_empire
		every_owned_province = {
			limit = {
				has_province_modifier = nor_scandinavian_empire_local
			}
			remove_province_modifier = nor_scandinavian_empire_local
		}
	}
}

on_war_declaration_effect = {
	if = {
		limit = { has_country_modifier = janissary_policemen }
		remove_country_modifier = janissary_policemen
	}
	if = {
		limit = { has_country_modifier = janissary_fireighters }
		remove_country_modifier = janissary_fireighters
	}
	if = {
		limit = { has_country_modifier = janissary_palace_guardians }
		remove_country_modifier = janissary_palace_guardians
	}
	random_list = {
		1 = {
			country_event = {
				id = new_court_flavour_events.21
			}
		}
		9 = {}
	}
}

remove_all_age_of_discovery_modifiers = {
	if = {
		limit = {
			NOT = { current_age = age_of_discovery }
		}
		if = {
			limit = { has_country_modifier = eng_a_house_united }
			remove_country_modifier = eng_a_house_united
		}
		if = {
			limit = { has_country_modifier = eng_jousting_tournaments }
			remove_country_modifier = eng_jousting_tournaments
		}
		if = {
			limit = { has_country_modifier = YEM_rise_of_yemen }
			remove_country_modifier = YEM_rise_of_yemen
		}
		if = {
			limit = { has_country_modifier = INC_bowmen_from_the_jungle }
			remove_country_modifier = INC_bowmen_from_the_jungle
		}
		if = {
			limit = { has_country_modifier = MAY_religion_reformed }
			remove_country_modifier = MAY_religion_reformed
		}
		if = {
			limit = { has_country_modifier = MAY_mayan_canoes }
			remove_country_modifier = MAY_mayan_canoes
		}
		if = {
			limit = { has_country_modifier = MUG_gunpowder_pioneers }
			remove_country_modifier = MUG_gunpowder_pioneers
		}
		if = {
			limit = { has_country_modifier = MUG_heir_of_timur }
			remove_country_modifier = MUG_heir_of_timur
		}
		if = {
			limit = { has_country_modifier = TIM_timurid_empire_modifier }
			remove_country_modifier = TIM_timurid_empire_modifier
		}
		if = {
			limit = { has_country_modifier = hab_onwards_for_glory }
			remove_country_modifier = hab_onwards_for_glory
		}
	}
}
remove_all_age_of_reformation_modifiers = {
	if = {
		limit = {
			NOT = { current_age = age_of_reformation }
		}
		if = {
			limit = { has_country_modifier = eng_the_age_of_reformation }
			remove_country_modifier = eng_the_age_of_reformation
		}
		if = {
			limit = { has_country_modifier = eng_reformer_ruler }
			remove_country_modifier = eng_reformer_ruler
		}
		if = {
			limit = { has_country_modifier = eng_catholic_ruler }
			remove_country_modifier = eng_catholic_ruler
		}
		if = {
			limit = { has_country_modifier = eng_tolerant_ruler }
			remove_country_modifier = eng_tolerant_ruler
		}
		if = {
			limit = { has_country_modifier = eng_reformer_ruler_for_catholic_gb }
			remove_country_modifier = eng_reformer_ruler_for_catholic_gb
		}
		if = {
			limit = { has_country_modifier = eng_catholic_ruler_for_reformed_gb }
			remove_country_modifier = eng_catholic_ruler_for_reformed_gb
		}
		if = {
			limit = { has_country_modifier = BYZ_ceasarean_conquests }
			remove_country_modifier = BYZ_ceasarean_conquests
		}
		if = {
			limit = { has_country_modifier = BYZ_economic_intimidation }
			remove_country_modifier = BYZ_economic_intimidation
		}
		if = {
			limit = { has_country_modifier = BYZ_roman_vigour }
			remove_country_modifier = BYZ_roman_vigour
		}
		if = {
			limit = { has_country_modifier = ITA_latin_tiara }
			remove_country_modifier = ITA_latin_tiara
		}
		if = {
			limit = { has_country_modifier = ITA_triumph_for_hispaniae }
			remove_country_modifier = ITA_triumph_for_hispaniae
		}
		if = {
			limit = { has_country_modifier = ITA_new_renaissance }
			remove_country_modifier = ITA_new_renaissance
		}
		if = {
			limit = { has_country_modifier = ITA_diplomatic_revolution }
			remove_country_modifier = ITA_diplomatic_revolution
			add_country_modifier = {
				name = ITA_diplomatic_revolution_weaker
				duration = -1
			}
		}
		if = {
			limit = { has_country_modifier = MUG_industrial_powerhouse }
			remove_country_modifier = MUG_industrial_powerhouse
		}
		if = {
			limit = { has_country_modifier = MUG_gunpowder_mastery }
			remove_country_modifier = MUG_gunpowder_mastery
		}
		if = {
			limit = { has_country_modifier = TIM_golden_horde }
			remove_country_modifier = TIM_golden_horde
		}
		if = {
			limit = { has_country_modifier = TIM_persian_economic_hegemon }
			remove_country_modifier = TIM_persian_economic_hegemon
		}
		if = {
			limit = { has_country_modifier = hordes_fall_of_china }
			remove_country_modifier = hordes_fall_of_china
		}
		if = {
            limit = { has_country_modifier = ITA_new_renaissance_non_dlc }
            remove_country_modifier = ITA_new_renaissance_non_dlc
        }
	}
}
remove_all_age_of_absolutism_modifiers = {
	if = {
		limit = {
			NOT = { current_age = age_of_absolutism }
		}
		if = {
			limit = { has_country_modifier = ITA_conquest_of_britain }
			remove_country_modifier = ITA_conquest_of_britain
		}
	}
	if = {
		limit = {
			NOT = { current_age = age_of_absolutism }
		}
		if = {
			limit = { has_country_modifier = GER_economic_influence }
			remove_country_modifier = GER_economic_influence
		}
	}
}
remove_all_age_of_revolution_modifiers = {
	#if = {
	#	limit = {
	#		NOT = { current_age = age_of_revolutions }
	#	}
	#}
	#Empty as there are no modifiers specific for this age
}

set_age_passed_global_flag = {
	if = {
		limit = {
			not = { current_age = age_of_discovery }
			or = {
				current_age = age_of_reformation
				current_age = age_of_absolutism
				current_age = age_of_revolutions
			}
		}
		set_global_flag = age_of_discovery_passed
	}
	if = {
		limit = {
			has_global_flag = age_of_discovery_passed
			not = { current_age = age_of_reformation }
			or = {
				current_age = age_of_absolutism
				current_age = age_of_revolutions
			}
		}
		set_global_flag = age_of_reformation_passed
	}
	if = {
		limit = {
			has_global_flag = age_of_discovery_passed
			has_global_flag = age_of_reformation_passed
			not = { current_age = age_of_absolutism }
			current_age = age_of_revolutions
		}
		set_global_flag = age_of_absolutism_passed
	}
	if = {
		limit = {
			has_global_flag = age_of_discovery_passed
			has_global_flag = age_of_reformation_passed
			has_global_flag = age_of_absolutism_passed
			not = { current_age = age_of_revolutions }
		}
		set_global_flag = age_of_revolutions_passed
	}
}

remove_all_age_timed_modifiers = {
	remove_all_age_of_discovery_modifiers = yes
	remove_all_age_of_reformation_modifiers = yes
	remove_all_age_of_absolutism_modifiers = yes
	remove_all_age_of_revolution_modifiers = yes
	# Generic ones
	if = { 
		limit = { has_country_modifier = jap_stability_edo_period_modifier }
		remove_country_modifier = jap_stability_edo_period_modifier 
	}
}

add_country_modifier_for_age = {
	if = {
		limit = {
			NOT = { has_global_flag = $age$_passed }
		}
		add_country_modifier = {
			name = $name$
			duration = -1
			desc = until_end_of_$age$_desc
		}
	}
	[[else]
		else = {
			$else$
		}
	]
}

on_parliament_abolished_effect = {
	custom_tooltip = on_parliament_abolished_effect_tt
	hidden_effect = {

	}
}

set_parliament_action_flag = {
	hidden_effect = {
		set_country_flag = $parliament_action$_flag
	}
}

on_harmonized_effect = {
	if = {
		limit = {
			has_government_attribute = full_loyalty_on_harmonization
		}
		add_estate_loyalty = {
			estate = estate_church
			loyalty = 100
		}
		add_adm_power = 50
	}
}

on_primary_culture_changed_effect = {
	if = {
		limit = { has_government_attribute = can_recruit_banners_from_primary_culture_provinces }
		every_owned_province = {
			if = {
				limit = {
					has_province_modifier = mongol_banners_location
					has_owner_culture = no
				}
				remove_province_modifier = mongol_banners_location
			}
			if = {
				limit = { has_owner_culture = yes }
				add_province_modifier = { name = mongol_banners_location duration = -1 hidden = yes }
			}
		}
	}
}

on_province_culture_change_effect = {
	if = {
		limit = { has_province_modifier = tur_competent_pashas }
		remove_province_modifier = tur_competent_pashas		
	}
	if = {
		limit = { has_province_modifier = the_provincial_system }
		remove_province_modifier = the_provincial_system
	}
	if = {
		limit = {
			owner = {
				has_country_flag = tur_improved_pashas
			}
		}
		area = {
			limit = { owned_by = owner NOT = { culture_group = owner } }
			add_province_modifier = { name = tur_competent_pashas duration = -1 hidden = yes }
		}
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = pasha_extra_bonuses
			}
		}
		area = {
			limit = { owned_by = owner NOT = { culture_group = owner } }
			add_province_modifier = { name = the_provincial_system duration = -1 hidden = yes }
		}
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = negate_unaccepted_levantine_culture
			}
		}
		if = {
			limit = {
				culture_group = turko_semitic
				NOT = { has_owner_accepted_culture = yes }
				NOT = { has_province_modifier = hsn_ayyubid_tolerance }
			}
			add_province_modifier = {
				name = hsn_ayyubid_tolerance
				duration = -1
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { culture_group = turko_semitic }
					has_owner_accepted_culture = yes
				}
				has_province_modifier = hsn_ayyubid_tolerance
			}
			remove_province_modifier = hsn_ayyubid_tolerance
		}
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = increase_nobles_loyalty_per_culture_conversion
			}
		}
		owner = {
			add_estate_loyalty = {
				estate = all
				loyalty = 1
			}
		}
	}
	if = {
		limit = {
			has_owner_culture = yes
			owner = { has_government_attribute = can_recruit_banners_from_primary_culture_provinces }
		}
		add_province_modifier = { name = mongol_banners_location duration = -1 hidden = yes }
	}
	else_if = {
		limit = { has_province_modifier = mongol_banners_location }
		remove_province_modifier = mongol_banners_location
	}
}

on_province_culture_converted_effect = {
	owner = {
		change_variable = {
			which = num_converted_culture
			value = 1
		}
	}
	if = {
		limit = { has_owner_culture = yes }
		owner = {
			change_variable = {
				which = num_converted_to_own_culture
				value = 1
			}
		}
	}
	if = {
		limit = {
			owner = {
				has_country_flag = arm_coversion_bonus
			}
			has_owner_culture = yes
			NOT = {
				has_province_flag = arm_converted_bonus
			}
		}
		add_base_tax = 1
		add_base_manpower = 1
		add_base_production = 1
		set_province_flag = arm_converted_bonus
	}
}

on_colony_finished_effect = {
	if = {
		limit = {
			owner = {
				OR = {
					has_country_modifier = colonial_venture_act_modifier
					has_country_flag = can_select_trade_goods_for_colonies
					has_government_attribute = selectable_trade_goods_for_colonies
				}
				NOT = { has_country_flag = eng_disabled_colonial_ventures }
			}
			NOT = { has_province_flag = had_trade_good_change_event }
		}
		set_province_flag = had_trade_good_change_event
		province_event = {
			id = flavor_gbr.200
		}
	}
}

on_colonist_boosting_colony_effect = {
	hidden_effect = {
		if = {
			limit = {
				OR = {
					religion = noreligion
					#test if colonists outnumber natives
					variable_arithmetic_trigger = {
						custom_tooltip = colonysize_is_larger_than_nativesize_tt
						export_to_variable = {
							which = vab_colonysize
							value = trigger_value:colonysize
						}
						export_to_variable = {
							which = vab_nativesize
							value = trigger_value:native_size
						}
						multiply_variable = {
							which = vab_nativesize
							value = 100
						}
						check_variable = {
							which = vab_colonysize
							which = vab_nativesize
						}
					}
					is_in_capital_area = yes
					continent = north_america
					continent = south_america
					continent = new_world
					NOT = {
						OR = {
							has_dlc = "Dharma"
							has_dlc = "Wealth of Nations"
						}
					}
				}
			}
			change_religion = FROM
		}
		if = {
			limit = {
				OR = {
					culture = noculture
					#test if colonists outnumber natives
					variable_arithmetic_trigger = {
						custom_tooltip = colonysize_is_larger_than_nativesize_tt
						export_to_variable = {
							which = vab_colonysize
							value = trigger_value:colonysize
						}
						export_to_variable = {
							which = vab_nativesize
							value = trigger_value:native_size
						}
						multiply_variable = {
							which = vab_nativesize
							value = 100
						}
						check_variable = {
							which = vab_colonysize
							which = vab_nativesize
						}
					}
					is_in_capital_area = yes
					continent = north_america
					continent = south_america
					continent = new_world
					NOT = {
						OR = {
							has_dlc = "Dharma"
							has_dlc = "Wealth of Nations"
						}
					}
				}
			}
			change_culture = FROM
			change_original_culture = FROM
		}
	}
}

on_alliance_broken_effect = {
	if = {
		limit = { has_country_modifier = mng_trade_access_in_china_modifier }
		remove_country_modifier = mng_trade_access_in_china_modifier
	}
	if = {
		limit = { has_country_modifier = rus_russian_caucasian_alliance FROM = { has_country_modifier = rus_russian_caucasian_alliance } }
		remove_country_modifier = rus_russian_caucasian_alliance
		FROM = { remove_country_modifier = rus_russian_caucasian_alliance }
	}
	if = {
		limit = { has_country_modifier = gbr_english_dutch_trade_partners FROM = { has_country_modifier = gbr_english_dutch_trade_partners } }
		remove_country_modifier = gbr_english_dutch_trade_partners
		FROM = { remove_country_modifier = gbr_english_dutch_trade_partners }
	}
	if = {
		limit = {
			has_saved_global_event_target = tur_ottoman_trade_partner
			OR = {
				tag = event_target:tur_ottoman_trade_partner
				FROM = { tag = event_target:tur_ottoman_trade_partner }
			}
		}
		if = {
			limit = { tag = event_target:tur_ottoman_trade_partner }
			if = {
				limit = { has_country_modifier = tur_ottoman_venetian_trade_deal_modifier }
				remove_country_modifier = tur_ottoman_venetian_trade_deal_modifier
			}
			every_owned_province = {
				limit = { has_province_modifier = tur_ottoman_venetian_trade_deal_modifier_prov }
				remove_province_modifier = tur_ottoman_venetian_trade_deal_modifier_prov
			}
		}
		FROM = {
			if = {
				limit = { tag = event_target:tur_ottoman_trade_partner }
				if = {
					limit = { has_country_modifier = tur_ottoman_venetian_trade_deal_modifier }
					remove_country_modifier = tur_ottoman_venetian_trade_deal_modifier
				}
				every_owned_province = {
					limit = { has_province_modifier = tur_ottoman_venetian_trade_deal_modifier_prov }
					remove_province_modifier = tur_ottoman_venetian_trade_deal_modifier_prov
				}
			}
		}
		clear_global_event_target = tur_ottoman_trade_partner
	}
	FROM = {
		if = {
			limit = { has_country_modifier = mng_trade_access_in_china_modifier }
			remove_country_modifier = mng_trade_access_in_china_modifier
		}
	}
	change_asha_vahishta = { value = -5 }
	if = {
		limit = { 
			has_country_modifier = mam_ven_cooperation_modifier
			NOT = { alliance_with = VEN }
		}
		remove_country_modifier = mam_ven_cooperation_modifier
	}
	FROM = {
		if = {
			limit = { 
				has_country_modifier = mam_ven_cooperation_modifier
				NOT = { alliance_with = VEN }
			}
			remove_country_modifier = mam_ven_cooperation_modifier
		}
	}
}

on_adm_development_effect = {
	if = {
        limit = { owner = { has_country_modifier = tre_revitalization } }
        add_local_autonomy = -5
    }
	if = { 
		limit = { owner = { has_government_attribute = developing_manufactories_extra_dev_chance } has_manufactory_trigger = yes }
		random_list = { 10 = { add_base_tax = 1 } 90 = { } }
	}
	if = {
		limit = { owner = { has_country_flag = hun_bonus_dev_budapest } province_id = 153 }
		random_list = { 20 = { add_base_tax = 1 }  80 = {  }  }
	}
	if = {
		limit = { owner = { has_country_flag = enable_supplemental_development_flag } }
		random_list = { 20 = { add_base_tax = 1 } 80 = { } }
	}
	if = {
		limit = { owner = { has_country_modifier = lit_increased_dev_modifier } }
		add_base_tax = 1 
	}
	if = { 
		limit = { has_state_edict = chinese_industrialization } 
		random_list = {
			10 = { add_base_tax = 1 } 
			10 = { add_prosperity = 1 } 
			10 = { add_province_modifier = { name = qng_center_of_industrialization_modifier duration = 3650 } }
			70 = {  } 
		}
	}
	if = {
		limit = { owner = { has_country_modifier = JAP_cadastral_surveys has_dlc = "Domination" } }
		owner = { change_estate_land_share = { estate = all share = -0.2 } }
	}
	if = {
		limit = { owner = { has_country_modifier = jap_20_years_devving_tax_yields_twice_bonus_1_burgher_loyalt_modifier } }
		add_base_tax = 1 
		owner = { add_estate_loyalty = { estate = estate_burghers loyalty = 1 } }
	}
	if = {
		limit = { religion = ROOT owner = { has_country_flag = geo_orthodox_dev } }
		random_list = { 10 = { add_base_tax = 1 } 90 = { } }
	}
	if = {
		limit = { OR = { trade_goods = cloth trade_goods = silk } owner = { has_country_modifier = turkoman_expanding_industry } }
		random_list = { 20 = { add_base_tax = 1 } 80 = {  } }
	}
}
on_dip_development_effect = {
	if = {
        limit = { owner = { has_country_modifier = tre_revitalization } }
        add_local_autonomy = -5
    }
	if = { 
		limit = { owner = { has_country_modifier = boh_early_industrialization } has_production_building_trigger = yes }
		random_list = { 20 = { add_base_production = 1 } 80 = { } }
	}
	if = { 
		limit = { owner = { has_government_attribute = developing_manufactories_extra_dev_chance } has_manufactory_trigger = yes }
		random_list = { 10 = { add_base_production = 1 } 90 = { } }
	}
	if = {
		limit = { owner = { has_country_flag = hun_bonus_dev_budapest } province_id = 153 }
		random_list = { 20 = { add_base_production = 1 }  80 = {  }  }
	}
	if = {
		limit = { owner = { has_country_flag = enable_supplemental_development_flag } }
		random_list = { 20 = { add_base_production = 1 } 80 = { } }
	}
	if = {
		limit = { owner = { has_country_modifier = lit_increased_dev_modifier } }
		add_base_production = 1 
	}
	if = { 
		limit = { has_state_edict = chinese_industrialization } 
		random_list = {
			10 = { add_base_production = 1 } 
			10 = { add_prosperity = 1 } 
			10 = { add_province_modifier = { name = qng_center_of_industrialization_modifier duration = 3650 } }
			70 = {  } 
		}
	}
	if = {
		limit = { religion = ROOT owner = { has_country_flag = geo_orthodox_dev } }
		random_list = { 10 = { add_base_production = 1 } 90 = { } }
	}
	if = {
		limit = { OR = { trade_goods = cloth trade_goods = silk } owner = { has_country_modifier = turkoman_expanding_industry } }
		random_list = { 20 = { add_base_production = 1 } 80 = {  } }
	}
}
on_mil_development_effect = {
	if = {
        limit = { owner = { has_country_modifier = tre_revitalization } }
        add_local_autonomy = -5
    }
	if = { 
		limit = {  owner = { has_government_attribute = developing_manufactories_extra_dev_chance } has_manufactory_trigger = yes }
		random_list = { 10 = { add_base_manpower = 1 } 90 = { } }
	}
	if = {
		limit = { owner = { has_country_flag = hun_bonus_dev_budapest } province_id = 153 }
		random_list = { 20 = { add_base_manpower = 1 }  80 = {  }  }
	}
	if = {
		limit = { owner = { has_country_flag = enable_supplemental_development_flag } }
		random_list = { 20 = { add_base_manpower = 1 } 80 = { } }
	}
	if = {
		limit = { owner = { has_country_modifier = lit_increased_dev_modifier } }
		add_base_manpower = 1 
	}
	if = { 
		limit = { has_state_edict = chinese_industrialization } 
		random_list = {
			10 = { add_base_manpower = 1 } 
			10 = { add_prosperity = 1 } 
			10 = { add_province_modifier = { name = qng_center_of_industrialization_modifier duration = 3650 } }
			70 = {  } 
		}
	}
	if = {
		limit = { religion = ROOT owner = { has_country_flag = geo_orthodox_dev } }
		random_list = { 10 = { add_base_manpower = 1 } 90 = { } }
	}
	if = {
		limit = { OR = { trade_goods = cloth trade_goods = silk } owner = { has_country_modifier = turkoman_expanding_industry } }
		random_list = { 20 = { add_base_manpower = 1 } 80 = {  } }
	}
}
on_development_effect = {
	owner = { change_variable = { which = num_of_times_developed value = 1 } }
	if = {
		limit = { owner = { has_mission = ARB_the_harsh_desert } has_climate = arid }
		owner = { change_variable = { which = num_of_times_developed_arid value = 1 } }
	}	
	if = {
		limit = { owner = { is_andean_society_trigger = yes } OR = { has_terrain = mountain has_terrain = highlands has_terrain = hills } }
		owner = { change_variable = { which = num_of_times_developed_mountains value = 1 } }
	}	
	if = {
		limit = { has_terrain = jungle }
		owner = { change_variable = { which = num_of_times_developed_jungles value = 1 } }
	}	
	if = {
		limit = { owner = { has_reform = german_cultural_disunity_reform  } GER_has_matching_culture = yes }
		owner = { add_government_power = { mechanic_type = cultural_unity_mechanic power_type = cultural_unity value = 1.5 } }
	}
	FROM = { change_variable = { which = num_of_times_developed_var value = 1 } }
	if = {
		limit = { owner = { has_country_flag = ned_unlock_dutch_urbanization_flag } region = low_countries_region development = 25 }
		add_province_modifier = { name = ned_dutch_urbanization duration = -1 }
	}
	if = {
		limit = { owner = { has_country_flag = ned_unlock_flemish_urbanization_flag } region = low_countries_region development = 25 }
		add_province_modifier = { name = ned_flemish_urbanization duration = -1 }
	}
	if = {
        limit = {
            owner = { has_estate_privilege = estate_burghers_hungarian_royal_cities }
            NOT = { has_province_modifier = estate_burghers_hungarian_royal_city_modifier }
            development = 20
            region = carpathia_region
            province_has_center_of_trade_of_level = 1
        }
        add_province_modifier = { name = estate_burghers_hungarian_royal_city_modifier duration = -1 }
    }
	if = { 
		limit = { owner = { has_country_modifier = pru_victory_lower_saxony_modifier } OR = { culture = saxon culture = lower_saxon } }
		add_nationalism = -3
		add_local_autonomy = -5
		add_prosperity = 1
	}
	on_$type$_development_effect = yes
}

# THIS = Province, FROM = Country, ROOT = Merc Unit
on_mercenary_recruited_effect = {
	if = {
        limit = {
            FROM = { 
                has_country_flag = hun_no_prof_black_army
            }
            OR = {
                ROOT = { mercenary_company = merc_black_army }
                ROOT = { mercenary_company = merc_black_army_2 }
            }
        }
        FROM = { add_army_professionalism = 0.25 }
    }
	if = {
		limit = {
			FROM = { has_not_free_mercs_trait = yes }
			is_not_free_merc_company = yes
			OR = {
				FROM = { NOT = { has_country_flag = oyo_cavalry_do_not_consume_ap } }
				ROOT = { NOT = { mercenary_company = merc_oyo_cavalry } }
				FROM = { NOT = { has_country_modifier = hsn_turkoman_mercenaries } }
			}
		}
		if = {
			limit = {
				FROM = { 
					OR = {
						has_country_flag = fifty_percent_merc_army_professionalism_cost 
						has_country_modifier = pol_cheap_ap_mercs_modifier
					}
				}
			}
			FROM = { add_army_professionalism = -0.5 }
		}
		else = { 
			FROM = { add_army_professionalism = -1 } 
		}
	}
}

on_parliament_debate_reset_effect = {
	add_country_modifier = {
		name = reset_parliament_debate_modifier
		duration = 3650
	}
	add_corruption = 2
	if = {
		limit = {
			has_government_mechanic = parliament_vs_monarchy_mechanic
		}
		add_government_power = { 
			mechanic_type = parliament_vs_monarchy_mechanic
			power_type = governmental_power
			value = 20
		}
	}
}

on_parliament_seat_given_effect = {
	owner = {
		if = { 
			limit = { has_country_flag = fra_powerful_parliament_flag } 
			change_government_reform_progress = 5
			random_list = {
				1 = { add_adm_power = 10 }
				1 = { add_dip_power = 10 }
				1 = { add_mil_power = 10 }
			}
		}
		if = {
			limit = {
				has_government_mechanic = parliament_vs_monarchy_mechanic
			}
			add_government_power = { 
				mechanic_type = parliament_vs_monarchy_mechanic
				power_type = governmental_power
				value = -5
			}
		}
		if = {
			limit = {
				has_government_attribute = parliament_seat_bonus
			}
			add_estate_loyalty = {
				estate = all
				loyalty = 1
			}
		}
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = parliament_seat_bonus
			}
		}
		add_province_modifier = {
			name = gov_buffed_parliament_seat
			duration = -1
		}
	}
}
on_parliament_seat_lost_effect = {
	owner = {
		if = {
			limit = {
				has_government_mechanic = parliament_vs_monarchy_mechanic
			}
			add_government_power = { 
				mechanic_type = parliament_vs_monarchy_mechanic
				power_type = governmental_power
				value = 5
			}
		}
	}
	if = {
		limit = {
			has_province_modifier = gov_buffed_parliament_seat
		}
		remove_province_modifier = gov_buffed_parliament_seat
	}
}
on_parliament_debate_failed_effect = {
	if = {
		limit = {
			has_government_mechanic = parliament_vs_monarchy_mechanic
		}
		add_government_power = { 
			mechanic_type = parliament_vs_monarchy_mechanic
			power_type = governmental_power
			value = 33
		}
	}
}
on_parliament_debate_succeeded_effect = {
	if = {
		limit = {
			has_government_mechanic = parliament_vs_monarchy_mechanic
		}
		add_government_power = { 
			mechanic_type = parliament_vs_monarchy_mechanic
			power_type = governmental_power
			value = -20
		}
	}
	if = {
		limit = { has_government_attribute = gain_rt_from_parliament }
		add_republican_tradition = 5
	}
}

on_main_war_won_effect = {
	if = {
		limit = {
			has_country_modifier = hun_avenge_varna
			FROM = { tag = TUR }
		}
		remove_country_modifier = hun_avenge_varna
	}
	if = {
		limit = {
			has_government_attribute = winning_wars_gives_rt
		}
		add_republican_tradition = 5
	}
	if = {
		limit = {
			has_government_attribute = winning_war_increases_legitimacy
		}
		add_legitimacy = 5
		add_devotion = 5
		add_meritocracy = 5
		add_horde_unity = 5
		add_republican_tradition = 2
	}
	if = {
		limit = {
			has_country_modifier = swe_fight_for_independence
			NOT = { has_country_flag = swe_defeated_denmark }
			FROM = { tag = DAN }
		}
		set_country_flag = swe_defeated_denmark
	}
	if = {
		limit = { 
			has_country_flag = nor_norwegian_independence_modifier 
			is_subject = no
			FROM = { tag = DAN }
		}
		clr_country_flag = nor_norwegian_independence_modifier
		remove_country_modifier = nor_norwegian_independence_war_mod
	}
	if = {
		limit = {
			ROOT = {
				religion = jewish
				has_church_aspect = judaism_purim_teachings_aspect
			}
		}
		add_church_power = 75
	}
	if = {
		limit = {
			has_country_flag = nor_norwegian_independence_modifier
			is_subject = no
		}
		clr_country_flag = nor_norwegian_independence_modifier
		remove_country_modifier = nor_norwegian_independence_war_mod
	}
	if = {
		limit = {
			ROOT = {
				has_mission = swe_devastate_the_christians
				NOT = { mission_completed = swe_devastate_the_christians }
				religion = norse_pagan_reformed
			}
			FROM = { religion_group = christian }
		}
		change_variable = {
			which = swe_won_wars_against_christians
			value = 1
		}
	}
	if = { 
		limit = {
			has_dlc = "Mandate of Heaven" 
			ROOT = {
				is_emperor_of_china = yes 
				has_country_flag = mng_outward_perfection_flag 
			}
		}
		add_mandate = 10
	}
	if = {
		limit = {
			ROOT = {
				has_government_mechanic = end_time_mechanic
				NOT = {
					government_power_frozen = {
						mechanic_type = end_time_mechanic
						power_type = fanatic_zeal
					}
				}
			}
		}
		add_government_power = {
			mechanic_type = end_time_mechanic
			power_type = fanatic_zeal
			value = -5
		}
	}
	
	if = {
		limit = {
			FROM = {
				religion_group = ROOT
				NOT = { religion = ROOT }
			}
		}
		change_variable = {
			which = num_of_wars_won_against_heretics
			value = 1
		}
	}
	if = {
		limit = {
			FROM = {
				NOT = { religion = ROOT }
			}
		}
		change_variable = {
			which = num_of_wars_won_against_non_believers
			value = 1
		}
	}
	if = {
		limit = {
			ROOT = {
				has_government_attribute = pp_on_heathen_wars
			}
			FROM = {
				NOT = {
					religion_group = ROOT
				}
			}
		}
		add_power_projection = {
			type = mission_rewards_power_projection
			amount = 10
		}
	}
	if = {
		limit = {
			ROOT = {
				has_country_flag = hun_pp_on_heathen_wars
			}
			FROM = {
				NOT = {
					religion_group = ROOT
				}
			}
		}
		add_power_projection = {
			type = mission_rewards_power_projection
			amount = 10
		}
	}
}

on_change_tag_effect = {
	hidden_effect = {
		restore_country_name = yes
		restore_country_color = yes
		#England specific
		if = { limit = { has_country_modifier = royal_impressment_act_modifier } remove_country_modifier = royal_impressment_act_modifier }
		if = { limit = { has_country_modifier = isolationism_act_modifier } remove_country_modifier = isolationism_act_modifier }
		if = { limit = { has_country_modifier = colonial_act_modifier } remove_country_modifier = colonial_act_modifier }
		if = { limit = { has_country_modifier = military_reassignment_act_modifier } remove_country_modifier = military_reassignment_act_modifier }
		if = { limit = { has_country_modifier = acts_of_development_modifier } remove_country_modifier = acts_of_development_modifier }
		if = { limit = { has_country_modifier = global_empire_act_modifier } remove_country_modifier = global_empire_act_modifier }
		if = { limit = { has_country_modifier = naval_reassignment_act_modifier } remove_country_modifier = naval_reassignment_act_modifier }
		if = { limit = { has_country_modifier = diplomatic_act_modifier } remove_country_modifier = diplomatic_act_modifier }
		if = { limit = { has_country_modifier = internal_focus_act_modifier } remove_country_modifier = internal_focus_act_modifier }
		if = {
			limit = {
				has_country_modifier = TIM_india_conquest
			}
			remove_country_modifier = TIM_india_conquest
		}
		if = {
			limit = {
				has_country_flag = feo_russian_ally
			}
			save_global_event_target_as = russian_ally
		}
		if = {
			limit = {
				has_country_flag = feo_russian_pu
			}
			save_global_event_target_as = feo_russian_pu
		}
	}
}

on_force_conversion_effect = {
	#if = {	#Commented out for now because Catholicism has received a lot of buffs already.
	#	limit = {
	#		FROM = { religion = catholic }
	#	}
	#	if = {
	#		limit = { ROOT = { government_rank = 3 } }
	#		FROM = { add_papal_influence = 20 }
	#	}
	#	else_if = {
	#		limit = { ROOT = { government_rank = 2 } }
	#		FROM = { add_papal_influence = 10 }
	#	}
	#	else = {
	#		FROM = { add_papal_influence = 5 }
	#	}
	#}
	FROM = {
		add_country_modifier = {
			name = recently_force_converted_protagonist_timer
			duration = 5475
			hidden = yes
		}
		if = {
			limit = { has_country_modifier = liv_protector_of_the_catholics }
			add_papal_influence = 25
		}
		change_variable = {
			which = num_of_forced_conversions
			value = 1
		}
		if = {
			limit = { has_government_attribute = gain_monarch_power_from_force_converting }
			export_to_variable = {
				variable_name = root_development
				value = total_development
				who = ROOT
			}
			while = {
				limit = {
					check_variable = {
						which = root_development
						value = 1
					}
				}
				subtract_variable = {
					which = root_development
					value = 1
				}
				add_adm_power = 1
				add_dip_power = 1
				add_mil_power = 1
			}
		}
		if = {
			limit = { has_government_attribute = gain_devotion_from_force_converting }
			export_to_variable = {
				variable_name = root_development
				value = total_development
				who = ROOT
			}
			while = {
				limit = {
					check_variable = {
						which = root_development
						value = 1
					}
				}
				subtract_variable = {
					which = root_development
					value = 1
				}
				add_devotion = 0.05
			}
		}
		if = {
			limit = { has_government_mechanic = the_three_royal_fires_mechanic NOT = { has_country_flag = removed_asha_vahishta_loss_from_force_conversion } }
			export_to_variable = {
				variable_name = root_development
				value = total_development
				who = ROOT
			}
			while = {
				limit = {
					check_variable = {
						which = root_development
						value = 1
					}
				}
				subtract_variable = {
					which = root_development
					value = 1
				}
				change_asha_vahishta = { value = -1 }
			}
		}
		if = {
			limit = { has_government_attribute = theocratic_monarchy_mechanic }
			change_statists_vs_orangists = -0.05
		}
	}
}

on_general_recruited_effect = {
	if = {
		limit = { has_country_modifier = pol_trigger_for_army_professionalism_modifier } 
		add_army_professionalism = 1.25
	}
	else = { add_army_professionalism = 1 }
	if = {
		limit = { has_government_attribute = recruiting_generals_increases_nobles_loyalty }
		if = {
			limit = {
				has_estate = estate_nobles
			}
			add_estate_loyalty = {
				estate = estate_nobles
				loyalty = 2
			}
		}
		if = {
			limit = {
				has_estate = estate_maratha
			}
			add_estate_loyalty = {
				estate = estate_maratha
				loyalty = 2
			}
		}
		if = {
			limit = {
				has_estate = estate_rajput
			}
			add_estate_loyalty = {
				estate = estate_rajput
				loyalty = 2
			}
		}
	}
	if = {
		limit = { has_government_attribute = recruiting_generals_increases_church_loyalty }
		if = {
			limit = {
				has_estate = estate_church
			}
			add_estate_loyalty = {
				estate = estate_church
				loyalty = 2
			}
		}
		if = {
			limit = {
				has_estate = estate_brahmins
			}
			add_estate_loyalty = {
				estate = estate_brahmins
				loyalty = 2
			}
		}
	}
	if = { 
		limit = { has_country_modifier = fra_french_papal_military_cooperation_modifier } 
		add_army_professionalism = 1.5
	}
	if = {
		limit = {
			has_reform = ayyubid_high_command
		}
		add_army_tradition = 0.5
	}
	if = {
		limit = {
			has_country_flag = ven_quality_reward_flag
		}
		add_army_tradition = 1
	}
}

on_sale_of_titles_effect = {
	hidden_effect = {
		change_variable = {
			which = sale_of_titles_counter
			value = 1
		}
	}
	if = {
		limit = {
			has_country_flag = ITA_selling_crownland_will_give_25_administrative_power_flag
		}
		add_adm_power = 25
	}
	if = {
		limit = { has_government_mechanic = council_of_ten }
		add_government_power = { 
			mechanic_type = council_of_ten
			power_type = authority_power
			value = 5
		}
	}
}
on_summon_the_diet_effect = {
	hidden_effect = {
		change_variable = {
			which = summon_the_diet_counter
			value = 1
		}
	}
}
on_seize_land_effect = {
	hidden_effect = {
		change_variable = {
			which = seize_land_counter
			value = 1
		}
		if = {
			limit = {
				has_government_attribute = has_appanages
			}
			change_variable = {
				which = can_annex_appanages_points
				value = 1
			}
		}
	}
	if = {
		limit = {
			has_country_flag = MUG_seize_land_gives_absolutism
			is_absolutism_active = yes
		}
		add_absolutism = 2
	}
	if = {
		limit = { has_government_mechanic = council_of_ten }
		add_government_power = { 
			mechanic_type = council_of_ten
			power_type = authority_power
			value = -5
		}
	}
}
on_heir_disinherited_or_death_effect = {
	if = {
		limit = { has_country_flag = heir_dip_education }
		clr_country_flag = heir_dip_education
	}
	if = {
		limit = { has_country_flag = heir_mil_education }
		clr_country_flag = heir_mil_education
	}
	if = {
		limit = { has_country_flag = heir_adm_education }
		clr_country_flag = heir_adm_education
	}
	if = {
		limit = { has_ruler_flag = well_advised_tutored_heir }
		clr_ruler_flag = well_advised_tutored_heir
	}
	if = {
		limit = { has_ruler_flag = heir_went_on_grand_tour }
		clr_ruler_flag = heir_went_on_grand_tour
	}
	if = {
		limit = { has_country_flag = albrecht_achilles_flag }
		clr_country_flag = albrecht_achilles_flag #Death of original Albrecht Achilles
	}
	if = {
		limit = { has_ruler_flag = sancaga_cikma }
		clr_ruler_flag = sancaga_cikma
		every_owned_province = {
			limit = {
				has_province_modifier = heir_in_training
			}
			remove_province_modifier = heir_in_training
		}
	}
	if = {
		limit = { has_ruler_flag = returned_from_sancaga_sikma_province }
		clr_ruler_flag = returned_from_sancaga_sikma_province
	}
	if = {
		limit = { primary_culture = maori }
		country_event = { id = polynesian.26 }
	}
	if = {
		limit = { has_any_heir_cult_active = yes }
		remove_heir_cult = yes
	}
}

on_defender_of_faith_loss_effect = {
	clr_country_flag = claimed_defender_of_faith_flag
	remove_country_modifier = liv_the_livonian_defender
	remove_country_modifier = gov_improved_defender_of_faith_mod
	remove_country_modifier = pol_shield_against_catholicism_modifier
	remove_country_modifier = per_persian_defender_of_faith
}
on_defender_of_faith_claim_effect = {
	set_country_flag = claimed_defender_of_faith_flag
	if = {
		limit = {
			religion = catholic
			has_country_flag = liv_the_livonian_defender_flag
			NOT = { has_country_modifier = liv_the_livonian_defender }
		}
		add_country_modifier = {
			name = liv_the_livonian_defender
			duration = -1
			desc = liv_the_livonian_defender_tt
		}
	}
	if = {
		limit = {
			has_government_attribute = improved_defender_of_faith
		}
		add_country_modifier = {
			name = gov_improved_defender_of_faith_mod
			duration = -1
		}
	}
	if = {
		limit = {
			has_country_flag = per_gain_persian_dotf_buff
		}
		add_country_modifier = {
			name = per_persian_defender_of_faith
			duration = -1
			desc = UNTIL_NO_MORE_DOTF
		}
	}
}

on_advisor_removed_effct_adm = {}
on_advisor_removed_effct_dip = {}
on_advisor_removed_effct_mil = {}
on_advisor_removed_effct = {
	on_advisor_removed_effct_$type$ = yes
	remove_grand_vizier_modifiers = yes
	remove_country_modifier = zoroastrian_prophet_in_the_court
}


on_built_tax_building_effect = {
	if = {
		limit = {
			owner = { has_country_flag = can_place_center_of_reformation }
			is_reformation_center = no
			expelling_minorities = no
			NOT = {
				any_neighbor_province = {
					is_reformation_center = yes
				}
			}
			NOT = {
				any_province = {
					area = PREV
					is_reformation_center = yes
					religion = zoroastrian
				}
			}
			OR = {
				has_owner_religion = yes
				NOT = { has_active_triggered_province_modifier = religious_center }
			}
		}
		if = {
			limit = { development = 31 }
			custom_tooltip = TOO_MUCH_DEV_FOR_CENTER_OF_CONVERSION_TT
		}
		else = {
			hidden_effect = { 
				owner = { 
					clr_country_flag = can_place_center_of_reformation 
				} 
				1 = {
					change_variable = {
						which = zoroastrian_reform_center_counter
						value = 1
					}
				}
			}
			change_religion = zoroastrian
			add_reform_center = zoroastrian
		}
	}
}

on_capital_moved_effect = {
	owner = {
        if = {
            limit = {
                has_estate_privilege = estate_burghers_hungarian_royal_cities
            }
            carpathia_region = {
                limit = {
                    owned_by = ROOT
                    development = 20
                    NOT = { has_province_modifier = estate_burghers_hungarian_royal_city_modifier }
                    province_has_center_of_trade_of_level = 1
                }
                add_province_modifier = {
                    name = estate_burghers_hungarian_royal_city_modifier
                    duration = -1
                }
            }
            capital_scope = {
                remove_province_modifier = estate_burghers_hungarian_royal_city_modifier
            }
        }
		if = {
			limit = {
				check_variable = {
					which = inca_amount_of_mummies
					value = 1
				}
			}
			subtract_variable = {
				which = inca_amount_of_mummies
				value = 1
			}
		}
    }
	if = {
		limit = { 
			owner = { has_reform = great_mongol_state_reform }
		}
		FROM = { remove_province_modifier = allow_banners_capital_modifier }
		ROOT = {
			add_province_modifier = {
				name = allow_banners_capital_modifier
				duration = -1
				hidden = yes
			}
		}
	}
}

on_government_change_effect = {
	if = {
		limit = { 
			has_country_modifier = ven_ten_restrained
		}
		remove_country_modifier = ven_ten_restrained
	}
	if = {
		limit = {
			any_owned_province = { has_province_modifier = hsn_ayyubid_tolerance }
		}
		every_owned_province = {
			limit = { has_province_modifier = hsn_ayyubid_tolerance }
			remove_province_modifier = hsn_ayyubid_tolerance
		}
	}
	clr_country_flag = pirate_mutineer_council
	clr_country_flag = caretaker_revolutionary_government
	if = {
		limit = {
			any_owned_province = { has_province_modifier = domain_of_spouses_family }
		}
		random_owned_province = {
			limit = { has_province_modifier = domain_of_spouses_family }
			remove_province_modifier = domain_of_spouses_family
		}
	}
	if = {
		limit = {
			any_owned_province = { has_province_modifier = home_of_consort }
		}
		random_owned_province = {
			limit = { has_province_modifier = home_of_consort }
			remove_province_modifier = home_of_consort
		}
	}
	if = {
		limit = {
			OR = {
				tag = ENG
				tag = GBR
			}
			any_owned_province = { has_province_modifier = rotten_borough }
		}
		every_owned_province = {
			limit = { has_province_modifier = rotten_borough }
			remove_province_modifier = rotten_borough
		}
	}
	if = {
		limit = { has_country_modifier = the_reign_of_terror }
		remove_country_modifier = the_reign_of_terror
	}
	if = {
		limit = {
			has_global_flag = great_peasants_war_flag
			is_part_of_hre = yes
			has_government_attribute = is_peasants_republic
		}
		1 = {
			change_variable = {
				which = GPW_counting_variable
				value = -3
			}
		}
	}
	if = {
		limit = {
			num_of_subjects = 1
			any_subject_country = {
				is_subject_of_type = cultural_sphere_of_influence_subject
			}
		}
		country_event = { id = persian_influence_events.3000 }
	}
	if = {
		limit = {
			has_country_flag = GER_unlocked_saxon_reform
		}
		every_owned_province = {
			limit = {
				has_province_modifier = GER_mining_provinces_saxon
			}
			remove_province_modifier = GER_mining_provinces_saxon
		}
	}
	if = {
		limit = {
			has_country_flag = GER_unlocked_franconian_reform
		}
		every_owned_province = {
			limit = {
				has_province_modifier = GER_paper_provinces_franconian
			}
			remove_province_modifier = GER_paper_provinces_franconian
		}
	}
}

on_native_government_change_effect = {
	hidden_effect = {
		every_owned_province = {
			if = { limit = { has_building = native_palisade } set_province_flag = native_palisade_flag }
			if = { limit = { has_building = native_fortified_house } set_province_flag = native_fortified_house_flag }
			if = { limit = { has_building = native_ceremonial_fire_pit } set_province_flag = native_ceremonial_fire_pit_flag }
			if = { limit = { has_building = native_storehouse } set_province_flag = native_storehouse_flag }
			if = { limit = { has_building = native_longhouse } set_province_flag = native_longhouse_flag }
			if = { limit = { has_building = native_sweat_lodge } set_province_flag = native_sweat_lodge_flag }
			if = { limit = { has_building = native_great_trail } set_province_flag = native_great_trail_flag }
		}
		country_event = {
			id = native_americans.999
			days = 35
		}
	}
}

on_non_estate_disaster_end = {
	hidden_effect = {
		change_variable = {
			which = total_disasters_completed_counter
			value = 1
		}
	}
}

on_startup_effect = {
	if = {
		limit = {
			NOT = { has_country_flag = new_flavour_bav_13_has_been_triggered }
			OR = {
				tag = UBV
				tag = LBV
				tag = ING
			}
		}
		set_country_flag = new_flavour_bav_13_has_been_triggered
		country_event = { id = new_flavour_bav.13 days = 90 } #better not to allow almost instant DOWs
	}
	if = {
		limit = {
			OR = {
				has_country_modifier = rise_of_the_ottomans
				has_country_modifier = zenith_of_the_ottomans
				has_country_modifier = twilight_of_the_ottomans
				has_country_modifier = decline_of_the_ottomans
			}
		}
		remove_country_modifier = rise_of_the_ottomans
		remove_country_modifier = zenith_of_the_ottomans
		remove_country_modifier = twilight_of_the_ottomans
		remove_country_modifier = decline_of_the_ottomans
	}
	if = {
		limit = {
			has_government_mechanic = ottoman_decadence_mechanic
			current_age = age_of_discovery
		}
		add_country_modifier = {
			name = rise_of_the_ottomans
			duration = -1
			desc = until_end_of_age_desc
		}
	}
	if = {
		limit = {
			has_government_mechanic = ottoman_decadence_mechanic
			current_age = age_of_reformation
		}
		add_country_modifier = {
			name = zenith_of_the_ottomans
			duration = -1
			desc = until_end_of_age_desc
		}
	}
	if = {
		limit = {
			has_government_mechanic = ottoman_decadence_mechanic
			current_age = age_of_absolutism
		}
		add_country_modifier = {
			name = twilight_of_the_ottomans
			duration = -1
			desc = until_end_of_age_desc
		}
	}
	if = {
		limit = {
			has_government_mechanic = ottoman_decadence_mechanic
			current_age = age_of_revolutions
		}
		add_country_modifier = {
			name = decline_of_the_ottomans
			duration = -1
			desc = until_end_of_age_desc
		}
	}
	if = {
		limit = {
			tag = BOH
			NOT = {
				has_country_flag = boh_hussite_aftermath_flag
			}
		}
		set_country_flag = boh_hussite_aftermath_flag
		country_event = { id = flavor_boh.15 }
	}
	if = {
		limit = {
			ai = no
			tag = BOH
			has_dlc = "Winds of Change"
			not_in_mission_preview_mode = { key = BOH_RELIGION }
			NOT = { mission_completed = boh_hussite_regency }
		}
		enable_branching_mission_review_without_ai  = {
			key = BOH_RELIGION
		}
	}
    if = {
        limit = {
			ai = no
            tag = HSN
            has_dlc = "Winds of Change"
			not_in_mission_preview_mode = { key = HSN }
			NOT = { mission_completed = hsn_fate_of_anatolia }
        }
        enable_branching_mission_review_without_ai  = {
            key = HSN
        }
    }
    if = {
        limit = {
			ai = no
            tag = HSN
            has_dlc = "Winds of Change"
			not_in_mission_preview_mode = { key = HSN2 }
			NOT = { mission_completed = hsn_sultan_shah }
        }
        enable_branching_mission_review_without_ai  = {
            key = HSN2
        }
    }
}

on_startup_dlc_cleanup_effect = {
	if = {
		limit = {
			has_dlc = "Cradle of Civilization"
			has_country_modifier = tur_janissary
		}
		remove_country_modifier = tur_janissary
	}
	if = {
		limit = {
			tag = BOH
			has_dlc = "Winds of Change"
			not_in_mission_preview_mode = { key = BOH_RELIGION }
			NOT = {
				mission_completed = boh_hussite_regency
			}
		}
		enable_branching_mission_review = {
			key = BOH_RELIGION
			ai_event_id = flavor_boh.14
		}
	}
    if = {
        limit = {
            tag = HSN
            has_dlc = "Winds of Change"
			not_in_mission_preview_mode = { key = HSN }
			NOT = {
				mission_completed = hsn_fate_of_anatolia
			}
        }
        enable_branching_mission_review_without_ai = {
            key = HSN
        }
    }
    if = {
        limit = {
            tag = HSN
            has_dlc = "Winds of Change"
			not_in_mission_preview_mode = { key = HSN2 }
			NOT = {
				mission_completed = hsn_sultan_shah
			}
        }
        enable_branching_mission_review_without_ai = {
            key = HSN2
        }
    }
}

on_dependency_gained_effect = {
	convert_special_subject_to_vassal = {
		overlord = ROOT
		subject = FROM
	}
	FROM = {
		if = {
			limit = {
				OR = {
					is_subject_of_type = personal_union
					is_subject_of_type = integrated_personal_union
				}
				has_reform = stadthalter_monarchy_reform
			}
			remove_government_reform = stadthalter_monarchy_reform
		}
		if = {
			limit = {
				OR = {
					has_country_flag = hun_ladislaus_postumus_king
					has_country_flag = hun_ladislaus_postumus_heir
				}
				is_lesser_in_union = yes
			}
			clr_country_flag = hun_ladislaus_postumus_king
			clr_country_flag = hun_ladislaus_postumus_heir
		}
	} 
	if = {
		limit = {
			FROM = {
				has_government_attribute = has_dutch_election
			}
		}
		ROOT = {
			country_event = {
				id = dutch_republic.31
			}# States General falls under a PU
		}
	}
	if = {
		limit = {
			FROM = {
				tag = AVE
				government_rank = 1
			}
		}
		FROM = {
			country_event = {
				id = flavor_gbr.20
			}
		}
	}
}

on_dependency_lost_effect = {
	if = {
		limit = {
			has_country_modifier = mng_tibetan_horses_monopoly_modifier
			FROM = { owns = 667 }
			
		}
		remove_country_modifier = mng_tibetan_horses_monopoly_modifier
	}
	if = {
		limit = {
			has_country_modifier = tur_tatar_vanguard_modifier
			FROM = { tag = CRI NOT = { is_subject_of = ROOT } }
		}
		remove_country_modifier = tur_tatar_vanguard_modifier
	}
	if = {
		limit = {
			has_country_modifier = rus_grand_duke_of_finland
			FROM = { tag = FIN }
		}
		remove_country_modifier = rus_grand_duke_of_finland
	}
	FROM = {
		if = {
			limit = { has_country_modifier = revoked_war_rights }
			remove_country_modifier = revoked_war_rights
		}
		if = {
			limit = { has_country_modifier = grain_trade_imports_modifier }
			remove_country_modifier = grain_trade_imports_modifier
		}
	}
}

on_monarch_death_effect = {
	if = {
		limit = {
			tag = ANS
			BRA = {
				has_country_flag = albrecht_achilles_flag
			}
		}
		BRA = {
			clr_country_flag = albrecht_achilles_flag #Just to be sure
			kill_heir = {} #If Albrecht Achilles dies in Ansbach he will also be dead in Brandenburg, will appear as normal death of heir to BRA.
		}
	}
	if = {
		limit = { has_country_modifier = sought_after_bachelor }
		remove_country_modifier = sought_after_bachelor
	}
	if = {
		limit = {
			tag = SAX
			has_country_flag = sax_thuringen_split_to_happen
			OR = {
				NOT = { dynasty = "von Wettin" }
				NOT = { senior_union_with = THU }
				has_regency = yes
			}
		}
		clr_country_flag = sax_thuringen_split_to_happen
	}
	if = {
		limit = { tag = SAM }
		country_event = { id = polynesian.35 }
	}
	if = {
		limit = { tag = TOG }
		country_event = { id = polynesian.36 }
	}
	if = {	# Ascension of Trailokanat	
		limit = { tag = AYU }
		country_event = { id = flavor_suk.1 }
	}
	if = {
		limit = { tag = GOT }
		country_event = { id = flavor_got.37 }
	}
	if = {
		limit = { has_government_attribute = no_stability_loss_on_monarch_death }
		add_stability = 1
	}
	if = {
		limit = {
			is_subject_of_type = pronoia_subject_type
			NOT = { liberty_desire = 50 }
		}
		overlord = {
			inherit = ROOT
			if = {
				limit = {
					has_country_flag = BYZ_inheriting_pronoia_crownland_flag
					OR = {
						NOT = { has_country_flag = BYZ_crownland_from_pronoia_proc }
						had_country_flag = {
							flag = BYZ_crownland_from_pronoia_proc
							days = 1825
						}
					}
				}
				clr_country_flag = BYZ_crownland_from_pronoia_proc
				set_country_flag = BYZ_crownland_from_pronoia_proc
				change_estate_land_share = {
					estate = all
					share = -1
				}
			}
		}
	}
	if = {
		limit = {
			has_government_attribute = civil_war_on_every_new_ruler
		}
		country_event = { id = 611 }
	}
	if = {
		limit = {
			tag = HAB
			NOT = { exists = HUN }
			NOT = { has_country_flag = hab_hungarian_crown_event_flag }
			num_of_owned_provinces_with = {
				value = 1
				OR = {
					culture = hungarian
					is_core = HUN
				}
			}
		}
		country_event = { id = hungarian_revolt_events.4 }
	}
}

on_conquest_effect = {
	remove_named_unrest = estate_land_seized
	clr_province_flag = has_estate_unrest_flag
	if = {
		limit = { 
			is_part_of_hre = no
			owner = { 
				has_country_flag = pru_dom_hre_flag 
				alliance_with = emperor 
			}
		}
		owner = {
			add_trust = {
				who = emperor 
				value = 3 
				mutual = yes 
			}
		}
	}
	else_if = {
		limit = { 
			is_part_of_hre = no
			owner = { 
				has_country_flag = pru_dom_hre_flag 
				NOT = { alliance_with = emperor } 
				is_emperor = no
			}
		}
		owner = {
			add_power_projection = {
				type = mission_rewards_power_projection
				amount = 1
			}
		}
	}
	else_if = {
		limit = { 
			is_part_of_hre = no
			owner = { is_emperor = yes }
			development = 25
		}
		emperor = { 
			add_imperial_influence = 1
		}
	}
	if = {
		limit = {
			has_fort_building_trigger = yes
			owner = {
				has_country_flag = orm_forts_trade_power_buff_flag
			}
		}
		add_province_modifier = {
			name = orm_forts_buff
			duration = -1
			hidden = yes
		}
	}
	if = {
		limit = {
			province_id = 134
			owner = {
				OR = {
					has_country_flag = enable_gothic_invasion_cb_flag
					overlord = { has_country_flag = enable_gothic_invasion_cb_flag }
				}
			}
			if = {
				limit = {
					owner = { has_country_flag = enable_gothic_invasion_cb_flag }
				}
				owner = {
					add_country_modifier = {
						name = feo_vienna
						duration = -1
					}
				}
			}
		}
		else = {
			owner = {
				overlord = {
					add_country_modifier = {
						name = feo_vienna
						duration = -1
					}
				}
			}
		}
	}
	if = {
		limit = {
			province_id = 266
			owner = {
				OR = {
					has_country_flag = enable_gothic_invasion_cb_flag
					overlord = { has_country_flag = enable_gothic_invasion_cb_flag }
				}
			}
		}
		if = {
			limit = {
				owner = { has_country_flag = enable_gothic_invasion_cb_flag }
			}
			owner = {
				add_country_modifier = {
					name = feo_prague
					duration = -1
				}
			}
		}
		else = {
			owner = {
				overlord = {
					add_country_modifier = {
						name = feo_prague
						duration = -1
					}
				}
			}
		}
	}
	if = {
		limit = {
			province_id = 45
			owner = {
				OR = {
					has_country_flag = enable_gothic_invasion_cb_flag
					overlord = { has_country_flag = enable_gothic_invasion_cb_flag }
				}
			}
		}
		if = {
			limit = {
				owner = { has_country_flag = enable_gothic_invasion_cb_flag }
			}
			owner = {
				add_country_modifier = {
					name = feo_lubeck
					duration = -1
				}
			}
		}
		else = {
			owner = {
				overlord = {
					add_country_modifier = {
						name = feo_lubeck
						duration = -1
					}
				}
			}
		}
	}
	if = {
		limit = {
			province_id = 1878
			owner = {
				OR = {
					has_country_flag = enable_gothic_invasion_cb_flag
					overlord = { has_country_flag = enable_gothic_invasion_cb_flag }
				}
			}
		}
		if = {
			limit = {
				owner = { has_country_flag = enable_gothic_invasion_cb_flag }
			}
			owner = {
				add_country_modifier = {
					name = feo_aachen
					duration = -1
				}
			}
		}
		else = {
			owner = {
				overlord = {
					add_country_modifier = {
						name = feo_aachen
						duration = -1
					}
				}
			}
		}
	}
	if = {
		limit = {
			province_id = 85
			owner = {
				OR = {
					has_country_flag = enable_gothic_invasion_cb_flag
					overlord = { has_country_flag = enable_gothic_invasion_cb_flag }
				}
			}
		}
		if = {
			limit = {
				owner = { has_country_flag = enable_gothic_invasion_cb_flag }
			}
			owner = {
				add_country_modifier = {
					name = feo_cologne
					duration = -1
				}
			}
		}
		else = {
			owner = {
				overlord = {
					add_country_modifier = {
						name = feo_cologne
						duration = -1
					}
				}
			}
		}
	}
}

on_convert_by_trade_policy_effect = {
	FROM = { change_variable = { which = propogation_counter value = 1 } }
	if = {
		limit = {
			trade_company_region = trade_company_moluccas
			FROM = { is_defender_of_faith = yes }
		}
		FROM = {
			if = {
				limit = {
					ai = no
					NOT = { check_variable = { which = religion_propagated_in_moluccas value = 1 } }
				}
				set_variable = {
					which = religion_propagated_in_moluccas value = 1
				}
			}
			else_if = {
				limit = {
					ai = no
					check_variable = { which = religion_propagated_in_moluccas value = 1 }
					NOT = { check_variable = { which = religion_propagated_in_moluccas value = 6 } }
				}
				change_variable = {
					which = religion_propagated_in_moluccas value = 1
				}
			}
		}
	}
	if = {
		limit = { FROM = { has_country_flag = YEM_propagation_gives_navy_tradition } }
		FROM = { add_navy_tradition = 1 }
	}
	if = {
		limit = {
			FROM = { has_country_flag = orm_better_sea_religious_propagation }
			OR = {
				region = indonesia_region
				region = moluccas_region
				region = malaya_region
			}
		}
		FROM = { add_piety = 0.005 }
	}
	if = {
		limit = { FROM = { has_country_flag = hormuz_religious_propagations_buffs_flag } }
		add_province_modifier = {
			name = orm_hormuz_merchants_influence
			duration = 7300
		}
	}
}

on_age_ability_taken_age_of_discovery = { } #for future use (and modders!) :)
on_age_ability_taken_age_of_reformation = { }
on_age_ability_taken_age_of_absolutism = { }
on_age_ability_taken_age_of_revolutions = { }
on_age_ability_taken = {
	on_age_ability_taken_$age$ = yes
	
	if = {
		limit = {
			has_government_attribute = GER_taking_age_rewards_gives_stability
		}
		add_stability_or_adm_power = yes
	}
}