namespace = Plus
namespace = trigger_schism

# reserved Plus.2700 to Plus.2749

character_event = { # Manually trigger the schism at any time
	id = trigger_schism.1
	desc = EVTDESC_Plus_2700
	picture = GFX_evt_great_schism
	
	is_triggered_only = yes
	hide_from = yes
	
	option = {
		name = EVTOPTA_Plus_2700
		
		hidden_tooltip = {
			set_global_flag = schism_manual_override # Required in order for the event to bypass normal checks
			d_pentarch_rome = { holder_scope = { character_event = { id = Plus.2285 } } } # Trigger the schism
		}
	}
	
	option = {
		name = EVTOPTB_Plus_2700
	}	
}

character_event = { # Setup player rules
	id = Plus.2700
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = {
		e_placeholder = { NOT = { has_title_flag = startup } }
		NOT = { e_placeholder = { had_title_flag = { flag = startup days = 1 } } }
		NOT = { has_global_flag = plus_rules_applied }
	}
	
	immediate = {
		set_global_flag = plus_rules_applied
		
		# Vanilla germans (yes)
		if = {
			limit = {
				has_game_rule = {
					name = vanilla_germans
					value = yes
				}
			}
			set_global_flag = vanilla_germans
			any_independent_ruler = { character_event = { id = Plus.2708 } }
		}
		
		# Vanilla italians (yes)
		if = {
			limit = {
				has_game_rule = {
					name = vanilla_italians
					value = yes
				}
			}
			set_global_flag = vanilla_italians
			any_independent_ruler = { character_event = { id = Plus.2714 } }
		}
		
		# Pagan reformation (Start Reformed)
		if = {
			limit = {
				has_game_rule = {
					name = pagan_reformation
					value = start_reformed
				}
			}
			set_global_flag = pagans_start_reformed
			d_miaphysite = { owner = { character_event = { id = Plus.2709 } } }
		}		
		
		# NWO
		if = {
			limit = {
				has_game_rule = {
					name = new_world_order
					value = yes
				}
			}
			d_miaphysite = { owner = { character_event = { id = emf_nwo.0 days = 1 } } }
		}
		
		# Aztec Invasion (Plus)
		if = {
			limit = { 
				NOT = {
					has_game_rule = {
						name = aztec_invasion
						value = plus
					}
				}
			}
			set_global_flag = vanilla_aztecs
		}
		
		# Crusades Unlock
		if = {
			limit = {
				has_game_rule = {
					name = crusade_rules
					value = activate_immediately
				}
			}
			set_global_flag = muslim_jihads_unlocked
			set_global_flag = christian_crusades_unlocked
			set_global_flag = pagan_ghws_unlocked
		}
		
		# Crusades Delay (1 year)
		if = {
			limit = {
				has_game_rule = {
					name = crusade_delay_rules
					value = one_year
				}
			}
			set_global_flag = delayed_crusades_1
		}
		
		# Crusades Delay (3 years)
		if = {
			limit = {
				has_game_rule = {
					name = crusade_delay_rules
					value = three_years
				}
			}
			set_global_flag = delayed_crusades_2
		}
		
		# Crusades Delay (5 years)
		if = {
			limit = {
				has_game_rule = {
					name = crusade_delay_rules
					value = five_years
				}
			}
			set_global_flag = delayed_crusades_3
		}
		
		# Crusades Delay (10 years)
		if = {
			limit = {
				has_game_rule = {
					name = crusade_delay_rules
					value = ten_years
				}
			}
			set_global_flag = delayed_crusades_4
		}
		
		# Vanilla De Jure Empires
		if = {
			limit = {
				has_game_rule = {
					name = vanilla_empires
					value = yes
				}
			}
			set_global_flag = vanilla_empires
			d_miaphysite = { owner = { character_event = { id = Plus.2704 } } }
		}
		
		# Ancient Religions
		if = {
			limit = {
				NOT = { 
					has_game_rule = {
						name = ancient_religions
						value = no
					}
				}
				has_game_rule = {
					name = new_world_order
					value = no
				}
			}
			d_miaphysite = { owner = { character_event = { id = Plus.2702 days = 1 } } }
		}
		
		# Gender Equality
		if = {
			limit = {
				has_game_rule = {
					name = gender
					value = plus
				}
			}
			d_miaphysite = { owner = { character_event = { id = Plus.2710 } } }
		}
		
		# Trigger Schism
		if = {
			limit = {
				#Schism hasn't happened already i.e. post 1000 starts.
				NOT = { k_papal_state = { has_title_flag = schism_happened } }
				has_game_rule = {
					name = trigger_schism_rule
					value = yes
				}
			}
			set_global_flag = schism_manual_override # Required in order for the event to bypass normal checks
			d_pentarch_rome = { holder_scope = { character_event = { id = Plus.2285 days = 1 } } } # Trigger the schism
		}
		
		# Revert Schism
		if = {
			limit = {
				#Schism has happened, but we want it reverted(not mended) immediately
				k_papal_state = { has_title_flag = schism_happened }
				has_game_rule = {
					name = trigger_schism_rule
					value = no
				}
			}
			set_global_flag = chalcedonians_joined
			c_roma = { holder_scope = { character_event = { id = Plus.2711 days = 1} } }
		}
		
		# Revert and Disable Schism
		if = {
			limit = {
				#Schism has happened, but we want it reverted(not mended) immediately
				k_papal_state = { has_title_flag = schism_happened }
				has_game_rule = {
					name = trigger_schism_rule
					value = disable
				}
			}
			set_global_flag = chalcedonians_joined
			set_global_flag = disabled_schism
			c_roma = { holder_scope = { character_event = { id = Plus.2711 days = 1} } }
		}
		
		# Disable Schism
		if = {
			limit = {
				#Schism has not happened, and we want to disable it
				NOT = { k_papal_state = { has_title_flag = schism_happened } }
				has_game_rule = {
					name = trigger_schism_rule
					value = disable
				}
			}
			set_global_flag = disabled_schism
		}
		
		# No Hidden Traits
		if = {
			limit = {
				# Do not use hidden traits
				has_game_rule = {
					name = hidden_character_traits_rule
					value = no
				}
			}
			set_global_flag = always_visible_traits
		}
		
		# Government Conversion - Go Feudal
		if = {
			limit = {
				has_game_rule = {
					name = government_conversion
					value = gofeudal
				}
			}
			d_miaphysite = { owner = { character_event = { id = Plus.2712 } } }
		}
		
		# Government Conversion - Go Tribal
		if = {
			limit = {
				has_game_rule = {
					name = government_conversion
					value = gotribal
				}
			}
			d_miaphysite = { owner = { character_event = { id = Plus.2713 } } }
		}
		
		# Rapid Conquest CBs
		if = {
			limit = {
				has_game_rule = {
					name = rapid_conquest_cbs
					value = yes
				}
			}
			set_global_flag = emf_rapid_conquest
		}
	}
}

