namespace = Plus

#reserved: Plus.1650 to Plus.1699

#######################################
# HOLY WAR EVENTS
# Written by Rylock
#######################################

# Ruler requests sanction to declare Holy War
letter_event = {
	id = Plus.1650
	desc = EVTDESC_Plus_1650
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	show_from_from = yes
	
	immediate = {
		if = {
			limit = { ai = no }
			set_character_flag = do_not_bug_me
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1650 # Agree
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.75
				event_target:sanction_requester = { has_character_modifier = holy_war_timer }
			}
			modifier = {
				factor = 1.5
				opinion = { who = event_target:sanction_requester value = 0 }
			}
			modifier = {
				factor = 0.5
				NOT = { opinion = { who = event_target:sanction_requester value = 0 } }
			}
			modifier = {
				factor = 1.5
				trait = zealous
			}
			modifier = {
				factor = 1.2
				trait = charitable
			}
			modifier = {
				factor = 1.2
				trait = just
			}
			modifier = {
				factor = 1.2
				trait = humble
			}
		}
		piety = 50
		event_target:sanction_requester = { letter_event = { id = Plus.1651 days = 10 random = 20 tooltip = AGREE_HOLY_SANCTION } }
		hidden_tooltip = {
			opinion = { who = event_target:sanction_requester modifier = asked_holy_sanction months = 60 }
		}
	}
	option = {
		name = EVTOPTB_Plus_1650 # Ask for incentive
		ai_chance = {
			factor = 75
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:sanction_requester value = 0 } }
			}
			modifier = {
				factor = 0.75
				opinion = { who = event_target:sanction_requester value = 0 }
			}
			modifier = {
				factor = 1.5
				event_target:sanction_requester = { has_character_modifier = holy_war_timer }
			}
			modifier = {
				factor = 1.2
				trait = greedy
			}
			modifier = {
				factor = 1.2
				trait = envious
			}
			modifier = {
				factor = 1.2
				trait = proud
			}
			modifier = {
				factor = 1.5
				trait = cynical
			}
		}
		event_target:sanction_requester = { letter_event = { id = Plus.1652 days = 10 random = 20 tooltip = ASK_MORE_HOLY_SANCTION } }
	}
	option = {
		name = EVTOPTC_Plus_1650 # Refuse
		ai_chance = {
			factor = 50
			modifier = {
				factor = 1.2
				NOT = { opinion = { who = event_target:sanction_requester value = -20 } }
			}
			modifier = {
				factor = 1.2
				NOT = { opinion = { who = event_target:sanction_requester value = -40 } }
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:sanction_requester value = -60 } }
			}
			modifier = {
				factor = 1.5
				NOT = { opinion = { who = event_target:sanction_requester value = -80 } }
			}
			modifier = {
				factor = 0.8
				opinion = { who = event_target:sanction_requester value = 20 }
			}
			modifier = {
				factor = 0.8
				opinion = { who = event_target:sanction_requester value = 40 }
			}
			modifier = {
				factor = 0.5
				opinion = { who = event_target:sanction_requester value = 60 }
			}
			modifier = {
				factor = 0.5
				opinion = { who = event_target:sanction_requester value = 80 }
			}
			modifier = {
				factor = 0.5
				event_target:sanction_target = {
					OR = {
						is_heresy_of = ROOT
						is_parent_religion = ROOT
					}
				}
			}
			modifier = {
				factor = 0
				religion_group = muslim
				event_target:sanction_target = {
					any_realm_province = {
						OR = {
							province_id = 719
							NOT = { distance = { where = 719 value = 300 } }
						}
					}
				}
			}
			modifier = {
				factor = 0
				religion_group = christian
				event_target:sanction_target = {
					any_realm_province = {
						OR = {
							province_id = 333
							NOT = { distance = { where = 333 value = 300 } }
						}
					}
				}
			}
			modifier = {
				factor = 0.5
				event_target:sanction_target = { any_realm_title = { is_holy_site = ROOT } }
			}
			modifier = {
				factor = 0.5
				OR = {
					vassal_of = event_target:sanction_requester
					dynasty = event_target:sanction_requester
				}
			}
			modifier = {
				factor = 1.1
				trait = slothful
			}
			modifier = {
				factor = 1.1
				trait = arbitrary
			}
			modifier = {
				factor = 1.1
				trait = kind
			}
		}
		prestige = 50
		event_target:sanction_requester = { letter_event = { id = Plus.1653 days = 10 random = 20 tooltip = REFUSE_HOLY_SANCTION } }
		hidden_tooltip = {
			opinion = { who = event_target:sanction_requester modifier = asked_holy_sanction months = 12 }
		}
	}
}

