﻿### Form the Outremer Empire ###
create_outremer_empire_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	desc = create_outremer_empire_decision_desc
	selection_tooltip = create_outremer_empire_decision_tooltip
	decision_group_type = major

	sort_order = 500 

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

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		#Visible to dukes and kings.
		highest_held_title_tier >= tier_duchy
		OR = { # 修改
			highest_held_title_tier <= tier_kingdom
			has_title = title:e_arabia
			has_title = title:e_latin_empire
		}
		#Must be in the right area.
		capital_province = {
			OR = {
				geographical_region = world_middle_east
				geographical_region = world_africa_north_east
			}
		}
		#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.
		faith = faith:catholic
		#Exempt Byzantine group: this is such a huge slap in the face to _anyone_ even vaguely in the Greek sphere.
		culture = {
			NOR = {
				has_cultural_pillar = heritage_byzantine
				has_cultural_pillar = heritage_caucasian
				has_cultural_pillar = heritage_syriac
			}
		}
		#Can only do it once.
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_created_outremer_empire
			}
		}
	}

	is_valid = {
		prestige_level >= 4
		highest_held_title_tier >= tier_kingdom
		has_title = title:k_jerusalem
		completely_controls_region = custom_outremer
	}

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

	effect = {
		custom_tooltip = create_outremer_empire_decision_effect_tooltip
		gain_heroic_legend_seed_tooltip_effect = yes
		show_as_tooltip = {
			form_outremer_main_scripted_effect = yes
		}
		trigger_event = {
			id = eoh_decisions.0015
		}
		# 添加传统说明
		custom_tooltip = form_outremer_tradition_addition_desc
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_created_outremer_empire
			}
			set_global_variable = {
				name = flag_created_outremer_empire
				value = root
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

### Create dar-al-islam
# create_dar_al_islam_decision = {
# 	picture = {
# 		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_foundation.dds"
# 	}
# 	decision_group_type = major

# 	desc = create_dar_al_islam_decision_desc
# 	selection_tooltip = create_dar_al_islam_decision_tt
	
# 	sort_order = 1000 # Should be at the very top

# 	is_shown = {
# 		# Only for Islamic head of faiths
# 		faith = { religious_head ?= root }
# 		faith.religion = religion:islam_religion
# 		# And only if it hasn't been created yet
# 		NOT = { has_global_variable = created_dar_al_islam }
# 	}
# 	is_valid = {
# 		# The basics
# 		is_independent_ruler = yes
# 		any_held_title = {
# 			count >= 2
# 			tier = tier_empire
# 		}
# 		faith = { has_doctrine = doctrine_temporal_head }
# 		# Must be very pious
# 		prestige_level >= 4
# 		piety_level >= 5
# 		Controls Islamic core lands
# 		completely_controls_region = world_middle_east_arabia
# 		completely_controls_region = world_middle_east_jerusalem
# 		completely_controls_region = world_persia
# 		completely_controls_region = world_africa_north
# 		# Also controls at minimum % of all islamic counties
# 		save_temporary_scope_as = root_scope
# 		custom_tooltip = {
# 			text = realm_controls_enough_islamic_counties_desc
# 			any_realm_county = {
# 				faith.religion = religion:islam_religion
# 				count >= islam_required_county_number_value
# 			}
# 		}
# 	}

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

# 	effect = {
# 		show_as_tooltip = {
# 			create_dar_al_islam_effect = yes
# 		}
# 		save_scope_as = dar_al_islam_ruler
# 		# Save all existing islamic head of faiths and their titles
# 		religion:islam_religion = {
# 			every_faith = {
# 				if = {
# 					limit = {
# 						exists = religious_head
# 						faith_hostility_level = {
# 							target = root.faith
# 							value < faith_hostile_level
# 						}
# 					}
# 					religious_head = {
# 						add_to_list = former_islamic_hofs
# 						set_variable = {
# 							name = old_hof_title
# 							value = faith.religious_head_title
# 						}
# 					}
# 				}
# 			}
# 		}
# 		# Trigger follow-up events
# 		trigger_event = middle_east_decisions.1100
# 		every_player = {
# 			limit = {
# 				this != root
# 				NOT = { is_in_list = former_islamic_hofs }
# 			}
# 			trigger_event = middle_east_decisions.1101
# 		}
# 		every_in_list = {
# 			list = former_islamic_hofs
# 			limit = { this != root }
# 			trigger_event = { id = middle_east_decisions.1102 days = 1 }
# 		}
# 	}

# 	cost = {
# 		piety = 1500
# 	}

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

# 	ai_potential = {
# 		faith = { religious_head ?= root }
# 		faith.religion = religion:islam_religion
# 	}

# 	ai_will_do = {
# 		base = 100
# 	}
# }

### Reclaim Constantinople ###
set_capital_constantinople_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	desc = set_capital_constantinople_decision_desc
	selection_tooltip = set_capital_constantinople_decision_tooltip
	decision_group_type = major

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

	is_shown = {
		is_ruler = yes
		is_playable_character = yes
		OR = {
			has_title = title:e_byzantium
			AND = {
				has_title = title:e_latin_empire
				has_global_variable = latin_empire_become_roman_empire
			}
		}
		NOT = { capital_county = { this = title:c_byzantion } }
		OR = {
			title:c_byzantion.holder = { 	
				any_liege_or_above = { this = root }
			}
			title:c_byzantion.holder = { this = root }
		}
	}

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

	effect = {
		if = { #Usurp if not held personally.
			limit = {
				NOT = { title:c_byzantion.holder = { this = root } }
			}
			title:c_byzantion.holder = { save_scope_as = target_for_denunciation }
			create_title_and_vassal_change = {
				type = returned
				save_scope_as = change
				add_claim_on_loss = no
			}
			title:c_byzantion = {
				change_title_holder = {
					holder = root
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change

		}
		set_realm_capital = title:c_byzantion
		if = {
			limit = {
				exists = scope:target_for_denunciation
			}
			scope:target_for_denunciation = {
				trigger_event = {
					id = roman_restoration.1204
				}
			}
		}
	}
	ai_potential = {
		primary_title.tier = tier_empire
		has_title = title:e_byzantium
	}

	ai_will_do = { #Do it always, for coherence.
		base = 100
		modifier = {
			title:c_byzantion.holder = {
				is_ai = no
				any_realm_county = {
					count < 2
					holder = title:c_byzantion.holder
				}
			}
			factor = 0
		}
	}
}

### Restore the Byzantine Empire ###
recreate_byzantine_empire_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_cerimonial_decision.dds"
	}
	decision_group_type = major

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

	desc = recreate_byzantine_empire_decision_desc
	selection_tooltip = recreate_byzantine_empire_decision_tooltip
	decision_group_type = roman

	is_shown = {
		has_dlc_feature = roads_to_power
		NOR = {
			exists = title:e_byzantium.holder
			exists = title:h_roman_empire.holder
			exists = title:h_eastern_roman_empire.holder
		}
		title:e_byzantium = { is_titular = no }
		### 不能被拉丁化
		NOT = { has_global_variable = latin_empire_become_roman_empire }
		OR = {
			culture = {
				OR = {
					this = culture:greek
					any_parent_culture_or_above = { this = culture:greek }
				}
			}
			AND = {
				OR = {
					ep3_orthodox_faith_trigger = yes
					faith = faith:hellenic_pagan
				}
				primary_title = {
					tier <= tier_empire
					empire = title:e_latin_empire
				}
			}
			AND = {
				OR = {
					ep3_orthodox_faith_trigger = yes
					faith = faith:hellenic_pagan
				}
				primary_title = {
					tier <= tier_empire
					empire = title:e_byzantium
				}
			}
		}
	}

	is_valid = {
		custom_tooltip = {
			NOT = {
				exists = title:e_byzantium.holder
			}
			text = no_byz_emp_exists_tt
		}
		top_liege = this
		OR = {
			custom_tooltip = {
				culture = {
					this = culture:greek
				}
				text = is_greek_tt
			}
			custom_tooltip = {
				culture = {
					any_parent_culture_or_above = { this = culture:greek }
				}
				text = is_greek_descendent_tt
			}
			ep3_orthodox_faith_trigger = yes
			faith = faith:hellenic_pagan
		}
		highest_held_title_tier >= tier_kingdom
		
		realm_size >= 12
		custom_tooltip = {
			title:c_byzantion.holder = {
				exists = this
				OR = {
					this = root
					AND = {
						is_ai = yes
						top_liege = root
					}
				}
			}
			text = pandidakterion_tt
		}
		primary_title = {
			tier <= tier_empire
			OR = {
				empire = title:e_latin_empire
				empire = title:e_byzantium
			}
		}
		trigger_if = {
			limit = {
				is_ai = no
				has_legitimacy = yes
			}
			legitimacy_level >= 3
		}
		#A liiiiiittle easier for AI
		trigger_if = {
			limit = {
				is_ai = yes
				has_legitimacy = yes
			}
			legitimacy_level >= 1
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = {
				is_ai = no
			}
			NOT = { exists = involved_activity }
			is_available = yes
		}
		trigger_else = {
			is_alive = yes
			is_imprisoned = no
			is_incapable = no
		}
	}

	cost = {
		prestige = {
			value = {
				add = 1000
				if = {
					limit = {
						any_held_title = {
							this = title:e_latin_empire
						}
					}
					add = 1000
				}
				if = {
					limit = {
						culture = {
							NOR = {
								this = culture:greek
								any_parent_culture_or_above = { this = culture:greek }
							}
						}
					}
					add = 500
				}
				#AI need to take this decision and aren't good at saving up for it
				if = {
					limit = {
						is_ai = yes
					}
					multiply = 0.5
				}
			}
		}
		piety = {
			value = {
				add = massive_piety_value
				if = {
					limit = {
						any_held_title = {
							this = title:e_latin_empire
						}
					}
					add = 500
				}
				if = {
					limit = {
						ep3_orthodox_faith_trigger = no
					}
					add = 500
				}
				if = {
					limit = {
						faith = faith:catholic
					}
					add = 500
				}
				#AI need to take this decision and aren't good at saving up for it
				if = {
					limit = {
						is_ai = yes
					}
					multiply = 0.5
				}
			}
		}
	}

	effect = {
		show_as_tooltip = {
			recreate_ere_decision_effect = yes
		}
		trigger_event = ep3_decisions_event.4030
	}

	ai_potential = {
		NOT = { exists = title:e_byzantium.holder }
		any_held_title = {
			title_tier = kingdom
			OR = {
				empire = title:e_latin_empire
				empire = title:e_byzantium
			}
		}
		OR = {
			culture = {
				OR = {
					this = culture:greek
					any_parent_culture_or_above = { this = culture:greek }
				}
			}
			ep3_orthodox_faith_trigger = yes
			primary_title = {
				tier <= tier_empire
				empire = title:e_latin_empire
			}
		}
	}

	ai_will_do = {
		base = 100
		modifier = {
			primary_title = {
				tier <= tier_empire
				empire = title:e_latin_empire
			}
			add = -60
		}
		modifier = {
			NAND = {
				culture = {
					OR = {
						this = culture:greek
						any_parent_culture_or_above = { this = culture:greek }
					}
				}
				OR = {
					ep3_orthodox_faith_trigger = yes
					faith = faith:hellenic_pagan
				}
			}
			add = -30
		}
	}
}

