county_conquest_cb = {
	group = conquest

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

	allowed_for_character = {
		can_use_conquest_cbs_trigger = yes
	}

	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
			
			
			add = {
				every_in_list = {
					list = target_titles
					limit = { tier = tier_county }
					if = {
						limit = {
							scope:defender.faith = scope:attacker.faith
						}
						add = {
							value = medium_piety_value
							desc = CB_SAME_FAITH_COST
						}
					}
				}

				desc = "CB_CLAIM_COST_TARGET_TITLES"
			}
			
			
			
			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
			
			
			
			add = {
				every_in_list = {
					list = target_titles
					limit = { tier = tier_county }
					if = {
						limit = {
							NOT = { scope:defender.faith = scope:attacker.faith }
						}
						add = {
							value = medium_prestige_value
							desc = CB_COST_DIFFERENT_FAITH
						}
					}
				}

				desc = "CB_CLAIM_COST_TARGET_TITLES"
			}
			
			
			
			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
	}

	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 = {
			type = conquest
			save_scope_as = change
			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
}
