﻿# this = a ruler, $TARGET$ = the other ruler.
# Removes every version of the marriage-ties opinion modifier this ruler holds toward the target.
nmt_remove_marriage_opinion_effect = {
	if = {
		limit = { has_opinion_modifier = { target = $TARGET$ modifier = nmt_marriage_truce_opinion } }
		remove_opinion = { target = $TARGET$ modifier = nmt_marriage_truce_opinion }
	}
	if = {
		limit = { has_opinion_modifier = { target = $TARGET$ modifier = nmt_marriage_truce_opinion_minimal } }
		remove_opinion = { target = $TARGET$ modifier = nmt_marriage_truce_opinion_minimal }
	}
	if = {
		limit = { has_opinion_modifier = { target = $TARGET$ modifier = nmt_marriage_truce_opinion_low } }
		remove_opinion = { target = $TARGET$ modifier = nmt_marriage_truce_opinion_low }
	}
	if = {
		limit = { has_opinion_modifier = { target = $TARGET$ modifier = nmt_marriage_truce_opinion_high } }
		remove_opinion = { target = $TARGET$ modifier = nmt_marriage_truce_opinion_high }
	}
	if = {
		limit = { has_opinion_modifier = { target = $TARGET$ modifier = nmt_ai_marriage_bond_opinion } }
		remove_opinion = { target = $TARGET$ modifier = nmt_ai_marriage_bond_opinion }
	}
}

# ---------------------------------------------------------------------------
# 'Attacking In-Laws' game rule
# ---------------------------------------------------------------------------
# this = the attacker, $TARGET$ = the in-law ruler they declared war on.
nmt_inlaw_war_penalty_effect = {
	if = {
		limit = { has_game_rule = nmt_inlaw_war_penalty_harsh }
		nmt_apply_inlaw_war_penalty_effect = { TARGET = $TARGET$ PRESTIGE = -250 MODIFIER = nmt_betrayed_inlaw_opinion_harsh }
	}
	else = {
		nmt_apply_inlaw_war_penalty_effect = { TARGET = $TARGET$ PRESTIGE = -100 MODIFIER = nmt_betrayed_inlaw_opinion_normal }
	}
}

# this = the attacker
nmt_apply_inlaw_war_penalty_effect = {
	save_scope_as = nmt_war_attacker
	add_prestige = $PRESTIGE$
	$TARGET$ = {
		add_opinion = { target = scope:nmt_war_attacker modifier = $MODIFIER$ }
	}
	# The spouses linking the two families: married into the attacker's family from
	# the target's side (remembered in-law ruler, or close family of the target).
	nmt_inlaw_war_spouse_effect = { TARGET = $TARGET$ MODIFIER = $MODIFIER$ }
	every_close_family_member = {
		limit = { is_alive = yes }
		nmt_inlaw_war_spouse_effect = { TARGET = $TARGET$ MODIFIER = $MODIFIER$ }
	}
	if = {
		limit = { is_ai = no }
		send_interface_toast = {
			type = event_toast_effect_bad
			title = nmt_inlaw_war_toast
			custom_tooltip = nmt_inlaw_war_details
			left_icon = $TARGET$
		}
	}
}

# this = the attacker or a close relative of the attacker
nmt_inlaw_war_spouse_effect = {
	every_spouse = {
		limit = {
			NOT = { this = $TARGET$ }
			NOT = { this = scope:nmt_war_attacker }
			OR = {
				AND = {
					exists = var:nmt_tie_ruler
					var:nmt_tie_ruler = $TARGET$
				}
				is_close_family_of = $TARGET$
			}
		}
		add_opinion = { target = scope:nmt_war_attacker modifier = $MODIFIER$ }
	}
}

# this = the human ruler. Gives one specific version of the modifier in both directions,
# after removing any other version so only one is ever held.
nmt_give_marriage_opinion_effect = {
	nmt_remove_marriage_opinion_effect = { TARGET = $RULER$ }
	$RULER$ = { nmt_remove_marriage_opinion_effect = { TARGET = $PLAYER$ } }
	add_opinion = {
		target = $RULER$
		modifier = $MODIFIER$
	}
	$RULER$ = {
		add_opinion = {
			target = $PLAYER$
			modifier = $MODIFIER$
		}
	}
}
