de_jure_cb = {
	group = de_jure
	should_check_for_interface_availability = no # Covered by the county dejure cb

	allowed_for_character = {
		scope:attacker = {
			culture = {
				has_innovation = innovation_rightful_ownership
			}
		}
	}
	
	allowed_against_character = {
		scope:attacker = {
			has_de_jure_claim_on = scope:defender
		}
		NOT = {
			OR = {
				scope:defender = { target_is_liege_or_above = scope:attacker }
				scope:attacker = { target_is_liege_or_above = scope:defender }
			}
		}
		OR = {
			has_game_rule = default_external_vw
			scope:attacker = {
				is_independent_ruler = yes
			}
			scope:attacker.top_liege = scope:defender.top_liege
			AND = {
				has_game_rule = player_external_vw
				any_player = { this = scope:attacker }
			}
		}
	}
	target_titles = de_jure
	ai_only_against_neighbors = yes
	#target_title_tier = all
	ignore_effect = change_title_holder
	#target_de_jure_regions_above = yes

	cost = {
		piety = {
			value = 0
			if = { # Attacking your HoF is impious
				limit = {
					exists = scope:attacker.faith.religious_head
					scope:attacker.faith.religious_head = scope:defender
				}
				if = {
					limit = {
						scope:attacker.faith = {
							has_doctrine = doctrine_spiritual_head
						}
					}
					add = {
						value = massive_piety_value
						desc = CB_ATTACKER_HOF
					}
				}
				else = {
					add = {
						value = medium_piety_value
						desc = CB_ATTACKER_HOF
					}
				}
			}
			if = {
				limit = {
					scope:attacker.faith = scope:defender.faith
					scope:defender = {
						has_government = theocracy_government
					}
				}
				add = {
					value = medium_piety_value
					desc = CB_ATTACKER_THEOCRACY
				}
			}
		}
		prestige = {
			value = 0
			# scale base value based on number of counties x 100
			# target_titles list works differently here apparently, hence the every_held_title
			add = {	
				scope:defender = {
					every_held_title = {
						every_in_de_jure_hierarchy = {
							limit = { tier = tier_county }
							add = 100
						}
					}
				}
				desc = CB_CLAIM_COST_TARGET_TITLES
			}

			#Innovation Prestige Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_chronicle_writing
							has_innovation = innovation_land_grants
							has_innovation = innovation_rightful_ownership
						}
					}
				}
				multiply = {
					value = 0.7
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
							}
							OR = {
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.8
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_ATTACKER_INNOVATIONS
				}
			}

			# Bellum Justum Perk
			if = {
				limit = {
					scope:attacker = {
						has_perk = bellum_justum_perk
					}
				}
				multiply = {
					add = bellum_justum_discount_percentage
					divide = 100
					desc = CB_ATTACKER_BELLUM_JUSTUM
				}
			}

			# Dynasty Warfare Perk
			if = {
				limit = {
					scope:attacker = {
						has_dynasty = yes
						dynasty = {
							has_dynasty_perk = warfare_legacy_2
						}
					}
				}
				multiply = {
					value = warfare_legacy_2_discount
					desc = CB_ATTACKER_DYNASTY_WARFARE
				}
			}

			# Vassal contract in-realm cost reduction
			if = {
				limit = {
					scope:attacker = {
						is_independent_ruler = no
						vassal_contract_has_flag = vassal_contract_war_override
						liege = scope:defender.liege
					}
				}
				multiply = {
					value = war_declaration_rights_allowed_cost_reduction
					desc = "CB_ATTACKER_VASSAL_CONTRACT"
				}
			}
			
			if = {
				limit = {
					has_game_rule = no_cost_casus_belli_costs
				}
				multiply = {
					value = 0
					desc = CB_GAME_RULE_NO_COST
				}
			}
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	should_invalidate = {
		NOT = {
			scope:attacker = {
				has_de_jure_claim_on = scope:defender
			}
		}
	}

	on_invalidated_desc = msg_de_jure_all_war_invalidated_message
	
	on_invalidated = {
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = de_jure_cb_victory_desc_attacker
			}
			desc = de_jure_cb_victory_desc
		}
		
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		every_in_list = {
			list = target_titles
			de_jure_liege.holder = { save_scope_as = temp_de_jure_liege }
			add_hook_from_temp_de_jure_liege_to_attacker = yes
		}
		
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		# Setup and execute the changes to titles and vassals.
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
		}
		resolve_title_and_vassal_change = scope:change

		# Attacker gets Prestige Experience, Defender loses Prestige, all other participants gain Prestige based on their war contribution.
		modify_all_participants_fame_values = {
			WINNER = scope:attacker
			LOSER = scope:defender
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
		
		# truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}
		
	}
	
	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Create an 'helper' de jure CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
		}
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
				multiply = -5.0
			}
		}
		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
		# Defender neither gains nor loses any prestige.
		
		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = de_jure_cb_defeat_desc_attacker
			}
			desc = de_jure_cb_defeat_desc
		}

		
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Attacker must pay the defender war reparations.
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
		}

		# Create an 'helper' de jure CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
		}
		# Attacker loses Prestige, all other participants gain Prestige based on their war contribution (Defender gets full Prestige).
		modify_all_participants_fame_values = {
			WINNER = scope:defender
			LOSER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}


	
		# Truce
		add_truce_attacker_defeat_effect = yes
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "DEJURE_CB_WAR_NAME"
	war_name_base = "DEJURE_CB_WAR_NAME_BASE"
	cb_name = DEJURE_CB_NAME
	interface_priority = 100
	
	attacker_wargoal_percentage = 0.8
	
	max_ai_diplo_distance_to_title = 500
	min_ai_score = 100
}