# Religion Head agrees to the request
letter_event = {
	id = Plus.1651
	desc = EVTDESC_Plus_1651
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	immediate = {
		log = "[Root.GetTitledName] has been granted holy sanction to war against [sanction_target.GetTitledName]."
	}
	
	option = {
		name = EXCELLENT
		ROOT = { custom_tooltip = { text = WILL_RECEIVE_SANCTION } }
		hidden_tooltip = {
			opinion = { who = event_target:sanction_target modifier = holy_war_sanction years = 5 }
			opinion = { who = FROM modifier = opinion_pleased years = 5 }
			if = {
				limit = { ai = yes }
				character_event = { id = Plus.1660 days = 10 } #start the war
			}
		}
	}
}

# Religion Head needs some convincing
letter_event = {
	id = Plus.1652
	desc = EVTDESC_Plus_1652
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_Plus_1652 #Donation
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0
				monthly_income = 4
				NOT = { scaled_wealth = 1.0 }
			}
			modifier = {
				factor = 0
				NOT = { monthly_income = 4 }
				NOT = { wealth = 100 }
			}
			modifier = {
				factor = 2.0
				monthly_income = 4
				scaled_wealth = 2.0
			}
			modifier = {
				factor = 2.0
				NOT = { monthly_income = 4 }
				wealth = 200
			}
		}
		trigger = {
			wealth = 0
			OR = {
				AND = {
					monthly_income = 4
					scaled_wealth = 0.5
				}
				AND = {
					NOT = { monthly_income = 4 }
					wealth = 50
				}
			}
		}
		log = "[Root.GetTitledName] has been granted conditional sanction to war against [sanction_target.GetTitledName]."
		if = {
			limit = { monthly_income = 4 }
			tooltip = { transfer_scaled_wealth = { to = FROM value = 0.5 } }
		}
		if = {
			limit = { NOT = { monthly_income = 4 } }
			tooltip = { wealth = -50 }
		}
		ROOT = { custom_tooltip = { text = WILL_RECEIVE_SANCTION } }
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.1654 } }
			opinion = { who = event_target:sanction_target modifier = holy_war_sanction years = 5 }
			if = {
				limit = { ai = yes }
				character_event = { id = Plus.1660 days = 10 } #start the war
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1652 #Praise
		ai_chance = {
			factor = 50
		}
		trigger = {
			prestige = 250
			primary_title = {
				NOT = { has_law = investiture_law_1 }
			}
		}
		log = "[Root.GetTitledName] has been granted conditional sanction to war against [sanction_target.GetTitledName]."
		prestige = -250
		ROOT = { custom_tooltip = { text = WILL_RECEIVE_SANCTION } }
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.1655 } }
			opinion = { who = event_target:sanction_target modifier = holy_war_sanction years = 5 }
			if = {
				limit = { ai = yes }
				character_event = { id = Plus.1660 days = 10 } #start the war
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1652 #Praise
		ai_chance = {
			factor = 25
		}
		trigger = {
			prestige = 250
			primary_title = { has_law = investiture_law_1 }
		}
		log = "[Root.GetTitledName] has been granted conditional sanction to war against [sanction_target.GetTitledName]."
		primary_title = {
			revoke_law = investiture_law_1
			add_law_w_cooldown = investiture_law_0
		}
		ROOT = { custom_tooltip = { text = WILL_RECEIVE_SANCTION } }
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.1655 } }
			opinion = { who = event_target:sanction_target modifier = holy_war_sanction years = 5 }
			if = {
				limit = { ai = yes }
				character_event = { id = Plus.1660 days = 10 } #start the war
			}
		}
	}
	option = {
		name = EVTOPTC_Plus_1652 #The service of a family member
		ai_chance = {
			factor = 50
		}
		trigger = {
			any_courtier = {
				OR = {
					diplomacy = 10
					martial = 10
					stewardship = 10
					intrigue = 10
					learning = 10
				}
				is_ruler = no
				prisoner = no
				is_adult = yes
				is_female = no
				is_married = no
				dynasty = ROOT
				religion = ROOT
				NOT = { trait = incapable }
			}
		}
		log = "[Root.GetTitledName] has been granted conditional sanction to war against [sanction_target.GetTitledName]."
		random_courtier = {
			limit = {
				OR = {
					diplomacy = 10
					martial = 10
					stewardship = 10
					intrigue = 10
					learning = 10
				}
				is_ruler = no
				prisoner = no
				is_adult = yes
				is_female = no
				is_married = no
				dynasty = ROOT
				religion = ROOT
				NOT = { trait = incapable }
			}
			tooltip = { move_character = FROM }
			save_event_target_as = sent_to_religion_head
		}
		ROOT = { custom_tooltip = { text = WILL_RECEIVE_SANCTION } }
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.1656 } }
			opinion = { who = event_target:sanction_target modifier = holy_war_sanction years = 5 }
			if = {
				limit = { ai = yes }
				character_event = { id = Plus.1660 days = 10 } #start the war
			}
		}
	}
	option = {
		name = EVTOPTD_Plus_1652 #Give a temple to serve the cause
		ai_chance = {
			factor = 25
		}
		trigger = {
			OR = {
				NOT = { prestige = 250 }
				NOT = { wealth = 0 }
				AND = {
					monthly_income = 4
					NOT = { scaled_wealth = 0.5 }
				}
				AND = {
					NOT = { monthly_income = 4 }
					NOT = { wealth = 50 }
				}
			}
			NOR = {
				has_character_modifier = expelled_d_knights_templar
				has_character_modifier = expelled_d_knights_hospitaler
				has_character_modifier = expelled_d_teutonic_order
				has_character_modifier = expelled_d_jomsvikings
				has_character_modifier = expelled_d_braedralag
				has_character_modifier = expelled_d_ansar
				has_character_modifier = expelled_d_hashshashin
				has_character_modifier = expelled_d_holy_sepulchre
				has_character_modifier = expelled_d_immortals
				has_character_modifier = expelled_d_zealots
				has_character_modifier = expelled_d_saint_anthony
				has_character_modifier = expelled_d_sky_lords
				has_character_modifier = expelled_d_spirit_guardians
				has_character_modifier = expelled_d_chosen_perkunas
				has_character_modifier = expelled_d_sons_kaleva
				has_character_modifier = expelled_d_huitzilopochtli
				has_character_modifier = expelled_d_knights_santiago
				has_character_modifier = expelled_d_knights_calatrava
				has_character_modifier = expelled_d_saint_addai
				has_character_modifier = expelled_d_zun_warriors
				has_character_modifier = expelled_d_haruriyyah
				has_character_modifier = expelled_d_harii
			}
		}
		log = "[Root.GetTitledName] has been granted conditional sanction to war against [sanction_target.GetTitledName]."
		ROOT = { custom_tooltip = { text = SANCTION_PLEDGE_TEMPLE } }
		ROOT = { custom_tooltip = { text = WILL_RECEIVE_SANCTION } }
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.1657 } }
			set_character_flag = pledged_temple
			opinion = { who = event_target:sanction_target modifier = holy_war_sanction years = 5 }
			if = {
				limit = { ai = yes }
				character_event = { id = Plus.1660 days = 10 } #start the war
			}
		}
	}
	option = {
		name = EVTOPTE_Plus_1652 #Nothing
		ai_chance = {
			factor = 100
			modifier = {
				factor = 1.5
				piety = 100
			}
			modifier = {
				factor = 0.5
				trait = zealous
			}
			modifier = {
				factor = 0.75
				trait = charitable
			}
			modifier = {
				factor = 0.75
				trait = humble
			}
			modifier = {
				factor = 2
				trait = greedy
			}
			modifier = {
				factor = 1.5
				trait = ambitious
			}
			modifier = {
				factor = 1.5
				trait = proud
			}
		}
		log = "[Root.GetTitledName] asked for holy sanction against [sanction_target.GetTitledName], but refused the religion head's terms."
		hidden_tooltip = {
			FROM = { letter_event = { id = Plus.1658 } }
			opinion = { who = FROM modifier = opinion_outraged years = 5 }
		}
	}
}

