﻿# Create the grand wedding variables between the two characters, they must already have been betrothed by the code hook in the marry
# interaction or by manually setting a betrothal. For manual betrothal setting prefer using create_grand_wedding_betrothal.
# SPOUSE_1 = First spouse character
# SPOUSE_2 = Second spouse character
# HOST = Character promising to host the grand wedding
set_grand_wedding_betrothal_variables = {
	$SPOUSE_1$ = {
		set_variable = { name = promised_grand_wedding_by value = $HOST$ }
		save_scope_as = spouse_1
	}
	$SPOUSE_2$ = {
		set_variable = { name = promised_grand_wedding_by value = $HOST$ }
		save_scope_as = spouse_2
	}
	$HOST$ = {
		set_variable = {
			name = promised_grand_wedding_marriage_countdown
			value = $SPOUSE_1$
			years = grand_wedding_timeout
		}
		set_variable = {
			name = promised_grand_wedding_to
			value = $PROMISEE$
		}
		# Notification that the countdown has expired (one day before, to avoid getting the variable deleted before we have used it)
		trigger_event = {
			id = ep2_wedding.0001
			days = grand_wedding_timeout_notification
		}
	}
}

# Recreate the variables setup if the host dies and is replaced
wedding_update_hosting_variable_effect = {
	if = {
		limit = {
			scope:spouse_1 = { has_variable = promised_grand_wedding_by }
		}
		scope:spouse_1 = {
			remove_variable = promised_grand_wedding_by
			set_variable = { name = promised_grand_wedding_by value = scope:new_host }
		}
	}
	if = {
		limit = {
			scope:spouse_2 = { has_variable = promised_grand_wedding_by }
		}
		scope:spouse_2 = {
			remove_variable = promised_grand_wedding_by
			set_variable = { name = promised_grand_wedding_by value = scope:new_host }
		}
	}
	if = {
		limit = {
			scope:host = { has_variable = promised_grand_wedding_marriage_countdown }
		}
		scope:new_host = {
			set_variable = {
				name = promised_grand_wedding_marriage_countdown
				value = scope:spouse_1
				years = grand_wedding_timeout
			}
		}
	}
}

# Crease a betrothal between SPOUSE_1 and SPOUSE_2 with HOST promising to host a grand wedding
# SPOUSE_1 = First spouse character
# SPOUSE_2 = Second spouse character
# HOST = Character promising to host the grand wedding
create_grand_wedding_betrothal = {
	if =  {
		limit = {
			$SPOUSE_1$ = {
				is_female = yes
			}
		}
		$SPOUSE_1$ = {
			create_betrothal_matrilineal = $SPOUSE_2$
		}
	}
	else = {
		$SPOUSE_1$ = {
			create_betrothal = $SPOUSE_2$
		}
	}
	
	set_grand_wedding_betrothal_variables = {
		SPOUSE_1 = $SPOUSE_1$
		SPOUSE_2 = $SPOUSE_2$
		HOST = $HOST$
		PROMISEE = $PROMISEE$
	}
}

# Wedding Options on_start
wedding_normal_option_effect = {
	scope:host = {
		if = {
			limit = {
				any_vassal = {
					OR = {
						has_vassal_stance = parochial
						has_vassal_stance = zealot
					}
				}
			}
			every_vassal = {
				limit = {
					OR = {
						has_vassal_stance = parochial
						has_vassal_stance = zealot
					}
				}
				add_opinion = {
					target = scope:host
					modifier = wedding_balanced_option_opinion
				}
			}
		}
	}
}

wedding_good_option_effect = {
	scope:host = {
		if = {
			limit = {
				any_vassal = {
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = glory_hound
					}
				}
			}
			every_vassal = {
				limit = {
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = glory_hound
					}
				}
				add_opinion = {
					target = scope:host
					modifier = wedding_good_option_opinion
				}
			}
		}
	}
}
