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
	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
	
	allowed_to_target_tributaries = no
	allowed_to_target_suzerains = no

	can_use_gui = {
		ROOT = {
			has_called_crusade = no
			religion_authority = 0.05
			OR = {
				religion_group = zoroastrian_group
				religion_group = jewish_group
				AND = {
					religion_group = pagan_group
					custom_tooltip = {
						text = CTT_PAGAN_GHWS_UNLOCKED
						has_global_flag = pagan_ghws_unlocked
					}
				}
				AND = { 
					religion_group = christian
					custom_tooltip = {
						text = CTT_CHRISTIAN_CRUSADES_UNLOCKED
						has_global_flag = christian_crusades_unlocked
					}
				}
				AND = {
					religion_group = muslim
					custom_tooltip = {
						text = CTT_MUSLIM_JIHADS_UNLOCKED
						has_global_flag = muslim_jihads_unlocked
					}
				}
			}
			mercenary = no
		}
	}

	can_use = {
		ROOT = {
			can_call_crusade = yes
		}
		
		FROM = {
			OR = {
				NOT = { religion_group = ROOT }
				is_heresy_of = ROOT
				is_parent_religion = ROOT
				AND = {
					religion_group = pagan_group
					NOT = { religion = ROOT }
				}
			}
		}
		
		NOT = { # Not if the Schism has been mended
			AND = {
				OR = {
					religion = catholic
					religion = fraticelli
				}
				has_global_flag = schism_mended
			}
		}
	}

	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
			}
		}
		
		# Restrictions on crusade targets for AI religion heads
		OR = {
			# Religion head is a player
			ROOT = { ai = no }
			# The target owns a holy site within that kingdom title
			FROM = {
				any_realm_title = {
					de_jure_liege_or_above = PREVPREV
					is_holy_site = ROOT
				}
			}
			# The target owns a province of the religion within that kingdom title
			any_direct_de_jure_vassal_title = {
				any_direct_de_jure_vassal_title = {
					owner_under_FROM = yes
					location = { religion = ROOT }
				}
			}
			# A ruler of the religion either owns a province in that kingdom or is neighboring
			any_direct_de_jure_vassal_title = {
				any_direct_de_jure_vassal_title = {
					location = {
						OR = {
							owner = { religion = ROOT }
							any_neighbor_province = { owner = { religion = ROOT } }
						}
					}
				}
			}
		}
	}
	
	is_valid = {
		ROOT = {
			can_call_crusade = yes
		}
		FROM = {
			OR = {
				NOT = { religion_group = ROOT }
				is_heresy_of = ROOT
				is_parent_religion = ROOT
				AND = {
					religion_group = pagan_group
					NOT = { religion = ROOT }
				}
			}
		}
	}

	is_valid_title = {
		FROM = {
			any_realm_title = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	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 = {
				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 }
				}
			}
		}
		
		# 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 = {
							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 = { character = ROOT }
			participation_scaled_prestige = 500
			participation_scaled_piety = 1000
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -100
			}
		}
		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 = {
			religion_authority = {
				modifier = won_crusade
				years = 20
			}
		}
		
		FROM = {
			piety = -100
			religion_authority = {
				modifier = lost_crusade
				years = 20
			}			
		}
	}

	on_fail = {
		ROOT = {
			piety = -100
		}
		
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 200
			participation_scaled_prestige = 100
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -50
			}
		}
		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 = {
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
					religion_group = christian
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					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 = {
			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
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_piety = 300
			participation_scaled_prestige = 150
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -100
			}
		}
		FROM = {
			if = {
				limit = { 
					has_dlc = "Legacy of Rome"
					OR = { 
						has_landed_title = e_byzantium
						has_landed_title = e_roman_empire
					}
					religion_group = christian
				}
				hidden_tooltip = { character_event = { id = LoR.30 days = 12 } }
			}
			hidden_tooltip = {
				if = {
					limit = {
						has_nickname = no
					}
					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
			}
			participation_scaled_decadence = 35
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
			}
			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
	}
}