#When adding effects directly in on_actions always consider if it would be best to do so through a scripted effect. on_actions with a lot of script in them are harder to get an overview of.

# country
on_startup = {
	emperor = {
		save_global_event_target_as = Emperor
	}
	if = {
		limit = {
			has_dlc = "Mandate of Heaven"
		}
		if = {
			limit = { is_emperor_of_china = yes }
			save_global_event_target_as = EmperorOfChina
		}
	}
	else = {
		if = {
			limit = { has_reform = celestial_empire }
			save_global_event_target_as = EmperorOfChina
		}
	}
	events = {
		muslim_school_events.20 #Pick School
		flavor_got.1 #Event for Gotland to select their mission tree
		flavor_mng.42 #Event for the starting situation of the Ming 
		#flavor_fra.15000 #Make the French Revolution happen if starting in 1789
		flavor_mos.1 #Event regarding the Tatar Yoke
		flavor_fra.206 # Setup the general for missions
		flavor_geo.1 # Disaster info
		flavor_mam.111 # Mamluks-Syria relations
	}
	on_startup_effect = yes
	on_startup_dlc_cleanup_effect = yes
	initialize_schools_effect = yes #This is only used here but is used for readability of on_action file.
}

# country
on_religion_change = {
	on_religion_change_effect = yes
	on_religion_change_estate_privileges_effect = yes
	judaism_on_religion_change_effect = yes
	events = {
		muslim_school_events.20 #Pick School
		propagate_religion_events.7 #Propagated Country is now Muslim
	}
}

# country.
on_secondary_religion_change = {
	# Done from code: add_prestige = -50 (Define: CHANGE_SECONDARY_PRESTIGE_HIT)
	on_secondary_religion_change_estate_privileges_effect = yes
	every_owned_province = {
		limit = { has_province_modifier = tengri_monastic_order }
		remove_province_modifier = tengri_monastic_order
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_shiite_settled_in_capital }
		remove_province_modifier = tengri_shiite_settled_in_capital
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_insincere_leadership }
		remove_province_modifier = tengri_insincere_leadership
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_religious_influx }
		remove_province_modifier = tengri_religious_influx
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_ruler_questioned }
		remove_province_modifier = tengri_ruler_questioned
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_strengthened_local_clans }
		remove_province_modifier = tengri_strengthened_local_clans
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_growing_cities }
		remove_province_modifier = tengri_growing_cities
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_christian_mission }
		remove_province_modifier = tengri_christian_mission
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_unchristian_values }
		remove_province_modifier = tengri_unchristian_values
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_monastic_order }
		remove_province_modifier = tengri_monastic_order
	}
	every_owned_province = {
		limit = { has_province_modifier = hindufication }
		remove_province_modifier = hindufication
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_influx_of_monks }
		remove_province_modifier = tengri_influx_of_monks
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_abandoning_the_old_ways }
		remove_province_modifier = tengri_abandoning_the_old_ways
	}
	remove_country_modifier = tengri_devout_muslim
	remove_country_modifier = tengri_confucian_elites_alienated
	remove_country_modifier = tengri_confucian_titles
	remove_country_modifier = tengri_traditionalists_strengthened
	remove_country_modifier = tengri_confucian_nobles
	remove_country_modifier = tengri_pali_legal_traditions
	remove_country_modifier = tengri_religious_pilgrimages
	remove_country_modifier = tengri_monks_in_capital
	remove_country_modifier = tengri_influx_of_monks
	remove_country_modifier = tengri_shiite_immigration
	remove_country_modifier = support_of_the_khojas
	remove_country_modifier = black_shamanism_modifier
	remove_country_modifier = tengri_animist_pantheon
	remove_country_modifier = zoroastrian_traders
	remove_country_modifier = spread_of_tengri_tea_ceremony
	remove_country_modifier = tengri_tea_ceremony
	remove_country_modifier = tengri_japanese_swordsmithing
	remove_country_modifier = tengri_bow_and_arrow_defended
	remove_country_modifier = tengri_support_of_shamans
	remove_country_modifier = tengri_hindu_conflict
	remove_country_modifier = tengri_hindu_syncretism
	remove_country_modifier = tengri_devout_christian_ruler
	remove_country_modifier = tengri_personal_confessor
	remove_country_modifier = tengri_confucian_administrators
	remove_country_modifier = tengri_traditional_elites_alienated
	remove_country_modifier = tengri_jihad
	remove_country_modifier = tengri_stood_up_for_yassa
	remove_country_modifier = tengri_sufi_teacher
	remove_country_modifier = tengri_qadi
	remove_country_modifier = tengri_religious_influx
	remove_country_modifier = tengri_ibadi_scholars
	remove_country_modifier = tengri_clergy_conflicts
	remove_country_modifier = tengri_shamans_spurned
	clr_country_flag = khojas_established
	clr_country_flag = tengri_christian_devout_court
	clr_ruler_flag = tengri_muslim_ruler_questioned
	if = {
		limit = {
			check_variable = { which = khojas_retained value = 1 }
		}
		set_variable = {
			which = khojas_retained value = 0
		}
	}
	if = {
		limit = {
			has_country_flag = hordes_devout_tengri_completion_flag
		}
		add_prestige = 50
	}
}

# country. Spawned when Enforcing Rebel Demands through a Support Rebels-war.
on_enforce_rebel_demands = {
	# ROOT = The winning country
	# FROM = The loosing country
	set_country_flag = helped_rebels_win_war
}

# country
on_colonial_liberation = {
	if = {
		limit = {
			NOT = { has_country_flag = old_world_to_new_world_flag }
		}
		country_event = { id = colonial_nation.90 days = 1 }
	}
}

# country
on_colonial_reintegration = {
	events = {
		colonial_nation.91
	}
}

# country
on_peace_actor = {
	events = {
		usa_dlc.36				# Evacuation Day
	}
}

# country
on_peace_recipient = {
}

# country
# root = winning country, from = loser country
on_war_won = {
	if = {
		limit = {
			has_country_modifier = hun_avenge_varna
			FROM = { tag = TUR }
		}
		remove_country_modifier = hun_avenge_varna
	}
	
	FROM = { country_event = { id = flavor_cri.6 } }
	ROOT = { country_event = { id = tributary_events.32 } }
	if = {
		limit = {
			has_country_flag = can_gain_legendary_pirates_flag
			NOT = { has_ruler_flag = historical_pirate }
			has_government_attribute = is_pirate_republic_reform
			FROM = { total_development = ROOT }
		}
		random = {
			chance = 5
			country_event = {
				id = pirates.25
			}
		}
	}
	
	if = {
		limit = {
			is_part_of_hre = yes
			FROM  = { is_part_of_hre = yes }
		}
		ROOT = { save_global_event_target_as = hre_winner }
		FROM = { save_global_event_target_as = hre_loser }
		random_known_country = {
			limit = {
				has_reform = free_city
				NOT = {
					prestige = 40
				}
				NOT = {
					has_country_modifier = fc_treatyconference_timer
				}
			}
			add_country_modifier = {
				name = fc_treatyconference_timer
				duration = 3650
				hidden = yes
			}
			country_event = {
				id = free_cities.7
				days = 7
			}
		}
	}

	if = {
		limit = {
			tag = MLO
			NOT = { has_country_flag = emp_mlo_won_war_with_swiss_mercs }
			any_hired_mercenary_company = {
				home_province = {
					OR = {
						area = switzerland_area
						area = romandie_area
					}
				}
			}
		}
		set_country_flag = emp_mlo_won_war_with_swiss_mercs
	}
	
	if = {
		limit = {
			is_hiring_condottiere_from = SWI
		}
		SWI = { set_country_flag = won_condottiere_war }
		if = {
			limit = {
				tag = PAP
			}
			SWI = {
				set_country_flag = hired_to_pope
			}
		}
	}
	
	if = {
		limit = {
			primary_culture = melanesian
			NOT = { has_country_modifier = warlord_mod }
		}
		FROM = {
			country_event = {
				id = polynesian.17
			}
		}
	}
	if = {
		limit = {
			ROOT = { 
				tag = SWE
				has_country_modifier = swe_vasa_leads_the_rebellion
				is_subject = no
			}
			FROM = { tag = DAN }
		}
		country_event = {
			id = flavor_swe.111
		}
	}
	if = {
		limit = {
			ROOT = { 
				tag = SWE
				has_country_modifier = swe_any_vasa_leads_the_rebellion
				is_subject = no
			}
			FROM = { tag = DAN }
		}
		country_event = {
			id = flavor_swe.105
		}
	}
	if = {
		limit = {
			ROOT = { 
				tag = SWE
				has_country_flag = swe_declared_independence_war
				is_subject = no
			}
			FROM = { tag = DAN }
		}
		country_event = {
			id = flavor_swe.121
		}
	}
	change_variable = {
		which = num_of_wars_won_var
		value = 1
	}
	if = {
		limit = {
			NOT = {
				can_be_overlord = nahuatl_tributary
			}
		}
		every_subject_country = {
			limit = {
				is_subject_of_type = nahuatl_tributary
			}
			grant_independence = yes
		}
	}
}

# country
# root = winning country, from = loser country
on_main_war_won = {
	on_main_war_won_effect = yes
	events = {
		native_americans.7
		flavor_kor.15
	}
}

# country
# root = winning country, from = loser country
on_separate_war_won = {
	if = {
		limit = {
			has_country_modifier = hun_avenge_varna
			FROM = { tag = TUR }
		}
		remove_country_modifier = hun_avenge_varna
	}
	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
		}
	}
}

# country
# root = loser country, from = winner country
on_war_lost = {
	if = {
		limit = {
			ROOT = {
				has_country_modifier = hun_avenge_varna
			}
			FROM = { tag = TUR }
		}
		remove_country_modifier = hun_avenge_varna
	}
	if = {
		limit = {
			ROOT = {
				has_country_modifier = boh_hegemon
			}
		}
		remove_country_modifier = boh_hegemon
	}
	if = {
		limit = {
			has_country_modifier = hun_avenge_varna
		}
		remove_country_modifier = hun_avenge_varna
	}
	ROOT = { country_event = { id = flavor_cri.6 } }
	ROOT = { country_event = { id = tributary_events.32 } }
	if = {
        limit = {
            government = republic
            is_lesser_in_union = yes
		}
		change_government_to_monarchy = yes
    }
	if = {
		limit = {
			FROM = { is_emperor = yes }
			NOT = { has_country_flag = reined_in_for_shadow_kingdom }
			NOT = { has_global_flag = italians_leave_hre }
			is_emperor = no
			is_part_of_hre = yes
			OR = {
				capital_scope = { region = italy_region }
				AND = {
					culture_group = latin
					any_owned_province = {
						region = italy_region
					}
				}
			}
		}
		set_country_flag = reined_in_for_shadow_kingdom
	}
	add_country_modifier = {
		name = just_lost_war_timer
		duration = 10
		hidden = yes
	}
}
on_main_war_lost = {
	if = {
		limit = {
			ROOT = {
				has_country_modifier = hun_avenge_varna
			}
			FROM = { tag = TUR }
		}
		remove_country_modifier = hun_avenge_varna
	}
	events = {
		flavor_kor.15
		flavor_tur.300 #Defeat of the Ottomans
	}
}
on_separate_war_lost = {
	if = {
		limit = {
			ROOT = {
				has_country_modifier = hun_avenge_varna
			}
			FROM = { tag = TUR }
		}
		remove_country_modifier = hun_avenge_varna
	}
}


# country
# root = winning country, from = loser country
on_battle_won_country = {
	on_battle_ended_effect = yes
	on_battle_won_country_effect = yes
	#Hungary Achievement -> this triggers first
	if = {
		limit = {
			any_hired_mercenary_company = {
				OR = {
					template = merc_black_army
					template = merc_black_army_2
				}
			}
			from = {
				war_with = root
				NOT = {
					check_variable = {
						which = hun_uniqe_defeated_country
						value = 3
					}
				}
			}
		}
		set_country_flag = hun_won_battle
		from = { set_country_flag = hun_lost_battle }
	}
}

# country
# root = loser country, from = winner country
on_battle_lost_country = {
	on_battle_ended_effect = yes
	battle_cult_spreading_effect = yes #Scripted effect for fetishist cult mechanics.
	random_events = {
		90 = 0
		10 = friendship_events.1 #Historical Friendship Broken
	}
	if = {
		limit = { 
			OR = {
				is_or_was_tag = { tag = QAR }
				is_or_was_tag = { tag = AKK }
			}
			FROM = {
				tag = TUR
			}
		}
		set_country_flag = turkoman_hasnt_lost_battle_to_ottomans
	}
}

# province
# root = location, from = loser country
on_battle_won_province = {
	if = {
		limit = {
			from = { tag = REB }
			owner = {
				tag = ENG
				has_disaster = war_of_the_roses
				has_country_modifier = wotr_one_year_timer
				NOT = { has_country_flag = war_of_the_roses_pretender_fled }
			}
		}
		owner = { country_event = { id = war_of_the_roses.200 days = 2 } }
	}
	if = {
		limit = {
			from = {
				tag = REB
				is_rebel_type = revolutionary_rebels
			}
			owner = {
				any_owned_province = {
					region = root
					has_revolution_in_province = yes
				}
				NOT = { has_disaster = french_revolution }
				NOT = { has_disaster = revolution }
				NOT = { has_spawned_rebels = revolutionary_rebels }
			}
		}
		owner = { country_event = { id = center_of_revolution.1600 } }
	}
	if = { 
		limit = { 
			FROM = { tag = REB }
			owner = { 
				has_country_flag = estate_eunuchs_in_power 
				is_emperor_of_china = yes 
				has_dlc = "Mandate of Heaven" 
			} 
		}
		owner = { add_mandate = -10 }
	}
	random_events = {
		1000 = 0
		100 = war_of_the_roses.6	# WotR - Rebel Leaders Captured
	}
}