character_event = { # This event deals with the setup of the scenario before conversion
	id = Plus.2702
		
	is_triggered_only = yes
	hide_window = yes
	
	trigger = { NOT = { has_global_flag = ancient_religions_start } }
	
	immediate = { 
		set_global_flag = ancient_religions_start
		# First deal with the religious heads
		d_sunni = {
			destroy_landed_title = THIS
		}
		d_shiite = {
			destroy_landed_title = THIS
		}
		if = {
			limit = {
				year = 1054
				NOT = {
					has_game_rule = {
						name = ancient_religions
						value = specific_provinces
					}
				}
			}
			k_papal_state = { # Distribute the catholic pope's titles
				owner = {
					any_vassal = {
						limit = {
							higher_tier_than = baron
						}
						set_defacto_liege = THIS
						save_event_target_as = holder_of_papal_lands
					}
					any_demesne_title = {
						limit = {
							OR = {
								tier = count
								tier = duke
							}
						}
						event_target:holder_of_papal_lands = {
							grant_title_no_opinion = PREV
						}
					}
					any_demesne_title = {
						limit = {
							tier = baron
						}
						create_character = {
							random_traits = yes
							age = 21
							female = no
							culture = PREVPREV
							religion = PREVPREV
							dynasty = RANDOM
						}
						new_character = {
							grant_title_no_opinion = PREV
							set_defacto_liege = THIS
						}
					}
				}
			}
		}
		
		if = {
			limit = {
				NOT = { year = 1054 }
				NOT = {
					has_game_rule = {
						name = ancient_religions
						value = specific_provinces
					}
				}
			}
			k_papal_chalcedon = { # Distribute the chalcedon pope's titles
				owner = {
					any_vassal = {
						limit = {
							higher_tier_than = baron
						}
						set_defacto_liege = THIS
						save_event_target_as = holder_of_papal_lands
					}
					any_demesne_title = {
						limit = {
							OR = {
								tier = count
								tier = duke
							}
						}
						event_target:holder_of_papal_lands = {
							grant_title_no_opinion = PREV
						}
					}
					any_demesne_title = {
						limit = {
							tier = baron
						}
						create_character = {
							random_traits = yes
							age = 21
							female = no
							culture = PREVPREV
							religion = PREVPREV
							dynasty = RANDOM
						}
						new_character = {
							grant_title_no_opinion = PREV
							set_defacto_liege = THIS
						}
					}
				}
			}
		}
		
		# Does the HRE exist? If so we have some cleaning up to do. First switch it to the German empire
		if = {
			limit = {
				e_hre = {
					has_holder = yes
					OR = {
						NOT = {
							has_game_rule = {
								name = ancient_religions
								value = specific_provinces
							}
						}
						capital_scope = {
							OR = {
								region = custom_germany
								region = custom_frisia
							}
						}
					}
				}
			}
			e_hre = { owner = { save_event_target_as = hre_kaiser } }
			
			event_target:hre_kaiser = { # Remove crowned by pope with the generic variant
				if = {
					limit = { trait = crowned_by_pope }
					remove_trait = crowned_by_pope
					add_trait = crowned
				}
			}
			event_target:hre_kaiser = {
				set_character_flag = centralize_without_penalties
			}
			if = { # Activate e_germany if needed
				limit = { NOT = { is_title_active = e_germany } }
				activate_title = { title = e_germany status = yes }
			}
			
			e_germany = { # Copy the HRE's laws to Germany
				hidden_tooltip = {
					copy_title_laws = e_hre
				}
				gain_title = event_target:hre_kaiser
				make_primary_title = yes
			}

			any_title = { # Replace e_hre claims with e_germany claims
				limit = {
					rebel = no
					has_holder = yes
					is_primary_holder_title = yes
					holder_scope = { top_liege = { character = event_target:hre_kaiser } }
				}
				holder_scope = {
					if = {
						limit = { has_weak_claim = e_hre }
						add_weak_pressed_claim = e_germany
						remove_claim = e_hre
					}
					if = {
						limit = { has_strong_claim = e_hre }
						add_pressed_claim = e_germany
						remove_claim = e_hre
					}
					any_realm_character = {
						if = {
							limit = { has_weak_claim = e_hre }
							add_weak_pressed_claim = e_germany
							remove_claim = e_hre
						}
						if = {
							limit = { has_strong_claim = e_hre }
							add_pressed_claim = e_germany
							remove_claim = e_hre
						}
					}
				}
			}
			
			e_hre = { # Migrate over the HRE's de Jure vassals
				any_direct_de_jure_vassal_title = {
					de_jure_liege = e_germany
				}
				destroy_landed_title = yes
			}
			
			event_target:hre_kaiser = {
				clr_character_flag = centralize_without_penalties
			}			
		}
		
		any_independent_ruler = { # Now that the world is set up, convert them all to ARs
			any_realm_province = {
				limit = {
					any_province_holding = {
						count = 1
						tier = baron
					}
				}
				if = {
					limit = {
						has_game_rule = {
							name = ancient_religions
							value = regions
						}
					}
					emf_nwo_generate_ancient_religion_provinces = yes
				}
				if = {
					limit = {
						OR = {
							has_game_rule = {
								name = ancient_religions
								value = cultures
							}
							has_game_rule = {
								name = ancient_religions
								value = cultures_characters
							}
						}
					}
					emf_nwo_generate_ancient_religion_provinces_culture = yes
				}
				if = {
					limit = {
						has_game_rule = {
							name = ancient_religions
							value = specific_provinces
						}
					}
					emf_nwo_generate_ancient_religion_provinces_specific = yes
				}				
			}
			
			# This will convert all the characters of the world to appropriate religions
			if = {
				limit = {
					capital_scope = {
						has_province_flag = ar_setup
					}
				}
				if = {
					limit = {
						NOT = {
							has_game_rule = {
								name = ancient_religions
								value = cultures_characters
							}
						}
					}
					capital_scope = {
						reverse_religion = PREV #change religion of independent ruler based on their capital
					}
					any_courtier = {
						religion = PREV #match courtier religion to ruler religion
					}
					any_realm_lord = {
						religion = PREV #match realm lord religion to ruler religion
						any_courtier = {
							religion = PREV #match courtier religion to realm lord religion
						}
					}
				}
				if = {
					limit = {
						has_game_rule = {
							name = ancient_religions
							value = cultures_characters
						}
					}
					capital_scope = {
						emf_nwo_generate_ancient_religion_characters = yes #change religion of independent ruler based on their culture
					}
					any_courtier = {
						emf_nwo_generate_ancient_religion_characters = yes #change courtier religion based on their culture
					}
					any_realm_lord = {
						emf_nwo_generate_ancient_religion_characters = yes #change realm lord religion based on their culture
						any_courtier = {
							emf_nwo_generate_ancient_religion_characters = yes #change courtier religion based on their culture
						}
					}
				}
			}
		}
		if = {
			limit = {
				has_game_rule = {
					name = ancient_religions
					value = cultures_characters
				}
			}
			set_mercenaries_to_ar_culture_effect = yes # Set mercenaries to ancient religions based on their culture
		}
		if = {
			limit = {
				NOT = {
					has_game_rule = {
						name = ancient_religions
						value = cultures_characters
					}
				}
			}
			set_mercenaries_to_ar_effect = yes # Set mercenaries to ancient religions based on their capital
		}
	}
}

