﻿### Form the Latin Empire ###
secure_byzantium_foothold_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp2_decision_struggle_hostility.dds"
	}
	desc = secure_byzantium_foothold_decision_desc
	selection_tooltip = secure_byzantium_foothold_decision_tooltip
	decision_group_type = major

	sort_order = 499

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 100
		hegemony = 100
	}

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		#Must be in the right area.
		capital_province = { geographical_region = world_middle_east }
		# 至少是国王
		highest_held_title_tier >= tier_kingdom
		# 是拉丁人
		culture = {
			OR = {
				# has_coa_gfx = english_coa_gfx
				# has_coa_gfx = frankish_group_coa_gfx
				# has_coa_gfx = latin_group_coa_gfx
				# has_coa_gfx = iberian_group_coa_gfx
				has_coa_gfx = western_coa_gfx
			}
		}
		# 拉丁帝国不存在
		NOR = {
			exists = title:e_latin_empire.holder
			title:e_latin_empire = {
				any_in_de_jure_hierarchy = {
					tier <= tier_kingdom
				}
			}
		}
		# 拜占庭有法理
		title:e_byzantium = {
			any_in_de_jure_hierarchy = {
				tier = tier_kingdom
				is_titular = no
			}
		}
		# 罗马尚未统一
		NOR = {
			exists = title:h_roman_empire.holder
			exists = title:h_eastern_roman_empire.holder
		}
		# 不是希腊人，不信东正教，也不是罗马皇帝
		NOR = {
			culture = culture:greek
			culture = culture:roman
			culture = {
				any_parent_culture_or_above = {
					this = culture:greek
				}
			}
			ep3_orthodox_faith_trigger = yes
			faith = faith:hellenic_pagan
			AND = {
				exists = title:e_byzantium.holder
				this = title:e_byzantium.holder
			}
			AND = {
				exists = title:h_roman_empire.holder
				this = title:h_roman_empire.holder
			}
			AND = {
				exists = title:h_eastern_roman_empire.holder
				this = title:h_eastern_roman_empire.holder
			}
		}
		#Can only do it once.
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_secure_byzantium_foothold_decision
			}
		}
	}

	is_valid = {
		is_independent_ruler = yes
		prestige_level >= 4
		# 首都在中东
		custom_tooltip = {
			text = secure_byzantium_foothold_kingdom_capital_tt
			capital_province = { geographical_region = world_middle_east }
		}
		# 是海外皇帝/十字军国王
		OR = {
			has_title = title:e_outremer
			any_held_title = {
				count >= 3
				tier = tier_kingdom
			}
		}
		# 和教宗的关系
		trigger_if = {
			limit = {
				exists = faith.religious_head
				root != root.faith.religious_head
			}
			faith.religious_head = {
				opinion = {
					target = root
					value >= {
						value = high_positive_opinion
					}
				}
			}
		}
		# 立足点要求
		custom_tooltip = {
			text = secure_byzantium_foothold_kingdom_byzantium_tt
			any_held_title = {
				tier = tier_kingdom
				de_jure_liege = title:e_byzantium
				root = { completely_controls = prev }
				save_temporary_scope_as = byzantium_kingdom_temp
			}
		}
		trigger_if = {
			limit = { exists = scope:byzantium_kingdom_temp }
			custom_tooltip = {
				text = secure_byzantium_foothold_kingdom_border_tt
				scope:byzantium_kingdom_temp = {
					any_de_jure_county = {
						OR = {
							any_title_to_title_neighboring_and_across_water_county = {
								NOT = { empire = title:e_byzantium }
								kingdom.holder = root
							}
							any_title_to_title_neighboring_and_across_water_county = {
								empire = title:e_outremer
								empire.holder = root
							}
						}
					} 
				}
			}
			# custom_tooltip = {
			# 	text = secure_byzantium_foothold_kingdom_held_tt
			# 	scope:byzantium_kingdom_temp = { title_held_years >= fp2_struggle_secure_iberian_foothold_years_value } # 15 years
			# }
		}
		trigger_else = {
			custom_tooltip = {
				text = secure_byzantium_foothold_kingdom_border_tt
				always = no
			}
			# custom_tooltip = {
			# 	text = secure_byzantium_foothold_kingdom_held_tt
			# 	always = no
			# }
		}
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_capable_adult = yes
		is_imprisoned = no
		top_liege = this
		is_at_war = no
	}

	effect = {
		show_as_tooltip = {
			secure_byzantium_foothold_scripted_effect = yes
		}
		trigger_event = {
			id = eoh_decisions.0005
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_secure_byzantium_foothold_decision
			}
			set_global_variable = {
				name = flag_secure_byzantium_foothold_decision
				value = root
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

### Establish the Empire of Heaven ###
create_empire_of_heaven_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	decision_group_type = major

	desc = create_empire_of_heaven_decision_desc
	selection_tooltip = create_empire_of_heaven_decision_tt
	
	sort_order = 1000 # Should be at the very top

	is_shown = {
		# 仅限基督徒
		faith.religion = religion:christianity_religion
		# 与达尔伊斯兰冲突
		NOT = { has_global_variable = created_dar_al_islam }
		#Must be in the right area.
		capital_province = {
			OR = {
				geographical_region = world_middle_east
				geographical_region = world_africa_north
			}
		}
		#Must have the correct religion, and support from the rest of Catholicism.
		religion = { exists = var:variable_ghw_unlocked } #The era of the Crusades must have started.
		# 持有海外帝国
		has_title = title:e_outremer
	}
	is_valid = {
		# The basics
		is_independent_ruler = yes
		any_held_title = {
			count >= 2
			tier = tier_empire
		}
		# Must be very pious
		prestige_level >= 3
		piety_level >= 4
		# Controls Islamic core lands
		completely_controls_region = eoh_outremer_region
		
		# 持有海外帝国
		has_title = title:e_outremer
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
		is_at_war = no
	}

	effect = {
		show_as_tooltip = {
			create_empire_of_heaven_effect = yes
		}
		save_scope_as = scoped_ruler
		if = {
			limit = {
				faith = {
					has_doctrine = doctrine_temporal_head
					religious_head ?= root
				}
				faith.religion = religion:christianity_religion
			}
			faith = {
				religious_head = {
					set_variable = {
						name = old_hof_title_root
						value = faith.religious_head_title
					}
				}
			}
		}
		religion:islam_religion = {
			every_faith = {
				if = {
					limit = {
						exists = religious_head
					}
					religious_head = {
						add_to_list = eoh_former_islamic_hofs
					}
				}
			}
		}
		
		trigger_event = eoh_decisions.0001
	}

	cost = {
		piety = 1500
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 24
		hegemony = 0
	}

	ai_potential = {
		has_title = title:e_outremer
		faith.religion = religion:christianity_religion
	}

	ai_will_do = {
		base = 100
	}
}

### Establish the Eranshahr ###
create_eranshahr_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_foundation.dds"
	}
	decision_group_type = major

	desc = create_eranshahr_decision_desc
	selection_tooltip = create_eranshahr_decision_tt
	
	sort_order = 1000 # Should be at the very top

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		# Only for Mazdayasna
		faith.religion = religion:zoroastrianism_religion
		culture = { has_cultural_pillar = heritage_iranian }
		# And only if it hasn't been created yet
		NOT = { has_global_variable = created_dar_al_islam }
		# 至少是皇帝
		highest_held_title_tier >= tier_empire
	}
	is_valid = {
		# The basics
		is_independent_ruler = yes
		has_title = title:e_persia
		any_held_title = {
			count >= 2
			tier = tier_empire
		}
		# Must be very pious
		prestige_level >= 3
		piety_level >= 4
		# Controls 波斯帝国、阿拉伯、耶路撒冷、小亚细亚
		# completely_controls_region = world_middle_east_arabia
		# completely_controls_region = world_middle_east_jerusalem
		# completely_controls_region = world_persian_empire
		# completely_controls_region = world_asia_minor
		# 是 Saoshyant 或 重建穆护团
		OR = {
			has_trait = saoshyant
			has_trait = saoshyant_descendant
			custom_tooltip = {
				text = zoroastrian_high_priesthood_has_been_restored_desc
				faith = { NOT = { has_doctrine = special_doctrine_not_allowed_to_hof } }
			}
		}
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
		is_at_war = no
	}

	effect = {
		show_as_tooltip = {
			create_eranshahr_effect = yes
		}
		save_scope_as = scoped_ruler
		
		trigger_event = eoh_decisions.0011
	}

	cost = {
		piety = 1500
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 24
		hegemony = 0
	}

	ai_potential = {
		OR = {
			has_trait = saoshyant
			has_trait = saoshyant_descendant
		}
		faith.religion = religion:zoroastrianism_religion
	}

	ai_will_do = {
		base = 100
	}
}

