empire_invasion = {
	group = invasion

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

	allowed_for_character = {

		OR = {
		highest_held_title_tier >= tier_empire
		is_ai = no
		}

	}

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

	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
	}

	valid_to_start = {
		scope:target = {
			any_in_de_jure_hierarchy = {
				tier = tier_county
				neighboring_county_or_viking_conquest_trigger = { CHARACTER = root }
			}
		}
		# Struggle constraint
		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_invasion_war_invalidated_message

#	on_invalidated = {
#		scope:attacker = {
#			if = {
#				limit = {
#					is_alive = yes
#				}
#				remove_character_flag = used_lifetime_invasion # If the war is invalidated, you should be permitted to try again
#			}
#		}
#	}

	cost = {
		piety = {
			value = 0
			add = common_cb_impious_piety_cost
		}
		prestige = {
			add = {
				value = 1000
				desc = CB_BASE_COST
			}

			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 = invasion_war_victory_desc_attacker
			}
			desc = invasion_war_victory_desc
		}
#		triggered_desc = {
#			trigger = { scope:attacker = { is_local_player = yes } }
#			desc = invasion_war_warning_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
		}

		setup_invasion_cb = {
			titles = target_titles
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
			take_occupied = yes
		}
		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_invasion_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 10
			LOSER_ALLY_FAME_SCALE = 10
		}

		# 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 = invasion_war_white_peace_desc_defender
			}
			desc = invasion_war_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }

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

		# Truce
		add_truce_white_peace_effect = yes

		scope:attacker = {
			add_prestige = mongol_invasion_cb_prestige_white_peace
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
		}

		scope:defender = {
			stress_impact = {
				arrogant = medium_stress_impact_gain
			}
		}
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = invasion_war_white_peace_desc_defender
			}
			desc = invasion_war_white_peace_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 = 5
			}
			add_prestige = {
				value = massive_prestige_value
				multiply = -1.0
			}
		}

		setup_invasion_cb = {
			titles = target_titles
			attacker = scope:attacker
			defender = scope:defender
			claimant = scope:claimant
			victory = no
		}

		# Attacker loses Prestige, all other war participants gain Prestige (Defender gains full prestige, all allies on both sides gain based on war contribution).
		modify_all_participants_fame_values = {
			WINNER = scope:defender
			LOSER = scope:attacker
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_claim_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = scale_10_war_defender_win
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 10
			LOSER_ALLY_FAME_SCALE = 10
		}

		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 = "INVASION_WAR_NAME"
	war_name_base = "INVASION_WAR_NAME_BASE"
	cb_name = "EMPIRE_INVASION_CB_NAME"

	interface_priority = 100

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8
}