character_event = { # Set to Vanilla CK2 Empires
	id = Plus.2704
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
	
		any_title = { # HRE, Carolingian Empire or German Empire, whichever one exists
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = custom_frisia
						region = custom_lotharingia
						region = custom_germany
						region = custom_bohemia
					}
				}
			}
			de_jure_liege = e_germany # Falls back to this if the below 2 checks fail
			
			if = {
				limit = { e_hre = { has_title_flag = hre_formed } }
				de_jure_liege = e_hre
			}
			
			if = {
				limit = { 
					e_karling = {
						has_title_flag = carolingian_empire_formed
						NOT = { has_title_flag = carolingian_empire_fallen }
					} 
				}
				de_jure_liege = e_karling
			}
		}
		
		any_title = { # Britannia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					region = world_europe_west_brittania
				}
			}
			de_jure_liege = e_britannia
			activate_title = { title = e_britannia status = yes }
		}
		
		any_title = { # Spain
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = custom_andalusia
						region = custom_aragon
						region = custom_asturias
						region = custom_castille
						region = custom_navarra
						region = custom_portugal
					}
				}
			}
			de_jure_liege = e_spain
		}
		
		any_title = { # Scandinavia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = world_europe_north
						region = custom_livonia
					}
				}
			}
			de_jure_liege = e_scandinavia
			activate_title = { title = e_scandinavia status = yes }
		}
		
		any_title = { # Francia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = world_europe_west_francia
						region = custom_burgundy
					}
				}
			}
			de_jure_liege = e_france
			activate_title = { title = e_france status = yes }
		}
		
		any_title = { # Italia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					region = custom_italy
				}
			}
			de_jure_liege = e_italy
			activate_title = { title = e_italy status = yes }
		}
		
		any_title = { # Byzantine/Byzanblob
			limit = {
				vanilla_empires_trigger = yes
				OR = {
					capital_scope = {
						OR = {
							region = custom_sicily
							region = world_europe_south_east
							region = world_asia_minor
							region = custom_azerbaijan
						}
					}
					title = k_venice
				}
			}
			de_jure_liege = e_byzantium
		}
		
		any_title = { # Wendish Empire
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = custom_pomerania
						region = custom_poland
						region = custom_lithuania
					}
				}
			}
			de_jure_liege = e_wend
			activate_title = { title = e_wend status = yes }
		}

		any_title = { # Carpathia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = custom_carpathia
						region = custom_wallachia
					}
				}
			}
			de_jure_liege = e_carpathia
			activate_title = { title = e_carpathia status = yes }
		}
		
		any_title = { # Russia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = custom_rus
						region = custom_novgorod
						region = custom_muscovy
						region = custom_perm
					}
				}
			}
			de_jure_liege = e_russia
		}

		any_title = { # Tartaria
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_steppe
						NOT = { region = custom_perm }
				}
			}
			de_jure_liege = e_tartaria
			activate_title = { title = e_tartaria status = yes }
		}
		
		any_title = { # Persia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						OR = {
							region = world_persia
							region = custom_mesopotamia
						}
						NOT = { region = custom_khwarizm }
				}
			}
			de_jure_liege = e_persia
			activate_title = { title = e_persia status = yes }
		}
		
		any_title = { # Abyssinia
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_africa_east
				}
			}
			de_jure_liege = e_abyssinia
			activate_title = { title = e_abyssinia status = yes }
		}
		
		any_title = { # Mali
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_africa_west
				}
			}
			de_jure_liege = e_mali
			activate_title = { title = e_mali status = yes }
		}

		any_title = { # Arabian Empire
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
					OR = {
						region = world_africa_north
						region = world_middle_east
					}
					NOT = { region = custom_mesopotamia }
				}
			}
			de_jure_liege = e_arabia
			activate_title = { title = e_arabia status = yes }
		}
		
		any_title = { # Rajastan
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_india_rajastan
				}
			}
			de_jure_liege = e_rajastan
			activate_title = { title = e_rajastan status = yes }
		}
		
		any_title = { # Bengal
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_india_bengal
				}
			}
			de_jure_liege = e_bengal
			activate_title = { title = e_bengal status = yes }
		}
		
		any_title = { # Deccan Empire
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_india_deccan
				}
			}
			de_jure_liege = e_deccan
			activate_title = { title = e_deccan status = yes }
		}
		
		any_title = { # Tibetan Empire
			limit = {
				vanilla_empires_trigger = yes
				capital_scope = {
						region = world_himalayas
				}
			}
			de_jure_liege = e_tibet
			activate_title = { title = e_tibet status = yes }
		}	
	}
}

