expd_t_from_is_not_in_any_tributary_war = {
	FROM = {
		NOR = {
			any_war = {
				using_cb = tributary_cb
			}
			any_war = {
				using_cb = tributary_permanent_cb
			}
			any_war = {
				using_cb = tributary_nomad_cb
			}
			any_war = {
				using_cb = free_tributary_cb
			}
			any_war = {
				using_cb = expd_t_chainable_extort_tributary_cb
			}
			any_war = {
				using_cb = expd_t_chainable_permanent_tributary_cb
			}
			any_war = {
				using_cb = expd_t_free_tributary_cb
			}
		}
	}
}

expd_t_from_borders_root_or_roots_tributaries = {
	# Border condition for validity of enforcing tributary status
	# The attacker (or one of their normal/modded tributaries) needs a border, or be at most two sea zones away from one of the target's counties
	FROM = {
		any_realm_province = {
			expd_t_this_province_borders_root_or_roots_tributaries = yes
		}
	}
}

expd_t_from_borders_root_or_roots_same_religion_tributaries = {
	# Border condition for expanded religious liberation CB
	# The attacker (or one of their normal/modded same-religion tributaries) needs a border, or be at most two sea zones away from one of the defender's counties
	FROM = {
		any_realm_province = {
			expd_t_this_province_borders_root_or_roots_same_religion_tributaries = yes
		}
	}
}

expd_t_this_de_jure_kingdom_borders_root_or_roots_same_religion_tributaries = {
	# Border condition for expanded religious liberation CB
	# The targeted kingdom title must border (or be at most 2 sea zones away) from one of the attacker's (or one of their normal/modded same-religion tributaries') counties
	any_de_jure_vassal_title = {
		tier = COUNT
		location = {
			expd_t_this_province_borders_root_or_roots_same_religion_tributaries = yes
		}
	}
}



############
# Holy War #
############

expd_t_this_character_can_maintain_valid_holy_war_against_from = {
	# Slightly-modified version of the "is_valid" clause of the "religious" CB (approx line 6023 of 00_cb_types)
	NOT = { religion_group = pagan_group }
	NOT = { pacifist = yes }
	NOT = { same_realm = FROM }
	OR = {
		NOT = { religion_group = FROM }
		is_heresy_of = FROM
		is_parent_religion = FROM
		AND = {
			has_dharmic_religion_trigger = yes
			FROM = { religion = taoist }
		}
		AND = {
			religion_group = FROM
			NOT = { has_character_modifier = known_satanist }
			FROM = { has_character_modifier = known_satanist }
		}
		AND = {
			religion_group = muslim
			NOT = { religion = FROM }
		}
	}
	# Add the requirement that this character must be functionally independent
	# This replaces all of the vanilla conditions on the top_liege
	top_liege = { character = PREV }
}




#############
# UTILITIES #
#############

expd_t_this_province_borders_root_or_roots_tributaries = {
	any_neighbor_province = {
		OR = {
			AND = {
				has_owner = yes
				owner = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
						expd_t_top_liege_is_normal_or_modded_tributary_of_root = yes
					}
				}
				NOT = { has_global_flag = expd_t_chainable_tributary_cbs_disallow_land_borders }
			}
			AND = {
				is_land = no
				any_neighbor_province = {
					OR = {
						AND = {
							has_owner = yes
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
									expd_t_top_liege_is_normal_or_modded_tributary_of_root = yes
								}
							}
							NOT = { has_global_flag = expd_t_chainable_tributary_cbs_disallow_sea_borders }
						}
						AND = {
							is_land = no
							any_neighbor_province = {
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
										expd_t_top_liege_is_normal_or_modded_tributary_of_root = yes
									}
								}
							}
							NOT = { has_global_flag = expd_t_chainable_tributary_cbs_disallow_sea_border_chaining }
						}
					}
				}
			}
		}
	}
}

expd_t_this_province_borders_root_or_roots_same_religion_tributaries = {
	any_neighbor_province = {
		OR = {
			AND = {
				has_owner = yes
				owner = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
						AND = {
							expd_t_top_liege_is_normal_or_modded_tributary_of_root = yes
							top_liege = { religion = ROOT }
						}
					}
				}
				NOT = { has_global_flag = expd_t_chainable_tributary_cbs_disallow_land_borders }
			}
			AND = {
				is_land = no
				any_neighbor_province = {
					OR = {
						AND = {
							has_owner = yes
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
									AND = {
										expd_t_top_liege_is_normal_or_modded_tributary_of_root = yes
										top_liege = { religion = ROOT }
									}
								}
							}
							NOT = { has_global_flag = expd_t_chainable_tributary_cbs_disallow_sea_borders }
						}
						AND = {
							is_land = no
							any_neighbor_province = {
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
										AND = {
											expd_t_top_liege_is_normal_or_modded_tributary_of_root = yes
											top_liege = { religion = ROOT }
										}
									}
								}
							}
							NOT = { has_global_flag = expd_t_chainable_tributary_cbs_disallow_sea_border_chaining }
						}
					}
				}
			}
		}
	}
}

expd_t_this_character_is_not_primary_attacker_in_any_other_war = {
	custom_tooltip = {
		text = expd_t_this_character_is_not_primary_attacker_in_any_other_war_tt
		NOT = { any_war = { attacker = { character = PREVPREV } } }
	}
}