#Unit Scope OnAction for Battle Won
on_battle_won_unit = {
	on_battle_won_unit_effect = yes
	if = {
		limit = {
			unit_owner = { ai = no } #Scopes to Unit Owner from Unit Scope
			general_with_steam_name = yes #Unit Scope Trigger
		}
		unit_owner = { set_country_flag = general_with_steam_name_won_battle }
	}
	if = {
		limit = {
			general_with_name = "Damarwulan"
			unit_owner = {
				has_country_flag = maj_damarwulan
			}
		}
		unit_owner = {
			change_variable = {
				which = DamarwulanWinVariable 
				value = 1
			}
		}
	}
	if = {
		limit = {
			general_with_name = "Damarwulan"
			unit_owner = {
				check_variable = {
					which = DamarwulanWinVariable
					value = 5
				}
			}
		}
		unit_owner = {
			country_event = { id = majapahit.2 days = 2 }
		}
	}
	if = {
		limit = {
			unit_owner = {
				mission_completed = son_military_expertise
				NOT = { mission_completed = son_win_battles }
			}
		}
		unit_owner = {
			change_variable = {
				which = son_fight_counter
				value = 1
			}
		}
		if = {
			limit = {
				is_ruler_commanding_unit = yes
			}
			unit_owner = {
				change_variable = {
					which = son_fight_counter
					value = 1
				}
			}
		}
	}
	if = {
		limit = {
			unit_owner = {
				has_government_attribute = winning_battles_increases_legitimacy
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			add_legitimacy = 0.5
			add_devotion = 0.5
			add_republican_tradition = 0.1
			add_revolutionary_zeal_or_absolutism = { amount = 0.1 }
		}
	}
	if = {
		limit = {
			general_with_name = "Jean Bureau"
		}
		unit_owner = {
			change_variable = {
				which = jean_bureau_battles_won 
				value = 1
			}
		}
	}
	if = {
		limit = {
			unit_owner = {
				religion = mesoamerican_religion
			}
		}
		unit_owner = {
			change_variable = {
				which = land_units_killed_since_last_reform
				which = land_units_killed
			}
		}
	}
	if = {
		limit = {
			unit_owner = {
				has_government_mechanic = blood_gathering_mechanic
			}
		}
		unit_owner = {
			set_variable = {
				which = blood_kill
				which = land_units_killed
			}
			if = {
				limit = {
					NOT = { has_country_flag = azt_blood_cap_flag }
					check_variable = {
						which = blood_kill
						value = 200001
					}
				}
				set_variable = {
					which = blood_kill
					value = 200000
				}
			}
			else_if = {
				limit = {
					has_country_flag = azt_blood_cap_flag
					check_variable = {
						which = blood_kill
						value = 400001
					}
				}
				set_variable = {
					which = blood_kill
					value = 400000
				}
			}
			while = {
				limit = {
					check_variable = {
						which = blood_kill
						value = 1000
					}
				}
				change_variable = {
					which = blood_kill
					value = -1000
				}
				add_government_power = { 
					mechanic_type = blood_gathering_mechanic 
					power_type = blood
					value = 0.1
				}
			}
		}
	}
	if = {
		limit = {
			unit_owner = {
				has_country_flag = hordes_legendary_conqueror_battles_flag
				ruler_has_personality = conqueror_personality
			}
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			change_variable = {
				which = NumOfRulerBattles
				value = 1
			}
			if = {
				limit = {
					check_variable = {
						which = NumOfRulerBattles
						value = 50
					}
				}
				remove_ruler_personality = conqueror_personality
				add_ruler_personality = legendary_conqueror_personality
			}
		}
	}
	if = {
		limit = {
			is_ruler_commanding_unit = yes
		}
		unit_owner = {
			change_variable = {
				which = num_of_battles_won_ruler
				value = 1
			}
		}
	}
	if = {
		limit = {
			OR = {
				mercenary_company = merc_black_army
				mercenary_company = merc_black_army_2
			}
			unit_owner = {
				has_country_flag = hun_won_battle
				any_war_enemy_country = {
					has_country_flag = hun_lost_battle
				}
			}
		}
		unit_owner = {
			change_variable = {
				which = black_army_glorious_victories
				value = 1
			}
			clr_country_flag = hun_won_battle
			random_war_enemy_country = {
				limit = { has_country_flag = hun_lost_battle }
				clr_country_flag = hun_lost_battle
				if = {
					limit = {
						NOT = { check_variable = { which = hun_uniqe_defeated_country value = 1 } }
					}
					set_variable = {
						which = hun_uniqe_defeated_country
						value = 1
					}
				}
				else = {
					change_variable = {
						which = hun_uniqe_defeated_country
						value = 1
					}
				}
			}
		}
	}
	else = {
		if = {
			limit = {
				unit_owner = {
					has_country_flag = hun_won_battle
				}
			}
			unit_owner = {
				clr_country_flag = hun_won_battle
				random_war_enemy_country = {
					limit = { has_country_flag = hun_lost_battle }
					clr_country_flag = hun_lost_battle
				}
			}
		}
	}
}

# #Unit Scope OnAction for Battle Lost
on_battle_lost_unit = {
	on_battle_lost_unit_effect = yes
    if = {
        limit = {
            unit_owner = {
                tag = MNG
                has_ruler_flag = mng_militry_incompetence
            }
            is_ruler_commanding_unit = yes
			enemy_unit = {
				unit_owner = {
					tag = OIR
				}
			}
        }
        OIR = {
            country_event = { id = flavor_oir.2 }
        }
    }
}

# province
# root = location, from = country doing it
on_added_to_trade_company ={
	if = { 
		limit = { 
			owner = { has_country_flag = adding_provinces_to_trade_c_merc_prod_flag } 
		}
		owner = { add_mercantilism = 1 } 
		add_base_production = 1 
	}
}

# province
# root = location, from = country doing it
on_removed_from_company ={
	if = { 
		limit = { 
			owner = { has_country_flag = adding_provinces_to_trade_c_merc_prod_flag } 
		}
		owner = { add_mercantilism = -1 } 
		add_base_production = -1 
	}
}

# province
# root = location, from = country doing it
on_company_formed ={

}

# province
# root = location, from = country doing it
on_company_disolved ={

}

# province
# root = location, from = winner country
on_battle_lost_province = {
	if = {
		limit = {
			FROM = {
				has_government_attribute = battles_on_own_territory_bonus_tradition
			}
			owned_by = FROM
		}
		FROM = {
			add_army_tradition = 0.1
		}
	}
	random_events = {
		1000 = 0
		100 = tyw_events.22	# Capital Battle in Religious War
	}
}

# country
# root = winning country, from = location
on_siege_won_country = {
	if = {
		limit = {
			from = { owned_by = SAX }
			OR = {
				is_in_war = {
					defenders = root
					defenders = THU
					defenders = emperor
					attackers = SAX
				}
				is_in_war = {
					attackers = root
					attackers = THU
					attackers = emperor
					defenders = SAX
				}
			}
			THU = {
				dynasty = "0000000000"
				is_elector = no
				is_emperor = no
				alliance_with = emperor
			}
			SAX = {
				is_elector = yes
				all_owned_province = {
					NOT = { controlled_by = SAX }
					OR = {
						controlled_by = THU
						controller = {
							OR = {
								is_in_war = {
									defenders = this
									defenders = THU
									defenders = emperor
									attackers = SAX
								}
								is_in_war = {
									attackers = this
									attackers = THU
									attackers = emperor
									defenders = SAX
								}
							}
						}
					}
				}
			}
		}
		THU = { country_event = { id = flavor_sax.10 } } # Ask Emperor for Saxon Electorate
	}
	if = {
		limit = {
			ROOT = {
				religion = jewish
				has_church_aspect = judaism_remember_passover_aspect
			}
			FROM = {
				owner = {
					war_with = ROOT
				}
				fort_level = 1
			}
		}
		ROOT = {
			add_church_power = 5
		}
	}
	grant_manpower_from_besieging_fort = yes
	if = {
		limit = {
			has_dlc = "Domination"
			not = { tag = MAM }
			exists = MAM
			NOT = { exists = EGY }
			FROM = {
				is_capital = yes
				owner = { tag = MAM }
			}
			root = {
				or = {
					tag = TUR
					and = {
						is_subject = yes
						is_subject_of = TUR
						is_subject_other_than_tributary_trigger = yes
					}
				}
				is_in_war = {
					casus_belli = cb_ottoman_invasion
					attacker_leader = TUR
					defender_leader = MAM
				}
			}
		}
		TUR = {
			country_event = { id = flavor_tur.240 }	#Collapse of the Mamluks
		}
	}
	events = {
		tyw_events.14 # Fall of Prague in Religious War
		flavor_oir.5 # Oirats capture Beijing
		flavor_lna.1 # Emerald Buddha
		flavor_son.14 # Djenne surrenders to Songhai Trigger
		flavor_teu.25 # Payback for the Hussite Wars
		flavor_kor.16 # Tripitaka Koreana
		flavor_tur.211 # Fall of Vienna
	}
	random_events = {
		10 = army_professionalism_events.1 #City Sacked
		100 = 0
	}
}

# country
# root = losing country, from = location
on_siege_lost_country = {
	events = {
		curia.8
		papacy_events.5
	}
	if = {
		limit = { 
			FROM = { has_province_modifier = fin_viipurin_linna_modifier }
		}
		FROM = { remove_province_modifier = fin_viipurin_linna_modifier } 
	}
}

# province
# root = location, from = losing country
on_siege_won_province = {
	events = {
		synthetic_dawn.4
	}
	if = {
		limit = {
			from = {
				tag = REB
				is_rebel_type = revolutionary_rebels
			}
			owner = {
				any_owned_province = {
					region = root
					has_revolution_in_province = yes
				}
				NOT = { has_disaster = french_revolution }
				NOT = { has_disaster = revolution }
				NOT = { has_spawned_rebels = revolutionary_rebels }
			}
		}
		owner = { country_event = { id = center_of_revolution.1600 } }
	}
	if = {
		limit = {
			superregion = china_superregion
			controller = {
				has_government_attribute = has_unify_china_cb
				OR = {
					is_in_war = {
						attacker_leader = this
						casus_belli = cb_chinese_unification
					}
					is_in_war = {
						defender_leader = this
						casus_belli = cb_chinese_unification
					}
				}
				NOT = { is_core = ROOT }
			}
		}
		controller = { 
			add_territorial_core = ROOT
			if = {
				limit = { is_claim = ROOT}
				remove_claim = ROOT
			}
		}
	}
}

# province
# root = location, from = winning country
on_siege_lost_province =  {
	events = {
		war_of_the_roses.10		# Lancaster Stronghold
		war_of_the_roses.11		# York Stronghold
		french_wars_of_religion.7 #Ravening Religious Fanatics
		french_wars_of_religion.9 #french_wars_of_religion.9
	}
}

# province
# root = location, from = country that abandons colony
# Fired right before the colony is abandoned.
on_abandon_colony = {
}

# province
# root = location, from = country that owns it
# Fired right after the great project is constructed
on_great_project_constructed = {
}

# OBS: Consider that the following on_actions can be called for Personal Union juniors as well.
# country
on_new_monarch = {
	on_new_monarch_effect = yes
	crimean_succession_effect = yes #Scripted effect
	slesvig_question_effect = yes #Scripted effect
	# ambrosian_republic_effect = yes
	succession_culture_religion_effect = yes
	sheik_ul_islam_effect = yes
	hab_remove_mission_mods_if_not_emperor_effect = yes
	thu_remain_von_wettin_effect = yes
	ladislaus_postumus_union_effect = yes
	if = {
		limit = {
			has_country_flag = hordes_legendary_conqueror_battles_flag
		}
		set_variable = {
			which = NumOfRulerBattles
			value = 0
		}
	}
	if = {
		limit = {
			has_country_flag = hordes_guaranteed_conquerors
			has_dlc = "Rights of Man"
			NOT = { ruler_has_personality = conqueror_personality }
		}
		add_ruler_personality = conqueror_personality
	}
	events = {
		tribal_succession.1		# Harsh anti-tribals.
		9492 					# Remove some event modifiers
		flavor_boh.8			# Winter King in Prague
		flavor_kol.1			# Bavarian Archbishop
		war_of_the_roses.101	# WotR - House of Lancaster wins
		war_of_the_roses.102	# WotR - House of York wins
		war_of_the_roses.106	# WotR - Another dynasty has seized the throne
		flavor_tur.102			# Janissary Reward
		flavor_ori.7			# Hamvira Victorious
		flavor_kbo.1			# The two branches of the Sayfawa dynasty
		flavor_kbo.8			# Sayfawa pretenders
		flavor_zan.5			# Coup of Coup of Suleiman and Muhammad al-Mazlum.
		purple_phoenix.1		# BYZ pretenders
		flavor_pol.3480			# The Pacta Conventa
		protestantism_events.15	# Catholic Leaning Monarch
		tengri_events.17		# Keep the Khojas in Power?
		flavor_tus.15			# Savonarola Dies
		flavor_brapru.22		# Succession of Albrecht Achilles
		flavor_brapru.25		# Dispositio Achillea (can also trigger from flavor_brapru.22)
		flavor_nor.27			# Proclamation in Hamar
		china_events.43			# Picking new Capital for China
		celestial_empire_events.3 #Resistance to Sinicization
		flavor_boh.2			#Heretic Kings
		flavor_hun.17			#Maintaining the Black Army
		flavor_tim.1			#Death of Shah Rukh
		muslim_school_events.20 #No Religious School
		flavor_daimyo.4			#Shiba Yoshikado
		flavor_fra.9000			# Fran�ois Villon
		flavor_sca.2			# Education Focus of the new Ruler
		flavor_rus.128			# Peter the Great
		flavor_rus.131			# Streltsy Payment
		flavor_gbr.102			# Religious Stance of the King
		MEE_Byzantine_Events.42 # Demetrios claims the throne
	}
	random_events = {
		1000 = 0
		100 = flavor_kol.1		# Bavarian Archbishop
		100 = flavor_hsa.3		# Hansa: Tagfahrt
		100 = inti_events.1		# Birth of a Panaca
		50 = dynastic_events.4
		50 = dynastic_events.5
		25 = harem_events.7		#Failed Policy of Fratricide
	}
}

on_new_consort = {
	country_event = { id = consort_events.2 }
	if = {
		limit = { has_ruler_flag = had_10_years_anniversary }
		clr_ruler_flag = had_10_years_anniversary
	}
	if = {
		limit = { has_ruler_flag = had_20_years_anniversary }
		clr_ruler_flag = had_20_years_anniversary
	}
	if = {
		limit = { has_ruler_flag = consort_had_affection_of_ruler }
		clr_ruler_flag = consort_had_affection_of_ruler
	}
	if = {
		limit = { has_country_modifier = sought_after_bachelor }
		remove_country_modifier = sought_after_bachelor
	}
	random_events = {
		1000 = 0
		25 = polynesian.16 #fijian marriage
	}
}

# country
on_monarch_death = {
	on_monarch_death_effect = yes
	burgundian_inheritance_start_effect = yes
	ladislaus_postumus_king_died_effect = yes
	joan_de_trastamara_king_died_effect = yes
	events = {
		flavor_wal.1 # Vlad the Impaler. So that he doesn't try to usurp his father.
		flavor_nav.4 # Navarra succession event
		flavor_sax.8 # Treaty of Leipzig
		flavor_pap.16 # Borgia Pope
		flavor_pap.19 # death of borgia pope
		flavor_tus.22 # Medici Pope
		flavor_tus.24 # death of the Medici Pope
		majapahit.8 # Majapahit pretenders
		flavor_mal.11 # Mali pretenders
		flavor_mal.47 # Pilgrimage ends prematurely
		government_events.3	# Election of a new Ruler
		flavor_inc.27 # Mummification of the Dead
	}
}

# country
on_regent = {
	if = {
		limit = {
			NOT = { has_global_flag = death_of_haji_giray } #Also set in history.
			tag = CRI
			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 = {
			NOT = { has_global_flag = death_of_haji_giray } #Also set in history.
			tag = CRI
			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
	}
	events = {
		tribal_succession.1	# harsh anti-tribals.
		flavor_tim.1			#Death of Shah Rukh
		flavor_daimyo.4			#Shiba Yoshikado
	}
}

# country
on_extend_regency = {
}

# country
on_new_term_election = {
	events = {
		700		# Election event
		elections.720		# Dutch Republic
		elections.800	# Lottery election
		pirates.1
	}
}

# country
on_death_election = {
	if = {
		limit = { has_reform = presidential_despot_reform }
		remove_government_reform = presidential_despot_reform
	}
	if = {
		limit = {
			has_government_attribute = is_pirate_republic_reform
		}
		set_country_flag = pirate_death_election
		country_event = { id = pirates.1 }
	}
	events = {
		701		# Election event
		elections.721		# Dutch Republic
		elections.800	# Lottery election
		flavor_tus.16 #Savonarola Leaves This World
	}
	if = {
		limit = { has_country_flag = ven_lichking_rulers_flag }
		add_ruler_modifier = {
			name = ven_plague_doctors_modifier
			duration = -1
			hidden = yes
		}
	}
	set_country_flag = INC_republic_death
	country_event = { id = flavor_inc.27 }
	clr_country_flag = INC_republic_death
}

# country
on_death_foreign_slave_ruler = {
	events = {
		mamluk_events.0 # Choose new ruler
	}
}

# country
on_replace_governor = {
	events = {
		elections.707
	}
}


# country
on_bankruptcy = {
}

# country (country annexing, root = target)
on_diplomatic_annex = {
	events = {
		610
		appanages_event.1
	}
	FRA = { 
		if = {
			limit = {
				has_estate_privilege = estate_nobles_french_strong_duchies
				NOT = { 
					any_subject_country = {
						capital_scope = { region = france_region }
						culture_group = french
					}
				}
			}
			remove_estate_privilege = estate_nobles_french_strong_duchies
		}
	}
}

# country
on_heir_death = {
	on_heir_disinherited_or_death_effect = yes
	ladislaus_postumus_heir_died_effect = yes
	joan_de_trastamara_heir_died_effect = yes
}

# country
on_queen_death = {

	if = {
		limit = { has_consort_flag = 10_years_anniversary }
		set_ruler_flag = had_10_years_anniversary
	}
	if = {
		limit = { has_consort_flag = 20_years_anniversary }
		set_ruler_flag = had_20_years_anniversary
	}
	if = {
		limit = { has_consort_flag = consort_has_affection_of_ruler }
		set_ruler_flag = consort_had_affection_of_ruler
	}

	if = {
		limit = {
			has_regency = no
			NOT = { has_ruler_flag = widow_widower }
		}
		set_ruler_flag = widow_widower
	}
	if = {
		limit = { has_consort_regency = no }
		random_owned_province = {
			limit = { has_province_modifier = domain_of_spouses_family }
			remove_province_modifier = domain_of_spouses_family
		}
	}
	if = {
		limit = { has_ruler_flag = accepted_help_from_spouses_family }
		clr_ruler_flag = accepted_help_from_spouses_family
	}
	if = {
		limit = { has_ruler_flag = helped_spouses_family }
		clr_ruler_flag = helped_spouses_family
	}
	if = {
		limit = { has_ruler_flag = refused_to_help_spouses_family }
		clr_ruler_flag = refused_to_help_spouses_family
	}
	if = {
		limit = { has_ruler_flag = has_lowborn_consort }
		random_owned_province = {
			limit = { has_province_modifier = home_of_consort }
			remove_province_modifier = home_of_consort
		}
	}
	if = {
		limit = { has_ruler_flag = has_lowborn_consort }
		clr_ruler_flag = has_lowborn_consort
	}
	if = {
		limit = { has_country_modifier = consort_adm_advice }
		remove_country_modifier = consort_adm_advice
	}
	if = {
		limit = { has_country_modifier = consort_dip_advice }
		remove_country_modifier = consort_dip_advice
	}
	if = {
		limit = { has_country_modifier = consort_mil_advice }
		remove_country_modifier = consort_mil_advice
	}
	if = {
		limit = { has_country_modifier = without_spouse_advice }
		remove_country_modifier = without_spouse_advice
	}
	if = {
		limit = { has_ruler_modifier = affectionate_royal_couple }
		remove_country_modifier = affectionate_royal_couple
	}
	if = {
		limit = { has_ruler_modifier = bav_woman_scorned_mod }
		remove_country_modifier = bav_woman_scorned_mod
	}
	if = {
		limit = { has_ruler_modifier = bav_building_wife_church }
		remove_country_modifier = bav_building_wife_church
	}
	clr_ruler_flag = marriage_length
}

# country
on_new_heir = {
	if = {
		limit = { has_any_heir_cult_active = yes }
		remove_heir_cult = yes
	}
	if = {
		limit = {
			has_country_flag = enabled_cult_for_heirs
		}
		country_event = {
			id = fetishist_flavor.600
		}
	}
	if = {
		limit = {
			has_country_flag = had_bmv
		}
		clr_country_flag = had_bmv
	}
}

# country
on_weak_heir_claim = {
	events = {
		611		# Pretenders rise up
	}
}

# country : no heir in theocracy
on_heir_needed_theocracy = {
	events = {
		flavor_sca.2
		theocracy.1
	}
}

# Emperor from same dynasty
on_successive_emperor = {
	emperor = {
		save_global_event_target_as = Emperor
	}
	if = {
		limit = {
			has_government_attribute = has_ruler_election
		}
		set_country_flag = has_internal_election_first
	}
	events = {
		900
	}
	if = {
		limit = {
			emperor = {
				has_country_flag = hun_imperial_reelection_bonus
			}
		}
		add_prestige = 10
		add_imperial_influence = 5
	}
}

# Called whenever a new emperor is elected
# FROM = Previous Emperor
# ROOT = New Emperor 
on_emperor_elected = {
	every_elector = {
		if = {
			limit = {
				preferred_emperor = root
			}
			change_variable = {
				which = supported_successive_emperors
				value = 1
			}
		}
		else = {
			set_variable = {
				which = supported_successive_emperors
				value = 0
			}
		}
	}

	emperor = {
		save_global_event_target_as = Emperor
	}
	if = {
		limit = { has_country_flag = got_promised_holstein_to_the_empire }
		clr_country_flag = got_promised_holstein_to_the_empire
	}
	FROM = {
		if = {
			limit = { has_country_modifier = diet_occupied }
			remove_country_modifier = diet_occupied
			ROOT = {
				add_country_modifier = { name = diet_occupied duration = -1 }
			}
		}
		if = {
			limit = {
				any_country = {
					reverse_has_opinion_modifier = {
						modifier = opinion_imperial_diplomacy
						who = prev
					}
				}
			}
			every_country = {
				limit = {
					reverse_has_opinion_modifier = {
						modifier = opinion_imperial_diplomacy
						who = prev
					}
				}
				reverse_remove_opinion = {
					modifier = opinion_imperial_diplomacy
					who = prev
				}
				ROOT = {
					add_opinion = {
						modifier = opinion_imperial_diplomacy
						who = prev
					}
				}
			}
		}
	}
}

# HRE Prince released by the emperor
on_released_hre_member = {
	events = {
	}
}

# HRE Prince converts to non-Emperor religion
on_hre_member_false_religion = {
	events = {
	}
}

# HRE Prince converts to Emperor religion
on_hre_member_true_religion = {
	events = {
	}
}

# Emperor wins HRE defensive war
on_hre_wins_defensive_war = {
	events = {
	}
}

# HRE member annexed by non-HRE country
on_hre_member_annexed = {
	events = {
	}
}

# HRE member released from non-HRE vassalage
on_hre_released_vassal = {
	events = {
	}
}

# HRE member transferred from non-HRE vassalage to Emperor
on_hre_transfered_vassal = {
	events = {
	}
}

# Emperor coming to the defense of a HRE member
on_hre_defense = {
	events = {
	}
}

# Emperor NOT coming to the defense of a HRE member
on_hre_non_defense = {
	events = {
		909
	}
}

# HRE Member takes a HRE province from an outs100e country in a peace (province scope)
on_hre_province_reconquest = {
	events = {
	}
}

on_lock_hre_religion = {
	events = {
		religious_leagues.1
		religious_leagues.8
	}
}

on_change_hre_religion = {
	events = {
		religious_leagues.2
		religious_leagues.3
	}
}

on_hre_religion_white_peace = {
	events = {
		religious_leagues.4
	}
}

# When a non-native changes government type
on_government_change = {
	on_government_change_effect = yes
}

# When a native changes government after filling all their advancement groups.
on_native_change_government = {
}

# Nation is integrated after being in union
on_integrate = {
	if = {
		limit = {
			has_country_flag = hun_integrate_pu_bonus
			FROM = { junior_union_with = ROOT }
		}
		if = {
			limit = {
				has_dlc = "Mandate of Heaven"
			}
			add_splendor = 100
		}
		else = {
			add_dip_power = 100
		}
	}
	events = {
		610
	}
}

# Nation annexed.
# FROM is the nation being annexed
on_annexed = {
	events = {
		celestial_empire_events.1 # Empire dismantled
	}
	on_annexed_estate_privileges_effect = yes
	FROM = {
		if = {
			limit = { is_emperor_of_china = yes }
			dismantle_empire_of_china = yes
			set_global_flag = empire_of_china_dismantled
		}
		if = {
			limit = { has_country_modifier = legatus_natus }
			remove_country_modifier = legatus_natus
			set_global_flag = no_legatus_natus
		}
		if = {
			limit = { has_country_modifier = primas_germaniae }
			remove_country_modifier = primas_germaniae
			set_global_flag = no_primas_germaniae
		}
		if = {
			limit = { tag = FIN }
			every_country = { limit = { has_country_modifier = rus_grand_duke_of_finland } remove_country_modifier = rus_grand_duke_of_finland }
		}
	}
	if = {
		limit = {
			tag = HAB
			FROM = { tag = 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 }
	}
	if = {
		limit = {
			has_country_flag = hun_integrate_pu_bonus
			FROM = { junior_union_with = ROOT }
		}
		if = {
			limit = {
				has_dlc = "Mandate of Heaven"
			}
			add_splendor = 100
		}
		else = {
			add_dip_power = 100
		}
	}
	if = {
		limit = {
			FROM = { tag = TUR }
			HUN = { has_country_modifier = hun_avenge_varna }
		}
		HUN = { remove_country_modifier = hun_avenge_varna }
	}
}

# When the chinese empire gets dismantled (e.g. when the emperor is annexed)
# FROM = Emperor, ROOT = Current Nation
on_chinese_empire_dismantled = {
	clear_global_event_target = EmperorOfChina
	events = {
	}
}

# When a nation gains the Mandate of Heaven (becomes the Emperor of China)
# FROM = Old Emperor, ROOT = New Emperor
on_mandate_of_heaven_gained = {
	save_global_event_target_as = EmperorOfChina
	if = {
		limit = {
			technology_group = nomad_group
		}
		change_technology_group = chinese
		change_unit_type = chinese
	}
	if = {
		limit = { 
			has_dlc = "Domination" 
			NOT = { primary_culture = mongol }
			NOT = { primary_culture = chahar }
			NOT = { primary_culture = khalkha }
			NOT = { primary_culture = oirats }
			has_domination_eoc_missions_available = yes
		}
		swap_non_generic_missions = yes 
	}
	if = {
		limit = {
			OR = {
				NOT = { government = monarchy }
				government = tribal
			}
		}
		change_government_to_monarchy = yes
	}
	add_government_reform = celestial_empire
	set_mandate = 60
	set_meritocracy = 60
	add_country_modifier = {
		name = new_mandate_holder
		duration = 9125
	}
	1816 = {
		if = {
			limit = {
				NOT = { owned_by = root }
				NOT = { is_core = root }
			}
			add_core = root
		}
	}
	1821 = {
		if = {
			limit = {
				NOT = { owned_by = root }
				NOT = { is_core = root }
			}
			add_core = root
		}
	}
	667 = {
		if = {
			limit = {
				NOT = { owned_by = root }
				NOT = { is_core = root }
			}
			add_core = root
		}
	}
	china_superregion = {
		limit = {
			NOT = { is_core = ROOT }
		}
		add_permanent_claim = ROOT
	}
	if = {
		limit = {
			has_dlc = "Mandate of Heaven"
		}
		remove_faction = temples
		remove_faction = enuchs
		remove_faction = bureaucrats
	}
	if = {
		limit = {
			has_country_modifier = lost_mandate_of_heaven
		}
		remove_country_modifier = lost_mandate_of_heaven
	}
	country_event = { #Reforming the Bureaucracy
		id = china_events.31
		days = 365
	}
	country_event = {
		id = china_events.32 #Records of the last Empire
		days = 183
	}
	country_event = {
		id = celestial_empire_events.2
		days = 1825
	}
}

# When a nation loses the Mandate of Heaven
# FROM = New Emperor, ROOT = Old Emperor
on_mandate_of_heaven_lost = {
	remove_government_reform = celestial_empire
	set_government_rank = 2
	add_country_modifier = {
		name = lost_mandate_of_heaven
		duration = 7300	# 20 years
	}
	if = {
		limit = { has_dlc = "Mandate of Heaven" }
		swap_non_generic_missions = yes 
	}
	add_stability = -2
	china_superregion = {
		limit = {
			is_permanent_claim = ROOT
		}
		if = {
			limit = { is_claim = ROOT}
			remove_claim = ROOT
		}
	}
	if = {
		limit = {
			has_country_modifier = new_mandate_holder
		}
		remove_country_modifier = new_mandate_holder
	}
	if = {
		limit = { has_country_modifier = jap_era_tranquil_sun_modifier } 
		remove_country_modifier = jap_era_tranquil_sun_modifier 
	}
}

on_embrace_revolution = {
	if = {	
		limit = {
			any_subject_country = {
				has_country_modifier = colony_inspired_by_revolution
			}
		}
		every_subject_country = {
			remove_country_modifier = colony_inspired_by_revolution
		}
	}
	if = {
		limit = { NOT = { government = republic } }
		change_government = republic
	}
	if = {
		limit = { 
			revolution_target_exists = no
			is_great_power = yes
		}
		set_revolution_target = ROOT
		add_government_reform = revolutionary_republic_reform
		if = { 
			limit = { tag = FRA has_dlc = "Domination" } 
			swap_non_generic_missions = yes
			country_event = { id = ideagroups.1 } #Swap Ideas
		}
		if = {
			limit = {
				any_country = {
					has_country_flag = last_revolutionary_country
				}
			}
			every_country = {
				limit = {
					has_country_flag = last_revolutionary_country
				}
				clr_country_flag = last_revolutionary_country
			}
		}
	}
	else = {
		add_government_reform = junior_revolutionary_republic_reform
	}
	if = {
		limit = { has_reform = parliamentary_reform }
		remove_government_reform = parliamentary_reform
	}
	kill_ruler = yes
	set_country_flag = revolutionary_republic_flag
	set_country_flag = had_revolution
	
	if = { 
		limit = { 
			tag = FRA 
		}
		swap_non_generic_missions = yes 
	}
}

# THIS = Revolutionary country being beaten, FROM = Country enforcing the peace treaty
on_dismantle_revolution = {
	events = {
		center_of_revolution.1500
	}
	if = {
		limit = {
			any_country = {
				has_country_flag = last_revolutionary_country
			}
		}
		every_country = {
			limit = {
				has_country_flag = last_revolutionary_country
			}
			clr_country_flag = last_revolutionary_country
		}
	}
	set_country_flag = last_revolutionary_country
}

# province
on_adm_development = {
	on_development_effect = { type = adm }
}

# province
on_dip_development = {
	on_development_effect = { type = dip }
}

# province
on_mil_development = {
	on_development_effect = { type = mil }
}

on_overextension_pulse = {
	random_events = {
		100 = overextension.1
		100 = overextension.2
		100 = overextension.3
		100 = overextension.4
		100 = overextension.5
		100 = overextension.6
		100 = overextension.7
		100 = overextension.8
		100 = overextension.9
		100 = overextension.10
	}
	#Decadence specific
	random = {
		chance = 10
		country_event = {
			id = flavor_tur.301
		}
	}
}


on_colonial_pulse = {
	random_events = {
		100 = colonial.1
		100 = colonial.2
		100 = colonial.3
		100 = colonial.4
		100 = colonial.5
		100 = colonial.8
		100 = colonial.9
		100 = colonial.10
		100 = colonial.11
		100 = colonial.12
		100 = colonial.13
		100 = colonial.14
		100 = colonial.15
		100 = colonial.16
		100 = colonial.17
		100 = colonial.18
		25 = dodo.1

		15000 = 0
	}
}

on_siberian_pulse = {
}


# country random events
on_monthly_pulse = {
}
on_yearly_pulse = {
	events = {
		flavor_mos.3 #Yearly Tatar Yoke Tribute
	}
}
on_yearly_pulse_2 = {
}
on_yearly_pulse_3 = {
}
on_yearly_pulse_4 = {
}
on_yearly_pulse_5 = {
}

on_bi_yearly_pulse = {
	events = {
		center_of_revolution.2950
		center_of_revolution.3000
	}
	random_events = {

		#Culture and Religion Events
		125 = culture_religion_events.1
		125 = culture_religion_events.3
		125 = culture_religion_events.4
		125 = culture_religion_events.5
		125 = culture_religion_events.6
		125 = culture_religion_events.7
		125 = culture_religion_events.8
		125 = culture_religion_events.9
		125 = culture_religion_events.10
		125 = culture_religion_events.11
		125 = culture_religion_events.12
		125 = culture_religion_events.13
		125 = culture_religion_events.14
		125 = culture_religion_events.15
		125 = culture_religion_events.16
		100 = culture_religion_events.17
		125 = culture_religion_events.18
		125 = culture_religion_events.19
		125 = culture_religion_events.20
		175 = culture_religion_events.21
		125 = culture_religion_events.22
		125 = culture_religion_events.23

		# Old Centralisation/Decentralisation
		100 = 806

		# Mercantilism
		100 = 6326
		100 = 6327
		100 = 6328
		100 = 6329

		# Trade Specific
		100 = trade.1
		100 = trade.2
		100 = trade.3
		100 = trade.4
		100 = trade.5
		100 = trade.6
		100 = trade.7
		100 = trade.8
		100 = trade.9
		100 = trade.10
		100 = trade.11
		100 = trade.12


		# Tradegoods events
		100 = 6418
		100 = 6419
		100 = 6420
		100 = 6421
		100 = 6422
		100 = 6423
		100 = 6424
		100 = 6425
		100 = 6426
		100 = 6427
		100 = 6428
		100 = 6429
		100 = 6431
		100 = 6432
		100 = 6433
		100 = 6434

		# Refoms, when having parliaments.
		100 = reforms.1
		100 = reforms.2
		100 = reforms.3
		100 = reforms.4

		100 = randomeventsstapehordes.1
		100 = randomeventsstapehordes.2
		100 = randomeventsstapehordes.3
		100 = randomeventsstapehordes.4
		100 = randomeventsstapehordes.5
		100 = randomeventsstapehordes.6
		100 = randomeventsstapehordes.7
		100 = randomeventsstapehordes.8
		100 = randomeventsstapehordes.13
		100 = randomeventsstapehordes.14
		100 = randomeventsstapehordes.17
		100 = randomeventsstapehordes.19
		100 = randomeventsstapehordes.20
		100 = randomeventsstapehordes.21
		100 = randomeventsstapehordes.22
		100 = randomeventsstapehordes.23
		100 = randomeventsstapehordes.24

		# Sailor events
		100 = sailor_event.1
		100 = sailor_event.2
		100 = sailor_event.3
		100 = sailor_event.4
		100 = sailor_event.5

		# Corruption Events
		100 = corruption_event.16
		100 = corruption_event.17
		100 = corruption_event.18
		100 = corruption_event.19
		100 = corruption_event.20


		# Institution Events
		#Feudalism Spread Events:
		150 = institution_events.8
		150 = institution_events.9
		150 = institution_events.10
		150 = institution_events.11
		#Global Trade Spread Events:
		150 = institution_events.50
		150 = institution_events.51
		150 = institution_events.52
		#Enlightenment Spread Events:
		150 = institution_events.70
		150 = institution_events.71
		150 = institution_events.72


		#Personality Events
		50 = personality_events.10 #Just Dilema
		50 = personality_events.11 #A righteous King
		50 = personality_events.12 #A Righteous Republican Ruler
		50 = personality_events.13
		50 = personality_events.14
		50 = personality_events.15
		50 = personality_events.16
		50 = personality_events.17
		50 = personality_events.18
		50 = personality_events.19
		50 = personality_events.20
		50 = personality_events.21
		50 = personality_events.22
		50 = personality_events.23
		50 = personality_events.24
		50 = personality_events.25
		50 = personality_events.26
		50 = personality_events.27
		50 = personality_events.28
		50 = personality_events.29
		50 = personality_events.30
		50 = personality_events.31
		50 = personality_events.32
		50 = personality_events.33
		50 = personality_events.34
		50 = personality_events.35
		50 = personality_events.36
		50 = personality_events.37
		50 = personality_events.38
		50 = personality_events.39
		50 = personality_events.40
		50 = personality_events.41
		50 = personality_events.42
		50 = personality_events.43
		50 = personality_events.44
		50 = personality_events.45
		50 = personality_events.46
		50 = personality_events.47
		50 = personality_events.48
		50 = personality_events.49
		50 = personality_events.50
		50 = personality_events.51
		50 = personality_events.52
		50 = personality_events.53
		50 = personality_events.54
		50 = personality_events.55
		50 = personality_events.56
		50 = personality_events.57
		50 = personality_events.58

		# Trade League Events
		100 = trade_league.1
		100 = trade_league.2
		100 = trade_league.3
		100 = trade_league.4
		100 = trade_league.7
		100 = trade_league.8
		100 = trade_league.9
		100 = trade_league.10
		100 = trade_league.11
		100 = trade_league.12
		100 = trade_league.13
		100 = trade_league.14

		#Industrial Revolution

		200 = industrialization_events.7
		200 = industrialization_events.8
		200 = industrialization_events.9
		200 = industrialization_events.10
		200 = industrialization_events.11
		200 = industrialization_events.12
		200 = industrialization_events.13
		200 = industrialization_events.14
		200 = industrialization_events.15
		200 = industrialization_events.16
		200 = industrialization_events.17
		200 = industrialization_events.18
		200 = industrialization_events.19
		200 = industrialization_events.20
		200 = industrialization_events.21
		200 = industrialization_events.22

		#Confucian Events
		75 = confucian_events.19
		75 = confucian_events.20

		# Orthodox Icon Events
		75 = orthodox_icon_events.1
		75 = orthodox_icon_events.3
		75 = orthodox_icon_events.4
		75 = orthodox_icon_events.5
		75 = orthodox_icon_events.6

		2000 = 0 #was 1250
	}
}

on_bi_yearly_pulse_2 = {
	random_events = {
		100 = corruption_event.1
		100 = corruption_event.2
		100 = corruption_event.3
		100 = corruption_event.4
		100 = corruption_event.5
		100 = corruption_event.6
		100 = corruption_event.7
		100 = corruption_event.8
		100 = corruption_event.9
		100 = corruption_event.10
		200 = corruption_event.11
		200 = corruption_event.12
		200 = corruption_event.13
		200 = corruption_event.14
		200 = corruption_event.15

		4000 = 0
	}
}

on_bi_yearly_pulse_3 = {

	#Fire estate agenda if you have that privilege
	# NOTE DOING THIS THROUGH RANDOM EVENT NOW WITH estate_privileges_and_agendas_events.4 INSTEAD!
	#on_bi_yearly_pulse_estate_privileges_effect = yes

	events = {
		muslim_school_events.20 #Pick School
		promoting_art_events.2	#Art finished!
	}
	random_events = {
		100 = promoting_art_events.3
		100 = promoting_art_events.4
		100 = promoting_art_events.5
		100 = promoting_art_events.6
		50 = promoting_art_events.7
		100 = new_court_flavour_events.25 #blood is thicker than water
		200 = 0
	}
}

on_bi_yearly_pulse_4 = {
	random_events = { #all these were shifted from on_bi_yearly_pulse_1
		#randomevents
		100 = 730
		100 = 731
		100 = 732
		100 = 733
		100 = 734
		100 = 735
		100 = 736
		100 = 737
		100 = 738
		100 = 739
		100 = 740
		100 = 741
		100 = 742

		100 = 850
		100 = 851
		100 = 852
		100 = 853
		100 = 854
		100 = 855
		100 = 857
		100 = 858
		100 = 859
		100 = 860
		100 = 861
		100 = 862
		100 = 863
		100 = 864
		100 = 865
		100 = 866
		100 = 867
		100 = 868
		100 = 869
		100 = 870
		100 = 871
		100 = 872
		100 = 873
		100 = 874
		100 = 875
		100 = 876
		100 = 877
		100 = 878
		100 = 879
		100 = 880
		100 = 881
		100 = 882
		100 = 883
		100 = 884
		100 = 885
		100 = 836
		100 = 837
		100 = 838

		100 = 9472
		100 = 3097
		100 = 5005
		100 = 5026
		100 = 5037
		100 = 5063
		100 = 6014


		# Innovativeness
		100 = innovativeness_events.1
		100 = innovativeness_events.2
		50 = innovativeness_events.3
		100 = innovativeness_events.4
		100 = innovativeness_events.5
		100 = innovativeness_events.6
		100 = innovativeness_events.7
		100 = innovativeness_events.8
		100 = innovativeness_events.9
		100 = innovativeness_events.10
		100 = innovativeness_events.11
		100 = innovativeness_events.12
		100 = innovativeness_events.13
		100 = innovativeness_events.14
		100 = innovativeness_events.15

		# Trade Company Investments
		100 = investment_events.1
		100 = investment_events.2
		100 = investment_events.3
		100 = investment_events.4
		100 = investment_events.5
		100 = investment_events.6
		100 = investment_events.7
		100 = investment_events.8
		100 = investment_events.9
		100 = investment_events.10

		# Catholic Order Events
		100 = order_events.1
		100 = order_events.2
		100 = order_events.3
		100 = order_events.4
		100 = order_events.5
		100 = order_events.6
		100 = order_events.7
		100 = order_events.8
		100 = order_events.9

		# Minority Expulsion Events
		100 = expel_minority_events.1
		100 = expel_minority_events.2
		100 = expel_minority_events.3
		100 = expel_minority_events.4
		100 = expel_minority_events.5
		
		# Papal Tithe Events
		100 = curia.1
		100 = curia.2
		100 = curia.4
		100 = curia.9	
		100 = curia.10
		100 = curia.11
		100 = curia.12
		
		# Defender of the Faith
		100 = dotf.1
		100 = dotf.4
		100 = dotf.6
		100 = dotf.7
		
		# Mercenaries
		100 = mercs.1
		100 = mercs.2
		100 = mercs.3
		100 = mercs.4
		#100 = mercs.7
		100 = mercs.8
		100 = mercs.10
		100 = mercs.11

		# Espionage
		#100 = espionage_events.1
		100 = espionage_events.4
		100 = espionage_events.8
		80 = espionage_events.9

		#Reign of Terror
		150 = french_revolution.302
		100 = french_revolution.303
		
		# Papacy events
		100 = papacy_events.6

		# Professionalism
		100 = army_professionalism_events.4
		100 = army_professionalism_events.5
		75 = army_professionalism_events.6
		100 = army_professionalism_events.8
		100 = army_professionalism_events.9
		100 = army_professionalism_events.10
		100 = army_professionalism_events.11
		75 = army_professionalism_events.12
		100 = army_professionalism_events.13
		75 = army_professionalism_events.16

		# Agenda from the Estates
		1000 = estate_privileges_and_agendas_events.4
		1000 = estate_privileges_and_agendas_events.5

		2000 = 0
	}
}

on_bi_yearly_pulse_5 = {
	random_events = { #all these were shifted from on_bi_yearly_pulse_1
		# Anglican Events
		100 = anglican_events.1
		100 = anglican_events.2
		100 = anglican_events.3
		100 = anglican_events.4
		100 = anglican_events.5
		100 = anglican_events.6
		100 = anglican_events.7
		100 = anglican_events.8
		100 = anglican_events.9
		100 = anglican_events.10
		100 = anglican_events.11
		100 = anglican_events.12
		100 = anglican_events.13
		150 = anglican_events.15
		
		# Hussite Events
		100 = hussite.1
		100 = hussite.2
		100 = hussite.3
		100 = hussite.4
		100 = hussite.5
		100 = hussite.6
		100 = hussite.7


		#Mamluk Events

		175 = mamluk_events.1
		175 = mamluk_events.2
		175 = mamluk_events.3
		235 = mamluk_events.4
		185 = mamluk_events.5
		175 = mamluk_events.6
		250 = mamluk_events.7
		185 = mamluk_events.10
		185 = mamluk_events.11
		235 = mamluk_events.12

		#Colonization of Siberia
		125 = siberian_events.2
		125 = siberian_events.3
		125 = siberian_events.4
		125 = siberian_events.5
		125 = siberian_events.6

		#Russian Principalities

		100 = russian_principality_events.1
		125 = russian_principality_events.2
		125 = russian_principality_events.3
		125 = russian_principality_events.4
		125 = russian_principality_events.6
		125 = russian_principality_events.5
		125 = russian_principality_events.7
		100 = russian_principality_events.8
		75 = russian_principality_events.9
		125 = russian_principality_events.10

		#Tsardoms

		125 = russian_tsardom_events.1
		125 = russian_tsardom_events.2
		125 = russian_tsardom_events.3
		100 = russian_tsardom_events.4
		125 = russian_tsardom_events.5
		100 = russian_tsardom_events.6
		100 = russian_tsardom_events.7
		100 = russian_tsardom_events.8
		125 = russian_tsardom_events.9
		125 = russian_tsardom_events.10
		100 = russian_tsardom_events.11

		#Streltsy Events
		125 = streltsy_events.1
		125 = streltsy_events.3
		125 = streltsy_events.4
		125 = streltsy_events.5
		100 = streltsy_events.6

		#Orthodox Metropolitans
		125 = patriarch_events.1
		125 = patriarch_events.2
		125 = patriarch_events.3
		75 = patriarch_events.4
		75 = patriarch_events.5

		# Catholic  Events
		100 = catholic_flavor.4
		100 = catholic_flavor.5
		100 = catholic_flavor.6
		100 = catholic_flavor.7
		100 = catholic_flavor.8
		100 = catholic_flavor.9
		100 = catholic_flavor.10

		# Japanese Daimyos
		15 = flavor_jap.10
		50 = flavor_jap.28
		100 = flavor_jap.40
		100 = flavor_jap.42
		100 = flavor_jap.43
		100 = flavor_jap.45
		100 = flavor_jap.49
		100 = flavor_jap.51
		100 = flavor_jap.52
		100 = flavor_jap.53
		100 = flavor_jap.54
		100 = flavor_jap.55



		# China
		75 = meritocracy_events.1
		75 = meritocracy_events.2
		75 = meritocracy_events.3
		75 = meritocracy_events.4
		75 = meritocracy_events.5
		50 = china_events.11
		25 = china_events.12
		25 = china_events.24

		2000 = 0
	}
}



# country random events
on_thri_yearly_pulse = {
	#events = {
	#	flavor_dan.100
	#}
	random_events = {
		# Republics
		100 = republics.4
		100 = republics.5
		100 = republics.6
		100 = republics.7
		100 = republics.8
		100 = republics.9
		100 = republics.10
		100 = republics.11
		100 = republics.12
		100 = republics.13
		100 = republics.14
		100 = republics.15
		100 = republics.16
		100 = republics.17
		100 = republics.18
		100 = republics.19
		100 = republics.20
		100 = republics.21
		100 = republics.22
		100 = republics.23
		100 = republics.24
		100 = republics.25
		100 = republics.26
		100 = republics.27
		100 = republics.28
		100 = republics.29
		100 = republics.30
		100 = republics.31
		100 = republics.32
		100 = republics.33
		100 = republics.34
		100 = republics.35
		100 = republics.36
		100 = republics.37
		100 = republics.38
		100 = republics.39
		100 = republics.40
		100 = republics.41
		100 = republics.42
		100 = republics.43

		# Theocracies
		100 = devotion_events.1
		100 = devotion_events.2
		100 = devotion_events.3
		100 = devotion_events.4
		100 = devotion_events.5
		100 = devotion_events.6
		100 = devotion_events.7
		100 = devotion_events.8
		100 = devotion_events.9
		100 = devotion_events.10
		100 = devotion_events.11
		100 = devotion_events.12
		100 = devotion_events.13
		100 = devotion_events.14
		100 = devotion_events.15
		100 = devotion_events.16
		100 = devotion_events.18
		100 = devotion_events.19
		100 = devotion_events.22
		100 = devotion_events.23
		100 = devotion_events.24
		100 = devotion_events.26
		100 = devotion_events.100
		100 = devotion_events.101
		100 = devotion_events.102
		100 = devotion_events.104
		100 = devotion_events.107
		100 = devotion_events.110
		100 = devotion_events.117
		100 = devotion_events.118
		100 = devotion_events.119
		100 = devotion_events.200
		100 = devotion_events.201
		100 = devotion_events.202
		100 = devotion_events.203
		100 = devotion_events.204
		100 = devotion_events.205
		100 = devotion_events.207
		100 = devotion_events.208
		100 = devotion_events.209
		100 = devotion_events.210
		100 = devotion_events.211
		100 = devotion_events.212
		100 = devotion_events.213
		100 = devotion_events.214
		100 = devotion_events.215
		100 = devotion_events.216
		100 = devotion_events.217
		100 = devotion_events.218
		100 = devotion_events.219



		#Center of Revolution - post-spawn (higher weighting than others as they are only relevant briefly)
		200 = center_of_revolution.1
		150 = center_of_revolution.2
		200 = center_of_revolution.3
		200 = center_of_revolution.8
		250 = center_of_revolution.9
		250 = center_of_revolution.10
		200 = center_of_revolution.12
		#Center of Revolution - pre-spawn
		100 = center_of_revolution.2000
		100 = center_of_revolution.2002
		100 = center_of_revolution.2003
		100 = center_of_revolution.2010

		1000 = 0
	}
}

on_thri_yearly_pulse_2 = {
	random_events = {
		# Random to increase or decrease patriarch authority.
		25 = orthodox_flavor.1
		20 = orthodox_flavor.2
		25 = orthodox_flavor.3
		25 = orthodox_flavor.4
		25 = orthodox_flavor.5

		# Muslim Piety Events
		40 = muslim_piety.1
		40 = muslim_piety.2
		40 = muslim_piety.3
		20 = muslim_piety.4
		20 = muslim_piety.5
		40 = muslim_piety.6
		40 = muslim_piety.7
		40 = muslim_piety.8
		40 = muslim_piety.9
		40 = muslim_piety.10
		40 = muslim_piety.11
		40 = muslim_piety.12
		40 = muslim_piety.13
		40 = muslim_piety.14
		40 = muslim_piety.15
		40 = muslim_piety.16
		40 = muslim_piety.22
		300 = 0
	}
}

on_thri_yearly_pulse_3 = {
	random_events = {
		# Subject Interactions
		50 = subject_interaction_events.1
		50 = subject_interaction_events.4
		50 = subject_interaction_events.5
		50 = subject_interaction_events.6
		50 = subject_interaction_events.7
		50 = subject_interaction_events.9
		50 = subject_interaction_events.11
		50 = subject_interaction_events.14
		50 = subject_interaction_events.15
		50 = subject_interaction_events.17
		50 = subject_interaction_events.18
		50 = subject_interaction_events.19
		50 = subject_interaction_events.20
		50 = subject_interaction_events.21
		50 = subject_interaction_events.22
		50 = subject_interaction_events.23
		50 = subject_interaction_events.24
		50 = subject_interaction_events.25
		50 = subject_interaction_events.26
		50 = subject_interaction_events.27
		50 = subject_interaction_events.29
		50 = subject_interaction_events.30
		50 = subject_interaction_events.31
		50 = subject_interaction_events.32
		50 = subject_interaction_events.34
		50 = subject_interaction_events.35
		50 = subject_interaction_events.36
		50 = subject_interaction_events.38
		50 = subject_interaction_events.40
		50 = subject_interaction_events.43
		75 = tributary_events.1
		75 = tributary_events.2
		75 = tributary_events.3
		75 = tributary_events.4
		75 = tributary_events.5
		75 = tributary_events.6
		75 = tributary_events.7
		75 = tributary_events.8
		75 = tributary_events.9
		75 = tributary_events.10
		75 = tributary_events.13
		75 = tributary_events.16
		75 = tributary_events.17
		75 = tributary_events.18
		75 = tributary_events.19
		75 = tributary_events.23
		75 = tributary_events.24
		75 = tributary_events.26
		75 = tributary_events.25
		75 = tributary_events.27

		1000 = 0
	}
}

on_thri_yearly_pulse_4 = {
	random_events = {
		#Low Mandate Events
		10 = china_events.45
		10 = china_events.46
		50 = china_events.47
		10 = china_events.48
		10 = china_events.49
		10 = china_events.50
		50 = china_events.51
		10 = china_events.52
		10 = china_events.53
		50 = china_events.54
		#10 = china_events.55 (triggers via neighbors)
		10 = china_events.56
		75 = china_events.57
		50 = china_events.58
		10 = china_events.59
		50 = china_events.60
	}
}

on_four_year_pulse = {
	random_events = {
		# Colonial Nations
		100 = colonial_nation.1
		100 = colonial_nation.4
		100 = colonial_nation.10
		100 = colonial_nation.12
		100 = colonial_nation.14
		100 = colonial_nation.77
		100 = colonial_nation.100
		100 = colonial_nation.102
		100 = colonial_nation.104
		100 = colonial_nation.106
		100 = colonial_nation.108
		100 = colonial_nation.110
		100 = colonial_nation.112
		100 = colonial_nation.114
		100 = colonial_nation.116
		100 = colonial_nation.118
		100 = colonial_nation.120
		100 = colonial_nation.122
		100 = colonial_nation.124
		100 = colonial_nation.126
		100 = colonial_nation.128
		100 = colonial_nation.130
		100 = colonial_nation.132
		100 = colonial_nation.134
		100 = colonial_nation.182
		100 = colonial_nation.183
		100 = colonial_nation.184
		100 = colonial_nation.185
		100 = colonial_nation.186
		100 = colonial_nation.187
		100 = colonial_nation.188
		100 = colonial_nation.189
		10 = colonial_nation.140
		10 = colonial_nation.142
		10 = colonial_nation.144
		10 = colonial_nation.146
		10 = colonial_nation.148
		10 = colonial_nation.150
		10 = colonial_nation.152
		10 = colonial_nation.154
		10 = colonial_nation.156
		10 = colonial_nation.158
		10 = colonial_nation.160
		10 = colonial_nation.162
		10 = colonial_nation.164
		10 = colonial_nation.166
		10 = colonial_nation.168
		10 = colonial_nation.170
		10 = colonial_nation.172
		10 = colonial_nation.174
		10 = colonial_nation.176

		# Dutch Republic
		100 = dutch_republic.1
		100 = dutch_republic.2
		100 = dutch_republic.3
		100 = dutch_republic.4
		100 = dutch_republic.5
		100 = dutch_republic.6
		100 = dutch_republic.7
		100 = dutch_republic.8
		100 = dutch_republic.9
		100 = dutch_republic.10
		150 = dutch_republic.11
		100 = dutch_republic.13
		100 = dutch_republic.14
		100 = dutch_republic.15
		100 = dutch_republic.16
		100 = dutch_republic.17
		100 = dutch_republic.18
		100 = dutch_republic.19
		100 = dutch_republic.20
		100 = dutch_republic.21
		100 = dutch_republic.22
		100 = dutch_republic.23
		100 = dutch_republic.24
		100 = dutch_republic.25
		100 = dutch_republic.27

		# Republic Factions
		100 = republic_factions.2
		100 = republic_factions.5
		100 = republic_factions.7
		100 = republic_factions.9
		100 = republic_factions.10
		100 = republic_factions.12
		100 = republic_factions.13
		100 = republic_factions.14
		100 = republic_factions.15
		100 = republic_factions.16
		100 = republic_factions.17
		100 = republic_factions.18
		100 = republic_factions.19
		100 = republic_factions.20
		100 = republic_factions.22
		100 = republic_factions.23
		100 = republic_factions.24

		# Revolutionary Republic Factions

		100 = revolutionary_republic_factions.0
		100 = revolutionary_republic_factions.1
		100 = revolutionary_republic_factions.2
		100 = revolutionary_republic_factions.3
		100 = revolutionary_republic_factions.4
		100 = revolutionary_republic_factions.5
		100 = revolutionary_republic_factions.6
		100 = revolutionary_republic_factions.7
		100 = revolutionary_republic_factions.8
		100 = revolutionary_republic_factions.9
		
		# Revolutionary Empires
		100 = napoleon.1
		100 = napoleon.2

		# Pirate Factions
		100 = pirates.10
		100 = pirates.11
		100 = pirates.12
		100 = pirates.13
		100 = pirates.14
		100 = pirates.15
		100 = pirates.16
		100 = pirates.17
		100 = pirates.18
		100 = pirates.19

		# Republican Dictatorship
		100 = republican_dictatorship.1
		100 = republican_dictatorship.2
		100 = republican_dictatorship.3
		100 = republican_dictatorship.4
		100 = republican_dictatorship.5
		100 = republican_dictatorship.6
		100 = republican_dictatorship.7
		100 = republican_dictatorship.8

		# Elective Monarchy
		150 = elective_monarchy.1
		150 = elective_monarchy.2
		25 = elective_monarchy.3
		25 = elective_monarchy.4
		150 = elective_monarchy.6
		150 = elective_monarchy.8
		150 = elective_monarchy.9
		150 = elective_monarchy.10
		150 = elective_monarchy.11
		150 = elective_monarchy.12
		150 = elective_monarchy.14
		150 = elective_monarchy.17
		25 = elective_monarchy.18

		# Free Cities
		25 = free_cities.3
		25 = free_cities.8
		25 = free_cities.10
		25 = free_cities.13
		25 = free_cities.17
		25 = free_cities.19

		#Tribal Federations
		50 = tribal_federation_events.1
		50 = tribal_federation_events.2
		50 = tribal_federation_events.3
		50 = tribal_federation_events.4
		50 = tribal_federation_events.5
		50 = tribal_federation_events.6
		50 = tribal_federation_events.7
		50 = tribal_federation_events.8
		50 = tribal_federation_events.10

		#Empire of China
		100 = china_events.1
		100 = china_events.2
		100 = china_events.3
		100 = china_events.4
		75 = china_events.5
		100 = china_events.6
		100 = china_events.7
		100 = china_events.8
		100 = china_events.9
		100 = china_events.10
		100 = china_events.11
		100 = china_events.12
		100 = china_events.13
		100 = china_events.14
		100 = china_events.15
		100 = china_events.16
		100 = china_events.17
		100 = china_events.18
		100 = china_events.19
		100 = china_events.20
		100 = china_events.21
		100 = china_events.22
		100 = china_events.23
		100 = china_events.24
		100 = china_events.25
		100 = china_events.26
		100 = china_events.27
		100 = china_events.28
		100 = china_events.29
		100 = china_events.30
		100 = china_events.33
		100 = china_events.34
		100 = china_events.35
		100 = china_events.36
		100 = china_events.37
		100 = china_events.38
		100 = china_events.39
		50 = china_events.40
		100 = china_events.41
		100 = china_events.42
		100 = china_events.44

		10 = tortoise.1 # Galapagos Island Tortoises
		
		100 = flavor_pue.5
		
		#Totemism Events
		100 = totemism_flavor.1
		100 = totemism_flavor.7
		100 = totemism_flavor.8
		100 = totemism_flavor.10
		100 = totemism_flavor.11
		100 = totemism_flavor.13
		100 = totemism_flavor.14
		100 = totemism_flavor.15
		100 = totemism_flavor.16
		100 = totemism_flavor.17
		100 = totemism_flavor.18
		
		#Volcano Events
		75 = volcano_events.2

		1000 = 0
	}
}

on_four_year_pulse_2 = {
	random_events = {
		# English Reformation events
		200 = flavor_gbr.103
		200 = flavor_gbr.104
		200 = flavor_gbr.105
		200 = flavor_gbr.106
		200 = flavor_gbr.107
		200 = flavor_gbr.108
		200 = flavor_gbr.109
		200 = flavor_gbr.110
		200 = flavor_gbr.111
		200 = 0
	}
}

on_four_year_pulse_3 = {
	random_events = {
		100 = decadence.1
		100 = decadence.2
		100 = decadence.3
		100 = decadence.4
		100 = decadence.5
		100 = decadence.6
		100 = decadence.7
		100 = decadence.8
		100 = decadence.9
		100 = decadence.10
		200 = 0
	}
}

on_four_year_pulse_4 = {
	random_events = {
		# randomevents.txt
		100 = 3051
		100 = 5008
		100 = 5014
		100 = 5015
		100 = 5017
		100 = 5018
		100 = 5019
		100 = 5020
		100 = 5021
		100 = 5022
		100 = 5023
		100 = 5024
		100 = 5025
		100 = 5027
		100 = 5032
		100 = 5040
		100 = 5045
		100 = 5050
		100 = 5051
		100 = 5052
		100 = 5053
		10 = 5054
		100 = 5055
		100 = 5056
		100 = 5058
		100 = 5059
		100 = 5060
		100 = 5061
		100 = 5064
		100 = 5065
		100 = 5066
		100 = 5068
		100 = 5070
		100 = 5071
		100 = 5072
		100 = 5074
		100 = 5075
		100 = 5076
		100 = 5077
		100 = 5082
		100 = 5083
		100 = 5084
		100 = 5085
		100 = 5086
		100 = 5088
		100 = 5089
		100 = 5090
		100 = 5091
		100 = 5092
		100 = 5093
		100 = 5094
		100 = 5095
		10 = 5096
		100 = 5097
		100 = 5098
		100 = 5099
		100 = 6000
		100 = 6001
		100 = 6003
		100 = 6004
		100 = 6005
		100 = 6006
		100 = 6012
		100 = 6013
		100 = 6015
		100 = 710
		100 = 711
		100 = 712
		100 = 713
		100 = 714
		100 = 715
		100 = 716
		100 = 717
		100 = 718
		100 = 719
		100 = 720
		100 = 722
		100 = 723
		100 = 724
		100 = 725
		100 = 726
		100 = 727
		100 = 728
		100 = 729
		#100 = random_event.1
		300 = random_event.2
		100 = random_event.3
		100 = random_event.4
		100 = random_event.5
		100 = random_event.6
		100 = random_event.7
		100 = random_event.8
		150 = random_event.9
		100 = random_event.10
		100 = random_event.11
		100 = random_event.12
		100 = random_event.13
		100 = random_event.14
		100 = random_event.15
		100 = random_event.16

		100 = random_event.26
		1 = random_event.27
	}
}

on_five_year_pulse = {
	random_events = {

		# Aristocracy 		13  (8g 5b)
		100 = ideagroups.100
		100 = ideagroups.101
		100 = ideagroups.102
		100 = ideagroups.103
		100 = ideagroups.104
		100 = ideagroups.105
		100 = ideagroups.106
		100 = ideagroups.107
		100 = ideagroups.108
		100 = ideagroups.109
		100 = ideagroups.110
		100 = ideagroups.111
		100 = ideagroups.112


		# Plutocracy 		19 (12g 7b)
		100 = ideagroups.200
		100 = ideagroups.201
		100 = ideagroups.202
		100 = ideagroups.203
		100 = ideagroups.204
		100 = ideagroups.205
		100 = ideagroups.206
		100 = ideagroups.207
		100 = ideagroups.208
		100 = ideagroups.209
		100 = ideagroups.210
		100 = ideagroups.211
		100 = ideagroups.212
		100 = ideagroups.213
		100 = ideagroups.214
		100 = ideagroups.215
		100 = ideagroups.216
		100 = ideagroups.217
		100 = ideagroups.218

		# Innovativenes		11 (7g 4b)
		100 = ideagroups.300
		100 = ideagroups.301
		100 = ideagroups.302
		100 = ideagroups.303
		100 = ideagroups.304
		100 = ideagroups.305
		100 = ideagroups.306
		100 = ideagroups.307
		100 = ideagroups.308
		100 = ideagroups.309
		100 = ideagroups.310

		# Religious		18 (11g 7b)
		100 = ideagroups.400
		100 = ideagroups.401
		100 = ideagroups.402
		100 = ideagroups.403
		100 = ideagroups.404
		100 = ideagroups.405
		100 = ideagroups.406
		100 = ideagroups.407
		100 = ideagroups.408
		100 = ideagroups.409
		100 = ideagroups.410
		100 = ideagroups.411
		100 = ideagroups.412
		100 = ideagroups.413
		100 = ideagroups.414
		100 = ideagroups.415
		100 = ideagroups.416
		100 = ideagroups.417


		# Spy			9 (6g 3b)
		100 = ideagroups.500
		100 = ideagroups.501
		100 = ideagroups.502
		100 = ideagroups.503
		100 = ideagroups.504
		100 = ideagroups.505
		100 = ideagroups.506
		100 = ideagroups.507
		100 = ideagroups.508


		# Diplomatic		9 (6g 3b)
		100 = ideagroups.600
		100 = ideagroups.601
		100 = ideagroups.602
		100 = ideagroups.603
		100 = ideagroups.604
		100 = ideagroups.605
		100 = ideagroups.606
		100 = ideagroups.607
		100 = ideagroups.608


		# Offensive 		14 (9g 5b)
		100 = ideagroups.700
		100 = ideagroups.701
		100 = ideagroups.702
		100 = ideagroups.703
		100 = ideagroups.704
		100 = ideagroups.705
		100 = ideagroups.706
		100 = ideagroups.707
		100 = ideagroups.708
		100 = ideagroups.709
		100 = ideagroups.710
		100 = ideagroups.711
		100 = ideagroups.712
		100 = ideagroups.713


		# Defensive		11 (5g 6b)
		100 = ideagroups.800
		100 = ideagroups.801
		100 = ideagroups.802
		100 = ideagroups.803
		100 = ideagroups.804
		100 = ideagroups.805
		100 = ideagroups.806
		100 = ideagroups.807
		100 = ideagroups.808
		100 = ideagroups.809
		100 = ideagroups.810
		100 = ideagroups.811
		100 = ideagroups.812
		100 = ideagroups.813
		100 = ideagroups.814
		100 = ideagroups.815


		# Trade			6 (7g 4b)
		100 = ideagroups.900
		100 = ideagroups.901
		100 = ideagroups.902
		100 = ideagroups.903
		100 = ideagroups.904
		100 = ideagroups.905
		100 = ideagroups.906
		100 = ideagroups.907
		100 = ideagroups.908
		100 = ideagroups.909
		100 = ideagroups.910

		# Maritime			22 (14g 8b)
		100 = ideagroups.1000
		100 = ideagroups.1001
		100 = ideagroups.1002
		100 = ideagroups.1003
		100 = ideagroups.1004
		100 = ideagroups.1005
		100 = ideagroups.1006
		100 = ideagroups.1007
		100 = ideagroups.1008
		100 = ideagroups.1009
		100 = ideagroups.1010
		100 = ideagroups.1011
		100 = ideagroups.1012
		100 = ideagroups.1013
		100 = ideagroups.1014
		100 = ideagroups.1015
		100 = ideagroups.1016
		100 = ideagroups.1017
		100 = ideagroups.1018
		100 = ideagroups.1019
		100 = ideagroups.1020
		100 = ideagroups.1021

		# Economic		11 (7g 4b)
		100 = ideagroups.1100
		100 = ideagroups.1101
		100 = ideagroups.1102
		100 = ideagroups.1103
		100 = ideagroups.1104
		100 = ideagroups.1105
		100 = ideagroups.1106
		100 = ideagroups.1107
		100 = ideagroups.1108
		100 = ideagroups.1109
		100 = ideagroups.1110

		# Exploration		11 (7g 4b)
		100 = ideagroups.1200
		100 = ideagroups.1201
		100 = ideagroups.1202
		100 = ideagroups.1203
		100 = ideagroups.1204
		100 = ideagroups.1205
		100 = ideagroups.1206
		100 = ideagroups.1207
		100 = ideagroups.1208
		100 = ideagroups.1209
		100 = ideagroups.1210

		# Quality		11 (7g 4b)
		100 = ideagroups.1300
		100 = ideagroups.1301
		100 = ideagroups.1302
		100 = ideagroups.1303
		100 = ideagroups.1304
		100 = ideagroups.1305
		100 = ideagroups.1306
		100 = ideagroups.1307
		100 = ideagroups.1308
		100 = ideagroups.1309
		100 = ideagroups.1310

		# Quantity		11 (7g 4b)
		100 = ideagroups.1400
		100 = ideagroups.1401
		100 = ideagroups.1402
		100 = ideagroups.1403
		100 = ideagroups.1404
		100 = ideagroups.1405
		100 = ideagroups.1406
		100 = ideagroups.1407
		100 = ideagroups.1408
		100 = ideagroups.1409
		100 = ideagroups.1410


		# Expansion		11 (7g 4b)
		100 = ideagroups.1500
		100 = ideagroups.1501
		100 = ideagroups.1502
		100 = ideagroups.1503
		100 = ideagroups.1504
		100 = ideagroups.1505
		100 = ideagroups.1506
		100 = ideagroups.1507
		100 = ideagroups.1508
		100 = ideagroups.1509
		100 = ideagroups.1510

		# Administrative	8 (5g 3b)
		100 = ideagroups.1600
		100 = ideagroups.1601
		100 = ideagroups.1602
		100 = ideagroups.1605
		100 = ideagroups.1606
		100 = ideagroups.1607
		100 = ideagroups.1608
		100 = ideagroups.1609

		# Naval		11 (7g 4b)
		100 = ideagroups.1700
		100 = ideagroups.1701
		100 = ideagroups.1702
		100 = ideagroups.1703
		100 = ideagroups.1704
		100 = ideagroups.1705
		100 = ideagroups.1706
		100 = ideagroups.1707
		100 = ideagroups.1708
		100 = ideagroups.1709
		100 = ideagroups.1710

		# Influence		11 (7g 4b)
		100 = ideagroups.1800
		100 = ideagroups.1801
		100 = ideagroups.1802
		100 = ideagroups.1803
		100 = ideagroups.1804
		100 = ideagroups.1805
		100 = ideagroups.1806
		100 = ideagroups.1807
		100 = ideagroups.1808
		100 = ideagroups.1809
		100 = ideagroups.1810

		# Humanist		11 (7g 4b)
		100 = ideagroups.1900
		100 = ideagroups.1901
		100 = ideagroups.1902
		100 = ideagroups.1903
		100 = ideagroups.1904
		100 = ideagroups.1905
		100 = ideagroups.1906
		100 = ideagroups.1907
		100 = ideagroups.1908
		100 = ideagroups.1909
		100 = ideagroups.1910

		# Horde Ideas		10 (8g 2b)
		100 = ideagroups.1922
		100 = ideagroups.1923
		100 = ideagroups.1924
		100 = ideagroups.1925
		100 = ideagroups.1926
		100 = ideagroups.1927
		100 = ideagroups.1928
		100 = ideagroups.1929
		100 = ideagroups.1930
		100 = ideagroups.1931
		
		#Theocracy Ideas		11 (9g 2b)
		100 = ideagroups.1911
		100 = ideagroups.1912
		100 = ideagroups.1913
		100 = ideagroups.1914
		100 = ideagroups.1915
		100 = ideagroups.1916
		100 = ideagroups.1917
		100 = ideagroups.1918
		100 = ideagroups.1919
		100 = ideagroups.1920
		100 = ideagroups.1921

		# Indigenous		10 (6g 4b)
		100 = ideagroups.1932
		100 = ideagroups.1933
		100 = ideagroups.1934
		100 = ideagroups.1935
		100 = ideagroups.1936
		100 = ideagroups.1937
		100 = ideagroups.1938
		100 = ideagroups.1939
		100 = ideagroups.1940
		100 = ideagroups.1941

		# Infrastructure		10 (5g 5b)
		100 = ideagroups.2000
		100 = ideagroups.2001
		100 = ideagroups.2002
		100 = ideagroups.2003
		100 = ideagroups.2004
		100 = ideagroups.2005
		100 = ideagroups.2006
		100 = ideagroups.2007
		100 = ideagroups.2008
		100 = ideagroups.2009
		
		#Court Events			8 (6g 2b)
		100 = ideagroups.2010
		100 = ideagroups.2011
		100 = ideagroups.2012
		100 = ideagroups.2013
		100 = ideagroups.2014
		100 = ideagroups.2015
		100 = ideagroups.2016
		100 = ideagroups.2017
		
		#Mercenary Ideas		9 (6g 3b)
		100 = ideagroups.2020
		100 = ideagroups.2021
		100 = ideagroups.1603
		100 = ideagroups.1604
		100 = ideagroups.1610
		100 = ideagroups.2025
		100 = ideagroups.2026
		100 = ideagroups.2027
		100 = ideagroups.2028
		
		1000 = 0
	}

	events = {
		seven_cities_events.1000 #Clearing of Seven Cities Hunt when goal is no longer possible
	}
}


# Estates pulse
on_five_year_pulse_2 = {
	random_events = {
		# Burghers
		100 = burghers_estate_events.1
		100 = burghers_estate_events.2
		100 = burghers_estate_events.3
		100 = burghers_estate_events.4
		100 = burghers_estate_events.5
		100 = burghers_estate_events.6
		100 = burghers_estate_events.7
		100 = burghers_estate_events.8
		100 = burghers_estate_events.9
		400 = burghers_estate_events.10 #Demands
		100 = burghers_estate_events.11 #Bonus
		100 = burghers_estate_events.12
		100 = burghers_estate_events.13
		400 = burghers_estate_events.14 #Demands
		100 = burghers_estate_events.15 #Disloyal
		# Nobles
		100 = nobles_estate_events.1 #Demands
		100 = nobles_estate_events.2
		100 = nobles_estate_events.3
		100 = nobles_estate_events.4
		400 = nobles_estate_events.5 #Demands
		100 = nobles_estate_events.6
		100 = nobles_estate_events.7
		400 = nobles_estate_events.8 #Disloyal
		400 = nobles_estate_events.9 #Disloyal
		50 = nobles_estate_events.10
		100 = nobles_estate_events.11 #Bonus
		# Clergy
		100 = church_estate_events.1
			#Regional Variations:
			100 = church_estate_events.101
			100 = church_estate_events.102
			100 = church_estate_events.103
			100 = church_estate_events.104
			100 = church_estate_events.105
		100 = church_estate_events.2
		100 = church_estate_events.3
		100 = church_estate_events.4
		400 = church_estate_events.5 #Disloyal
		400 = church_estate_events.6 #Demands
		100 = church_estate_events.7 #Bonus
		100 = church_estate_events.8
		100 = church_estate_events.9
		100 = church_estate_events.10
		# Dhimmi
		100 = dhimmi_estate_events.1
		400 = dhimmi_estate_events.2 #Demands
		100 = dhimmi_estate_events.3
		100 = dhimmi_estate_events.4
		100 = dhimmi_estate_events.5
		100 = dhimmi_estate_events.6
		400 = dhimmi_estate_events.7 #Disloyal
		100 = dhimmi_estate_events.8
		# Cossacks
		100 = cossack_estate_events.1
		#100 = cossack_estate_events.2 (triggers in neighbor country)
		100 = cossack_estate_events.6
		100 = cossack_estate_events.7
		100 = cossack_estate_events.8
		100 = cossack_estate_events.9
		100 = cossack_estate_events.10
		100 = cossack_estate_events.11
		400 = cossack_estate_events.12 #Disloyal
		100 = cossack_estate_events.13
		400 = cossack_estate_events.14 #Demands
		# Tribes
		100 = tribal_estate_events.1
		100 = tribal_estate_events.2
		100 = tribal_estate_events.3
		100 = tribal_estate_events.4
		100 = tribal_estate_events.5
		100 = tribal_estate_events.6
		100 = tribal_estate_events.7
		100 = tribal_estate_events.8
		100 = tribal_estate_events.9
		150 = tribal_estate_events.11 #Demands
		150 = tribal_estate_events.12 #Demands
		150 = tribal_estate_events.13 #Demands
		150 = tribal_estate_events.14 #Demands
		# Marathas
		100 = marathas_estate_events.2
		100 = marathas_estate_events.3
		100 = marathas_estate_events.4
		100 = marathas_estate_events.5
		100 = marathas_estate_events.6
		400 = marathas_estate_events.7 # Demands
		100 = marathas_estate_events.8
		100 = marathas_estate_events.9
		100 = marathas_estate_events.10
		400 = marathas_estate_events.11 # Disloyal
		# Brahmins
		400 = brahmins_estate_events.2 # demands
		100 = brahmins_estate_events.3
		100 = brahmins_estate_events.4
		100 = brahmins_estate_events.5
		400 = brahmins_estate_events.6 # disloyal
		100 = brahmins_estate_events.7
		100 = brahmins_estate_events.8
		100 = brahmins_estate_events.9
		100 = brahmins_estate_events.10
		100 = brahmins_estate_events.11
		# Jains
		100 = jains_estate_events.2
		100 = jains_estate_events.3
		100 = jains_estate_events.4
		100 = jains_estate_events.5
		100 = jains_estate_events.6
		100 = jains_estate_events.7
		400 = jains_estate_events.8 # Disloyal
		100 = jains_estate_events.9
		400 = jains_estate_events.10 # Demands
		100 = jains_estate_events.11
		# Vaishyas
		100 = vaisyas_estate_events.2
		100 = vaisyas_estate_events.3
		100 = vaisyas_estate_events.4
		100 = vaisyas_estate_events.5
		100 = vaisyas_estate_events.6
		100 = vaisyas_estate_events.7
		100 = vaisyas_estate_events.8
		400 = vaisyas_estate_events.9
		100 = vaisyas_estate_events.10
		100 = vaisyas_estate_events.11
		# Rajputs
		100 = rajputs_estate_events.2
		100 = rajputs_estate_events.3
		100 = rajputs_estate_events.4
		100 = rajputs_estate_events.5
		400 = rajputs_estate_events.6
		100 = rajputs_estate_events.7
		400 = rajputs_estate_events.8
		100 = rajputs_estate_events.9
		100 = rajputs_estate_events.10
		100 = rajputs_estate_events.11
		# Janissaries
		100 = janissaries_estate_events.1
		100 = janissaries_estate_events.2
		100 = janissaries_estate_events.3
		100 = janissaries_estate_events.4
		100 = janissaries_estate_events.5
		100 = janissaries_estate_events.6
		100 = janissaries_estate_events.7
		400 = janissaries_estate_events.8 # Disloyal
		400 = janissaries_estate_events.9 # Demands
		100 = janissaries_estate_events.10
		100 = janissaries_estate_events.11
		100 = janissaries_estate_events.12
		100 = janissaries_estate_events.13
		# Random
		5 = flavor_fra.9500
		1000 = 0
	}
}

on_five_year_pulse_3 = {
	random_events = {
		100 = estate_regency_events.2
		100 = estate_regency_events.3
		100 = estate_regency_events.4
		100 = estate_regency_events.5
		100 = estate_regency_events.6
		100 = estate_regency_events.7
		100 = estate_regency_events.9
		100 = propagate_religion_events.1
		100 = propagate_religion_events.2
		100 = propagate_religion_events.3
		100 = propagate_religion_events.4
		100 = propagate_religion_events.5
		100 = propagate_religion_events.6
		100 = propagate_religion_events.8
		100 = propagate_religion_events.9
		100 = propagate_religion_events.10
		#100 = propagate_religion_events.11 #Province event
		1000 = 0
	}
}

on_five_year_pulse_4 = {
	if = { #fail-safe for flavor_pap.7, making religious leagues happen at some point if there is no PAP
		limit = {
			is_year = 1610
			NOT = { exists = PAP }
			NOT = { has_global_flag = counter_reformation }
		}
		set_global_flag = counter_reformation
	}
	#fail-safe if for whatever reason these flags stay after being used in events
	if = {
		limit = {
			had_country_flag = {
				flag = advisor_events_adm
				days = 720
			}
		}
		clr_country_flag = advisor_events_adm
	}
	if = {
		limit = {
			had_country_flag = {
				flag = advisor_events_dip
				days = 720
			}
		}
		clr_country_flag = advisor_events_dip
	}
	if = {
		limit = {
			had_country_flag = {
				flag = advisor_events_mil
				days = 720
			}
		}
		clr_country_flag = advisor_events_mil
	}
	#Clearing of Jewish events flags
	if = {
		limit = {
			had_country_flag = {
				flag = shalosh_regalim
				days = 365
			}
		}
		clr_country_flag = shalosh_regalim
	}
	random_events = {
		200 = 0
		100 = kalmar_union_events.7
		100 = kalmar_union_events.8
		100 = kalmar_union_events.9
	}
}

# El Dorado
# FROM = country doing the exploring, ROOT = province discovered
on_explore_coast = {
	random_events = {
		10 = exploration_events.1
		10 = exploration_events.2
		10 = exploration_events.3
		10 = exploration_events.4
		10 = exploration_events.5
		10 = exploration_events.6
		10 = exploration_events.7
		10 = exploration_events.8
		10 = exploration_events.9
		10 = exploration_events.10
		10 = exploration_events.11
		10 = exploration_events.12
		10 = exploration_events.13
		10 = exploration_events.14
		10 = exploration_events.15
	}
}
on_conquistador_empty = {
	random_events = {
		10 = seven_cities_events.1
		10 = seven_cities_events.2
		10 = seven_cities_events.3
		10 = seven_cities_events.4
		10 = seven_cities_events.5
		10 = seven_cities_events.6
		10 = seven_cities_events.7
		10 = seven_cities_events.8

		10 = seven_cities_events.100
		10 = seven_cities_events.101
		10 = seven_cities_events.102
		10 = seven_cities_events.103
		10 = seven_cities_events.104
		10 = seven_cities_events.105

		50 = seven_cities_events.200
		50 = seven_cities_events.201
		50 = seven_cities_events.202
		50 = seven_cities_events.203
		50 = seven_cities_events.204
		50 = seven_cities_events.205
		50 = seven_cities_events.206
		50 = seven_cities_events.207
		50 = seven_cities_events.208
		50 = seven_cities_events.209
		50 = seven_cities_events.210
		50 = seven_cities_events.211
		50 = seven_cities_events.212
		50 = seven_cities_events.213
		50 = seven_cities_events.214
		50 = seven_cities_events.215
		50 = seven_cities_events.216
		50 = seven_cities_events.217
		50 = seven_cities_events.218
		50 = seven_cities_events.219
		50 = seven_cities_events.220
		50 = seven_cities_events.221
		50 = seven_cities_events.222
		50 = seven_cities_events.223

		10 = seven_cities_events.302
		10 = seven_cities_events.303
		10 = seven_cities_events.308
		10 = seven_cities_events.309

		10 = seven_cities_events.400
		10 = seven_cities_events.401
		10 = seven_cities_events.402
		10 = seven_cities_events.405
		10 = seven_cities_events.406
		10 = seven_cities_events.407
		10 = seven_cities_events.408
		10 = seven_cities_events.409
		10 = seven_cities_events.410
		10 = seven_cities_events.413
		10 = seven_cities_events.414

		2000 = 0
	}
}

on_conquistador_native = {
	random_events = {
		10 = seven_cities_events.300
		10 = seven_cities_events.301
		10 = seven_cities_events.303
		10 = seven_cities_events.304
		10 = seven_cities_events.305
		10 = seven_cities_events.306
		10 = seven_cities_events.307
		10 = seven_cities_events.308
		10 = seven_cities_events.309
		10 = seven_cities_events.310

		250 = 0
	}
}

on_buy_religious_reform = {
	events = {
		religious_reforms.1
		religious_reforms.2
		religious_reforms.3
	}
}

on_circumnavigation = {
	events = {
		exploration_events.17
		exploration_events.16 #First Circumnavigation Europe
	}
}

on_become_free_city = {
	events = {
		free_cities.1
	}
}

on_remove_free_city = {
	events = {
		free_cities.2
	}
}

on_revoke_estate_land_ai = { #AI can't handle the rebels atm or perform a gradual revoke, sorry
	add_province_modifier = {
		name = revoked_estate_modifier
		duration = 5475 #15 years
	}
}

on_revoke_estate_land = {
	add_province_modifier = {
		name = revoked_estate_modifier
		duration = 5475 #15 years
	}
	if = {
		limit = {
			has_estate = estate_cossacks
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_cossacks
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = cossack_rebels
			size = 1
		}
		province_event = { id = cossack_estate_events.15 }
	}
	if = {
		limit = {
			has_estate = estate_dhimmi
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_dhimmi
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = religious_rebels
			size = 1
		}
		province_event = { id = dhimmi_estate_events.9 }
	}
	if = {
		limit = {
			has_estate = estate_church
			has_owner_religion = yes
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_church
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = religious_rebels
			size = 1
		}
		province_event = { id = church_estate_events.11 }
	}
	if = {
		limit = {
			has_estate = estate_church
			has_owner_religion = no
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_church
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = church_estate_events.11 }
	}
	if = {
		limit = {
			has_estate = estate_nobles
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_nobles
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = noble_rebels
			size = 1
		}
		province_event = { id = nobles_estate_events.12 }
	}
	if = {
		limit = {
			has_estate = estate_burghers
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_burghers
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = burghers_estate_events.16 }
	}
	if = {
		limit = {
			has_estate = estate_nomadic_tribes
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_nomadic_tribes
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = tribal_rebels
			size = 1
		}
		province_event = { id = tribal_estate_events.10 }
	}
	if = {
		limit = {
			has_estate = estate_brahmins
			owner = {
				NOT = {
					religion = hinduism
				}
				NOT = {
					estate_loyalty = {
						estate = estate_brahmins
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = religious_rebels
			size = 1
		}
		province_event = { id = brahmins_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_brahmins
			owner = {
				religion = hinduism
				NOT = {
					estate_loyalty = {
						estate = estate_brahmins
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = brahmins_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_vaisyas
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_vaisyas
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = vaisyas_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_rajput
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_rajput
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = noble_rebels
			size = 1
		}
		province_event = { id = rajputs_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_jains
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_jains
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = jains_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_maratha
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_maratha
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = noble_rebels
			size = 1
		}
		province_event = { id = marathas_estate_events.1 }
	}
}

on_revoke_estate_land_ai_post = {
	add_local_autonomy = 25
}
on_revoke_estate_land_post = {
	add_local_autonomy = 25
}

on_grant_estate_land = {
	if = {
		limit = {
			has_province_modifier = revoked_estate_modifier
		}
		remove_province_modifier = revoked_estate_modifier
	}
}

on_death_has_harem = {
	if = {
		limit = {
			has_heir = no
		}
		country_event = { id = harem_events.2 }
	}
}

on_select_heir_from_harem = {
}

on_fetishist_cult_change = {
	country_event = { id = fetishist_flavor.302 days = 10 } #removing tomb if incompatible cult is picked
	country_event = { id = fetishist_flavor.304 days = 10 } #rebuilding tomb if lost
	if = {
		limit = {
			has_country_flag = lost_ancestral_lands
			NOT = { has_adopted_cult = zanahary_cult }
			NOT = { has_adopted_cult = central_african_ancestor_cult }
		}
		clr_country_flag = lost_ancestral_lands
	}
}

# country
on_gain_great_power_status = {
	if = {
		limit = {
			NOT = { has_country_flag = became_great_power_flag }
		}
		set_country_flag = became_great_power_flag
	}
}

# country
on_lose_great_power_status = {
}

# province
on_province_religion_converted = {
	on_province_religion_changed_effect = yes
	on_province_religion_converted_effect = yes
	if = {
		limit = { 
			owner = { 
				has_government_attribute = more_25_tax_in_true_faith_provinces
			}
			religion_group = owner 
			NOT = { has_province_modifier = ottoman_siyasah_tax_reform_tax }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_tax
			duration = -1
		}
	}
	if = {
		limit = {
			OR = {
				NOT = { 
					owner = { has_government_attribute = more_25_tax_in_true_faith_provinces } 
				}
				NOT = { religion_group = owner }
			}
			has_province_modifier = ottoman_siyasah_tax_reform_tax
		}
		remove_province_modifier = ottoman_siyasah_tax_reform_tax
	}
	if = {
		limit = { 
			owner = { 
				has_government_attribute = more_15_manpower_in_heathen_provinces
			}
			NOT ={ religion_group = owner }
			NOT = { has_province_modifier = ottoman_siyasah_tax_reform_manpower }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_manpower
			duration = -1
		}
	}
	if = {
		limit = {
			OR = {
				NOT = { 
					owner = { has_government_attribute = more_15_manpower_in_heathen_provinces } 
				}
				religion_group = owner 
			}
			has_province_modifier = ottoman_siyasah_tax_reform_manpower
		}
		remove_province_modifier = ottoman_siyasah_tax_reform_manpower
	}
}

on_province_religion_changed = {
	on_province_religion_changed_effect = yes
	if = {
		limit = { 
			owner = { 
				has_government_attribute = more_25_tax_in_true_faith_provinces
			}
			religion_group = owner 
			NOT = { has_province_modifier = ottoman_siyasah_tax_reform_tax }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_tax
			duration = -1
		}
	}
	if = {
		limit = {
			OR = {
				NOT = { 
					owner = { has_government_attribute = more_25_tax_in_true_faith_provinces } 
				}
				NOT = { religion_group = owner }
			}
			has_province_modifier = ottoman_siyasah_tax_reform_tax
		}
		remove_province_modifier = ottoman_siyasah_tax_reform_tax
	}
	if = {
		limit = { 
			owner = { 
				has_government_attribute = more_15_manpower_in_heathen_provinces
			}
			NOT ={ religion_group = owner }
			NOT = { has_province_modifier = ottoman_siyasah_tax_reform_manpower }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_manpower
			duration = -1
		}
	}
	if = {
		limit = {
			OR = {
				NOT = { 
					owner = { has_government_attribute = more_15_manpower_in_heathen_provinces } 
				}
				religion_group = owner 
			}
			has_province_modifier = ottoman_siyasah_tax_reform_manpower
		}
		remove_province_modifier = ottoman_siyasah_tax_reform_manpower
	}
}

# province, manually conversion
on_province_culture_converted = {
	on_province_culture_converted_estate_privilges_effect = yes
	judaism_on_province_culture_converted_effect = yes
	imperial_modifiers_on_province_change_culture_or_change_owner_effect = yes
	on_province_culture_change_effect = yes
	on_province_culture_converted_effect = yes
}

# province, general conversion through effects
on_province_culture_changed = {
	on_province_culture_converted_estate_privilges_effect = yes
	judaism_on_province_culture_converted_effect = yes
	imperial_modifiers_on_province_change_culture_or_change_owner_effect = yes
	on_province_culture_change_effect = yes
}

# THIS = Province, FROM = Country who Propogated
on_convert_by_trade_policy = {
	on_convert_by_trade_policy_effect = yes
}

# province
# FROM = old owner
on_province_owner_change = {
	events = {
		japan.1			#Fall of the current Shogun
		flavor_tur.207	#Victory over the Knights
	}
	on_province_owner_change_government_effect = yes

	if = {
		limit = {
			owned_by = SRU
			exists = ARA
		}
		ARA = {
			set_country_flag = ARA_defeat_saruhan
		}
	}
	if = {
		limit = {
			NOT = { owner = { religion_group = muslim } }
			has_province_modifier = sufi_shrine
		}
		remove_province_modifier = sufi_shrine
	}
	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
	}
	on_province_owner_change_estate_privileges_effect = yes
	imperial_modifiers_on_province_change_culture_or_change_owner_effect = yes
	
	if = {
		limit = {
			region = indo_china_region
			has_building = farm_estate
			trade_goods = grain
			owner = {
				has_mission = mnd_khm_irrigation 
				NOT = {
					OR = {
						has_estate = estate_vaisyas
						has_estate = estate_burghers
					}
				}
			}
		}
		add_province_modifier = {
			name = grain_production_improved
			duration = 7300
		}
	}

	if = {
		limit = {
			trade_goods = gold
			NOT = { has_province_modifier = estate_burghers_control_over_gold_mine }
			owner = {
				has_estate_privilege = estate_burghers_control_over_the_mint
			}
		}
		add_province_modifier = {
			name = estate_burghers_control_over_gold_mine
			duration = -1
		}
	}
	
	if = {
		limit = {
			province_id = 379
			owner = {
				NOT = { religion = jewish }
			}
		}
		remove_country_modifier = third_temple_country_modifier
	}
	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 = { 
			owner = { NOT = { has_reform = jap_gokaido_reform } }
		}
		remove_province_modifier = jap_gokaido_modifier
	}
	if = {
		limit = { 
			owner = { 
				has_government_attribute = more_15_manpower_in_heathen_provinces
			}
			NOT ={ religion_group = owner }
			NOT = { has_province_modifier = ottoman_siyasah_tax_reform_manpower }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_manpower
			duration = -1
		}
	}
	if = {
		limit = { 
			owner = { 
				has_government_attribute = more_15_manpower_in_heathen_provinces
			}
			NOT ={ religion_group = owner }
			NOT = { has_province_modifier = ottoman_siyasah_tax_reform_manpower }
		}
		add_province_modifier = {
			name = ottoman_siyasah_tax_reform_manpower
			duration = -1
		}
	}
	if = {
		limit = {
			owner = { has_government_attribute = negate_unaccepted_levantine_culture }
			culture_group = turko_semitic
			has_owner_accepted_culture = no
		}
		add_province_modifier = {
			name = hsn_ayyubid_tolerance
			duration = -1
		}
	}
	if = {
		limit = {
			owner = {
				has_government_attribute = seven_provinces_organization
			}
		}
		if = {
			limit = {
				region = low_countries_region
				culture_group = ROOT
			}
			add_province_modifier = {
				name = ned_seven_provinces_organization_positive_modifier
				duration = -1
			}
		}
		else_if = {
			limit = {
				NOT = { region = low_countries_region }
				continent = europe
			}
			add_province_modifier = {
				name = ned_seven_provinces_organization_negative_modifier
				duration = -1
			}
		}
	}
	
	if = {
		limit = {
			owner = {
				has_country_flag = ned_buffed_forts_flag
				NOT = {
					full_idea_group = defensive_ideas
				}
			}
			region = low_countries_region
			has_fort_building_trigger = yes
		}
		add_province_modifier = {
			name = ned_low_countries_fort_buff
			duration = -1
			hidden = yes
		}
	}
	else_if = {
		limit = {
			owner = {
				has_country_flag = ned_buffed_forts_flag
				full_idea_group = defensive_ideas
			}
			region = low_countries_region
			has_fort_building_trigger = yes
		}
		add_province_modifier = {
			name = ned_low_countries_fort_buff_buffed
			duration = -1
			hidden = yes
		}
	}
	
	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 = {
			OR = {
				continent = south_america
				continent = north_america
				continent = new_world
			}
			colonial_territory_trigger_on_action = yes
		}
		set_province_flag = SUN_colonial_territory
	}
	if = {
		limit = {
			owner = {
				has_country_flag = INC_royal_roads_flag 
			}
			OR = {
				has_terrain = mountain
				has_terrain = highlands
				has_terrain = hills
			}
			continent = south_america
		}
		add_province_modifier = {
			name = INC_royal_roads
			duration = -1
		}
	}
	
	if = {
		limit = {
			owner = {
				has_estate_privilege = estate_church_INC_idol_making 
			}
			trade_goods = gold
		}
		add_province_modifier = {
			name = INC_gold_debuff
			duration = -1
		}
	}
	
	if = {
		limit = {
			owner = {
				has_country_flag = azt_temples_buffs_flag
			}
			has_tax_building_trigger = yes
		}
		add_province_modifier = {
			name = azt_religious_classes
			duration = -1
			hidden = yes
		}
	}
	
	if = {
		limit = {
			owner = {
				has_government_attribute = chinampa_farms_mechanic
			}
			trade_goods = grain
		}
		add_province_modifier = {
			name = chinampa_farms_modifier
			duration = -1
			hidden = yes
		}
	}

	if = {
        limit = {
            owner = {
                has_estate_privilege = estate_nobles_vegvar_system
            }
            has_fort_building_trigger = yes
            any_neighbor_province = {
                NOT = { owned_by = ROOT }
            }
        }
        add_province_modifier = {
            name = estate_nobles_vegvar_system_modifier
            duration = -1
        }
    }
	if = {
        limit = {
			has_province_modifier = estate_nobles_vegvar_system_modifier
            NOT = {
				any_neighbor_province = {
                	NOT = { owned_by = ROOT }
            	}
			}
        }
        remove_province_modifier = estate_nobles_vegvar_system_modifier
    }
    if = {
        limit = {
            owner = {
                has_estate_privilege = estate_nobles_vegvar_system
            }
        }
        owner = {
            every_owned_province = {
                limit = {
                    has_province_modifier = estate_nobles_vegvar_system_modifier
                    has_fort_building_trigger = yes
                    all_neighbor_province = {
                        owned_by = ROOT
                    }
                }
                remove_province_modifier = estate_nobles_vegvar_system_modifier
            }
        }
    }
	if = {
        limit = {
			has_province_modifier = estate_nobles_vegvar_system_modifier
			NOT = {
				owner = {
					has_estate_privilege = estate_nobles_vegvar_system
				}
				has_fort_building_trigger = yes
				any_neighbor_province = {
					NOT = { owned_by = ROOT }
				}
			}
        }
		remove_province_modifier = estate_nobles_vegvar_system_modifier
	}
	if = {
        limit = {
			has_province_modifier = estate_nobles_vegvar_system_modifier
			NOT = {
				owner = {
					has_estate_privilege = estate_nobles_vegvar_system
				}
				has_fort_building_trigger = yes
				any_neighbor_province = {
					NOT = { owned_by = ROOT }
				}
			}
        }
		remove_province_modifier = estate_nobles_vegvar_system_modifier
	}
	if = {
		limit = {
			FROM = {
				has_estate_privilege = estate_nobles_vegvar_system
			}
		}
		if = {
			limit = {
				any_neighbor_province = {
					owned_by = FROM
				}
				FROM = {
					has_estate_privilege = estate_nobles_vegvar_system
				}
			}
			every_neighbor_province = {
				limit = {
					owned_by = FROM
					has_fort_building_trigger = yes
					NOT = {
						has_province_modifier = estate_nobles_vegvar_system_modifier
					}
				}
				add_province_modifier = {
					name = estate_nobles_vegvar_system_modifier
					duration = -1
				}
			}
		}
	}
	if = {
        limit = {
			NOT = {
				has_province_modifier = estate_nobles_vegvar_system_modifier
			}
			owner = {
				has_estate_privilege = estate_nobles_vegvar_system
			}
			has_fort_building_trigger = yes
			any_neighbor_province = {
				NOT = { owned_by = ROOT }
			}
        }
        add_province_modifier = {
            name = estate_nobles_vegvar_system_modifier
            duration = -1
        }
	}
	if = {
		limit = {
			owner = {
				has_country_flag = enable_gothic_invasion_cb_flag
			}
			OR = {
				region = north_german_region
				region = south_german_region
			}
		}
		add_province_modifier = {
			name = feo_return_to_gothic_ways
			duration = -1
		}
	}
}

# country
on_parliament_debate_reset = {
	on_parliament_debate_reset_effect = yes
}

#province
on_parliament_seat_given = {
	on_parliament_seat_given_effect = yes
}

#province
on_parliament_seat_lost = {
	on_parliament_seat_lost_effect = yes
}

# country
on_parliament_debate_failed = {
	on_parliament_debate_failed_effect = yes
}

# country
on_parliament_debate_succeeded = {
	on_parliament_debate_succeeded_effect = yes
	increase_issue_passed_counter = yes
}

# country
on_harmonized_pagan = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.1
	}
}
on_harmonized_christian = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.2
	}
}
on_harmonized_muslim = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.3
	}
}
on_harmonized_jewish_group = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.5
	}
}
on_harmonized_zoroastrian_group = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.6
	}
}
on_harmonized_dharmic = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.4
	}
}
on_harmonized_mahayana = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.9
	}
}
on_harmonized_buddhism = { #Theravada
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.8
	}
}
on_harmonized_shinto = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.7
	}
}
on_harmonized_vajrayana = {
	on_harmonized_effect = yes
	on_harmonized_religion_estate_privileges_effect = yes
	events = {
		confucian_events.10
	}
}

