
decisions = {
	stem_duchy_of_brandenburg = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 120

		potential = {
			capital_scope = {
				OR = {
					province = 312
					province = 1589
					province = 88
					province = 311
					province = 310
					province = 1988
					province = 365
					province = 366
					province = 307
					province = 306
					province = 308
					province = 304 
				}
			}
			top_liege = {
				has_landed_title = e_hre
			}
			lower_tier_than = KING
			k_brandenburg = {
				is_titular = yes
			}
			is_alternate_start = no
		}
		allow = {
			prestige = 3000
			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}
			tier = DUKE
			completely_controls = c_meissen
			completely_controls = c_gorlitz
			completely_controls = c_plauen
			completely_controls = c_lausitz
			completely_controls = c_anhalt
			completely_controls = c_havelberg
			completely_controls = c_brandenburg
			completely_controls = c_werle
			completely_controls = c_rostock
			completely_controls = c_rugen
			completely_controls = c_wolgast
			completely_controls = c_stettin
			completely_controls = c_neumark
		}
		effect = {
			hidden_tooltip = {
				primary_title = {
					k_brandenburg = {
						copy_title_laws = PREV
					}
				}
			}
			grant_title_no_opinion = k_brandenburg
			hidden_tooltip = {
				d_brandenburg = {
					de_jure_liege = k_brandenburg
				}
				d_lausitz = {
					de_jure_liege = k_brandenburg
				}
				d_meissen = {
					de_jure_liege = k_brandenburg
				}
				d_rugen = {
					de_jure_liege = k_brandenburg
				}
				d_pommerania = {
					de_jure_liege = k_brandenburg
				}
				e_hre = {
					owner = {
						ROOT = {
							set_defacto_liege = PREV
						}
					}
				}
				ROOT = {
					narrative_event = { id = HFP.40038 }
				}
				any_playable_ruler = {
					limit = {
						OR = {
							has_landed_title = e_hre
							top_liege = {
								has_landed_title = e_hre
							}
						}
					}
					narrative_event = { id = HFP.40038 }
				}
			}
		}
	}
	create_istria = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 120

		potential = {
			NOT = { has_global_flag = istria_destroyed }
			e_istria = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
			NOT = { has_global_flag = hre_reformed }
		}
		allow = {
			e_istria = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
		}
		effect = {
			primary_title = {
				e_istria = {
					copy_title_laws = PREV
					copy_title_history = e_hre
				}
			}
			grant_title_no_opinion = e_istria
		}
	}
	create_franconia = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 120

		potential = {
			NOT = { has_global_flag = franconia_destroyed }
			e_franconia = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
			NOT = { has_global_flag = hre_reformed }
		}
		allow = {
			e_franconia = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
		}
		effect = {
			primary_title = {
				e_franconia = {
					copy_title_laws = PREV
					copy_title_history = e_hre
				}
			}
			grant_title_no_opinion = e_franconia
		}
	}
	create_swabia = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 120

		potential = {
			NOT = { has_global_flag = swabia_destroyed }
			e_swabia = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
			NOT = { has_global_flag = hre_reformed }
		}
		allow = {
			e_swabia = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
		}
		effect = {
			primary_title = {
				e_swabia = {
					copy_title_laws = PREV
					copy_title_history = e_hre
				}
			}
			grant_title_no_opinion = e_swabia
		}
	}
	create_brandenburg = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 120

		potential = {
			NOT = { has_global_flag = brandenburg_destroyed }
			e_brandenburg = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
			NOT = { has_global_flag = hre_reformed }
		}
		allow = {
			e_brandenburg = {
				has_holder = no
			}
			e_hre = {
				has_holder = no
			}
		}
		effect = {
			primary_title = {
				e_brandenburg = {
					copy_title_laws = PREV
					copy_title_history = e_hre
				}
			}
			grant_title_no_opinion = e_brandenburg
		}
	}
	reform_the_hre_early = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			conditional_tooltip = {
				trigger = {
					is_alternate_start = no
				}
				NOT = { has_global_flag = hre_reformed }
			}
			NOT = { has_global_flag = rome_restored }
			independent = yes
			OR = {
				religion = catholic
				religion = fraticelli
			}
			NOT = { has_landed_title = e_byzantium }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
			e_hre = {
				has_holder = no
			}
			OR = {
				has_landed_title = e_istria
				has_landed_title = e_franconia
				has_landed_title = e_swabia
				has_landed_title = e_brandenburg
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			custom_tooltip = {
				text = onlyoneemperor_opb
				hidden_tooltip = {
					OR = {
						AND = {
							e_istria = { has_holder = no }
							e_franconia = { has_holder = no }
							e_swabia = { has_holder = no }
							has_landed_title = e_brandenburg
						}
						AND = {
							e_brandenburg = { has_holder = no }
							e_franconia = { has_holder = no }
							e_swabia = { has_holder = no }
							has_landed_title = e_istria
						}
						AND = {
							e_brandenburg = { has_holder = no }
							e_istria = { has_holder = no }
							e_swabia = { has_holder = no }
							has_landed_title = e_franconia
						}
						AND = {
							e_brandenburg = { has_holder = no }
							e_istria = { has_holder = no }
							e_franconia = { has_holder = no }
							has_landed_title = e_swabia
						}
					}
				}
			}
			conditional_tooltip = {
				trigger = {
					ai = no
				}
				AND = {
					religion_head = {
						opinion = { who = ROOT value = 25 }
					}
					scaled_wealth = 2
				}
			}
		}
		effect = {
			set_global_flag = hre_reformed
			activate_title = { title = e_hre status = yes }
			if = {
				limit = {
					ai = no
				}
				scaled_wealth = -2
			}
			give_nickname = nick_the_great
			#Create Electors, depending on capital location:
			princely_elective_apply_elector_setup_effect = yes
			primary_title = {
				show_scope_change = no
				e_hre = {
					show_scope_change = no
					grant_title = ROOT
					copy_title_laws = PREV
					add_law = succ_hre_elective
				}
			}
			any_demesne_title = {
				limit = { tier = KING }
				de_jure_liege = e_hre
			}
			any_demesne_title = {
				limit = {
					AND = {
						tier = EMPEROR
						NOT = {
							title = e_hre
						}
					}
				}
				destroy_landed_title = THIS
			}
			hidden_tooltip = {
				any_demesne_title = {
					if = {
						limit = { tier = EMPEROR }
						any_direct_de_jure_vassal_title = {
							de_jure_liege = e_hre
						}
					}
				}
			}
			create_bloodline = {
				type = hre_reformer
				inheritance = patrilinial
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}
	form_the_hre_early = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 24
		
		potential = {
			is_playable = yes
			conditional_tooltip = {
				trigger = {
					is_alternate_start = no
				}
				#NOR = { 
				#	has_global_flag = charlemagne_hre 
				#	is_title_active = e_hre 
				#}
			}
			NOT = { has_global_flag = rome_restored }
			independent = yes
			OR = {
				religion = catholic
				religion = fraticelli
			}
			NOT = { has_landed_title = e_byzantium }
			NOT = {
				has_alternate_start_parameter = { key = religion_names value = random }
			}
			e_hre = {
				has_holder = no
			}
		}
		allow = {
			is_adult = yes
			prisoner = no
			NOT = { trait = incapable }
			prestige = 1000
			realm_size = 270
			conditional_tooltip = {
				trigger = {
					is_alternate_start = no
				}
				custom_tooltip = {
					text = form_the_hre_early_tooltip_1
					hidden_tooltip = {
						OR = {
							has_landed_title = k_italy
							has_landed_title = e_italy
						}
					}
				}
				custom_tooltip = {
					text = form_the_hre_early_tooltip_2
					hidden_tooltip = {
						any_demesne_title = {
							OR = {
								title = e_france
								title = e_germany
								title = e_britannia
								title = e_spain
								AND = {
									tier = KING
									NOT = {	title = k_italy	}
									OR = {
										empire = { title = e_france }
										empire = { title = e_germany }
										empire = { title = e_britannia }
										empire = { title = e_spain }
									}
								}
							}
						}
					}
				}
			}
			conditional_tooltip = {
				trigger = {
					ai = no
				}
				AND = {
					religion_head = {
						opinion = { who = ROOT value = 25 }
					}
					scaled_wealth = 2
				}
			}
		}
		effect = {
			set_global_flag = charlemagne_hre
			activate_title = { title = e_hre status = yes }
			if = {
				limit = {
					ai = no
				}
				scaled_wealth = -2
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			#Create Electors, depending on capital location:
			princely_elective_apply_elector_setup_effect = yes
			primary_title = {
				show_scope_change = no
				e_hre = {
					show_scope_change = no
					grant_title = ROOT
					copy_title_laws = PREV
					add_law = succ_hre_elective
				}
			}
			any_demesne_title = {
				limit = { tier = KING }
				de_jure_liege = e_hre
			}
			hidden_tooltip = {
				any_demesne_title = {
					if = {
						limit = { tier = EMPEROR }
						any_direct_de_jure_vassal_title = {
							de_jure_liege = e_hre
						}
					}
				}
			}
			any_demesne_title = {
				limit = {
					tier = EMPEROR
					NOT = { title = e_hre }
				}
				destroy_landed_title = THIS
				hidden_tooltip = { activate_title = { title = THIS status = no } }
			}
			any_demesne_title = {
				limit = { tier = KING }
				destroy_landed_title = THIS
			}
			e_byzantium = {
				show_scope_change = no
				holder_scope = {
					show_scope_change = no
					opinion = {
						who = ROOT
						modifier = opinion_unhappy
						months = 1200
					}
					hidden_tooltip = {
						k_papal_state = {
							holder_scope = {
								reverse_opinion = {
									who = PREVPREV
									modifier = opinion_unhappy
									months = 1200
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					OR = {
						NOT = {	has_character_flag = is_charlemagne }
						has_character_flag = charlemagne_coronation
					}
				}
				add_artifact = crown_hre
				hidden_tooltip = { narrative_event = { id = CM.510 } }        # Spread the news
			}
			if = {
				limit = {
					has_character_flag = is_charlemagne
					NOT = { has_character_flag = charlemagne_coronation }
				}
				hidden_tooltip = { narrative_event = { id = CM.1500 } }        # Charlemagne coronation
			}
			if = {
				limit = { ai = no }
				set_character_flag = achievement_holy_and_roman
			}
			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE
				picture = GFX_evt_coronation
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
		}
	}
}