﻿namespace = regula_initialize_event

# Free the Keeper of Souls
# Landed version
regula_initialize_event.0001 = {
	type = character_event
	title = regula_initialize_event.0001.t
	desc = {
		# What kind of Ritual?
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:desperate_initialize_reveal_decision = yes
				}
				desc = regula_initialize_event.0001.desperate_desc
			}
			triggered_desc = {
				trigger = {
					scope:modest_initialize_reveal_decision = yes
				}
				desc = regula_initialize_event.0001.modest_desc
			}
			triggered_desc = {
				trigger = {
					scope:glorious_initialize_reveal_decision = yes
				}
				desc = regula_initialize_event.0001.glorious_desc
			}
		}

		# Do we have wife?
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { scope:desperate_initialize_reveal_decision = yes }
					exists = scope:domina
				}
				desc = regula_initialize_event.0001.wife_desc
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:desperate_initialize_reveal_decision = yes }
					NOT = { exists = scope:domina }
				}
				desc = regula_initialize_event.0001.no_wife_desc
			}
		}

		# Start ritual
		triggered_desc = {
			trigger = {
				NOT = { scope:desperate_initialize_reveal_decision = yes }
			}
			desc = regula_initialize_event.0001.start_ritual_desc
		}
	}

	theme = regula_theme

	override_background = {
		reference = regula_workshop_night
	}

	right_portrait = {
		character = scope:domina
		animation = personality_zealous
	}

	immediate = {
		play_music_cue = "mx_cue_sacredrite"
		remove_character_flag = regula_decision_taken

		primary_spouse ?= {
			if = {
				limit = {
					any_secret = { secret_type = regula_covert_conversion }
				}

				save_scope_as = domina
				add_character_flag = is_naked
			}
		}
	}

	# Become the magister
	# Glorious Reveal
	option = {
		name = regula_initialize_event.0001.a
		add_internal_flag = special
		trigger = {
			scope:glorious_initialize_reveal_decision = yes
		}

		# Some misc effects to do
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
			add_piety_level = 2
		}
		add_trait = magister

		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}

	# Modest Reveal
	option = {
		name = regula_initialize_event.0001.a
		trigger = {
			scope:modest_initialize_reveal_decision = yes
		}

		# Some misc effects to do
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
			add_piety_level = 1
		}
		add_trait = magister

		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}

	# Desperate Reveal
	option = {
		name = regula_initialize_event.0001.a
		add_internal_flag = dangerous
		trigger = {
			scope:desperate_initialize_reveal_decision = yes
		}

		# Some misc effects to do
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
		}
		increase_wounds_no_death_effect = { REASON = wounds }
		add_trait = magister

		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}

	# Back out fully.
	option = {
		name = regula_initialize_event.0001.b
		flavor = regula_initialize_event.0001.b.flavor
		add_internal_flag = dangerous

		add_character_flag = {
			flag = regula_destroyed_character
		}

		random_secret = {
			limit = {
				secret_type = regula_covert_conversion
			}
			remove_secret = yes
		}
	}

	# Back out for now.
	option = {
		name = regula_initialize_event.0001.c
		flavor = regula_initialize_event.0001.c.flavor
	}

	# Debug: Skip all events and immediately become Magister
	option = {
		name = regula_initialize_event.0001.debug
		flavor = regula_initialize_event.0001.debug.flavor

		trigger = {
			debug_only = yes
		}

		# Core initialization
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }
		add_trait = magister

		hidden_effect = {
			add_piety_level = -5
			add_piety_level = 2
		}

		# Find closest faith, set region, apply all initialization effects
		regula_debug_free_keeper_of_souls_effect = yes
	}

	after = {
		scope:domina ?= {
			remove_character_flag = is_naked
		}
	}
}

