﻿nomadic_conquest_cb = {
	icon = county_conquest_cb
	group = conquest

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

	allowed_for_character = {
		government_has_flag = government_is_nomadic
		has_realm_law_flag = access_to_nomadic_county_conquest
	}

	allowed_against_character = {
		scope:attacker = {
			ALL_FALSE = {
				top_liege = scope:defender.top_liege
				liege = scope:defender
			}
		}
		scope:defender = {
			government_has_flag = government_is_nomadic
			has_realm_law_flag = access_to_nomadic_county_conquest
		}
	}
	target_titles = neighbor_land
	target_title_tier = county
	ignore_effect = change_title_holder
	
	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_score_mult = {
		value = viking_conquest_ai_score_value

		# AI in struggles act insularly for wars that don't have a familial or legal basis.
		multiply = struggle_wars_prioritise_struggle_targets_value
		# Tell the Romans to stop going adventuring into the steppe for no gods-damned reason.
		multiply = byzantium_conquests_ai_score_value
		multiply = muslim_invasions_prefer_nonmuslims_ai_score_value

		if = {
			limit = {
				scope:attacker = {
					domain_size >= domain_limit
				}
			}
			multiply = 0.33
		}
		
		#Declaring war on the frankokratia leader can really ruin the whole thing
		#if = {
		#	limit = {
		#		scope:defender = {
		#			any_owned_story = {
		#				story_type = frankokratia_story
		#				NOT = { has_variable = franko_war_complete }
		#			}
		#		}
		#	}
		#	multiply = 0
		#}
	}

	allowed_for_character_display_regardless = {
		# Struggle constraint - Note: This is the CB you get in FP2 opportunity, if you need to debug, test it here first.
		custom_tooltip = {
			text = struggle_involvement_cb_check_failure
			struggle_blocks_invasion_conquest_cb_trigger = 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_invalidated_desc = msg_county_conquest_war_invalidated_message

	cost = {
		prestige = {
			value = 50
			multiply = common_cb_prestige_cost_multiplier
		}
	}

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

		# Influence
		add_influence_attacker_victory_effect = yes

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = 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

		# 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 = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

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

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_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 = {
		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 = minor_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
 			}
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_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 = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = medium_prestige_loss
		}

		# 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 = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

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

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "NOMADIC_CONQUEST_WAR_NAME"
	war_name_base = "NOMADIC_CONQUEST_WAR_NAME_BASE"
	cb_name = "NOMADIC_CONQUEST_COUNTY_CB_NAME"

	interface_priority = 75

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 1.5
	
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

nomadic_conquest_duchy_cb = {
	icon = duchy_conquest_cb
	group = conquest

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

	allowed_for_character = {
		government_has_flag = government_is_nomadic
		has_realm_law_flag = access_to_nomadic_duchy_conquest
	}

	allowed_against_character = {
		scope:attacker = {
			ALL_FALSE = {
				top_liege = scope:defender.top_liege
				liege = scope:defender
			}
		}
		scope:defender = {
			government_has_flag = government_is_nomadic
		}
	}
	target_titles = neighbor_land
	target_title_tier = duchy
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	
	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_score_mult = {
		value = viking_conquest_ai_score_value
		if = {
			limit = {
				scope:attacker = {
					OR = {
						is_landed = no
						capital_county = {
							any_county_situation = {
								any_situation_sub_region = {
									sub_region_current_phase = situation_steppe_havsarsan_zud_season
									situation_sub_region_has_county = scope:attacker.capital_county
								}
							}
						}
					}
				}
			}
			multiply = 0.33
		}

		# AI in struggles act insularly for wars that don't have a familial or legal basis.
		multiply = struggle_wars_prioritise_struggle_targets_value
		# Tell the Romans to stop going adventuring into the steppe for no gods-damned reason.
		multiply = byzantium_conquests_ai_score_value
		multiply = muslim_invasions_prefer_nonmuslims_ai_score_value

		#Declaring war on the frankokratia leader can really ruin the whole thing
		#if = {
		#	limit = {
		#		scope:defender = {
		#			any_owned_story = {
		#				story_type = frankokratia_story
		#				NOT = { has_variable = franko_war_complete }
		#			}
		#		}
		#	}
		#	multiply = 0
		#}
	}

	allowed_for_character_display_regardless = {
		# Struggle constraint - Note: This is the CB you get in FP2 opportunity, if you need to debug, test it here first.
		custom_tooltip = {
			text = struggle_involvement_cb_check_failure
			struggle_blocks_invasion_conquest_cb_trigger = yes
		}
	}

	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_county_conquest_war_invalidated_message

	cost = {
		prestige = {
			value = 100
			multiply = common_cb_prestige_cost_multiplier
		}
	}

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

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_med_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		# go through the dejure hierarchy under target titles, transfer eligible vassals and sieze counties from ineligible ones
		every_in_list = {
			list = target_titles
			custom_tooltip = CONQUEST_CB_TITLE

			conquest_cb_title_transfer = {
				RELIGIOUS_WAR = no
			}
		}

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

		resolve_title_and_vassal_change = scope:change

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

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

		if = { # Warning that only counties are changing hands
			limit = {
				any_in_list = {
					list = target_titles
					tier = tier_duchy
				}
			}
			random_in_list = {
				list = target_titles
				limit = { tier = tier_duchy }
				save_scope_as = de_jure_target
			}
		}
		if = {
			limit = {
				any_in_list = {
					list = target_titles
					tier = tier_duchy
					holder = scope:defender
				}
			}
			if = {
				limit = {
					scope:defender = {
						any_held_title = {
							tier = tier_county
							NOT = { target_is_de_jure_liege_or_above = scope:de_jure_target }
						}
					}
				}
				custom_tooltip = conquest_title_not_transferred_tt
			}
			else = { custom_tooltip = conquest_title_destroyed_tt }
		}
		else = {
			if = {
				limit = {
					any_in_list = {
						list = target_titles
						tier = tier_duchy
						is_title_created = yes
					}
				}
				custom_tooltip = conquest_title_usurp_tt
			}
			else = { custom_tooltip = conquest_title_create_tt }
		}

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_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 = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker

		#EP2 accolade glory gain for doing pretty good against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.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 # not impactful as the scale are identical
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_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 = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_med_effect = yes }

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = major_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
		}

		add_truce_attacker_defeat_effect = yes

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

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "NOMADIC_CONQUEST_WAR_NAME"
	war_name_base = "NOMADIC_CONQUEST_WAR_NAME_BASE"
	cb_name = "NOMADIC_CONQUEST_DUCHY_CB_NAME"

	interface_priority = 76

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 1.5
	
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}