# province
on_consecrate_patriarch = {
	if = {
		limit = {
			owner = { has_country_flag = has_improved_consecration }
		}
		every_province_in_state = {
			limit = { has_state_patriach = yes }
			add_province_modifier = {
				name = consecrated_ground
				duration = -1
				hidden = yes
			}
		}
	}
	if = {
		limit = {
			owner = { has_country_flag = BYZ_extra_patriarch_authority }
			NOT = { has_province_flag = BYZ_consecrated_here_bonus }
		}
		owner = {
			add_patriarch_authority = 0.025
		}
		every_province_in_state = {
			limit = { has_state_patriach = yes }
			set_province_flag = BYZ_consecrated_here_bonus
		}
	}
	if = {
		limit = {
			owner = { has_country_flag = geo_metropolitan_flag }
		}
		every_province_in_state = {
			add_province_modifier = {
				name = geo_consecrated_ground
				duration = -1
				hidden = yes
			}
		}
	}
	if = {
		limit = {
			owner = { has_country_flag = metropolitan_double_buff }
		}
		every_province_in_state = {
			add_province_modifier = {
				name = tre_consecrated_ground
				duration = -1
				hidden = yes
			}
		}
	}
}

# country. from = overlord
on_accept_tribute = {
	if = {
		limit = {
			FROM = {
				has_country_flag = azt_imperial_tributes_flag
			}
		}
		FROM = {
			add_estate_loyalty = {
				estate = estate_nobles
				loyalty = 1
			}
		}
	}
	if = {
		limit = {
			FROM = {
				has_country_flag = basaqs_tribes_loyalty_from_tribute_flag
				has_estate_privilege = estate_nomadic_tribes_basqaq_autonomy
			}
		}
		FROM = {
			add_estate_loyalty = {
				estate = estate_nomadic_tribes
				loyalty = 1
			}
		}
	}
	if = {
		limit = {
			FROM = {
				has_country_flag = basaqs_tribes_loyalty_from_tribute_flag
				has_estate_privilege = estate_nobles_basqaq_autonomy
			}
		}
		FROM = {
			add_estate_loyalty = {
				estate = estate_nobles
				loyalty = 1
			}
		}
	}
}