# Religion Head refuses the request
letter_event = {
	id = Plus.1653
	desc = EVTDESC_Plus_1653
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes
	
	immediate = {
		log = "[Root.GetTitledName] has been denied holy sanction to war against [sanction_target.GetTitledName]."
	}
	
	option = {
		name = CURSES
		hidden_tooltip = {
			opinion = { who = FROM modifier = opinion_angry years = 5 }
		}
	}
}

# Religion Head notified of donation
letter_event = {
	id = Plus.1654
	desc = EVTDESC_Plus_1654
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes

	option = {
		name = EXCELLENT
		if = {
			limit = { FROM = { monthly_income = 4 } }
			FROM = { transfer_scaled_wealth = { to = ROOT value = 0.5 } }
		}
		if = {
			limit = { FROM = { NOT = { monthly_income = 4 } } }
			wealth = 50
		}
		hidden_tooltip = {
			opinion = { who = FROM modifier = asked_holy_sanction months = 60 }
		}
	}
}

# Religion Head notified of prestige
letter_event = {
	id = Plus.1655
	desc = EVTDESC_Plus_1655
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes

	option = {
		name = EXCELLENT
		prestige = -100
		hidden_tooltip = {
			opinion = { who = FROM modifier = asked_holy_sanction months = 60 }
		}
	}
}

