﻿##########
# Special 'claim' CB used by William the Bastard to invade England in 1066.
# If victorious, Harold personally seizes all land in Northern England (ostensibly to distribute to good Norwegian vassals). Otherwise should be mostly-identical to a Claim CB.
##########

#norman_conquest_cb = {
#	icon = invasion
#	group = event
#	mutually_exclusive_titles = {
#		always = yes
#	}
#
#	allow_hostages = no
#	allowed_for_character = {}
#	allowed_against_character = {
#		faith.religion = scope:attacker.faith.religion
#	}
#
#	is_allowed_claim_title = {
#		scope:claimant =  {
#			NOT = { has_trait = incapable }
#			is_imprisoned = no
#			OR = {
#				this = scope:attacker
#				AND = {
#					religion = scope:attacker.religion
#					dynasty = scope:attacker.dynasty
#				}
#			}
#		}
#	}
#
#	cost = {}
#	target_titles = claim
#	
#	on_declaration = {
#		on_declared_war = 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 = { set_global_variable = norman_conquest_cb_concluded }
#	on_invalidated_desc = msg_claim_war_invalidated_message
#
#	on_victory_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { scope:defender = { is_local_player = yes } }
#				desc = norman_conquest_cb_victory_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = norman_conquest_cb_victory_desc_attacker
#			}
#			desc = norman_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_high_effect = yes }
#
#		# Set land acquisition type to conquest.
#		create_title_and_vassal_change = {
#			type = conquest
#			save_scope_as = change
#			add_claim_on_loss = yes
#		}
#
#		# Transfer landed titles to the attacker.
#		setup_claim_cb = {
#			titles = target_titles
#			attacker = scope:attacker
#			defender = scope:defender
#			claimant = scope:claimant
#			change = scope:change
#		}
#
#		# EP3 Laamp possibility warning
#		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }
#
#		#Hereward the Wake departs for the Fenlands
#		character:90028 = { save_scope_as = hereward }
#
#		if = {
#			limit = {
#				exists = scope:hereward
#			}
#
#			scope:hereward = {
#				trigger_event = {
#					id = ep3_laamps.6000
#					days = { 1 2 }
#				}
#			}
#		}
#
#		#Eadgar becomes a LAAMP
#		character:112 = { save_scope_as = eadgar }
#
#		if = {
#			limit = {
#				exists = scope:eadgar
#			}
#
#			scope:eadgar = {
#				trigger_event = {
#					id = ep3_laamps.7000
#					days = { 1 2 }
#				}
#			}
#		}
#	
#		every_in_list = {
#			list = target_titles
#
#			#Remove elective succession law from k_england.
#			clear_title_laws = yes
#
#			# Personally seize all duchy titles in Southern England AND duchy titles personally held by the King of England.
#			every_in_de_jure_hierarchy = {
#				limit = {
#					tier = tier_duchy
#					special_invasion_cb_seize_land_in_region_trigger = {
#						TARGET_REGION = custom_southern_england
#						TARGET_KINGDOM = title:k_england
#					}
#				}
#				if = {
#					limit = {
#						holder ?= {
#							top_liege ?= scope:defender
#
#							# Vassal players in England get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#							NAND = {
#								this != top_liege
#								is_ai = no
#							}
#						}
#					}
#					custom_description = {
#						text = custom_seize_title_and_below_de_jure
#						subject = scope:attacker
#						object = this
#						change_title_holder = {
#							holder = scope:attacker
#							change = scope:change
#							take_baronies = yes
#						}
#					}
#
#					# Grab the counties that go with the duchies, too.
#					every_in_de_jure_hierarchy = {
#						limit = {
#							tier = tier_county
#							holder ?= {
#								top_liege = scope:defender
#
#								# Vassal players in England get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#								NAND = {
#									this != top_liege
#									is_ai = no
#								}
#							}
#						}
#						hidden_effect = {
#							change_title_holder = {
#								holder = scope:attacker
#								change = scope:change
#								take_baronies = yes
#							}
#						}
#						add_to_temporary_list = county_titles_under_transfer
#					}
#				}
#			}
#			# Personally seize every county title in the Southern England AND county titles personally held by the King of England.
#			every_in_de_jure_hierarchy = {
#				limit = {
#					tier = tier_county
#					special_invasion_cb_seize_land_in_region_trigger = {
#						TARGET_REGION = custom_southern_england
#						TARGET_KINGDOM = title:k_england
#					}
#					NOT = { is_in_list = county_titles_under_transfer }
#				}
#				if = {
#					limit = {
#						holder ?= {
#							top_liege ?= scope:defender
#
#							# Vassal players in England get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#							NAND = {
#								this != top_liege
#								is_ai = no
#							}
#						}
#					}
#					custom_description = {
#						text = custom_seize_title
#						subject = scope:attacker
#						object = this
#						change_title_holder = {
#							holder = scope:attacker
#							change = scope:change
#							take_baronies = yes
#						}
#					}
#				}
#			}
#		}
#
#		resolve_title_and_vassal_change = scope:change
#		
#		scope:attacker = { 
#			give_nickname = nick_the_conqueror 
#			if = {
#				limit = { exists = global_var:started_norman_yoke_achievement }
#				add_achievement_global_variable_effect = {
#					VARIABLE = achievement_norman_yoke_war_flag
#					VALUE = yes
#				}
#			}
#			if = {
#				limit = {
#					is_ai = yes
#					has_title = title:c_middlesex
#				}
#				set_realm_capital = title:c_middlesex
#			}
#		}
#
#		modify_all_participants_fame_values = {
#			WINNER = scope:attacker
#			LOSER = scope:defender
#			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_claim_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 }
#
#		set_global_variable = norman_conquest_cb_concluded
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_defeat_effects = yes
#	}
#
#	on_white_peace_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { scope:defender = { is_local_player = yes } }
#				desc = norman_conquest_cb_white_peace_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = norman_conquest_cb_white_peace_desc_attacker
#			}
#			desc = norman_conquest_cb_white_peace_desc
#		}
#	}
#	
#	on_white_peace = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#
#		#EP2 accolade glory gain for doing ok against higher ranked enemy
#		scope:defender = { accolade_defender_war_end_glory_gain_med_effect = yes }
#		
#		# press claims
#		every_in_list = {
#			list = target_titles
#			if = {
#				limit = { scope:attacker = { has_weak_claim_on = prev } }
#				scope:attacker = {
#					make_claim_strong = prev
#				}
#			}
#		}
#		
#		setup_claim_cb = {
#			titles = target_titles
#			attacker = scope:attacker
#			defender = scope:defender
#			claimant = scope:claimant
#			victory = no
#		}
#
#		# Small prestige penalty to the attacker for failing to win their own war.
#		scope:attacker = {
#			add_prestige = {
#				value = scope:cb_prestige_factor # Set by 'setup_claim_cb'
#				multiply = -5
#			}
#			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
#			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_claim_cb'
#			IS_RELIGIOUS_WAR = no
#			WINNER_ALLY_FAME_SCALE = 10
#			LOSER_ALLY_FAME_SCALE = 10
#		}
#
#		if = {
#			limit = {
#				scope:claimant != scope:attacker
#				scope:claimant = {
#					can_add_hook = {
#						type = favor_hook
#						target = scope:attacker
#					}
#				}
#			}
#			scope:claimant = {
#				add_hook = {
#					target = scope:attacker
#					type = favor_hook
#				}
#			}
#		}
#
#		scope:defender = {
#			stress_impact = {
#				arrogant = medium_stress_impact_gain
#			}
#		}
#
#		# Truce
#		add_truce_white_peace_effect = yes
#
#		set_global_variable = norman_conquest_cb_concluded
#
#		# 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 = norman_conquest_cb_defeat_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = norman_conquest_cb_defeat_desc_attacker
#			}
#			desc = norman_conquest_cb_defeat_desc
#		}
#	}
#	
#	on_defeat = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#		
#		# Legitimacy
#		add_legitimacy_attacker_defeat_effect = yes
#
#		scope:defender = {
#			mandala_peacemaker_perk_serenity_effect = yes
#			#EP2 accolade glory gain for winning against higher ranked enemy
#			accolade_defender_war_end_glory_gain_high_effect = yes 
#		}
#	
#		# lose claims
#		if = {
#			limit = { scope:attacker = scope:claimant }
#			every_in_list = {
#				list = target_titles
#				scope:claimant = {
#					remove_claim = prev
#				}
#			}
#		}
#
#		if = {
#			limit = {
#				scope:claimant != scope:attacker
#				scope:claimant = {
#					can_add_hook = {
#						type = favor_hook
#						target = scope:attacker
#					}
#				}
#			}
#			scope:claimant = {
#				add_hook = {
#					target = scope:attacker
#					type = favor_hook
#				}
#			}
#		}
#		
#		# Award the appropriate amount of prestige to all participants in the war.
#		setup_claim_cb = {
#			titles = target_titles
#			attacker = scope:attacker
#			defender = scope:defender
#			claimant = scope:claimant
#			victory = no
#		}
#		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
#		}
#
#		# Truce
#		add_truce_attacker_defeat_effect = yes
#		
#		scope:attacker = {
#			save_temporary_scope_as = loser
#		}
#		on_lost_aggression_war_discontent_loss = yes
#
#		set_global_variable = norman_conquest_cb_concluded
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_defeat_effects = yes
#	}
#	
#	on_primary_attacker_death = inherit
#	on_primary_defender_death = inherit
#	
#	transfer_behavior = transfer
#	
#	attacker_allies_inherit = yes
#	defender_allies_inherit = yes
#	
#	war_name = "CLAIM_WAR_NAME"
#	my_war_name = "CLAIM_WAR_NAME_MY"
#	war_name_base = "CLAIM_WAR_NAME_BASE"
#	cb_name = "CLAIM_CB_NAME"
#	interface_priority = 60
#
#	should_show_war_goal_subview = yes
#	
#	attacker_wargoal_percentage = 0.8
#	
#	max_defender_score_from_occupation = 150
#	max_attacker_score_from_occupation = 150
#	
#	max_ai_diplo_distance_to_title = 1000
#}
#
###########
## Special 'claim' CB used by Harold the Hard-ruler to invade England in 1066.
## If victorious, Harold personally seizes all land in Northern England (ostensibly to distribute to good Norwegian vassals). Otherwise should be mostly-identical to a Claim CB.
###########
#norwegian_invasion_cb = {
#	icon = invasion
#	group = event
#	mutually_exclusive_titles = {
#		always = yes
#	}
#
#	allow_hostages = no
#	#allowed_for_character = {}
#
#	allowed_against_character = {
#		faith.religion = scope:attacker.faith.religion
#	}
#
#	is_allowed_claim_title = {
#		scope:claimant =  {
#			NOT = { has_trait = incapable }
#			is_imprisoned = no
#			OR = {
#				this = scope:attacker
#				AND = {
#					religion = scope:attacker.religion
#					dynasty = scope:attacker.dynasty
#				}
#			}
#		}
#	}
#
#	cost = {
#		#prestige = 1000
#	}
#	
#	target_titles = claim
#	#target_title_tier = all
#	
#	on_declaration = {
#		on_declared_war = 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_claim_war_invalidated_message
#
#	on_invalidated = { set_global_variable = norwegian_invasion_cb_concluded }
#
#	on_victory_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { scope:defender = { is_local_player = yes } }
#				desc = norwegian_invasion_cb_victory_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = norwegian_invasion_cb_victory_desc_attacker
#			}
#			desc = norwegian_invasion_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_high_effect = yes }
#
#		# Loc setup.
#		character:124 = { save_scope_as = tostig }
#		title:d_northumberland = { save_scope_as = northumberland}
#		title:d_york = { save_scope_as = york }
#		title:d_lancaster = { save_scope_as = lancaster}
#		custom_tooltip = norwegian_invasion_cb_victory_with_tostig_desc
#		# Set land acquisition type to conquest.
#		create_title_and_vassal_change = {
#			type = conquest
#			save_scope_as = change
#			add_claim_on_loss = yes
#		}
#		
#		# Transfer landed titles to the attacker.
#		setup_claim_cb = {
#			titles = target_titles
#			attacker = scope:attacker
#			defender = scope:defender
#			claimant = scope:claimant
#			change = scope:change
#		}
#
#		# EP3 Laamp possibility warning
#		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }
#		
#		every_in_list = {
#			list = target_titles
#
#			#Remove elective succession law from k_england.
#			clear_title_laws = yes	
#
#			# Personally seize all duchy titles in Northern England AND all duchy titles personally held by the King of England.
#			every_in_de_jure_hierarchy = {
#				limit = {
#					tier = tier_duchy
#					special_invasion_cb_seize_land_in_region_trigger = {
#						TARGET_REGION = custom_northern_england
#						TARGET_KINGDOM = title:k_england
#					}
#				}
#				if = {
#					limit = {
#						holder ?= {
#							top_liege ?= scope:defender
#
#							# Vassal players in England get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#							NAND = {
#								this != top_liege
#								is_ai = no
#							}
#						}
#					}
#					custom_description = {
#						text = custom_seize_title_and_below_de_jure
#						subject = scope:attacker
#						object = this
#						change_title_holder = {
#							holder = scope:attacker
#							change = scope:change
#							take_baronies = no
#						}
#					}
#
#					# Grab the counties that go with the duchies, too.
#					every_in_de_jure_hierarchy = {
#						limit = {
#							tier = tier_county
#							holder ?= {
#								top_liege = scope:defender
#
#								# Vassal players in England get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#								NAND = {
#									this != top_liege
#									is_ai = no
#								}
#							}
#						}
#						hidden_effect = {
#							change_title_holder = {
#								holder = scope:attacker
#								change = scope:change
#								take_baronies = no
#							}
#						}
#					}
#				}
#			}
#			# Personally seize every county title in the Northern England AND county titles personally held by the King of England.
#			every_in_de_jure_hierarchy = {
#				limit = {
#					tier = tier_county
#					special_invasion_cb_seize_land_in_region_trigger = {
#						TARGET_REGION = custom_northern_england
#						TARGET_KINGDOM = title:k_england
#					}
#				}
#				if = {
#					limit = {
#						holder ?= {
#							top_liege ?= scope:defender
#
#							# Vassal players in England get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#							NAND = {
#								this != top_liege
#								is_ai = no
#							}
#						}
#					}
#					custom_description = {
#						text = custom_seize_title
#						subject = scope:attacker
#						object = this
#						change_title_holder = {
#							holder = scope:attacker
#							change = scope:change
#							take_baronies = no
#						}
#					}
#				}
#			}
#		}				
#		resolve_title_and_vassal_change = scope:change
#
#		#If Tostig is still alive, and in Harold's court, give him back his northern lands, and give Hardrada a reward.
#		scope:attacker = {
#			if = {
#				limit = {
#					character:124 = {
#						is_alive = yes
#						is_pool_character = no
#						liege ?= scope:attacker
#					}
#				}
#
#				#Grab the appropriate titles.
#				title:d_northumberland = {
#					every_in_de_jure_hierarchy = {
#						continue = { tier >= tier_duchy }
#						add_to_list = tostig_reward_titles
#					}
#				}
#				title:d_york = {
#					every_in_de_jure_hierarchy = {
#						continue = { tier >= tier_duchy }
#						add_to_list = tostig_reward_titles
#					}
#				}
#				title:d_lancaster = {
#					every_in_de_jure_hierarchy = {
#						continue = { tier >= tier_duchy }
#						add_to_list = tostig_reward_titles
#					}
#				}
#
#				#Adjust titles.
#				hidden_effect = {
#					create_title_and_vassal_change = {
#						type = granted
#						save_scope_as = change
#						add_claim_on_loss = no
#					}
#					every_in_list = {
#						list = tostig_reward_titles
#						limit = { holder = scope:attacker }
#						change_title_holder = {
#							holder = character:124
#							change = scope:change
#						}
#					}
#					resolve_title_and_vassal_change = scope:change
#				
#					#A hook for Harold.
#					add_hook = {
#						type = loyalty_hook
#						target = character:124
#					}
#					#And some opinion.
#					reverse_add_opinion = {
#						target = character:124
#						modifier = loyal_servant
#					}
#				}
#			}
#		}
#
#		#If William already won the conquest, loose Normandy back into the continent.
#		scope:attacker = {
#			if = {
#				limit = {
#					any_vassal = {
#						primary_title = title:d_normandy
#					}
#				}
#				random_vassal = {
#					limit = { primary_title = title:d_normandy }
#					save_scope_as = free_william	#Harald Hardrada & William the Bastard? A friendship you could never imagine!
#				}
#				scope:free_william = {
#					#De-vassalise him.
#					create_title_and_vassal_change = {
#						type = independency
#						save_scope_as = change
#						add_claim_on_loss = no
#					}
#					becomes_independent = { change = scope:change }
#					resolve_title_and_vassal_change = scope:change
#					#Take away his "Conqueror" title. Clearly he does not deserve it.
#					if = {
#						#William goes back to being the Bastard.
#						limit = {
#							this = character:140
#							has_nickname = nick_the_conqueror
#						}
#						give_nickname = nick_the_bastard
#					}
#					else = {
#						#Anyone else will be mocked forever for their brief victory.
#						give_nickname = nick_the_unready
#					}
#				}
#			}
#			#And give him Maine & Sable too.
#			if = {
#				limit = { title:c_maine.holder.liege = scope:attacker }
#				create_title_and_vassal_change = {
#					type = revoked
#					save_scope_as = change
#					add_claim_on_loss = no
#				}
#				title:c_maine.holder = {
#					change_liege = {
#						liege = scope:free_william
#						change = scope:change
#					}
#				}
#				resolve_title_and_vassal_change = scope:change
#			}
#			if = {
#				limit = {
#					NOT = { title:c_sable.holder = title:c_maine.holder }
#					title:c_sable.holder.liege = scope:attacker
#				}
#				create_title_and_vassal_change = {
#					type = revoked
#					save_scope_as = change
#					add_claim_on_loss = no
#				}
#				title:c_sable.holder = {
#					change_liege = {
#						liege = scope:free_william
#						change = scope:change
#					}
#				}
#				resolve_title_and_vassal_change = scope:change
#			}
#		}
#
#		modify_all_participants_fame_values = {
#			WINNER = scope:attacker
#			LOSER = scope:defender
#			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_claim_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 }
#
#		set_global_variable = norwegian_invasion_cb_concluded
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_victory_effects = yes
#	}
#
#	on_white_peace_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { scope:defender = { is_local_player = yes } }
#				desc = norwegian_invasion_cb_white_peace_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = norwegian_invasion_cb_white_peace_desc_attacker
#			}
#			desc = norwegian_invasion_cb_white_peace_desc
#		}
#	}
#	
#	on_white_peace = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#
#		#EP2 accolade glory gain for winning against higher ranked enemy
#		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
#		scope:defender = { accolade_defender_war_end_glory_gain_med_effect = yes }
#		
#		# press claims
#		every_in_list = {
#			list = target_titles
#			if = {
#				limit = { scope:attacker = { has_weak_claim_on = prev } }
#				scope:attacker = {
#					make_claim_strong = prev
#				}
#			}
#		}
#		
#		setup_claim_cb = {
#			titles = target_titles
#			attacker = scope:attacker
#			defender = scope:defender
#			claimant = scope:claimant
#			victory = no
#		}
#
#		# Small prestige penalty to the attacker for failing to win their own war.
#		scope:attacker = {
#			add_prestige = {
#				value = scope:cb_prestige_factor # Set by 'setup_claim_cb'
#				multiply = -5
#			}
#			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
#			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_claim_cb'
#			IS_RELIGIOUS_WAR = no
#			WINNER_ALLY_FAME_SCALE = 10
#			LOSER_ALLY_FAME_SCALE = 10
#		}
#
#		if = {
#			limit = {
#				scope:claimant != scope:attacker
#				scope:claimant = {
#					can_add_hook = {
#						type = favor_hook
#						target = scope:attacker
#					}
#				}
#			}
#			scope:claimant = {
#				add_hook = {
#					target = scope:attacker
#					type = favor_hook
#				}
#			}
#		}
#
#		scope:defender = {
#			stress_impact = {
#				arrogant = medium_stress_impact_gain
#			}
#		}
#
#		# Truce
#		add_truce_white_peace_effect = yes
#
#		set_global_variable = norwegian_invasion_cb_concluded
#
#		# 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 = norwegian_invasion_cb_defeat_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = norwegian_invasion_cb_defeat_desc_attacker
#			}
#			desc = norwegian_invasion_cb_defeat_desc
#		}
#	}
#	
#	on_defeat = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#		
#		# Legitimacy
#		add_legitimacy_attacker_defeat_effect = yes
#
#		scope:defender = { 
#			mandala_peacemaker_perk_serenity_effect = yes
#			#EP2 accolade glory gain for winning against higher ranked enemy
#			accolade_defender_war_end_glory_gain_high_effect = yes
#		}
#	
#		# lose claims
#		if = {
#			limit = { scope:attacker = scope:claimant }
#			every_in_list = {
#				list = target_titles
#				scope:claimant = {
#					remove_claim = prev
#				}
#			}
#		}
#
#		if = {
#			limit = {
#				scope:claimant != scope:attacker
#				scope:claimant = {
#					can_add_hook = {
#						type = favor_hook
#						target = scope:attacker
#					}
#				}
#			}
#			scope:claimant = {
#				add_hook = {
#					target = scope:attacker
#					type = favor_hook
#				}
#			}
#		}
#		
#		# Award the appropriate amount of prestige to all participants in the war.
#		setup_claim_cb = {
#			titles = target_titles
#			attacker = scope:attacker
#			defender = scope:defender
#			claimant = scope:claimant
#			victory = no
#		}
#		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
#		}
#
#		# Truce
#		add_truce_attacker_defeat_effect = yes
#		
#		scope:attacker = {
#			save_temporary_scope_as = loser
#		}
#		on_lost_aggression_war_discontent_loss = yes
#
#		set_global_variable = norwegian_invasion_cb_concluded
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_defeat_effects = yes
#	}
#	
#	on_primary_attacker_death = inherit
#	on_primary_defender_death = inherit
#	
#	transfer_behavior = transfer
#	
#	attacker_allies_inherit = yes
#	defender_allies_inherit = yes
#	
#	war_name = "CLAIM_WAR_NAME"
#	my_war_name = "CLAIM_WAR_NAME_MY"
#	war_name_base = "CLAIM_WAR_NAME_BASE"
#	cb_name = "CLAIM_CB_NAME"
#	interface_priority = 60
#	
#	attacker_wargoal_percentage = 0.8
#	
#	max_defender_score_from_occupation = 150
#	max_attacker_score_from_occupation = 150
#
#	should_show_war_goal_subview = yes
#	
#	max_ai_diplo_distance_to_title = 1000
#}
#
###########
## Special 'claim' CB used by the Sons of Lothbrok to invade England & Scotland in 867.
## If victorious, they personally seize all land in k_england or k_scotland (depending on the war). Otherwise very close to a duchy conquest CB.
###########
#
#sons_of_lothbrok_invasion_cb = {
#	icon = fp1_varangian_adventurer_conquest
#	group = event
#
#	allowed_for_character = {
#	}
#
#	allowed_against_character = {
#		scope:attacker = {
#			ALL_FALSE = {
#				top_liege = scope:defender.top_liege
#				liege = scope:defender
#			}
#		}
#	}
#	target_titles = none
#	target_title_tier = all
#	target_de_jure_regions_above = yes
#	ignore_effect = change_title_holder
#	ai_only_against_neighbors = yes
#	allow_hostages = no
#
#	valid_to_start = {
#		always = no
#	}
#
#	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_religious_war_invalidation_region_message
#
#	on_invalidated = {
#	}
#
#	cost = {
#	}
#
#	on_declaration = {
#		on_declared_war = yes
#	}
#
#	on_victory_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = sons_of_lothbrok_invasion_cb_victory_desc_attacker
#			}
#			triggered_desc = {
#				trigger = { scope:defender = { is_local_player = yes } }
#				desc = sons_of_lothbrok_invasion_cb_victory_desc_defender
#			}
#			desc = sons_of_lothbrok_invasion_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_high_effect = yes }
#
#		create_title_and_vassal_change = {
#			type = conquest
#			save_scope_as = change
#			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
#					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
#			}
#		}
#
#		# 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 }
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_victory_effects = yes
#	}
#
#	on_white_peace_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = { scope:defender = { is_local_player = yes } }
#				desc = sons_of_lothbrok_invasion_cb_white_peace_desc_defender
#			}
#			triggered_desc = {
#				trigger = { scope:attacker = { is_local_player = yes } }
#				desc = sons_of_lothbrok_invasion_cb_white_peace_desc_attacker
#			}
#			desc = sons_of_lothbrok_invasion_cb_white_peace_desc
#		}
#	}
#
#	on_white_peace = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#
#		#EP2 accolade glory gain for winning against higher ranked enemy
#		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
#		scope:defender = { accolade_defender_war_end_glory_gain_med_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 scale values 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
#			}
#		}
#
#		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 = sons_of_lothbrok_invasion_cb_defeat_desc_defender
#			}
#			triggered_desc = {
#				trigger = {	scope:attacker = { is_local_player = yes } }
#				desc = sons_of_lothbrok_invasion_cb_defeat_desc_attacker
#			}
#			desc = sons_of_lothbrok_invasion_cb_defeat_desc
#		}
#	}
#
#	on_defeat = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#		
#		# Legitimacy
#		add_legitimacy_attacker_defeat_effect = yes
#
#		scope:defender = { 
#			mandala_peacemaker_perk_serenity_effect = yes
#			#EP2 accolade glory gain for winning against higher ranked enemy
#			accolade_defender_war_end_glory_gain_high_effect = yes
#			# Prestige for Defender
#			add_prestige_war_defender_effect = {
#				PRESTIGE_VALUE = major_prestige_value
#			}
#		}
#
#		# Prestige loss for the attacker
#		scope:attacker = {
#			pay_short_term_gold_reparations_effect = {
#				GOLD_VALUE = 5
#			}
#			add_prestige = {
#				value = major_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: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
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_defeat_effects = 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_CB_NAME"
#
#	interface_priority = 79
#
#	use_de_jure_wargoal_only = yes
#
#	attacker_wargoal_percentage = 0.8
#	
#	max_defender_score_from_occupation = 150
#	max_attacker_score_from_occupation = 150
#
#	max_ai_diplo_distance_to_title = 500
#}
#
###########
## Special 'invasion' CB used by the Hungarians to migrate from the steppe to Pannonia
## If victorious, the Hungarians directly usurp all land within Pannonia not held by a player.
###########
#
#hungarian_migration_cb = {
#	icon = invasion
#	group = invasion	#Switching this to event will render the CB invisible.
#	ai = no # AI targeting is handled through game_rule events.
#
#	allowed_for_character = {
#		culture = culture:mogyer
#		faith = { has_doctrine_parameter = unreformed }
#	}
#
#	allowed_against_character = {
#		#Realm must have at least some land in Hungary.
#		scope:defender = {
#			any_realm_county = {
#				title_province = { geographical_region = custom_hungary }
#			}
#		}
#	}
#
#	target_titles = all
#	target_title_tier = kingdom
#	target_de_jure_regions_above = yes
#	ignore_effect = change_title_holder
#	use_de_jure_wargoal_only = yes
#	combine_into_one = yes
#
#	#Configure war-score. This is a bit different to usual, focusing mostly on battles and almost not at all on back-capping the attacker: the Mogyers literally do not care at all if you occupy their homelands, they're moving their whole people to Pannonia anyway.
#
#	max_attacker_score_from_battles = 200
#	max_defender_score_from_battles = 200
#	max_defender_score_from_occupation = 25
#	max_attacker_score_from_occupation = 150
#	full_occupation_by_defender_gives_victory = no
#	landless_attacker_needs_armies = no
#	attacker_capital_gives_war_score = no
#
#	valid_to_start = {
#		#May only target Hungary.
#		scope:target = title:k_hungary
#		#Must have taken the appropriate decision.
#		has_character_flag = undertaking_hungarian_migration
#	}
#
#	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
#					}
#				}
#			}
#		}
#		#Emperors do not deign to migrate. Plus it'll mess up title destruction.
#		scope:attacker = { highest_held_title_tier >= tier_empire }
#	}
#
#	on_invalidated = {
#		if = {
#			limit = { exists = scope:attacker.player_heir }
#			scope:attacker.player_heir = {
#				if = {
#					limit = {
#						culture = culture:mogyer
#						faith = { has_doctrine_parameter = unreformed }
#					}
#					#Give scope:attacker back their ability to declare a migration in the event of invalidation.
#					add_character_flag = undertaking_hungarian_migration
#				}
#			}
#		}
#	}
#
#	on_invalidated_desc = msg_invasion_war_invalidated_message
#
#	#No cost: that's paid in the decision.
#	
#	on_declaration = {
#		on_declared_war = yes
#		hidden_effect = {
#			add_to_global_variable_list = {
#				name = unavailable_unique_decisions
#				target = flag:flag_launched_hungarian_migration
#			}
#		}
#		#Give scope:attacker some armies to ensure success & use up their free invasion.
#		scope:attacker = {
#			remove_character_flag = undertaking_hungarian_migration
#			#One army to conquer.
#			if = {
#				limit = {
#					has_mpo_dlc_trigger = yes
#				}
#				spawn_army = {
#					name = event_troop_default_name
#					men_at_arms = {
#						type = nomadic_riders
#						stacks = 20
#					}
#					men_at_arms = {
#						type = heavy_horse_archers
#						stacks = 5
#					}
#					men_at_arms = {
#						type = steppe_raiders
#						stacks = 5
#					}
#					location = scope:attacker.capital_province
#					uses_supply = no
#					war = scope:war
#					inheritable = no
#				}
#			}
#			else = {
#				spawn_army = {
#					name = event_troop_default_name
#					levies = 2000
#					men_at_arms = {
#						type = horse_archers
#						stacks = 10
#					}
#					location = scope:attacker.capital_province
#					uses_supply = no
#					war = scope:war
#					inheritable = no
#				}
#			}
#			#And one army to hold.
#			if = {
#				limit = {
#					has_mpo_dlc_trigger = yes
#				}
#				spawn_army = {
#					name = event_troop_default_name
#					men_at_arms = {
#						type = nomadic_riders
#						stacks = 10
#					}
#					men_at_arms = {
#						type = horse_archers
#						stacks = 10
#					}
#					location = scope:attacker.capital_province
#					uses_supply = no
#					inheritable = no
#				}
#			}
#			else = {
#				spawn_army = {
#					name = event_troop_default_name
#					levies = 1000
#					men_at_arms = {
#						type = horse_archers
#						stacks = 10
#					}
#					location = scope:attacker.capital_province
#					uses_supply = no
#					inheritable = no
#				}
#			}
#			
#			#If we're a few decades in, beef the Mogyers a bit with another temporary army.
#			if = {
#				limit = { current_date >= 890.1.1 }
#				if = {
#					limit = {
#						has_mpo_dlc_trigger = yes
#					}
#					spawn_army = {
#						name = event_troop_default_name
#						men_at_arms = {
#							type = nomadic_riders
#							stacks = 20
#						}
#						men_at_arms = {
#							type = heavy_horse_archers
#							stacks = 5
#						}
#						men_at_arms = {
#							type = steppe_raiders
#							stacks = 5
#						}
#						location = scope:attacker.capital_province
#						uses_supply = no
#						war = scope:war
#						inheritable = no
#					}
#				}
#				else = {
#					spawn_army = {
#						name = event_troop_default_name
#						levies = 2000
#						men_at_arms = {
#							type = horse_archers
#							stacks = 10
#						}
#						location = scope:attacker.capital_province
#						uses_supply = no
#						war = scope:war
#						inheritable = no
#					}
#				}
#			}
#			#And if we're almost out of the valid time-frame, add another holding army.
#			if = {
#				limit = { current_date >= 905.1.1 }
#				if = {
#					limit = {
#						has_mpo_dlc_trigger = yes
#					}
#					spawn_army = {
#						name = event_troop_default_name
#						men_at_arms = {
#							type = nomadic_riders
#							stacks = 10
#						}
#						men_at_arms = {
#							type = horse_archers
#							stacks = 10
#						}
#						location = scope:attacker.capital_province
#						uses_supply = no
#						inheritable = no
#					}
#				}
#				else = {
#					spawn_army = {
#						name = event_troop_default_name
#						levies = 1000
#						men_at_arms = {
#							type = horse_archers
#							stacks = 10
#						}
#						location = scope:attacker.capital_province
#						uses_supply = no
#						inheritable = no
#					}
#				}
#			}
#		}
#	}	
#
#	on_victory_desc = {
#		first_valid = {
#			triggered_desc = {
#				trigger = {
#					scope:attacker = { is_local_player = yes }
#				}
#				desc = hungarian_invasion_war_victory_desc_attacker
#			}
#			desc = hungarian_invasion_war_victory_desc
#		}
#		triggered_desc = {
#			trigger = {
#				scope:attacker = { is_local_player = yes }
#			}
#			desc = hungarian_invasion_war_warning_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_high_effect = yes }
#
#		#If the Mogyers aren't independent, make them so.
#		if = {
#			limit = {
#				scope:attacker = { top_liege != this }
#			}
#			create_title_and_vassal_change = {
#				type = independency
#				save_scope_as = change
#				add_claim_on_loss = no
#			}
#			change_liege_or_become_independent = {
#				CHANGE = scope:change
#				VASSAL = scope:attacker
#			}
#			resolve_title_and_vassal_change = scope:change
#		}
#
#		#Take lands within Pannonia.
#		hidden_effect = {
#			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 = no
#			}
#			every_in_list = {
#				list = target_titles
#
#				# Personally seize all duchy titles in k_hungary AND duchy titles personally held by the target king.
#				every_in_de_jure_hierarchy = {
#					limit = {
#						tier = tier_duchy
#						special_invasion_cb_seize_land_in_region_trigger = {
#							TARGET_REGION = custom_hungary
#							TARGET_KINGDOM = title:k_hungary
#						}
#					}
#					if = {
#						limit = {
#							holder ?= {
#								top_liege ?= scope:defender
#
#								# Vassal players in Hungary get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#								NAND = {
#									this != top_liege
#									is_ai = no
#								}
#							}
#						}
#						hidden_effect = {
#							# As a security set all the county below the duchy as under transfer in case the defender owned the duchy and the counties below
#							every_in_de_jure_hierarchy = {
#								limit = {
#									tier = tier_county
#									holder ?= scope:defender
#								}
#								add_to_temporary_list = county_titles_under_transfer
#							}
#						}
#						custom_description = {
#							text = custom_seize_title_and_below_de_jure
#							subject = scope:attacker
#							object = this
#							change_title_holder = {
#								holder = scope:attacker
#								change = scope:change
#								take_baronies = yes
#							}
#						}
#					}
#				}
#
#				# Grab counties belonging to duchies that don't exist
#				every_in_de_jure_hierarchy = {
#					limit = {
#						tier = tier_county
#						holder ?= {
#							top_liege = scope:defender
#
#							# Vassal players in Hungary get to keep their holdings, so they can play as vassals of the new king instead of game-overing.
#							NAND = {
#								this != top_liege
#								is_ai = no
#							}
#						}
#					}
#					hidden_effect = {
#						if = { 
#							limit = { NOT = { is_in_list = county_titles_under_transfer } } # Theoretically prevents cases in which a title was already on the list
#							add_to_temporary_list = county_titles_under_transfer
#							change_title_holder = {
#								holder = scope:attacker
#								change = scope:change
#								take_baronies = yes
#							}
#						}
#					}
#				}
#			}
#			resolve_title_and_vassal_change = scope:change
#		}
#
#		#Start processing the Hungarian-specific effects.
#		scope:attacker = {
#			launch_hungarian_migration_scripted_effect = { INVADER = scope:attacker }
#		}
#
#		# 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 }
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_victory_effects = 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 }
#
#		#EP2 accolade glory gain for doing ok against higher ranked enemy
#		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
#		scope:defender = { accolade_defender_war_end_glory_gain_med_effect = yes }
#
#		# Prestige for the attacker's war allies
#
#		# 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
#		}
#
#		# 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 = invasion_war_white_peace_desc_defender
#			}
#			desc = invasion_war_white_peace_desc
#		}
#	}
#	
#	on_defeat = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#		
#		# Legitimacy
#		add_legitimacy_attacker_defeat_effect = yes
#
#		scope:defender = { 
#			mandala_peacemaker_perk_serenity_effect = yes
#			#EP2 accolade glory gain for winning against higher ranked enemy
#			accolade_defender_war_end_glory_gain_high_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
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_defeat_effects = yes
#	}
#	
#	transfer_behavior = transfer
#	
#	on_primary_attacker_death = inherit
#	on_primary_defender_death = inherit
#	transfer_behavior = transfer
#	
#	attacker_allies_inherit = yes
#	defender_allies_inherit = yes
#	
#	war_name = "HUNGARIAN_INVASION_WAR_NAME"
#	war_name_base = "HUNGARIAN_INVASION_WAR_NAME_BASE"
#	cb_name = "HUNGARIAN_INVASION_CB_NAME"
#	
#	interface_priority = 100
#	
#	use_de_jure_wargoal_only = yes
#	
#	attacker_wargoal_percentage = 0.5
#}
#
###########
## Special 'invasion' CB used by the Azariqa to secede in Iraq
## If victorious, they directly usurp all land within Jazira & create the relevant title.
###########
#
#azariqa_rebellion_cb = {
#	icon = invasion
#	group = event
#
#	combine_into_one = yes
#	should_show_war_goal_subview = yes
#	mutually_exclusive_titles = { always = yes }
#	allow_hostages = no
#
#	allowed_for_character = {}
#
#	allowed_for_character_display_regardless = {}
#	
#	allowed_against_character = {}
#	target_titles = all
#	target_title_tier = kingdom
#	target_de_jure_regions_above = yes
#	ignore_effect = change_title_holder
#
#	valid_to_start = { always = no }
#
#	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
#
#	cost = {}
#	
#	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
#		}
#	}
#	
#	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_high_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
#		}
#		# Take k_jazira directly.
#		title:k_jazira = {
#			if = {
#				limit = {
#					OR = {
#						is_title_created = no
#						holder = {
#							OR = {
#								this = scope:defender
#								any_liege_or_above = { this = scope:defender }
#							}
#						}
#					}
#				}
#				change_title_holder = {
#					holder = scope:attacker
#					change = scope:change
#				}
#			}
#		}
#		resolve_title_and_vassal_change = scope:change
#
#		create_title_and_vassal_change = {
#			type = independency
#			save_scope_as = change
#		}
#		scope:attacker = {
#			becomes_independent = { change = scope:change }
#		}
#		resolve_title_and_vassal_change = scope:change
#		
#		hidden_effect = {
#			scope:attacker = {
#				faith = { save_scope_as = faith }
#				set_up_dynamic_temporal_hof_title_effect = { NEW_HOLDER = scope:attacker }
#			}
#		}
#
#		# 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 = yes
#			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 }
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_victory_effects = 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 }
#
#		#EP2 accolade glory gain for doing ok against higher ranked enemy
#		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
#		scope:defender = { accolade_defender_war_end_glory_gain_med_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
#			}
#		}
#
#		# 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 = invasion_war_white_peace_desc_defender
#			}
#			desc = invasion_war_white_peace_desc
#		}
#	}
#	
#	on_defeat = {
#		scope:attacker = { show_pow_release_message_effect = yes }
#		
#		# Legitimacy
#		add_legitimacy_attacker_defeat_effect = yes
#
#		scope:defender = {
#			mandala_peacemaker_perk_serenity_effect = yes
#			#EP2 accolade glory gain for winning against higher ranked enemy
#			accolade_defender_war_end_glory_gain_high_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
#		
#		imprison_character_effect = {
#			TARGET = scope:attacker
#			IMPRISONER = scope:defender
#		}
#
#		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
#		laamp_as_mercenary_payout_tooltip_effect = yes
#
#		#Mandalas gain or lose piety/devotion depending on Decree
#		mandala_war_defeat_effects = 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 = "INVASION_CB_NAME"
#	
#	interface_priority = 100
#	
#	use_de_jure_wargoal_only = yes
#	
#	attacker_wargoal_percentage = 0.8
#	
#	max_defender_score_from_occupation = 150
#	max_attacker_score_from_occupation = 150
#}

