﻿county_conquest_cb = {
	group = conquest

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

	allowed_for_character = {
		can_use_conquest_cbs_trigger = yes
	}
	
	allowed_for_character_display_regardless = {
		trigger_if = {
			limit = { NOT = { has_game_rule = conquest_war_cb_default } }
			NOT = { has_character_modifier = mgr_recent_conquest_war }
		}
	}

	allowed_against_character = {
		scope:attacker = {
			ALL_FALSE = {
				top_liege = scope:defender.top_liege
				liege = scope:defender
			}
		}
	}
	target_titles = all
	target_title_tier = county
	ignore_effect = change_title_holder

	ai_can_target_all_titles = {
		can_use_viking_invasion_cbs_trigger = yes
	}
	ai_score_mult = {
		value = viking_conquest_ai_score_value
	}

	valid_to_start = {
		scope:target = {
			neighboring_county_or_viking_conquest_trigger = { CHARACTER = root }
		}
	}

	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 = msg_county_conquest_war_invalidated_message
	on_invalidated = {
	}

	cost = {
		piety = {
			value = 0
			if = {
				limit = {
					scope:defender.faith = scope:attacker.faith
				}
				add = {
					value = medium_piety_value
					desc = CB_SAME_FAITH_COST
				}
			}
			if = {
				limit = {
					scope:attacker = { has_government = tribal_government }
				}
				multiply = {
					value = 0.5
					desc = CB_TRIBAL_COST
				}
			}

			#Innovation Piety Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_reconquista
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_RECONQUISTA_COST
				}
			}

			# 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
				}
			}
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:defender.faith = scope:attacker.faith }
				}
				add = {
					value = medium_prestige_value
					desc = CB_COST_DIFFERENT_FAITH
				}
			}
			if = {
				limit = {
					scope:attacker = { has_government = tribal_government }
				}
				multiply = {
					value = 0.5
					desc = CB_TRIBAL_COST
				}
			}

			#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
		scope:attacker = { conquest_war_cb_cooldown_effect = yes }
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = county_conquest_cb_victory_desc_attacker
			}
			desc = county_conquest_cb_victory_desc
		}
	}

	on_victory = {
		create_title_and_vassal_change = change
		scope:change = {
			set_title_and_vassal_change_type = conquest
			set_add_claim_on_loss = yes
		}

		#As this is just a county conquest, simply grab the designated county.
		every_in_list = {
			list = target_titles
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold = {
				gold = 2
				target = scope:defender
				yearly_income = yes
			}
			add_prestige = {
				value = medium_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige = medium_prestige_value
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CONQUEST_WAR_NAME"
	war_name_base = "CONQUEST_WAR_NAME_BASE"
	cb_name = "CONQUEST_COUNTY_CB_NAME"

	interface_priority = 79

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	min_ai_score = 100
}

duchy_conquest_cb = {
	group = conquest

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

	allowed_for_character = {
		can_use_conquest_cbs_trigger = yes
	}

	allowed_for_character_display_regardless = {
		prestige_level >= 3
		trigger_if = {
			limit = { NOT = { has_game_rule = conquest_war_cb_default } }
			NOT = { has_character_modifier = mgr_recent_conquest_war }
		}
	}

	allowed_against_character = {
		scope:attacker = {
			ALL_FALSE = {
				top_liege = scope:defender.top_liege
				liege = scope:defender
			}
		}
	}
	target_titles = all
	target_title_tier = duchy
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder

	ai_can_target_all_titles = {
		can_use_viking_invasion_cbs_trigger = yes
	}
	ai_score_mult = {
		value = viking_conquest_ai_score_value
	}

	valid_to_start = {
		scope:target = {
			any_in_de_jure_hierarchy = {
				tier = tier_county
				neighboring_county_or_viking_conquest_trigger = { CHARACTER = root }
			}
		}
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						target_is_same_character_or_above = scope:defender
					}
				}
			}
		}
	}

	on_invalidated_desc = msg_religious_war_invalidation_region_message
	
	on_invalidated = {
	}

	cost = {
		piety = {
			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
				}
			}
			value = 0
			if = {
				limit = {
					scope:defender.faith = scope:attacker.faith
				}
				add = {
					value = massive_piety_value
					desc = CB_SAME_FAITH_COST
				}
			}
			if = {
				limit = {
					scope:attacker = { has_government = tribal_government }
				}
				multiply = {
					value = 0.5
					desc = CB_TRIBAL_COST
				}
			}

			#Innovation Piety Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_reconquista
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_RECONQUISTA_COST
				}
			}

			# 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
				}
			}
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:defender.faith = scope:attacker.faith }
				}
				add = {
					value = massive_prestige_value
					desc = CB_COST_DIFFERENT_FAITH
				}
			}
			if = {
				limit = {
					scope:attacker = { has_government = tribal_government }
				}
				multiply = {
					value = 0.5
					desc = CB_TRIBAL_COST
				}
			}

			#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
		scope:attacker = { conquest_war_cb_cooldown_effect = yes }
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = county_conquest_cb_victory_desc_attacker
			}
			desc = county_conquest_cb_victory_desc
		}
	}

	on_victory = {
		create_title_and_vassal_change = change
		scope:change = {
			set_title_and_vassal_change_type = conquest
			set_add_claim_on_loss = yes
		}

		# go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
		# take the holder as vassal otherwise and don't go deeper
		every_in_list = {
			list = target_titles
			custom_tooltip = CONQUEST_CB_TITLE
			every_in_de_jure_hierarchy = {
				continue = {
					OR = {
						NOT = {
							exists = holder
						}
						NOT = {
							holder = {
								target_is_liege_or_above = scope:defender
							}
						}
						AND = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith <= scope:defender.faith
								}
							}
							holder = {
								OR = {
									this = scope:defender
									target_is_liege_or_above = scope:defender
								}
							}
						}
					}
					tier > tier_county
				}
				limit = {
					tier = tier_county
					exists = holder
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}

				if = {
					limit = {
						OR = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith >= scope:defender.faith
								}
							}
							holder.primary_title.tier >= scope:attacker.primary_title.tier
						}
					}
					add_to_temporary_list = titles_taken
				}
				else = {
					holder = {
						add_to_temporary_list = vassals_taken
					}
				}
			}
		}

		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
				take_baronies = yes
			}
		}

		every_in_list = {
			list = vassals_taken
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = medium_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige = major_prestige_value
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CONQUEST_WAR_NAME"
	war_name_base = "CONQUEST_WAR_NAME_BASE"
	cb_name = "CONQUEST_DUCHY_CB_NAME"

	interface_priority = 79

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	min_ai_score = 100
}