# Unlanded version
regula_initialize_event.0002 = {
	type = character_event
	title = regula_initialize_event.0002.t
	desc = {
		# What kind of Ritual?
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:desperate_initialize_reveal_decision = yes
				}
				desc = regula_initialize_event.0002.desperate_desc
			}
			triggered_desc = {
				trigger = {
					scope:modest_initialize_reveal_decision = yes
				}
				desc = regula_initialize_event.0002.modest_desc
			}
			triggered_desc = {
				trigger = {
					scope:glorious_initialize_reveal_decision = yes
				}
				desc = regula_initialize_event.0002.glorious_desc
			}
		}

		# Do we have wife?
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { scope:desperate_initialize_reveal_decision = yes }
					exists = scope:domina
				}
				desc = regula_initialize_event.0002.wife_desc
			}
			triggered_desc = {
				trigger = {
					NOT = { scope:desperate_initialize_reveal_decision = yes }
					NOT = { exists = scope:domina }
				}
				desc = regula_initialize_event.0002.no_wife_desc
			}
		}

		# Start ritual
		triggered_desc = {
			trigger = {
				NOT = { scope:desperate_initialize_reveal_decision = yes }
			}
			desc = regula_initialize_event.0002.start_ritual_desc
		}
	}

	theme = regula_theme

	override_background = {
		reference = ep3_camp_night
	}

	right_portrait = {
		character = scope:domina
		animation = personality_zealous
	}

	immediate = {
		play_music_cue = "mx_cue_sacredrite"
		remove_character_flag = regula_decision_taken

		primary_spouse ?= {
			if = {
				limit = {
					any_secret = { secret_type = regula_covert_conversion }
				}

				save_scope_as = domina
				add_character_flag = is_naked
			}
		}
	}

	# Become the magister
	# Glorious Reveal
	option = {
		name = regula_initialize_event.0002.a
		add_internal_flag = special
		trigger = {
			scope:glorious_initialize_reveal_decision = yes
		}

		# Some misc effects to do
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
			add_piety_level = 2
		}
		add_trait = magister

		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}

	# Modest Reveal
	option = {
		name = regula_initialize_event.0002.a
		trigger = {
			scope:modest_initialize_reveal_decision = yes
		}

		# Some misc effects to do
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
			add_piety_level = 1
		}
		add_trait = magister

		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}

	# Desperate Reveal
	option = {
		name = regula_initialize_event.0002.a
		add_internal_flag = dangerous
		trigger = {
			scope:desperate_initialize_reveal_decision = yes
		}

		# Some misc effects to do
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
		}
		increase_wounds_no_death_effect = { REASON = wounds }
		add_trait = magister

		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}

	# Back out fully.
	option = {
		name = regula_initialize_event.0002.b
		flavor = regula_initialize_event.0002.b.flavor
		add_internal_flag = dangerous

		add_character_flag = {
			flag = regula_destroyed_character
		}

		random_secret = {
			limit = {
				secret_type = regula_covert_conversion
			}
			remove_secret = yes
		}
	}

	# Back out for now.
	option = {
		name = regula_initialize_event.0002.c
		flavor = regula_initialize_event.0002.c.flavor
	}

	# Debug: Skip all events and immediately become Magister
	option = {
		name = regula_initialize_event.0002.debug
		flavor = regula_initialize_event.0002.debug.flavor

		trigger = {
			debug_only = yes
		}

		# Core initialization
		regula_free_keeper_of_souls_misc_effect = yes
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = monumental }
		add_trait = magister

		hidden_effect = {
			add_piety_level = -5
			add_piety_level = 2
		}

		# Find closest faith, set region, apply all initialization effects
		regula_debug_free_keeper_of_souls_effect = yes
	}

	after = {
		scope:domina ?= {
			remove_character_flag = is_naked
		}
	}
}

regula_initialize_event.0004 = { # Primary wife conversion.
	type = character_event
	title = regula_initialize_event.0004.t
	desc = regula_initialize_event.0004.desc

	theme = regula_theme

	override_background = {
		reference = bedchamber
	}

	right_portrait = {
		character = scope:recipient
		animation = reading
	}

	immediate = {
		play_music_cue = "mx_cue_sacredrite"
		scope:recipient = {
			regula_secret_conversion = { CONVERTER = scope:actor }
		}
	}

	option = {
		name = regula_initialize_event.0004.a
	}
}

regula_initialize_event.0005 = { # Character converted. Letter event.
	type = letter_event
	opening = {
		desc = regula_initialize_event.0005.opening
	}
	desc = regula_initialize_event.0005.desc
	sender = scope:recipient

	immediate = {
		scope:recipient = {
			regula_secret_conversion = { CONVERTER = scope:actor }
		}
	}

	option = {
		name = regula_initialize_event.0005.a
	}
}