##########
# Special war to claim Byzantium for Raiktor
# If victorious, you gain the kingdom of Epirus for yourself!
##########

raiktor_claim_cb = {
	icon = claim_cb
	group = event
	
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }
	allow_hostages = no

	allowed_for_character = {}

	allowed_for_character_display_regardless = {}
	
	allowed_against_character = {}
	target_titles = claim
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder

	valid_to_start = { always = no }

	should_invalidate = {
		
	}

	on_invalidated_desc = msg_invasion_war_invalidated_message

	cost = {}
	
	on_declaration = { on_declared_war = yes }	

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claimant = { is_local_player = yes }
				}
				desc = claim_cb_victory_desc_attacker_claimant
			}
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = claim_cb_victory_desc_attacker
			}
			desc = claim_cb_victory_desc
		}
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		#EP2 Accolade glory gain from winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_med_effect = yes }
		
		custom_tooltip = you_gain_epirus
		scope:defender = {
			pay_short_term_gold = {
				target = scope:attacker
				gold = scope:defender.major_gold_value
			}
		}
		hidden_effect = {
			title:k_epirus = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier >= tier_county
						holder ?= {
							OR = {
								this = scope:defender
								is_vassal_or_below_of = scope:defender
							}
						}
					}
					add_to_list = epirus_titles
				}
			}
			
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = change_epirus
				add_claim_on_loss = yes
			}
			
			title:k_epirus = {
				if = {
					limit = {
						OR = {
							is_title_created = no
							holder = {
								OR = {
									this = scope:defender
									any_liege_or_above = { this = scope:defender }
								}
							}
						}
					}
					change_title_holder = {
						holder = scope:attacker
						change = scope:change_epirus
					}
				}
			}
			
			every_in_list = {
				list = epirus_titles
				change_title_holder = {
					holder = scope:attacker
					change = scope:change_epirus
				}
			}

			resolve_title_and_vassal_change = scope:change_epirus
		}
		
		custom_tooltip = raiktor_gains_byzantium
		hidden_effect = {
			create_title_and_vassal_change = {
				type = conquest_claim
				save_scope_as = change
				add_claim_on_loss = yes
			}

			setup_claim_cb = {
				titles = target_titles
				attacker = scope:attacker
				defender = scope:defender
				claimant = scope:claimant
				change = scope:change
			}

			resolve_title_and_vassal_change = scope:change
		}

		if = {
			limit = {
				scope:claimant != scope:attacker
				scope:claimant.primary_title.tier < scope:attacker.primary_title.tier
				scope:claimant = {
					NOT = { target_is_liege_or_above = scope:attacker }
				}
			}

			create_title_and_vassal_change = {
				type = conquest_claim
				save_scope_as = change_two
				add_claim_on_loss = yes
			}
			scope:claimant = {
				change_liege = {
					liege = scope:attacker
					change = scope:change_two
				}
			}
			resolve_title_and_vassal_change = scope:change_two
		}

		if = {
			limit = {
				scope:claimant != scope:attacker
				scope:attacker = {
					can_add_hook = {
					  	type = loyalty_hook
					  	target = scope:claimant
					}
				}
			}
			scope:attacker = {
				add_hook = {
		  			target = scope:claimant
		  			type = loyalty_hook
		 		}
			}
		}

		# 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_claim_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 }
		
		hidden_effect = {
			scope:claimant = {
				remove_trait = devoted
				add_gold = 750
			}
		}

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_victory_effects = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = claim_cb_white_peace_desc_defender
			}
			desc = claim_cb_white_peace_desc
		}
		
	}

	on_white_peace = {
		scope:attacker = {
			show_pow_release_message_effect = yes
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}

		#EP2 accolade glory gain for defender doing alright
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		# press claims
		every_in_list = {
			list = target_titles
			if = {
				limit = { scope:claimant = { has_weak_claim_on = prev } }
				scope:claimant = {
					make_claim_strong = prev
				}
			}
		}

		# Create an 'helper' claim CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		setup_claim_cb = {
			titles = target_titles
			attacker = scope:attacker
			defender = scope:defender
			claimant = scope:claimant
			victory = no
		}
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = scope:cb_prestige_factor # Set by 'setup_claim_cb'
				multiply = -5.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
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_claim_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 10
			LOSER_ALLY_FAME_SCALE = 10
		}
		# Defender neither gains nor loses any prestige.
		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}

		if = {
			limit = {
				scope:claimant != scope:attacker
				scope:attacker = {
					can_add_hook = {
					  	type = favor_hook
					  	target = scope:claimant
					}
				}
			}
			scope:attacker = {
				add_hook = {
		  			target = scope:claimant
		  			type = favor_hook
		 		}
			}
		}

		# Truce
		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 = claim_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = { scope:claimant = { is_local_player = yes } }
				desc = claim_cb_defeat_desc_attacker_claimant
			}
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = claim_cb_defeat_desc_attacker
			}
			desc = claim_cb_defeat_desc
		}
		
	}

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

		# lose claims
		every_in_list = {
			list = target_titles
			scope:claimant = {
				remove_claim = prev
			}
		}

		if = {
			limit = {
				scope:claimant != scope:attacker
				scope:attacker = {
					can_add_hook = {
					  	type = favor_hook
					  	target = scope:claimant
					}
				}
			}
			scope:attacker = {
				add_hook = {
		  			target = scope:claimant
		  			type = favor_hook
		 		}
			}
		}

		# Attacker pays gold to the defender as reparations.
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
		}
		# Create an 'helper' claim CB which we won't execute, but can use to determine how much Prestige should be given to war participants.
		setup_claim_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
		}

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_defeat_effects = yes
	}
	
	transfer_behavior = transfer
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "CLAIM_WAR_NAME"
	my_war_name = "CLAIM_WAR_NAME_MY"
	war_name_base = "CLAIM_WAR_NAME_BASE"
	cb_name = "CLAIM_CB_NAME"
	
	interface_priority = 100
	
	attacker_wargoal_percentage = 0.8
	
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