# country. from = overlord
on_refuse_tribute = {
}

# country
on_leader_recruited = {
	if = {
		limit = {
			has_estate_privilege = estate_nobles_command_of_the_military
		}
		add_estate_influence_modifier = {
			estate = estate_nobles
			influence = 5
			duration = 3650
			desc = EST_VAL_NOBLE_LEADER
		}
	}
	if = {
		limit = { has_government_attribute = theocratic_monarchy_mechanic }
		change_statists_vs_orangists = 0.01
	}
}

# country
on_general_recruited = {
	on_general_recruited_effect = yes
	if = {
		limit = {
			has_reform = sparapet_office
		}
		add_army_tradition = 0.25
	}
}

# country
on_admiral_recruited = {
	if = {
		limit = { has_country_flag = admirals_give_army_professionalism }
		add_army_professionalism = 0.005
	}
	if = {
		limit = { 
			OR = {
				has_country_modifier = pol_global_maritime_empire_modifier 
				has_country_modifier = pol_global_maritime_empire_2_modifier
			}
		}
		add_navy_tradition = 1 
	}
	if = {
		limit = {
			has_country_flag = improve_nav_prof_flag
		}
		add_navy_tradition = 1
	}
}

# country
on_conquistador_recruited = {
}

# country
on_explorer_recruited = {
	if = {
		limit = { 
			OR = {
				has_country_modifier = pol_global_maritime_empire_modifier 
				has_country_modifier = pol_global_maritime_empire_2_modifier
			}
		}
		add_navy_tradition = 1 
	}
}