# Religion Head notified of relative
letter_event = {
	id = Plus.1656
	desc = EVTDESC_Plus_1656
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes

	option = {
		name = EXCELLENT
		event_target:sent_to_religion_head = { move_character = ROOT }
		hidden_tooltip = {
			opinion = { who = FROM modifier = asked_holy_sanction months = 60 }
		}
	}
}

# Religion Head notified of promised temple
letter_event = {
	id = Plus.1657
	desc = EVTDESC_Plus_1657
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes

	option = {
		name = EXCELLENT
		hidden_tooltip = {
			opinion = { who = FROM modifier = asked_holy_sanction months = 60 }
		}
	}
}

# Religion Head notified of refusal
letter_event = {
	id = Plus.1658
	desc = EVTDESC_Plus_1658
	border = GFX_event_letter_frame_religion
	
	is_triggered_only = yes

	option = {
		name = OK
		hidden_tooltip = {
			opinion = { who = FROM modifier = asked_holy_sanction months = 12 }
		}
	}
}

# Ruler reminded of promise to offer a temple
character_event = {
	id = Plus.1659
	desc = EVTDESC_Plus_1659
	picture = GFX_evt_battle
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	hide_from = yes
	
	immediate = {
		random_vassal = {
			limit = {
				holy_order = yes
				religion = ROOT
			}
			save_event_target_as = target_holy_order
			break = yes
		}
		random_independent_ruler = {
			limit = {
				holy_order = yes
				religion = ROOT
			}
			save_event_target_as = target_holy_order
			break = yes
		}
		random_independent_ruler = {
			limit = {
				any_vassal = {
					holy_order = yes
					religion = ROOT
				}
			}
			random_vassal = {
				limit = {
					holy_order = yes
					religion = ROOT
				}
				save_event_target_as = target_holy_order
				break = yes
			}
		}
		rightful_religious_head_scope = {
			save_event_target_as = target_holy_order
		}
	}
	
	option = {
		name = EVTOPTA_Plus_1659 #Fulfil the promise
		ai_chance = {
			factor = 100
		}
		piety = 50
		hidden_tooltip = {
			if = {
				limit = {
					event_target:target_holy_order = { independent = no }
				}
				event_target:target_holy_order = {
					liege = { save_event_target_as = target_holy_order_liege }
				}
			}
		}
		event_target:granted_temple = {
			event_target:target_holy_order = {
				grant_title = PREV
				hidden_tooltip = {
					if = {
						limit = { event_target:target_holy_order_liege = { is_alive = yes } }
						set_defacto_liege = event_target:target_holy_order_liege
						pf_liege_change_effect = yes
					}
				}
			}
		}
	}
	option = {
		name = EVTOPTB_Plus_1659 #Refuse
		trigger = { NOT = { trait = zealous } }
		ai_chance = {
			factor = 0
		}
		piety = -100
		if = {
			limit = {
				can_excommunicate_trigger = yes
			}
			add_trait = excommunicated
		}
		if = {
			limit = {
				NOT = { can_excommunicate_trigger = yes }
			}
			rightful_religious_head_scope = { opinion = { who = ROOT modifier = opinion_outraged multiplier = 2 months = 120 } }
		}
		if = {
			limit = { NOT = { trait = cynical } }
			random = {
				chance = 50
				add_trait = cynical
			}
		}
		if = {
			limit = {
				NOR = {
					trait = honest
					trait = deceitful
				}
			}
			random = {
				chance = 50
				add_trait = deceitful
			}
		}
		if = {
			limit = { trait = honest }
			random = {
				chance = 50
				remove_trait = honest
			}
		}
	}
}