##########
# Another Raiktor war, specifically for a few counties
# If victorious, Raiktor gets three counties along the coast
##########

raiktor_conquest_cb = {
	icon = claim_cb
	group = event

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

	allowed_for_character = {}

	allowed_for_character_display_regardless = {}
	
	allowed_against_character = {}
	target_titles = all
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder

	valid_to_start = { always = no }

	should_invalidate = {
		
	}

	on_invalidated_desc = msg_invasion_war_invalidated_message

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

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_high_effect = yes }
		scope:attacker = {
			random_courtier = {
				limit = {
					has_character_flag = raiktor
				}
				save_scope_as = vassal_to_be
			}
		}
		
		if = {
			limit = {
				exists = scope:vassal_to_be
			}
			custom_tooltip = raiktor_vassal_desc
		}
		else = {
			custom_tooltip = raiktor_vassal_backup_desc
		}
		
		hidden_effect = {
			
			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 = no
			}
			resolve_title_and_vassal_change = scope:change
			
			if = {
				limit = {
					exists = scope:vassal_to_be
				}
				create_title_and_vassal_change = {
					type = conquest
					save_scope_as = change
					add_claim_on_loss = yes
				}

				every_in_list = {
					list = target_titles
					change_title_holder = {
						holder = scope:vassal_to_be
						change = scope:change
					}
				}

				resolve_title_and_vassal_change = scope:change
			}
			
		}
		

		if = {
			limit = {
				exists = scope:vassal_to_be
				scope:attacker = {
					can_add_hook = {
					  	type = loyalty_hook
					  	target = scope:vassal_to_be
					}
				}
			}
			scope:attacker = {
				add_hook = {
		  			target = scope:vassal_to_be
		  			type = loyalty_hook
		 		}
			}
		}

		# 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 = yes
			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 }
		
		hidden_effect = {
			scope:claimant = {
				remove_trait = devoted
				add_gold = 100
			}
		}

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_victory_effects = 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 }

		#EP2 accolade glory gain for doing ok against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
		scope:defender = { accolade_defender_war_end_glory_gain_med_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
			}
		}

		# 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 = invasion_war_white_peace_desc_defender
			}
			desc = invasion_war_white_peace_desc
		}
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
	
		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_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
		
		imprison_character_effect = {
			TARGET = scope:attacker
			IMPRISONER = scope:defender
		}

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_defeat_effects = 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 = 100
	
	use_de_jure_wargoal_only = yes
	
	attacker_wargoal_percentage = 0.8
	
	attacker_ticking_warscore_delay = { days = 0 }
	attacker_score_from_occupation_scale = 300
	defender_score_from_occupation_scale = 300
	attacker_score_from_battles_scale = 300
	defender_score_from_battles_scale = 300
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