individual_county_de_jure_cb = {
	group = de_jure
	
	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		scope:attacker = {
			culture = {
				has_innovation = innovation_casus_belli
			}
		}
	}

	allowed_against_character = {
		scope:attacker = {
			has_de_jure_claim_on = scope:defender
		}
		NOT = {
			OR = {
				scope:defender = { target_is_liege_or_above = scope:attacker }
				scope:attacker = { target_is_liege_or_above = scope:defender }
			}
		}
		OR = {
			has_game_rule = default_external_vw
			scope:attacker = {
				is_independent_ruler = yes
			}
			scope:attacker.top_liege = scope:defender.top_liege
			AND = {
				has_game_rule = player_external_vw
				any_player = { this = scope:attacker }
			}
		}

	}
	target_titles = all
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	ai_only_against_neighbors = yes
	
	valid_to_start = {
		scope:target = {
			tier = tier_county
			any_this_title_or_de_jure_above = {
				exists = holder
				holder = {
					OR = {
						this = scope:attacker
						target_is_liege_or_above = scope:attacker
					}
				}
			}
		}
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:attacker.liege = {
						any_character_war = {
							primary_defender = {
								save_temporary_scope_as = defender_check
							}
						}
					}
					scope:defender = scope:defender_check
				}
				desc = msg_de_jure_duchy_war_invalidated_liege_war_message
			}
			desc = msg_de_jure_county_war_invalidated_message
		}

		
	}

	on_invalidated = {
	}

	cost = {
		piety = {
			value = 0
			if = { # Attacking your HoF is impious
				limit = {
					exists = scope:attacker.faith.religious_head
					scope:attacker.faith.religious_head = scope:defender
				}
				if = {
					limit = {
						scope:attacker.faith = {
							has_doctrine = doctrine_spiritual_head
						}
					}
					add = {
						value = massive_piety_value
						desc = CB_ATTACKER_HOF
					}
				}
				else = {
					add = {
						value = medium_piety_value
						desc = CB_ATTACKER_HOF
					}
				}
			}
			if = {
				limit = {
					scope:attacker.faith = scope:defender.faith
					scope:defender = {
						has_government = theocracy_government
					}
				}
				add = {
					value = medium_piety_value
					desc = CB_ATTACKER_THEOCRACY
				}
			}
		}
		prestige = {
			# scale base value based on number of counties x 100, in this case 1
			add = {
				value = 100
				desc = CB_CLAIM_COST_TARGET_TITLES
			}

			#Innovation Prestige Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_chronicle_writing
							has_innovation = innovation_land_grants
							has_innovation = innovation_rightful_ownership
						}
					}
				}
				multiply = {
					value = 0.7
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
							}
							OR = {
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.8
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_ATTACKER_INNOVATIONS
				}
			}

			# Bellum Justum Perk
			if = {
				limit = {
					scope:attacker = {
						has_perk = bellum_justum_perk
					}
				}
				multiply = {
					add = bellum_justum_discount_percentage
					divide = 100
					desc = CB_ATTACKER_BELLUM_JUSTUM
				}
			}

			# Dynasty Warfare Perk
			if = {
				limit = {
					scope:attacker = {
						has_dynasty = yes
						dynasty = {
							has_dynasty_perk = warfare_legacy_2
						}
					}
				}
				multiply = {
					value = warfare_legacy_2_discount
					desc = CB_ATTACKER_DYNASTY_WARFARE
				}
			}

			# Vassal contract in-realm cost reduction
			if = {
				limit = {
					scope:attacker = {
						is_independent_ruler = no
						vassal_contract_has_flag = vassal_contract_war_override
						liege = scope:defender.liege
					}
				}
				multiply = {
					value = war_declaration_rights_allowed_cost_reduction
					desc = "CB_ATTACKER_VASSAL_CONTRACT"
				}
			}
			
			if = {
				limit = {
					has_game_rule = no_cost_casus_belli_costs
				}
				multiply = {
					value = 0
					desc = CB_GAME_RULE_NO_COST
				}
			}
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = individual_county_de_jure_cb_victory_desc_attacker
			}
			desc = individual_county_de_jure_cb_victory_desc
		}

		
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		every_in_list = {
			list = target_titles
			if = {
				limit = {
					exists = de_jure_liege.holder
				}
				de_jure_liege.holder = { save_scope_as = temp_de_jure_liege }
			}
			add_hook_from_temp_de_jure_liege_to_attacker = yes
		}
		
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
			title = scope:target
		}
		resolve_title_and_vassal_change = scope:change
		
		# Attacker gets Prestige Experience, Defender loses Prestige, all other participants gain Prestige based on their war contribution.
		modify_all_participants_fame_values = {
			WINNER = scope:attacker
			LOSER = scope:defender
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
		
		# truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = individual_county_de_jure_cb_white_peace_desc_defender
			}
			desc = individual_county_de_jure_cb_white_peace_desc
		}

		
	}
	
	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Create an 'helper' de jure CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
				multiply = -5.0
			}
		}
		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
		# Defender neither gains nor loses any prestige.
		
		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = individual_county_de_jure_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = individual_county_de_jure_cb_defeat_desc_attacker
			}
			desc = individual_county_de_jure_cb_defeat_desc
		}

		
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Attacker must pay the defender war reparations.
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
		}

		# Create an 'helper' de jure CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}
		# Attacker loses Prestige, all other participants gain Prestige based on their war contribution (Defender gets full Prestige).
		modify_all_participants_fame_values = {
			WINNER = scope:defender
			LOSER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
	
		# Truce
		add_truce_attacker_defeat_effect = yes
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "DEJURE_CB_WAR_SPECIFIC_NAME"
	war_name_base = "DEJURE_CB_WAR_SPECIFIC_NAME_BASE"
	cb_name = DEJURE_CB_COUNTY_NAME
	cb_name_no_target = DEJURE_CB_COUNTY_NAME_GENERIC
	interface_priority = 99 # Below the "take all" one
	
	attacker_wargoal_percentage = 0.8
	
	max_ai_diplo_distance_to_title = 500
	min_ai_score = 100
}

