﻿county_struggle_cb = {
	group = struggle
	icon = struggle
	combine_into_one = yes
	interface_priority = 111
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = {
		scope:attacker = {
			any_character_struggle = {
				involvement = involved
				has_struggle_phase_parameter = struggle_clash_restricted_to_single_county
			}
		}
	}

	allowed_against_character = {
		OR = {
			# Keep the CB if your house completed the Hostility ending
			AND = {
				exists = scope:attacker.house
				scope:attacker.house = {
					OR ={
						has_house_modifier = fp2_struggle_hostility_house_combined_modifier
						has_house_modifier = fp2_struggle_hostility_house_faith_modifier
						has_house_modifier = fp2_struggle_hostility_house_culture_modifier
					}
				}
			}
			# During the Struggle
			scope:attacker = {
				any_character_struggle = {
					involvement = involved
					is_secondary_character_involvement_either_trigger = { CHAR = scope:defender }
				}
			}
		}

		NOT = {
			scope:attacker = {
				any_liege_or_above = { this = scope:defender }
			}
		}
	}
	
	target_titles = all
	target_title_tier = county
	ignore_effect = change_title_holder
	defender_ticking_warscore = 0.125
	attacker_ticking_warscore = 0.125

	defender_score_from_battles_scale = 150
	attacker_score_from_battles_scale = 150

	ai_only_against_neighbors = yes
	#ai_can_target_all_titles = { always = yes }
	ai_score_mult = { value = struggle_conquest_ai_score_value }

	valid_to_start = {
		scope:target = {
			valid_struggle_cb_target_trigger = { CHARACTER = scope:attacker }
		}
	}

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

	on_invalidated_desc = msg_county_conquest_war_invalidated_message
	on_invalidated = {
	}

	cost = {
		# Charge piety against same-faith opponents.
		piety = {
			value = 0
			if = {
				limit = {
					scope:defender.faith = scope:attacker.faith
				}
				# Struggle multipliers.
				value = struggle_cb_phase_modifier_cost
			}
			# Standard multipliers.
			multiply = common_cb_piety_cost_multiplier_sans_struggles
		}
		# & prestige against diff-faith opponents.
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:defender.faith = scope:attacker.faith }
				}
				# Struggle multipliers.
				value = struggle_cb_phase_modifier_cost
			}
			# Standard multipliers.
			multiply = common_cb_prestige_cost_multiplier_sans_struggles
		}
	}

	on_declaration = { on_declared_war = yes }

	on_victory_desc = {
		first_valid = {
			# We play a different version for OPMs...
			triggered_desc = {
				trigger = {
					struggle_conquest_cb_target_is_ocm_trigger = yes
					scope:attacker = { is_local_player = yes }
				}
				desc = county_struggle_cb_victory_desc_opm_attacker
			}
			triggered_desc = {
				trigger = { struggle_conquest_cb_target_is_ocm_trigger = yes }
				desc = county_struggle_cb_victory_desc_opm
			}
			# ... compared to just regular quarrels.
			triggered_desc = {
				trigger = {
					scope:attacker = { is_local_player = yes }
				}
				desc = county_struggle_cb_victory_desc_attacker
			}
			desc = county_struggle_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
			custom_tooltip = CONQUEST_CB_TITLE

			struggle_cb_title_transfer = yes
		}
		every_in_list = {
			list = vassals_taken
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
		}
		every_in_list = {
			list = titles_taken
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
				take_baronies = no
			}
		}
		resolve_title_and_vassal_change = scope:change
		# Prestige Progress for the Attacker
		scope:attacker = {
			add_prestige_experience = {
				value = 0
				every_in_list = {
					list = target_titles
					add = minor_prestige_value
				}
			}
		}
		# 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 = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		#Modded New & Inverted
		if = {
			limit = {
				NOT = { scope:defender.faith = scope:attacker.faith }
			}			
			scope:attacker.faith = {
				change_fervor = {
					value = 3
					desc = fervor_gain_attacker_religious_war
				}
			}
			scope:defender.faith = {
				change_fervor = {
					value = -1
					desc = fervor_loss_defender_religious_war
				}
			}		
		}
		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:defender = { is_local_player = yes }
				}
				desc = county_struggle_cb_white_peace_desc_defender
			}
			desc = county_struggle_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}
		# 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 # Not important as the scales are identical
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		scope:defender = {
			stress_impact = { arrogant = medium_stress_impact_gain }
		}
		#Modded New
		if = {
			limit = {
				NOT = { scope:defender.faith = scope:attacker.faith }
			}			
			scope:attacker.faith = {
				change_fervor = {
					value = -1
					desc = fervor_gain_attacker_religious_war
				}
			}
			scope:defender.faith = {
				change_fervor = {
					value = 1
					desc = fervor_loss_defender_religious_war
				}
			}		
		}		
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:defender = { is_local_player = yes }
				}
				desc = county_struggle_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_struggle_cb_defeat_desc_attacker
			}
			desc = county_struggle_cb_defeat_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = {
				value = medium_prestige_value
				multiply = -1.0
			}
		}
		# Prestige for Defender
		scope:defender = {
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}
		# 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:defender
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		#Modded New & Inverted
		if = {
			limit = {
				NOT = { scope:defender.faith = scope:attacker.faith }
			}			
			scope:attacker.faith = {
				change_fervor = {
					value = -1
					desc = fervor_gain_attacker_religious_war
				}
			}
			scope:defender.faith = {
				change_fervor = {
					value = 3
					desc = fervor_loss_defender_religious_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 = "STRUGGLE_WAR_NAME"
	war_name_base = "STRUGGLE_WAR_NAME_BASE"
	cb_name = "STRUGGLE_COUNTY_CB_NAME"

	interface_priority = 79

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8
}