##########
# Special 'conquest' CB used by the Norse whilst they harass the North Atlantic.
# If you feel like you can't get away from the Vikings in the 800s & 900s, they're doing their job.
##########

fp1_scandi_adventurer_conquest = {
	icon = fp1_varangian_adventurer_conquest
	group = event

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

	allowed_for_character = {
		is_ai = yes
	}

	allowed_against_character = {
		always = yes
	}
	target_titles = all
	target_title_tier = duchy
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder

	valid_to_start = {
		always = no
	}

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

	on_declaration = {
		on_declared_war = yes

		# If scope:defender is a player or a king, give them a few choices.
		scope:defender = {
			if = {
				limit = {
					OR = {
						is_ai = no
						highest_held_title_tier >= tier_kingdom
					}
				}
				trigger_event = {
					id = fp1_trade_events.1131
					days = 30
				}
			}
		}
	}

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

		# go through the dejure hierarchy under target titles, transfer titles with same or worse tolerance holders (their religion equally 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_duchy
					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
			}
		}

		# 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

		#Clean-up adventurer things.
		scope:attacker = { clean_scandinavian_adventurer_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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_victory_effects = 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 = {
		#EP2 accolade glory gain for doing ok against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		# Prestige loss for the attacker
		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 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
		}

		add_truce_white_peace_effect = yes

		#Clean-up adventurer things.
		scope:attacker = { clean_scandinavian_adventurer_effect = yes }

		# Since they failed to win, take away their efficacy loan.
		scope:attacker = { remove_short_term_gold = scandinavian_adventurer_efficacy_loan_value }

		# 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 = {
		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes
		
		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_med_effect = yes
		}

		# Prestige loss for the attacker
		scope:attacker = {
			if = {
				limit = { scope:war ?= { NOT = { has_variable = no_gold_reparations } } }
				pay_short_term_gold_reparations_effect = { GOLD_VALUE = 5 }
			}
			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

		# Give scope:defender some goodies.
		scope:defender = {
			# Including a break from the fighting.
			fp1_add_realm_size_appropriate_sa_reprieve_effect = yes
			# And a tally towards a nickname.
			## Which starts...
			if = {
				limit = {
					NOT = { has_variable = fp1_has_beaten_sa_progress }
				}
				set_variable = {
					name = fp1_has_beaten_sa_progress
					value = 1
				}
			}
			## ... and grows...
			else_if = {
				limit = {
					has_variable = fp1_has_beaten_sa_progress
					## If <9 adventurers has already been defeated, add +1 otherwise...
					var:fp1_has_beaten_sa_progress <= 8
				}
				change_variable = {
					name = fp1_has_beaten_sa_progress
					add = 1
				}
			}
			## ... towards a pay-off.
			## if >8 adventures has already been defeated give nickname
			else_if = {
				limit = {
					OR = {
						has_bad_nickname = yes
						has_any_nickname = no
					}
				}
				hidden_effect = {
					random_list = {
						20 = { give_nickname = nick_the_bane_of_danes }
						20 = { give_nickname = nick_the_culture_wall }
						20 = { give_nickname = nick_nord_foe }
						20 = { give_nickname = nick_the_scourge_of_the_northerners }
						20 = { give_nickname = nick_the_burner_of_ash }
					}
				}
			}
		}

		#Clean-up adventurer things.
		scope:attacker = { clean_scandinavian_adventurer_effect = yes }

		# Since they lost, take away their efficacy loan.
		scope:attacker = { remove_short_term_gold = scandinavian_adventurer_efficacy_loan_value }

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_defeat_effects = 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
	
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

##########
# Special 'vassalise' CB used by diarchs when trying to retract a vassal from a co-vassal.
# If victorious, the diarch takes the affected vassal for their own.
##########

diarch_vassalisation_cb = {
	icon = vassalization
	group = event
	ai_only_against_neighbors = yes
	allow_hostages = no

	allowed_for_character = { always = yes }

	target_titles = de_jure

	should_invalidate = {
		scope:attacker = {
				# No longer same realm.
				top_liege != scope:defender.top_liege
				# No longer of a suitable tier.
				highest_held_title_tier <= scope:secondary_recipient.highest_held_title_tier
			}
	}
	
	on_declaration = { on_declared_war = yes }
	
	on_invalidated_desc = msg_vassalization_war_invalidated_message
	
	on_invalidated = {}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = diarch_vassalization_cb_victory_desc_attacker
			}
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = diarch_vassalization_cb_victory_desc_defender
			}
			desc = diarch_vassalization_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_low_effect = yes }
		
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
		}
		resolve_title_and_vassal_change = scope:change
		
		# Prestige level progress for the attacker
		scope:attacker = {
			add_prestige_experience = {
				value = medium_prestige_value
			}
		}

		# Prestige loss for the defender
		scope:defender = {
			add_prestige = {
				value = medium_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
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		
		# Truce
		add_truce_attacker_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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_victory_effects = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = diarch_vassalization_cb_white_peace_desc_defender
			}
			desc = diarch_vassalization_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
			}
		}

		# Truce
		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 = diarch_vassalization_cb_white_peace_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = diarch_vassalization_cb_defeat_desc_attacker
			}
			desc = diarch_vassalization_cb_white_peace_desc
		}
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_low_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 the 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 = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}

		# Truce
		add_truce_attacker_defeat_effect = yes
		
		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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_defeat_effects = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "DIARCH_VASSALIZATION_WAR_NAME"
	war_name_base = "DIARCH_VASSALIZATION_WAR_NAME_BASE"
	cb_name = "DIARCH_VASSALIZATION_CB_NAME"
	interface_priority = 59
	
	ticking_war_score_targets_entire_realm = yes
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
	attacker_ticking_warscore = 0
	attacker_wargoal_percentage = 0.8
	
	max_ai_diplo_distance_to_title = 500
}