character_event = { # Notify Player of normal end date
	id = Plus.2706
	desc = EVTDESC_Plus_2706
	picture = GFX_evt_game_over

	hide_from = yes
	
	ai = no

	trigger = {
		year = 1453
		NOT = { has_global_flag = players_informed_of_end }
	}

	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		set_global_flag = players_informed_of_end
	}
	
	option = {
		name = EVTOPTA_Plus_2706 # Just a bit longer!

	}
}

character_event = { # Set to Vanilla Germans
	id = Plus.2708
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		if = {
			limit = { german_cultures_no_old_german_trigger = yes }
			culture = german
		}
		any_courtier = {
			if = {
				limit = { german_cultures_no_old_german_trigger = yes }
				culture = german
			}
		}
		any_realm_province = {
			if = {
				limit = { german_cultures_no_old_german_trigger = yes }
				culture = german
			}
		}
		any_vassal = {
			character_event = { id = Plus.2708 }
		}
	}
}

character_event = { # Reformed Pagans
	id = Plus.2709
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		# Convert all holy orders and set the reformation global_flags
		d_jomsvikings = {
			religion = norse_pagan_reformed # This Holy Order now changes religion
		}
		d_braedralag = {
			religion = norse_pagan_reformed # This Holy Order now changes religion
		}
		set_global_flag = norse_reformation
		activate_title = { title = d_norse_pagan_reformed status = yes }
		
		d_great_host = {
			religion = tengri_pagan_reformed # This Holy Order now changes religion
		}
		d_sky_lords = {
			religion = tengri_pagan_reformed # This Holy Order now changes religion
		}
		set_global_flag = tengri_reformation
		activate_title = { title = d_tengri_pagan_reformed status = yes }
		
		d_chosen_perkunas = {
			religion = baltic_pagan_reformed # This Holy Order now changes religion
		}						
		d_guardians_of_the_sacred_flame = {
			religion = baltic_pagan_reformed # This Holy Order now changes religion
		}	
		set_global_flag = baltic_reformation
		activate_title = { title = d_baltic_pagan_reformed status = yes }

		d_disciples_of_the_old_gods = {
			religion = finnish_pagan_reformed # This Holy Order now changes religion
		}	
		d_sons_kaleva = {
			religion = finnish_pagan_reformed # This Holy Order now changes religion
		}
		set_global_flag = finnish_reformation
		activate_title = { title = d_finnish_pagan_reformed status = yes }

		d_harii = {
			religion = german_pagan_reformed # This Holy Order now changes religion
		}	
		set_global_flag = german_reformation
		activate_title = { title = d_german_pagan_reformed status = yes }

		d_warriors_perun = {
			religion = slavic_pagan_reformed # This Holy Order now changes religion
		}
		set_global_flag = slavic_reformation
		activate_title = { title = d_slavic_pagan_reformed status = yes }

		d_spirit_guardians = {
			religion = west_african_pagan_reformed # This Holy Order now changes religion
		}
		set_global_flag = west_african_reformation
		activate_title = { title = d_west_african_pagan_reformed status = yes }

		d_zun_warriors = {
			religion = zun_pagan_reformed # This Holy Order now changes religion
		}
		set_global_flag = zun_reformation
		activate_title = { title = d_zun_pagan_reformed status = yes }
		
		# Convert all characters to the reformation versions
		any_character = {
			if = {
				limit = { is_reformed_pagan_religion = no }
				start_reformed_effect = yes
			}
		}

		# Convert all provinces to the reformation versions
		any_independent_ruler = {
			any_realm_province = {
				if = {
					limit = { is_reformed_pagan_religion = no }
					start_reformed_effect = yes
				}
			}
		}
	}
}