# THIS = Province, FROM = Country
on_regiment_recruited = {

}

# THIS = Province, FROM = Country, ROOT = Merc Unit
on_mercenary_recruited = {
	on_mercenary_recruited_effect = yes
}
# THIS = One province in the state
on_add_pasha = {
	hidden_effect = {
		owner = {
			save_event_target_as = province_owner
		}
	}
	if = {
		limit = {
			event_target:province_owner = {
				has_country_flag = tur_improved_pashas
			}
		}
		area = {
			limit = { owned_by = event_target:province_owner NOT = { culture_group = event_target:province_owner } }
			add_province_modifier = { name = tur_competent_pashas duration = -1 }
		}
	}
	if = {
		limit = {
			event_target:province_owner = {
				has_government_attribute = pasha_extra_bonuses
			}
		}
		area = {
			limit = { owned_by = event_target:province_owner NOT = { culture_group = event_target:province_owner } }
			add_province_modifier = { name = the_provincial_system duration = -1 }
		}
	}
}

# THIS = One province in the state
on_remove_pasha = {
	hidden_effect = {
		owner = {
			save_event_target_as = province_owner
		}
	}

	area = {
		limit = { owned_by = event_target:province_owner }
		add_or_extend_province_modifier_effect = { MODIFIER = pasha_removed_modifier DURATION = 3650 }
		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
		}
	}
}

