﻿### Avenge the Battle of Nahrawan ###
avenge_the_battle_of_nahrawan_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/fp3_decision_supremacy.dds"
	}
	decision_group_type = major
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 120
		empire = 120
		hegemony = 120
	}
	sort_order = 30

	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					faith = {
						OR = {
							has_doctrine = tenet_fp3_fedayeen
							has_doctrine = tenet_warmonger 
							has_doctrine_parameter = pluralism_fundamentalist_proselytization_bonus
						}
					}
				}
				desc = destroy_the_apostates_decision_name
			}
			desc = avenge_the_battle_of_nahrawan_decision_name
		}
	}

	desc = avenge_the_battle_of_nahrawan_decision_desc

	selection_tooltip = avenge_the_battle_of_nahrawan_decision_tooltip

	is_shown = {
		has_fp3_dlc_trigger = yes
		faith = { has_doctrine = muhammad_succession_muhakkima_doctrine	}
		capital_province ?= {
			OR = {
				geographical_region = world_persian_empire
				geographical_region = world_middle_east 
			}		
		}
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:avenge_the_battle_of_nahrawan_decision
			}
		}
	}

	is_valid = {
		completely_controls_region = world_mesopotamia
		custom_description = {
			text = "restore_high_priesthood_holy_sites"
			faith = {
				any_holy_site = {
					OR = {
						county.holder = root
						county.holder.top_liege = { this = root }
					}
					count >= 3
				}
			}
		}
		custom_description = {
			text = avenge_the_battle_of_nahrawan_sunni_caliphate_irrelevant
			NOT = { exists = title:d_sunni.holder }
		}
		custom_description = {
			text = avenge_the_battle_of_nahrawan_shia_caliphate_irrelevant
			NOT = { exists = title:d_shiite.holder }
		}
	}	

	is_valid_showing_failures_only = {
		is_alive = yes
		not = { exists = involved_activity }
		is_imprisoned = no
	}


	effect = {
		save_scope_as = avenger
		
		#Sunni penalty scope save
		title:e_arabia = {
			random_de_jure_county_holder = { #If there's a big Sunni presence in Arabia
				limit = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine } 
					highest_held_title_tier = tier_empire
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
					highest_held_title_tier = tier_kingdom
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
					highest_held_title_tier = tier_duchy
				}
				faith = {
					save_scope_as = sunni_faith
				}
			}
		}

		title:e_persia = {
			random_de_jure_county_holder = { #If there's a big Sunni presence in Persia
				limit = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine } 
					highest_held_title_tier = tier_empire
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
					highest_held_title_tier = tier_kingdom
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_sunni_doctrine }
					highest_held_title_tier = tier_duchy
				}
				faith = {
					save_scope_as = sunni_faith
				}
			}
		}

		#Shia penalty scope save
		title:e_arabia = {
			random_de_jure_county_holder = { #If there's a big Shia presence in Arabia
				limit = {
					faith = { has_doctrine = muhammad_succession_shia_doctrine } 
					highest_held_title_tier = tier_empire
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_shia_doctrine }
					highest_held_title_tier = tier_kingdom
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_shia_doctrine }
					highest_held_title_tier = tier_duchy
				}
				faith = {
					save_scope_as = shia_faith
				}
			}
		}

		#Shia penalty scope save
		title:e_persia = {
			random_de_jure_county_holder = { #If there's a big Shia presence in Persia
				limit = {
					faith = { has_doctrine = muhammad_succession_shia_doctrine } 
					highest_held_title_tier = tier_empire
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_shia_doctrine }
					highest_held_title_tier = tier_kingdom
				}
				alternative_limit = {
					faith = { has_doctrine = muhammad_succession_shia_doctrine }
					highest_held_title_tier = tier_duchy
				}
				faith = {
					save_scope_as = shia_faith
				}
			}
		}

		show_as_tooltip = { avenge_the_battle_of_nahrawan_scripted_effect = yes } #Actually applied in fp3_decision.0011 - Prestige, religion bonuses

		#Events
		trigger_event = fp3_decision.0011
		every_player = {
			limit = {
				this != scope:avenger
				is_within_diplo_range = { CHARACTER = scope:avenger }
			}
			trigger_event = fp3_decision.0012
		}

		#Can only be done once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:avenge_the_battle_of_nahrawan_decision
		}
	}

	ai_will_do = {
		base = 100
	}
}


