decisions = {

	### ENGLAND
	
	abolish_witan_william = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			NOT = { has_global_flag = witan_abolished_norwegian }
			NOT = { has_global_flag = witan_abolished }
			has_character_flag = william_the_conqueror
			has_landed_title = k_england
		}

		allow = {
			war = no
			prisoner = no
		}

		effect = {
			set_global_flag = witan_abolished
			character_event = { id = Plus.500 }
		}

		ai_will_do = {
			factor = 1
		}
	}
	
	abolish_witan_hardrada = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			NOT = { has_global_flag = witan_abolished_norwegian }
			NOT = { has_global_flag = witan_abolished }
			has_character_flag = harald_hardrada
			has_landed_title = k_england
		}

		allow = {
			war = no
			prisoner = no   
		}

		effect = {
			set_global_flag = witan_abolished_norwegian
			character_event = { id = Plus.501 }
		}

		ai_will_do = {
			factor = 1	
		}
	}

	invade_england_sveinn = {
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 3
		potential = {
			independent = yes
			has_landed_title = k_denmark
			NOT = { has_landed_title = k_england }
			k_england = { has_holder = yes }
			has_character_flag = sveinn_forkbeard
			NOT = {
				has_character_flag = millenium_england_invasion
				religion_group = muslim
				is_pagan_religion = yes
			}
		}

		allow = {
			war = no
			has_regent = no
			prestige = 800
			piety = 0
			wealth = 0
		}

		effect = {
			set_character_flag = millenium_england_invasion
			prestige = 50
			hidden_tooltip = {
				k_england = {
					holder_scope = {
						character_event = { id = Plus.544 days = 1 }
					}
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}	

	ai_form_england = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			ai = yes
			is_ruler = yes
			has_regent = no
			OR = {
				tier = DUKE
				AND = {
					tier = KING
					primary_title = { is_titular = yes }
				}
			}
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			culture_group = west_germanic
			k_england = { has_holder = no }
			capital_scope = {
				region = custom_england
			}
			NOT = {
				has_global_flag = witan_abolished
				has_global_flag = witan_abolished_norwegian
			}
		}
		allow = {
			war = no
			piety = 0
			wealth = 50
			num_of_duke_titles = 2
			any_realm_title = {
				tier = count
				de_jure_liege_or_above = k_england
				count = 20
			}
		}
		effect = {
			k_england = { grant_title = ROOT }
			any_demesne_title = {
				limit = {
					tier = KING
					is_titular = yes
				}
				destroy_landed_title = THIS
			}
			prestige = 300
			wealth = -50
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = content
					trait = humble
				}
			}
		}
	}
	
	form_great_britain = {
		only_independent = yes
		ai_check_interval = 12
		potential = {
			OR = {
				has_landed_title = k_england
				has_landed_title = k_scotland
				has_landed_title = k_wales
			}
			NOR = {
				is_title_active = e_great_britain
				e_great_britain = { has_title_flag = gb_formed }
				e_britannia = { has_holder = yes }
			}
			independent = yes
		}
		allow = {
			war = no
			has_regent = no
			piety = 0
			wealth = 500
			prestige = 1000
			has_empire_size_trigger = yes
			is_adult = yes
			has_landed_title = k_england
			has_landed_title = k_scotland
			has_landed_title = k_wales
		}
		effect = {
			wealth = -500
			prestige = -1000
			activate_title = { title = e_great_britain status = yes }
			k_england = { de_jure_liege = e_great_britain }
			k_scotland = { de_jure_liege = e_great_britain }
			k_wales = { de_jure_liege = e_great_britain }
			primary_title = { save_event_target_as = primary_british_title }
			e_great_britain = {
				gain_title = ROOT
				copy_title_laws = event_target:primary_british_title
			}
			clear_event_target = primary_british_title
		}
		ai_will_do = {
			factor = 1
		}
	}

	### IRELAND
	
	claim_high_king = {
		only_playable = yes
		ai_check_interval = 12
		potential = {
			is_playable = yes
			is_tribal = yes
			culture = irish
			capital_scope = { region = custom_ireland }
			k_ireland = {
				has_holder = yes
				holder_scope = {
					is_tribal = yes
					NOT = { reverse_has_truce = ROOT }
					NOT = { has_non_aggression_pact_with = ROOT }
				}
			}
			NOT = {
				has_regent = yes
				has_landed_title = k_ireland
				has_strong_claim = k_ireland
				any_heir_title = { title = k_ireland }
				any_demesne_title = { temporary = yes }
			}
		}
		allow = {
			tier = DUKE
			trait = ambitious
			prestige = 250
		}
		effect = {
			set_character_flag = justified_claimant
			prestige = -250
			add_claim = k_ireland
			hidden_tooltip = {
				k_ireland = {
					holder_scope = {
						character_event = { id = Plus.563 }
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					war = yes
					any_liege = { war = yes }
				}
			}
			modifier = {
				factor = 0
				k_ireland = {
					holder_scope = {
						reverse_opinion = { who = ROOT value = 25 }
					}
				}
			}
			modifier = {
				factor = 0
				trait = humble
			}
		}
	}
	
	ai_form_ireland = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			ai = yes
			is_ruler = yes
			has_regent = no
			OR = {
				tier = DUKE
				AND = {
					tier = KING
					primary_title = { is_titular = yes }
				}
			}
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			culture_group = celtic
			k_ireland = { has_holder = no }
			capital_scope = {
				region = custom_ireland
			}
		}
		allow = {
			war = no
			piety = 0
			wealth = 50
			num_of_duke_titles = 2
			any_realm_title = {
				tier = count
				de_jure_liege_or_above = k_ireland
				count = 10
			}
		}
		effect = {
			k_ireland = { grant_title = ROOT }
			any_demesne_title = {
				limit = {
					tier = KING
					is_titular = yes
				}
				destroy_landed_title = THIS
			}
			prestige = 200
			wealth = -50
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = content
					trait = humble
				}
			}
		}
	}
	
	### ITALY / SICILY
	
	sicily_falls = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			k_papal_state = { has_title_flag = schism_happened }
			has_landed_title = k_papal_state # He always exists		
			NOT = {
				has_global_flag = emf_nwo
				has_global_flag = sicily_falls
				has_global_flag = italian_rec_success
				has_global_flag = italian_rec_failure
				has_global_flag = christian_crusades_unlocked # This event unlocks them
			}
		}
		allow = { # Don't fire if independent Christians still inhabit k_sicily
			c_benevento = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_teate = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_foggia = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}			
			c_capua = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_napoli = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_gaete = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_apulia = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_bari = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_lecce = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_salerno = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_taranto = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_amalfi = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_consenza = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_reggio = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_palermo = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_messina = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_siracusa = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_agrigento = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_trapani = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}
			c_malta = {
				holder_scope = {
					top_liege = { NOT = { religion_group = christian } }
				}
			}		
		}
		effect = {
			set_global_flag = sicily_falls
			set_global_flag = italian_reconquest_planning
			k_papal_state = {
				holder_scope = {
					add_character_modifier = {
						name = italian_reconquest_pope
						duration = -1
						inherit = yes
						hidden = yes
					}
				}
			}
			any_playable_ruler = { narrative_event = { id = Plus.504 } }
		}
		ai_will_do = {
			factor = 1
		}		
	}
	
	sicily_regained = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			has_global_flag = italian_reconquest_started
			NOT = { 
				has_global_flag = italian_rec_success
				has_global_flag = italian_rec_failure
			}
			OR = {
				has_landed_title = d_benevento
				has_landed_title = d_capua
				has_landed_title = d_apulia
				has_landed_title = d_salerno
				has_landed_title = d_calabria
				has_landed_title = d_sicily
			}
			has_character_modifier = italian_reconquest 
		}
		allow = {
			war = no
			custom_tooltip = {
				text = italian_reconq_ctt
				c_benevento = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_teate = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_foggia = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}				
				c_capua = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_napoli = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_gaete = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_apulia = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_bari = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_lecce = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_salerno = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_taranto = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_amalfi = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_consenza = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_reggio = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_palermo = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_messina = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_siracusa = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_agrigento = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_trapani = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
				c_malta = {
					holder_scope = {
						top_liege = { religion_group = christian }
					}
				}
			}
		}
		effect = {
			set_global_flag = italian_rec_success
			set_global_flag = christian_crusades_unlocked
			k_sicily = { gain_title = ROOT }
			prestige = 500
			hidden_tooltip = {
				remove_character_modifier = italian_reconquest
				narrative_event = { id = Plus.516 }
				any_playable_ruler = {
					limit = { NOT = { character = ROOT } }
					narrative_event = { id = Plus.510 }
				}
			}
		}
		ai_will_do = {
			factor = 1
		}	
	}
	
	### ALBANIA
	
	create_kingdomofalbania = {
		ai_check_interval = 12
		potential = {
			NOT = { has_global_flag = kingdom_of_albania_formed }
			470 = { culture = arberian }
			completely_controls = c_dyrrachion
			completely_controls = c_valona
			k_albania = { is_titular = yes }
			OR = {
				tier = KING
				tier = EMPEROR 
				AND = {
					num_of_duke_titles = 2
					culture_group = south_slavic
				}
				AND = {
					num_of_duke_titles = 2
					culture = arberian
				}
			}
			NOT = {
				OR = {
					has_landed_title = e_roman_empire
					has_landed_title = e_byzantium
				}
			}
		}

		allow = {
			treasury = 300
			OR = {
				piety = 500
				prestige = 500
			}
			OR = {
				independent = yes
				tier = KING
			}
		}

		effect = {
			set_global_flag = kingdom_of_albania_formed
			treasury = -300
			narrative_event = { id = Plus.522 }
		}

		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { wealth = 500 }
			}
			modifier = {
				factor = 0
				higher_real_tier_than = DUKE
				NOT = { realm_size = 75 }
			}
			modifier = {
				factor = 0
				NOT = { culture_group = south_slavic }
			}
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
		}
	}
	
	### POLAND
	
	extend_claims_boleslaw = {
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 12
		potential = {
			has_character_flag = boleslaw_the_brave
			NOT = { has_character_flag = extend_claim_boleslaw }
			independent = yes
			has_landed_title = d_moravia
			NOT = { has_landed_title = d_bohemia }
		}

		allow = {
			war = no
			prisoner = no
			prestige = 500
			piety = 0
			wealth = 0
		}

		effect = {
			set_character_flag = extend_claim_boleslaw
			prestige = 50
			add_claim = c_lausitz
			add_claim = d_bohemia
			hidden_tooltip = {
				random_independent_ruler = {
					limit = { has_landed_title = d_bohemia }
					character_event = { id = Plus.524 }
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	become_king_of_poland_boleslaw = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			has_character_flag = boleslaw_the_brave
			has_character_flag = extend_claim_boleslaw
			piety = 0
			wealth = 0
			has_landed_title = d_silesia
			has_landed_title = d_greater_poland
			has_landed_title = d_lesser_poland
			NOT = { has_character_flag = k_poland_boleslaw }
			k_poland = { has_holder = no }
		}

		allow = {
			war = no
			prisoner = no
			independent = yes
			has_landed_title = d_moravia
			prestige = 1000
		}

		effect = {
			set_character_flag = k_poland_boleslaw
			prestige = 200
			k_poland = { grant_title = ROOT }
		}

		ai_will_do = {
			factor = 1
		}
	}
	
	### HRE
	
	papal_coronation  = {
		is_high_prio = yes
		only_independent = yes
		potential = {
			is_feudal = yes
			independent = yes
			OR = {
				religion = catholic
				religion = chalcedonian
			}
			is_heretic = no
			tier = EMPEROR
			OR = {
				has_landed_title = e_hre
				has_landed_title = e_karling
			}
			NOR = {
				has_character_flag = wants_coronation
				trait = crowned_by_pope
			}
		}
		allow = {
			war = no
			has_regent = no
			prestige = 1000
			scaled_wealth = 1.0
			piety = 200
			is_adult = yes
			custom_tooltip = {
				text = POPE_WOULD_HEAR_REQUEST
				hidden_tooltip = {
					NOT = { trait = excommunicated }
					rightful_religious_head_scope = {
						NOT = {
							has_opinion_modifier = {
								who = ROOT
								modifier = coronation_rejected
							}
						}
					}
				}
			}
		}
		effect = {
			set_character_flag = wants_coronation
			scaled_wealth = -1.0
			character_event = { id = Plus.1175 }
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	first_coronation = {
		is_high_prio = yes
		only_playable = yes
		potential = {
			e_hre = { has_holder = no }
			e_roman_empire = { has_holder = no }
			is_playable = yes
			higher_tier_than = DUKE
			is_heretic = no				
			OR = {
				religion = catholic
				religion = chalcedonian
			}			
			rightful_religious_head_scope = {
				NOT = { character = ROOT }
				OR = {
					has_landed_title = k_papal_state
					has_landed_title = k_papal_chalcedon
				}
			}			
			e_karling = { has_title_flag = carolingian_empire_fallen }
			NOR = {
				is_title_active = e_karling
				e_hre = { has_title_flag = hre_formed }
				has_global_flag = rome_restored
				rightful_religious_head_scope = { has_character_flag = approached_for_coronation }
			}
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			prestige = 1000
			piety = 100
			realm_size = 150
			is_adult = yes
			custom_tooltip = {
				text = NOT_DEPOSED_EMPEROR
				hidden_tooltip = {
					NOT = { has_character_flag = former_carolingian_emperor }
				}
			}
			has_landed_title = k_germany
			custom_tooltip = {
				text = CONTROLS_6_GERMAN_DUCHIES
				hidden_tooltip = {
					any_realm_title = {
						count = 6
						tier = DUKE
						dejure_liege_title = {
							OR = {
								title = k_germany
								title = k_bavaria
								title = k_saxony
							}
						}
						OR = {
							holder_scope = { same_realm = ROOT }
							any_direct_de_jure_vassal_title = {
								count = 3
								holder_scope = { same_realm = ROOT }
							}
							any_direct_de_jure_vassal_title = {
								OR = {
									dejure_liege_title = { title = d_thuringia }
									dejure_liege_title = { title = d_baden }
									dejure_liege_title = { title = d_osterreich }
									dejure_liege_title = { title = d_tyrol }
								}
								count = 2
								holder_scope = { same_realm = ROOT }
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = POPE_WOULD_HEAR_REQUEST
				hidden_tooltip = {
					NOT = { trait = excommunicated }
					rightful_religious_head_scope = {
						NOT = {
							has_opinion_modifier = {
								who = ROOT
								modifier = coronation_rejected
							}
						}
					}
				}
			}
		}
		effect = {
			rightful_religious_head_scope = {
				set_character_flag = approached_for_coronation
				letter_event = { id = Plus.1155 tooltip = ask_for_coronation }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	form_the_hre_early = {
		is_high_prio = yes
		only_playable = yes
		potential = {
			e_hre = { has_holder = no }
			e_roman_empire = { has_holder = no }
			is_playable = yes
			higher_tier_than = DUKE
			is_heretic = no			
			OR = {
				religion = catholic
				religion = chalcedonian
			}
			rightful_religious_head_scope = {
				NOT = { character = ROOT }
				OR = {
					has_landed_title = k_papal_state
					has_landed_title = k_papal_chalcedon
				}
			}
			NOR = {
				dynasty = 25061
				is_title_active = e_karling
				e_karling = { has_title_flag = carolingian_empire_formed }
				e_hre = { has_title_flag = hre_formed }
				has_global_flag = rome_restored
				rightful_religious_head_scope = { has_character_flag = approached_for_coronation }
			}
		}
		allow = {
			war = no
			has_regent = no
			independent = yes
			prestige = 1000
			piety = 100
			realm_size = 150
			custom_tooltip = {
				text = POPE_WOULD_HEAR_REQUEST
				hidden_tooltip = {
					NOT = { trait = excommunicated }
					rightful_religious_head_scope = {
						NOT = {
							has_opinion_modifier = {
								who = ROOT
								modifier = coronation_rejected
							}
						}
					}
				}
			}
			custom_tooltip = {
				text = CONTROL_ANY_THREE_KINGDOMS
				hidden_tooltip = {
					calc_true_if = {
						amount = 3
						AND = {
							k_france = { is_titular = no }
							OR = {
								has_landed_title = k_france
								any_vassal = { has_landed_title = k_france }
							}
						}
						AND = {
							k_lotharingia = { is_titular = no }
							OR = {
								has_landed_title = k_lotharingia
								any_vassal = { has_landed_title = k_lotharingia }
							}
						}
						AND = {
							k_saxony = { is_titular = no }
							OR = {
								has_landed_title = k_saxony
								any_vassal = { has_landed_title = k_saxony }
							}
						}
						AND = {
							k_bavaria = { is_titular = no }
							OR = {
								has_landed_title = k_bavaria
								any_vassal = { has_landed_title = k_bavaria }
							}
						}
						AND = {
							k_italy = { is_titular = no }
							OR = {
								has_landed_title = k_italy
								any_vassal = { has_landed_title = k_italy }
							}
						}
						AND = {
							k_germany = { is_titular = no }
							OR = {
								has_landed_title = k_germany
								any_vassal = { has_landed_title = k_germany }
							}
						}
					}
				}
			}
		}
		effect = {
			rightful_religious_head_scope = {
				set_character_flag = approached_for_coronation
				letter_event = { id = Plus.1155 tooltip = ask_for_coronation }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	form_brandenburg = {
		only_independent = yes
		ai_check_interval = 12
		potential = {
			higher_real_tier_than = COUNT
			NOT = { is_title_active = k_brandenburg }
			OR = {
				has_landed_title = e_hre
				any_liege = { has_landed_title = e_hre }
			}
			OR = {
				independent = yes
				liege = { tier = EMPEROR }
			}
			capital_scope = {
				OR = {
					empire = { title = e_hre }
					duchy = { title = d_brandenburg }
				}
			}
		}
		allow = {
			war = no
			has_regent = no
			piety = 0
			wealth = 500
			prestige = 1000
			completely_controls = d_brandenburg
			OR = {
				completely_controls = d_meissen
				any_liege = { completely_controls = d_meissen }
			}
		}
		effect = {
			wealth = -500
			prestige = -1000
			hidden_tooltip = {
				if = {
					limit = { independent = no }
					liege = { save_event_target_as = current_liege }
				}
			}
			activate_title = { title = k_brandenburg status = yes }
			d_brandenburg = { de_jure_liege = k_brandenburg }
			d_meissen = { de_jure_liege = k_brandenburg }
			k_brandenburg = { 
				gain_title = ROOT
				de_jure_liege = e_hre
			}
			if = {
				limit = { event_target:current_liege = { is_alive = yes } }
				set_defacto_liege = event_target:current_liege
				pf_liege_change_effect = yes
			}
			any_realm_province = {
				limit = {
					NOT = { religion = ROOT }
					OR = {
						duchy = { title = d_brandenburg }
						duchy = { title = d_meissen }
					}
				}
				random = {
					chance = 50
					religion = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	### NORSE
	
	organise_braedralag = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			is_ruler = yes
			higher_tier_than = count
			OR = {
				religion = norse_pagan
				religion = norse_pagan_reformed
			}
			NOT = { has_global_flag = braedralag_founded }
		}
		allow = {
			tier = emperor
			has_regent = no
			prestige = 300
			wealth = 300	
		}
		effect = {
			set_global_flag = braedralag_founded
			prestige = -300
			wealth = -300
			activate_title = { title = d_braedralag status = yes }
			hidden_tooltip = {
				d_braedralag = { religion = ROOT }
				narrative_event = { id = Plus.553 }
				create_character = {
					random_traits = yes
					religion = ROOT
					culture = ROOT
					dynasty = NONE
					female = no
					age = 34
					trait = skilled_tactician
					trait = berserker
					trait = viking
					trait = zealous
				}
				new_character = {
					d_braedralag = {
						grant_title = PREV
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { prestige = 500 }
				NOT = { wealth = 500 }
			}
		}
	}
	
	become_braedralag = {
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 12
		potential = {
			tier = count
			religion = norse_pagan_reformed
			has_regent = no
			ai = yes
			independent = yes
			NOT = { has_global_flag = braedralag_founded }
		}
		allow = {
			piety = 300
			trait = zealous
			OR = {
				trait = viking
				trait = berserker
				trait = holy_warrior
			}
		}
		effect = {
			hidden_tooltip = {
				set_global_flag = braedralag_founded
				narrative_event = { id = Plus.553 }
			}
			activate_title = { title = d_braedralag status = yes }
			d_braedralag = {
				grant_title = ROOT
				religion = ROOT
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	organise_jomsvikings = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			is_ruler = yes
			higher_tier_than = count
			OR = {
				religion = norse_pagan
				religion = norse_pagan_reformed
			}
			NOT = { has_global_flag = jomsvikings_founded }
		}
		allow = {
			has_regent = no
			higher_tier_than = duke
			prestige = 300
			wealth = 300
		}
		effect = {
			set_global_flag = jomsvikings_founded
			prestige = -300
			wealth = -300
			activate_title = { title = d_jomsvikings status = yes }
			hidden_tooltip = {
				d_jomsvikings = { religion = ROOT }
				narrative_event = { id = Plus.555 }
				create_character = {
					random_traits = yes
					religion = ROOT
					culture = ROOT
					dynasty = NONE
					female = no
					age = 34
					trait = skilled_tactician
					trait = berserker
					trait = viking
					trait = zealous
				}
				new_character = {
					d_jomsvikings = {
						grant_title = PREV
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { prestige = 500 }
				NOT = { wealth = 500 }
			}
			modifier = {
				factor = 0
				NOT = { total_years_played = 5 }
			}
		}
	}
	
	claim_sami = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			has_landed_title = k_sweden
			NOT = { culture = lappish }
			d_norrland = { de_jure_liege = k_sami }
			OR = {
				k_sami = { has_holder = no }
				completely_controls = d_norrland
				any_vassal = { has_landed_title = d_norrland }
			}
			NOT = { has_global_flag = sami_claimed }
		}
		
		allow = {
			war = no
			has_regent = no
			ruled_years = 5
			prestige = 100
		}
		
		effect = {
			set_global_flag = sami_claimed
			prestige = 50
			hidden_tooltip = {
				d_norrland = {
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							NOT = { culture = ROOT }
						}
						opinion = {
							who = ROOT
							modifier = opinion_outraged
							years = 10
						}
					}
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							culture = ROOT
						}
						opinion = {
							who = ROOT
							modifier = opinion_furious
							years = 10
						}
					}
					if = {
						limit = { has_holder = yes }
						holder_scope = {
							opinion = {
								who = ROOT
								modifier = opinion_outraged
								years = 20
							}
						}
					}
				}
			}
			d_norrland = {
				de_jure_liege = k_sweden
				set_name=""
				adjective=""
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	claim_finnmark = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			has_landed_title = k_norway
			NOT = { culture = lappish }
			d_nordland = { de_jure_liege = k_sami }
			OR = {
				k_sami = { has_holder = no }
				completely_controls = d_nordland
				any_vassal = { has_landed_title = d_nordland }
			}
			NOT = { has_global_flag = finnmark_claimed }
		}
		
		allow = {
			war = no
			has_regent = no
			ruled_years = 5
			prestige = 100
		}
		
		effect = {
			set_global_flag = finnmark_claimed
			prestige = 50
			hidden_tooltip = {
				d_nordland = {
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							NOT = { culture = ROOT }
						}
						opinion = {
							who = ROOT
							modifier = opinion_outraged
							years = 10
						}
					}
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							culture = ROOT
						}
						opinion = {
							who = ROOT
							modifier = opinion_furious
							years = 10
						}
					}
					if = {
						limit = { has_holder = yes }
						holder_scope = {
							opinion = {
								who = ROOT
								modifier = opinion_outraged
								years = 20
							}
						}
					}
				}
			}
			d_nordland = {
				de_jure_liege = k_norway
				set_name=""
				adjective=""
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	
	claim_kola = {
		is_high_prio = yes
		ai_check_interval = 12
		potential = {
			OR = {
				has_landed_title = k_finland
				AND = {
					has_landed_title = d_finland
					has_global_flag = finnmark_claimed
					has_global_flag = sami_claimed
				}
			}
			NOT = { culture = lappish }
			d_osterbotten = { de_jure_liege = k_sami }
			d_kola = { de_jure_liege = k_sami }
			OR = {
				k_sami = { has_holder = no }
				completely_controls = d_osterbotten
				any_vassal = { has_landed_title = d_osterbotten }
			}
			NOT = { has_global_flag = kola_claimed }
		}
		
		allow = {
			war = no
			has_regent = no
			ruled_years = 5
			prestige = 100
		}
		
		effect = {
			set_global_flag = kola_claimed
			prestige = 50
			hidden_tooltip = {
				d_osterbotten = {
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							NOT = { culture = ROOT }
						}
						opinion = {
							who = ROOT
							modifier = opinion_outraged
							years = 10
						}
					}
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							culture = ROOT
						}
						opinion = {
							who = ROOT
							modifier = opinion_furious
							years = 10
						}
					}
					if = {
						limit = { has_holder = yes }
						holder_scope = {
							opinion = {
								who = ROOT
								modifier = opinion_outraged
								years = 20
							}
						}
					}
				}
				d_kola = {
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							NOT = { culture = ROOT }
						}
						opinion = {
							who = ROOT
							modifier = opinion_outraged
							years = 10
						}
					}
					any_de_jure_vassal = {
						limit = {
							NOT = { is_liege_or_above = ROOT }
							culture = ROOT
						}
						opinion = {
							who = ROOT
							modifier = opinion_furious
							years = 10
						}
					}
					if = {
						limit = { has_holder = yes }
						holder_scope = {
							opinion = {
								who = ROOT
								modifier = opinion_outraged
								years = 20
							}
						}
					}
				}
			}
			d_osterbotten = {
				de_jure_liege = k_finland
				set_name=""
				adjective=""
			}
			d_kola = {
				de_jure_liege = k_finland
			}
		}
		
		ai_will_do = {
			factor = 1
		}
	}

	ai_form_sweden = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			ai = yes
			is_ruler = yes
			has_regent = no
			OR = {
				tier = DUKE
				AND = {
					tier = KING
					primary_title = { is_titular = yes }
				}
			}
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			culture_group = north_germanic
			k_sweden = { has_holder = no }
			capital_scope = {
				region = custom_sweden
			}
		}
		allow = {
			war = no
			piety = 0
			wealth = 50
			num_of_duke_titles = 2
			any_realm_title = {
				tier = count
				de_jure_liege_or_above = k_sweden
				count = 11
			}
		}
		effect = {
			k_sweden = { grant_title = ROOT }
			any_demesne_title = {
				limit = {
					tier = KING
					is_titular = yes
				}
				destroy_landed_title = THIS
			}
			prestige = 200
			wealth = -50
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = content
					trait = humble
				}
			}
		}
	}
	
	ai_form_norway = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			ai = yes
			is_ruler = yes
			has_regent = no
			OR = {
				tier = DUKE
				AND = {
					tier = KING
					primary_title = { is_titular = yes }
				}
			}
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			culture_group = north_germanic
			k_norway = { has_holder = no }
			capital_scope = {
				region = custom_norway
			}
		}
		allow = {
			war = no
			piety = 0
			wealth = 50
			num_of_duke_titles = 2
			any_realm_title = {
				tier = count
				de_jure_liege_or_above = k_norway
				count = 6
			}
		}
		effect = {
			k_norway = { grant_title = ROOT }
			any_demesne_title = {
				limit = {
					tier = KING
					is_titular = yes
				}
				destroy_landed_title = THIS
			}
			prestige = 200
			wealth = -50
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = content
					trait = humble
				}
			}
		}
	}
	
	ai_form_denmark = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			ai = yes
			is_ruler = yes
			has_regent = no
			OR = {
				tier = DUKE
				AND = {
					tier = KING
					primary_title = { is_titular = yes }
				}
			}
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			culture_group = north_germanic
			k_denmark = { has_holder = no }
			capital_scope = {
				region = custom_denmark
			}
		}
		allow = {
			war = no
			piety = 0
			wealth = 50
			num_of_duke_titles = 2
			any_realm_title = {
				tier = count
				de_jure_liege_or_above = k_denmark
				count = 6
			}
		}
		effect = {
			k_denmark = { grant_title = ROOT }
			any_demesne_title = {
				limit = {
					tier = KING
					is_titular = yes
				}
				destroy_landed_title = THIS
			}
			prestige = 200
			wealth = -50
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				OR = {
					trait = content
					trait = humble
				}
			}
		}
	}
	
	# Saxon
	
	organise_harii = {
		is_high_prio = yes
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			is_ruler = yes
			higher_tier_than = count
			OR = {
				religion = german_pagan
				religion = german_pagan_reformed
			}
			NOT = { has_global_flag = harii_founded }
		}
		allow = {
			has_regent = no
			higher_tier_than = duke
			prestige = 300
			wealth = 300
		}
		effect = {
			set_global_flag = harii_founded
			prestige = -300
			wealth = -300
			activate_title = { title = d_harii status = yes }
			hidden_tooltip = {
				d_harii = { religion = ROOT }
				narrative_event = { id = Plus.560 }
				create_character = {
					random_traits = yes
					religion = ROOT
					culture = ROOT
					dynasty = NONE
					female = no
					age = 34
					trait = skilled_tactician
					trait = zealous
				}
				new_character = {
					d_harii = {
						grant_title = PREV
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { prestige = 500 }
				NOT = { wealth = 500 }
			}
		}
	}

	# Hungary/Magyars
	take_carpathia = {
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 6
		potential = {
			OR = {
				has_landed_title = k_magyar
				is_nomadic = yes
			}
			culture = hungarian
			is_pagan_religion = yes
			is_reformed_pagan_religion = no
			independent = yes
			any_independent_ruler = {
				any_realm_province = {
					any_neighbor_province = {
						owner = { same_realm = ROOT }
					}
				}
				any_realm_title = { de_jure_liege = k_carpathia }
				any_realm_title = { title = c_pest }
				NOR = {
					is_nomadic = yes
					religion = ROOT
					reverse_has_truce = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					pays_tribute_to = ROOT
					ROOT = { pays_tribute_to = PREV }
				}
			}
			NOR = {
				is_inaccessible_trigger = yes
				any_realm_province = { region = custom_carpathia }
				has_global_flag = magyar_1066_invasion
				has_global_flag = hungary_formed
				has_global_flag = magyar_defeat
			}
		}
		allow = {
			war = no
			has_regent = no
			prestige = 200
			realm_size = 6
			NOT = { realm_size = 20 }
		}
		effect = {
			set_global_flag = magyar_1066_invasion
			prestige = -200
			capital_scope = {
				ROOT = {
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						leader = THIS
						troops = {
							light_infantry = { 1626 1626 }
							heavy_infantry = { 75 75 }
							archers = { 325 325 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = king_magyar_forces
					}
					spawn_unit = {
						province = PREV
						home = PREV
						owner = THIS
						leader = THIS
						troops = {
							light_infantry = { 1626 1626 }
							heavy_infantry = { 75 75 }
							archers = { 325 325 }
						}
						attrition = 0.25
						maintenance_multiplier = 0
						earmark = king_magyar_forces
					}
					if = {
						limit = { ai = yes }
						spawn_unit = {
							province = PREV
							home = PREV
							owner = THIS
							leader = THIS
							troops = {
								light_infantry = { 1626 1626 }
								heavy_infantry = { 75 75 }
								archers = { 325 325 }
							}
							attrition = 0.25
							maintenance_multiplier = 0
							earmark = magyar_forces
						}
						spawn_unit = {
							province = PREV
							home = PREV
							owner = THIS
							leader = THIS
							troops = {
								light_infantry = { 1626 1626 }
								heavy_infantry = { 75 75 }
								archers = { 325 325 }
							}
							attrition = 0.25
							maintenance_multiplier = 0
							earmark = king_magyar_forces
						}
					}
					create_character = {
						random_traits = yes
						dynasty = random
						religion = THIS
						culture = THIS
						female = no
						age = 23
						attributes = {
							martial = 6
						}
						trait = skilled_tactician
					}
					new_character = {
						spawn_unit = {
							province = PREVPREV
							home = PREVPREV
							owner = PREV
							leader = THIS
							troops = {
								light_infantry = { 1626 1626 }
								heavy_infantry = { 75 75 }
								archers = { 325 325 }
							}
							attrition = 0.25
							maintenance_multiplier = 0
							earmark = magyar_forces
						}
					}
					create_character = {
						random_traits = yes
						dynasty = random
						religion = THIS
						culture = THIS
						female = no
						age = 27
						attributes = {
							martial = 6
						}
						trait = skilled_tactician
					}
					new_character = {
						spawn_unit = {
							province = PREVPREV
							home = PREVPREV
							owner = PREV
							leader = THIS
							troops = {
								light_infantry = { 1626 1626 }
								heavy_infantry = { 75 75 }
								archers = { 325 325 }
							}
							attrition = 0.25
							maintenance_multiplier = 0
							earmark = magyar_forces
						}
					}
				}
			}
			522 = {
				kingdom = {
					ROOT = {
						war = {
							casus_belli = magyar_invasion
							target = PREVPREV
							thirdparty_title = PREV
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				NOT = { year = 865 }
			} 
			modifier = {
				factor = 0
				NOR = {
					trait = ambitious
					prestige = 1000
					martial = 15
				}
			}
			modifier = {
				factor = 0
				NOT = { prestige = 600 }
			}
		}
	}

	# Altaic Tribals
	become_nomad = {
		only_rulers = yes
		ai_check_interval = 12
		potential = {
			OR = {
				culture_group = altaic
				culture_group = magyar
				AND = {
					independent = yes
					any_demesne_province = {
						any_neighbor_province = {
							owner = {
								is_nomadic = yes
							}
						}
					}
					ai = no
				}
			}
			is_tribal = yes
			pacifist = no
			is_female = no
			capital_scope = { num_of_empty_holdings = 1 }
			OR = {
				num_of_count_titles = 3
				liege = { is_nomadic = yes }
			}
			OR = {
				tier = DUKE
				tier = KING
			}
			NOT = { has_landed_title = k_hungary }
		}
		allow = {
			war = no
			is_ill = no
			has_regent = no
			prestige = 1000
			martial = 12
			calc_true_if = {
				amount = 2
				martial = 15
				martial = 20
				trait = brave
				trait = strong
				trait = robust
			}
		}
		effect = {
			set_government_type = nomadic_government
			population = 500
			if = {
				limit = { prestige = 1500 }
				population = 500
			}
			if = {
				limit = { prestige = 2000 }
				population = 500
			}
			if = {
				limit = { prestige = 2500 }
				population = 500
			}
			if = {
				limit = { prestige = 3000 }
				population = 500
			}
			if = {
				limit = { independent = yes }
			}
			narrative_event = { id = Plus.564 }
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.5
				always = yes
			}
			modifier = {
				factor = 0
				has_character_flag = start_of_game_character
			}
			modifier = {
				factor = 0
				any_realm_title = {
					tier = COUNT
					is_feudal = yes
					count = 4
				}
			}
		}
	}
	
	# Valencian
	declare_valencian_kingdom = {
		is_high_prio = yes
		only_playable = yes
		only_independent = yes
		ai_check_interval = 12
		potential = {
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			culture = catalan
			lower_tier_than = king
			k_valencia = { has_holder = no }
			religion_group = christian
			holy_order = no
			primary_title = { is_primary_type_title = no }
		}

		allow = {
			is_adult = yes
			war = no
			has_regent = no
			wealth = 500
			prestige = 1000
			custom_tooltip = {
				text = HAS_TWO_DUKE_TITLES
				hidden_tooltip = {
					any_demesne_title = {
						tier = DUKE
						is_titular = no
						count = 2
					}
				}
			}
			capital_scope = { TECH_MAJESTY = 1 }
			completely_controls = d_valencia
		}

		effect = {
			activate_title = { title = k_valencia status = yes }
			d_valencia = {
				de_jure_liege = k_valencia
			}
			k_valencia = { gain_title = ROOT }
			wealth = -500
			prestige = -1000
		}

		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
			modifier = {
				factor = 0
				NOT = { wealth = 600 }
			}
			modifier = {
				factor = 0
				NOT = { culture = catalan }
			}
		}
	}
	
	# Revive Alexander's Macedonia
	create_macedon_kingdom = {
		is_high_prio = yes
		only_playable = yes
		only_independent = yes
		ai_check_interval = 12
		potential = {
			OR = {
				independent = yes
				liege = {
					real_tier = EMPEROR
					NOT = { has_law = kingdom_lockout_0 }
				}
			}
			OR = {
				culture = arberian
				culture = bulgarian
				culture = greek
			}
			lower_tier_than = king
			k_macedon = { has_holder = no }
			OR = {
				religion_group = christian
				is_pagan_religion = yes
			}
			holy_order = no
			primary_title = { is_primary_type_title = no }
		}

		allow = {
			is_adult = yes
			war = no
			has_regent = no
			wealth = 500
			prestige = 1000
			ROOT = {
				has_landed_title = c_chalkidike
				has_landed_title = c_ochrid
				has_landed_title = c_strymon
				has_landed_title = c_thessalonike
			}
			custom_tooltip = {
				text = HAS_TWO_DUKE_TITLES
				hidden_tooltip = {
					any_demesne_title = {
						tier = DUKE
						is_titular = no
						count = 2
					}
				}
			}
			capital_scope = { TECH_MAJESTY = 1 }
		}

		effect = {
			activate_title = { title = k_macedon status = yes }
			k_macedon = { gain_title = ROOT }
			if = {
				limit = { has_nickname = no }
				wealth = -500
				prestige = -1000
				give_nickname = nick_the_diadochos
			}
		}

		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0
				has_character_modifier = ai_austerity
			}
			modifier = {
				factor = 0
				NOT = { wealth = 600 }
			}
			modifier = {
				factor = 0
				NOR = {
					culture = arberian
					culture = bulgarian
					culture = greek
				}
			}
		}
	}
}