### Expunge Latin Dominion ###
expunge_latin_dominion_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/ep3_decision_hold_triumph.dds"
	}
	decision_group_type = major

	desc = expunge_latin_dominion_decision_desc
	selection_tooltip = expunge_latin_dominion_decision_tooltip
	decision_group_type = roman

	cooldown = { days = 60 }
	
	is_shown = {
		### 不能被拉丁化
		NOT = { has_global_variable = latin_empire_become_roman_empire }
		has_dlc_feature = roads_to_power
		#Latin land needs to exist
		title:e_latin_empire = {
			any_in_de_jure_hierarchy = {
				tier <= tier_kingdom
			}
		}
		#Must be a Greek or Greekoid
		OR = {
			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
			}
		}
		OR = {
			capital_province = {
				OR = {
					geographical_region = world_asia_minor
					geographical_region = world_europe_south
					geographical_region = world_middle_east
					geographical_region = world_europe_east
					geographical_region = world_steppe_west
				}
			}
			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
			}
		}
	}

	is_valid = {
		trigger_if = {
			limit = {
				top_liege != this
			}
			custom_tooltip = {
				text = liege_isnt_latin_emp_tt
				NOT = {
					top_liege = {
						primary_title = title:e_latin_empire
					}
				}
			}
		}
		trigger_else = {
			OR = {
				highest_held_title_tier <= tier_kingdom
				custom_tooltip = {
					exists = title:e_byzantium.holder
					this = title:e_byzantium.holder
					text = holds_byz_emp_tt
				}
				custom_tooltip = {
					exists = title:h_roman_empire.holder
					this = title:h_roman_empire.holder
					text = holds_roman_emp_tt
				}
				custom_tooltip = {
					exists = title:h_eastern_roman_empire.holder
					this = title:h_eastern_roman_empire.holder
					text = holds_roman_emp_tt
				}
			}
		}
		#Must be a Greek or Greekoid
		OR = {
			culture = culture:greek
			culture = culture:roman
			custom_tooltip = {
				culture = {
					any_parent_culture_or_above = { this = culture:greek }
				}
				text = is_greek_descendent_tt
			}
			ep3_orthodox_faith_trigger = yes
			faith = faith:hellenic_pagan
			custom_tooltip = {
				exists = title:e_byzantium.holder
				this = title:e_byzantium.holder
				text = holds_byz_emp_tt
			}
			custom_tooltip = {
				exists = title:h_roman_empire.holder
				this = title:h_roman_empire.holder
				text = holds_roman_emp_tt
			}
			custom_tooltip = {
				exists = title:h_eastern_roman_empire.holder
				this = title:h_eastern_roman_empire.holder
				text = holds_roman_emp_tt
			}
		}
		OR = {
			#Controls entire kingdom
			custom_tooltip = {
				text = control_latin_kingdom_tt
				title:e_latin_empire = {
					any_in_de_jure_hierarchy = {
						tier = tier_kingdom
						NOT = { this = title:e_latin_empire }
						any_de_jure_county = {
							percent >= 1
							holder.top_liege = {
								this = root
							}
						}
					}
				}
			}
			#Controls half and has de jure title
			custom_tooltip = {
				text = has_latin_kingdom_title_tt
				title:e_latin_empire = {
					any_in_de_jure_hierarchy = {
						tier = tier_kingdom
						NOT = { this = title:e_latin_empire }
						holder ?= {
							OR = {
								this = root
								top_liege = root
							}
						}
						OR = {
							any_de_jure_county = {
								this = root.capital_county
							}
							any_de_jure_county = {
								percent >= 0.5
								holder.top_liege = {
									this = root
								}
							}
						}
					}
				}
			}
		}
		trigger_if = {
			limit = {
				has_legitimacy = yes
				is_ai = no
			}
			legitimacy_level >= 2
		}
		#A liiiiiittle easier for AI
		trigger_if = {
			limit = {
				has_legitimacy = yes
				is_ai = yes
			}
			legitimacy_level >= 1
		}
	}

	is_valid_showing_failures_only = {
		trigger_if = {
			limit = {
				is_ai = no
			}
			NOT = { exists = involved_activity }
			is_available = yes
		}
		trigger_else = {
			is_alive = yes
			is_imprisoned = no
			is_incapable = no
		}
		is_at_war = no
	}

	cost = {
		prestige = {
			value = {
				add = major_prestige_value
				#AI should definitely take this
				if = {
					limit = {
						is_ai = yes
					}
					multiply = 0.5
				}
			}
		}
		piety = {
			value = {
				add = major_piety_value
				if = {
					limit = {
						is_ai = yes
					}
					multiply = 0.5
				}
			}
		}
	}

	effect = {
		custom_tooltip = remove_latin_kingdom_de_jure_tt
		custom_tooltip = legitimize_byz_control_tt
		custom_tooltip = legitimize_byz_claim_tt
		show_as_tooltip = {
			expunge_latin_dominion_effect = yes
		}
		trigger_event = ep3_frankokratia_events.0090
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 36
		kingdom = 9
		empire = 9
		hegemony = 9
	}
	
	ai_potential = {
		is_available = yes
		OR = {
			highest_held_title_tier >= tier_kingdom
			realm_size >= 10
		}
		#Must be a Greek or Greekoid
		OR = {
			culture = culture:greek
			culture = culture:roman
			culture = {
				any_parent_culture_or_above = {
					this = culture:greek
				}
			}
			ep3_orthodox_faith_trigger = yes
			faith = faith:hellenic_pagan
			primary_title = title:e_byzantium
		}
		OR = {
			#Controls entire kingdom
			title:e_latin_empire = {
				any_in_de_jure_hierarchy = {
					tier = tier_kingdom
					NOT = { this = title:e_latin_empire }
					any_de_jure_county = {
						percent >= 1
						holder.top_liege = {
							this = root
						}
					}
				}
			}
			#Controls half and has de jure title
			title:e_latin_empire = {
				any_in_de_jure_hierarchy = {
					tier = tier_kingdom
					NOT = { this = title:e_latin_empire }
					holder ?= {
						OR = {
							this = root
							top_liege = root
						}
					}
					OR = {
						any_de_jure_county = {
							this = root.capital_county
						}
						any_de_jure_county = {
							percent >= 0.5
							holder.top_liege = {
								this = root
							}
						}
					}
				}
			}
		}
	}

	ai_will_do = {
		base = 75
		modifier = {
			add = 25
			primary_title = title:e_byzantium
		}
		modifier = {
			add = -50
			any_held_title = {
				this = title:e_latin_empire
			}
		}
	}
}