regula_initialize_event.0006 = { # They ask for money.
	type = letter_event
	opening = {
		desc = regula_initialize_event.0006.opening
	}
	desc = regula_initialize_event.0006.desc
	sender = scope:recipient

	immediate = {
	}

	#Accept
	option = {
		name = regula_initialize_event.0006.a
		pay_short_term_gold = {
			target = scope:recipient
			gold = minor_gold_value
		}

		stress_impact = {
			greedy = minor_stress_impact_gain
		}

		scope:recipient = {
			regula_secret_conversion = { CONVERTER = scope:actor }
		}
	}

	#Refuse
	option = {
		name = regula_initialize_event.0006.b
	}

	#Use a Hook to force it through
	option = {
		name = regula_initialize_event.0006.c
		trigger = {
			has_strong_usable_hook = scope:recipient
		}
		use_hook = scope:recipient

		scope:recipient = {
			regula_secret_conversion = { CONVERTER = scope:actor }
		}
	}
}


regula_initialize_event.0007 = { # Character not converted. No major effect. Letter event.
	type = letter_event
	opening = {
		desc = regula_initialize_event.0007.opening
	}
	desc = regula_initialize_event.0007.desc
	sender = scope:recipient

	immediate = {
		scope:recipient = {
		}
	}

	option = {
		name = regula_initialize_event.0007.a
	}
}

regula_initialize_event.0008 = { # Covert secret revealed.
	type = character_event
	title = regula_initialize_event.0008.t
	desc = regula_initialize_event.0008.desc

	theme = regula_theme

	override_background = {
		reference = corridor_night
	}

	right_portrait = {
		character = root
		animation = poison
	}

	option = {
		name = regula_initialize_event.0008.a
		flavor = regula_initialize_event.0008.a.tt
		add_character_flag = {
			flag = regula_forced_start
		}
		add_realm_law_skip_effects = regula_magister_gender_law
		add_trait = magister
		hidden_effect = {
			increase_wounds_no_death_effect = { REASON = wounds }
		}
		increase_wounds_no_death_effect = { REASON = wounds }
		add_piety_level = -5  # Because set_piety_level doesn't exist.
		set_global_variable = {
			name = regula_initialized
			value = yes
		}
		trigger_event = {
			id = regula_holy_site_event.0001
		}
	}
}

regula_initialize_event.0009 = { # Maintain covert gender succession law.
	hidden = yes
	type = character_event

	trigger = {
		is_male = no
		is_landed = yes
		any_secret = {
			secret_type = regula_covert_conversion
		}
		regula_is_regula_trigger = no
		NOT = { has_trait = devoted_trait_group }
	}

	immediate = {
		if = {
			limit = {
				NOT = { has_realm_law = regula_covert_vassal_succession_law }
			}
			add_realm_law_skip_effects = regula_covert_vassal_succession_law
		}
	}
}