ducal_conquest_cb = {
	group = conquest

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

	allowed_for_character = {
		has_perk = ducal_conquest_perk
		can_use_conquest_cbs_trigger = no
	}
	
	allowed_for_character_display_regardless = {
		trigger_if = {
			limit = { NOT = { has_game_rule = conquest_war_cb_default } }
			NOT = { has_character_modifier = mgr_recent_conquest_war }
		}
	}

	allowed_against_character = {
		#scope:attacker = {
		#	ALL_FALSE = {
		#		top_liege = scope:defender.top_liege
		#		liege = scope:defender
		#	}
		#}
	}
	target_titles = neighbor_land
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder

	valid_to_start = {
		scope:target = {
			tier = tier_county
		}
		scope:attacker = { # The attacker has a County in an uncreated Duchy
			any_sub_realm_title = {
				tier = tier_county
				duchy = {
					is_title_created = no
					any_in_de_jure_hierarchy = {
						this = scope:target
					}
				}
			}
		}
	}

	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 = msg_county_conquest_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 = {
			value = 0
			if = {
				limit = {
					scope:attacker.primary_title.tier <= tier_county
				}
				add = {
					value = major_prestige_value
					desc = CB_BASE_COST
				}
			}
			else = {
				add = {
					value = massive_prestige_value
					desc = CB_BASE_COST
				}
			}

			#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
		scope:attacker = { conquest_war_cb_cooldown_effect = yes }

	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = ducal_conquest_cb_victory_desc_attacker
			}
			desc = ducal_conquest_cb_victory_desc
		}
	}

	on_victory = {
		create_title_and_vassal_change = change
		scope:change = {
			set_title_and_vassal_change_type = conquest
			set_add_claim_on_loss = yes
		}

		# go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
		# take the holder as vassal otherwise and don't go deeper
		every_in_list = {
			list = target_titles
			custom_tooltip = CONQUEST_CB_TITLE
			every_in_de_jure_hierarchy = {
				continue = {
					OR = {
						NOT = {
							exists = holder
						}
						NOT = {
							holder = {
								target_is_liege_or_above = scope:defender
							}
						}
						AND = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith <= scope:defender.faith
								}
							}
							holder = {
								OR = {
									this = scope:defender
									target_is_liege_or_above = scope:defender
								}
							}
						}
					}
					tier > tier_county
				}
				limit = {
					tier = tier_county
					exists = holder
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}

				if = {
					limit = {
						OR = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith >= scope:defender.faith
								}
							}
							holder.primary_title.tier >= scope:attacker.primary_title.tier
						}
					}
					add_to_temporary_list = titles_taken
				}
				else = {
					holder = {
						add_to_temporary_list = vassals_taken
					}
				}
			}
		}

		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
				take_baronies = yes
			}
		}

		every_in_list = {
			list = vassals_taken
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = ducal_conquest_cb_white_peace_desc_defender
			}
			desc = ducal_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = ducal_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = ducal_conquest_cb_defeat_desc_attacker
			}
			desc = ducal_conquest_cb_defeat_desc
		}
	}

	on_defeat = {

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold = {
				gold = 2
				target = scope:defender
				yearly_income = yes
			}
			add_prestige = {
				value = medium_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige = medium_prestige_value
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "DUCAL_CONQUEST_WAR_NAME"
	war_name_base = "DUCAL_CONQUEST_WAR_NAME_BASE"
	cb_name = "DUCAL_CONQUEST_CB_NAME"

	interface_priority = 79

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_ai_diplo_distance_to_title = 1500
	min_ai_score = 100
}

ireland_laudabiliter_conquest_cb = {
	group = conquest

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

	allowed_for_character = {
		exists = scope:attacker.house
		scope:attacker.house = { #Laudabiliter modifier allows conquest on Ireland region.
			has_house_modifier = ireland_laudabiliter_modifier
		}
	}

	allowed_for_character_display_regardless = {
		trigger_if = {
			limit = { NOT = { has_game_rule = conquest_war_cb_default } }
			NOT = { has_character_modifier = mgr_recent_conquest_war }
		}
	}

	allowed_against_character = {
		scope:attacker = {
			ALL_FALSE = {
				top_liege = scope:defender.top_liege
				liege = 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_county
			scope:attacker.house = { #
				has_house_modifier = ireland_laudabiliter_modifier
			}
			title_province = { geographical_region = custom_roman_hibernia }
		}
	}

	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 = {	
	}

	cost = {
		piety = {
			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
				}
			}
			value = 0
			if = {
				limit = {
					scope:defender.faith = scope:attacker.faith
				}
				add = {
					value = medium_piety_value
					desc = CB_SAME_FAITH_COST
				}
			}
			if = {
				limit = {
					scope:attacker = { has_government = tribal_government }
				}
				multiply = {
					value = 0.5
					desc = CB_TRIBAL_COST
				}
			}

			#Innovation Piety Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_reconquista
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_RECONQUISTA_COST
				}
			}

			# 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
				}
			}
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:defender.faith = scope:attacker.faith }
				}
				add = {
					value = medium_prestige_value
					desc = CB_COST_DIFFERENT_FAITH
				}
			}
			if = {
				limit = {
					scope:attacker = { has_government = tribal_government }
				}
				multiply = {
					value = 0.5
					desc = CB_TRIBAL_COST
				}
			}

			#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 = 0.9
			}

			# 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
		scope:attacker = { conquest_war_cb_cooldown_effect = yes }
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = ireland_laudabiliter_conquest_cb_victory_desc_attacker
			}
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = ireland_laudabiliter_conquest_cb_victory_desc_defender
			}
			desc = ireland_laudabiliter_conquest_cb_victory_desc
		}
	}

	on_victory = {
		create_title_and_vassal_change = change
		scope:change = {
			set_title_and_vassal_change_type = conquest
			set_add_claim_on_loss = yes
		}

		# go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equaly or less tolerated than the defender's),
		# take the holder as vassal otherwise and don't go deeper
		every_in_list = {
			list = target_titles
			custom_tooltip = CONQUEST_CB_TITLE
			every_in_de_jure_hierarchy = {
				continue = {
					OR = {
						NOT = {
							exists = holder
						}
						NOT = {
							holder = {
								target_is_liege_or_above = scope:defender
							}
						}
						AND = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith <= scope:defender.faith
								}
							}
							holder = {
								OR = {
									this = scope:defender
									target_is_liege_or_above = scope:defender
								}
							}
						}
					}
					tier > tier_county
				}
				limit = {
					tier = tier_county
					exists = holder
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}

				if = {
					limit = {
						OR = {
							scope:attacker.faith = {
								faith_hostility_level_comparison = {
									prev.holder.faith >= scope:defender.faith
								}
							}
							holder.primary_title.tier >= scope:attacker.primary_title.tier
						}
					}
					add_to_temporary_list = titles_taken
				}
				else = {
					holder = {
						add_to_temporary_list = vassals_taken
					}
				}
			}
		}

		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
				take_baronies = yes
			}
		}

		every_in_list = {
			list = vassals_taken
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Truce
		add_truce_attacker_victory_effect = yes

	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = ireland_laudabiliter_conquest_cb_white_peace_desc_defender
			}
			desc = ireland_laudabiliter_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = ireland_laudabiliter_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = ireland_laudabiliter_conquest_cb_defeat_desc_attacker
			}
			desc = ireland_laudabiliter_conquest_cb_defeat_desc
		}
	}

	on_defeat = {
		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold = {
				gold = 2
				target = scope:defender
				yearly_income = yes
			}
			add_prestige = {
				value = medium_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige = medium_prestige_value
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes
	}

	on_invalidated_desc = msg_county_conquest_war_invalidated_message

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "LAUDABILITER_CONQUEST_WAR_NAME"
	war_name_base = "LAUDABILITER_CONQUEST_WAR_NAME_BASE"
	cb_name = "LAUDABILITER_CONQUEST_CB_NAME"

	interface_priority = 80

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_ai_diplo_distance_to_title = 500
	min_ai_score = 100
}
