frtholic_crusade = {
	name = CB_NAME_CRUSADE
	war_name = WAR_NAME_CRUSADE
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	battle_warscore_mult = 0.5
	max_defender_occupation_score = 85
	check_de_jure_tier = KING # this scans all de jure kingdoms for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	is_crusade = yes
	
	allowed_to_target_tributaries = no
	
	sort_priority = 3000

	can_use_gui = {
		custom_tooltip = {
			text = z_France_SchismCatholic
			has_global_flag = France_SchismCatholic_flag
		}
		custom_tooltip = {
			text = tooltip_Fail_France_SchismCatholic
			NOT = { has_global_flag = Fail_France_SchismCatholic_flag }			
		}
		ROOT = {
			uses_new_crusade = no
			has_called_crusade = no
			religion_authority = 0.05
			religion_group = christian
			#custom_tooltip = {
				#text = CTT_CHRISTIAN_CRUSADES_UNLOCKED
				#has_global_flag = christian_crusades_unlocked
			#}			
			mercenary = no
		}
		FROM = {
			religion_group = christian
			NOT = { religion = ROOT }							
		}
		NOT = { is_vassal_or_below = FROM }
		NOT = { is_liege_or_above = FROM }
	}

	can_use = {
		has_global_flag = France_SchismCatholic_flag
		NOT = { has_global_flag = Fail_France_SchismCatholic_flag }
		ROOT = {
			uses_new_crusade = no			
			religion = frtholic
			can_call_crusade = yes				
			#NOT = { has_character_modifier = frtholic_crusade_modifier }	
			mercenary = no
		}
		FROM = {
			religion_group = christian
			NOT = { religion = frtholic }
			NOT = { is_heresy_of = ROOT }
			NOT = { is_parent_religion = ROOT }	
		}		
	}

	can_use_title = {
		FROM = {
			any_realm_title = {
				de_jure_liege_or_above = PREVPREV
			}
			
			independent = yes # Don't declare Crusades on revolters - chances are high the war will invalidate
			
			num_of_realm_counties = {
				value = 6
				title = PREV
			}
		}
	}
	
	is_valid = {
		ROOT = {
			#uses_new_crusade = no			
			religion = frtholic
			can_call_crusade = yes				
			#NOT = { has_character_modifier = frtholic_crusade_modifier }	
		}
		FROM = {
			NOT = { religion = frtholic }					
		}	
	}

	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_add = {			
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}			
	}

	on_success_title = {
	
		# Should we give the seized land to its current king?
		if = {
			limit = {
				has_holder = yes
				holder_scope = {
					religion = ROOT
				}
			}
			holder_scope = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
					type = holy_war
				}
			}
		}
		
		# Should we give the seized land to a claimant of our faith?
		if = {
			limit = {
				OR = {
					has_holder = no
					holder_scope = {
						NOT = { religion = ROOT }
					}
				}
				
				best_crusade_claimant = {
					always = yes # There is a "best" claimant
				}
			}
			
			# Claimants must be of ROOT's religion, and are ranked by strength of claim and actual contribution to the war
			best_crusade_claimant = {
				if = {
					limit = { is_ruler = no }
					set_character_flag = set_feudal_gov
				}
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					is_crusade = yes # Even if the title holder is not participating in the war, gain holdings occupied by all Crusade participants
					type = holy_war
				}
				if = {
					limit = {
						top_liege = {
							character = FROM
						}
					}
					set_defacto_liege = THIS
				}
				if  = {
					limit = {
						PREV = {
							OR = { 
								has_holder = no
								holder_scope = { 
									top_liege = { character = FROM }
								}
							} 
						}
						OR = {
							independent = yes
							is_ruler = no
							liege = {
								tier = EMPEROR
							}
						}
					}
					usurp_title = { target = PREV type = holy_war }
				}
				if = {
					limit = { has_character_flag = set_feudal_gov }
					set_government_type = feudal_government
				}
				clr_character_flag = set_feudal_gov
			}
		}
		
		# Give the seized land to the main contributor of the Crusade
		if = {
			limit = {
				OR = {
					has_holder = no
					NOT = {
						holder_scope = {
							religion = ROOT
						}
					}
				}
				NOT = {
					best_crusade_claimant = {
						always = yes
					}
				}
			}
			most_participating_crusader = {
				gain_settlements_under_title = {
					title = PREV
					enemy = FROM
					type = holy_war
				}
				if  = {
					limit = {
						primary_title = { is_primary_type_title = no } # Mercs, the Pope, Holy Orders, etc
						PREV = { 
							OR = {
								has_holder = no 
								holder_scope = {
									top_liege = { character = FROM }
								}
							}
						}
						NOT = { character = ROOT }
						OR = {
							independent = yes
							liege = {
								tier = EMPEROR
							}
						}
					}
					usurp_title_only = { target = PREV type = holy_war }
					
					if = {
						limit = {
							NOT = { culture = PREV }
						}
						hidden_tooltip = { 
							save_event_target_as = winning_crusader
							PREV = { conquest_culture = event_target:winning_crusader } 
						}
					}
				}
				hidden_tooltip = {
					if = {
						limit = {
							OR = {
								this_has_lame_nickname_trigger = yes
								has_nickname = no
							}
						}
						random_list = {
							10 = {
								modifier = {
									factor = 0
									NOT = { religion_group = christian }
								}
								give_nickname = nick_the_crusader
							}
							10 = { give_nickname = nick_the_holy }
							10 = { give_nickname = nick_the_glorious }
							10 = { give_nickname = nick_the_lionheart }
							10 = { give_nickname = nick_the_great }
							10 = { give_nickname = nick_the_hammer }
							10 = { give_nickname = nick_the_pilgrim }
							40 = {
								modifier = {
									factor = 0
									religion_group = christian
								}
								give_nickname = nick_the_sword_of_god
							}
						}
					}
				}
			}
		}
		
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 500
				participation_scaled_piety = 1000
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -100
				}
			}
		}
		any_attacker = {
			limit = {
				ai = no
				NOT = { has_character_flag = achievement_crusader }
			}
			set_character_flag = achievement_crusader
		}
		
		ROOT = {
			show_scope_change = no
			participation_scaled_prestige = 500
			participation_scaled_piety = 1000
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -100
			}
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
		}
		
		FROM = {
			piety = -100
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}			
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		ROOT = {
			show_scope_change = no
			piety = -100
		}
		
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -50
				}
			}
		}
		
		FROM = {
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -50
			}
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
						OR = { 
							religion_group = christian
							religion = hellenic_pagan
							religion = hellenic_pagan_reformed
						}
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			
			hidden_tooltip = {
				if = {
					limit = {
						OR = {
							this_has_lame_nickname_trigger = yes
							has_nickname = no
						}
					}
					hidden_effect = {
						random_list = {
							10 = { give_nickname = nick_the_holy }
							10 = { give_nickname = nick_the_glorious }
							10 = { give_nickname = nick_the_lionheart }
							10 = { give_nickname = nick_the_great }
							10 = { give_nickname = nick_the_hammer }
							20 = {
								modifier = {
									factor = 0
									religion_group = christian
								}
								give_nickname = nick_the_sword_of_god
							}
						}
					}
				}
			}
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -200
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}
		}
		FROM = {
			piety = 100
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
			participation_scaled_piety = 300
			participation_scaled_prestige = 150
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -100
			}
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
						OR = { 
							religion_group = christian
							religion = hellenic_pagan
							religion = hellenic_pagan_reformed
						}
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			hidden_tooltip = {
				if = {
					limit = {
						OR = {
							this_has_lame_nickname_trigger = yes
							has_nickname = no
						}
					}
					hidden_effect = {
						random_list = {
							10 = { give_nickname = nick_the_holy }
							10 = { give_nickname = nick_the_glorious }
							10 = { give_nickname = nick_the_lionheart }
							10 = { give_nickname = nick_the_great }
							10 = { give_nickname = nick_the_hammer }
							20 = {
								modifier = {
									factor = 0
									religion_group = christian
								}
								give_nickname = nick_the_sword_of_god
							}
						}
					}
				}
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 300
				participation_scaled_prestige = 150
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -100
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
				NOT = {
					any_liege = {
						dynasty = PREV
					}
				}
			}
			participation_scaled_decadence = 35
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
				NOT = {
					any_liege = {
						dynasty = PREV
					}
				}
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 35
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = {
		factor = 100
	}
}