individual_duchy_de_jure_cb = {
	group = de_jure
	should_check_for_interface_availability = no # Covered by the county dejure cb
	
	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }
	
	allowed_for_character = {
		scope:attacker = {
			culture = {
				has_innovation = innovation_chronicle_writing
			}
		}
	}

	allowed_against_character = {
		scope:attacker = {
			has_de_jure_claim_on = scope:defender
		}
		NOT = {
			OR = {
				scope:defender = { target_is_liege_or_above = scope:attacker }
				scope:attacker = { target_is_liege_or_above = scope:defender }
			}
		}
		OR = {
			has_game_rule = default_external_vw
			scope:attacker = {
				is_independent_ruler = yes
			}
			scope:attacker.top_liege = scope:defender.top_liege
			AND = {
				has_game_rule = player_external_vw
				any_player = { this = scope:attacker }
			}
		}

	}
	target_titles = all
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	ai_only_against_neighbors = yes
	
	valid_to_start = {
		scope:target = {
			tier = tier_duchy
			any_this_title_or_de_jure_above = {
				exists = holder
				holder = {
					OR = {
						this = scope:attacker
						target_is_liege_or_above = scope:attacker
					}
				}
			}
		}
	}

	cost = {
		piety = {
			value = 0
			if = { # Attacking your HoF is impious
				limit = {
					exists = scope:attacker.faith.religious_head
					scope:attacker.faith.religious_head = scope:defender
				}
				if = {
					limit = {
						scope:attacker.faith = {
							has_doctrine = doctrine_spiritual_head
						}
					}
					add = {
						value = massive_piety_value
						desc = CB_ATTACKER_HOF
					}
				}
				else = {
					add = {
						value = medium_piety_value
						desc = CB_ATTACKER_HOF
					}
				}
			}
			if = {
				limit = {
					scope:attacker.faith = scope:defender.faith
					scope:defender = {
						has_government = theocracy_government
					}
				}
				add = {
					value = medium_piety_value
					desc = CB_ATTACKER_THEOCRACY
				}
			}
		}
		prestige = {
			value = 0
			# scale base value based on number of counties x 100
			add = {
				every_in_list = {
					list = target_titles
					every_in_de_jure_hierarchy = { # goes down, not up
						limit = { tier = tier_county }
						add = 100
					}
				}
				desc = CB_CLAIM_COST_TARGET_TITLES
			}

			#Innovation Prestige Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_chronicle_writing
							has_innovation = innovation_land_grants
							has_innovation = innovation_rightful_ownership
						}
					}
				}
				multiply = {
					value = 0.7
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
							}
							OR = {
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.8
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_ATTACKER_INNOVATIONS
				}
			}

			# Bellum Justum Perk
			if = {
				limit = {
					scope:attacker = {
						has_perk = bellum_justum_perk
					}
				}
				multiply = {
					add = bellum_justum_discount_percentage
					divide = 100
					desc = CB_ATTACKER_BELLUM_JUSTUM
				}
			}

			# Dynasty Warfare Perk
			if = {
				limit = {
					scope:attacker = {
						has_dynasty = yes
						dynasty = {
							has_dynasty_perk = warfare_legacy_2
						}
					}
				}
				multiply = {
					value = warfare_legacy_2_discount
					desc = CB_ATTACKER_DYNASTY_WARFARE
				}
			}

			# Vassal contract in-realm cost reduction
			if = {
				limit = {
					scope:attacker = {
						is_independent_ruler = no
						vassal_contract_has_flag = vassal_contract_war_override
						liege = scope:defender.liege
					}
				}
				multiply = {
					value = war_declaration_rights_allowed_cost_reduction
					desc = "CB_ATTACKER_VASSAL_CONTRACT"
				}
			}
			
			if = {
				limit = {
					has_game_rule = no_cost_casus_belli_costs
				}
				multiply = {
					value = 0
					desc = CB_GAME_RULE_NO_COST
				}
			}
		}
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:attacker.liege = {
						any_character_war = {
							primary_defender = {
								save_temporary_scope_as = defender_check
							}
						}
					}
					scope:defender = scope:defender_check
				}
				desc = msg_de_jure_duchy_war_invalidated_liege_war_message
			}
			desc = msg_de_jure_duchy_war_invalidated_message
		}
	}

	on_invalidated = {
	}

	on_declaration = {
		on_declared_war = yes

	}	

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = de_jure_cb_victory_desc_attacker
			}
			desc = de_jure_cb_victory_desc
		}

		
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		every_in_list = {
			list = target_titles
			limit = { exists = holder }
			
			holder = { save_scope_as = temp_de_jure_liege }
			add_hook_from_temp_de_jure_liege_to_attacker = yes
		}
	
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
			title = scope:target
		}
		resolve_title_and_vassal_change = scope:change

		# Attacker gets Prestige Experience, Defender loses Prestige, all other participants gain Prestige based on their war contribution.
		modify_all_participants_fame_values = {
			WINNER = scope:attacker
			LOSER = scope:defender
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
		
		# truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}

		
	}
	
	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Create an 'helper' de jure CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
				multiply = -5.0
			}
		}
		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
		# Defender neither gains nor loses any prestige.
		
		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = de_jure_cb_defeat_desc_attacker
			}
			desc = de_jure_cb_defeat_desc
		}

		
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Attacker must pay the defender war reparations.
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
		}

		# Create an 'helper' de jure CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}
		# Attacker loses Prestige, all other participants gain Prestige based on their war contribution (Defender gets full Prestige).
		modify_all_participants_fame_values = {
			WINNER = scope:defender
			LOSER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_de_jure_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 100
			LOSER_ALLY_FAME_SCALE = 100
		}
	
		# Truce
		add_truce_attacker_defeat_effect = yes
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "DEJURE_CB_WAR_SPECIFIC_NAME"
	war_name_base = "DEJURE_CB_WAR_SPECIFIC_NAME_BASE"
	cb_name = DEJURE_CB_DUCHY_NAME
	cb_name_no_target = DEJURE_CB_DUCHY_NAME_GENERIC
	interface_priority = 99 # Below the "take all" one
	
	attacker_wargoal_percentage = 0.8
	
	max_ai_diplo_distance_to_title = 500
	min_ai_score = 100
}