##########
# Special CB used against diarchs when trying to force them from office.
# If victorious, the rebel imprisons the diarch and takes a chunk of their cash.
##########

remove_regent_cb = {
	icon = dissolution_war
	group = event

	allow_hostages = no
	allowed_for_character = { always = yes }

	allowed_against_character = {
		# Scope:defender must be the diarch of one of scope:attacker's lieges.
		scope:attacker = {
			any_liege_or_above = {
				has_active_diarchy = yes
				diarch = scope:defender
				has_diarchy_active_parameter = diarchy_is_regency
			}
		}
	}

	ignore_effect = change_title_holder
	valid_to_start = { always = no }

	should_invalidate = {}

	on_invalidated_desc = msg_remove_regent_cb_invalidated_message
	
	on_invalidated = {
		#remove the temporary fort level
		root.war.var:barony_with_temporary_fort ?= { remove_province_modifier = temporary_fort_province_modifier }
	}

	cost = {}

	on_declaration = {
		on_declared_war = yes
		#add a temporary fort level so that the diarch can be sieged
		if = {
			limit = {
				scope:defender = {
					capital_barony.title_province = { fort_level = 0 }
				}
			}
			scope:defender = {
				capital_barony.title_province = {
					save_scope_as = defender_capital
					add_province_modifier = temporary_fort_province_modifier
				}
			}
		}
		war ?= {
			set_variable = {
				name = barony_with_temporary_fort
				value = scope:defender_capital
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:attacker = { is_local_player = yes }
				}
				desc = remove_regent_cb_victory_desc_attacker
			}
			desc = remove_regent_cb_victory_desc
		}
	}

	on_victory = {
		# Scope:attacker imprisons the diarch instead.
		imprison_character_effect = {
			TARGET = scope:defender
			IMPRISONER = scope:attacker
		}
		# Provided our primaries share a realm, the regency moves on, otherwise, we're just warring for prison.
		scope:defender = {
			if = {
				limit = {
					top_liege = scope:attacker.top_liege
					# Plus, make sure that they're still a diarch.
					is_diarch = yes
				}
				depose_diarch = yes
			}
			#remove the temporary fort level
			if = {
				limit = {
					root.war.var:barony_with_temporary_fort ?= { has_province_modifier = temporary_fort_province_modifier }
				}
				custom_tooltip = remove_regent_cb_temporary_fort
				hidden_effect = {
					root.war.var:barony_with_temporary_fort = {
						remove_province_modifier = temporary_fort_province_modifier
					}
				}
			}
		}

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = 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: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

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_victory_effects = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = remove_regent_cb_white_peace_desc_defender
			}
			desc = remove_regent_cb_white_peace_desc
		}
	}

	on_white_peace = {
		#EP2 accolade glory gain for doing ok against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_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 = {
			#remove the temporary fort level
			if = {
				limit = {
					root.war.var:barony_with_temporary_fort = { has_province_modifier = temporary_fort_province_modifier }
				}
				custom_tooltip = remove_regent_cb_temporary_fort
				hidden_effect = {
					root.war.var:barony_with_temporary_fort = {
						remove_province_modifier = temporary_fort_province_modifier
					}
				}
			}
			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 = remove_regent_cb_defeat_desc_defender
			}
			desc = remove_regent_cb_defeat_desc
		}
	}

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

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

		# Get imprisoned anyway.
		imprison_character_effect = {
			TARGET = scope:attacker
			IMPRISONER = scope:defender
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = major_prestige_value
			}
			#remove the temporary fort level
			if = {
				limit = {
					root.war.var:barony_with_temporary_fort = { has_province_modifier = temporary_fort_province_modifier }
				}
				custom_tooltip = remove_regent_cb_temporary_fort
				hidden_effect = {
					root.war.var:barony_with_temporary_fort = {
						remove_province_modifier = temporary_fort_province_modifier
					}
				}
			}
		}

		# 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

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

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_defeat_effects = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "REMOVE_REGENT_WAR_NAME"
	war_name_base = "REMOVE_REGENT_WAR_NAME_BASE"
	cb_name = "REMOVE_REGENT_CB_NAME"

	interface_priority = 79

	attacker_wargoal_percentage = 0.8
	
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}
