################## Added one condition in can_use_gui

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 = {
		ROOT = {
			uses_new_crusade = no
			has_called_crusade = no
			religion_authority = 0.05
			conditional_tooltip = {
				trigger = {
					is_alternate_start = yes
					has_alternate_start_parameter = {
						key = religion_names
						value = random
					}
				}
				custom_tooltip = {
					text = ALT_GHW_STARTED
					has_global_flag = muslim_jihads_unlocked
					has_global_flag = pagan_ghws_unlocked
					has_global_flag = christian_crusades_unlocked
				}
			}
			conditional_tooltip = {
				trigger = {
					NOT = {
						has_alternate_start_parameter = {
							key = religion_names
							value = random
						}
					}
				}
				OR = {
					religion_group = zoroastrian_group
					religion_group = jewish_group
					
					AND = { #################################################### new stuff
						religion = satanism
						has_global_flag = satanism_formed
					}
					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 = {
			uses_new_crusade = no
			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
			}
		}
	}
	
	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_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
	}
}