# Empty scope
on_game_start = {
	events = {
		fp1_scandinavian_adventurers.0004	# FP1 - Organise Norse adventurers.
		fp1_scandinavian_adventurers.0011	# FP1 - Corral famous Norse adventurers that haven't done much yet.
		fp1_scandinavian_adventurers.0021	# FP1 - Mark game-start prioritised adventurers.
		#Guaranteed historical artifacts fixed spawning
		debug_portraits.1 					# Debug portraits for animation testing
		easteregg_event.0001				# Charna and Jakub duel.
	}

	effect = {
		#Epidemics 3 months grace
		set_global_variable = {
			name = start_epidemic_grace
			value = yes
			months = 3
		}
		#Rabbene Gershom outlaws polygamy
		if = {
			limit = {
				current_date >= 1000.1.1
			}
			religion:judaism_religion = {
				every_faith = {
					limit = {
						has_doctrine = temple_authority_rabbinic_doctrine
					}
					remove_doctrine = doctrine_polygamy
					add_doctrine = doctrine_monogamy
				}
			}
		}
		### 867 - RADHANITES IN KHAZARIA ###
		character:74025 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				trigger_event = bookmark.0200
			}
		}
		### 867 - WRATH OF THE NORTHMEN ###
		#Æthelred dying (probably)
		character:33358 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				trigger_event = {
					id = bookmark.0001
					days = { 365 730 }
				}
			}
		}

		#Alfred the Great becoming the Great
		character:7627 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				trigger_event = {
					id = bookmark.0002
					days = 1800 #~5 years
				}
			}
		}

		### 867 - THE GREAT ADVENTURERS ###
		character:251187 = {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
					AND = {
						character:251180 = { is_ai = yes }
						character:251181 = {
							is_ai = yes
							is_alive = yes
						}
					}
				}
				trigger_event = {
					id = bookmark.0101
					days = { 21 35 }
				}
			}
		}

		### 1066 - HASAN SABBAH STORY CYCLE ###
		character:41702 ?= {
			if = {
				limit = {
					is_alive = yes
					is_playable_character = yes
				}
				house = { set_house_head = prev }
				trigger_event = {
					id = hasan_sabbah.1000
					days = 1
				}
			}
		}
		### 1066 - EL CID STORY CYCLE ###
		character:107590 ?= {
			if = {
				limit = {
					cid_story_cycle_start_trigger = yes
				}
				trigger_event = { 
					id = cid.0001
					days = 1
				}
			}
		}
		### 1066 - LOUIS THE GERMAN ###
		if = {
			limit = {
				exists = character:90107
				current_date >= 1066.1.1
			}
			character:90107 = { give_nickname = nick_the_german_post_mortem }
		}

		### 1178 - SIBYLLA ###
		if = {
			limit = {
				exists = character:223522
				current_date >= 1178.1.1
				AND = {
					character:223541 = {
						is_ai = yes
						is_alive = yes
					}
				}
			}
			character:223522 = {
				trigger_event = {
					id = bookmark.0300
					days = { 21 28 }
				}
			}
		}

		### HRE SETUP ###
		if = {
			limit = { exists = title:e_hre.holder }
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:c_cologne
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:c_mainz
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:c_trier
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_bohemia
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_east_franconia
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_ostmark
			}
			add_to_global_variable_list = {
				name = hre_elector_list
				target = title:d_angria
			}
			hre_elector_list_save_effect = yes
			hre_margraves_effect = yes
		}

		### ARMENIAN SETUP ###
		title:e_byzantium.holder ?= {
			every_vassal = {
				limit = {
					government_has_flag = government_is_feudal
					vassal_contract_has_modifiable_obligations = yes
					faith = faith:armenian_apostolic
				}
				vassal_contract_set_obligation_level = { type = religious_rights level = 1 }
				set_vassal_contract_modification_blocked = no
			}
		}
		title:e_arabia.holder ?= {
			every_vassal = {
				limit = {
					government_has_flag = government_is_feudal
					vassal_contract_has_modifiable_obligations = yes
					faith = faith:armenian_apostolic
				}
				vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 3 }
				vassal_contract_set_obligation_level = { type = feudal_government_levies level = 2 }
				vassal_contract_set_obligation_level = { type = jizya_special_rights level = 1 }
				set_vassal_contract_modification_blocked = no
			}
		}

		### RELIGIOUS THINGS ###
		# Set up Holy Site Buildings to be buildable in Holy Sites
		religion:islam_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_mosque_01
					}
				}
			}
		}
		religion:christianity_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_cathedral_01
					}
				}
			}
		}
		religion:zoroastrianism_religion = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_fire_temple_01
					}
				}
			}
		}
		every_religion_global = {
			limit = {
				OR = {
					this = religion:hinduism_religion
					this = religion:buddhism_religion
					this = religion:jainism_religion
					this = religion:tani_religion
					this = religion:bon_religion
				}
			}
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_indian_grand_temple_01
					}
				}
			}
		}
		every_religion_global = {
			limit = {
				is_in_family = rf_pagan
			}
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_pagan_grand_temple_01
					}
				}
			}
		}
		every_religion_global = {
			every_faith = {
				every_holy_site = {
					limit = {
						title_province = {
							has_special_building_slot = no
						}
					}
					title_province = {
						add_special_building_slot = holy_site_other_grand_temple_01
					}
				}
			}
		}

		# If your capital on game start is Mecca, you get the Hajjaj trait (since you can't Hajj to your capital)
		title:b_makka.county.holder = {
			if = {
				limit = {
					faith = { has_doctrine_parameter = mandatory_hajj }
					NOT = { has_trait = hajjaj }
				}
				# Have some Hajjaj
				add_trait = hajjaj
			}
		}

		# Pagans that start pre-reformed
		## Bon has already been reformed into new bon.
		faith:old_bon = {
			set_variable = { name = has_been_reformed }
		}

		# Mark some faiths to block conversion till specific decisions are taken.
		faith:basque_pagan = {
			set_variable = { name = block_conversion_till_decision_taken }
		}
		faith:adoptionist = {
			set_variable = { name = block_conversion_till_nebulous_circumstances }
		}
		# Kuzarite cannot be reformed under normal circumstances
		faith:kabarism = {
			set_variable = { name = block_reformation_var }
		}

		### GAME RULE: EXTRA ADMINS
		apply_historic_administrative_game_rule_effect = yes

		### 1178 CRUSADE SETUP ###
		if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			religion:islam_religion = {
				set_variable = { 
					name = variable_ghw_unlocked 
					value = yes 
				}
			}
			religion:christianity_religion = {
				set_variable = { 
					name = variable_ghw_unlocked 
					value = yes 
				}
			}
			set_global_variable = {
				name = had_first_catholic_crusade
				value = yes
			}
		}
		if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			character:st_amand_1 = {
				save_scope_as = leader
			}
			character:223523 = {
				save_scope_as = founder
			}
			title:b_saida = {
				save_scope_as = barony
			}
			create_holy_order_neutral_effect = {
				LEADER = scope:leader
				CAPITAL = scope:barony
				NEW_HO_SCOPE = new_holy_order
				FOUNDER = scope:founder
			}
		}
		if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			character:231000 = {
				save_scope_as = leader
			}
			character:223523 = {
				save_scope_as = founder
			}
			title:b_hebron = {
				save_scope_as = barony
			}
			create_holy_order_neutral_effect = {
				LEADER = scope:leader
				CAPITAL = scope:barony
				NEW_HO_SCOPE = new_holy_order
				FOUNDER = scope:founder
			}
		}

		### UNIVERSITIES ###
		title:b_fes.title_province = { add_special_building_slot = generic_university }
		#title:b_bologna.title_province = { add_special_building_slot = generic_university } # Added in province history
		title:b_salamanca.title_province = { add_special_building_slot = generic_university }
		title:b_madrid.title_province = { add_special_building_slot = generic_university }
		#title:b_oxford.title_province = { add_special_building_slot = generic_university } # Added in province history
		title:b_cambridge.title_province = { add_special_building_slot = generic_university }
		title:b_padua.title_province = { add_special_building_slot = generic_university }
		title:b_coimbra.title_province = { add_special_building_slot = generic_university }
		title:b_napoli.title_province = { add_special_building_slot = generic_university }
		title:b_milano.title_province = { add_special_building_slot = generic_university }
		title:b_vienna.title_province = { add_special_building_slot = generic_university }
		title:b_praha.title_province = { add_special_building_slot = generic_university }
		title:b_perugia.title_province = { add_special_building_slot = generic_university }
		title:b_malappuram.title_province = { add_special_building_slot = generic_university }
		title:b_janakpur.title_province = { add_special_building_slot = generic_university }
		title:b_uppsala.title_province = { add_special_building_slot = generic_university }
		title:b_montlhery.title_province = { add_special_building_slot = generic_university } # Technically should be Paris, but that's occupied by Notre Dame
		title:b_qartajana.title_province = { add_special_building_slot = generic_university } # Technically should be Tunis, but that's occupied by a cathedral
		title:b_wazwan.title_province = { add_special_building_slot = generic_university } # Technically should be Isfahan, but that's occupied by the Friday Mosque
		title:b_sarsar.title_province = { add_special_building_slot = generic_university } # Technically should be Baghdad, but that's occupied by the House of Wisdom
		title:b_speyer.title_province = { add_special_building_slot = generic_university } # 1350ish, should be in Heidelberg but that's a church
		title:b_krakow.title_province = { add_special_building_slot = generic_university } # 1350ish
		title:b_pisa.title_province = { add_special_building_slot = generic_university } # 1350ish
		title:b_rostock.title_province = { add_special_building_slot = generic_university } # 1400ish
		title:b_turin.title_province = { add_special_building_slot = generic_university } # 1400ish
		title:b_ferrara.title_province = { add_special_building_slot = generic_university } # 1400ish
		title:b_leipzig.title_province = { add_special_building_slot = generic_university } # 1400ish, a city holding
		title:b_messina.title_province = { add_special_building_slot = generic_university }  # 1400ish, should be in Catania but that's a church
		title:b_barcelona.title_province = { add_special_building_slot = generic_university } # 1450ish, but still fun to build
		title:b_dumbarton.title_province = { add_special_building_slot = generic_university } # 1450ish, but still fun to build
		title:b_bidar.title_province = { add_special_building_slot = generic_university } # 1450ish, but still fun to build

		### COA ###
		if = {
			limit = {
				game_start_date <= 1000.1.1
			}
			title:e_scandinavia = { set_coa = e_scandinavia_norse }
			title:k_sweden = { set_coa = k_sweden_norse }
			title:d_svealand = { set_coa = d_svealand_norse }
			title:c_upland = { set_coa = c_upland_norse }
			title:c_gastrikland = { set_coa = c_gastrikland_norse }
			title:c_sodermannaland = { set_coa = c_sodermannaland_norse }
			title:c_aland = { set_coa = c_aland_norse }
			title:d_bergslagen = { set_coa = d_bergslagen_norse }
			title:c_vastmanland = { set_coa = c_vastmanland_norse  }
			title:c_varmland = { set_coa = c_varmland_norse }
			title:c_dalarna = { set_coa = c_dalarna_norse }
			title:c_dalabergslagen = { set_coa = c_dalabergslagen_norse }
			title:d_vastergotland = { set_coa = d_vastergotland_norse }
			title:c_vastergotland = { set_coa = c_vastergotland_norse }
			title:c_skara = { set_coa = c_skara_norse }
			title:c_dal = { set_coa = c_dal_norse }
			title:c_nordmark = { set_coa = c_nordmark_norse }
			title:d_ostergotland = { set_coa = d_ostergotland_norse }
			title:c_ostergotland = { set_coa = c_ostergotland_norse }
			title:c_kinda = { set_coa = c_kinda_norse }
			title:c_narke = { set_coa = c_narke_norse }
			title:d_smaland = { set_coa = d_smaland_norse }
			title:c_more = { set_coa = c_more_norse }
			title:c_sevede = { set_coa = c_sevede_norse }
			title:c_varend = { set_coa = c_varend_norse }
			title:c_njudung = { set_coa = c_njudung_norse }
			title:c_finnveden = { set_coa = c_finnveden_norse }
			title:c_oland = { set_coa = c_oland_norse }
			title:d_norrland = { set_coa = d_norrland_norse }
			title:c_halsingland = { set_coa = c_halsingland_norse }
			title:c_medelpad = { set_coa = c_medelpad_norse }
			title:c_angermanland = { set_coa = c_angermanland_norse }
			title:d_gotland = { set_coa = d_gotland_norse }
			title:c_gutland = { set_coa = c_gutland_norse }
			title:k_norway = { set_coa = k_norway_norse }
			title:d_viken = { set_coa = d_viken_norse }
			title:c_vingulmork = { set_coa = c_vingulmork_norse }
			title:c_raniriki = { set_coa = c_raniriki_norse }
			title:c_vestfold = { set_coa = c_vestfold_norse }
			title:c_telemark = { set_coa = c_telemark_norse }
			title:d_agder = { set_coa = d_agder_norse }
			title:c_nedenes = { set_coa = c_nedenes_norse }
			title:c_agdeside = { set_coa = c_agdeside_norse }
			title:d_vestlandi = { set_coa = d_vestlandi_norse }
			title:c_rogalandi = { set_coa = c_rogalandi_norse }
			title:c_hordalandi = { set_coa = c_hordalandi_norse }
			title:c_sogn = { set_coa = c_sogn_norse }
			title:d_trandalog = { set_coa = d_trandalog_norse }
			title:c_trandheim = { set_coa = c_trandheim_norse }
			title:c_norwegian_more = { set_coa = c_norwegian_more_norse }
			title:c_firdafylki = { set_coa = c_firdafylki_norse }
			title:d_dalir = { set_coa = d_dalir_norse }
			title:c_hedmork = { set_coa = c_hedmork_norse }
			title:c_gudbrandsdalir = { set_coa = c_gudbrandsdalir_norse }
			title:c_eystridalir = { set_coa = c_eystridalir_norse }
			title:c_gauldala = { set_coa = c_gauldala_norse }
			title:d_halogaland = { set_coa = d_halogaland_norse }
			title:c_vastvag = { set_coa = c_vastvag_norse }
			title:c_bothin = { set_coa = c_bothin_norse }
			title:c_namdalfylki = { set_coa = c_namdalfylki_norse }
			title:d_iceland = { set_coa = d_iceland_norse }
			title:c_vestisland = { set_coa = c_vestisland_norse }
			title:c_nordrland = { set_coa = c_nordrland_norse }
			title:c_austisland = { set_coa = c_austisland_norse }
			title:c_sudurland = { set_coa = c_sudurland_norse }
			title:d_northern_isles = { set_coa = d_northern_isles_norse }
			title:c_orkney = { set_coa = c_orkney_norse }
			title:c_faereyar = { set_coa = c_faereyar_norse }
			title:c_shetland = { set_coa = c_shetland_norse }
			title:d_jamtland = { set_coa = d_jamtland_norse }
			title:c_jamtfir = { set_coa = c_jamtfir_norse }
			title:c_morarna = { set_coa = c_morarna_norse }
			title:c_helgum = { set_coa = c_helgum_norse }
			title:c_harjadalen = { set_coa = c_harjadalen_norse }
			title:k_denmark = { set_coa = k_denmark_norse }
			title:d_sjaelland = { set_coa = d_sjaelland_norse }
			title:c_sjaelland = { set_coa = c_sjaelland_norse }
			title:c_fyn = { set_coa = c_fyn_norse }
			title:c_lolland_falster = { set_coa = c_lolland_falster_norse }
			title:d_skane = { set_coa = d_skane_norse }
			title:c_skane = { set_coa = c_skane_norse }
			title:c_halland = { set_coa = c_halland_norse }
			title:c_bornholm = { set_coa = c_bornholm_norse }
			title:c_blekinge = { set_coa = c_blekinge_norse }
			title:d_jylland = { set_coa = d_jylland_norse }
			title:c_aarhus = { set_coa = c_aarhus_norse }
			title:c_viborg = { set_coa = c_viborg_norse }
			title:c_ringkobing = { set_coa = c_ringkobing_norse }
			title:c_aalborg = { set_coa = c_aalborg_norse }
			title:d_slesvig = { set_coa = d_slesvig_norse }
			title:c_slesvig = { set_coa = c_slesvig_norse }
			title:c_vorbasse = { set_coa = c_vorbasse_norse }
			title:c_ribe = { set_coa = c_ribe_norse }
			title:d_york = { set_coa = d_york_norse }
			title:c_east_riding = { set_coa = c_east_riding_norse }
			title:d_western_isles = { set_coa = d_western_isles_norse }
			title:c_inner_hebrides = { set_coa = c_inner_hebrides_norse  }
			title:c_dublin = { set_coa = c_dublin_norse }
			title:c_argyll = { set_coa = c_argyll_norse }
		}
		if = {
			limit = {
				game_start_date >= 1067.12.25
			}
			title:k_england = { set_coa = k_england_norman}
		}

		### GRANDEUR ###
		#Royal Court: Set starting Grandeur to be the same as Expected
		if = {
			limit = {
				has_dlc_feature = royal_court
			}
			every_character_with_royal_court = {
				set_current_court_grandeur = court_grandeur_minimum_expected
				apply_hold_court_grace_effect = yes
				# Stops Hold Court reminders at game start
				set_variable = {
					name = last_hold_court_date
					value = current_year
				}
			}
		}

		### STRUGGLES ###
		if = {
			limit = { current_date = 867.1.1 }

			# Iberian Struggle
			if = { # If we're in 867, Aragonese should be removed from the Struggle, since they don't quite exist yet.
				limit = { exists = struggle:iberian_struggle }
				struggle:iberian_struggle = { set_culture_as_uninvolved = culture:aragonese }
			}

			# Persian Struggle
			if = { # If the load order ever changes this struggle is going to break. This must always be read before the struggle.
				limit = { exists = struggle:persian_struggle }
				debug_log = "Samarra Struggle: Gamne start data has been set"
				struggle:persian_struggle = { # Use the object explorer to debug this data (yes, the time has come to learn how to use it)

					# Struggle on_start
					fp3_remove_vassal_contract_cooldown_for_tension_effect = yes

					# Flag some titles as un-dissolutionable within the struggle.
					title:e_arabia = { set_variable = struggle_block_dissolution_faction }
					title:d_sunni = { set_variable = struggle_block_dissolution_faction }
				}
			}
		}

		### REGENCIES ###
		# Pre-defined historic regencies setup.
		## NOTE: we do these first to avoid feed messages getting weird due to regents being replaced immediately after getting their position.
		## 867.
		### None. Yet.
		## 1066.
		if = {
			limit = { game_start_date = 1066.9.15 }
			# Designate some regents.
			## King Philippe of France & Duke Boudewijn of Flanders (friend of his dad's)
			character:214 = {
				designate_diarch = character:364
				# Baldwin of Flanders also promised the prior king he'd take care of Philippe, so we add that starting loyalty hook.
				add_hook = {
					type = predecessor_loyalty_hook
					target = character:364
					years = historic_regent_loyal_after_death_hook_duration_years_char_214_value
				}
			}
			### Plus remember who the promise was made to.
			character:364 = {
				add_opinion = {
					target = character:214
					modifier = promise_to_predecessor
					opinion = 50
				}
				set_variable = {
					name = promise_to_predecessor
					value = character:208
					years = historic_regent_loyal_after_death_hook_duration_years_char_214_value
				}
			}
			## Count Bouchard of Vendome & Guy de Bachaumont (his uncle)
			character:40905 = { designate_diarch = character:40376 }
			## Caliph al-Mustansir & Rasad (his mother)
			character:3096 = { designate_diarch = character:additional_fatimids_1 }
			## Count Ermengol of Urgell & Infanta Sancha of Aragon (his stepmother)
			character:110550 = { designate_diarch = character:110514 }
			## Duke Dirk of Holland & Count Robrecht of Zeeland (his stepfather)
			character:106520 = { designate_diarch = character:368 }
			## Duke Sven of Ostergotland & Kol Sverker (his father)
			character:100530 = { designate_diarch = character:100529 }
			## King Salamon of Hungary & Queen Mother Anastasia (his mother, in the absence of any better recorded options, and to keep other hostile relatives out of the job)
			character:476 = { designate_diarch = character:637 }
			## Prince Demetre of Georgia & Alda Oseti (his mother)
			character:9957 = { designate_diarch = character:9956 }
			## Sultan al-Muazzam Alp Arslan and Hassan "the Order of the Realm".
			character:3040 = {
				designate_diarch = character:3050
				# This is a vizierate as well, so start the diarchy manually.
				start_diarchy = vizierate
				# Tell Alp that he appointed Hassan so he remembers not to dismiss him.
				set_variable = {
					name = my_vizier
					value = character:3050
				}
			}
			## Constantine X & Michael Doukas.
			character:1732 = {
				if = {
					limit = { has_ep3_dlc_trigger = yes }
					start_diarchy = co_emperorship
					set_diarch = character:1736
					set_designated_heir = character:1736
				}
			}
			# Plus remove all the generated opinions.
			## King Philippe of France & Duke Boudewijn of Flanders
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:364
				LIEGE = character:214
			}
			## Count Bouchard of Vendome & Guy de Bachaumont
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:40376
				LIEGE = character:40905
			}
			## Caliph al-Mustansir & Rasad
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:additional_fatimids_1
				LIEGE = character:3096
			}
			## Count Ermengol of Urgell & Infanta Sancha of Aragon
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:110514
				LIEGE = character:110550
			}
			## Duke Dirk of Holland & Count Robrecht of Zeeland
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:368
				LIEGE = character:106520
			}
			## Duke Sven of Ostergotland & Kol Sverker
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:100529
				LIEGE = character:100530
			}
			## King Salamon of Hungary & Queen Mother Anastasia
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:637
				LIEGE = character:476
			}
			## Prince Demetre of Georgia & Alda Oseti
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:9956
				LIEGE = character:9957
			}
			## Sultan al-Muazzam Alp Arslan and Hassan "the Order of the Realm".
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:3050
				LIEGE = character:3040
			}
		}
		if = {
			limit = { game_start_date = 1178.10.1 }
			# Set up some diarchs.
			## The future Richard I of England managing Aquitaine in place of his mother (who is under house arrest)
			character:205730 = { designate_diarch = character:204510 }
			## Jahan Pahlavan Muhammad as regent for Togrul
			character:144056 = { designate_diarch = character:144052 }
			## Manuel Komnenos and Alexios Komnenos
			character:215530 = {
				if = {
					limit = { has_ep3_dlc_trigger = yes }
					start_diarchy = junior_emperorship
					set_diarch = character:215531
					set_designated_heir = character:215531
				}
			}
			## Henry II of England and the Young King
			character:204500 = {
				designate_diarch = character:204508
				start_diarchy = co_monarchy
				set_designated_heir = character:204508
			}
			## Teresa of Portugal for Afonso the Conqueror
			character:209503 = { 
				start_diarchy = regency
				set_diarch = character:209510 
			}
			# Plus remove all the generated opinions.
			## Richard I and Eleanor of Aquitaine
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:204510
				LIEGE = character:205730
			}
			## Muhammad Jahan Pahlavan and Togrul
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:144052
				LIEGE = character:144056
			}
			## Manuel Komnenos and Alexios
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:215531
				LIEGE = character:215530
			}
			## Henry II and Young Henry
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:204508
				LIEGE = character:204500
			}
			## Teresa and Afonso
			remove_generated_diarch_consequences_effect = {
				NEW_DIARCH = character:209510
				LIEGE = character:209503
			}
		}
		# Set up anyone who should be in a regency at start whether we have sources or not.
		## If you start as a child, incapable, or imprisoned, you get a regency.
		every_ruler = {
			limit = {
				OR = {
					is_adult = no
					is_incapable = yes
					is_imprisoned = yes
				}
			}
			# We don't want to check over so many characters *twice*, so we check again inside the block to determine what type of regency to put 'em in.
			## Temporary Regencies.
			if = {
				limit = { is_imprisoned = yes }
				trigger_event = {
					id = diarchy.0001
					delayed = yes
				}
			}
			## Entrenched Regencies.
			else = {
				trigger_event = {
					id = diarchy.0011
					delayed = yes
				}
			}
		}
		# Sort custom regencies.
		## Fatimid Caliphate - basically stuck in the back-end of an entrenched regencies from game start.
		if = {
			limit = { exists = character:3096 }
			character:3096 = { trigger_event = diarchy.0012 }
		}

		### FERTILE LANDS ###
		# For deserts that are supposed to be very fertile
		title:c_taizz = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_mandab = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_zabid = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_sanaa = { add_county_modifier = fertile_desert_mountains_modifier }
		title:c_dathina = { add_county_modifier = fertile_desert_mountains_modifier }

		### HENDEKAPOLIS ###
		title:c_ionia = { add_county_modifier = dodekapolis_modifier }
		title:c_chios = { add_county_modifier = dodekapolis_modifier }
		title:c_aeolis = { add_county_modifier = dodekapolis_modifier }
		title:c_lesbos = { add_county_modifier = dodekapolis_modifier }

		### GREECE BACKWATER COUNTIES ###
		if = {
			limit = { has_ep3_dlc_trigger = yes }
			title:c_laconia = { add_county_modifier = backwater_county_modifier }
			title:c_messenia = { add_county_modifier = backwater_county_modifier }
			title:c_korinthos = { add_county_modifier = backwater_county_modifier }
			title:c_achaia = { add_county_modifier = backwater_county_modifier }
			title:c_cephalonia = { add_county_modifier = backwater_county_modifier }
			title:c_attica = { add_county_modifier = backwater_county_modifier }
			title:c_boeotia = { add_county_modifier = backwater_county_modifier }
			title:c_aetolia = { add_county_modifier = backwater_county_modifier }
			title:c_naxos = { add_county_modifier = backwater_county_modifier }
			title:c_euboea = { add_county_modifier = backwater_county_modifier }
			title:c_neopatras = { add_county_modifier = backwater_county_modifier }
			title:c_demetrias = { add_county_modifier = backwater_county_modifier }
			title:c_thessaliotis = { add_county_modifier = backwater_county_modifier }
			title:c_thessalia = { add_county_modifier = backwater_county_modifier }
			title:c_epeiros = { add_county_modifier = backwater_county_modifier }
			title:c_buthrotum = { add_county_modifier = backwater_county_modifier }
			title:c_veria = { add_county_modifier = backwater_county_modifier }
			title:c_metzovo = { add_county_modifier = backwater_county_modifier }
			title:c_chalkidike = { add_county_modifier = backwater_county_modifier }
			title:c_thessalonika = { add_county_modifier = backwater_county_modifier }
			title:c_serres = { add_county_modifier = backwater_county_modifier }
			title:c_mosynopolis = { add_county_modifier = backwater_county_modifier }
			title:c_ohrid = { add_county_modifier = backwater_county_modifier }
			title:c_antipatreia = { add_county_modifier = backwater_county_modifier }
			title:c_dyrrachion = { add_county_modifier = backwater_county_modifier }
			title:c_avlonas = { add_county_modifier = backwater_county_modifier }
		}

		### Pandidakterion IN CONSTANTINOPLE ###
		if = {
			limit = {
				has_ep3_dlc_trigger = yes
				current_date >= 1046.1.1
			}
			title:c_byzantion = { add_county_modifier = pandidakterion_university_modifier }
		}

		### Varangian Guard ###
		if = {
			limit = {
				has_ep3_dlc_trigger = yes
				current_date >= 988.1.1
			}
			title:e_byzantium = { set_variable = founded_varangian_guard }
		}

		### DEBUG GLOBAL VARIABLES ###
		# We set these here so that they present nicely and you can see when some variables register zero.

		# FP3 Struggle.
		if = {
			limit = { gather_debug_variables_for_persian_struggle_trigger = yes }
			# ENDING
			set_global_variable = {
				name = sp_end_date
				value = 0
			}
			# There's also fp3_struggle_ending; we don't track that here because it has functional usage that depends on it existing or not, so it's not a debug variable.

			# PHASES
			set_global_variable = {
				name = sp_phase_unrest
				value = 0
			}
			set_global_variable = {
				name = sp_phase_stabil
				value = 0
			}

			# UNREST
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_major
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_medium
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_minor
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_yearly_influential_house_is_antagonistic_minimal
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_becomes_rival_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_gain_claim_on_title_fp3
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_usurp_title_fp3
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_cadet_branch_created
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_supporter_forced_conversion
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_execute_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_imprison_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_unnatural_death_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_reveal_secret_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_turn_supporter_into_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_forming_alliance_between_detractor_uninvolved_rulers
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_win_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_win_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_declare_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_detractor_declare_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_unrest_catalyst_became_detractor_fp3
				value = 0
			}
			# STABILISATION
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_major
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_medium
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_minor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_yearly_influential_house_is_harmonious_minimal
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_learned_new_language_important
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_vassalize_independent_ruler
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_invite_involved_as_honorary_guests_to_feast_hunt
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_win_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_win_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_declare_unfair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_supporter_declare_fair_war_within_the_region
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_install_loyalist_cb
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_imprison_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_execute_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_unnatural_death_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_reveal_secret_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_detractor_forced_conversion
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_turn_detractor_into_supporter
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_gain_struggle_titles_from_interlopers_uninvolved
				value = 0
			}
			set_global_variable = {
				name = sp_stabil_catalyst_became_supporter_fp3
				value = 0
			}
			# CONCESSION
			set_global_variable = {
				name = sp_concession_catalyst_missing_caliphate_or_arabian_empire
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_or_emperor_loses_revolt_war
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_or_emperor_accepts_faction_demands
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_died_violently
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_caliph_died_naturally
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_war_ends_in_white_peace_between_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_became_best_friend_soulmate_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_became_friend_lover_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_forming_alliance_between_supporter_detractor_rulers
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_abandon_hook_on_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_grants_pardon_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_release_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_ransom_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_grants_vassal_to_de_jure_liege_supporter_detractor
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_gift_supporter_detractor_ruler
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_interloper_uninvolved_gain_struggle_titles
				value = 0
			}
			set_global_variable = {
				name = sp_concession_catalyst_raided_involved
				value = 0
			}
		}

		# UNITY CONFIG
		## 867.
		if = {
			limit = { game_start_date = 867.1.1 }
			# Twiddle some starting unities.
			## The Abassids are in the middle of a self-killing frenzy, so we lower theirs substantially.
			house:house_abbasid ?= {
				add_unity_value = {
					value = -100
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Samanids are juuuuust about to get started on killing each other over who gets to lead Transoxiana.
			house:house_samanid ?= {
				add_unity_value = {
					value = -40
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Afrighids (both of them) are having fairly few arguments because only one of them can speak and it's very easy to manage relations with a baby.
			dynasty:1042112.dynast.house ?= {
				add_unity_value = {
					value = 50
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Tahirids are scattered but actually get along quite well and support each other politically (mostly).
			dynasty:811.dynast.house ?= {
				add_unity_value = {
					value = 100
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
			## The Umayyads are having something of a renaissance.
			dynasty:597.dynast.house ?= {
				add_unity_value = {
					value = 100
					# This is from historical circumstances, so we just do use the house head.
					character = house_head
					desc = clan_unity_historical_circumstances.desc
				}
			}
		}
		# LEGITIMACY CONFIG
		## 867.
		if = {
			limit = { game_start_date = 867.1.1 }
			## Basileus Basileios was actually elected, so he's technically legitimate, but starts at level 2. With this he should be level 3.
			character:1700 = {
				add_legitimacy = major_legitimacy_gain
			}
		}
		
		# Cultural setup
		if = {
			limit = {
				game_start_date = 1178.10.1
			}
			culture:norman = {
				set_name_list = name_list_late_norman
			}
		}

		### EP3 BYZANTIUM IMPORTANT COUNTIES ###
		if = {
			limit = { has_ep3_dlc_trigger = yes }
			title:c_antiocheia = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_jerusalem = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_alexandria = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_abbadan = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_edessa = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_bari = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_siracusa = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_roma = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_ravenna = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_tunis = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_tangiers = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_murcia = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_lombardia = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_trier = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_cumberland = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_northumberland = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_chandax = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_tourraine = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = ep3_emperor_yearly.2000
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = ep3_emperor_yearly.2000
				}
			}
			title:c_byzantion = {
				set_important_location = {
					title = title:e_byzantium
					enter_realm_event = roman_restoration.1200
				}
				set_important_location = {
					title = title:e_roman_empire
					enter_realm_event = roman_restoration.1200
				}
			}
		}
		
		# Byzantine name game rule
		title:e_byzantium = {
			if = {
				limit = {
					has_game_rule = eastern_rome_name_of_byzantium
				}
				set_title_name = e_eastern_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = roman_empire_name_of_byzantium
				}
				set_title_name = e_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = romania_name_of_byzantium
				}
				set_title_name = e_romania_empire
			}
			else_if = {
				limit = {
					has_game_rule = empire_of_the_greeks_name_of_byzantium
				}
				set_title_name = e_empire_of_the_greeks
			}
			else_if = {
				limit = {
					has_game_rule = rhomaion_name_of_byzantium
				}
				set_title_name = e_rhomaion
			}
			else_if = {
				limit = {
					has_game_rule = unholy_roman_empire_name_of_byzantium
				}
				set_title_name = e_unholy_roman_empire
			}
		}
		
		# Admin - Let's give existing governors the Governor trait on game start
		every_independent_ruler = {
			limit = { government_allows = administrative }
			every_vassal = {
				limit = {
					is_governor = yes
					NOT = { has_trait = governor }
				}
				add_trait = governor
				add_trait_xp = {
					trait = governor
					value = {
						add = primary_title.title_held_years
						multiply = 2
					}
				}
			}
		}
	}
}

# Like on_game_start, except it is called once the host (or player, in single player) exits the lobby. Good for anything where you need to know who the players are, or what the game rules are
on_game_start_after_lobby = {
	effect = {
		# Make sure that Realm Priests are landed theocrats where it makes sense
		every_ruler = {
			limit = {
				highest_held_title_tier >= tier_duchy
			}
			if = {
				limit = {
					exists = cp:councillor_court_chaplain
					cp:councillor_court_chaplain = {
						is_ruler = no
					}
					faith = { has_doctrine = doctrine_clerical_succession_spiritual_fixed_appointment }
					any_vassal = {
						is_physically_able_adult = yes
						is_councillor = no
						government_has_flag = government_is_theocracy
						can_be_court_chaplain_trigger = { COURT_OWNER = liege }
						faith = liege.faith
					}
				}
				random_vassal = {
					limit = {
						is_physically_able_adult = yes
						is_councillor = no
						government_has_flag = government_is_theocracy
						can_be_court_chaplain_trigger = { COURT_OWNER = liege }
						faith = liege.faith
					}
					weight = {
						base = 1
						modifier = {
							add = 1000
							faith.religious_head ?= this
						}
						modifier = {
							add = learning
						}
						modifier = {
							add = primary_title.tier
						}
					}
					liege = {
						assign_councillor_type = {
							type = councillor_court_chaplain
							remove_existing_councillor = yes
							target = prev
						}
					}
				}
			}
			if = {
				limit = {
					is_landless_adventurer = yes
				}
				if = { limit = { has_realm_law = crown_authority_0 } remove_realm_law = crown_authority_0 }
			}
		}

		### GAME RULE: VIEW ON SAME-SEX RELATIONS
		if = {
			limit = { has_game_rule = accepted_same_sex_relations }
			game_rule_accepted_same_sex_relations_effect = yes
		}

		### GAME RULE: RANDOM RULER PLACEMENT
		if = {
			limit = { NOT = { has_game_rule = random_ruler_placement_off } }
			game_rule_random_ruler_placement_effect = yes
		}

		### GAME RULE: RANDOMIZE FAITH
		if = {
			limit = { has_game_rule = randomized_faiths_on }
			game_rule_randomize_faith_effect = yes
		}

		### GAME RULE: FAITH ACCEPTANCE
		if = {
			limit = { has_game_rule = full_faith_acceptance }
			game_rule_faith_acceptance_effect = yes
		}

		### GAME RULE: GENDER EQUALITY ###
		if = {
			limit = { has_game_rule = full_gender_equality }
			game_rule_full_gender_equality_effect = yes
		}
		else_if = {
			limit = { has_game_rule = inversed_gender_equality }
			game_rule_inversed_gender_equality_effect = yes
		}

		### GAME RULE: SEXUALITY DISTRIBUTION ###
		if = {
			limit = { NOT = { has_game_rule = sexuality_distribution_default } }
			game_rule_sexuality_distribution_effect = yes
		}
		else = { # So that children 10+ starts with a sexuality
			child_sexuality_distribution_effect = yes
		}

		### GAME RULE: STRUGGLE TOGGLES
		struggle:iberian_struggle ?= {
			if = {
				limit = { has_game_rule = struggle_iberia_toggle_off }
				end_struggle = yes
			}
		}
		struggle:persian_struggle ?= {
			if = {
				limit = { has_game_rule = struggle_persia_toggle_off }
				end_struggle = yes
			}
		}

		### GAME RULE: RULER OF MUNSTER
		if = {
			limit = {
				game_start_date = 1066.9.15
				has_game_rule = historicity_ruler_of_munster_historical_toirdelbach
			}
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = title_change
			}
			character:83355 = {
				every_held_title = {
					limit = { tier >= tier_county }
					change_title_holder = {
						holder = character:906
						change = scope:title_change
					}
				}
				pay_short_term_gold = {
					target = character:83355
					gold = gold
				}
			}
			random_player = {
				limit = { this = character:83355 }
				set_player_character = character:906
			}
			resolve_title_and_vassal_change = scope:title_change
			# Since Murchad is back to his historical self, he gets to suck.
			character:83355 = {
				add_diplomacy_skill = -10
				remove_trait = gregarious
				add_trait = craven
				# Plus, usurpation rivalry — now Toidelbach has a perfectly good claim to the kingdom and will do a lot more with it than Murchad managed in his 5m in power, but by gameplay terms, this _is_ a usurpation.
				set_relation_rival = {
					target = character:906
					reason = rival_usurper
				}
			}
			# Alright, let's give Toirdelbach his alliance.
			character:906 = {
				add_opinion = {
					modifier = perk_negotiated_alliance_opinion
					target = character:922
				}
				reverse_add_opinion = {
					modifier = event_negotiated_alliance_opinion
					target = character:922
				}
				create_alliance = {
					target = character:922
					allied_through_owner = character:906
					allied_through_target = character:922
				}
			}
		}

		### GAME RULE: DETERMINISTIC CONQUEST
		if = {
			limit = {
				OR = {
					NOT = { has_game_rule = historicity_norman_conquest_default_random }
					game_rule_rig_norman_conquest_for_hereward_trigger = yes
				}
			}
			set_global_variable = deterministic_conquest_of_england_1066
			# See if we should just teleport our combatants' armies into place.
			trigger_event = {
				id = game_rule.1151
				trigger_on_next_date = 1066.09.25
			}
			trigger_event = {
				id = game_rule.1152
				trigger_on_next_date = 1066.10.14
			}
		}

		### 867 - MISC ###
		# Basileios has just murdered Michael III.
		character:1700 ?= { trigger_event = bookmark.0211 }

		### GAME RULE: EXTRA ADMINS
		## We'll be doing some excessive triggers below in a bid to lightly future-proof + error-spam mods less, don't worry about it.
		### We handle players after the lobby.
		# Historic chars.
		apply_historic_administrative_game_rule_effect = yes
		# Players.
		if = {
			limit = { has_dlc_feature = roads_to_power }
			if = {
				limit = {
					NOT = { has_game_rule = historicity_extra_admin_player_wherever_gameplay_not_administrative }
				}
				if = {
					limit = { has_game_rule = historicity_extra_admin_player_wherever_alt_historic_always }
					every_player = {
						limit = {
							highest_held_title_tier >= tier_kingdom
							NOR = {
								government_has_flag = government_is_administrative
								government_has_flag = government_is_landless_adventurer
							}
						}
						convert_to_administrative_from_feudalism_game_start_effect = yes
					}
				}
				else_if = {
					limit = { has_game_rule = historicity_extra_admin_player_wherever_alt_historic_with_august_trait }
					every_player = {
						limit = {
							highest_held_title_tier >= tier_kingdom
							NOR = {
								government_has_flag = government_is_administrative
								government_has_flag = government_is_landless_adventurer
							}
							has_trait = august
						}
						convert_to_administrative_from_feudalism_game_start_effect = yes
					}
				}
			}
		}

		# Give Ruler Designer characters regencies.
		every_in_global_list = {
			variable = rd_chars_needing_regencies
			trigger_event = diarchy.0011
			# Aaaand clean the list.
			save_temporary_scope_as = char_temp
			remove_list_global_variable = {
				name = rd_chars_needing_regencies
				target = scope:char_temp
			}
		}

		### ACHIEVEMENT: FROM RAGS TO RICHES
		every_player = {
			limit = { highest_held_title_tier = tier_county }
			add_achievement_global_variable_effect = {
				VARIABLE = achievement_rags_to_riches_valid
				VALUE = yes
			}
		}

		### ACHIEVEMENT (FP2): Holidaying in Iberia
		every_player = {
			limit = { fp2_character_involved_in_struggle_trigger = no }
			add_achievement_global_variable_effect = {
				VARIABLE = fp2_holiday_in_iberia_achievement_unlocked
				VALUE = no # Boolean in actual usage
			}
		}

		### ACHIEVEMENT TRACKING FOR STARTING CHARACTERS
		if = {
			limit = { has_multiple_players = no }
			every_player = {
				# Base Title
				if = {
					limit = {
						exists = character:7757
						this = character:7757
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_give_a_dog_a_bone_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:1128
						this = character:1128
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_wily_as_the_fox_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							AND = {
								exists = character:108501
								this = character:108501
							}
							AND = {
								exists = character:107500
								this = character:107500
							}
							AND = {
								exists = character:107501
								this = character:107501
							}
							AND = {
								exists = character:108500
								this = character:108500
							}
							AND = {
								exists = character:109500
								this = character:109500
							}
						}
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_sibling_rivalry_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							AND = {
								exists = character:163108
								this = character:163108
							}
							AND = {
								exists = character:163110
								this = character:163110
							}
							AND = {
								exists = character:163111
								this = character:163111
							}
							AND = {
								exists = character:163112
								this = character:163112
							}
							AND = {
								exists = character:163119
								this = character:163119
							}
						}
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_blood_eagle_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:6448
						this = character:6448
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_kings_to_the_seventh_generation_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:140
						this = character:140
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_norman_yoke_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:522
						this = character:522
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_royal_dignity_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:40605
						this = character:40605
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_land_of_the_rus_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:251187
						this = character:251187
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_mother_of_us_all_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							culture = { has_cultural_pillar = heritage_iberian }
							culture = culture:andalusian
						}
						has_religion = religion:christianity_religion
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_reconquista_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						culture = culture:irish
						capital_province = { geographical_region = custom_ireland }
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_the_emerald_isle_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						OR = {
							culture = culture:castilian
							culture = culture:basque
							culture = culture:portuguese
							culture = culture:catalan
							culture = culture:andalusian
							culture = culture:visigothic
							culture = culture:suebi
						}
						has_religion = religion:islam_religion
						capital_province = { geographical_region = world_europe_west_iberia }
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_al_andalus_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:159137
						this = character:159137
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_almost_there_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:109607
						this = character:109607
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_last_count_first_king_achievement
						VALUE = yes
					}
				}
				if = {
					limit = {
						exists = character:6878
						this = character:6878
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_going_places_achievement
						VALUE = yes
					}
				}
				# FP1
				## far_from_home_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_far_from_home_achievement
						VALUE = yes
					}
				}
				## miklagardariki_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_miklagardariki_achievement
						VALUE = yes
					}
				}
				## canute_the_greater_achievement
				add_achievement_global_variable_effect = {
					VARIABLE = started_canute_the_greater_achievement
					VALUE = yes
				}
				## king_of_all_the_isles_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_king_of_all_the_isles_achievement
						VALUE = yes
					}
				}
				## faster_than_the_fox_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_faster_than_the_fox_achievement
						VALUE = yes
					}
				}
				## volva_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse-cultured character.
						fp1_achievement_culture_plus_religion_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_volva_achievement
						VALUE = yes
					}
				}
				## saga_in_stone_achievement
				add_achievement_global_variable_effect = {
					VARIABLE = started_saga_in_stone_achievement
					VALUE = yes
				}
				## first_of_the_crusader_kings_achievement
				if = {
					limit = {
						# Starting as a Norse-cultured character.
						fp1_achievement_culture_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_first_of_the_crusader_kings_achievement
						VALUE = yes
					}
				}
				## vladimirs_second_choice_achievement
				if = {
					limit = {
						# Starting as a Norse pagan Norse or Rus-cultured character.
						fp1_achievement_culture_norse_or_rus_trigger = yes
						fp1_achievement_religious_norse_trigger = yes
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_vladimirs_second_choice_achievement
						VALUE = yes
					}
				}
				## a_dangerous_business_achievement
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_dangerous_business_achievement
					VALUE = yes
				}
				# EP1
				##1 Patronage
				add_achievement_global_variable_effect = {
					VARIABLE = started_patronage_achievement
					VALUE = yes
				}
				##2 Converging Paths
				add_achievement_global_variable_effect = {
					VARIABLE = started_converging_paths_achievement
					VALUE = yes
				}
				##3 Changing course
				add_achievement_global_variable_effect = {
					VARIABLE = started_changing_course_achievement
					VALUE = yes
				}
				##4 Hoarder
				add_achievement_global_variable_effect = {
					VARIABLE = started_hoarder_achievement
					VALUE = yes
				}
				##5 creme de la creme
				add_achievement_global_variable_effect = {
					VARIABLE = started_creme_de_la_creme_achievement
					VALUE = yes
				}
				##6 Give it back!
				add_achievement_global_variable_effect = {
					VARIABLE = started_polyglot_achievement
					VALUE = yes
				}
				##7 Inspirational
				add_achievement_global_variable_effect = {
					VARIABLE = started_inspirational_achievement
					VALUE = yes
				}
				##8 One of a Kind
				add_achievement_global_variable_effect = {
					VARIABLE = started_one_of_a_kind_achievement
						VALUE = yes
				}
				##9 True Tolerance
				add_achievement_global_variable_effect = {
					VARIABLE = started_true_tolerance_achievement
					VALUE = yes
				}
				##10 Delusions of Grandeur
				add_achievement_global_variable_effect = {
					VARIABLE = started_delusions_of_grandeur_achievement_achievement
					VALUE = yes
				}
				##11 Bod Chen Po
				if = {
					limit = {
						this.dynasty = dynasty:105800
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_bod_chen_po_achievement
						VALUE = yes
					}
				}
				##12 Turkish Eagle
				if = {
					limit = {
						NOT = { this = character:3040 } # Not Alp Arslan
						house = house:house_seljuk # Seljuk
						game_start_date < 1067.1.1 # 1066 only, and no Seljuks in 867
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_turkish_eagle_achievement
						VALUE = yes
					}
				}
				##13 Rise of the Ghurids
				if = {
					limit = {
						has_title = title:d_ghur
						this.dynasty = dynasty:791 #Ghurid
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_rise_of_the_ghurids_achievement
						VALUE = yes
					}
				}
				##14 Brave and Bold
				if = {
					limit = {
						game_start_date < 868.1.1
						this.dynasty = dynasty:699 #Piast
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_brave_and_bold_achievement
						VALUE = yes
					}
				}
				##15 Lingua Franca
				add_achievement_global_variable_effect = {
					VARIABLE = started_lingua_franca_achievement
					VALUE = yes
				}
				##16 Beta Israel
				add_achievement_global_variable_effect = {
					VARIABLE = started_beta_israel_achievement
					VALUE = yes
				}
				## 17 They belong in a museum!
				add_achievement_global_variable_effect = {
					VARIABLE = started_they_belong_in_a_museum_achievement
					VALUE = yes
				}
				##18 I made this!
				add_achievement_global_variable_effect = {
					VARIABLE = started_i_made_this_achievement
					VALUE = yes
				}
				##19 Nobody Comes to Fika!
				add_achievement_global_variable_effect = {
					VARIABLE = started_nobody_comes_to_fika_achievement
					VALUE = yes
				}
				## 20 The True Royal Court
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_true_royal_court_achievement
						VALUE = yes
				}
				# EP2
				## 01. The Grandest Tour
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_grandest_tour_achievement
					VALUE = yes
				}
				## 02. Your Eternal Reward
				add_achievement_global_variable_effect = {
					VARIABLE = started_your_eternal_reward_achievement
					VALUE = yes
				}
				## 03. Imperial March
				add_achievement_global_variable_effect = {
					VARIABLE = started_imperial_march_achievement
					VALUE = yes
				}
				## 04. Black Dinner
				add_achievement_global_variable_effect = {
					VARIABLE = started_black_dinner_achievement
					VALUE = yes
				}
				## 05. There and Back Again
				add_achievement_global_variable_effect = {
					VARIABLE = started_there_and_back_again_achievement
					VALUE = yes
				}
				## 06. The Very Best
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_very_best_achievement
					VALUE = yes
				}
				## 07. Like No One Ever Was
				add_achievement_global_variable_effect = {
					VARIABLE = started_like_no_one_ever_was_achievement
					VALUE = yes
				}
				## 08. A Thousand and One Night
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_thousand_and_one_nights_achievement
					VALUE = yes
				}
				## 09. A Knight's Tale
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_knights_tale_achievement
					VALUE = yes
				}
				## 10. Hunting Accident
				add_achievement_global_variable_effect = {
					VARIABLE = started_hunting_accident_achievement
					VALUE = yes
				}
				## 11. Lions and Tigers and Bears, Oh My!
				add_achievement_global_variable_effect = {
					VARIABLE = started_lions_and_tigers_and_bears_oh_my_achievement
					VALUE = yes
				}
				## 12. Fly, my Pretty!
				add_achievement_global_variable_effect = {
					VARIABLE = started_fly_my_pretty_achievement
					VALUE = yes
				}
				## 13. Pathway to Heaven
				add_achievement_global_variable_effect = {
					VARIABLE = started_pathway_to_heaven_achievement
					VALUE = yes
				}
				## 14. Sir Lance-a-Lot
				add_achievement_global_variable_effect = {
					VARIABLE = started_sir_lance_a_lot_achievement
					VALUE = yes
				}
				## 15. I'm in my Element(s)
				add_achievement_global_variable_effect = {
					VARIABLE = started_im_in_my_elements_achievement
					VALUE = yes
				}
				## 16. Ahab
				add_achievement_global_variable_effect = {
					VARIABLE = started_ahab_achievement
					VALUE = yes
				}
				## 17. Little William Marshal
				add_achievement_global_variable_effect = {
					VARIABLE = started_little_william_marshal_achievement
					VALUE = 0
				}
				add_achievement_global_variable_effect = {
					VARIABLE = little_william_marshal_achievement_tally
					VALUE = 0
				}
				## 18. A True & Perfect Knight
				add_achievement_global_variable_effect = {
					VARIABLE = started_a_true_and_perfect_knight_achievement
					VALUE = yes
				}
				## 19. A.E.I.O.U & Me
				if = {
					limit = {
						# Etichonen, of whom the Hapsburgs are a cadet - we check dynasty rather than house so that an accidental cadet doesn't screw you.
						this.house ?= house:house_habsburg
					}
					add_achievement_global_variable_effect = {
						VARIABLE = started_a_e_i_o_u_and_me_achievement
						VALUE = yes
					}
				}
				## 20. The Iron and Golden King
				add_achievement_global_variable_effect = {
					VARIABLE = started_the_iron_and_golden_king_achievement
					VALUE = yes
				}

				### RULER DESIGNER ACHIEVEMENT BLOCKS ###
				if = {
					limit = {
						num_virtuous_traits >= 3
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_paragon_of_virtue_achievement_flag	}
				}
				if = {
					limit = {
						any_child = {
							count >= 10
							is_alive = yes
						}
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_the_succession_is_safe_achievement_flag }
				}
				if = {
					limit = {
						any_child = {
							has_trait = inbred
						}
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_keeping_it_in_the_family_achievement_flag }
				}
				if = {
					limit = {
						highest_held_title_tier >= tier_empire
						should_be_naked_trigger = yes
					}
					add_achievement_flag_effect = { FLAG = rd_character_blocked_the_emperors_new_clothes_achievement_flag }
				}
				if = {
					limit = {
						is_from_ruler_designer = yes
						OR = {
							fp1_achievement_culture_norse_trigger = yes
							fp1_achievement_religious_norse_trigger = yes
						}
					}
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_far_from_home_achievement }
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_miklagardariki_achievement }
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_faster_than_the_fox_achievement }
				}
				if = {
					limit = {
						any_ruler = {
							is_from_ruler_designer = yes
						}
					}
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_iberia_or_iberia_achievement }
					add_to_global_unavailable_achievements_list_effect = { FLAG = flag:rd_character_blocked_el_cid_achievement }
					add_achievement_global_variable_effect = {
						VARIABLE = any_ruler_designed_character_achievement
						VALUE = yes
					}
				}
			}
		}

		### ACHIEVEMENT (FP3): The Ummayad Strikes Back
		every_player = {
			if = {
				limit = {
					dynasty = character:73683.dynasty
					location = { geographical_region = world_europe_west_iberia }
				}
				set_global_variable = fp3_the_umma_strikes_back_achievement_tracker # Is not removed (sad!)
			}
		}
		
		### ACHIEVEMENT: FROM RAGS TO RICHES TO RAGS TO RICHES 
		every_player = {
			limit = { highest_held_title_tier = tier_county }
			add_achievement_global_variable_effect = {
				VARIABLE = achievement_rags_to_riches_to_rags_to_riches_valid
				VALUE = yes
			}
		}

		#Set starting cultural acceptance
		culture:vlach = {
			change_cultural_acceptance = {
				target = culture:serbian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:croatian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:bosnian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:bulgarian
				value = 40
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:khazar = {
			change_cultural_acceptance = {
				target = culture:radhanite
				value = 25
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:mordvin
				value = 30
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:meshchera
				value = 30
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:muroma
				value = 30
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:russian
				value = 30
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:norse = {
			change_cultural_acceptance = {
				target = culture:sami
				value = 20
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:finnish
				value = 20
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:swedish = {
			change_cultural_acceptance = {
				target = culture:sami
				value = 20
				desc = cultural_acceptance_historical_relations
			}
			change_cultural_acceptance = {
				target = culture:finnish
				value = 20
				desc = cultural_acceptance_historical_relations
			}
		}
		culture:norwegian = {
			change_cultural_acceptance = {
				target = culture:sami
				value = 20
				desc = cultural_acceptance_historical_relations
			}
		}
		# In 867, the Slavic cultures are still very similar to each other, so we start them off at a very high tolerance.
		if = {
			limit = { current_date = 867.1.1 }
			# West Slavic.
			culture:pommeranian = {
				change_cultural_acceptance = {
					target = culture:czech
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:polish
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:polabian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:czech = {
				change_cultural_acceptance = {
					target = culture:polish
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:polabian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:polish = {
				change_cultural_acceptance = {
					target = culture:polabian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:polabian = {
				change_cultural_acceptance = {
					target = culture:slovien
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:slovien = {
				change_cultural_acceptance = {
					target = culture:carantanian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:carantanian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:croatian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			# South Slavic.
			culture:croatian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bosnian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:bosnian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:serbian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:serbian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:bulgarian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:bulgarian = {
				change_cultural_acceptance = {
					target = culture:russian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			# East Slavic.
			culture:russian = {
				change_cultural_acceptance = {
					target = culture:ilmenian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			culture:ilmenian = {
				change_cultural_acceptance = {
					target = culture:severian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:volhynian
					value = 50
					desc = cultural_acceptance_historical_relations
				}
			}
			## Volhynian doesn't get its own box, because we've already applied acceptance to it bilaterally everywhere else.
			#Splitting up Byzantine heritage means we need a little help reflecting historical relations
			culture:greek = {
				change_cultural_acceptance = {
					target = culture:armenian
					value = 20
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:georgian
					value = 20
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:alan
					value = 5
					desc = cultural_acceptance_historical_relations
				}
			}
		}
		if = {
			limit = {
				game_start_date >= 1066.1.1
				game_start_date < 1178.1.1
			}
			culture:greek = {
				change_cultural_acceptance = {
					target = culture:armenian
					value = 40
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:georgian
					value = 25
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:alan
					value = 10
					desc = cultural_acceptance_historical_relations
				}
			}
		}
		if = {
			limit = { game_start_date >= 1178.1.1 }
			culture:greek = {
				change_cultural_acceptance = {
					target = culture:armenian
					value = 30
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:georgian
					value = 15
					desc = cultural_acceptance_historical_relations
				}
				change_cultural_acceptance = {
					target = culture:alan
					value = 10
					desc = cultural_acceptance_historical_relations
				}
			}
		}


		# Specific innovation unlock
		if = {
			limit = {
				game_start_date >= 1066.1.1
			}
			every_culture_global = {
				limit = {
					OR = {
						has_cultural_pillar = heritage_arabic
						this = culture:yemeni
					}
				}
				add_innovation = innovation_ghilman
			}
		}
		# Custom ruler under the HRE should have lowered feudal obligations
		if = {
			limit = { exists = title:e_hre.holder }
			title:e_hre.holder ?= {
				every_vassal = {
					limit = {
						vassal_contract_has_modifiable_obligations = yes
					}
					vassal_contract_decrease_obligation_level = feudal_government_taxes
					vassal_contract_decrease_obligation_level = feudal_government_levies
					set_vassal_contract_modification_blocked = no
				}
			}
		}
		### CE1 LEGITIMACY SETUP ###
		every_ruler = {
			limit = {
				has_legitimacy = yes
			}
			add_legitimacy = base_legitimacy_value
		}
		
		if = { # Special historical events for Matilda!
			limit = {
				character:7757 ?= { is_alive = yes }
			}
			character:7757 ?= {
				trigger_event = bookmark.1066 # Matildas marriage to her step-brother, with plausible historical options!
				trigger_event = { # Matildas suspected witchcraft, the player decides if its true or not!
					id = bookmark.1067
					years = { 1 5 }
				}
			}
		}
		
		if = { # Special historical events for Vratislav!
			limit = {
				character:522 ?= { is_alive = yes }
			}
			character:522 ?= {
				trigger_event = { # Vratislav and the Slavic Marches, he didn't historically get them (one briefly, but eh). The player chooses to appease the emperor or go after the coveted lands themselves!
					id = bookmark.1068
					days = { 35 120 }
				}
				trigger_event = { # Jaromir, Vratislav's brother, was a pain - this event is an opportunity for the player to handle the rivalry
					id = bookmark.1069
					days = { 1 29 }
				}
			}
		}
		
		if = { # Special historical events for Robert the Fox!
			limit = {
				character:1128 ?= { is_alive = yes }
			}
			character:1128 ?= {
				trigger_event = { # A Norman Sicily - Robert historically conquered quite a bit here, the player can choose how far they want to go and the risk they want to take. The more risk, the more event troops/claims.
					id = bookmark.1070
					days = { 35 120 }
				}
				trigger_event = { # The Pretender Monk - Raiktor is a historical character, a monk wo pretended to be a deposed Byzantine emperor which Robert used to beat up Byzantium. Here you can follow historical conquests (taking a bit of the coast) or go full on 'install him as emperor for real'-mode!
					id = bookmark.1071
					years = { 1 7 }
				}
			}
		}
		
		if = { # Special historical events for Emir Yahya!
			limit = {
				character:3924 ?= { is_alive = yes }
			}
			character:3924 ?= {
				trigger_event = { # Conquering Cordoba - Gain an opportunity to conquer Cordoba while gaining one of two buffs; one intrigue-focused, and one military. Historically he was poisoned after having conquered the city... but that's no fun for the player!
					id = bookmark.1072
					days = { 10 35 }
				}
			}
		}

		### EP3 SETUP ###
		if = {
			limit = { has_ep3_dlc_trigger = yes }
			### EP3 LAAMP SETUP ###
			# Resources.
			every_independent_ruler = {
				limit = { is_landless_adventurer = yes }
				# Cash.
				add_gold = {
					value = {
						value = 0
						add = prestige
						add = piety
						divide = 10
					}
				}
				save_temporary_scope_as = adventurer_scope
				# Set CoA
				primary_title = { set_coa = scope:adventurer_scope.house }
				# Cleanup characters
				every_councillor = {
					if = {
						limit = {
							NOR = {
								has_council_position = councillor_court_chaplain
								has_council_position = councillor_spouse
							}
						}
						scope:adventurer_scope = {
							fire_councillor = prev
						}
						remove_opinion = {
							modifier = fired_from_council_opinion
							target = scope:adventurer_scope
						}
					}
					else_if = {
						limit = {
							NOR = {
								is_close_or_extended_family_of = prev
								has_relation_lover = prev
								has_relation_friend = prev
								is_consort_of = prev
								has_council_position = councillor_spouse
							}
						}
						death = {
							death_reason = death_vanished
						}
					}
				}
				# Evict everyone who isn't your family from your camp.
				every_courtier = {
					limit = {
						prev = { save_temporary_scope_as = char_temp }
						NOR = {
							dynasty ?= scope:char_temp.dynasty
							is_imprisoned_by = scope:char_temp
							# Plus any relations, who are presumably meant to be here.
							has_important_relationship_with_character_trigger = { CHARACTER = scope:char_temp }
							# Catch bastards and such that may be left over.
							is_close_or_extended_family_of = scope:char_temp
						}
					}
					move_to_pool = yes
				}
				# Courtiers.
				trigger_event = ep3_laamps.1001
			}
			# Starting camp purposes.
			## Hereweard the Wake
			character:90028 ?= {
				if = {
					limit = { is_alive = yes }
					add_realm_law_skip_effects = camp_purpose_brigands
					if = {
						limit = {
							character:90160 = {
								NOT = { is_courtier_of = character:90028 }
							}
						}
						add_courtier = character:90160
					}
				}
				# Setup event for his story
				trigger_event = {
					id = ep3_laamps.5999
					days = { 1 2 }
				}
			}
			## El Cid 
			character:107590 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
					if = {
						limit = {
							character:71391 = {
								NOT = { is_courtier_of = character:107590 }
							}
						}
						add_courtier = character:71391
					}
					if = {
						limit = {
							character:castilian0248 = {
								NOT = { is_courtier_of = character:107590 }
							}
						}
						add_courtier = character:castilian0248
					}
					if = {
						limit = {
							character:castilian0249 = {
								NOT = { is_courtier_of = character:107590 }
							}
						}
						add_courtier = character:castilian0249
					}
				}
			}
			## Robert Crispin
			character:norman_crispin_06 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
				}
			}
			## Hassan Sabbah
			character:41702 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_scholars
				}
			}
			## Suleyman Qutalmishog
			character:3046 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
					trigger_event = bookmark.1073 # Suleyman's beef with Alp Arslan
				}
			}
			## Wallada bint al-Mustakfi
			character:andalusian_0003 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_scholars
					trigger_event = ep3_story_cycle_violet_poet.0001
				}
			}
			## Roger Raoul
			character:232504 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
				}
			}
			## Taylu Danişmend
			character:danishmendid_1 ?= {
				if = {
					limit = {
						is_alive = yes
						is_landless_adventurer = yes
					}
					add_realm_law_skip_effects = camp_purpose_mercenaries
				}
			}
			every_independent_ruler = {
				limit = { is_landless_adventurer = yes }
				# C... food.
				domicile = { change_provisions = starting_provisions_value }
				# Contracts
				if = {
					limit = { is_ai = no }
					# Set up additional firing contracts.
					player_adventurer_contract_generation_on_wait_in_place_effect = yes
					#generate contracts if you are far away from your previous location
					player_adventurer_contract_generation_on_domicile_moved_effect = yes
				}
				else = {
					create_story = { type = story_adventurer_ai }
					trigger_event = {
						on_action = on_adventurer_ai_new_employer_arrival
						days = { 10 30 }
					}
				}
				# Sort our starting flavourisation.
				if = {
					limit = { has_realm_law = camp_purpose_mercenaries }
					set_variable = flavourise_camp_purpose_mercenaries
				}
				else_if = {
					limit = { has_realm_law = camp_purpose_wanderers }
					set_variable = flavourise_camp_purpose_wanderers
				}
				else_if = {
					limit = { has_realm_law = camp_purpose_scholars }
					set_variable = flavourise_camp_purpose_scholars
				}
				else_if = {
					limit = { has_realm_law = camp_purpose_explorers }
					set_variable = flavourise_camp_purpose_explorers
				}
				else_if = {
					limit = { has_realm_law = camp_purpose_brigands }
					set_variable = flavourise_camp_purpose_brigands
				}
				else_if = {
					limit = { has_realm_law = camp_purpose_legitimists }
					set_variable = flavourise_camp_purpose_legitimists
				}
				# And tally our numbers for performance purposes.
				add_to_global_variable_list = {
					name = laamps_tally
					target = this.primary_title
				}
			}
			### EP3 ADMIN SETUP ###
			every_independent_ruler = {
				limit = { government_allows = administrative }
				save_scope_as = top_liege
				### EP3 NOBLE FAMILIES & DOMICILE SETUP ###
				random_held_title = { # May be removed once every_noble_family includes liege (TIT-51212)
					limit = { is_noble_family_title = yes }
					set_coa = scope:top_liege.house
				}
				every_noble_family = {
					# Ensure Noble Family CoA match House
					set_coa = holder.house
					# Ensure holders of historical noble family titles are the default house heads
					holder ?= {
						save_scope_as = nf_holder
						if = {
							limit = { is_landed = yes }
							capital_province = { save_scope_as = domicile_location }
						}
						# TODO_CD_EP3: remove once TIT-51212 is resolved and confirmed
						house ?= {
							if = {
								limit = { house_head != scope:nf_holder }
								set_house_head = scope:nf_holder
							}
						}
					}
					set_color_from_title = scope:nf_holder.capital_county
				}
			}
		}
		# Byzantium naming
		title:e_byzantium = {
			if = {
				limit = {
					has_game_rule = eastern_rome_name_of_byzantium
				}
				set_title_name = e_eastern_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = roman_empire_name_of_byzantium
				}
				set_title_name = e_roman_empire
			}
			else_if = {
				limit = {
					has_game_rule = romania_name_of_byzantium
				}
				set_title_name = e_romania_empire
			}
			else_if = {
				limit = {
					has_game_rule = empire_of_the_greeks_name_of_byzantium
				}
				set_title_name = e_empire_of_the_greeks
			}
			else_if = {
				limit = {
					has_game_rule = rhomaion_name_of_byzantium
				}
				set_title_name = e_rhomaion
			}
			else_if = {
				limit = {
					has_game_rule = unholy_roman_empire_name_of_byzantium
				}
				set_title_name = e_unholy_roman_empire
			}
		}
		# Saharan stuff.
		every_county_in_region = {
			region = custom_sahara_proper
			# Every county is in the region, not every province of every county, so we go to county to avoid iterating over every world province _then_ check which ones are in the region.
			every_county_province = { apply_saharan_provisions_debuff_effect = yes }
		}
		# 1066 Buildings
		if = {
			limit = {
				game_start_date >= 1066.1.1
				game_start_date < 1178.10.1
			}
			every_province = {
				limit = {
					has_holding = yes
				}
				generate_building = yes
				brewery_counter_start_effect = yes
			}
			every_domicile = {
				if = {
					limit = {
						is_domicile_type = estate
					}
					if = {
						limit = {
							NOT = { has_domicile_building_or_higher = estate_main_02 }
							owner.culture ?= { has_innovation = innovation_city_planning }
						}
						add_domicile_building = estate_main_02
						add_random_internal_estate_building = yes
					}
					
					fill_external_estate_building_effect = yes
				}
			}
		}
		# 1178 Buildings
		else_if = {
			limit = {
				game_start_date >= 1178.10.1
			}
			every_province = {
				limit = {
					has_holding = yes
				}
				generate_building = yes
				generate_building = yes
				generate_building = yes
				generate_building = yes
				generate_building = yes
				generate_building = yes
				if = {
					limit = {
						county.development_level >= 8
					}
					generate_building = yes
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 10
					}
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 12
					}
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 14
					}
					generate_building = yes
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 16
					}
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 18
					}
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 20
					}
					generate_building = yes
				}
				if = {
					limit = {
						county.development_level >= 25
					}
					generate_building = yes
					generate_building = yes
					generate_building = yes
				}
				brewery_counter_start_effect = yes
			}
			every_domicile = {
				#if = { # Left in if we want adventurers to spawn with stuff
				#	limit = {
				#		is_domicile_type = camp
				#	}
				#	add_domicile_building = camp_main_02
				#	add_domicile_building = camp_main_03
				#	random_list = {
				#		10 = {
				#			add_domicile_building = supply_tent_01
				#			add_domicile_building = supply_tent_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = supply_tent_sutler
				#				}
				#				10 = {
				#					add_domicile_building = supply_tent_mender
				#				}
				#				10 = {
				#					add_domicile_building = supply_tent_smithy
				#				}
				#				10 = {
				#					add_domicile_building = supply_tent_arsenal
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = barber_tent_01
				#			add_domicile_building = barber_tent_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = barber_tent_surgeons_tools
				#				}
				#				10 = {
				#					add_domicile_building = barber_tent_dentists_tools
				#				}
				#				10 = {
				#					add_domicile_building = barber_tent_torturers_tools
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = baggage_train_01
				#			add_domicile_building = baggage_train_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = baggage_train_ample_steeds
				#				}
				#				10 = {
				#					add_domicile_building = baggage_train_porters
				#				}
				#				10 = {
				#					add_domicile_building = baggage_train_trackers
				#				}
				#				10 = {
				#					add_domicile_building = baggage_train_kennel
				#				}
				#			}
				#		}
				#	}
				#	random_list = {
				#		10 = {
				#			add_domicile_building = mess_tent_01
				#			add_domicile_building = mess_tent_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = mess_tent_herbalists
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_brewers
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_curers
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_bakers
				#				}
				#				10 = {
				#					add_domicile_building = mess_tent_cooks
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = camp_fire_01
				#			add_domicile_building = camp_fire_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = camp_fire_trailing_musicians
				#				}
				#				10 = {
				#					add_domicile_building = camp_fire_wandering_poets
				#				}
				#				10 = {
				#					add_domicile_building = camp_fire_capering_fools
				#				}
				#				10 = {
				#					add_domicile_building = camp_fire_libations_for_the_lost
				#				}
				#			}
				#		}
				#	}
				#	random_list = {
				#		10 = {
				#			add_domicile_building = camp_perimeter_01
				#			add_domicile_building = camp_perimeter_02
				#			random_list = {
				#				10 = {
				#					add_domicile_building = camp_perimeter_good_siting
				#				}
				#				10 = {
				#					add_domicile_building = camp_perimeter_fixed_layout
				#				}
				#			}
				#		}
				#		10 = {
				#			add_domicile_building = proving_grounds_01
				#			add_domicile_building = proving_grounds_02
				#		}
				#	}
				#}
				if = {
					limit = {
						is_domicile_type = estate
					}
					if = {
						limit = {
							NOT = { has_domicile_building_or_higher = estate_main_02 }
							owner.culture ?= { has_innovation = innovation_city_planning }
						}
						add_domicile_building = estate_main_02
						add_random_internal_estate_building = yes
					}
					if = {
						limit = {
							has_domicile_building = estate_main_02
							NOT = { has_domicile_building_or_higher = estate_main_03 }
							owner.culture ?= { has_innovation = innovation_manorialism }
						}
						add_domicile_building = estate_main_03
						while = {
							count = 2
							add_random_internal_estate_building = yes
						}
					}
					
					fill_external_estate_building_effect = yes
				}
			}
		}
		# Purge family titles if Admin isn't enabled
		if = {
			limit = {
				NOT = { has_dlc_feature = roads_to_power }
			}
			every_ruler = {
				save_temporary_scope_as = this_ruler
				every_held_title = {
					limit = {
						has_title_law = noble_family_succession_law
					}
					scope:this_ruler = {
						destroy_title = prev
					}
				}
			}
		}
		# Conquerors
		character:144133 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		character:144141 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		character:175080 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		character:226000 ?= {
			if = {
				limit = {
					is_alive = yes
					NOT = { has_game_rule = no_conquerors_frequency }
				}
				create_story = story_conqueror
			}
		}
		#NEOW
		#Benelux claims
		character:benelux0002 ?= {
			if = {
				limit = {
					is_alive = yes
				}
				trigger_event = benelux.1
			}
		}
		character:benelux0003 ?= {
			if = {
				limit = {
					is_alive = yes
				}
				trigger_event = benelux.2
			}
		}
		character:benelux0004 ?= {
			if = {
				limit = {
					is_alive = yes
				}
				trigger_event = benelux.3
			}
		}
	}
	events = {
		game_rule.1000	#Autopopulate families.
		game_rule.1011	#Hungarian Migration management.
		historical_artifacts.0023			# Historical Artifacts Generator
	}
}

#$CHARACTER$.house = {
#			save_scope_as = character_house
#
#			add_unity_value = {
#				value = {
#					value = $VALUE$
#					if = { # House heads have a larger impact on unity
#						limit = { house_head = $CHARACTER$ }
#						multiply = unity_house_head_multiplier_value
#					}
#				}
#				character = $CHARACTER$
#				desc = $DESC$
#			}
#		}