### Latin Empire become REAL Roman Empire ###
frankokratia_victory_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_hold_triumph.dds"
	}
	desc = frankokratia_victory_decision_desc
	selection_tooltip = frankokratia_victory_decision_tooltip
	decision_group_type = roman

	sort_order = 499

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 100
		hegemony = 100
	}

	is_shown = {
		is_ruler = yes
		is_playable_character = yes

		# 是拉丁帝国皇帝
		has_title = title:e_latin_empire
		# 拉丁帝国有法理
		title:e_latin_empire = {
			any_in_de_jure_hierarchy = {
				tier = tier_kingdom
				is_titular = no
			}
		}
		# 罗马尚未统一
		NOR = {
			exists = title:h_roman_empire.holder
			exists = title:h_eastern_roman_empire.holder
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_restored_roman_empire
			}
		}
		# 不是希腊人，不信东正教，也不是罗马皇帝
		NOR = {
			culture = culture:greek
			culture = culture:roman
			culture = {
				any_parent_culture_or_above = {
					this = culture:greek
				}
			}
			ep3_orthodox_faith_trigger = yes
			faith = faith:hellenic_pagan
			AND = {
				exists = title:e_byzantium.holder
				this = title:e_byzantium.holder
			}
			AND = {
				exists = title:h_roman_empire.holder
				this = title:h_roman_empire.holder
			}
			AND = {
				exists = title:h_eastern_roman_empire.holder
				this = title:h_eastern_roman_empire.holder
			}
		}
		#Can only do it once.
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_frankokratia_victory_decision
			}
		}
	}

	is_valid = {
		is_independent_ruler = yes
		prestige_level >= 4
		OR = {
			# 拜占庭帝国所有实地王国都没了
			custom_tooltip = {
				text = frankokratia_victory_ere_lost_all_kingdoms_tooltip
				title:e_byzantium = { is_titular = yes }
				# title:e_byzantium = {
				# 	NOT = {
				# 		any_in_de_jure_hierarchy = {
				# 			tier = tier_kingdom
				# 			is_titular = no
				# 		}
				# 	}
				# }
			}
			# 完全控制拜占庭核心区域 且 拜皇不存在
			AND = {
				custom_tooltip = {
					text = frankokratia_victory_ere_holder_not_exists_tooltip
					NOT = { exists = title:e_byzantium.holder }
				}
				completely_controls_region = eoh_roman_balkan
				completely_controls_region = eoh_roman_anatolia
			}
		}
		
		# 控制君堡
		custom_tooltip = {
			text = frankokratia_victory_control_byzantion_tooltip
			OR = {
				has_title = title:c_byzantion
				any_sub_realm_title = {
					this = title:c_byzantion
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_capable_adult = yes
		is_imprisoned = no
		top_liege = this
		is_at_war = no
	}

	effect = {
		show_as_tooltip = {
			frankokratia_victory_scripted_effect = yes
		}
		custom_tooltip = latin_empire_become_roman_empire_tooltip
		trigger_event = {
			id = eoh_decisions.0008
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_frankokratia_victory_decision
			}
			set_global_variable = {
				name = flag_frankokratia_victory_decision
				value = root
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

### Restore the Roman Empire ###
restore_roman_empire_latin_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_roman_restoration.dds"
	}
	desc = restore_roman_empire_latin_decision_desc
	selection_tooltip = restore_roman_empire_decision_tooltip
	# Deliberately left in the major group rather than the Roman one.
	decision_group_type = roman

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 120
		hegemony = 0
	}

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		has_title = title:e_latin_empire
		OR = {
			NAND = {
				has_title = title:e_byzantium #Prioritize Byzaboos
				has_title = title:e_hre #And the Germans
				has_title = title:e_italy #And the Italians
			}
			primary_title = title:e_latin_empire
		}
		NOT = {  #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_restored_roman_empire
			}
		}
		# culture = { has_cultural_pillar = heritage_latin }
		# 完成拉丁化
		has_global_variable = latin_empire_become_roman_empire
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_republic
			government_has_flag = government_is_clan
			government_has_flag = government_is_administrative
		}
	}

	is_valid = {
		prestige_level >= max_prestige_level
		
		completely_controls = title:d_latium
		completely_controls = title:d_venice
		completely_controls = title:d_romagna
		completely_controls = title:d_sicily
		completely_controls = title:d_genoa
		completely_controls = title:d_capua
		completely_controls = title:d_apulia
		completely_controls = title:d_thrace
		completely_controls = title:d_antioch
		completely_controls = title:d_palestine
		completely_controls = title:d_alexandria
		completely_controls = title:d_athens
		completely_controls = title:d_tunis
		completely_controls = title:d_croatia
		completely_controls = title:d_thessalonika
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		is_capable_adult = yes
		is_imprisoned = no
		top_liege = this

		OR = {
			religion = { is_in_family = rf_abrahamic }
			religion = religion:hellenism_religion
			culture = { has_cultural_pillar = heritage_latin }
			culture = { has_cultural_pillar = heritage_byzantine }
		}
	}

	effect = {
		custom_tooltip = restore_roman_empire_decision_effect_tooltip
		show_as_tooltip = {
			create_roman_empire_latin_scripted_effect = yes
		}
		trigger_event = {
			id = eoh_decisions.0021
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_restored_roman_empire
			}
			set_global_variable = {
				name = flag_restored_roman_empire
				value = root
			}
		}
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

