regula_claim_vassal_war = {
	group = de_jure
	
	allowed_for_character = {	
		scope:attacker = {
			has_trait = magister_trait_group
		}
	}

	# Root is the title
	# scope:attacker is the attacker
	# scope:defender is the defender

	allowed_for_character_display_regardless = {
		custom_description = {
			text = magister_trait_4_required_trigger
			has_trait_rank = {
				trait = magister_trait_group 
				rank >= 4
			}
		}
	}
	
	allowed_against_character = {
		scope:defender = {
			is_independent_ruler = yes
			any_vassal_or_below = {
				has_trait = devoted_trait_group
			}
			trigger_if = {
				limit = { scope:attacker = { is_ai = no } } # Already pre-filtered by the AI due to ai_only_against_neighbors = yes. any_neighboring_top_liege_realm_owner is expensive
			}
			NOR = { # Can't vassalize holy orders or Heads of Faith
				any_held_title = {
					is_holy_order = yes
				}
			}
		}
		scope:attacker.primary_title.tier >= scope:defender.primary_title.tier # Must be lower tier or equal (so the vassals are lower)
	}
	
	cost = {
		piety = {
			value = 250
		}

		prestige = {
			value = 0
			desc = REGULA_CLAIM_VASSAL_COST
			scope:defender = {
				every_vassal_or_below = {
					limit = {
						has_trait = devoted_trait_group
						highest_held_title_tier = tier_kingdom
					}
					add = 500
				}
				every_vassal_or_below = {
					limit = {
						has_trait = devoted_trait_group
						highest_held_title_tier = tier_duchy
					}
					add = 250
				}
				every_vassal_or_below = {
					limit = {
						has_trait = devoted_trait_group
						highest_held_title_tier = tier_county
					}
					add = 125
				}
			}

			# Vassal contract in-realm cost reduction
			if = {
				limit = {
					scope:attacker = {
						is_independent_ruler = no
						vassal_contract_has_flag = vassal_contract_war_override
						liege = scope:defender.liege
					}
				}
				multiply = {
					value = war_declaration_rights_allowed_cost_reduction
					desc = "CB_ATTACKER_VASSAL_CONTRACT"
				}
			}
			
			if = {
				limit = {
					has_game_rule = no_cost_casus_belli_costs
				}
				multiply = {
					value = 0
					desc = CB_GAME_RULE_NO_COST
				}
			}
		}
	}
	
	should_invalidate = {
		OR = {
			scope:defender = {
				OR = {
					is_independent_ruler = no
					NOT = {
						any_vassal_or_below = {
							has_trait = devoted_trait_group
						}
					}
				}
			}
			scope:defender.primary_title.tier > scope:attacker.primary_title.tier
		}
	}
	
	on_declaration = {
		on_declared_war = yes
	}	
	
	on_invalidated_desc = msg_regula_claim_vassal_war_invalidated_message
	
	on_invalidated = {
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = regula_claim_vassal_war_victory_desc_attacker
			}
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = regula_claim_vassal_war_victory_desc_defender
			}
			desc = regula_claim_vassal_war_victory_desc
		}
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:defender = {
			every_vassal_or_below = {
				limit ={
					has_trait = devoted_trait_group
				}
				change_liege = {
					liege = scope:attacker
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}
		
		# Iterate the Domination War Tally
		global_var:magister_character = {
			change_variable = {
				name = regula_domination_war_tally
				add = 1
			}
		}
		
		# 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
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = {
				value = major_prestige_value
			}
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = {
				value = major_prestige_value
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		# Truce
		add_truce_attacker_victory_effect = yes
				
	}

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

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = regula_claim_vassal_war_white_peace_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = regula_claim_vassal_war_defeat_desc_attacker
			}
			desc = regula_claim_vassal_war_white_peace_desc
		}
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the defender
		scope:defender = {
			add_prestige = {
				value = medium_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = major_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = major_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}

		# Truce
		add_truce_attacker_defeat_effect = yes
		
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "REGULA_CLAIM_VASSAL_WAR_NAME"
	war_name_base = "REGULA_CLAIM_VASSAL_WAR_NAME_BASE"
	cb_name = "REGULA_CLAIM_VASSAL_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

}