# AI uses the Holy War CB
character_event = {
	id = Plus.1660
	
	is_triggered_only = yes
	hide_window = yes
	
	only_independent = yes
	
	trigger = {
		has_any_opinion_modifier = holy_war_sanction
		war = no
		independent = yes
		has_called_crusade = no
		top_liege = { religion_group = ROOT }
		NOR = {
			has_character_modifier = holy_truce_timer
			has_character_modifier = holy_war_timer
			has_character_modifier = holding_epic_tournament
			has_character_modifier = holding_nomad_wargames
			trait = on_pilgrimage
			trait = on_hajj
			pacifist = yes
		}
	}
	
	immediate = {
		random_opinion_modifier_target = {
			limit = {
				reverse_has_opinion_modifier = { who = ROOT modifier = holy_war_sanction }
				reverse_realm_levy_diff = { who = ROOT value = 3000 }
				OR = {
					NOR = {
						religion = hindu
						religion = buddhist
					}
					ROOT = { NOT = { religion_group = indian_group } }
				}
				OR = {
					NOT = { religion_group = ROOT }
					is_heresy_of = ROOT
					is_parent_religion = ROOT
					AND = {
						OR = {
							religion_group = muslim
							religion_group = pagan_group
							religion = paulician
						}
						NOT = { religion = ROOT }
					}
				}
				NOR = {
					reverse_has_truce = ROOT
					has_non_aggression_pact_with = ROOT
					same_realm = ROOT
					has_character_modifier = holy_truce_timer
					has_character_modifier = crusade_block_timer
				}
			}
			save_event_target_as = holy_war_target
			random_realm_province = {
				limit = {
					any_neighbor_province = {
						has_province_flag = contingent_territory
						owner = {
							OR = {
								is_liege_or_above = ROOT
								character = ROOT
							}
						}
					}
				}
				duchy = {
					event_target:holy_war_target = {
						reverse_war = {
							target = ROOT
							casus_belli = holy_war
							thirdparty_title = PREV
						}
					}
				}
				break = yes
			}
			random_realm_province = {
				limit = {
					ROOT = { 
						any_realm_province = {
							has_province_flag = contingent_territory
							NOT = { distance = { where = PREVPREV value = 75 } }
							owner = {
								OR = {
									is_liege_or_above = ROOT
									character = ROOT
								}
							}
						}
					}
				}
				duchy = {
					event_target:holy_war_target = {
						reverse_war = {
							target = ROOT
							casus_belli = holy_war
							thirdparty_title = PREV
						}
					}
				}
			}
		}
	}
}