# Regular Holy War CB
frtholic_religious = {
	name = CB_NAME_RELIGIOUS
	war_name = WAR_NAME_RELIGIOUS
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	check_de_jure_tier = DUKE # this scans all dejure duchies for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes

	allowed_to_target_tributaries = no
	
	sort_priority = 800
	
	can_use_gui = {
		OR = {
			AND = {
				ROOT = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}							
				}
				FROM = {
					OR = {
						is_heresy_of = catholic
						religion= catholic
					}							
				}	
			}
			AND = {				
				ROOT = {
					OR = {
						is_heresy_of = catholic
						religion= catholic
					}								
				}
				FROM = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}	
				}
			}
		}
		ROOT = { mercenary = no }
		NOT = { is_vassal_or_below = FROM }
		NOT = { is_liege_or_above = FROM }
	}
	
	on_add = {		
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {
		NOT = { has_global_flag = FoundFrenchChurch_flag }
		OR = {
			AND = {
				ROOT = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}	
				}
				FROM = {
					OR = {
						is_heresy_of = catholic
						religion= catholic						
					}							
				}	
			}
			AND = {				
				ROOT = {
					OR = {
						is_heresy_of = catholic
						religion= catholic
					}							
				}
				FROM = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}	
				}
			}
		}
		ROOT = {			
			is_nomadic = no
			NOT = { religion_group = pagan_group }
			NOT = { pacifist = yes }
			NAND = {
				OR = {
					has_landed_title = k_teutonic_state
					has_landed_title = d_teutonic_order
				}
				has_global_flag = northern_crusades_active
			}
			NOR = {
				has_character_flag = currently_reconquering_iberia
				reconquista_check_trigger = yes
			}			
			NOT = { same_realm = FROM }
			mercenary = no
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						OR = {
							AND = {
								has_owner = yes
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
							AND = {
								is_land = no
								OR = {
									ROOT = { religion_group = muslim }
									FROM = { religion_group = muslim }
									AND = {
										ROOT = { religion_group = pagan_group }
										has_global_flag = pagan_ghws_unlocked
									}
									AND = {
										ROOT = { religion_group = christian }
										has_global_flag = christian_crusades_unlocked
									}
									AND = {
										ROOT = { religion_group = muslim }
										has_global_flag = muslim_jihads_unlocked
									}
								}
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			OR = {
				religion = frtholic
				religion = frtholic_OLD
				is_heresy_of = catholic
				religion = catholic	
			}
		}
		FROM = {
			NOT = { religion = ROOT }
		}		
	}
	
	on_success = {
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		
		ROOT = { 
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		FROM = {
			if = {
				limit = {
					NOT = {
						has_character_modifier = known_satanist
					}
				}
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}		
			}
		}
		FROM = { show_scope_change = no piety = -100 }
		FROM = { show_scope_change = no prestige = -50 }
	}

	on_success_title = {
		if = { # Standard Holy War behaviour for Non-Muslims and Muslims fighting other Muslims
			show_scope_change = no
			limit = {
				OR = {
					ROOT = {
						NOT = {
							religion_group = muslim
						}
					}
					AND = {
						ROOT = {
							religion_group = muslim
						}
						FROM = {
							religion_group = muslim
						}
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							same_religion = yes # Only vassalize rulers of my religion
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
		if = { # Muslims fighting Non-Muslims preserve vassals
			show_scope_change = no
			limit = {
				ROOT = {
					religion_group = muslim
				}
				FROM = {
					NOT = {
						religion_group = muslim
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_muslim_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}

		hidden_tooltip = {
			check_war_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		ROOT = {
			show_scope_change = no
			piety = -50 
			prestige = -100
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		FROM = {
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
				NOT = {
					any_liege = {
						dynasty = PREV
					}
				}
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
				NOT = {
					any_liege = {
						dynasty = PREV
					}
				}
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 20
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
		
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				religion = frtholic
				has_landed_title = e_french_religions_head
				has_character_modifier = flag_preparing_coronation
			}
		}
		
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_nomadic = no
				NOT = {
					is_tribal = yes
				}
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_tribal = yes
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
							holding_type = tribal
						}
					}
				}
			}
		}
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 2.0
			OR = {
				culture = persian
				culture = baloch
				culture = afghan
				culture = turkish
			}
			empire = {
				OR = {
					title = e_persia
					title = e_rajastan
				}
			}
		}
	}
}

# Regular Holy War CB
frtholic_orthodox_religious = {
	name = CB_NAME_RELIGIOUS
	war_name = WAR_NAME_RELIGIOUS
	sprite = 9
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	check_de_jure_tier = DUKE # this scans all dejure duchies for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes

	allowed_to_target_tributaries = no
	
	sort_priority = 800
	
	can_use_gui = {
		OR = {
			AND = {
				ROOT = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}							
				}
				FROM = {
					OR = {
						is_heresy_of = orthodox
						religion= orthodox
					}							
				}	
			}
			AND = {				
				ROOT = {
					OR = {
						is_heresy_of = orthodox
						religion= orthodox
					}								
				}
				FROM = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}	
				}
			}
		}
		ROOT = { mercenary = no }
		NOT = { is_vassal_or_below = FROM }
		NOT = { is_liege_or_above = FROM }
	}
	
	on_add = {		
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {
		has_global_flag = France_SchismCatholic_flag		
		OR = {
			AND = {
				ROOT = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}	
				}
				FROM = {
					OR = {
						is_heresy_of = orthodox
						religion= orthodox						
					}							
				}	
			}
			AND = {				
				ROOT = {
					OR = {
						is_heresy_of = orthodox
						religion= orthodox
					}							
				}
				FROM = {
					OR = {
						religion = frtholic
						religion = frtholic_OLD
					}	
				}
			}
		}
		ROOT = {			
			is_nomadic = no
			NOT = { religion_group = pagan_group }
			NOT = { pacifist = yes }
			NAND = {
				OR = {
					has_landed_title = k_teutonic_state
					has_landed_title = d_teutonic_order
				}
				has_global_flag = northern_crusades_active
			}
			NOR = {
				has_character_flag = currently_reconquering_iberia
				reconquista_check_trigger = yes
			}			
			NOT = { same_realm = FROM }
			mercenary = no
		}
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						OR = {
							AND = {
								has_owner = yes
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
							AND = {
								is_land = no
								OR = {
									ROOT = { religion_group = muslim }
									FROM = { religion_group = muslim }
									AND = {
										ROOT = { religion_group = pagan_group }
										has_global_flag = pagan_ghws_unlocked
									}
									AND = {
										ROOT = { religion_group = christian }
										has_global_flag = christian_crusades_unlocked
									}
									AND = {
										ROOT = { religion_group = muslim }
										has_global_flag = muslim_jihads_unlocked
									}
								}
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		ROOT = {
			OR = {
				religion = frtholic
				religion = frtholic_OLD
				is_heresy_of = orthodox
				religion = orthodox	
			}
		}
		FROM = {
			NOT = { religion = ROOT }
		}		
	}
	
	on_success = {
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		
		ROOT = { 
			participation_scaled_piety = 100
			participation_scaled_prestige = 50
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		FROM = {
			if = {
				limit = {
					NOT = {
						has_character_modifier = known_satanist
					}
				}
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}		
			}
		}
		FROM = { show_scope_change = no piety = -100 }
		FROM = { show_scope_change = no prestige = -50 }
	}

	on_success_title = {
		if = { # Standard Holy War behaviour for Non-Muslims and Muslims fighting other Muslims
			show_scope_change = no
			limit = {
				OR = {
					ROOT = {
						NOT = {
							religion_group = muslim
						}
					}
					AND = {
						ROOT = {
							religion_group = muslim
						}
						FROM = {
							religion_group = muslim
						}
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							same_religion = yes # Only vassalize rulers of my religion
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}
		if = { # Muslims fighting Non-Muslims preserve vassals
			show_scope_change = no
			limit = {
				ROOT = {
					religion_group = muslim
				}
				FROM = {
					NOT = {
						religion_group = muslim
					}
				}
			}
			custom_tooltip = {
				text = religious_cb_succ_muslim_tip
				hidden_tooltip = {
					ROOT = {
						vassalize_or_take_under_title = {
							title = PREV
							enemy = FROM
							is_religious = yes
							type = holy_war
						}
					}
				}
			}
		}

		hidden_tooltip = {
			check_war_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}

	on_fail = {
		ROOT = {
			show_scope_change = no
			piety = -50 
			prestige = -100
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -75
			prestige = -150
		}
		FROM = {
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { 
				participation_scaled_piety = 200
				participation_scaled_prestige = 100
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				hidden_tooltip = {
					if = {
						limit = {
							has_ambition = obj_strengthen_religion
						}
						change_variable = { which = strengthen_religion value = 1 }
					}
				}
			}
		}
		any_attacker = {
			limit = {
				character = ROOT
				uses_decadence = yes
				NOT = {
					any_liege = {
						dynasty = PREV
					}
				}
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
				NOT = {
					any_liege = {
						dynasty = PREV
					}
				}
			}
			hidden_tooltip = { 
				participation_scaled_decadence = 20
			}
		}
		ROOT = { 
			religion_authority = {
				modifier = lost_holy_war
				years = 20
			}
		}
		FROM = { 
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
		
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				religion = frtholic
				has_landed_title = e_french_religions_head
				has_character_modifier = flag_preparing_coronation
			}
		}
		
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_nomadic = no
				NOT = {
					is_tribal = yes
				}
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
						}
					}
				}
			}
		}
		modifier = {
			factor = 0
			FROM = {
				is_nomadic = yes
			}
			ROOT = {
				is_tribal = yes
			}
			NOT = {
				any_direct_de_jure_vassal_title = {
					any_direct_de_jure_vassal_title = {
						OR = {
							holding_type = castle
							holding_type = city
							holding_type = tribal
						}
					}
				}
			}
		}
		
		# Try to guide the Hordes in the right direction
		modifier = {
			factor = 0.1
			ROOT = {
				OR = {
					dynasty = 613 # Seljuks
					dynasty = 800 # Timurids
					primary_title = { title = e_il-khanate }
				}
			}
			OR = {
				empire = {
					NOT = {
						OR = {
							title = e_persia
							title = e_byzantium
							title = e_arabia
						}
					}
				}
				FROM = {
					primary_title = { title = e_golden_horde }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 0.1
			ROOT = {
				primary_title = { title = e_golden_horde }
			}
			OR = {
				empire = {
					OR = {
						title = e_persia
						title = e_byzantium
						title = e_arabia
					}
				}
				FROM = {
					primary_title = { title = e_il-khanate }
					NOT = { year = 1300 }
				}
			}
		}
		modifier = {
			factor = 2.0
			OR = {
				culture = persian
				culture = baloch
				culture = afghan
				culture = turkish
			}
			empire = {
				OR = {
					title = e_persia
					title = e_rajastan
				}
			}
		}
	}
}

frtholic_depose_antipope = {
	name = CB_NAME_FRTHOLIC_DEPOSE_ANTIPOPE
	war_name = WAR_FRTHOLIC_NAME_DEPOSE_ANTIPOPE
	sprite = 29
	truce_days = 3650
	is_permanent = yes
	can_ask_to_join_war = yes
	
	defender_unoccupied_warscore = yes
	
	attacker_rel_head_is_ally = yes # The attacker can call his (main) Pope into the war
	allowed_to_target_tributaries = no
	
	sort_priority = 3750
	
	can_use_gui = {
		#check_if_crusader_trigger = yes
		custom_tooltip = {
			text = z_France_SchismCatholic
			has_global_flag = France_SchismCatholic_flag
		}
		custom_tooltip = {
			text = tooltip_Fail_France_SchismCatholic
			NOT = { has_global_flag = Fail_France_SchismCatholic_flag }			
		}
		ROOT = { war = no }
		NOT = { is_vassal_or_below = FROM }
		NOT = { is_liege_or_above = FROM }
	}

	can_use = {
		has_global_flag = France_SchismCatholic_flag
		NOT = { has_global_flag = Fail_France_SchismCatholic_flag }
		ROOT = {
			religion = catholic
			mercenary = no
		}
		FROM = {			
			OR = {
				AND = {
					religion = frtholic
					controls_religion	= yes					
				}				
				any_vassal = {
					religion = frtholic
					controls_religion	= yes
				}
			}			
		}
	}
	
	is_valid = {
		NOT = { has_global_flag = Fail_France_SchismCatholic_flag }
		ROOT = {
			religion = catholic			
		}
		FROM = {			
			OR = {
				AND = {
					religion = frtholic
					controls_religion	= yes					
				}	
				any_vassal = {
					religion = frtholic
					controls_religion	= yes
				}
			}				
		}
	}

	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}		

	on_success = {		
		set_global_flag = Fail_France_SchismCatholic_flag	
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 500
				participation_scaled_prestige = 250
			}
		}
		ROOT = {
			participation_scaled_piety = 500
			participation_scaled_prestige = 250
			religion_authority = { modifier = fail_catholic_francereligionSchismCatholic_authority years = 100 }
			if = {
				limit = {
					rightful_religious_head_scope = {
						ROOT = {
							excommunicated_for = PREV
						}
					}
				}
				excommunicate = no
			}			
			rightful_religious_head_scope = {
				opinion = {
					who = ROOT
					modifier = opinion_deposed_antipope
				}
			}
		}		
		FROM = { 
			piety = -5000
			prestige = -2500
			transfer_scaled_wealth = {
				to = ROOT
				value = 4.0
			}
			religion_authority = { modifier = fail_francereligionSchismCatholic_authority years = 100 }
		}
		catholic = {
			set_religion_head = k_papal_state
			set_can_have_antipopes = yes
			set_autocephaly = no		
		}
		frtholic = {
			set_religion_head = none			
			set_autocephaly = yes			
		}
		hidden_tooltip = {
			d_knights_templar = {
				religion = catholic
				holder_scope = {
					religion = catholic
				}
			}
			d_knights_hospitaler = {
				religion = catholic
				holder_scope = {
					religion = catholic
				}
			}
			d_teutonic_order = {
				religion = frtholic
				holder_scope = {
					religion = frtholic
				}
			}
			d_knights_calatrava = {
				religion = catholic
				holder_scope = {
					religion = catholic
				}
			}
			d_knights_santiago = {
				religion = catholic
				holder_scope = {
					religion = catholic
				}
			}				
		}
	}

	on_fail = {		
		ROOT = { 
			piety = -250
			prestige = -125
		}
		FROM = { 
			piety = 100
			prestige = 50
		}
	}

	on_reverse_demand = {		
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -500
			prestige = -250
		}		
		FROM = { 
			piety = 500
			prestige = 250
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	ai_will_do = {
		factor = 100
	}
}