regula_initialize_event.0010 = { # Once more into the breach.
	type = character_event
	title = regula_initialize_event.0010.t
	desc = regula_initialize_event.0010.desc

	theme = realm

	right_portrait = {
		character = root
		animation = stress
	}

	trigger = {
		is_ai = no
		is_male = yes
		age >= 16
		has_global_variable = regula_initialized
		NOT = { has_global_variable = regula_burned }
		NOT = {
			regula_is_magister = yes
			has_character_flag = regula_destroyed_character
		}
	}

	immediate = {
		play_music_cue = "mx_cue_sacredrite"
		remove_character_flag = regula_decision_taken
	}

	option = {
		name = regula_initialize_event.0010.a
		add_piety_level = -5  # Because set_piety_level doesn't exist.
		hidden_effect = {
			add_piety_level = 1
		}
		add_trait = magister
		set_character_faith = global_var:magister_character.faith

		hidden_effect = {
			regula_initialize_magister_effect = yes
		}
		trigger_event = {
			on_action = regula_title_law_maint
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0010.b	# Disable the Magister traits.
		custom_tooltip = regula_initialize_event.0010.b.tt
		hidden_effect = {

			add_character_flag = {
				flag = regula_destroyed_character
			}
			set_global_variable = {  # Sets up a magister scope.
				name = regula_burned
				value = yes
			}
			while = {
				limit = {
					list_size = {
						name = regula_undying_character_list
						value > 0
					}
				}
				every_in_list = {
					list = regula_undying_character_list
					remove_from_list = regula_undying_character_list
					death = {
						death_reason = death_vanished
					}
				}
			}
		}
	}
}

# Re-initializes the mod, for those that previously destroyed the book and for those on the covert chain.
regula_initialize_event.0011 = {
	type = character_event
	title = regula_initialize_event.0011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_global_variable = regula_initialized
				}
				desc = regula_initialize_event.0011.burned_desc
			}
			desc = regula_initialize_event.0011.covert_desc
		}
	}
	theme = realm

	override_background = {
		reference = study
	}

	right_portrait = {
		character = root
		animation = personality_rational
	}

	immediate = {
		remove_character_flag = regula_decision_taken
	}

	option = { # Become a Magister.
		trigger = { has_global_variable = regula_initialized }
		name = regula_initialize_event.0011.a

		hidden_effect = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
			add_piety_level = 1
		}
		add_trait = magister
		set_character_faith = global_var:magister_character.faith

		hidden_effect = {
			regula_initialize_magister_effect = yes
		}

		remove_global_variable = regula_burned
		if = {
			limit = { NOT = { has_realm_law = regula_magister_gender_law } }
			add_realm_law_skip_effects = regula_magister_gender_law
		}
		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			if = {
				limit = { NOT = { has_realm_law = regula_vassal_succession_law } }
				add_realm_law_skip_effects = regula_vassal_succession_law
			}
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = { # Burn it.
		name = regula_initialize_event.0011.b
		custom_tooltip = regula_initialize_event.0011.b.tt
		trigger = { has_global_variable = regula_initialized }
		hidden_effect = {
			add_character_flag = {
				flag = regula_destroyed_character
			}
			every_in_global_list = {
				list = regula_undying_character_list
				death = {
					death_reason = death_vanished
				}
			}
		}
	}

	option = { # Gain the Conversion Secret
		trigger = { NOT = { has_global_variable = regula_initialized } }
		name = regula_initialize_event.0011.c

		# Reveal the conversion secret to new potential Magister
		regula_secret_reboot = yes
		add_secret = {
			type = regula_covert_conversion
		}
	}

	option = { # Cast it into the fire!
		trigger = { NOT = { has_global_variable = regula_initialized } }
		name = regula_initialize_event.0011.d
		custom_tooltip = regula_initialize_event.0011.d.tt

		hidden_effect = {
			add_character_flag = {
				flag = regula_destroyed_character
			}
			every_in_global_list = {
				list = regula_undying_character_list
				death = {
					death_reason = death_vanished
				}
			}
		}
	}
}

# Keep the Compeditae Election humming
regula_initialize_event.0013 = {
	type = character_event
	hidden = yes

	trigger = {
		is_ai = no
		any_held_title = {
			has_title_law = compeditae_elective_succession_law
		}
	}

	immediate = {
		every_held_title = {
			limit = {
				NOT = { this = root.primary_title }
				is_titular = no
				NOR = {
					has_title_law = compeditae_lower_title_succession_law
					has_title_law = compeditae_elective_succession_law
				}
			}
			add_title_law = compeditae_lower_title_succession_law
		}
		if = {
			limit = {
				NOT = { has_character_modifier = regula_compeditae_succession_modifier }
			}
			add_character_modifier = regula_compeditae_succession_modifier
		}
	}
}