regula_dominate_female_ruler_war = {
	group = de_jure
	ai_only_against_neighbors = yes
	
	allowed_for_character = {
		has_trait = magister_trait_group
	}

	# Root is the title
	# scope:attacker is the attacker
	# scope:defender is the defender

	allowed_for_character_display_regardless = {
		custom_description = {
			text = magister_trait_3_required_trigger
			has_trait_rank = {
				trait = magister_trait_group 
				rank >= 3
			}
		}
	}
	
	allowed_against_character = {
		scope:defender = {
			OR = {
				is_independent_ruler = yes
				scope:defender.liege = scope:attacker.liege
			}
			is_adult = yes
			is_female = yes
			trigger_if = {
				limit = { scope:attacker = { is_ai = no } } # Already pre-filtered by the AI due to ai_only_against_neighbors = yes. any_neighboring_top_liege_realm_owner is expensive
				scope:attacker = {
					any_neighboring_top_liege_realm_owner = {
						this = scope:defender
					}
				}
			}
			NOR = { # Can't vassalize holy orders or Heads of Faith
				any_held_title = {
					is_holy_order = yes
				}
				AND = {
					exists = faith.religious_head
					faith.religious_head = root
				}
			}
		}
		
		scope:attacker.primary_title.tier > scope:defender.primary_title.tier # Must be lower tier
		
	}
	
	cost = {
		piety = {
			value = 250
			if = {
				limit = {
					scope:defender.primary_title = {
						tier = tier_kingdom
					}
				}
				multiply = {
					value = 2
					desc = CB_VASSALIZING_KING
				}
			}
			if = {
				limit = {
					scope:attacker.faith = scope:defender.faith
					scope:defender = {
						has_government = theocracy_government
					}
				}
				add = {
					value = medium_piety_value
					desc = CB_ATTACKER_THEOCRACY
				}
			}
			if = {
				limit = {
					has_game_rule = no_cost_casus_belli_costs
				}
				multiply = {
					value = 0
					desc = CB_GAME_RULE_NO_COST
				}
			}
		}
		prestige = {
			value = 0
			add = {
				desc = CB_SIZE_OF_TARGET_REALM_COST
				scope:defender = {
					every_sub_realm_county = {
						add = {
							value = 100
						}
					}
				}
			}
			if = {
				limit = {
					scope:defender.primary_title = {
						tier = tier_duchy
					}
				}
				multiply = {
					value = 1.25
					desc = CB_VASSALIZING_DUKE
				}
			}
			if = {
				limit = {
					scope:defender.primary_title = {
						tier = tier_kingdom
					}
				}
				multiply = {
					value = 2
					desc = CB_VASSALIZING_KING
				}
			}

			#Innovation Prestige Discounts
			if = {
				limit = {
					scope:attacker = {
						culture = {
							has_innovation = innovation_chronicle_writing
							has_innovation = innovation_land_grants
							has_innovation = innovation_rightful_ownership
						}
					}
				}
				multiply = {
					value = 0.7
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
							}
							OR = {
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.8
					desc = CB_ATTACKER_INNOVATIONS
				}
			}
			else_if = {
				limit = {
					scope:attacker = {
						culture = {
							OR = {
								has_innovation = innovation_chronicle_writing
								has_innovation = innovation_land_grants
								has_innovation = innovation_rightful_ownership
							}
						}
					}
				}
				multiply = {
					value = 0.9
					desc = CB_ATTACKER_INNOVATIONS
				}
			}

			# Bellum Justum Perk
			if = {
				limit = {
					scope:attacker = {
						has_perk = bellum_justum_perk
					}
				}
				multiply = {
					add = bellum_justum_discount_percentage
					divide = 100
					desc = CB_ATTACKER_BELLUM_JUSTUM
				}
			}

			# Dynasty Warfare Perk
			if = {
				limit = {
					scope:attacker = {
						has_dynasty = yes
						dynasty = {
							has_dynasty_perk = warfare_legacy_2
						}
					}
				}
				multiply = {
					value = warfare_legacy_2_discount
					desc = CB_ATTACKER_DYNASTY_WARFARE
				}
			}

			# Vassal contract in-realm cost reduction
			if = {
				limit = {
					scope:attacker = {
						is_independent_ruler = no
						vassal_contract_has_flag = vassal_contract_war_override
						liege = scope:defender.liege
					}
				}
				multiply = {
					value = war_declaration_rights_allowed_cost_reduction
					desc = "CB_ATTACKER_VASSAL_CONTRACT"
				}
			}
			
			if = {
				limit = {
					has_game_rule = no_cost_casus_belli_costs
				}
				multiply = {
					value = 0
					desc = CB_GAME_RULE_NO_COST
				}
			}
		}
	}
	
	should_invalidate = {
		OR = {
			scope:defender = {
				NOR = {
					is_independent_ruler = yes
					scope:defender.liege = scope:attacker.liege
				}
			}
			scope:defender.primary_title.tier >= scope:attacker.primary_title.tier
		}
	}
	
	on_declaration = {
		on_declared_war = yes
	}	
	
	on_invalidated_desc = msg_regula_dominate_female_ruler_war_invalidated_message
	
	on_invalidated = {}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = regula_dominate_female_ruler_war_victory_desc_attacker
			}
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = regula_dominate_female_ruler_war_victory_desc_defender
			}
			desc = regula_dominate_female_ruler_war_victory_desc
		}
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:defender = {
			change_liege = {
				liege = scope:attacker
				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
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = {
				value = major_prestige_value
			}
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = {
				value = major_prestige_value
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		# Domination Effects
		# Iterate the Domitans Tribunal and Domination War counters
		global_var:magister_character = {
			change_variable = {
				name = regula_domitans_tally
				add = 1
			}
		}
		global_var:magister_character = {
			change_variable = {
				name = regula_domination_war_tally
				add = 1
			}
		}
		scope:defender = {
			# Domitans pregnancy trigger.
			if = {
				limit = {
					is_pregnant = yes
				}
				random = {
					chance = 25
					trigger_event = regula_paelex_event.1040
				}
			}
			# Spouses, if any exist, are removed.
			if = {
				limit = {
					is_married = yes
				}
				if = {
					limit = { 
						NOT = { 
							is_consort_of = scope:attacker
						}
					}
					every_spouse = {
						if = {
							limit = {
								is_spouse_of = scope:defender
							}
							add_opinion = {
								target = scope:attacker
								modifier = forced_spouse_concubine_marriage_opinion
							}
							scope:defender = {
								divorce = prev # no opinion hit, no scripted effect
							}
						}
						else_if = {
							limit = {
								scope:defender = {
									is_concubine_of = prev
								}
							}
							add_opinion = {
								target = scope:attacker
								modifier = stole_concubine_opinion
							}
							remove_concubine = scope:defender
						}
					}
				}
			}
					
			# Stealing concubines pisses the former concubinist off.
			if = {
				limit = {
					is_concubine = yes
					NOT = { is_concubine_of = scope:attacker }
				}
				this.concubinist = {
					if = {
						limit = {
							is_spouse_of = scope:defender
						}
						add_opinion = {
							target = scope:attacker
							modifier = forced_spouse_concubine_marriage_opinion
						}
						scope:defender = {
							divorce = prev # no opinion hit, no scripted effect
						}
					}
					else_if = {
						limit = {
							scope:defender = {
								is_concubine_of = prev
							}
						}
						add_opinion = {
							target = scope:attacker
							modifier = stole_concubine_opinion
						}
						remove_concubine = scope:defender
					}
				}
			}

			# Break any betrothals which may exist (without additional opinion penalties).
			if = {
				limit = { exists = betrothed }
				betrothed = { 
					if = {
						limit = {
							is_spouse_of = scope:defender
						}
						add_opinion = {
							target = scope:attacker
							modifier = forced_spouse_concubine_marriage_opinion
						}
						scope:defender = {
							divorce = prev # no opinion hit, no scripted effect
						}
					}
				}
				break_betrothal = betrothed
			}
		}
		if = { # Redirect towards domina events. UPDATE - Non-functional
			limit = {
				OR = {
					scope:attacker.primary_spouse = scope:defender
					scope:attacker = {
						is_married = no
					}
				}
			}
			scope:attacker = {
				marry = scope:defender 
				hidden_effect = {
					every_spouse = {
						remove_opinion = {
							modifier = polygamous_marriage_opinion
							target = scope:attacker
						}
					}
				}
				trigger_event = {
					id = regula_paelex_event.1009
					days = 7
				}
			}
		}
		else = { # Paelex events.
			scope:attacker = {
				marry = scope:defender 
				hidden_effect = {
					every_spouse = {
						remove_opinion = {
							modifier = polygamous_marriage_opinion
							target = scope:attacker
						}
					}
				}
				trigger_event = {
					id = regula_paelex_event.1009
					days = 7
				}
			}
		}

		# Truce
		add_truce_attacker_victory_effect = yes
				
	}

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

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = minor_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = regula_dominate_female_ruler_war_white_peace_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = regula_dominate_female_ruler_war_defeat_desc_attacker
			}
			desc = regula_dominate_female_ruler_war_white_peace_desc
		}
	}
	
	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold = {
				gold = 3
				target = scope:defender
				yearly_income = yes
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the defender
		scope:defender = {
			add_prestige = {
				value = medium_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = major_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = major_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		scope:attacker = {
			save_temporary_scope_as = loser
		}

		# Truce
		add_truce_attacker_defeat_effect = yes
		
		on_lost_aggression_war_discontent_loss = yes
	}
	
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "REGULA_DOMINATION_WAR_NAME"
	war_name_base = "REGULA_DOMINATION_WAR_NAME_BASE"
	cb_name = "REGULA_DOMINATION_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
}


regula_servitude_faction_war = {
	group = civil_war
	ai_only_against_liege = yes
	target_titles = independence_domain
	allowed_for_character = {
		scope:attacker = {
			is_leading_faction_type = regula_servitude_faction
		}
	}

	allowed_against_character = {
		scope:attacker = {
			liege = scope:defender
			scope:defender = {
				NOT = { has_trait = magister_trait_group }
				NOT = {
					any_ally = {
						has_trait = magister_trait_group
					}
				}
				NOT = {
					faith = {
						religion_tag = regula_religion
					}
				}
				NOT = {
					any_character_war = {
						is_attacker = global_var:magister_character
						using_cb = regula_dominate_female_ruler_war
					}
				}
				NOT = {
					any_character_war = {
						is_attacker = global_var:magister_character
						using_cb = regula_claim_vassal_war
					}
				}
			}
		}
	}

	target_de_jure_regions_above = yes

	valid_to_start = {

	}

	on_declaration = {
		#on_declared_war = yes
	}

	on_victory_desc = {  # Should be visible to AI only.
		first_valid = {
			triggered_desc = {
				trigger = { # Desc for only one player attacker
					scope:attacker = {
						is_local_player = yes
						joined_faction = {
							any_faction_member = {
								count = 1
							}
						}
					}
				}
				desc = independence_war_victory_desc_local_player_attacker_alone
			}
			triggered_desc = { # Desc for only one attacker, player defender
				trigger = {
					scope:defender = {
						is_local_player = yes
					}
					scope:attacker = {
						joined_faction = {
							any_faction_member = {
								count = 1
							}
						}
					}
				}
				desc = independence_war_victory_desc_local_player_defender_attacker_alone
			}
			triggered_desc = { # Desc for player attacker
				trigger = {
					scope:attacker.joined_faction = {
						any_faction_member = { is_local_player = yes }
					}
				}
				desc = regula_servitude_war_victory_desc_local_player_attacker
			}
			triggered_desc = { # Desc for player defender
				trigger = { scope:defender = { is_local_player = yes } }
				desc = independence_war_victory_desc_local_player_defender
			}
			desc = regula_servitude_war_victory_desc # Desc for a third party involved
		}
		
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:attacker.joined_faction = {
			every_faction_member = {
				change_liege = {
					liege = global_var:magister_character
					CHANGE = scope:change
				}
			}
		}
		scope:attacker = {
			if = {
				limit = {
					is_ai = yes
				}
				add_prestige = medium_prestige_value
				add_piety = medium_piety_value
			}
		}
		# Iterate the servitude war counter
		global_var:magister_character = {
			change_variable = {
				name = regula_servitude_war_tally
				add = 1
			}
		}
		global_var:magister_character = {
			send_interface_message = {  # Let the MC know the war is won.
				type = event_war_good
				title = regula_servitude_faction_victory_notification.t
				desc = regula_servitude_faction_victory_notification_desc 
				right_icon = scope:attacker
				left_icon = scope:defender
			}
			add_prestige = major_prestige_value
		}

		scope:defender = {
			add_prestige = {
				value = medium_prestige_value
				multiply = -1
			}
			if = {
				limit = { has_realm_law = crown_authority_1 }
				add_realm_law = crown_authority_0
			}
			if = {
				limit = { has_realm_law = crown_authority_2 }
				add_realm_law = crown_authority_1
			}
			if = {
				limit = { has_realm_law = crown_authority_3 }
				add_realm_law = crown_authority_2
			}
		}
		resolve_title_and_vassal_change = scope:change	
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = regula_servitude_war_white_peace_defender_desc
			}
			triggered_desc = {
				trigger = {
					scope:attacker.joined_faction = {
						any_faction_member = { is_local_player = yes }
					}
				}
				desc = regula_servitude_war_white_peace_attacker_desc
			}
			desc = regula_servitude_war_white_peace_desc
		}
		desc = regula_servitude_war_white_peace_end_desc
		
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		hidden_effect = {
			scope:attacker = {
				if = {
					limit = { is_ai = yes }
					add_truce_both_ways = {
						character = scope:defender
						days = 1825
						war = root.war
						result = white_peace
					}
					joined_faction = {
						add_faction_discontent = -200
					}
				}
			}
		}

		scope:defender = {
			add_character_flag = {
				flag = recent_regula_servitude_faction_war
				years = faction_war_white_peace_cooldown
			}
			add_prestige = minor_prestige_value
		}
		global_var:magister_character = {
			send_interface_message = {  # Let the MC know the war is lost.
				type = event_war_bad
				title = regula_servitude_faction_defeat_notification.t
				right_icon = scope:attacker
				left_icon = scope:defender			
				desc = regula_servitude_faction_defeat_notification_desc
			}
			add_prestige = major_prestige_value
		}
		on_white_peace_faction_revolt_war = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = independence_defeat_defender_desc
			}
			triggered_desc = {
				trigger = {
					scope:attacker.joined_faction = {
						any_faction_member = { is_local_player = yes }
					}
				}
				desc = regula_servitude_war_defeat_attacker_desc
			}
			desc = regula_servitude_war_player_defeat_desc #same loc as for player
		}
		desc = regula_servitude_war_defeat_end_desc
		
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		scope:defender = {
			add_character_flag = {
				flag = recent_regula_servitude_faction_war
				years = faction_war_defeat_cooldown
			}
			add_dread = medium_dread_gain
			# Prestige for Defender
			add_prestige = medium_prestige_value
		}
		global_var:magister_character = {
			send_interface_message = {  # Let the MC know the war is lost.
				type = event_war_bad
				title = regula_servitude_faction_defeat_notification.t
				right_icon = scope:attacker
				left_icon = scope:defender			
				desc = regula_servitude_faction_defeat_notification_desc
			}
			add_prestige = major_prestige_value
		}
		on_lost_faction_revolt_war = yes
	}

	on_invalidated_desc = msg_invalidate_war_title

	check_defender_inheritance_validity = yes

	on_primary_attacker_death = inherit_faction
	on_primary_defender_death = inherit

	transfer_behavior = transfer

	attacker_allies_inherit = no
	defender_allies_inherit = yes

	war_name = "REGULA_SERVITUDE_WAR_NAME"

	interface_priority = 80

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 1.0
	defender_wargoal_percentage = 0.0 # A single occupation will do
	defender_ticking_warscore_delay = { days = 0 } # No need for a delay here since the defender actually needs to occupy something rather than starting in control

	max_attacker_score_from_battles = 100
	max_defender_score_from_battles = 50

	max_ai_diplo_distance_to_title = 500
}