### Promote Persian Scriptures ###
fp3_promote_persian_scripture_decision = {
	title = fp3_promote_persian_scripture_decision_name
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp3/friendly.dds"
	}
	desc = fp3_promote_persian_scripture_decision_desc
	decision_group_type = major
	selection_tooltip = fp3_promote_persian_scripture_decision_tooltip 
	sort_order = -10
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	is_shown = {
		has_religion = religion:islam_religion
		has_fp3_dlc_trigger = yes
		is_landed = yes # Don't bother laamps with this
		NOT = {
			culture = { has_cultural_pillar = heritage_arabic }		
		}
		capital_province ?= { geographical_region = world_persian_empire }
		
		NOT = {
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:promote_persian_scripture_decision
			}
		}
	}

	is_valid = {
		top_liege = this
		highest_held_title_tier >= tier_kingdom
		piety_level >= high_piety_level 
		OR = {
			knows_language_of_culture = culture:persian
			knows_language_of_culture = culture:khwarezmian
		}
		culture = {
			cultural_acceptance = { target = culture:persian value >= 70 }
		}
		trigger_if = {
			limit = { 
				AND = {
					exists = faith.religious_head 
					root.faith.religious_head.culture = { has_cultural_pillar = heritage_arabic }
				}
			}
			NOT = { 
				root.faith.religious_head = { has_strong_hook = root }		
			}		
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		not = { exists = involved_activity }
		has_contagious_deadly_disease_trigger = no
		custom_description = {
			text = "pledged_to_not_promote_persian_desc"
			NOT = { has_variable = pledged_to_not_promote_persian }
		}
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					has_treasury = no
				}
				add = 500
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
				}
				add = 500
			}
		}
		piety = promote_persian_scripture_piety_cost
	}

	effect = {

		save_scope_as = persian_fanboy

		#Can only be done once
		add_to_global_variable_list = {
			name = unavailable_unique_decisions
			target = flag:promote_persian_scripture_decision
		}

		# Save the piety value for refund purposes.
		set_variable = {
			name = promote_persian_scripture_piety_refund
			value = promote_persian_scripture_piety_cost
		}

		show_as_tooltip = { promote_persian_scripture_scripted_effect = yes } #Actually applied in fp3_decision.0013.   

		if = {
			limit = {
				exists = root.faith.religious_head 
				root.faith.religious_head = {
					is_ai = yes
					NOR = {
						has_trait = craven
						has_trait = shy
						has_relation_lover = root
						has_relation_soulmate = root
						is_vassal_of = root
					}
				}
			}
			trigger_event = fp3_decision.0013
		}
		else = { trigger_event = fp3_decision.0014 }
	}

	ai_will_do = { #not likely, unless the AI is pluralist or very ambitious 
		base = 0

		modifier = {
			add = 25
			has_trait = ambitious
		}
		modifier = {
			add = 25
			has_trait = diligent
		}
		modifier = {
			add = 25
			root.faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		modifier = {
			add = 30
			exists = root.faith.religious_head 
			this != root.faith.religious_head
			root.faith.religious_head = { num_sinful_traits >= 1 }		
		}
		modifier = { #AI doesn't do it if their Head of Faith is a player, since that'd require additional events
			add = -100
			exists = root.faith.religious_head 
			root.faith.religious_head = { is_ai = no }		
		}
	}
}
#
#### Declare Stance in the Iranian Intermezzo ###
#fp3_name_read_in_friday_prayer_decision = {
#	picture = {
#		reference = "gfx/interface/illustrations/decisions/fp3/antagonistic.dds"
#	}
#	selection_tooltip = fp3_name_read_in_friday_prayer_decision_tooltip 
#	decision_group_type = major 
#	sort_order = -20
#	decision_group_type = struggle
#	# We check this via the struggle itself.
#	ai_check_interval = 0
#
#	title = {
#		first_valid = {
#			# Supporter turns Detractor.
#			triggered_desc = {
#				trigger = { has_trait = fp3_struggle_supporter }
#				desc = fp3_name_read_in_friday_prayer_decision.supporter_turns_detractor.t
#			}
#			# Detractor turns Supporter.
#			triggered_desc = {
#				trigger = { has_trait = fp3_struggle_detractor }
#				desc = fp3_name_read_in_friday_prayer_decision.detractor.turns_supporter.t
#			}
#			# Neither trait.
#			desc = fp3_name_read_in_friday_prayer_decision.neutral.t
#		}
#	}
#
#	desc = {
#		first_valid = {
#			# Supporter turns Detractor.
#			triggered_desc = {
#				trigger = { has_trait = fp3_struggle_supporter }
#				desc = fp3_name_read_in_friday_prayer_decision.supporter_turns_detractor.desc
#			}
#			# Detractor turns Supporter.
#			triggered_desc = {
#				trigger = { has_trait = fp3_struggle_detractor }
#				desc = fp3_name_read_in_friday_prayer_decision.detractor.turns_supporter.desc
#			}
#			# Neither trait.
#			desc = fp3_name_read_in_friday_prayer_decision.neutral.desc
#		}
#	}
#
#	is_shown = {
#		has_fp3_dlc_trigger = yes
#		any_character_struggle = { this = struggle:persian_struggle }
#		has_religion = religion:islam_religion
#	}
#
#	is_valid = {
#		custom_tooltip = {
#			text = fp3_name_read_in_friday_prayer_decision.tt.orthodox_sunnis_only
#			faith.religious_head ?= title:d_sunni.holder
#		}
#		OR = {
#			fp3_name_read_in_friday_prayer_decision_liege_requirements_trigger = yes
#			trigger_if = {
#				# If you meet the requirements, there'll be no warning copy as it just doesn't apply to you.
#				limit = { fp3_name_read_in_friday_prayer_decision_liege_requirements_trigger = no }
#				custom_tooltip = {
#					text = fp3_name_read_in_friday_prayer_decision.tt.fallback_validity
#					always = yes
#				}
#			}
#		}
#		is_at_war = no
#		# Supporters can't switch away to detraction if they're allied to the caliph.
#		trigger_if = {
#			limit = {
#				has_trait = fp3_struggle_supporter
#				exists = title:d_sunni.holder
#			}
#			NOT = { is_allied_to = title:d_sunni.holder }
#		}
#	}
#
#	is_valid_showing_failures_only = {
#		is_available_adult = yes
#		custom_tooltip = {
#			text = fp3_name_read_in_friday_prayer_decision.tt.orthodox_sunnis_only
#			has_religion = religion:islam_religion
#			faith.religious_head ?= title:d_sunni.holder
#		}
#		custom_tooltip = {
#			text = fp3_name_read_in_friday_prayer_decision.tt.sunni_caliph_must_exist
#			exists = title:d_sunni.holder
#		}
#		custom_tooltip = {
#			text = fp3_name_read_in_friday_prayer_decision.tt.sunni_caliph_cannot_change_prayer_order
#			NOT = { has_title = title:d_sunni }
#		}
#		# If you've already got the modifier, then you can't flipflop unless the caliph changes.
#		trigger_if = {
#			limit = {
#				has_variable = last_explicit_friday_prayer_caliph
#				title:d_sunni.holder ?= var:last_explicit_friday_prayer_caliph
#				OR = {
#					has_character_modifier = fp3_name_read_in_friday_prayer_modifier
#					has_character_modifier = fp3_displayed_pious_submission_to_caliph_modifier
#				}
#			}
#			custom_tooltip = {
#				text = fp3_name_read_in_friday_prayer_decision.tt.require_new_caliph_or_modifier_lapse
#				always = no
#			}
#		}
#		# If you rejected the caliph's demands previously, then you can't flipflop unless the caliph changes.
#		custom_tooltip = {
#			text = fp3_name_read_in_friday_prayer_decision.tt.require_new_caliph_or_flag_lapse
#			OR = {
#				NOT = { has_variable = last_explicit_defied_caliph }
#				NOT = { title:d_sunni.holder ?= var:last_explicit_defied_caliph }
#			}
#		}
#		# If you killed the caliph at any point, you can't switch at all.
#		trigger_if = {
#			limit = {
#				has_trait = fp3_struggle_detractor
#				exists = title:d_sunni.holder
#				exists = title:d_sunni.holder.dynasty
#				NOT = { dynasty ?= title:d_sunni.holder.dynasty }
#			}
#			custom_tooltip = {
#				text = fp3_name_read_in_friday_prayer_decision.tt.caliph_murderers_cant_become_supporters
#				NOT = {
#					any_killed_character = {
#						save_temporary_scope_as = char_temp
#						title:d_sunni = {
#							any_past_holder = { this = scope:char_temp }
#						}
#					}
#				}
#			}
#		}
#	}
#
#	cost = {
#		piety = {
#			# Base value.
#			value = 250
#			# Not meeting the liege trigger reqs gives you an extra surcharge.
#			if = {
#				limit = { fp3_name_read_in_friday_prayer_decision_liege_requirements_trigger = no }
#				add = 350
#			}
#		}
#	}
#
#	effect = {
#		show_as_tooltip = { read_name_in_friday_prayer_scripted_effect = yes }
#		trigger_event = fp3_decision.0015
#	}
#		
#
#	# No AI checks here as we handle them taking the decision as part of general struggle stuff.
#}
#