### MENA文化改革
mena_cultural_reform_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_golden_age.dds"
	}
	desc = mena_cultural_reform_decision_desc
	selection_tooltip = mena_cultural_reform_decision_tooltip
	#decision_group_type = realm

	sort_order = 120

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 36
		hegemony = 36
	}

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		# Must be in the right area.
		capital_province = {
			OR = {
				geographical_region = world_middle_east
				geographical_region = world_africa_north
			}
		}
		# 至少是国王
		highest_held_title_tier >= tier_kingdom
		# 有对应传统
		culture = {
			OR = {
				has_cultural_tradition = tradition_mubarizuns
				has_cultural_tradition = tradition_philosopher_culture
				has_cultural_tradition = tradition_dryland_dwellers
				has_cultural_tradition = tradition_religious_patronage
				has_cultural_tradition = tradition_fervent_temple_builders
			}
		}
		# 是文化领袖
		culture.culture_head = {
			this = root
		}
	}
	is_valid = {
		is_independent_ruler = yes
		prestige_level >= 3
		# 控制智慧宫/有宫廷学者
		OR = {
			any_realm_province = { has_building_or_higher = house_of_wisdom_01 }
			employs_court_position = court_scholar_court_position
		}
	}
	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "CHOOSE_REFORMATION_TYPE"
		show_from_start = yes

		item = { # 军事（穆巴里尊）
			value = mena_cr_martial
			is_valid = {
				culture = {
					has_cultural_tradition = tradition_mubarizuns
				}
				custom_tooltip = {
					text = mena_cultural_reform_decision_martial_tt
					OR = {
						AND = {
							faith.religion = religion:christianity_religion
							OR = {
								has_title = title:e_outremer
								has_title = title:h_dar_al_islam
								top_liege = { has_title = title:e_outremer }
								top_liege = { has_title = title:h_dar_al_islam }
							}
						}
						AND = {
							faith.religion = religion:islam_religion
							OR = {
								has_title = title:h_dar_al_islam
								top_liege = { has_title = title:h_dar_al_islam }
							}
						}
					}
				}
			}
			current_description = mena_cultural_reform_decision_martial_desc
			localization = mena_cultural_reform_decision_martial
			icon = "gfx/interface/icons/court_position_types/champion_court_position.dds"
			ai_chance = { value = 10 }
		}
		item = { # 信仰（宗教赞助/神殿建造者）
			value = mena_cr_faith
			is_valid = {
				custom_tooltip = {
					text = mena_cultural_reform_decision_holy_sites_tt
					faith = { holy_sites_controlled = 5 }
				}
				custom_tooltip = {
					text = mena_cultural_reform_decision_faith_tt
					OR = {
						culture = { has_cultural_tradition = tradition_religious_patronage }
						culture = { has_cultural_tradition = tradition_fervent_temple_builders }
					}
				}
			}
			current_description = mena_cultural_reform_decision_faith_desc
			localization = mena_cultural_reform_decision_faith
			icon = "gfx/interface/icons/court_position_types/camp_priest_camp_officer.dds"
			ai_chance = { value = 10 }
		}
		item = { # 学术（哲人文化）
			value = mena_cr_learning
			is_valid = {
				culture = {
					has_cultural_tradition = tradition_philosopher_culture
				}
			}
			current_description = mena_cultural_reform_decision_learning_desc
			localization = mena_cultural_reform_decision_learning
			icon = "gfx/interface/icons/court_position_types/court_scholar_court_position.dds"
			ai_chance = { value = 10 }
		}
		item = { # 灌溉（旱地居民）
			value = mena_cr_irrigation
			is_valid = {
				culture = {
					has_cultural_tradition = tradition_dryland_dwellers
				}
			}
			current_description = mena_cultural_reform_decision_irrigation_desc
			localization = mena_cultural_reform_decision_irrigation
			icon = "gfx/interface/icons/court_position_types/court_gardener_court_position.dds"
			ai_chance = { value = 10 }
		}
	}

	cost = {
		gold = 1000
	}

	effect = {
		if = {
			limit = {
				scope:mena_cr_martial = yes
			}
			if = {
				limit = { faith.religion = religion:islam_religion }
				culture = {
					remove_culture_tradition = tradition_mubarizuns
					add_culture_tradition = tradition_muslim_warrior
				}
			}
			else_if = {
				limit = { faith.religion = religion:christianity_religion }
				culture = {
					remove_culture_tradition = tradition_mubarizuns
					add_culture_tradition = tradition_crusader_warrior
				}
			}
		}
		else_if = {
			limit = {
				scope:mena_cr_learning = yes
			}
			culture = {
				remove_culture_tradition = tradition_philosopher_culture
				add_culture_tradition = tradition_fp3_beacon_of_learning
			}
		}
		else_if = {
			limit = {
				scope:mena_cr_faith = yes
			}
			culture = {
				add_culture_tradition = tradition_holyland_guardian
				if = {
					limit = { has_cultural_tradition = tradition_religious_patronage }
					remove_culture_tradition = tradition_religious_patronage
				}
				if = {
					limit = { has_cultural_tradition = tradition_fervent_temple_builders }
					remove_culture_tradition = tradition_fervent_temple_builders
				}
			}
		}
		else_if = {
			limit = {
				scope:mena_cr_irrigation = yes
			}
			culture = {
				remove_culture_tradition = tradition_dryland_dwellers
				add_culture_tradition = tradition_fp3_irrigation_experts
			}
		}
		
	}
	
	cooldown = {
		years = 5
	}
}