# Ensures that any Regula Mercenary companies have female commanders.
regula_initialize_event.0014 = {
	type = character_event
	hidden = yes

	trigger = {
		# Check they are a mercenary
		has_government = mercenary_government
		# Check if they should have female leaders
		culture = {
			has_cultural_pillar = martial_custom_regula
		}
	}

	immediate = {

		# If we dont have female sucession, change it so we do
		if = {
			limit = {
				NOT = { has_realm_law = regula_vassal_succession_law }
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}

		# If the current ruler is a man, abdicate to a female commander
		if = {
			limit = {
				is_male = yes
			}

			create_character = {
				template = mercenary
				dynasty = none
				location = root.location
				culture = root.culture
				faith = root.faith
				gender = female
				save_scope_as = new_leader
			}

			# Change our titles for women
			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_held_title = {
				change_title_holder_include_vassals = {
					holder = scope:new_leader
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change

			# Also generate some female commanders, similar to how we do holy orders
			while = {
				count = 2
				create_character = {
					template = mercenary
					employer = scope:new_leader
					culture = scope:new_leader.culture
					faith = scope:new_leader.faith
					gender = female
					age = { 25 30 }
				}
			}

			while = {
				count = 3
				create_character = {
					template = mercenary
					employer = scope:new_leader
					culture = scope:new_leader.culture
					faith = scope:new_leader.faith
					gender = female
					age = { 18 25 }
				}
			}

			# Get rid of male commanders (that still exist)
			scope:new_leader = {
				every_courtier = {
					limit = { is_female = no }
					death = { death_reason = death_vanished }
				}
			}

			# At last, the old mercenary leader vanishes into the night
			death = { death_reason = death_vanished }
		}
	}
}

# Removes and adds the scaling Paelex/Traopaeum modifiers for Magister to refresh value
regula_initialize_event.0015 = {
	hidden = yes
	type = character_event

	# This should only trigger for Player Magister
	trigger = {
		is_ai = no
		regula_is_magister = yes
	}

	# We simply remove and replace the modifier, to keep it up to date
	immediate = {
	
		remove_all_character_modifier_instances = regula_paelex_realm_benefits_low
		remove_all_character_modifier_instances = regula_regina_paelex_realm_benefits
		remove_all_character_modifier_instances = regula_ducissa_paelex_realm_benefits
		remove_all_character_modifier_instances = regula_comitissa_paelex_realm_benefits
		remove_all_character_modifier_instances = regula_paelex_unlanded_penalty
		remove_all_character_modifier_instances = regula_magister_tropaeum_prestige

		if = {
			limit = {
				regula_num_leader_spouses > 0
				faith = { has_doctrine_parameter = regula_paelex_realm_benefits_low }
			}
			add_character_modifier = regula_paelex_realm_benefits_low
		}

		if = {
			limit = {
				regula_num_regina_paelex > 0
				NOT = { faith = { has_doctrine_parameter = regula_paelex_realm_benefits_low } }
			}
			add_character_modifier = regula_regina_paelex_realm_benefits
		}

		if = {
			limit = {
				regula_num_ducissa_paelex > 0
				NOT = { faith = { has_doctrine_parameter = regula_paelex_realm_benefits_low } }
			}
			add_character_modifier = regula_ducissa_paelex_realm_benefits
		}

		if = {
			limit = {
				regula_num_comitissa_paelex > 0
				NOT = { faith = { has_doctrine_parameter = regula_paelex_realm_benefits_low } }
			}
			add_character_modifier = regula_comitissa_paelex_realm_benefits
		}	
		
		if = {
			limit = {
				regula_num_unlanded_spouses > 0
				NOT = { faith = { has_doctrine_parameter = regula_paelex_realm_benefits_low } }
			}
			add_character_modifier = regula_paelex_unlanded_penalty
		}

		if = {
			limit = {
				regula_num_tropaeum > 0
			}
			add_character_modifier = regula_magister_tropaeum_prestige
		}
	}
}

# Removes and adds the scaling contubernalis modifiers for Magister to refresh value
regula_initialize_event.0016 = {
	hidden = yes
	type = character_event

	# This should only trigger for Player Magister
	trigger = {
		is_ai = no
		regula_is_magister = yes
		root.faith = { has_doctrine_parameter = regula_contubernalis_realm_benefits }
	}

	# We simply remove and replace the modifier, to keep it up to date
	immediate = {
	
		remove_all_character_modifier_instances = regula_contubernalis_realm_benefits

		if = {
			limit = {
				regula_contubernalis_renown > 0
		}
			}
			add_character_modifier = regula_contubernalis_realm_benefits
		}
}

# Restores the secret faith for devoted characters who was converted from Regula Magistri to other religion
regula_initialize_event.0017 = {
	hidden = yes
	type = character_event

	# All enchanted but without Regula magistri faith
	trigger = {
		regula_is_devoted_trigger = yes
		root.faith = {
			regula_is_regula_faith_trigger = no
		}
		OR = {
			NOT = {
				exists = root.secret_faith
			}
			root.secret_faith ?= {
				regula_is_regula_faith_trigger = no
			}
		}
		exists = global_var:magister_character
	}

	immediate = {
		debug_log = "Restore secret faith"
		convert_to_regula_secretly_effect = {
			FAITH = global_var:magister_character.faith
		}
	}
}

# Makes any Regula holy orders have female commanders/knights.
regula_initialize_event.0018 = {
	type = character_event
	hidden = yes

	trigger = {
		# Check they are a holy order
		has_government = holy_order_government
		# Check if they should have female leaders
		culture = {
			has_cultural_pillar = martial_custom_regula
		}

		faith = {
			regula_is_regula_faith_trigger = yes
		}
	}

	immediate = {
		every_courtier = {
			limit = {
				is_male = yes
				is_lowborn = yes
			}
			death = { death_reason = death_vanished }
		}

		while = {
			limit = { 
				regula_num_courtiers < 5
			}
			random_list = {
				75 = {
					create_character = {
						save_scope_as = recruit
						template = regula_initiate_soldier_common_character
						employer = root
						culture = root.culture
						faith = root.faith
						gender = female
						age = { 18 25 }
					}
				}
				20 = {
					create_character = {
						save_scope_as = recruit
						template = regula_initiate_soldier_noble_character
						employer = root
						culture = root.culture
						faith = root.faith
						gender = female
						age = { 18 25 }
					}
				}
				5 = {
					create_character = {
						save_scope_as = recruit
						template = regula_initiate_soldier_royal_character
						employer = root
						culture = root.culture
						faith = root.faith
						gender = female
						age = { 18 25 }
					}
				}
			}
			scope:recruit = {
				add_trait = order_member
				add_trait = mulsa
			}
		}
	}
}

#Religious Tenet Choice
regula_initialize_event.0020 = {
	type = character_event
	title = regula_initialize_event.0020.t
	desc = regula_initialize_event.0020.desc

	override_background = {
		reference = regula_kos_reborn
	}

	theme = regula_theme

	option = {
		# Add Sacred Childbirth
		name = regula_initialize_event.0020.a
		flavor = regula_initialize_event.0020.a.flavor

		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_sacred_childbirth }
	}

	option = {
		#Replace with legacy tenet
		name = regula_initialize_event.0020.b
		flavor = regula_initialize_event.0020.b.flavor
		if = {
			limit = { global_var:regula_region = flag:mediterranean }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_sacred_shadows }
		}
		if = {
			limit = { global_var:regula_region = flag:europe }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_warmonger }
		}
		if = {
			limit = { global_var:regula_region = flag:asia }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_pursuit_of_power }
		}
		if = {
			limit = { global_var:regula_region = flag:east_asia }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_pursuit_of_knowledge }
		}
		if = {
			limit = { global_var:regula_region = flag:africa }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_ancestor_worship }
		}
		if = {
			limit = { global_var:regula_region = flag:special }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_astrology }
		}
	}

	option = {
		#Replace with syncretism tenet
		name = regula_initialize_event.0020.c
		flavor = regula_initialize_event.0020.c.flavor

		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_pluralism_fundamentalist }
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_pluralism_righteous }

		if = {
			limit = { global_var:regula_region = flag:mediterranean }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_islamic_syncretism }
		}
		if = {
			limit = { global_var:regula_region = flag:europe }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_christian_syncretism }
		}
		if = {
			limit = { global_var:regula_region = flag:asia }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_eastern_syncretism }
		}
		if = {
			limit = { global_var:regula_region = flag:east_asia }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_sinitic_syncretism }
		}
		if = {
			limit = { global_var:regula_region = flag:africa }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_unreformed_syncretism }
		}
		if = {
			limit = { global_var:regula_region = flag:special }
			regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = tenet_unreformed_syncretism }
		}
	}

	after = {
		trigger_event = regula_initialize_event.0021
	}
}

