claim_cb = {
	icon = claim_cb
	group = claim
	mutually_exclusive_titles = {
		NOT = {
			# If pushing personal claims, you can press multiple claims with the Divine Right innovation (High Medieval Era).
			trigger_if = {
				limit = {
					scope:attacker = scope:claimant
				}
				scope:attacker = {
					OR = {
						culture = {
							has_innovation = innovation_chronicle_writing
						}
						AND = {
							government_has_flag = government_is_landless_adventurer
							has_realm_law = camp_purpose_legitimists
							has_variable = legitimist_claimed_title
							var:legitimist_claimed_title = {
								OR = {
									holder = scope:defender
									de_jure_liege.holder = scope:defender
								}
							}
						}
					}
				}
			}
			# If pushing claims for someone else, you need the Rightful Ownership innovation to press multiple claims (Late Medieval Era).
			trigger_else = {
				scope:attacker = {
					culture = {
						has_innovation = innovation_divine_right
					}
				}
			}
		}
	}

	# This whole section was already commented out, I just commented it out more to prevent console errors
	#allowed_for_character = {}

	# allowed_against_character = {
	# 	faith.religion = scope:attacker.faith.religion
	# }

	# Root is the title
	# scope:claimant is the claimant
	# scope:attacker is the attacker
	# scope:defender is the defender
	is_allowed_claim_title = {
		trigger_if = {
			limit = {
				scope:attacker = {
					is_ai = yes
					has_variable = conqueror
				}
			}
			tier >= tier_duchy
		}
		custom_description = {
			text = "claimant_titles_held_by_you_or_vassal"
			NOR = {
				holder = scope:attacker
				holder = {
					target_is_liege_or_above = scope:attacker
				}
			}
		}
		scope:claimant = {
			NOT = { has_trait = incapable }
			is_hostage = no
			custom_description = {
				text = is_not_a_minister_desc
				tgp_is_any_minister = no
			}
			trigger_if = {
				limit = { scope:claimant != scope:attacker } # You can always press your own claims
				is_imprisoned = no
			}
			#religion = scope:attacker.religion
			# claimant must not be at war against defender for this claim already
			custom_description = {
				text = "claimant_already_pressing_their_claim"
				object = root
				NAND = {
					liege = scope:attacker
					any_character_war = {
						casus_belli = {
							any_target_title = {
								this = root
							}
						}
					}
				}
			}
		}
		scope:attacker = {
			#Cannot press claims against your own vassals, as these must be revoked.
			custom_description = {
				text = "claimant_titles_held_by_attacker_vassals"
				NOT = {
					root.holder = {
						target_is_liege_or_above = scope:attacker
					}
				}
			}
		}
		trigger_if = {
			limit = {
				scope:claimant != scope:attacker # You can always press your own claims (though the prestige cost might be high)
			}
			trigger_if = {
				limit = {
					is_weak_claimant_due_to_gender_trigger = { FAITH = scope:attacker.faith CHARACTER = scope:claimant }
				}
				trigger_if = {
					limit = {
						scope:claimant = { is_adult = yes }
					}
					save_temporary_scope_as = treat_claim_as_weak
				}
				trigger_else = {
					always = no
				}
			}
			trigger_else_if = {
				limit = {
					scope:claimant = { is_adult = no }
				}
				save_temporary_scope_as = treat_claim_as_weak
			}
			# making the default behavior explicit if no other trigger_(else_)ifs are valid
			trigger_else = {
				always = yes
			}
		}
		trigger_if = {
			limit = { exists = scope:treat_claim_as_weak }
			holder = {
				custom_description = {
					text = "claim_target_position_is_weak"
					object = scope:attacker
					OR = {
						has_trait = incapable
						is_adult = no
						is_weak_claimant_due_to_gender_trigger = { FAITH = scope:attacker.faith CHARACTER = root.holder }
					}
				}
			}
		}
		#Under Byzantine law, a ruler must be unblemished
		trigger_if = {
			limit = {
				scope:defender.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
			}
			scope:claimant = {
				custom_description = {
					text = "byzantine_claimant_is_disfigured"
					object = scope:claimant
					valid_for_byz_succession_trigger = yes
				}
			}
		}
		#Under Byzantine law, a ruler must be able to produce children.
		trigger_if = {
			limit = {
				scope:defender.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
			}
			scope:claimant = {
				custom_description = {
					text = "byzantine_claimant_is_celibate"
					object = scope:defender
					is_eunuch_trigger = no
					NOT = {
						has_trait = celibate
					}
				}
			}
		}
	}

	allowed_for_character_display_regardless = {
		#If you're landless, you need the Legitimist camp purpose
		trigger_if = {
			limit = {
				scope:attacker = {
					government_has_flag = government_is_landless_adventurer
				}
			}
			scope:attacker = {
				has_realm_law = camp_purpose_legitimists
			}
		}
		tgp_japan_offensive_wars_ban_trigger = yes
	}

	cost = {
		piety = {
			value = 0
			add = common_cb_impious_piety_cost
		}
		prestige = {
			value = 0
			add = claim_cb_prestige_cost
			multiply = common_cb_prestige_cost_multiplier

			if = {
				limit = {
					scope:attacker = {
						has_character_flag = temp_no_claim_war_cost
					}
				}
				multiply = {
					value = 0
					desc = "free_cost" # Says 'free'
				}
			}

			# LEGITIMACY AFFECTS COST
			multiply = {
				value = {
					value = 0
					scope:attacker = {
						if = {
							limit = { has_legitimacy_flag = reduced_claim_cb_cost }
							add = 0.5 
						}
						else_if = {
							limit = { has_legitimacy_flag = very_reduced_claim_cb_cost }
							add = 0.25 
						}
						else_if = {
							limit = { has_legitimacy_flag = extra_reduced_claim_cb_cost }
							add = 0.15 
						}
						else = {
							add = 1
						}
					}
				}
				desc = legitimacy_high_modifier_tt
			}
			multiply = {
				value = {
					value = 0
					scope:attacker = {
						if = {
							limit = { has_legitimacy_flag = massively_increased_claim_cb_cost }
							add = 2.5
						}
						else_if = {
							limit = { has_legitimacy_flag = very_increased_claim_cb_cost }
							add = 2
						}
						else_if = {
							limit = { has_legitimacy_flag = increased_claim_cb_cost }
							add = 1.5
						}
						else = {
							add = 1
						}
					}
				}
				desc = legitimacy_low_modifier_tt
			}
		}
	}

	target_titles = claim
	#target_title_tier = all

	on_declaration = {
		on_declared_war = yes
		if = {
			limit = {
				scope:defender = { is_sibling_of = scope:attacker }
			}
			scope:attacker = {
				add_achievement_flag_effect = { FLAG = achievement_bad_blood_flag }
			}
		}
	}

	should_invalidate = {
		OR = {
			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
							}
						}
					}
				}
			}
			AND = { 
				scope:claimant != scope:attacker
				scope:claimant = {
					OR = {
						is_alive = no 
						NOR = { 
							is_vassal_or_below_of = scope:attacker 
							is_courtier_of = scope:attacker
						}
					}
				}
			}
			scope:claimant = {
				tgp_is_any_minister = yes
			}
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claimant != scope:attacker 
					scope:claimant = { is_alive = no }
				}
				desc = msg_claim_war_invalidated_claimant_unavailable_dead_message
			}
			triggered_desc = {
				trigger = {
					scope:claimant = {
						NOR = { 
							this = scope:attacker 
							NOR = { 
								is_vassal_or_below_of = scope:attacker 
								is_courtier_of = scope:attacker 
							}
							tgp_is_any_minister = yes
						}
					}
				}
				desc = msg_claim_war_invalidated_claimant_unavailable_not_vassal_message
			}
			triggered_desc = {
				trigger = {
					scope:claimant = {
						tgp_is_any_minister = yes
					}
				}
				desc = msg_claim_war_invalidated_claimant_is_now_a_minister_message
			}
			desc = msg_claim_war_invalidated_message
		}
	}
	
	on_invalidated = {
	}

	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 = {
		#Grab the higher title tier
		ordered_in_list = {
			list = target_titles
			order_by = tier
			save_scope_as = target
		}

		scope:attacker = {
			if = {
				limit = {
					is_ai = no
					has_realm_law = camp_purpose_legitimists
					any_in_list = {
						list = target_titles
						tier >= tier_kingdom
					}
				}
				add_achievement_global_variable_effect = {
					VARIABLE = finished_birthright_achievement
					VALUE = yes
				}
			}
			if = {
				limit = {
					is_landless_adventurer = yes
					NOT = { government_has_flag = government_is_nomadic }
				}
				hidden_effect = {
					if = {
						limit = {
							NOT = { has_trait = adventurer }
						}
						add_trait = adventurer
					}
					save_scope_as = the_adventurer
					every_courtier = {
						set_variable = {
							name = former_camp_leader
							value = scope:the_adventurer
						}
						add_trait = adventurer_follower
					}
				}
			}
			if = {
				limit = {
					has_variable = install_claimants_oath
					has_variable = install_claimants_oath_counter
				}
				add_to_variable_list = {
					name = installed_claimants_oath
					target = scope:claimant
				}
				change_variable = {
					name = install_claimants_oath_counter
					add = 1
				}
			}

			show_pow_release_message_effect = yes

			#EP2 Accolade glory gain from winning against higher ranked enemy
			accolade_attacker_war_end_glory_gain_med_effect = yes

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

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		scope:defender ?= {
			if = {
				limit = {
					top_liege = this
					government_allows = administrative
					primary_title = { is_in_list = target_titles }
				}
				every_held_title = {
					title_tier >= county
					limit = { is_noble_family_title = no }
					add_to_list = target_titles
				}
			}

			# EP3 Laamp possibility warning
			ep3_war_loss_adventurer_tt_effect = yes
		}

		create_title_and_vassal_change = {
			type = conquest_claim
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		# Create a claim CB which is executed to handle title/vassal changes, in addition to being used to calculate Prestige awards for war participants.
		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

		# Landless Ceremonial Liege
		if = {
			limit = {
				scope:claimant.top_liege != scope:defender.top_liege
				scope:claimant.primary_title.tier < scope:defender.primary_title.tier
				scope:claimant = { is_landed = no }
				any_in_list = {
					list = target_titles
					exists = var:ceremonial_title
				}
				NOT = {
					any_in_list = {
						list = target_titles
						OR = {
							is_landless_type_title = no
							is_noble_family_title = yes
						}
					}
				}
			}
			scope:defender = {
				faction_demand_regent_transfer_effect = {
					NEW_REGENT = scope:claimant
					REASON = conquest_claim
				}
			}
			create_title_and_vassal_change = {
				type = conquest_claim
				save_scope_as = change_three
				add_claim_on_loss = no
			}
			# Landless Ceremonial Liege must be house head
			scope:claimant = {
				if = {
					limit = { is_house_head = no }
					house = {
						house_head = {
							if = {
								limit = {
									is_landed = no
									is_ai = no
								}
								found_cadet_house_decision_effect = {
									CHARACTER = this
									PRESTIGE = 0
								}
							}
						}
						set_house_head = scope:claimant
					}
				}
			}
			resolve_title_and_vassal_change = scope:change_three
		}
		else_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 = favor_hook
					  	target = scope:claimant
					}
				}
			}
			scope:attacker = {
				add_hook = {
		  			target = scope:claimant
		  			type = favor_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

		# 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 }
		
		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

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

	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

	ai_score_mult = {
		value = 1
		# HOUSE RELATIONS
		add = house_relation_ai_score_value
		#There is no fighting in the admin room!
		if = {
			limit = {
				scope:attacker = {
					government_has_flag = government_is_feudal
					liege ?= {
						government_has_flag = government_is_administrative
					}
				}
				scope:defender = {
					government_has_flag = government_is_administrative
					liege ?= scope:attacker.liege
				}
			}
			multiply = 0.4
		}
		add = frankokratia_leader_protection_value #Set back to 0. Declaring war on the frankokratia leader can really ruin the whole thing
	}
}