# THIS = Province
on_janissaries_raised = {
}

on_cawa_raised = {
}

on_carolean_raised = {
}

on_hussars_raised = {
}

on_revolutionary_guard_raised = {
}

on_banner_raised = {
	owner = { 
		if = { 
			limit = { has_country_flag = refund_partial_corruption_on_banner_recruited_flag }
			add_corruption = -0.04
		}
	}
}

on_cossack_raised = {
}

on_marine_raised = {
}

on_rajput_raised = {
}

on_streltsy_raised = {
}

on_tercio_raised = {
}

on_musketeer_raised = {
}

on_samurai_raised = {
}

on_qizilbash_raised = {
}

on_mamluks_raised = {
}

on_geobukseon_raised = {
}

on_man_of_war_raised = {
}

on_galleon_raised = {
}

on_galleass_raised = {
}

on_caravel_raised = {
}

on_voc_indiamen_raised = {
}

on_hre_reform_passed = {
}

on_mandate_reform_passed = {
	if = {
		limit = { has_country_flag = mng_shengshi_reward_flag }
		add_estate_loyalty = {
			estate = estate_eunuchs 
			loyalty = 10 
		}
		add_estate_loyalty = {
			estate = estate_nobles 
			loyalty = 10 
		}
		add_estate_loyalty = {
			estate = estate_burghers 
			loyalty = 10 
		}
		add_estate_loyalty = {
			estate = estate_church 
			loyalty = 10 
		}
		add_estate_loyalty = {
			estate = estate_nomadic_tribes 
			loyalty = 10 
		}
	}
	if = {
		limit = { has_country_flag = qng_passing_decree_reduces_autonomy_everywhere_by_5_flag } 
		every_owned_province = {
			add_local_autonomy = -10
		}
	}
}