#Religious Tenet Choice - Harem style
regula_initialize_event.0021 = {
	type = character_event
	title = regula_initialize_event.0021.t
	desc = regula_initialize_event.0021.desc

	override_background = {
		reference = regula_kos_reborn
	}

	theme = regula_theme

	option = {
		add_internal_flag = special
		# Add Devoted tenet
		name = regula_initialize_event.0021.a
		flavor = regula_initialize_event.0021.a.flavor

		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_regula_harem_devoted }
	}

	option = {
		add_internal_flag = dangerous
		# Add Regula sacrifice tenet
		name = regula_initialize_event.0021.b
		flavor = regula_initialize_event.0021.b.flavor

		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_regula_harem_sacrifice }
	}

	after = {	
		trigger_event = regula_initialize_event.0023
	}
}
#Religious Tenet Choice - Futanari
regula_initialize_event.0023 = {
	type = character_event
	title = regula_initialize_event.0023.t
	desc = regula_initialize_event.0023.desc

	override_background = {
		reference = regula_kos_reborn
	}

	theme = regula_theme

	option = {
		trigger = {
			carn_is_futa_trigger = yes
		}
		add_internal_flag = special
		# Add Devoted tenet
		name = regula_initialize_event.0023.a
		flavor = regula_initialize_event.0023.a.flavor
		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_shunned }
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_venerated }
		
		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_homosexuality_shunned}
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_homosexuality_accepted }
	}

	option = {
		add_internal_flag = special
		# Add Regula sacrifice tenet
		name = regula_initialize_event.0023.b
		flavor = regula_initialize_event.0023.b.flavor
		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_shunned }
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_virtuous }
		
		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_homosexuality_shunned}
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_homosexuality_accepted }
	}
	option = {
		# Add Devoted tenet
		name = regula_initialize_event.0023.c
		flavor = regula_initialize_event.0023.c.flavor
		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_shunned }
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_accepted }
		
		regula_remove_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_homosexuality_shunned}
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = doctrine_homosexuality_accepted }
	}

	option = {
		trigger = {
			NOT = {
				carn_is_futa_trigger = yes
			}
		}
		name = regula_initialize_event.0023.d
		flavor = regula_initialize_event.0023.d.flavor
		
		regula_attach_doctrine_to_all_of_same_faith = { DOCTRINE = futa_doctrine_futanari_equality_shunned }
	}
	

	after = {	
		trigger_event = regula_initialize_event.0022
	}
}
# The Keeper explains the Magister trait tracks
# This is the "welcome to the mod" event that explains progression
regula_initialize_event.0022 = {
	type = character_event
	title = regula_initialize_event.0022.t
	desc = regula_initialize_event.0022.desc

	theme = regula_theme

	override_background = {
		reference = regula_kos_reborn
	}

	option = {
		name = regula_initialize_event.0022.a
		flavor = regula_initialize_event.0022.a.flavor
	}
}