character_event = { # Set all titles to Cognatic
	id = Plus.2710
	
	is_triggered_only = yes
	hide_window = yes
	
	trigger = { NOT = { has_global_flag = gender_equality } }
	
	immediate = {
		set_global_flag = gender_equality
		any_title = {
			add_law = true_cognatic_succession
			add_law = female_council_law_4
		}
	}
}

character_event = { #Switch to chalcedonian
	id = Plus.2711
	
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		k_papal_state = {
			holder_scope = {
				any_vassal = {
					set_character_flag = pope_is_my_liege
				}
			}
			clr_title_flag = schism_happened
		}
		k_papal_state = {
			unsafe_destroy_landed_title = THIS
		}
		k_orthodox = {
			unsafe_destroy_landed_title = THIS
		}
		activate_title = { title = k_papal_state status = no}
		activate_title = { title = k_orthodox status = no}
		#heresies
		set_parent_religion = { religion = cathar parent = chalcedonian }
		set_parent_religion = { religion = waldensian parent = chalcedonian }
		set_parent_religion = { religion = lollard parent = chalcedonian }
		set_parent_religion = { religion = adoptionist parent = chalcedonian }
		set_parent_religion = { religion = iconoclast parent = chalcedonian }
		set_parent_religion = { religion = monothelite parent = chalcedonian }
		set_parent_religion = { religion = bogomilist parent = chalcedonian }
		# mercs
		any_title = {
			limit = {
				mercenary = yes
			}
			religion = chalcedonian
			holder_scope = {
				religion = chalcedonian
			}
		}
		# reset catholic/orthodox holy orders
		if = {
			limit = { d_knights_calatrava = { has_holder = yes } }
			d_knights_calatrava = {
				religion = chalcedonian
				holder_scope = {
					religion = chalcedonian
				}
			}
		}
		if = {
			limit = { d_knights_hospitaler = { has_holder = yes } }
			d_knights_hospitaler = {
				religion = chalcedonian
				holder_scope = {
					religion = chalcedonian
				}
			}
		}
		if = {
			limit = { d_knights_santiago = { has_holder = yes } }
			d_knights_santiago = {
				religion = chalcedonian
				holder_scope = {
					religion = chalcedonian
				}
			}
		}
		if = {
			limit = { d_knights_templar = { has_holder = yes } }
			d_knights_templar = {
				religion = chalcedonian
				holder_scope = {
					religion = chalcedonian
				}
			}
		}
		if = {
			limit = { d_teutonic_order = { has_holder = yes } }
			d_teutonic_order = {
				religion = chalcedonian
				holder_scope = {
					religion = chalcedonian
				}
			}
		}
		if = {
			limit = { d_holy_sepulchre = { has_holder = yes } }
			d_holy_sepulchre = {
				religion = chalcedonian
				holder_scope = {
					religion = chalcedonian
				}
			}
		}
		#convert all provinces
		any_province = {
			limit = {
				OR = {
					religion = catholic
					religion = orthodox
				}
			}
			religion = chalcedonian
		}
		#convert all characters
		any_character = {
			limit = {
				OR = {
					religion = catholic
					religion = orthodox
				}
			}
			religion = chalcedonian
		}
		activate_title = { title = k_papal_chalcedon status = yes }
		activate_title = { title = d_pentarch_rome status = yes }
		character_event = { id = Plus.2200 days = 1 }
		any_character = { character_event = { id = Plus.2275 days = 2 } }
	}
}