frtholic_hre_depose_antipope = {
	name = CB_NAME_FRTHOLIC_DEPOSE_ANTIPOPE
	war_name = WAR_FRTHOLIC_NAME_DEPOSE_ANTIPOPE
	sprite = 29
	truce_days = 3650
	is_permanent = yes
	can_ask_to_join_war = yes
	
	defender_unoccupied_warscore = yes
	
	attacker_rel_head_is_ally = yes # The attacker can call his (main) Pope into the war
	allowed_to_target_tributaries = no
	
	sort_priority = 3750
	
	can_use_gui = {
		#check_if_crusader_trigger = yes
		custom_tooltip = {
			text = z_Common_SchismCatholic
			has_global_flag = Common_SchismCatholic_flag
		}
		custom_tooltip = {
			text = tooltip_Fail_France_SchismCatholic
			NOT = { has_global_flag = Fail_Common_SchismCatholic_flag }			
		}
		ROOT = { war = no }
		NOT = { is_vassal_or_below = FROM }
		NOT = { is_liege_or_above = FROM }
	}

	can_use = {
		has_global_flag = Common_SchismCatholic_flag
		NOT = { has_global_flag = Fail_Common_SchismCatholic_flag }
		ROOT = {
			OR = {
				religion = catholic
				religion = frtholic
			}			
			mercenary = no
		}
		FROM = {			
			OR = {
				AND = {
					religion = catholic
					controls_religion	= yes					
				}				
				any_vassal = {
					religion = catholic
					controls_religion	= yes
				}
			}			
		}
	}
	
	is_valid = {
		NOT = { has_global_flag = Fail_Common_SchismCatholic_flag }
		ROOT = {
			OR = {
				religion = catholic
				religion = frtholic
			}	
		}
		FROM = {			
			OR = {
				AND = {
					religion = catholic
					controls_religion	= yes					
				}	
				any_vassal = {
					religion = catholic
					controls_religion	= yes
				}
			}				
		}
	}

	on_add = {
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}	
	

	on_success = {		
		set_global_flag = Fail_Common_SchismCatholic_flag	
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_piety = 500
				participation_scaled_prestige = 250
			}
		}
		ROOT = {
			participation_scaled_piety = 500
			participation_scaled_prestige = 250
			religion_authority = { modifier = fail_catholic_francereligionSchismCatholic_authority years = 100 }
			if = {
				limit = {
					rightful_religious_head_scope = {
						ROOT = {
							excommunicated_for = PREV
						}
					}
				}
				excommunicate = no
			}			
			rightful_religious_head_scope = {
				opinion = {
					who = ROOT
					modifier = opinion_deposed_antipope
				}
			}
		}		
		FROM = { 
			piety = -5000
			prestige = -2500
			transfer_scaled_wealth = {
				to = ROOT
				value = 4.0
			}
			#religion_authority = { modifier = fail_francereligionSchismCatholic_authority years = 100 }
		}
		catholic = {
			set_religion_head = k_papal_state
			set_can_have_antipopes = yes
			#set_autocephaly = no			
		}
		k_catholic_head = {
			activate_title = { title = THIS status = no }
			destroy_landed_title = THIS
		}		
	}

	on_fail = {		
		ROOT = { 
			piety = -250
			prestige = -125
		}
		FROM = { 
			piety = 100
			prestige = 50
		}
	}

	on_reverse_demand = {		
		ROOT = {
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -500
			prestige = -250
		}		
		FROM = { 
			piety = 500
			prestige = 250
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	ai_will_do = {
		factor = 100
	}
}