imperial_reconquest_cb = {
	group = de_jure

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		scope:attacker = {
			has_title = title:e_roman_empire
			OR = {
				faith.religion = faith:catholic.religion #Either Christian
				faith.religion = faith:hellenic_pagan.religion #Or Hellenic
			}
		}
	}
	
	allowed_against_character = {
	#	scope:attacker = { #Not a regular de jure cb.
	#		has_de_jure_claim_on = scope:defender
	#	}
		NOR = {
			scope:defender = { target_is_liege_or_above = scope:attacker }
			scope:attacker = { target_is_liege_or_above = scope:defender }
		}
	}
	target_titles = all
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	ai_only_against_neighbors = yes
	
	valid_to_start = {
		scope:target = {
			tier = tier_duchy
			any_in_de_jure_hierarchy = {
				tier = tier_county
				title_province = { geographical_region = custom_roman_full_borders }
			}
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = de_jure_cb_victory_desc_attacker
			}
			desc = de_jure_cb_victory_desc
		}
		
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
			title = scope:target
		}
		resolve_title_and_vassal_change = scope:change
		
		
		# truce
		add_truce_attacker_victory_effect = yes
				
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}
		
	}
	
	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}
		
		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = de_jure_cb_defeat_desc_attacker
			}
			desc = de_jure_cb_defeat_desc
		}
		
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
	
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}
	
		# Truce
		add_truce_attacker_defeat_effect = yes
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "IMPERIAL_RECONQUEST_WAR_SPECIFIC_NAME"
	war_name_base = "IMPERIAL_RECONQUEST_WAR_SPECIFIC_NAME_BASE"
	cb_name = IMPERIAL_RECONQUEST_SPECIFIC_NAME
	interface_priority = 98 #Below take all and regular dejure.

	attacker_wargoal_percentage = 0.8
	
	max_ai_diplo_distance_to_title = 500
	min_ai_score = 100
	
	on_invalidated_desc = msg_invalidate_war_title

}