on_reform_enacted = {
}

on_reform_changed = {
}

on_trade_company_investment = {
}

on_center_of_trade_upgrade = {
	if = {
		limit = { owner = { has_country_flag = enable_upgrading_centers_of_trade_dev } }
		add_base_production = 1 
	}
	if = {
		limit = { owner = { has_country_modifier = geo_centers_of_trade } }
		add_base_production = 1 
	}
}

on_center_of_trade_downgrade = {
	if = {
		limit = { owner = { has_country_flag = enable_upgrading_centers_of_trade_dev } }
		add_base_production = -1 
	}
	if = {
		limit = { owner = { has_country_modifier = geo_centers_of_trade } }
		add_base_production = -1 
	}
}

on_culture_promoted = {
	on_culture_promoted_estate_privileges_effect = yes
	judaism_on_culture_country_effect = yes
	imperial_modifiers_on_culture_country_effect = yes
	
	GER_on_culture_promoted = yes
	
	if = { 
		limit = { has_country_flag = reduce_ae_from_prom_cultures_flag }
		every_country = {
			add_aggressive_expansion = {
				who = ROOT 
				value = -3
				apply_calc = no 
			}
		}
	}
}

on_culture_demoted = {
	on_culture_demoted_estate_privileges_effect = yes
	judaism_on_culture_country_effect = yes
	imperial_modifiers_on_culture_country_effect = yes
	on_culture_demoted_effect = yes
	#on_culture_demoted_effect_remove_all_free_slots = yes
	
	GER_on_culture_demoted = yes
}

on_primary_culture_changed = {
	on_primary_culture_changed_effect = yes
	on_primary_culture_changed_privileges_effect = yes
	judaism_on_culture_country_effect = yes
	imperial_modifiers_on_primary_culture_change_effect = yes
}

# FROM = Previous Country, ROOT = Province
on_company_chartered = {
	if = {
		limit = {
			OR = {
				region = bengal_region
				region = hindusthan_region
				region = west_india_region
				region = deccan_region
				region = coromandel_region
			}
		}
		ROOT = {
			owner = {
				set_country_flag = the_coin_is_stronger_than_the_sword
			}
		}
	}
}

# ROOT = Overlord, FROM = Minor
on_dependency_gained = {
	on_dependency_gained_effect = yes
}

# ROOT = Overlord, FROM = Minor
on_dependency_lost = {
	on_dependency_lost_effect = yes
}

# ROOT = New vassal, FROM = Overlord
on_create_vassal = {
	on_religion_change_estate_privileges_effect = yes
	if = {
		limit = {
			tag = TUR
			HUN = { has_country_modifier = hun_avenge_varna }
		}
		HUN = { remove_country_modifier = hun_avenge_varna }
	}
	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
        }
    }
	if = {
		limit = {
			has_dlc = "Emperor"
			FROM = {
				is_revolutionary = yes
			}
		}
		change_government = republic
		add_government_reform = junior_revolutionary_republic_reform
		set_country_flag = had_revolution
	}
	if = {
		limit = {
			tag = PAP
		}
		change_government = theocracy
		change_religion = catholic
		add_government_reform = papacy_reform
		adopt_reform_progress = FROM
	}
	if = {
		limit = { NOT = { is_year = 1445 } }
		set_country_flag = released_in_1444
	}
}

# ROOT = Country establishing it
# First province in state is set
on_holy_order_established = {
	ROOT = {
		if = {
			limit = {
				has_country_flag = ven_establish_scuola_effect_flag
			}
			change_innovativeness = 1
		}
	}
}

# When a minority is expelled to a colony
# THIS = Colony, ROOT = Colony, FROM = Home province
on_minority_expelled = {
	FROM = {
		remove_province_modifier = religious_zeal_at_conv
		add_permanent_province_modifier = {
			name = expelled_minority_home
			duration = 7300
		}
	}
}

# THIS = Raiding country, FROM = Sea province
on_raid_coast = {
	if = {
		limit = {
			has_faction = pr_buccaneers
		}
		add_faction_influence = {
			faction = pr_buccaneers
			influence = 1
		}
	}
	if = {
		limit = {
			has_government_attribute = raiding_increases_pp
		}
		add_power_projection = {
			type = high_sea_power_projection
			amount = 1
		}
	}
	if = {
		limit = {
			has_mission = dan_raid_the_north_sea
			NOT = { mission_completed = dan_raid_the_north_sea } 
		}
		change_variable = {
			which = num_of_raided_coasts
			value = 1
		}
	}
}

# ROOT = Tag that captured the flagship, FROM = Tag that lost the flagship
on_flagship_captured = {
	FROM = {
		set_country_flag = captured_flagship_country_flag
	}
	ROOT = {
		country_event = { id = flagship_events.2 }
		set_country_flag = trophy_hunter_flag
	}
	FROM = {
		country_event = { id = flagship_events.1 }
	}
	FROM = { 
		if = { 
			limit = { has_country_modifier = hsa_pride_eagle_of_the_fleet_modifier }
			remove_country_modifier = hsa_pride_eagle_of_the_fleet_modifier
		}
	}
}

# ROOT = Tag that destroyed the flagship, FROM = Tag that lost the flagship
on_flagship_destroyed = {
	FROM = {
		set_country_flag = sunk_flagship_country_flag
	}
	ROOT = {
		country_event = { id = flagship_events.4 }
	}
	FROM = {
		country_event = { id = flagship_events.3 }
	}
	FROM = { 
		if = { 
			limit = { has_country_modifier = hsa_pride_eagle_of_the_fleet_modifier }
			remove_country_modifier = hsa_pride_eagle_of_the_fleet_modifier
		}
	}
}

# this = Released country, FROM = Releasing country
on_country_released = {
	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
        }
    }
	if = {
		limit = {
			tag = PAP
		}
		change_government = theocracy
		change_religion = catholic
		add_government_reform = papacy_reform
		adopt_reform_progress = FROM
	}
	if = {
		limit = {
			FROM = { has_reform = religious_permanent_revolution_reform }
			NOT = { tag = PAP }
		}
		change_religion = FROM
		adopt_reform_progress = FROM
		add_country_modifier = {
			name = global_holy_war_released_modifier
			duration = 3650
			hidden = yes
		}
		capital_scope = {
			change_religion = FROM
		}
	}
	if = {
		limit = { NOT = { is_year = 1445 } }
		set_country_flag = released_in_1444
	}
}

# ROOT = province, FROM = country
on_trade_good_changed = {
	on_trade_good_changed_estate_privileges_effect = yes
	on_trade_good_changed_government_effect = yes
	ROOT = {
		if = {
			limit = { 
				trade_goods = coal 
				FROM = { economic_ideas = 3 }
				has_manufactory_trigger = yes 
				base_production = 2
			}
			add_base_production = -1 
		}
		if = {
			limit = {
				has_province_modifier = INC_gold_debuff
				NOT = { trade_goods = gold }
			}
			remove_province_modifier = INC_gold_debuff
		}
		else_if = {
			limit = {
				from = { has_estate_privilege = estate_church_INC_idol_making }
				NOT = { has_province_modifier = INC_gold_debuff }
				trade_goods = gold
			}
			add_province_modifier = {
				name = INC_gold_debuff
				duration = -1
			}
		}
	}
}