character_event = { #Turn tribal to feudal gov
	id = Plus.2712
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		any_independent_ruler = {
			any_demesne_province = {
				limit = {
					any_province_holding = {
						holding_type = tribal
					}
				}
				any_province_holding = {
					limit = {
						holding_type = tribal
					}
					set_title_flag = refill_levy
					convert_to = CASTLE
					hidden_tooltip = {
						refill_holding_levy = yes
					}
				}
				hidden_tooltip = {
					add_province_modifier = {
						name = new_buildings_timer
						duration = 36500
						hidden = yes
					}
				}
			}

			if = {
				limit = {
					NOT = { religion_group = muslim }
					NOT = { religion = bogomilist }
					is_tribal = yes
				}
				set_government_type = feudal_government
			}
			if = {
				limit = { 
					religion_group = muslim
					is_tribal = yes
				}
				set_government_type = muslim_government
			}
			if = {
				limit = { 
					religion = bogomilist
					is_tribal = yes
				}
				set_government_type = bogomilist_government
			}				
			if = {
				limit = {
					higher_tier_than = king
					is_tribal = yes
				}
				primary_title = {
					add_law = feudal_administration
				}
			}
			primary_title = {
				hidden_tooltip = {
					revoke_law = tribal_organization_0
					revoke_law = tribal_organization_1
					revoke_law = tribal_organization_2
					revoke_law = tribal_organization_3
					revoke_law = tribal_organization_4
				}
			}
			hidden_tooltip = {
				any_demesne_title = {
					if = {
						limit = { is_crown_law_title = yes }
						set_title_flag = do_not_destroy
					}
				}
				character_event = { id = Plus.352 days = 3 } #refill the levies
			}
			any_realm_character = {
				limit = {
					is_ruler = yes
				}
				any_demesne_province = {
					limit = {
						any_province_holding = {
							holding_type = tribal
						}
					}
					any_province_holding = {
						limit = {
							holding_type = tribal
						}
						set_title_flag = refill_levy
						convert_to = CASTLE
						hidden_tooltip = {
							refill_holding_levy = yes
						}
					}
					hidden_tooltip = {
						add_province_modifier = {
							name = new_buildings_timer
							duration = 36500
							hidden = yes
						}
					}
				}
				
				if = {
					limit = {
						NOT = { religion_group = muslim }
						NOT = { religion = bogomilist }
						is_tribal = yes
					}
					set_government_type = feudal_government
				}
				if = {
					limit = {
						religion_group = muslim
						is_tribal = yes
					}
					set_government_type = muslim_government
				}
				if = {
					limit = {
						religion = bogomilist
						is_tribal = yes
					}
					set_government_type = bogomilist_government
				}
				primary_title = {
					hidden_tooltip = {
						revoke_law = tribal_organization_0
						revoke_law = tribal_organization_1
						revoke_law = tribal_organization_2
						revoke_law = tribal_organization_3
						revoke_law = tribal_organization_4
					}
				}
				hidden_tooltip = {
					any_demesne_title = {
						if = {
							limit = { is_crown_law_title = yes }
							set_title_flag = do_not_destroy
						}
					}
					character_event = { id = Plus.352 days = 3 } #refill the levies
				}
			}
		}
	}
}