dismantle_holy_pretender_cb = {
	group = de_jure
	
	allowed_for_character = {
		scope:attacker = {
			has_character_flag = flag_emperor_challenging_hre
		}
	}

	allowed_against_character = {
		NOR = {
			scope:defender = { target_is_liege_or_above = scope:attacker }
			scope:attacker = { target_is_liege_or_above = scope:defender }
			scope:attacker = { has_character_flag = flag_emperor_challenged_hre } #Only once per Emperor.
		}
	}
	target_titles = all
	target_title_tier = all
	ignore_effect = change_title_holder

	white_peace_possible = no
	on_white_peace_desc = {
		desc = WHITE_PEACE_DISABLED
	}
	
	valid_to_start = {
		scope:target = { this = title:e_hre }
	}

	on_declaration = {
		on_declared_war = yes
	}	

	on_victory_desc = {
		desc = dismantle_holy_pretender_cb_victory_desc
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		scope:defender = { save_scope_as = hre_emperor }
		scope:attacker = {
			save_scope_as = byz_emperor
			destroy_title = title:e_hre
			add_character_flag = { #No repeats.
				flag = flag_emperor_challenged_hre
			}
		}		
		hidden_effect = {
			title:e_hre = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_kingdom
					}
					set_de_jure_liege_title = scope:attacker.primary_title #Drift all the HRE vassal titles to de jure Roman Empire.
				}
			}
		}
		# truce
		add_truce_attacker_victory_effect = yes

		hidden_effect = {
			scope:attacker = {
				trigger_event = roman_restoration.0162
			}
			scope:defender = {
				trigger_event = roman_restoration.0163
			}
		}
	}

	on_defeat_desc = {
		desc = dismantle_holy_pretender_cb_defeat_desc
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		scope:defender = { save_scope_as = hre_emperor }
		scope:attacker = {
			save_scope_as = byz_emperor
			add_character_flag = { #No repeats.
				flag = flag_emperor_challenged_hre
			}
			pay_short_term_gold = {
				gold = 10
				target = scope:defender
				yearly_income = yes
			}
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			#attacker_prestige = -10
			victory = no
			title = scope:target
		}
	
		# Truce
		add_truce_attacker_defeat_effect = yes

		hidden_effect = {
			scope:attacker = {
				trigger_event = roman_restoration.0164
			}
			scope:defender = {
				trigger_event = roman_restoration.0165
			}
		}
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "DISMANTLE_EMPIRE_WAR_SPECIFIC_NAME"
	war_name_base = "DISMANTLE_EMPIRE_WAR_SPECIFIC_NAME_BASE"
	cb_name = DISMANTLE_EMPIRE_SPECIFIC_NAME
	interface_priority = 98 #Below take all and regular dejure.
	
	attacker_ticking_warscore = 0.01
	defender_ticking_warscore = 0.05
	attacker_wargoal_percentage = 0.9
	defender_ticking_warscore_delay = { months = 24 }
	
	max_ai_diplo_distance_to_title = 2000
	min_ai_score = 100
	
	on_invalidated_desc = msg_invalidate_war_title

}