regula_initialize_event.1030 = {
	type = character_event

	title = regula_initialize_event.1030.t
	desc = regula_initialize_event.1030.desc

	theme = regula_theme
	override_background = {
		reference = throne_room
	}

	left_portrait = {
		character = root
		animation = personality_bold
	}

	trigger = {
	}

	immediate = {
		play_music_cue = "mx_cue_epic_sacral_moment"
	}

	option = {
		name = regula_initialize_event.1030.a

		primary_title = {
			add_title_law = compeditae_elective_succession_law
		}
		if = {
			limit = {
				NOT = { has_character_modifier = regula_compeditae_succession_modifier }
			}
			add_character_modifier = regula_compeditae_succession_modifier
		}
		hidden_effect = {
			every_held_title = {
				limit = {
					NOT = { this = root.primary_title }
					is_titular = no
				}
				add_title_law = compeditae_lower_title_succession_law
			}
		}
	}
}

# Create your Regula Palace Holding
regula_initialize_event.1040 = {
		type = character_event

	title = regula_initialize_event.1040.t
	desc = regula_initialize_event.1040.desc

	theme = regula_theme
	override_background = {
		reference = throne_room
	}

	left_portrait = {
		character = root
		animation = personality_bold
	}

	immediate = {
		every_held_title = {
			title_province = {
				if = {
					limit = { has_holding_type = palace_holding }
					barony = {
						save_scope_as = palace_barony
					}
				}
			}
		}
	}

	option = {
		name = regula_initialize_event.1040.a

		scope:palace_barony = {
			set_capital_barony = yes
		}
		set_realm_capital = scope:palace_barony
	}

	option = {
		name = regula_initialize_event.1040.b
	}
}