character_event = { #Go Tribal
	id = Plus.2713
	
	hide_window = yes
	is_triggered_only = yes
	
	immediate = {
		any_independent_ruler = {
			limit = {
				OR = {
					is_feudal = yes
					is_republic = yes
					is_theocracy = yes
				}
			}
			any_demesne_province = {
				capital_holding = {
					if = {
						limit = {
							NOT = { holding_type = temple }
						}
						convert_to = tribal
					}
				}
				any_province_holding = {
					limit = {
						NOT = { holding_type = tribal }
						NOT = { holding_type = temple }
					}
					destroy_settlement = THIS
				}
			}
			if = {
				limit = {
					is_theocracy = no
				}
				set_government_type = tribal_government
				if = {
					limit = { higher_tier_than = count }
					primary_title = {
						add_law = tribal_organization_0
					}
				}
			}

			any_realm_character = {
				limit = {
					is_ruler = yes
					OR = {
						is_feudal = yes
						is_republic = yes
						is_theocracy = yes
					}
				}
				any_demesne_province = {
					capital_holding = {
						if = {
							limit = {
								NOT = { holding_type = temple }
							}
							convert_to = tribal
						}
					}
					any_province_holding = {
						limit = {
							NOT = { holding_type = tribal }
							NOT = { holding_type = temple }
						}
						destroy_settlement = THIS
					}
				}
				if = {
					limit = {
						is_theocracy = no
					}
					set_government_type = tribal_government
					if = {
						limit = { higher_tier_than = count }
						primary_title = {
							add_law = tribal_organization_0
						}
					}
				}
			}
		}
	}
}

character_event = { # Set to Vanilla Italians
	id = Plus.2714
	
	is_triggered_only = yes
	hide_window = yes
	
	immediate = {
		if = {
			limit = {
				is_italian_trigger = yes
				NOT = { culture = italian }
				NOT = { culture = neapolitan }
			}
			culture = italian
		}
		if = {
			limit = {
				culture = neapolitan
			}
			culture = sicilian
		}
		any_courtier = {
			if = {
				limit = { is_italian_trigger = yes NOT = { culture = italian } NOT = { culture = neapolitan } }
				culture = italian
			}
			if = {
				limit = {
					culture = neapolitan
				}
				culture = sicilian
			}
		}
		any_realm_province = {
			if = {
				limit = { is_italian_trigger = yes NOT = { culture = italian } NOT = { culture = neapolitan } }
				culture = italian
			}
			if = {
				limit = {
					culture = neapolitan
				}
				culture = sicilian
			}
		}
		any_vassal = {
			character_event = { id = Plus.2714 }
		}
	}
}