dismantle_byz_pretender_cb = {
	group = de_jure
	
	allowed_for_character = {
		scope:attacker = {
			has_character_flag = flag_emperor_challenging_byz
		}
	}

	allowed_against_character = {
		NOR = {
			scope:defender = { target_is_liege_or_above = scope:attacker }
			scope:attacker = { target_is_liege_or_above = scope:defender }
			scope:attacker = { has_character_flag = flag_emperor_challenged_byz } #Only once per Emperor.
		}
	}
	target_titles = all
	target_title_tier = all
	ignore_effect = change_title_holder

	white_peace_possible = no
	on_white_peace_desc = {
		desc = WHITE_PEACE_DISABLED
	}
	
	valid_to_start = {
		scope:target = { this = title:e_byzantium }
	}

	on_declaration = {
		on_declared_war = yes
	}	

	on_victory_desc = {
		desc = dismantle_byz_pretender_cb_victory_desc
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		scope:defender = { save_scope_as = byz_emperor }
		scope:attacker = {
			save_scope_as = hre_emperor
			destroy_title = title:e_byzantium
			add_character_flag = { #No repeats.
				flag = flag_emperor_challenged_hre
			}
		}		
		hidden_effect = {
			title:e_byzantium = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_kingdom
					}
					set_de_jure_liege_title = scope:attacker.primary_title #Drift all the HRE vassal titles to de jure Roman Empire.
				}
			}
		}
		
		# truce
		add_truce_attacker_victory_effect = yes

		hidden_effect = {
			scope:attacker = {
				trigger_event = roman_restoration.0172
			}
			scope:defender = {
				trigger_event = roman_restoration.0173
			}
		}
	}

	on_defeat_desc = {
		desc = dismantle_byz_pretender_cb_defeat_desc
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		scope:defender = { save_scope_as = byz_emperor }
		scope:attacker = {
			save_scope_as = hre_emperor
			add_character_flag = { #No repeats.
				flag = flag_emperor_challenged_byz
			}
			pay_short_term_gold = {
				gold = 10
				target = scope:defender
				yearly_income = yes
			}
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			#attacker_prestige = -10
			victory = no
			title = scope:target
		}

		# Truce
		add_truce_attacker_defeat_effect = yes
	
		hidden_effect = {
			scope:attacker = {
				trigger_event = roman_restoration.0174
			}
			scope:defender = {
				trigger_event = roman_restoration.0175
			}
		}
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "DISMANTLE_EMPIRE_WAR_SPECIFIC_NAME"
	war_name_base = "DISMANTLE_EMPIRE_WAR_SPECIFIC_NAME_BASE"
	cb_name = DISMANTLE_EMPIRE_SPECIFIC_NAME
	interface_priority = 98 #Below take all and regular dejure.
	
	attacker_ticking_warscore = 0.01
	defender_ticking_warscore = 0.05
	attacker_wargoal_percentage = 0.9
	defender_ticking_warscore_delay = { months = 24 }
	
	max_ai_diplo_distance_to_title = 2000
	min_ai_score = 100
	
	on_invalidated_desc = msg_invalidate_war_title

}