# this = country
on_loan_repaid = {
	on_loan_repaid_estate_privileges_effect = yes
	if = {
		limit = { 
			THIS = {
				economic_ideas = 4 
			}
		}
		THIS = { add_inflation = -0.05 }
	}
}

# this = country
on_rebels_break_country = {
	add_country_modifier = {
		name = just_lost_to_rebels
		duration = 10
		hidden = yes
	}
	events = {
		flavor_per.64	#No more Zoroastrian
	}
}

# this = country
## Fires when you fire or replace your ADM advisor, in the moment before they are actually removed from their post.
## Note: Defining a new advisor here will result in the shortest appointment in history. Use on_post_adm_advisor_fired instead :)
on_pre_adm_advisor_fired = {
	if = {
		limit = {
			has_country_flag = need_to_fire_adm_advisor
		}
		set_country_flag = just_fired_adm_advisor
		remove_advisor_by_category_no_action = ADM
	}
}

# this = country
on_pre_dip_advisor_fired = {
	if = {
		limit = {
			has_country_flag = need_to_fire_dip_advisor
		}
		set_country_flag = just_fired_dip_advisor
		remove_advisor_by_category_no_action = DIP
	}
}

# this = country
on_pre_mil_advisor_fired = {
	if = {
		limit = {
			has_country_flag = need_to_fire_mil_advisor
		}
		set_country_flag = just_fired_mil_advisor
		remove_advisor_by_category_no_action = MIL
	}
}

# this = country
on_post_adm_advisor_fired = {
	on_advisor_removed_effct = { type = adm }
}

# this = country
on_post_dip_advisor_fired = {
	on_advisor_removed_effct = { type = dip }
}

# this = country
on_post_mil_advisor_fired = {
	on_advisor_removed_effct = { type = mil }
}

# this = new client state, from = parent country
on_create_client_state = {
	if = { 
		limit = { 
			FROM = { mission_completed = fra_grande_armee }
		}
		FROM = {
			add_power_projection = {
				type = mission_rewards_power_projection
				amount = 10
			}
		}
	}
}

# this = new target, from = previous target (both can be non-existent tag)
on_change_revolution_target = {
	if = {
		limit = { has_reform = junior_revolutionary_republic_reform }
		add_government_reform = revolutionary_republic_reform
	}
}

# this = curia controller (enactor of the bull)
on_golden_bull_enacted = {
	set_country_flag = enacted_golden_bull
	if = {
		limit = { 
			FRA = { has_country_flag = gain_25_random_pp_and_10_pi_per_bull_flag } 
		}
		FRA = {
			random_list = {
				10 = { add_adm_power = 25 }
				10 = { add_dip_power = 25 }
				10 = { add_mil_power = 25 }
			}
			add_papal_influence = 10 
		}
	}
}


# province:  spawned whenever a new owner takes over the province
# FROM = The previous owner.
on_conquest = {
	on_conquest_effect = yes
}

on_country_creation = {
	if = {
		limit = {
			tag = PAP
			OR = {
				NOT = {
					religion = catholic
				}
				NOT = {
					has_reform = papacy_reform
				}
				NOT = {
					government = theocracy
				}
			}
		}
		change_religion = catholic
		change_government = theocracy
		add_government_reform = papacy_reform
	}
}

on_federation_leader_change = {
	if = {
		limit = { tag = FROM }
		disband_federation = THIS
	}
	else = {
		# New strongest member becomes the new federation leader
		set_federation_leader = THIS
	}
}

#FROM = country pillaged, ROOT = country doing the pillaging
on_pillaged_capital = {
	slave_raid_pillage_capital_effect = yes
}

#FROM = country dev was transferred from, ROOT = country doing the transferring. It is triggered by normal concentrate too though FROM isn't set in that case
on_transfer_development = {
}
#FROM = overlord, ROOT - colony
on_colonial_type_change = {
	clr_country_flag = encourage_cash_crops_flag
}

on_estate_led_regency = {
	if = {
		limit = {
			has_government_attribute = improved_nobles_regency
			OR = {
				has_estate = estate_nobles
				AND = {
					NOT = { has_estate = estate_nobles }
					OR = {
						has_estate = estate_maratha
						has_estate = estate_rajput
					}
				}
			}
		}
		add_ruler_modifier = {
			name = empowered_regency_modifier
			duration = -1
		}
		change_adm = 1
		change_dip = 1
		change_mil = 1
	}
	if = { 
		limit = { 
			has_country_flag = jap_regency_ga_flag 
			has_estate_led_regency = { estate = estate_nobles } 
		}
		add_ruler_modifier = { 
			name = golden_era_bushi_modifier
			duration = -1 
		}
	}
}

on_estate_led_regency_surpassed = {
	if = {
		limit = {
			is_lesser_in_union = no
			num_of_powerful_estates = 1
			has_estate_led_regency = {
				estate = any
			}
			NOT = {
				estate_led_regency_influence = 70
			}
			OR = {
				AND = {
					has_estate_led_regency = {
						estate = estate_burghers
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_church
							modifier = REFUSED_REGENCY
						}
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_nobles
							modifier = REFUSED_REGENCY
						}
					}
				}
				AND = {
					has_estate_led_regency = {
						estate = estate_church
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_burghers
							modifier = REFUSED_REGENCY
						}
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_nobles
							modifier = REFUSED_REGENCY
						}
					}
				}
				AND = {
					has_estate_led_regency = {
						estate = estate_nobles
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_burghers
							modifier = REFUSED_REGENCY
						}
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_church
							modifier = REFUSED_REGENCY
						}
					}
				}
			}
		}
		country_event = { id = estate_regency_events.1 }
	}
}

on_extended_regency = {
	random_events = {
		100 = extended_regency_events.4
		100 = extended_regency_events.5
		100 = extended_regency_events.6
		
		300 = 0
	}
}

on_estate_removed = {
	if = {
		limit = {
			has_country_modifier = dhimmi_building_restrictions
			NOT = {
				has_estate = estate_dhimmi
			}
		}
		remove_country_modifier = dhimmi_building_restrictions
	}
	if = {
		limit = {
			has_country_modifier = swe_debt_with_the_clergy
			NOT = { has_estate = estate_church }
		}
		remove_country_modifier = swe_debt_with_the_clergy
	}
	if = {
		limit = {
			has_country_modifier = swe_debt_with_the_burghers
			NOT = { has_estate = estate_burghers }
		}
		remove_country_modifier = swe_debt_with_the_burghers
	}
	if = {
		limit = {
			has_country_modifier = swe_debt_with_the_nobles
			NOT = { has_estate = estate_nobles }
		}
		remove_country_modifier = swe_debt_with_the_nobles
	}
}

##scope = colony province, FROM = owner country or province if there's a minority expulsion source, fires when the colony is created
on_colony_established = {
}

#scope = new country, FROM = parent country
on_colonial_nation_established = {
}

##scope = colony province, FROM = owner country or province if there's a minority expulsion source
on_colonist_boosting_colony = {
	on_colonist_boosting_colony_effect = yes
}

#ROOT = converted country, FROM = country which force converts ROOT, on_action gets called on Force religion peace and Enforce Religion subject interaction
on_force_conversion = {
	on_force_conversion_effect = yes
}

on_institution_embracement = {
	if = {
		limit = {
			has_government_attribute = monarch_power_on_institutions
		}
		add_adm_power = 100
		add_dip_power = 100
		add_mil_power = 100
	}
}
on_national_focus_change = {}

#ROOT = new capital province, FROM = old capital
on_capital_moved = {
	on_capital_moved_effect = yes
}

#ROOT = province that was expanded in, FROM = country that did it
on_expanded_infrastructure = {
	if = {
		limit = {
			province_id = 266
			owner = {
				has_country_flag = boh_expand_infrastructure_prague_flag
			}
			NOT = {
				check_variable = {
					which = boh_expanded_infrastructure_prague
					value = 3
				}
			}
		}
        change_variable = {
            which = boh_expanded_infrastructure_prague
            value = 1
        }
		add_base_tax = 1
		add_base_production = 1
		add_base_manpower = 1
	}
	if = {
		limit = {
			has_province_flag = feo_expand_infrastructure_gold_income
		}
		FROM = {
			add_years_of_owned_provinces_production_income = {
				years = 2
				trigger = {
					province_id = 1766
				}
			}
		}
		1766 = { clr_province_flag = feo_expand_infrastructure_gold_income}
	}
	if = {
		limit = {
			has_province_flag = azt_tenochtitlan_expand_infrastructure_flag
		}
		FROM = {
			change_government_reform_progress = 10
		}
	}
	if = {
		limit = {
			FROM = {
				has_country_flag = MUG_upgrade_expanding_infrastructure
			}
		}
		area = {
			limit = {
				owned_by = FROM
			}
			add_province_modifier = {
				name = MUG_expanded_infrastructure
				duration = 7300
			}
		}
	}
}
on_expanded_infrastructure_removed = {
}

#ROOT = province that was centralized in
on_centralized_state = {
	if = {
		limit = {
			owner = { has_government_attribute = centralize_state_no_reform_cost }
		}
		owner = {
			add_adm_power = 50
			change_government_reform_progress = 50
		}
	}
	else_if = {
		limit = {
			owner = { has_government_attribute = centralize_state_half_refund }
		}
		owner = {
			add_adm_power = 25
			change_government_reform_progress = 25
		}
	}
	if = {
		limit = {
			owner = { 
				OR = {
					has_government_attribute = centralize_state_development
					has_country_modifier = hun_strengthen_the_government
				}
			}
		}
		area = {
			limit = {
				owned_by = ROOT
			}
			random_list = {
				1 = { add_base_tax = 1 }
				1 = { add_base_production = 1 }
				1 = { add_base_manpower = 1 }
			}
		}
	}
}

#ROOT = country
monarch_on_shipwreck = {
}
heir_on_shipwreck = {
}
consort_on_shipwreck = {
}

#ROOT = country
on_defender_of_faith_loss = {
	on_defender_of_faith_loss_effect = yes
}
on_defender_of_faith_claim = {
	on_defender_of_faith_claim_effect = yes
}
on_hre_dismantled = {
	country_event = {
		id = hre_event.15
	}
	if = {
		limit = { has_country_flag = fra_shed_the_blood_of_the_saxon_man_flag }
		clr_country_flag = fra_shed_the_blood_of_the_saxon_man_flag
		set_country_flag = fra_fufujoni_flag
		swap_non_generic_missions = yes
	}
}
on_new_age = {
	events = {
		flavor_rus.44 #Update the Russian mission tree
		flavor_gbr.122 #Assign Religious Chaos to England
	}
	set_age_passed_global_flag = yes
	remove_all_age_timed_modifiers = yes
	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 = {
			has_country_flag = ITA_gain_100_splendor_flag
			has_dlc = "Mandate of Heaven"
		}
		add_splendor = 100
	}
}

#ROOT = province
on_adm_exploited = {
	if = {
		limit = { owner = { has_government_attribute = may_not_reduce_tax_on_exploitation } }
		random = {
			chance = 50
			add_base_tax = 1
		}
	}
	if = {
		limit = { owner = { has_government_attribute = may_not_reduce_tax_on_own_exploitation culture_group = ROOT } }
		random = {
			chance = 25
			add_base_tax = 1
		}
	}
	if = {
		limit = { owner = { has_government_attribute = may_not_reduce_tax_on_foreign_exploitation NOT = { culture_group = ROOT } } }
		random = {
			chance = 50
			add_base_tax = 1
		}
	}
	if = {
		limit = {
			owner = { has_government_mechanic = blood_gathering_mechanic }
		}
		owner = {
			add_government_power = {
				mechanic_type = blood_gathering_mechanic
				power_type = blood
				value = 1
			}
		}
	}
    if = {
        limit = {
            has_province_modifier = estate_burghers_hungarian_royal_city_modifier
			NOT = { development = 20 }
		}
    }
    remove_province_modifier = estate_burghers_hungarian_royal_city_modifier
}
on_dip_exploited = {
	if = {
		limit = {
			owner = { has_government_mechanic = blood_gathering_mechanic }
		}
		owner = {
			add_government_power = {
				mechanic_type = blood_gathering_mechanic
				power_type = blood
				value = 1
			}
		}
	}
	if = {
        limit = {
            has_province_modifier = estate_burghers_hungarian_royal_city_modifier
			NOT = { development = 20 }
		}
    }
    remove_province_modifier = estate_burghers_hungarian_royal_city_modifier
}
on_mil_exploited = {
	if = {
		limit = {
			owner = { has_government_mechanic = blood_gathering_mechanic }
		}
		owner = {
			add_government_power = {
				mechanic_type = blood_gathering_mechanic
				power_type = blood
				value = 1
			}
		}
	}
	if = {
        limit = {
            has_province_modifier = estate_burghers_hungarian_royal_city_modifier
			NOT = { development = 20 }
		}
    }
    remove_province_modifier = estate_burghers_hungarian_royal_city_modifier
}
on_raze = {
	add_permanent_province_modifier = {
		name = province_razed
		duration = 7300
	}
	owner = {
		change_variable = {
			which = HordeProvincesRazed
			value = 1
		}
	}
	
	if = {
		limit = {
			has_tax_building_trigger = yes
			owner = {
				has_country_flag = tatars_curch_raze_flag
			}
		}
		owner = {
			add_treasury = 10
		}
	}
	
	if = {
		limit = {
			owner = {
				has_country_flag = hordes_unlock_tribes_loyalty_through_razing_flag
			}
		}
		owner = {
			add_estate_loyalty = {
				estate = estate_nomadic_tribes
				loyalty = 1
			}
		}
	}
}
on_concentrate_development = {
	if = { 
		limit = { 
			owner = { has_country_modifier = fra_french_isles_modifier }
		}
		add_nationalism = -5
	}
}

on_slacken_start = {
	add_country_modifier = {
		name = slackening_modifier
		duration = -1
	}
}
on_slacken_stop = {
	remove_country_modifier = slackening_modifier
}

on_colony_finished = { #ROOT - Province
	on_colony_finished_effect = yes
}

on_advisor_hired = { #ROOT - Country

}

on_adm_advisor_hired = { #ROOT - Country, executed after on_advisor_hired!

}

on_dip_advisor_hired = { #ROOT - Country, executed after on_advisor_hired!
	if = {
		limit = {
			has_country_flag = ITA_cavour_alive
		}
		clr_country_flag = ITA_cavour_alive
	}
}

on_mil_advisor_hired = { #ROOT - Country, executed after on_advisor_hired!

}

on_core = { #ROOT - Province, #FROM - Country that gets the core
	if = {
		limit = {
			FROM = { has_country_flag = GER_get_full_core_on_cored_italian_provinces_flag }
		}
		add_core = FROM
	}
	if = {
		limit = {
			FROM = { has_country_modifier = INC_the_mitma_for_control }
			NOT = { is_territorial_core = FROM }
		}
		FROM = {
			random_owned_province = {
				limit = {
					is_state_core = ROOT
					NOT = { has_province_modifier = INC_mitma_settlers }
					NOT = { nationalism = 1 }
				}
				random_list = {
					50 = { }
					50 = { add_random_development = 1 }
				}
				add_province_modifier = {
					name = INC_mitma_settlers
					duration = 10950
				}
			}
		}
	}
}

on_tech_taken = { #ROOT - Country
	if = {
		limit = { has_country_flag = ven_academy_of_the_unknowns_reward_flag }
		if = {
			limit = { has_dlc = "Rule Britannia" }
			change_innovativeness = 1
		}
		add_republican_tradition = 1
	}
}

on_adm_tech_taken = { #ROOT - Country, executed after on_tech_taken!
	if = {
		limit = {
			ROOT = {
				ruler_total_stats = {
					amount = 12
				}
				has_country_flag = hun_refund_mana_on_tech
			}
		}
		add_adm_power = 50
	}
}

on_dip_tech_taken = { #ROOT - Country, executed after on_tech_taken!
	if = {
		limit = {
			ruler_total_stats = {
				amount = 12
			}
			ROOT = {
				has_country_flag = hun_refund_mana_on_tech
			}
		}
		add_dip_power = 50
	}
}

on_mil_tech_taken = { #ROOT - Country, executed after on_tech_taken!
	if = {
		limit = {
			ruler_total_stats = {
				amount = 12
			}
			ROOT = {
				has_country_flag = hun_refund_mana_on_tech
			}
		}
		add_mil_power = 50
	}
} 

on_barrage = { #ROOT - barraging country, FROM - barraged province 

}

on_naval_barrage = { #ROOT - barraging country, FROM - barraged province 

}

on_scorch_earth  = { #ROOT - scorching country, FROM - scorched province

}

on_war_ended = { #ROOT - Winer FROM - Loser
	
}

on_alliance_broken = { #ROOT - Original alliance creator, FROM - Alliance accepter
	on_alliance_broken_effect = yes
	if = {
		limit = { has_country_modifier = grain_trade_imports_modifier }
		remove_country_modifier = grain_trade_imports_modifier
	}
	FROM = { 
		if = {
			limit = { has_country_modifier = grain_trade_imports_modifier }
			remove_country_modifier = grain_trade_imports_modifier
		}
	}
	if = {
		limit = { has_country_flag = enable_galleass }
		clr_country_flag = enable_galleass
	}
	FROM = {
		if = {
			limit = { has_country_flag = enable_galleass }
			clr_country_flag = enable_galleass
		}
	}
}

on_royal_marriage_broken = { #ROOT - Original marriage creator, FROM - Marriage accepter
}

on_alliance_created = { #ROOT - Alliance sender, FROM - Alliance accepter

}

on_royal_marriage = { #ROOT - Marraige sender, FROM - marriage accepter
	if = {
		limit = {
			tag = BUR
			NOT = { has_country_flag = burgundian_succession_has_already_fired }
		}
		FROM = { set_country_flag = received_burgundian_marriage }
	}
}

on_heir_disinherited = {
	on_heir_disinherited_or_death_effect = yes
}
on_overrun = { #ROOT - winner, FROM - loser, on stackwipe
	if = {
		limit = {
			ROOT = {
				has_government_attribute = army_tradition_on_stackwipe
			}
		}
		ROOT = {
			add_army_tradition = 0.1
		}
	}
}