### NEW CBs 2.8
dejure_duchy_claim = { # New1
	name = CB_NAME_DEJURECLAIM
	war_name = WAR_NAME_DEJURECLAIM
	sprite = 31
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	check_de_jure_tier = DUKE
	press_claim = yes
	can_ask_to_join_war = no

	allowed_to_target_tributaries = no
	
	sort_priority = 790

	can_use_gui = {
		check_if_crusader_trigger = yes
		ROOT = {
			show_scope_change = no
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
				}
				prestige = 250
			}
			conditional_tooltip = {
				trigger = { 
					tier = KING
				}
				prestige = 500
			}
			conditional_tooltip = {
				trigger = { 
					tier = EMPEROR
				}
				prestige = 1000
			}
		}
	}
	
	on_add = {
		ROOT = {
			if = {
				limit = {
					tier = DUKE
				}
				prestige = -250
			}
			if = {
				limit = {
					tier = KING
				}
				prestige = -500
			}
			if = {
				limit = {
					tier = EMPEROR
				}
				prestige = -1000
			}
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}
	
	can_use_title = {
		
		OR = {
			holder = ROOT
			kingdom = {
				holder = ROOT
			}
			empire = {
				holder = ROOT
			}
		}
		
		FROM = { # Can only De Jure claim duchies from the same religion group
			religion_group = ROOT
			NOT = {
				is_liege_of = ROOT
			}
		}
		
		OR = { # This ensures that the AI doesn't declare this type of war against someone who only holds one county within the targeted title...
			ROOT = {
				ai = no
			}
			any_de_jure_vassal_title = {
				count = 2
				tier = count
				holder_scope = {
					same_realm = FROM
				}
			}
		}
		
		NAND = { # Though different sects of Muslims must Holy War each other instead
			ROOT = {
				NOT = {
					religion = FROM
				}
			}
			ROOT = {
				religion_group = muslim
			}
			FROM = {
				religion_group = muslim
			}
		}
		
		FROM = {
			OR = {
				holy_order = no
				NOT = { religion = ROOT }
				NOT = { has_dlc = "Sons of Abraham" }
				OR = {
					AND = {
						primary_title = { title = d_flaming_rose }
						ROOT = {
							has_character_modifier = expelled_d_flaming_rose
						}
					}
				}
			}
		}
	}
	
	can_use = {
		has_dlc = "Jade Dragon"
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			NOT = {
				has_game_rule = {
					name = jade_dragon_cbs
					value = off
				}
			}
		}
	}

	on_success_title = {
		ROOT = {
			vassalize_or_take_under_title = {
				title = PREV
				enemy = FROM
				#anti_nomad = yes # Vassalize non-nomadic rulers
				type = claim
			}
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}

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

		
	}

	on_fail_title = {
		ROOT = {
			show_scope_change = no
			prestige = -100
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	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 = {
			factor = 0
			ROOT = {
				has_character_flag = is_temujin
				has_landed_title = e_mongol_empire
				demesne_size = 1
			}
			FROM = {
				has_landed_title = e_china_west_governor
			}
		}
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}

force_vassalization = { # New2
	name = CB_NAME_FORCE_VASSALIZATION
	war_name = WAR_NAME_FORCE_VASSALIZATION
	sprite = 32
	truce_days = 365
	is_permanent = yes
	can_ask_to_join_war = yes
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	sort_priority = 830
	
	can_use_gui = {
		check_if_crusader_trigger = yes
		FROM = {
			show_scope_change = no
			conditional_tooltip = {
				trigger = { 
					tier = COUNT
				}
				ROOT = {
					show_scope_change = no
					OR = { 
						prestige = 250
						custom_tooltip = { 
							text = tooltip_antagonize_vassalize_claim 
							hidden_tooltip = { has_opinion_modifier = { who = FROM modifier = opinion_antagonize_vassalize_claim } } 
						}
					}
				}
			}
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
				}
				ROOT = {
					show_scope_change = no
					OR = { 
						prestige = 1000
						custom_tooltip = { 
							text = tooltip_antagonize_vassalize_claim 
							hidden_tooltip = { has_opinion_modifier = { who = FROM modifier = opinion_antagonize_vassalize_claim } } 
						}
					}
				}
			}
			conditional_tooltip = {
				trigger = { 
					tier = KING
				}
				ROOT = {
					show_scope_change = no
					OR = { 
						prestige = 2500
						custom_tooltip = { 
							text = tooltip_antagonize_vassalize_claim 
							hidden_tooltip = { has_opinion_modifier = { who = FROM modifier = opinion_antagonize_vassalize_claim } } 
						}
					}
				}
			}
		}
	}
	
	on_add = {
		FROM = {
			if = {
				limit = {
					tier = COUNT					
					NOT = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_antagonize_vassalize_claim } } 
				}
				ROOT = {
					prestige = -250
				}
			}
			if = {
				limit = {
					tier = DUKE
					NOT = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_antagonize_vassalize_claim } } 
				}
				ROOT = {
					prestige = -1000
				}
			}
			if = {
				limit = {
					tier = KING
					NOT = { reverse_has_opinion_modifier = { who = ROOT modifier = opinion_antagonize_vassalize_claim } } 
				}
				ROOT = {
					prestige = -2500
				}
			}
			if = {
				limit = {
					reverse_has_opinion_modifier = { who = ROOT modifier = opinion_antagonize_vassalize_claim }
				}
				ROOT = {
					remove_opinion = { who = ROOT modifier = opinion_antagonize_vassalize_claim }
				}
			}
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}
	
	can_use = {
		has_dlc = "Jade Dragon"
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			NOT = {
				has_game_rule = {
					name = jade_dragon_cbs
					value = off
				}
			}
			higher_tier_than = count
			NOT = { same_realm = FROM }
			NOT = { is_liege_or_above = FROM }
			mercenary = no
			is_nomadic = no
		}
		
		FROM = {
			lower_tier_than = ROOT
			NOT = {
				realm_size = 31
			}
			in_revolt = no
			is_nomadic = no
			controls_religion = no
			holy_order = no
			OR = {
				religion = ROOT
				culture_group = ROOT
			}
			shares_realm_border_with = ROOT
		}
	}
	
	is_valid = {
		FROM = {
			is_landed = yes
			lower_tier_than = ROOT
		}
	}

	on_success = {
		ROOT = {
			show_scope_change = no
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = {
			show_scope_change = no
			prestige = -100
			set_defacto_liege = ROOT
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}
	
	on_fail = {
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	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 = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}

great_realm_conflict = { # New3
	name = CB_NAME_GREATREALMCONFLICT
	war_name = WAR_NAME_GREATREALMCONFLICT
	sprite = 33
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	check_de_jure_tier = KING
	can_ask_to_join_war = no

	allowed_to_target_tributaries = no
	
	sort_priority = 820

	can_use_gui = {
		check_if_crusader_trigger = yes
		ROOT = {
			prestige = 3000
			piety = 1500
		}
		FROM = {
			relative_power = {
				who = ROOT
				power = 0.95
			}
		}
	}
	
	on_add = {
		ROOT = {
			prestige = -3000
			piety = -1500
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}
	
	can_use = {
		has_dlc = "Jade Dragon"
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			NOT = {
				has_game_rule = {
					name = jade_dragon_cbs
					value = off
				}
			}
		}
		FROM = {
			relative_power = {
				who = ROOT
				power = 0.95
			}
		}
	}
	
	can_use_title = {
		ROOT = {
			is_nomadic = no
			independent = yes
			realm_size = 200
			OR = {
				tier = KING
				tier = EMPEROR
			}
		}
		FROM = {
			realm_size = 200
			in_revolt = no
			is_nomadic = no
			OR = {
				tier = KING
				tier = EMPEROR
			}
		}
		
		OR = { # This ensures that the AI doesn't declare this type of war against someone who only holds a few counties within the targeted title...
			ROOT = {
				ai = no
			}
			FROM = {
				num_of_realm_counties = {
					value = 5
					title = PREV
				}
			}
		}
		
		any_direct_de_jure_vassal_title = {
			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
									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_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}
	
	on_invalidation = {
		ROOT = {
			prestige = 3000
			piety = 1500
		}
	}

	on_success_title = {
		if = { # Claim the targeted Kingdom if it is held by the target
			limit = {
				controls_religion = no
				holder_scope = {
					OR = {
						character = FROM
						is_liege_or_above = FROM
					}
				}
			}
			usurp_title = { target = ROOT type = invasion }
		}
		ROOT = {
			vassalize_or_take_under_title = {
				title = PREV
				enemy = FROM
				type = invasion
			}
			hidden_tooltip = {
				vassalize_or_take_under_title = {
					title = PREV
					enemy = FROM
					type = invasion
				}
			}
		}
		
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}

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

	on_fail_title = {
		ROOT = {
			show_scope_change = no
			prestige = -1500
			piety = -750
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -3000
			piety = -1500
			transfer_scaled_wealth = {
				to = FROM
				value = 10.0
			}
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 3000
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 1500 }
		}
	}

	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 = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}

ducal_county_conquest = { # New4
	name = CB_NAME_DUCALCOUNTYCONQUEST
	war_name = WAR_NAME_DUCALCOUNTYCONQUEST
	sprite = 34
	truce_days = 3650
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	press_claim = yes
	can_ask_to_join_war = no

	allowed_to_target_tributaries = no
	
	sort_priority = 720
	
	can_use_gui = {
		check_if_crusader_trigger = yes
		ROOT = {
			show_scope_change = no
			conditional_tooltip = {
				trigger = { 
					tier = COUNT
				}
				piety = 100
				scaled_wealth = 1.0
			}
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
				}
				piety = 250
				scaled_wealth = 1.0
			}
		}
	}
	
	on_add = {
		ROOT = {
			if = {
				limit = {
					tier = COUNT
				}
				piety = -100
				scaled_wealth = -1.0
			}
			if = {
				limit = {
					tier = DUKE
				}
				piety = -250
				scaled_wealth = -1.0
			}
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}
	
	can_use = {
		has_dlc = "Jade Dragon"
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			NOT = {
				has_game_rule = {
					name = jade_dragon_cbs
					value = off
				}
			}
		}
	}
	
	can_use_title = {
		ROOT = {
			NOR = { # These all have other ways to expand in the early game
				religion_group = muslim
				religion_group = pagan_group
				is_nomadic = yes
			}
			OR = { # Only Counts and Dukes can use this
				tier = COUNT
				tier = DUKE
			}
		}
	
		tier = COUNT
		
		dejure_liege_title = {
			has_holder = no
			any_de_jure_vassal_title = {
				holder = ROOT
			}
		}
		
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
		
		
		NOR = {
			ROOT = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = ROOT
			}
			holder_scope = {
				ROOT = {
					any_liege = {
						character = PREVPREV
					}
				}
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
	}

	on_success_title = {
		if = { # If the attacker is a duke, and the target is a one-county ruler, vassalize them
			limit = {
				ROOT = {
					tier = DUKE
				}
				holder_scope = {
					tier = COUNT
					is_patrician = no
					NOT = { num_of_count_titles = 2 }
					lower_tier_than = ROOT
				}
			}

			holder_scope = {
				set_defacto_liege = ROOT
			}
		}

		if = {
			limit = {
				holder_scope = {
					OR = {
						ROOT = {
							tier = COUNT
						}
						higher_tier_than = COUNT
						num_of_count_titles = 2
						is_patrician = yes
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = { target = ROOT type = claim }
			any_de_jure_vassal_title = { # take all baronies under the one we're fighting for
				limit = {
					has_holder = yes
					NOT = {
						de_facto_liege = PREV
					}
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
				}

				usurp_title_plus_barony_if_unlanded = { target = ROOT type = claim }
			}
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}

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

	on_fail_title = {
		ROOT = {
			show_scope_change = no
			prestige = -100
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	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 = {
			factor = 0
			ROOT = {
				NOT = { scaled_wealth = 1.25 }
			}
		}
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}

hostages_cb = { # New5
	name = CB_NAME_HOSTAGES
	war_name = WAR_NAME_HOSTAGES
	sprite = 25
	truce_days = 3650
	is_permanent = yes
	can_ask_to_join_war = no
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	hostages_block_cb = no
	
	sort_priority = 100000 # When there are hostages you can usually not declare any other war, so we want this first
	
	can_use_gui = {
		check_if_crusader_trigger = yes
	}

	can_use = {
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			independent = yes
		}
		FROM = {
			any_realm_character = {
				is_landed = no
				OR = {
					any_spouse = { character = ROOT }
					is_friend = ROOT
					is_close_relative = ROOT
					dynasty = ROOT
					is_consort = ROOT
				}
				OR = {
					prisoner = yes
					ROOT_FROM = {
						any_realm_character = {
							reverse_has_opinion_modifier = {
								modifier = opinion_forced_consort
								who = PREVPREV
							}
						}
					}
				}
			}
		}
	}
	
	is_valid = {
		always = yes
	}
	
	on_add = {
		FROM = { character_event = { id = JD.2000 days = 5 } } # Chance to execute captives
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}
	
	on_success = {
		ROOT = {
			show_scope_change = no
			prestige = 250
		}
		FROM = {
			show_scope_change = no
			prestige = -250
		}
		FROM = {
			show_scope_change = no
			save_event_target_as = character_kidnapper
			transfer_scaled_wealth = {
				to = ROOT
				value = 3.0
			}
			any_realm_character = {
				limit = {
					is_landed = no
					OR = {
						any_spouse = { character = ROOT }
						is_friend = ROOT
						is_close_relative = ROOT
						dynasty = ROOT
						is_consort = ROOT
					}
					OR = {
						prisoner = yes
						ROOT_FROM = {
							any_realm_character = {
								reverse_has_opinion_modifier = {
									modifier = opinion_forced_consort
									who = PREVPREV
								}
							}
						}
					}
				}
				hidden_effect = {
					if = { # Concubines are released...
						limit = {
							is_consort = yes
							consort = { # ...if they are taken by someone in the same realm of your target
								same_realm = event_target:character_kidnapper
							}
						}
						consort = {
							remove_consort = PREV
						}
					}
					if = {
						limit = { # Marriages are annuled
							is_married = yes
							any_spouse = { same_realm = event_target:character_kidnapper }
						}
						remove_spouse = yes
					}
				}
				if = { # Release prisoners
					limit = {
						prisoner = yes
					}
					imprison = no
				}
				if = { # Move to the saviours court...
					limit = {
						OR = { # ...unless you are a concubine to a landed character...
							is_consort = no
							AND = {
								is_consort = yes
								spouse = {
									is_landed = no
								}
							}
						}
						OR = { # ...or the wife to a landed character
							is_married = no
							AND = {
								is_married = yes
								spouse = {
									is_landed = no
								}
							}
						}
					}
					move_character = ROOT
				}
				opinion = {
					who = ROOT
					modifier = opinion_my_saviour
					years = 100
				}
			}
			custom_tooltip = {
				text = hostages_random_imprisonment_tt
				hidden_effect = {
					random_realm_character = {
						limit = {
							NOT = {
								character = PREV
							}
							prisoner = no
							ai = yes
							is_close_relative = PREV
						}
						imprison = ROOT
					}
				}
			}
		}
	}

	on_fail = {
		ROOT = {
			show_scope_change = no
			prestige = -250
		}
		FROM = { 
			show_scope_change = no
			prestige = 250
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 3.0
			}
			prestige = -250
		}
		FROM = { 
			show_scope_change = no
			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
		
		modifier = {
			factor = 2
			FROM = {
				trait = proud
			}
		}
		
		modifier = {
			factor = 3
			FROM = {
				tier = KING
			}
		}

		modifier = {
			factor = 0.85
			ROOT = {
				relative_power = { who = FROM power = 1.2 }
			}
		}

		modifier = {
			factor = 0.85
			ROOT = {
				relative_power = { who = FROM power = 1.5 }
			}
		}

		modifier = {
			factor = 0.8
			ROOT = {
				relative_power = { who = FROM power = 2.0 }
			}
		}

		modifier = {
			factor = 0.8
			ROOT = {
				relative_power = { who = FROM power = 2.5 }
			}
		}

		modifier = {
			factor = 0.8
			ROOT = {
				relative_power = { who = FROM power = 3 }
			}
		}

		modifier = {
			factor = 0.75
			ROOT = {
				relative_power = { who = FROM power = 4 }
			}
		}

		modifier = {
			factor = 0.75
			ROOT = {
				relative_power = { who = FROM power = 5 }
			}
		}

		modifier = {
			factor = 0.75
			ROOT = {
				relative_power = { who = FROM power = 6 }
			}
		}

		modifier = {
			factor = 0.5
			ROOT = {
				relative_power = { who = FROM power = 8 }
			}
		}

		modifier = {
			factor = 0.25
			ROOT = {
				relative_power = { who = FROM power = 10 }
			}
		}

		modifier = {
			factor = 2
			ROOT = {
				distance_from_realm = { who = FROM value = 20 }
			}
		}

		modifier = {
			factor = 2
			ROOT = {
				distance_from_realm = { who = FROM value = 40 }
			}
		}
		
		modifier = {
			factor = 3
			ROOT = {
				distance_from_realm = { who = FROM value = 80 }
			}
		}
		
		modifier = {
			factor = 4
			ROOT = {
				distance_from_realm = { who = FROM value = 120 }
			}
		}
	}
	
	ai_will_do = {
		factor = 0 # Player Only
	}
}

liberate_religion = { # New6
	name = CB_NAME_LIBERATE_RELIGION
	war_name = WAR_NAME_LIBERATE_RELIGION
	sprite = 35
	truce_days = 3650
	is_permanent = yes
	is_holy_war = yes
	check_de_jure_tier = KING
	apply_short_occ_mod = no # Do not apply the 'recently_conquered' modifier to Holdings

	allowed_to_target_tributaries = no
	
	sort_priority = 4000
	
	on_add = {
		hidden_tooltip = {
			if = { 
				limit = {
					NOT = {
						ROOT = {
							any_owned_bloodline = {  
								has_bloodline_flag = bloodline_religious_liberation
								bloodline_is_active_for = PREV
							}
						}
					}
				}
				ROOT = {
					set_character_flag = used_liberate_opportunity
				}
			}
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}

	can_use = {
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		
		OR = {
			has_dlc = "Holy Fury" 
			has_dlc = "Jade Dragon"
		}
		ROOT = {
			OR = {
				any_owned_bloodline = {  
					has_bloodline_flag = bloodline_religious_liberation
					bloodline_is_active_for = PREV
				}
				NOT = {
					has_game_rule = {
						name = jade_dragon_cbs
						value = off
					}
				}
			}
			independent = yes
			OR = {
				any_owned_bloodline = {  
					has_bloodline_flag = bloodline_religious_liberation
					bloodline_is_active_for = PREV
				}
				has_character_flag = had_liberate_opportunity
			}
			NOT = {
				has_character_flag = used_liberate_opportunity
			}
			is_nomadic = no
			mercenary = no
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			NOT = { religion = FROM }
			top_liege = {
				religion = ROOT
			}
		}
	}
	
	can_use_title = {
		any_de_jure_vassal_title = {
			tier = COUNT
			holder_scope = {
				OR = {
					character = FROM
					is_liege_or_above = FROM
				}
			}
			location = {
				religion = ROOT
			}
		}
		# 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_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 = {
			NOT = { pacifist = yes }
			NOT = { same_realm = FROM }
			NOT = { religion = FROM }
			top_liege = {
				NOT = { religion = FROM }
			}
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}
	
	on_success = {
		hidden_tooltip = { 
			any_attacker = {
				limit = { NOT = { character = ROOT } }
				
				participation_scaled_piety = 100
				participation_scaled_prestige = 50
				if = {
					limit = {
						uses_decadence = yes
					}
					participation_scaled_decadence = -10
				}
				if = {
					limit = {
						has_ambition = obj_strengthen_religion
					}
					change_variable = { which = strengthen_religion value = 1 }
				}
			}
		}
		
		ROOT = {
			show_scope_change = no
			participation_scaled_piety = 500
			participation_scaled_prestige = 250
			if = {
				limit = {
					uses_decadence = yes
				}
				participation_scaled_decadence = -10
			}
			religion_authority = {
				modifier = won_holy_war
				years = 20
			}
		}
		FROM = { show_scope_change = no piety = -100 }
		FROM = { show_scope_change = no prestige = -50 }
	}

	on_success_title = {
		custom_tooltip = {
			text = religious_liberation_cb_succ_tip
			hidden_tooltip = {
				FROM = {
					if = {
						limit = {
							any_realm_title = {
								tier = COUNT
								kingdom = { title = PREVPREVPREV }
								location = {
									religion = ROOT
								}
							}
						}
						random_realm_title = {
							limit = {
								tier = COUNT
								kingdom = { title = PREVPREVPREV }
								location = {
									religion = ROOT
								}
							}
							location = {
								create_character = {
									religion = ROOT
									culture = THIS
									dynasty = random
									random_traits = yes
									female = no
									age = 20
									health = 7
									fertility = 0.7
									attributes = {
										martial = 10
										diplomacy = 10
										stewardship = 10
									}
									flag = is_religious_liberation_ruler
								}
								new_character = {
									remove_trait = cynical
									add_trait = zealous
									wealth = 500
									prestige = 500
									piety = 500
									save_event_target_as = new_ruler
									usurp_title = { target = PREVPREV type = invasion }
								}
							}
						}
					}
					if = {
						limit = {
							NOR = {
								event_target:new_ruler = { is_alive = yes }
								any_realm_title = {
									tier = COUNT
									kingdom = { title = PREVPREVPREV }
									location = {
										religion = ROOT
									}
								}
							}
						}
						random_realm_title = {
							limit = {
								tier = COUNT
								kingdom = { title = PREVPREVPREV }
							}
							location = {
								create_character = {
									religion = ROOT
									culture = THIS
									dynasty = random
									random_traits = yes
									female = no
									age = 20
									health = 7
									fertility = 0.7
									attributes = {
										martial = 10
										diplomacy = 10
										stewardship = 10
									}
									flag = is_religious_liberation_ruler
								}
								new_character = {
									remove_trait = cynical
									add_trait = zealous
									wealth = 500
									prestige = 500
									piety = 500
									save_event_target_as = new_ruler
									usurp_title = { target = PREVPREV type = invasion }
								}
							}
						}
					}
				}
				if = {
					limit = {
						has_holder = no
					}
					usurp_title = { target = event_target:new_ruler type = invasion }
				}
				else = {
					event_target:new_ruler = {
						create_title = {
							tier = KING
							landless = no
							temporary = no
							custom_created = yes
							culture = event_target:new_ruler
							holder = event_target:new_ruler
							name = "LIBERATED_KINGDOM"
							base_title = PREV
						}
					}
				}
				
				event_target:new_ruler = {
					vassalize_or_take_under_title = {
						title = PREV
						enemy = FROM
						same_religion = yes # Only vassalize rulers of my religion
						is_religious = yes
						type = holy_war
						as_if_allied_to = ROOT
					}
					set_defacto_liege = THIS
				}
				
				if = {
					limit = {
						has_holder = yes
						holder_scope = {
							OR = {
								character = FROM
								is_liege_or_above = FROM
							}
						}
					}
					destroy_landed_title = THIS
					usurp_title_only = { target = event_target:new_ruler type = invasion }
					make_primary_title = yes
					event_target:new_ruler = {
						any_demesne_title = {
							limit = {
								tier = KING
								is_primary_holder_title = no
							}
							destroy_landed_title = THIS
						}
					}
				}
				
				ROOT = {
					hidden_tooltip = {
						if = {
							limit = {
								has_ambition = obj_strengthen_religion
							}
							change_variable = { which = strengthen_religion value = 1 }
						}
					}
					make_tributary = { who = event_target:new_ruler tributary_type = permanent }
				}
			}
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
			FROM = {
				landless_pope_effect = yes
			}
		}
	}
	
	is_valid_title = {
		FROM = {
			any_realm_province = {
				de_jure_liege_or_above = PREVPREV
			}
		}
	}

	on_fail = {
		ROOT = { 
			show_scope_change = no
			piety = -125 
			prestige = -250
		}
	}
	
	on_invalidation = {
		ROOT = {
			clr_character_flag = used_liberate_opportunity
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			piety = -250
			prestige = -500
		}
		FROM = {
			show_scope_change = no
			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
			}
			participation_scaled_decadence = 20
		}
		any_attacker = {
			limit = {
				NOT = { character = ROOT }
				uses_decadence = yes
			}
			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 = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}

unjust_conquest = { # New7
	name = CB_NAME_UNJUST_COUNTY_CONQUEST
	war_name = WAR_NAME_UNJUST_COUNTY_CONQUEST
	sprite = 27
	truce_days = 1825
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	can_ask_to_join_war = no
	allowed_to_target_tributaries = no
	infamy_modifier = 2
	
	sort_priority = 690

	can_use_gui = {
		check_if_crusader_trigger = yes
		ROOT = {
			show_scope_change = no
			conditional_tooltip = { # Pagans have a much easier time using this CB in general
				trigger = { 
					religion_group = pagan_group
				}
				prestige = 100
			}
			conditional_tooltip = {
				trigger = { 
					tier = COUNT
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = 100
				scaled_wealth = { value = 3.0 min = 50 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = COUNT
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 50
				scaled_wealth = { value = 2.0 min = 50 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = COUNT
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 25
				scaled_wealth = { value = 1.0 min = 50 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = 200
				scaled_wealth = { value = 3.0 min = 100 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 100
				scaled_wealth = { value = 2.0 min = 100 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = DUKE
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 50
				scaled_wealth = { value = 1.0 min = 100 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = KING
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = 300
				scaled_wealth = { value = 3.0 min = 200 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = KING
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 200
				scaled_wealth = { value = 2.0 min = 200 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = KING
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 100
				scaled_wealth = { value = 1.0 min = 200 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = EMPEROR
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = 600
				scaled_wealth = { value = 3.0 min = 400 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = EMPEROR
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 400
				scaled_wealth = { value = 2.0 min = 400 }
			}
			conditional_tooltip = {
				trigger = { 
					tier = EMPEROR
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = 200
				scaled_wealth = { value = 1.0 min = 400 }
			}
		}
	}
	
	on_add = {
		ROOT = {
			show_scope_change = no
			if = { # Pagans have a much easier time using this CB in general
				limit = {
					religion_group = pagan_group
				}
				prestige = -100
			}
			if = {
				limit = {
					tier = COUNT
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = -100
				scaled_wealth = { value = -3.0 min = -100 }
			}
			if = {
				limit = {
					tier = COUNT
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -50
				scaled_wealth = { value = -2.0 min = -100 }
			}
			if = {
				limit = {
					tier = COUNT
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -25
				scaled_wealth = { value = -1.0 min = -100 }
			}
			
			if = {
				limit = {
					tier = DUKE
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = -200
				scaled_wealth = { value = -3.0 min = -100 }
			}
			if = {
				limit = {
					tier = DUKE
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -100
				scaled_wealth = { value = -2.0 min = -100 }
			}
			if = {
				limit = {
					tier = DUKE
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -50
				scaled_wealth = { value = -1.0 min = -100 }
			}
			
			if = {
				limit = {
					tier = KING
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = -300
				scaled_wealth = { value = -3.0 min = -100 }
			}
			if = {
				limit = {
					tier = KING
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -200
				scaled_wealth = { value = -2.0 min = -100 }
			}
			if = {
				limit = {
					tier = KING
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -100
				scaled_wealth = { value = -1.0 min = -100 }
			}
			
			if = {
				limit = {
					tier = EMPEROR
					religion = FROM
					NOT = { religion_group = pagan_group }
				}
				piety = -600
				scaled_wealth = { value = -3.0 min = -100 }
			}
			if = {
				limit = {
					tier = EMPEROR
					religion_group = FROM
					NOT = { religion = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -400
				scaled_wealth = { value = -2.0 min = -100 }
			}
			if = {
				limit = {
					tier = EMPEROR
					NOT = { religion_group = FROM }
					NOT = { religion_group = pagan_group }
				}
				piety = -200
				scaled_wealth = { value = -1.0 min = -100 }
			}
						
			if = { # Opinion hit for same religion
				limit = {
					religion = FROM
				}
				if = {
					limit = {
						controls_religion = no
						NOT = {
							religion_group = pagan_group
						}
					}
					rightful_religious_head_scope = {
						show_scope_change = no
						opinion = {
							who = ROOT
							modifier = opinion_declared_unjust_conquest
							years = 25
						}
					}
				}
				custom_tooltip = {
					text = custom_opinion_hit_tooltip
					hidden_effect = {
						generate_tooltip = no
						any_realm_character = {
							limit = {
								controls_religion = no
								religion_group = ROOT
								is_landed = yes
								NOT = {
									character = ROOT
								}
							}
							opinion = {
								who = ROOT
								modifier = opinion_declared_unjust_conquest
								years = 10
							}
						}
						FROM = {
							any_realm_character = {
								limit = {
									controls_religion = no
									religion_group = ROOT
									is_landed = yes
								}
								opinion = {
									who = ROOT
									modifier = opinion_declared_unjust_conquest
									years = 10
								}
							}
						}
					}
				}
			}
			if = { # Opinion hit for same group
				limit = {
					religion_group = FROM
					NOT = { religion = FROM }
				}
				custom_tooltip = {
					text = custom_opinion_hit_tooltip
					hidden_effect = {
						generate_tooltip = no
						any_realm_character = {
							limit = {
								religion_group = ROOT
								is_landed = yes
								NOT = {
									character = ROOT
								}
							}
							opinion = {
								who = ROOT
								modifier = opinion_declared_unjust_conquest
								years = 10
							}
						}
						FROM = {
							any_realm_character = {
								limit = {
									religion_group = ROOT
									is_landed = yes
								}
								opinion = {
									who = ROOT
									modifier = opinion_declared_unjust_conquest
									years = 10
								}
							}
						}
					}
				}
			}
			if = {
				limit = {
					NOT = { religion_group = FROM }
				}
				custom_tooltip = {
					text = custom_opinion_hit_tooltip_enemy
					hidden_effect = {
						generate_tooltip = no
						any_realm_character = {
							limit = {
								religion = FROM
								is_landed = yes
							}
							opinion = {
								who = ROOT
								modifier = opinion_declared_unjust_conquest
								years = 10
							}
						}
						FROM = {
							any_realm_character = {
								limit = {
									religion = ROOT
									is_landed = yes
								}
								opinion = {
									who = ROOT
									modifier = opinion_declared_unjust_conquest
									years = 10
								}
							}
						}
					}
				}
			}
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}
	
	can_use = {
		has_dlc = "Jade Dragon"
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			NOT = {
				has_game_rule = {
					name = unjustified_wars
					value = off
				}
			}
			NOT = { is_liege_or_above = FROM }
			mercenary = no
			NOT = { pacifist = yes }
			is_nomadic = no # Use the 'pagan_county_conquest' CB instead
			NOT = {
				religion_group = muslim # Use 'muslim_county_conquest' instead
			}
			NAND = { # Use 'pagan_county_conquest' instead
				religion_group = pagan_group
				FROM = {
					NOT = {
						religion = ROOT
					}
				}
			}
		}
		OR = {
			is_shattered_world = no
			AND = {
				is_shattered_world = yes
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = on_limited
				}
				total_years_played = 25
			}
			AND = {
				is_shattered_world = yes
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = on_long
				}
				total_years_played = 100
			}
			AND = {
				is_shattered_world = yes
				has_alternate_start_setting = {
					setting = shattered_cbs
					option = off
				}
			}
		}
	}

	can_use_title = {
		tier = count
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
				NOT = { same_realm = ROOT }
			}
		}

		NOR = {
			ROOT = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = ROOT
			}
		}
		
		location = {
			any_neighbor_province = {
				owner = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
			}
		}
	}

	is_valid_title = {
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
	}

	on_success_title = {
		if = {
			limit = {
				holder_scope = {
					tier = count
					NOT = { num_of_count_titles = 2 }
					lower_tier_than = ROOT
				}
			}

			holder_scope = {
				set_defacto_liege = ROOT
			}
		}

		if = {
			limit = {
				holder_scope = {
					OR = {
						higher_tier_than = count
						num_of_count_titles = 2
						NOT = { lower_tier_than = ROOT }
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
			any_de_jure_vassal_title = { # take all baronies under the one we're fighting for
				limit = {
					has_holder = yes
					NOT = {
						de_facto_liege = PREV
					}
					holder_scope = {
						is_liege_or_above = FROM
					}
				}

				usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
			}
		}
		
		add_pressed_claim = FROM
		
		ROOT = {
			show_scope_change = no
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}

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

	on_fail_title = {
		ROOT = {
			show_scope_change = no
			prestige = -100
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		FROM = {
			show_scope_change = no
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	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 = {
			factor = 0.7 # Prefer using CB's without on_add costs
		}
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				independent = no
				same_liege = FROM
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				higher_tier_than = DUKE
				num_of_count_titles_in_realm = 10
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				OR = {
					trait = just
					trait = content
				}
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				NOR = {
					trait = arbitrary
					trait = ambitious
				}
			}
		}
		modifier = {
			factor = 0
			ROOT = {
				has_character_flag = is_temujin
				has_landed_title = e_mongol_empire
				demesne_size = 1
			}
			FROM = {
				has_landed_title = e_china_west_governor
			}
		}
	}
}

tributary_permanent_cb = { # New8
	name = CB_NAME_PERMANENT_TRIBUTARY
	war_name = WAR_NAME_PERMANENT_TRIBUTARY
	sprite = 37
	truce_days = 365
	is_permanent = yes
	hostile_against_others = yes
	can_ask_to_join_war = no
	display_on_map = no
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	sort_priority = 810
	
	can_use_gui = {
		check_if_crusader_trigger = yes
		ROOT = {
			relative_realm_size = {
				who = FROM 
				size > 1
			}
			conditional_tooltip = {
				trigger = {
					always = no
				}
				prestige = 200
				TECH_MAJESTY = 2
			}
			conditional_tooltip = {
				trigger = {
					capital_scope = {
						OR = {
							region = world_the_north
							region = world_the_south
						}
					}
				}
				prestige = 200
				TECH_MAJESTY = 4
			}
		}
	}
	
	can_use = {
		has_dlc = "Jade Dragon"
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			NOT = {
				has_game_rule = {
					name = jade_dragon_cbs
					value = off
				}
			}
			is_nomadic = no
			independent = yes
			mercenary = no
			OR = {
				is_tributary = no
				is_tributary = {
					type = offmap
				}
			}
			NOT = { is_vassal_or_below = FROM }
			NOT = { is_liege_or_above = FROM }
			NOT = {
				rightful_religious_head_scope = {
					character = FROM
				}
			}
			NAND = {
				holy_order = yes
				religion = FROM
			}
		}
		FROM = {
			is_nomadic = no
			higher_tier_than = BARON
			NOT = {
				is_offmap_governor = yes
			}
			NAND = {
				holy_order = yes
				religion = ROOT
			}
			independent = yes
			NOT = {
				suzerain = {
					OR = {
						character = ROOT
						any_liege = {
							character = ROOT
						}
					}
				}
			}
		}
		
		# The attacker needs a border, or be at most two sea zones away from one of the target's counties
		FROM = {
			any_realm_province = {
				any_neighbor_province = {
					OR = {
						AND = {
							has_owner = yes
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
									top_liege = {
										is_tributary = {
											type = permanent
											suzerain = ROOT
										}
									}
								}
							}
						}
						AND = {
							is_land = no
							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
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		# The defender 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
				}
			}
		}
	}

	is_valid = {
		NOT = {
			ROOT = {
				rightful_religious_head_scope = {
					character = FROM 
				}
			}
		}
	}

	on_add = {
		# Chance to surrender early
		ROOT = { save_event_target_as = tribute_war_suzerain }
		FROM = {
			show_scope_change = no
			save_event_target_as = tribute_war_target
			set_character_flag = surrender_tributary_permanent_cb
			character_event = { id = JD.2500 days = 5 tooltip = surrender_tributary_tt }
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}

	on_success = {
		FROM = {
			show_scope_change = no
			save_event_target_as = target_loser
			prestige = -100
			custom_tooltip = {
				text = "REMOVE_PREVIOUS_SUZERAIN"
				hidden_tooltip = {
					any_suzerain = {
						event_target:target_loser = {
							remove_tributary = PREV
						}
					}
				}
			}
			opinion = {
				modifier = opinion_forced_tributary 
				who = ROOT
				years = 15
			}
		}

		ROOT = {
			show_scope_change = no
			prestige = 200
			make_tributary = { who = FROM tributary_type = permanent }
		}
		
		if  = {
			limit = {
				ROOT = {
					uses_decadence = yes
				}
			}
			ROOT = {
				decadence = -10
			}
		}
		if  = {
			limit = {
				ROOT = {
					is_nomadic = yes
				}
			}
			ROOT = {
				clan_title = {
					ROOT = {
						any_vassal = {
							limit = { is_nomadic = yes }
							clan_title = {
								clan_opinion = {
									who = PREVPREVPREV
									modifier = won_tributary_war
									years = 5
								}
							}
						}
					}
				}
			}
		}
		
		if = {
			limit = {
				ROOT = {
					is_tribal = yes
				}
			}
			ROOT = {
				any_vassal = {
					limit = { is_tribal = yes }
					opinion = {
						who = PREV
						modifier = won_tributary_war
						years = 5
					}
				}
			}
		}
	}

	on_fail = {
		ROOT = {
			show_scope_change = no
			prestige = -100
		}
		FROM = {
			show_scope_change = no
			prestige = 100
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}

		FROM = {
			show_scope_change = no
			prestige = 200
		}
	}
	
	on_attacker_leader_death = {
		end_war = invalid
	}

	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 = {
			factor = 0.5  # Low prio CB
		}
		modifier = { #Focus on Coronation first.
			factor = 0.1
			has_dlc = "Holy Fury"
			ROOT = {
				is_feudal = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
				NOR = {
					trait = crowned_by_priest
					trait = crowned_by_bishop
					trait = crowned_by_pope
					trait = crowned_by_myself
				}
			}
		}
	}
}

tributary_nomad_cb = { # New9
	name = CB_NAME_NOMAD_TRIBUTARY
	war_name = WAR_NAME_NOMAD_TRIBUTARY
	sprite = 37
	truce_days = 365
	is_permanent = yes
	hostile_against_others = yes
	can_ask_to_join_war = no
	display_on_map = no
	allowed_to_target_tributaries = no
	
	defender_unoccupied_warscore = yes
	
	sort_priority = 810
	
	can_use_gui = {
		check_if_crusader_trigger = yes
		ROOT = {
			prestige = 100
		}
	}
	
	can_use = {
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		ROOT = {
			is_nomadic = yes
			mercenary = no
			OR = {
				is_tributary = no
				is_tributary = {
					type = offmap
				}
			}
			NOT = { is_vassal_or_below = FROM }
			NOT = { is_liege_or_above = FROM }
			NOT = {
				rightful_religious_head_scope = {
					character = FROM
				}
			}
			NAND = {
				holy_order = yes
				religion = FROM
			}
		}
		FROM = {
			higher_tier_than = BARON
			NOT = {
				is_offmap_governor = yes
			}
			NAND = {
				holy_order = yes
				religion = ROOT
			}
			independent = yes
			NOT = {
				suzerain = {
					OR = {
						character = ROOT
						any_liege = {
							character = ROOT
						}
					}
				}
			}
		}
		
		# The attacker needs a border, or be at most two sea zones away from one of the target's counties
		FROM = {
			any_realm_province = {
				any_neighbor_province = {
					OR = {
						AND = {
							has_owner = yes
							owner = {
								OR = {
									character = ROOT
									is_liege_or_above = ROOT
									top_liege = {
										is_tributary = {
											type = nomadic
											suzerain = ROOT
										}
									}
								}
							}
						}
						AND = {
							is_land = no
							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
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		# The defender 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
				}
			}
		}
	}

	is_valid = {
		NOT = {
			ROOT = {
				rightful_religious_head_scope = {
					character = FROM 
				}
			}
		}
	}

	on_add = {
		# Chance to surrender early
		ROOT = { save_event_target_as = tribute_war_suzerain }
		FROM = {
			show_scope_change = no
			save_event_target_as = tribute_war_target
			set_character_flag = surrender_tributary_nomad_cb
			character_event = { id = JD.2500 days = 5 tooltip = surrender_tributary_tt }
		}
		hidden_tooltip = { fire_haruspicy_event_effect = yes }
	}

	on_success = {
		FROM = {
			show_scope_change = no
			transfer_scaled_wealth = {
				to = ROOT
				value = 2.0
			}
		}
	
		FROM = {
			show_scope_change = no
			save_event_target_as = target_loser
			prestige = -100
			custom_tooltip = {
				text = "REMOVE_PREVIOUS_SUZERAIN"
				hidden_tooltip = {
					any_suzerain = {
						event_target:target_loser = {
							remove_tributary = PREV
						}
					}
				}
			}
		}

		ROOT = {
			show_scope_change = no
			prestige = 200
			make_tributary = { who = FROM tributary_type = nomadic }
		}
		
		if  = {
			limit = {
				ROOT = {
					uses_decadence = yes
				}
			}
			ROOT = {
				decadence = -10
			}
		}
		if  = {
			limit = {
				ROOT = {
					is_nomadic = yes
				}
			}
			ROOT = {
				clan_title = {
					ROOT = {
						any_vassal = {
							limit = { is_nomadic = yes }
							clan_title = {
								clan_opinion = {
									who = PREVPREVPREV
									modifier = won_tributary_war
									years = 20
								}
							}
						}
					}
				}
			}
		}
		
		if = {
			limit = {
				ROOT = {
					is_tribal = yes
				}
			}
			ROOT = {
				any_vassal = {
					limit = { is_tribal = yes }
					opinion = {
						who = PREV
						modifier = won_tributary_war
						years = 20
					}
				}
			}
		}
	}

	on_fail = {
		ROOT = {
			show_scope_change = no
			prestige = -100
		}
		FROM = {
			show_scope_change = no
			prestige = 100
		}
	}

	on_reverse_demand = {
		ROOT = {
			show_scope_change = no
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}

		FROM = {
			show_scope_change = no
			prestige = 200
		}
	}
	
	on_attacker_leader_death = {
		end_war = invalid
	}

	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
		
		modifier = {
			factor = 2
			FROM = {
				trait = proud
			}
		}
		
		modifier = {
			factor = 2
			FROM = {
				trait = brave
			}
		}
		
		modifier = {
			factor = 2
			FROM = {
				trait = greedy
			}
		}
		
		modifier = {
			factor = 3
			FROM = {
				tier = KING
			}
		}

		modifier = {
			factor = 0.85
			ROOT = {
				relative_power = { who = FROM power = 1.2 }
			}
		}

		modifier = {
			factor = 0.85
			ROOT = {
				relative_power = { who = FROM power = 1.5 }
			}
		}

		modifier = {
			factor = 0.8
			ROOT = {
				relative_power = { who = FROM power = 2.0 }
			}
		}

		modifier = {
			factor = 0.8
			ROOT = {
				relative_power = { who = FROM power = 2.5 }
			}
		}

		modifier = {
			factor = 0.8
			ROOT = {
				relative_power = { who = FROM power = 3 }
			}
		}

		modifier = {
			factor = 0.75
			ROOT = {
				relative_power = { who = FROM power = 4 }
			}
		}

		modifier = {
			factor = 0.75
			ROOT = {
				relative_power = { who = FROM power = 5 }
			}
		}

		modifier = {
			factor = 0.75
			ROOT = {
				relative_power = { who = FROM power = 6 }
			}
		}

		modifier = {
			factor = 0.5
			ROOT = {
				relative_power = { who = FROM power = 8 }
			}
		}

		modifier = {
			factor = 0.25
			ROOT = {
				relative_power = { who = FROM power = 10 }
			}
		}

		modifier = {
			factor = 2
			ROOT = {
				distance_from_realm = { who = FROM value = 20 }
			}
		}

		modifier = {
			factor = 2
			ROOT = {
				distance_from_realm = { who = FROM value = 40 }
			}
		}
		
		modifier = {
			factor = 3
			ROOT = {
				distance_from_realm = { who = FROM value = 80 }
			}
		}
		
		modifier = {
			factor = 4
			ROOT = {
				distance_from_realm = { who = FROM value = 120 }
			}
		}
	}

	ai_will_do = {
		factor = 1
		
		modifier = { # In general, Nomads only want to make smaller nomads their tributaries
			factor = 0.1
			AND = {
				ROOT = {
					NOT = {
						relative_realm_size = {
							who = FROM 
							size > 1.1
						}
					}
				}
				FROM = {
					is_nomadic = yes
				}
			}
		}
		modifier = { # The Mongol Empire just wants to take land
			factor = 0
			ROOT = {
				has_landed_title = e_hakland
			}
		}
	}
}

### CHINA CBs 2.8
#offmap_submission = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#	
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#	
#	ai_will_do = { 
#	}
#}

#tributary_offmap_cb = {
#	
#	can_use = {
#	}
#
#	is_valid = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#dismantle_pretender_china_cb = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

# force_open_china_cb = {
	
#	can_use = {
#	}

#	is_valid = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#destabilization_china_cb = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}
#
#invasion_of_china_cb = {
#	
#	can_use = {
#	}
#
#	is_valid = {}
#
#	on_success = {
#	}
#
#	on_invalidation = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

truebelievers_bid_for_independence = {
	name = CB_NAME_INDEPENDENCE
	war_name = WAR_NAME_TRIBAL_INDEPENDENCE #Faction Independence
	sprite = 12
	truce_days = 3650
	major_revolt = yes
	
	attacker_can_call_allies = no
	can_ask_to_join_war = no
	
	is_independence = yes
	
	can_use = {
		FROM = { NOT = { culture = wilderness } }
		ROOT = { NOT = { culture = wilderness } }
		
		ROOT = {
			vassal_of = FROM
		}
	}

	is_valid = {
		ROOT = {
				NOT = { religion = FROM }
			OR = {
				liege = {
					character = PREV # either independent
				}
				liege = { 
					FROM = { 
						is_liege_or_above = PREV # or have shared liege
					}
				}
			}
		}
		FROM = {
			any_demesne_title = {
				NOT = { lower_tier_than = ROOT }
				temporary = no
			}
			independent = yes
			in_revolt = no
			liege_before_war = {
				in_revolt = no
				liege_before_war = {
					in_revolt = no
				}
			}
		}
	}

	on_success = {
		#FROM = { 
		#	any_vassal = { 
		#			limit = { has_character_flag = independent_joining_flag }
		#			set_defacto_liege = THIS
		#			clr_character_flag = independent_joining_flag
		#		} 
		#	}
		if = {
			limit = {
				FROM = {
					independent = no
					liege = { religion = ROOT }
				}
			}
			FROM = {
				if = {
					limit = {
						in_revolt = yes
					}
					liege_before_war = {
						#ROOT = {
						#	set_defacto_liege = PREV
						#}
						any_attacker = {
							set_defacto_liege = PREV
						}
					}
				}
				if = {
					limit = {
						in_revolt = no
					}
					liege = {
						#ROOT = {
						#	set_defacto_liege = PREV
						#}
						any_attacker = {
							set_defacto_liege = PREV
						}
					}
				}
			}
		}

		if = {
			limit = {
				FROM = {
					OR = { independent = yes
						liege = { religion = ROOT }
					}
				}
			}
			#ROOT = {
			#	set_defacto_liege = ROOT
			#}
			any_attacker = {
				set_defacto_liege = ROOT
				clr_character_flag = flag_truebelievers_revolter
			}
		}

		hidden_tooltip = {
			ROOT = {
				clr_character_flag = flag_truebelievers_revolter
				prestige = 100
				piety = 100
				religion_authority = {
					modifier = won_holy_war
					years = 20
				}
				any_demesne_title = {
					add_pressed_claim = FROM
				}
			}
			FROM = {
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}	
			}	
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
			participation_scaled_piety = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 100
				participation_scaled_piety = 100

			}
		}

		FROM = {
			any_demesne_title = { #All titles
				limit = {
					OR = {
						tier = duke
						tier = king
						tier = emperor
					}
					#is_titular = no
					NOT = {	has_law = tribal_organization_0	}
				}
				if = {
					limit = { has_law = tribal_organization_1 }
					add_law = tribal_organization_0
				}
				if = {
					limit = { has_law = tribal_organization_2 }
					add_law = tribal_organization_0
				}
				if = {
					limit = { has_law = tribal_organization_3 }
					add_law = tribal_organization_1
				}
				if = {
					limit = { has_law = tribal_organization_4 }
					add_law = tribal_organization_2
				}
			}
		}

		hidden_tooltip = {
			check_if_reconquista_finished_effect = yes
		}
	}

	on_fail = {
		if = {
			limit = {
				FROM = {
					independent = no
				}
			}
			FROM = {
				if = {
					limit = {
						in_revolt = yes
					}
					liege_before_war = {
						ROOT = {
							set_defacto_liege = PREV
						}
					}
				}
				if = {
					limit = {
						in_revolt = no
					}
					liege = {
						ROOT = {
							set_defacto_liege = PREV
						}
						any_vassal = { limit = { has_character_flag = independent_joining_flag }
							set_defacto_liege = PREV
							clr_character_flag = independent_joining_flag
						}
					}
				}
			}
		}

		if = {
			limit = {
				FROM = {
					independent = yes
				}
			}
			ROOT = {
				set_defacto_liege = FROM
			}
						any_vassal = { limit = { has_character_flag = independent_joining_flag }
							set_defacto_liege = PREV
							clr_character_flag = independent_joining_flag
						}
		}

		hidden_tooltip = {
			ROOT = {
				prestige = 100
				any_demesne_title = {
					add_pressed_claim = FROM
				}
			}
			any_attacker = {
				clr_character_flag = flag_truebelievers_revolter
			}
		}
	}

	on_reverse_demand = {
		hidden_tooltip = {
			any_attacker = {
				clr_character_flag = flag_truebelievers_revolter
			}
			ROOT = {
				religion_authority = {
					modifier = lost_holy_war
					years = 20
				}
			}
			FROM = {
				religion_authority = {
					modifier = won_holy_war
					years = 20
				}	
			}	
		}
		ROOT = {
			prisoner = FROM
		}
		any_attacker = {
			hidden_tooltip = { 
				participation_scaled_prestige = -100
				participation_scaled_piety = -100 
			}
		}
		FROM = {
			prestige = 100
			piety = 100
			hidden_tooltip = { 
				if = { 
					limit = { NOT = { has_opinion_modifier = { modifier = opinion_traitor who = ROOT } } } #Allow free revocation of a title.
					opinion = {
						who = ROOT
						modifier = opinion_traitor
					}
				}
			}
		}
	}
	on_invalidation = {
		any_attacker = {
			clr_character_flag = flag_truebelievers_revolter
		}
	} 

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

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

# Event-tied cb for Papal Holy War (that is, holy war on behalf of the Papacy)
#pepin_religious = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

# Romans rise up after their city's churches have been destroyed by mad Emperor.
#roman_christian_revolt = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#abrahamic_antihellenic_revolt = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#flower_war_cb = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#childrens_crusade = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#Warmongering + PMatriarchy = Sex Deposition cb
#Matriarchal version
#matriarchal_deposition_war = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

#Patriarchal version
#patriarchal_deposition_war = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

# Impious Saint induced Catholic Civil War
#depose_impious_pope = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

# Shepherds' Crusade
#shepherds_crusade_invasion = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}

# Northern Crusade
#northern_crusade_war = {
#	
#	can_use = {
#	}
#
#	on_success = {
#	}
#
#	on_fail = {
#	}
#
#	on_reverse_demand = {
#	}
#	
#	on_attacker_leader_death = {
#	}
#
#	attacker_ai_victory_worth = {
#	}
#	
#	attacker_ai_defeat_worth = {
#	}
#
#	defender_ai_victory_worth = {
#	}
#	
#	defender_ai_defeat_worth = {
#	}
#
#	ai_will_do = {
#	}
#}
