code:
namespace = regula_corrupt_holy_order_event

regula_corrupt_holy_order_event.0001 = {
	type = character_event
	title = regula_corrupt_holy_order_event.0001.t
	desc = {
		desc = regula_corrupt_holy_order_event.0001.desc
		triggered_desc = {
			trigger = {
				NOT = { scope:order_founder = root }
				}
			desc = regula_corrupt_holy_order_event.0001.vassal.desc
		}
		desc = regula_corrupt_holy_order_event.0001.direct.desc
	}

	theme = regula_theme
	override_background = {
		event_background = regula_holy_order
	}
	right_portrait = {
		character = scope:order_founder
		animation = personality_bold
	}

	immediate = {
		if = {
			limit = {
				any_held_title = {
					barony_is_valid_for_holy_order_lease_cancellation_trigger = yes
					is_under_holy_order_lease = yes
					lessee_title.holder = {
						NOT = {
							faith = global_var:magister_character.faith
						}
						save_temporary_scope_as = infidel_grandmaster
					}
				}
			}
			scope:infidel_grandmaster = {
				save_scope_as = infidel_grandmaster2
				faith = {
					save_scope_as = corrupted_faith
					random_faith_holy_order = {
						limit = {
							leader = scope:infidel_grandmaster
						}
						save_scope_as = infidel_holy_order
						every_leased_title = {
							limit = {
								OR = {
									holder.top_liege = global_var:magister_character
									holder = global_var:magister_character
								}
								barony_is_valid_for_holy_order_lease_cancellation_trigger = yes
								tier = tier_barony
							}
							add_to_list = corruptible_titles
						}
					}
				}
				every_held_title = {
					limit = {
						holder.top_liege = global_var:magister_character
						barony_is_valid_for_holy_order_lease_cancellation_trigger = yes
						tier = tier_barony
					}
					add_to_list = corruptible_titles
				}
			}
		}
		else = {
			random_vassal_or_below = {
				limit = {
					has_trait = devoted_trait_group
					any_held_title = {
						barony_is_valid_for_holy_order_lease_cancellation_trigger = yes
						is_under_holy_order_lease = yes
						lessee_title.holder = {
							NOT = {
								faith = global_var:magister_character.faith
							}
							save_temporary_scope_as = infidel_grandmaster
						}
					}
				}
			}
			scope:infidel_grandmaster = {
				save_scope_as = infidel_grandmaster2
				faith = {
					save_scope_as = corrupted_faith
					random_faith_holy_order = {
						limit = {
							leader = scope:infidel_grandmaster
						}
						save_scope_as = infidel_holy_order
						every_leased_title = {
							limit = {
								OR = {
									holder.top_liege = global_var:magister_character
									holder = global_var:magister_character
								}
								barony_is_valid_for_holy_order_lease_cancellation_trigger = yes
								tier = tier_barony
							}
							add_to_list = corruptible_titles
						}
					}
				}
				every_held_title = {
					limit = {
						holder.top_liege = global_var:magister_character
						barony_is_valid_for_holy_order_lease_cancellation_trigger = yes
						tier = tier_barony
					}
					add_to_list = corruptible_titles
				}
			}
		}
		random_in_list = {
			list = corruptible_titles
			save_scope_as = corruptible_capital
			holder = {
				save_scope_as = order_founder
			}
		}
	}

	option = { # Corrupt order
		name = regula_corrupt_holy_order_event.0001.a

		custom_tooltip = corrupt_holy_order_decision_effect_message

		create_character = {
			template = holy_order_leader_character
			location = scope:corruptible_capital.title_province
			save_scope_as = leader
		}

		scope:corruptible_capital = {
			revoke_lease = yes
		}

		create_holy_order = {
			leader = scope:leader
			capital = scope:corruptible_capital
			save_scope_as = new_holy_order
		}
		every_in_list = {
			list = corruptible_titles
			if = {
				limit = {
					NOT = { this = scope:corruptible_capital }
				}
				revoke_lease = yes
				lease_out_to = scope:new_holy_order
			}
		}

		hidden_effect = {
			scope:leader = {
				add_gold = 100 #So that they have some money to lend out
				add_piety_level = 2
				add_gold = holy_order_starting_gold
				add_trait = lustful
				add_trait = mulsa
				every_courtier = {
					add_trait = order_member
					add_trait = mulsa
				}
			}

			# Messages
			global_var:magister_character = {
				send_interface_message = {
					type = holy_order_founded_message
					desc = regula_corrupt_holy_order_message
					left_icon = scope:leader
					right_icon = scope:new_holy_order.title
				}
			}
			every_ruler = {
				limit = {
					faith = scope:order_founder.faith
					NOT = { this = scope:order_founder }
					NOT = { this = global_var:magister_character }
				}
				send_interface_message = {
					type = holy_order_founded_message
					desc = someone_created_holy_order_message
					left_icon = scope:order_founder
					right_icon = scope:new_holy_order.title
				}
			}
			every_neighboring_top_liege_realm_owner = {
				limit = {
					NOT = { faith = scope:order_founder.faith }
				}
				send_interface_message = {
					type = enemy_holy_order_founded_message
					desc = other_faith_neighbor_created_holy_order_message
					left_icon = scope:order_founder
					right_icon = scope:new_holy_order.title
				}
			}
		}
		faith = {
			change_fervor = {
				value = 5
				desc = fervor_gain_holy_order_founded
			}
		}
		scope:corrupted_faith = {
			change_fervor = {
				value = -15
				desc = fervor_gain_holy_order_expelled_by_force
			}
		}

		trigger_event = regula_corrupt_holy_order_event.0002
	}

	option = { # Do nothing.
		name = regula_corrupt_holy_order_event.0001.b
		flavor = regula_corrupt_holy_order_event.0001.b.tt

		add_piety = 2000
	}
}

regula_corrupt_holy_order_event.0002 = {
	type = character_event
	title = regula_corrupt_holy_order_event.0002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:new_recruit = {
						has_trait = giant
					}
				}
				desc = regula_corrupt_holy_order_event.0002.giant.desc
			}
			desc = regula_corrupt_holy_order_event.0002.commander.desc
		}
	}

	theme = regula_theme
	override_background = {
		event_background = regula_holy_order_interior
	}
	left_portrait = {
		character = scope:left_portrait
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = personality_coward
	}
	right_portrait = {
		character = scope:new_recruit
		outfit_tags = { no_cloak no_hat no_pants no_clothes }
		animation = war_defender
	}

	immediate = {
		random = {
			chance = 50
			regula_create_champion_giant_effect = { WHO = scope:order_founder }
			scope:created_character = { save_scope_as = new_recruit }
			regula_create_orgy_guest_effect = { WHO = scope:order_founder }
			scope:created_orgy_guest = { save_scope_as = new_plaything }
		}
		if = {
			limit = { NOT = { exists = scope:new_recruit } }
			regula_create_commander_effect = { WHO = root }
			scope:created_character = { save_scope_as = new_recruit }
		}
		hidden_effect = {
			scope:new_recruit = {
				add_trait = lustful
				set_sexuality = bisexual
				add_trait = mulsa
			}
			if = {
				limit = { exists = scope:new_plaything }
				scope:new_plaything = {
					add_character_flag = regula_short
					add_trait = mulsa
					save_scope_as = left_portrait
				}
			}
		}
	}

	option = {
		name = regula_corrupt_holy_order_event.0002.a

		recruit_courtier = scope:new_recruit
	}
	option = {
		name = regula_corrupt_holy_order_event.0002.b
		trigger = {
			exists = scope:new_plaything
		}

		recruit_courtier = scope:new_recruit
		recruit_courtier = scope:new_plaything
	}
}


code:
namespace = regula_holy_site_event

# Decision point for demigod.
regula_holy_site_event.1001 = {
	type = character_event
	title = regula_holy_site_event.1001.t

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					faith = {
						controls_holy_site = reg_gotland
					}
				}
				desc = regula_holy_site_event.1001.european
			}
			triggered_desc = {
				trigger = {
					faith = {
						controls_holy_site = reg_carthage
					}
				}
				desc = regula_holy_site_event.1001.mediterranean
			}
			triggered_desc = {
				trigger = {
					faith = {
						controls_holy_site = reg_yazd
					}
				}
				desc = regula_holy_site_event.1001.alexandrian
			}
			triggered_desc = {
				trigger = {
					faith = {
						controls_holy_site = reg_jara
					}
				}
				desc = regula_holy_site_event.1001.west_africa
			}
		}
	}

	theme = regula_theme
	override_background = {
		event_background = throne_room
	}
	right_portrait = {
		character = scope:recipient
		animation = personality_content
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	option = { # Go ahead with it
		name = regula_holy_site_event.1001.a
		trigger_event = {
			id = regula_holy_site_event.1002
			days = { 15 45 }
		}
	}

	option = { # Abort
		name = regula_holy_site_event.1001.b

		remove_variable = regula_sanctifica_serva_in_progress
	}
}

# Preparations complete
regula_holy_site_event.1002 = {
	type = character_event
	title = regula_holy_site_event.1002.t
	desc = regula_holy_site_event.1002.desc
	theme = regula_theme
	override_background = {
		event_background = regula_ritual_site  ### UPDATE - Ritual site. Thomas chapel or Max procession?
	}
	right_portrait = { ### UPDATE - Need new poses
		character = scope:recipient
		animation = none
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	option = { # Go ahead with it
		name = regula_holy_site_event.1002.a

		add_piety = -750

		remove_variable = regula_sanctifica_serva_in_progress

		add_character_modifier = {
			modifier = regula_sanctifica_serva_penalty
			years = 5
		}
		scope:recipient = {
			add_diplomacy_skill =5
			add_martial_skill = 5
			add_stewardship_skill = 5
			add_intrigue_skill = 5
			add_learning_skill = 5
			add_prowess_skill = 10
			add_trait = regula_undying
			hidden_effect = {
				set_immortal_age = 25
			}
		}

		trigger_event = {
			id = regula_holy_site_event.1003
		}
	}

	option = { # Abort
		name = regula_holy_site_event.1002.b
		remove_variable = regula_sanctifica_serva_in_progress
		add_prestige = -250
	}
}

regula_holy_site_event.1003 = {  ### UPDATE - Sound: Verdi Requiem, Dies irae  https://youtu.be/ZDFFHaz9GsY?t=30
	type = character_event
	title = regula_holy_site_event.1003.t
	desc = {
		desc = regula_holy_site_event.1003.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = {
						highest_skill = diplomacy
					}
				}
				desc = regula_holy_site_event.1003.desc.diplomacy
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						highest_skill = martial
					}
				}
				desc = regula_holy_site_event.1003.desc.martial
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						highest_skill = stewardship
					}
				}
				desc = regula_holy_site_event.1003.desc.stewardship
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						highest_skill = intrigue
					}
				}
				desc = regula_holy_site_event.1003.desc.intrigue
			}
			triggered_desc = {
				trigger = {
					scope:recipient = {
						highest_skill = learning
					}
				}
				desc = regula_holy_site_event.1003.desc.learning
			}
		}
	}

	theme = regula_theme

	override_background = { ### UPDATE - Depending on how the triggered desc work these may have to be arranged back to front.
		trigger = {
			scope:recipient = {
				highest_skill = diplomacy
			}
		}
		event_background = regula_goddess_diplomacy # bastien-grivet-thenaiade-sd - pallet switch to red?
	}

	override_background = {
		trigger = {
			scope:recipient = {
				highest_skill = martial
			}
		}
		event_background = regula_goddess_martial # SamWhiteArt - Black angel
	}

	override_background = {
		trigger = {
			scope:recipient = {
				highest_skill = stewardship
			}
		}
		event_background = regula_goddess_stewardship # eduardo-pena-2-bird-goddess - forehead has Isis symbol.  OR ilya-vatutin-shailen-keeper-of-the-way
	}

	override_background = {
		trigger = {
			scope:recipient = {
				highest_skill = intrigue
			}
		}
		event_background = regula_goddess_intrigue # nina-is-curse-us
	}

	override_background = {
		trigger = {
			scope:recipient = {
				highest_skill = learning
			}
		}
		event_background = regula_goddess_learning # adrian-virlan-daily-sketch-30-process1
	}

	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	immediate ={
		play_music_cue = "regula_dies_irae"
		scope:recipient = {
			add_to_global_variable_list = {
				name = regula_undying_character_list
				target = scope:recipient
			}
			if = {
				limit = {
					highest_skill = diplomacy
				}
				give_nickname = regula_nickname_avatar_diplomacy
				add_character_flag = {
					flag = regula_goddess_diplomacy_trait
				}
			}
			else_if = {
				limit = {
					highest_skill = martial
				}
				give_nickname = regula_nickname_avatar_martial
				add_character_flag = {
					flag = regula_goddess_martial_trait
				}
			}
			else_if = {
				limit = {
					highest_skill = stewardship
				}
				give_nickname = regula_nickname_avatar_stewardship
				add_character_flag = {
					flag = regula_goddess_stewardship_trait
				}
			}
			else_if = {
				limit = {
					highest_skill = intrigue
				}
				give_nickname = regula_nickname_avatar_intrigue
				add_character_flag = {
					flag = regula_goddess_intrigue_trait
				}
			}
			else_if = {
				limit = {
					highest_skill = learning
				}
				give_nickname = regula_nickname_avatar_learning
				add_character_flag = {
					flag = regula_goddess_learning_trait
				}
			}
			carn_remove_all_wounds_effect = yes
			carn_remove_all_major_disfigurements_effect = yes
			carn_recover_from_all_diseases_effect = yes
			carn_remove_all_minor_disfigurements_effect = yes
		}
	}

	option = { # It is done.
		name = regula_holy_site_event.1003.a
	}
}

# Pregnancy gender adjustment
regula_holy_site_event.2000 = {
    hidden = yes

    trigger = {
		# faith = { religion_tag = regula_religion }
        faith = {
			controls_holy_site_with_flag = holy_site_reg_offspring_flag
        }
	}

	immediate = {
		random_list = {
			75 = {
				set_pregnancy_gender = female
			}
			25 = {
				set_pregnancy_gender = male
			}
		}
	}
}

regula_holy_site_event.2001 = {
    hidden = yes

    trigger = {
		# faith = { religion_tag = regula_religion }
		exists = global_var:regula_child_max
		global_var:regula_child_max = {
			compare_value >= regula_num_magister_children
		}
	}
	# trigger = {
	# 	# faith = { religion_tag = regula_religion }
	# 	exists = global_var:regula_child_max
	# 	if = {
	# 		limit = {
	# 			global_var:regula_child_max = 0
	# 		}
	# 	}
	# 	else_if = {
	# 		limit = {
	# 			global_var:regula_child_max = Two
	# 			regula_num_magister_children > 2
	# 		}
	# 	}
	# 	else_if = {
	# 		limit = {
	# 			global_var:regula_child_max = Four
	# 			regula_num_magister_children > 4
	# 		}
	# 	}
	# }

	immediate = {
		add_character_flag = carn_suppress_next_on_pregnancy_maintenance
		add_character_flag = carn_suppress_next_on_pregnancy_notification
		add_character_flag = carn_suppress_next_on_birth_notification
		end_pregnancy = yes
	}
}

# Christianity and Islam fervor adjustment
# regula_holy_site_event.2003 = {
# 	type = character_event
# 	hidden = yes
# 	trigger = {
# 		has_trait = magister_trait_group
# 		faith = {
# 			controls_holy_site_with_flag = 	holy_site_reg_jerusalem_flag
# 		}
# 	}

# 	immediate = {
# 		religion:christianity_religion = {
# 			every_faith = {
# 				change_fervor = -2.5
# 			}
# 		}
# 		religion:islam_religion = {
# 			every_faith = {
# 				change_fervor = -2.5
# 			}
# 		}
# 	}
# }

license: mit


code:
namespace = regula_initialize_event

regula_initialize_event.0001 = {
	type = character_event
	title = regula_initialize_event.0001.t
	desc = regula_initialize_event.0001.desc

	theme = regula_theme

	override_background = {
		event_background = regula_workshop_night
	}

	right_portrait = {
		character = root.primary_spouse
		animation = personality_zealous
	}

	immediate = {
		play_music_cue = "mx_cue_sacredrite"
		remove_character_flag = regula_decision_taken

		primary_spouse = {
			save_scope_as = domina
			add_character_flag = {
				flag = is_naked
				days = 7
			}
		}
	}

	# Become the magister
	option = {
		name = regula_initialize_event.0001.a
		show_as_tooltip = {
			add_realm_law_skip_effects = regula_magister_gender_law
		}
		set_character_faith = faith:regula_default
		add_trait = magister_2

		set_global_variable = {
			name = regula_initialized
			value = yes
		}
		trigger_event = {
			id = regula_initialize_event.0002
		}
	}

	# Back out.
	option = {
		name = regula_initialize_event.0001.b

		add_character_flag = {
			flag = regula_destroyed_character
		}

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

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

regula_initialize_event.0002 = {
	type = character_event
	title = regula_initialize_event.0002.t
	desc = regula_initialize_event.0002.desc

	theme = regula_theme

	override_background = {
		event_background = regula_kos_reborn
	}

	left_portrait = {
	}

	immediate = {
		play_music_cue = "regula_keeper_released"
		add_piety_level = -5  # Because set_piety_level doesn't exist.
		hidden_effect = { add_piety_level = 1 }

		remove_character_flag = regula_decision_taken

		set_global_variable = {
			name = regula_initialized
			value = yes
		}
		add_piety = 600
		add_prestige = 400

		hidden_effect = {
			regula_initialize_magister_effect = yes
			regula_secret_conversion_reveal_effect = yes
			set_up_dynamic_temporal_hof_title_effect = { NEW_HOLDER = root }
			scope:domina = {
				if = {
					limit = { is_landed = yes }
					remove_trait = mulsa
					add_trait = domina
					add_martial_skill = 2
					add_stewardship_skill = 2
					add_intrigue_skill = 2
					add_learning_skill = 2
					add_diplomacy_skill = 2
				}
			}
		}

		# TODO, safety check for whether magister is head of culture?
		global_var:magister_character.culture = {
			add_culture_tradition = tradition_magistri_submission
		}
	}

	option = {
		name = regula_initialize_event.0002.a
		flavor = regula_initialize_event.0002.a.tt

		custom_tooltip = regula_initialize_event.0002.a.tooltip
		hidden_effect = {
			faith:regula_default = {
				activate_holy_site = reg_jerusalem
				activate_holy_site = reg_brescia
				activate_holy_site = reg_alexandria
				activate_holy_site = reg_carthage
				activate_holy_site = reg_lesbos
			}
		}
		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.b
		flavor = regula_initialize_event.0002.b.tt
		custom_tooltip = regula_initialize_event.0002.b.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_rome
			activate_holy_site = reg_toulouse
			activate_holy_site = reg_krakow
			activate_holy_site = reg_gotland
			activate_holy_site = reg_zeeland
			}
		}

		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.c
		flavor = regula_initialize_event.0002.c.tt
		custom_tooltip = regula_initialize_event.0002.c.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_baghdad
			activate_holy_site = reg_veria
			activate_holy_site = reg_tyre
			activate_holy_site = reg_yazd
			activate_holy_site = reg_lahur
			}
		}

		root.capital_province.county = {
			set_county_faith = faith:regula_default
		}
		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.d
		flavor = regula_initialize_event.0002.d.tt
		custom_tooltip = regula_initialize_event.0002.d.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_djenne
			activate_holy_site = reg_wenyon
			activate_holy_site = reg_daura
			activate_holy_site = reg_jara
			activate_holy_site = reg_oyo
			}
		}

		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.e
		flavor = regula_initialize_event.0002.e.tt
		custom_tooltip = regula_initialize_event.0002.e.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_britain_dublin
			activate_holy_site = reg_britain_glamorgan
			activate_holy_site = reg_britain_gowrie
			activate_holy_site = reg_britain_middlesex
			activate_holy_site = reg_britain_west_riding
			}
		}

		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}
}

regula_initialize_event.0003 = { #Initialization of the Covert Chain
	type = character_event
	title = regula_initialize_event.0003.t
	desc = regula_initialize_event.0003.desc

	theme = realm

	override_icon = {
		reference = "gfx/interface/icons/event_types/regula_frame.dds"
	}

	override_background = {
		event_background = sitting_room
	}

	right_portrait = {
		character = root
		animation = personality_rational
	}

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

	option = {
		name = regula_initialize_event.0003.a

		regula_first_secret_conversion = yes

		set_global_variable = {
			name = regula_covert_initialized
			value = yes
		}
	}

		option = {
		name = regula_initialize_event.0003.b	# Back out.
	}
}

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 = {
		event_background = bedchamber
	}

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

	immediate = {
		play_music_cue = "regula_opening_book"
		scope:recipient = {
			regula_secret_conversion = yes
		}
	}

	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 = yes
		}
	}

	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 = yes
		}
	}

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

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 = {
		event_background = corridor_night
	}

	right_portrait = {
		character = root
		animation = poison
	}

	immediate = {
		root = {
			add_piety_level = -5  # Because set_piety_level doesn't exist.
			hidden_effect = { add_piety_level = 1 }
			set_character_faith = faith:regula_default
			add_trait = magister_2
			add_trait = wounded_2
			remove_character_flag = regula_decision_taken
			capital_province.county = {
				set_county_faith = faith:regula_default
			}
		}
		regula_initialize_magister_effect = yes
		set_global_variable = {
			name = regula_initialized
			value = yes
		}

	}

	option = {
		name = regula_initialize_event.0002.a
		flavor = regula_initialize_event.0002.a.tt

		custom_tooltip = regula_initialize_event.0002.a.tooltip
		hidden_effect = {
			faith:regula_default = {
				activate_holy_site = reg_jerusalem
				activate_holy_site = reg_brescia
				activate_holy_site = reg_alexandria
				activate_holy_site = reg_carthage
				activate_holy_site = reg_lesbos
			}
		}
		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.b
		flavor = regula_initialize_event.0002.b.tt
		custom_tooltip = regula_initialize_event.0002.b.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_rome
			activate_holy_site = reg_toulouse
			activate_holy_site = reg_krakow
			activate_holy_site = reg_gotland
			activate_holy_site = reg_zeeland
			}
		}

		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.c
		flavor = regula_initialize_event.0002.c.tt
		custom_tooltip = regula_initialize_event.0002.c.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_baghdad
			activate_holy_site = reg_veria
			activate_holy_site = reg_tyre
			activate_holy_site = reg_yazd
			activate_holy_site = reg_lahur
			}
		}

		root.capital_province.county = {
			set_county_faith = faith:regula_default
		}
		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}

	option = {
		name = regula_initialize_event.0002.d
		flavor = regula_initialize_event.0002.d.tt
		custom_tooltip = regula_initialize_event.0002.d.tooltip

		hidden_effect = {
			faith:regula_default = {
			# Holy Sites
			activate_holy_site = reg_djenne
			activate_holy_site = reg_wenyon
			activate_holy_site = reg_daura
			activate_holy_site = reg_jara
			activate_holy_site = reg_oyo
			}
		}

		add_realm_law_skip_effects = regula_magister_gender_law

		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
			}
			add_realm_law_skip_effects = regula_vassal_succession_law
		}
		trigger_event = {
			on_action = regula_initialize_complete_response
		}
	}
}

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

	trigger = {
		any_secret = {
			secret_type = regula_covert_conversion
		}
		NOT = {
			religion = {
				is_in_family = rf_regula
			}
		}
		NOT = { has_trait = devoted_trait_group }
	}

	immediate = {
		if = {
			limit = {
				is_male = no
			}
				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 = {
			has_trait = magister_trait_group
			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_2
		set_character_faith = global_var:magister_character.faith

		hidden_effect = {
			regula_initialize_magister_effect = yes
		}
		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 = {
		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 = {
		event_background = 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
		add_piety_level = -5  # Because set_piety_level doesn't exist.
		hidden_effect = {
			add_piety_level = 1
		}

		add_trait = magister_2
		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

		regula_secret_reboot = yes

	}

	option = { # Set it aside.
		trigger = { NOT = { has_global_variable = regula_initialized } }
		name = regula_initialize_event.0011.d

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

# Remove magister traits from characters that no longer follow the religion.
regula_initialize_event.0012 = {
	type = character_event
	hidden = yes

	trigger = {
		has_trait = magister_trait_group
		faith = {
			NOT = { has_doctrine_parameter = magister_tenet_traits }
		}
	}

	immediate = {
		if = {
			limit = {
				has_trait = magister_2
			}
			remove_trait = magister_2
			add_trait = magister_1
		}
		if = {
			limit = {
				has_trait = magister_3
			}
			remove_trait = magister_3
			add_trait = magister_1
		}
		if = {
			limit = {
				has_trait = magister_4
			}
			remove_trait = magister_4
			add_trait = magister_1
		}
		if = {
			limit = {
				has_trait = magister_5
			}
			remove_trait = magister_5
			add_trait = magister_1
		}
		if = {
			limit = {
				has_trait = magister_6
			}
			remove_trait = magister_6
			add_trait = magister_1
		}
	}
}

# 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
		}
	}
}

# Settings Menu
regula_initialize_event.1000 = {
	type = character_event
	title = regula_initialize_event.1000.t
	desc = regula_initialize_event.1000.desc

    theme = regula_theme

    override_background = {
		event_background = throne_room
	}

	# option = { # Tweak Suggestions Tab
	# 	name = regula_initialize_event.1000.a

	# 	trigger_event = {
	# 		id = regula_initialize_event.1001
	# 	}
	# }

	option = { # Religion
		name = regula_initialize_event.1000.b

		trigger = {
			religion = {
				is_in_family = rf_regula
			}
		}

		trigger_event = {
			id = regula_initialize_event.1010
		}
	}

	# option = { # Birth Control
	# 	name = regula_initialize_event.1000.c

	# 	trigger_event = {
	# 		id = regula_childhood_event.0020
	# 	}
	# }

	option = { # Wards
		name = regula_initialize_event.1000.d

		trigger_event = {
			id = regula_childhood_event.0010
		}
	}

	option = { # Stats
		name = regula_initialize_event.1000.e

		trigger_event = {
			id = regula_initialize_event.1003
		}
	}

	option = { # Notification Settings
		name = regula_initialize_event.1000.f

		trigger_event = {
			id = regula_initialize_event.1004
		}
	}

	option = { # Exit
		name = regula_initialize_event.1000.exit
	}
}

# Tweak Suggestions Tab
regula_initialize_event.1001 = {
	type = character_event
	title = regula_initialize_event.1001.t
	desc = regula_initialize_event.1001.desc
    theme = regula_theme

    override_background = {
		event_background = throne_room
	}

	option = {
		name = regula_initialize_event.1001.a

		trigger_event = {
			id = regula_initialize_event.1002
		}
	}

	option = {
		name = regula_initialize_event.1001.menu
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1001.exit
	}
}

# Suggestions Tab - Dominate Mulsa Suggestion
regula_initialize_event.1002 = {
	type = character_event
	title = regula_initialize_event.1002.t
	desc = regula_initialize_event.1002.desc
    theme = regula_theme

    override_background = {
		event_background = throne_room
	}

	immediate = {
	}

	# Dominate all
	option = {
		name = regula_initialize_event.1002.a
		flavor = regula_initialize_event.1002.a.tt
	}

	# Direct Vassals
	option = {
		name = regula_initialize_event.1002.b
	}

	# Hide the suggestion
	option = {
		name = regula_initialize_event.1002.c
	}

	option = {
		name = regula_initialize_event.1001.menu
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1001.exit
	}
}

# Stats
regula_initialize_event.1003 = {
	type = character_event
	title = regula_initialize_event.1003.t

	desc = {
		desc = regula_initialize_event.1003.desc_start
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_potestas_queen_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_1_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_potestas_queen_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_1_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_potestas_queen_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_1_f
			}
		}
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_servitude_war_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_2_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_servitude_war_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_2_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_servitude_war_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_2_f
			}
		}
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_domination_war_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_3_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_domination_war_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_3_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_domination_war_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_3_f
			}
		}
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_contubernalis_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_4_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_contubernalis_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_4_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_contubernalis_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_4_f
			}
		}
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_domitans_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_5_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_domitans_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_5_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_domitans_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_5_f
			}
		}
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_fascinare_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_6_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_fascinare_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_6_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_fascinare_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_6_f
			}
		}
		desc = line_break
		desc = line_break
		first_valid = {
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_single_life
					NOT = { global_var:regula_obedience_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_7_s
			}
			triggered_desc = {
				trigger = {
					has_game_rule = regula_bloodline_tally_goals_cumulative
					NOT = { global_var:regula_obedience_bloodline_active = yes }
				}
				desc = regula_initialize_event.1003.desc_7_c
			}
			triggered_desc = {
				trigger = {
					global_var:regula_obedience_bloodline_active = yes
				}
				desc = regula_initialize_event.1003.desc_7_f
			}
		}
	}

	right_portrait = {
		character = root
		animation = personality_rational
	}

	theme = regula_theme
	override_background = {
		event_background = throne_room
	}

	immediate = {
		global_var:regula_secret_keeper = {
			save_scope_as = dead_baby
			random_targeting_secret = {
				limit = {
					secret_type = regula_covert_conversion
					secret_owner = {
						is_male = yes
					}
				}
				save_scope_as = regula_secret
				scope:regula_secret.secret_owner = {
					save_scope_as = proto_magister
				}
			}
			every_targeting_secret = {
				reveal_to = scope:proto_magister
			}
		}
	}

	option = {
		name = regula_initialize_event.1001.menu
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1001.exit
	}
}

# Notification Settings
regula_initialize_event.1004 = {
	type = character_event
	title = regula_initialize_event.1004.t
	desc = regula_initialize_event.1004.desc

	theme = regula_theme
	override_background = {
		event_background = throne_room
	}

	immediate = {
		# Make sure Notification Settings are initialised
		if = {
			limit = {
				NOT = {
					has_global_variable = fascinare_events_enabled
				}
			}
			set_global_variable = {
				name = fascinare_events_enabled
				value = yes
			}
		}
		if = {
			limit = {
				NOT = {
					has_global_variable = ward_enslavement_events_enabled
				}
			}
			set_global_variable = {
				name = ward_enslavement_events_enabled
				value = yes
			}
		}
	}

	option = {
		name = regula_initialize_event.1004.a_on
		trigger = {
			global_var:fascinare_events_enabled = no
		}
		set_global_variable = {
			name = fascinare_events_enabled
			value = yes
		}
		trigger_event = {
			id = regula_initialize_event.1004
		}
	}

	option = {
		name = regula_initialize_event.1004.a_off
		trigger = {
			global_var:fascinare_events_enabled = yes
		}
		set_global_variable = {
			name = fascinare_events_enabled
			value = no
		}
		trigger_event = {
			id = regula_initialize_event.1004
		}
	}

	option = {
		name = regula_initialize_event.1004.b_on
		trigger = {
			global_var:ward_enslavement_events_enabled = no
		}
		set_global_variable = {
			name = ward_enslavement_events_enabled
			value = yes
		}
		trigger_event = {
			id = regula_initialize_event.1004
		}
	}

	option = {
		name = regula_initialize_event.1004.b_off
		trigger = {
			global_var:ward_enslavement_events_enabled = yes
		}
		set_global_variable = {
			name = ward_enslavement_events_enabled
			value = no
		}
		trigger_event = {
			id = regula_initialize_event.1004
		}
	}

	option = {
		name = regula_initialize_event.1001.menu
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1001.exit
	}
}

# Swap religion types.
regula_initialize_event.1010 = {
	type = character_event
	title = regula_initialize_event.1010.t
	desc = regula_initialize_event.1010.desc
    theme = regula_theme

    override_background = {
		event_background = throne_room
	}

	option = {
		name = regula_initialize_event.1010.a

		# faith = {
		# 	save_scope_as = old_faith
		# }
		# set_character_faith = faith:regula_default
		# # First, make sure everyone is the default faith (for backwards compatibility).
		# if = {
		# 	limit = {
		# 		NOT = {
		# 			scope:old_faith = faith:regula_default
		# 		}
		# 	}
		# 	if = {
		# 		limit = {
		# 			exists = faith.religious_head
		# 			root = faith.religious_head
		# 		}
		# 		faith = {
		# 			remove_religious_head_title = yes
		# 		}
		# 		set_character_faith = faith:regula_default
		# 		hidden_effect = {
		# 			regula_faith_swap = yes

		# 		}
		# 	}
		# 	else = {
		# 		hidden_effect = {
		# 			regula_faith_swap = yes
		# 		}
		# 	}

		# }
		# Now swap holy sites.
		faith = {
			hidden_effect = {
				regula_holy_site_deactivation = yes
			}
			# Holy Sites
			activate_holy_site = reg_jerusalem
			activate_holy_site = reg_brescia
			activate_holy_site = reg_alexandria
			activate_holy_site = reg_carthage
			activate_holy_site = reg_lesbos
		}
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1010.b

		# faith = {
		# 	save_scope_as = old_faith
		# }
		# set_character_faith = faith:regula_default
		# # First, make sure everyone is the default faith (for backwards compatibility).
		# if = {
		# 	limit = {
		# 		NOT = {
		# 			scope:old_faith = faith:regula_default
		# 		}
		# 	}
		# 	if = {
		# 		limit = {
		# 			exists = faith.religious_head
		# 			root = faith.religious_head
		# 		}
		# 		faith = {
		# 			remove_religious_head_title = yes
		# 		}
		# 		set_character_faith = faith:regula_default
		# 		hidden_effect = {
		# 			regula_faith_swap = yes

		# 		}
		# 	}
		# 	else = {
		# 		hidden_effect = {
		# 			regula_faith_swap = yes
		# 		}
		# 	}

		# }
		# Now swap holy sites.
		faith = {
			hidden_effect = {
				regula_holy_site_deactivation = yes
			}
			# Holy Sites
			activate_holy_site = reg_rome
			activate_holy_site = reg_toulouse
			activate_holy_site = reg_krakow
			activate_holy_site = reg_gotland
			activate_holy_site = reg_zeeland

		}
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1010.c

		faith = {
			hidden_effect = {
				regula_holy_site_deactivation = yes
			}
			# Holy Sites
			activate_holy_site = reg_baghdad
			activate_holy_site = reg_veria
			activate_holy_site = reg_tyre
			activate_holy_site = reg_yazd
			activate_holy_site = reg_lahur
		}
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1010.d

		faith = {
			hidden_effect = {
				regula_holy_site_deactivation = yes
			}
			# Holy Sites
			activate_holy_site = reg_djenne
			activate_holy_site = reg_wenyon
			activate_holy_site = reg_daura
			activate_holy_site = reg_jara
			activate_holy_site = reg_oyo
		}
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1010.e

		faith = {
			hidden_effect = {
				regula_holy_site_deactivation = yes
			}
			# Holy Sites
			activate_holy_site = reg_britain_dublin
			activate_holy_site = reg_britain_glamorgan
			activate_holy_site = reg_britain_gowrie
			activate_holy_site = reg_britain_middlesex
			activate_holy_site = reg_britain_west_riding
		}
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1010.menu
		trigger_event = {
			id = regula_initialize_event.1000
		}
	}

	option = {
		name = regula_initialize_event.1010.exit
	}
}

regula_initialize_event.1030 = {
	type = character_event

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

	theme = regula_theme
	override_background = {
		event_background = 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
			}
		}
	}
}


code:
namespace = regula_stress_loss_sex_event

regula_stress_loss_sex_event.0001 = {
	hidden = yes

	trigger = {
		has_trait = devoted_trait_group # Fallback
		NOR = {
			has_trait = mulsa
			has_trait = orba
			has_trait = contubernalis
		}
		global_var:magister_character = {
			regula_num_landed_concubines >= 2
		}
	}

	immediate = {
		save_scope_as = stressed

		global_var:magister_character = {
			random_spouse = {
				limit = {
					has_trait = devoted_trait_group
				}
				weight = {
					base = 1

					modifier = {
						add = 15
						has_trait = lustful
					}
					modifier = {
						add = 25
						NOT = { has_sexuality = heterosexual }
					}
					modifier = {
						add = 25
						opinion = {
							target = scope:stressed
							value > 50
						}
					}
					modifier = {
						add = 75
						has_relation_lover = scope:stressed
					}
					modifier = {
						add = 50
						has_relation_soulmate = scope:stressed
					}
					modifier = {
						add = 25
						has_relation_friend = scope:stressed
					}
					modifier = {
						add = 50
						stress > medium_stress
					}
				}
				save_scope_as = stressed_partner
			}
		}
		carn_had_sex_with_effect = {
			CHARACTER_1 = scope:stressed
			CHARACTER_2 = scope:stressed_partner
			C1_PREGNANCY_CHANCE = 0
			C2_PREGNANCY_CHANCE = 0
			STRESS_EFFECTS = no
			DRAMA = no
		}
		global_var:magister_character = {
			send_interface_message = {
				type = event_spouse_task_good
				title = regula_stress_loss_sex_event.0001.t
				desc = regula_stress_loss_sex_event.0001.desc

				left_icon = scope:stressed
				right_icon = scope:stressed_partner

				scope:stressed = {  # UPDATE - This is going to be a lot.
					random_list = {
						20 = {
							modifier = {
								has_trait = lustful
								add = -20
							}
							add_trait = lustful
						}
						20 = {
							modifier = {
								has_sexuality = bisexual
								add = -20
							}
							modifier = {
								has_sexuality = homosexual
								add = -20
							}
							set_sexuality = bisexual
						}
						5 = {
							modifier = {
								has_sexuality = bisexual
								add = -5
							}
							modifier = {
								has_sexuality = homosexual
								add = -5
							}
							modifier = {
								has_trait = lustful
								add = -5
							}
							add_trait = lustful
							set_sexuality = bisexual
						}
						55 = {
							modifier = {
								has_sexuality = bisexual
								add = -20
							}
							modifier = {
								has_sexuality = homosexual
								add = -20
							}
							modifier = {
								has_trait = lustful
								add = -20
							}
						}
					}
					scope:stressed_partner = {
						random_list = {
							20 = {
								modifier = {
									has_trait = lustful
									add = -20
								}
								add_trait = lustful
							}
							20 = {
								modifier = {
									has_sexuality = bisexual
									add = -20
								}
								modifier = {
									has_sexuality = homosexual
									add = -20
								}
								set_sexuality = bisexual
							}
							5 = {
								modifier = {
									has_sexuality = bisexual
									add = -5
								}
								modifier = {
									has_sexuality = homosexual
									add = -5
								}
								modifier = {
									has_trait = lustful
									add = -5
								}
								add_trait = lustful
								set_sexuality = bisexual
							}
							55 = {
								modifier = {
									has_sexuality = bisexual
									add = -20
								}
								modifier = {
									has_sexuality= homosexual
									add = -20
								}
								modifier = {
									has_trait = lustful
									add = -20
								}
							}
						}
					}
					hidden_effect = {
						add_stress = -275
						scope:stressed_partner = {
							add_stress = -275
						}
						if = {
							limit = {
								can_set_relation_potential_lover_trigger = { CHARACTER = scope:stressed_partner }
							}
							hidden_effect = {
								set_relation_potential_lover = scope:stressed_partner
							}
						}
						else = {
							random = {
								chance = 40
								if = {
									limit = {
										can_set_relation_lover_trigger = { CHARACTER = scope:stressed_partner }
									}
								}
								set_relation_lover = scope:stressed_partner
							}
						}
					}
				}
			}
		}
	}
}

regula_stress_loss_sex_event.0002 = {
	hidden = yes

	trigger = {
		has_trait = mulsa
	}

	immediate = {
		# save_scope_as = stressed

		# global_var:magister_character = {
		# 	random_spouse = {
		# 		limit = {
		# 			has_trait = devoted_trait_group
		# 		}
		# 		weight = {
		# 			base = 1

		# 			modifier = {
		# 				add = 15
		# 				has_trait = lustful
		# 			}
		# 			modifier = {
		# 				add = 25
		# 				NOT = { has_sexuality = heterosexual }
		# 			}
		# 			modifier = {
		# 				add = 25
		# 				opinion = {
		# 					target = scope:stressed
		# 					value > 50
		# 				}
		# 			}
		# 			modifier = {
		# 				add = 75
		# 				has_relation_lover = scope:stressed
		# 			}
		# 			modifier = {
		# 				add = 50
		# 				has_relation_soulmate = scope:stressed
		# 			}
		# 			modifier = {
		# 				add = 50
		# 				scope:stressed_partner = {
		# 					stress > medium_stress
		# 				}
		# 			}
		# 		}
		# 		save_scope_as = stressed_partner
		# 	}
		# }
		# carn_had_sex_with_effect = {
		# 	CHARACTER_1 = scope:stressed
		# 	CHARACTER_2 = scope:stressed_partner
		# 	C1_PREGNANCY_CHANCE = 0
		# 	C2_PREGNANCY_CHANCE = 0
		# 	STRESS_EFFECTS = no
		# 	DRAMA = no
		# }
		# global_var:magister_character = {
		# 	send_interface_message = {
		# 		type = event_spouse_task_good
		# 		title = regula_stress_loss_sex_event.0001.t
		# 		desc = regula_stress_loss_sex_event.0001.desc

		# 		left_icon = scope:stressed
		# 		right_icon = scope:stressed_partner

		# 		scope:stressed = {  # UPDATE - This is going to be a lot.
		# 			add_stress = -275
		# 			scope:stressed_partner = {
		# 				add_stress = -275
		# 			}
		# 			random_list = {
		# 				20 = {
		# 					modifier = {
		# 						has_trait = lustful
		# 						add = -20
		# 					}
		# 					add_trait = lustful
		# 				}
		# 				20 = {
		# 					modifier = {
		# 						has_trait = bisexual
		# 						add = -20
		# 					}
		# 					modifier = {
		# 						has_trait = homosexual
		# 						add = -20
		# 					}
		# 					set_sexuality = bisexual
		# 				}
		# 				5 = {
		# 					modifier = {
		# 						has_trait = bisexual
		# 						add = -5
		# 					}
		# 					modifier = {
		# 						has_trait = homosexual
		# 						add = -5
		# 					}
		# 					modifier = {
		# 						has_trait = lustful
		# 						add = -5
		# 					}
		# 					add_trait = lustful
		# 					set_sexuality = bisexual
		# 				}
		# 				55 = {
		# 					modifier = {
		# 						has_trait = bisexual
		# 						add = -20
		# 					}
		# 					modifier = {
		# 						has_trait = homosexual
		# 						add = -20
		# 					}
		# 					modifier = {
		# 						has_trait = lustful
		# 						add = -20
		# 					}
		# 				}
		# 			}
		# 			scope:stressed_partner = {
		# 				random_list = {
		# 					20 = {
		# 						modifier = {
		# 							has_trait = lustful
		# 							add = -20
		# 						}
		# 						add_trait = lustful
		# 					}
		# 					20 = {
		# 						modifier = {
		# 							has_trait = bisexual
		# 							add = -20
		# 						}
		# 						modifier = {
		# 							has_trait = homosexual
		# 							add = -20
		# 						}
		# 						set_sexuality = bisexual
		# 					}
		# 					5 = {
		# 						modifier = {
		# 							has_trait = bisexual
		# 							add = -5
		# 						}
		# 						modifier = {
		# 							has_trait = homosexual
		# 							add = -5
		# 						}
		# 						modifier = {
		# 							has_trait = lustful
		# 							add = -5
		# 						}
		# 						add_trait = lustful
		# 						set_sexuality = bisexual
		# 					}
		# 					55 = {
		# 						modifier = {
		# 							has_trait = bisexual
		# 							add = -20
		# 						}
		# 						modifier = {
		# 							has_trait = homosexual
		# 							add = -20
		# 						}
		# 						modifier = {
		# 							has_trait = lustful
		# 							add = -20
		# 						}
		# 					}
		# 				}
		# 			}
		# 			if = {
		# 				limit = {
		# 					NOR = {
		# 						has_relation_lover = scope:stressed_partner
		# 						has_relation_potential_lover = scope:stressed_partner
		# 					}
		# 				}
		# 				hidden_effect = {
		# 					add_relation_potential_lover = scope:stressed_partner
		# 				}
		# 			}
		# 			else = {
		# 				random = {
		# 					chance = 40
		# 					add_relation_lover = scope:stressed_partner
		# 				}
		# 			}
		# 		}
		# 	}
		# }
	}
}


code:
namespace = regula_take_initiates_from_holy_order

# Regula Take Initiates From Holy Order events
# 0001 - Three Initiates
# 0002 - Five Initiates

regula_take_initiates_from_holy_order.0001 = {
	type = character_event

	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 15
				}
				desc = regula_take_initiates_from_holy_order_common.title
			}
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 30
				}
				desc = regula_take_initiates_from_holy_order_noble.title
			}
			desc = regula_take_initiates_from_holy_order_royal.title
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 15
				}
				desc = regula_take_initiates_from_holy_order_common.desc
			}
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 30
				}
				desc = regula_take_initiates_from_holy_order_noble.desc
			}
			desc = regula_take_initiates_from_holy_order_royal.desc
		}
	}

	theme = realm
	override_background = {
		event_background = temple
	}

	left_portrait = {
		character = scope:initiate1
		animation = personality_bold
		outfit_tags = { regula_solider }
	}
	right_portrait = {
		character = scope:initiate2
		animation = personality_zealous
		outfit_tags = { regula_priestess}
	}
	lower_left_portrait = {
		character = scope:initiate3
		outfit_tags = {regula_inititate_lady}
	}

	# Create our Inititates
	immediate = {

		# Now pick the right option
		# could use switch statement?
		if = {
			limit = {
				regula_num_holy_order_counties < 15
			}

			regula_create_inititate_effect = { WHO = root inititate_type = 1 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate1 }

			regula_create_inititate_effect = { WHO = root inititate_type = 2 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate2 }

			regula_create_inititate_effect = { WHO = root inititate_type = 3 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate3 }
		}
		else_if = {
			limit = {
				regula_num_holy_order_counties < 30
				regula_num_holy_order_counties >= 15
			}

			regula_create_inititate_effect = { WHO = root inititate_type = 1 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate1 }

			regula_create_inititate_effect = { WHO = root inititate_type = 2 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate2 }

			regula_create_inititate_effect = { WHO = root inititate_type = 3 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate3 }
		}
		else_if = {
			limit = {
				regula_num_holy_order_counties >= 30
			}

			regula_create_inititate_effect = { WHO = root inititate_type = 1 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate1 }

			regula_create_inititate_effect = { WHO = root inititate_type = 2 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate2 }

			regula_create_inititate_effect = { WHO = root inititate_type = 3 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate3 }
		}
	}

	# Now choose
	# 1. Choose first Intitate
	# 2. Choose second Intitate
	# 3. Choose third Intitate
	option = {
		name = regula_take_initiates_from_holy_order.a
		add_courtier = scope:initiate1
		# Remove others
		hidden_effect = {
			scope:initiate2 = {
				death = {
					death_reason = death_disappearance
				}
			}
			scope:initiate3 = {
				death = {
					death_reason = death_disappearance
				}
			}
		}
	}

	option = {
		name = regula_take_initiates_from_holy_order.b
		add_courtier = scope:initiate2
		# Remove others
		hidden_effect = {
			scope:initiate1 = {
				death = {
					death_reason = death_disappearance
				}
			}
			scope:initiate3 = {
				death = {
					death_reason = death_disappearance
				}
			}
		}
	}

	option = {
		name = regula_take_initiates_from_holy_order.c
		add_courtier = scope:initiate3
		# Remove others
		hidden_effect = {
			scope:initiate1 = {
				death = {
					death_reason = death_disappearance
				}
			}
			scope:initiate2 = {
				death = {
					death_reason = death_disappearance
				}
			}
		}
	}
}

regula_take_initiates_from_holy_order.0002 = {
	type = character_event

	# set title and description based on "power" of event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 15
				}
				desc = regula_take_initiates_from_holy_order_common.title
			}
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 30
				}
				desc = regula_take_initiates_from_holy_order_noble.title
			}
			desc = regula_take_initiates_from_holy_order_royal.title
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 15
				}
				desc = regula_take_initiates_from_holy_order_common.desc
			}
			triggered_desc = {
				trigger = {
					regula_num_holy_order_counties < 30
				}
				desc = regula_take_initiates_from_holy_order_noble.desc
			}
			desc = regula_take_initiates_from_holy_order_royal.desc
		}
	}

	theme = faith
	override_background = {
		event_background = temple
	}

	left_portrait = {
		character = scope:initiate1
		animation = personality_bold
		outfit_tags = { regula_solider }
	}
	right_portrait = {
		character = scope:initiate2
		animation = personality_zealous
		outfit_tags = { regula_priestess}
	}
	lower_left_portrait = {
		character = scope:initiate3
		outfit_tags = {regula_lady}
	}
	lower_center_portrait = {
		character = scope:initiate4
		outfit_tags = {regula_spy}
	}
	lower_right_portrait = {
		character = scope:initiate5
		outfit_tags = {regula_lady}
	}

	# Create our Inititates
	# Each Inititate is specialised
	# 1. The Solider - Giant, Strong style traits, good martial and prowess
	# 2. The Priestess - High Learning, Zealous
	# 3. The Lady - decent stats all around, content, good vassal/wife
	# 4. The Spy - High Intrigue, prowess
	# 5. The Breeder - Good congential traits, chance for pure blooded, not so great stat line
	# Just create them in order, no need for random list

	# inititate_rarity can be 1,2,3 (common,noble,royal)
	# depends on number of counties owned by regula holy orders
	# 0+ counties for common, 15+ counties for noble, 30+ for royal

	# num_leased_titles holy order

	# Common
	immediate = {

		# Now pick the right option
		# could use switch statement?
		if = {
			limit = {
				regula_num_holy_order_counties < 15
			}

			regula_create_inititate_effect = { WHO = root inititate_type = 1 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate1 }

			regula_create_inititate_effect = { WHO = root inititate_type = 2 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate2 }

			regula_create_inititate_effect = { WHO = root inititate_type = 3 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate3 }

			regula_create_inititate_effect = { WHO = root inititate_type = 4 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate4 }

			regula_create_inititate_effect = { WHO = root inititate_type = 5 inititate_rarity = 1}
			scope:created_character = { save_scope_as = initiate5 }
		}
		else_if = {
			limit = {
				regula_num_holy_order_counties < 30
				regula_num_holy_order_counties >= 15
			}

			regula_create_inititate_effect = { WHO = root inititate_type = 1 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate1 }

			regula_create_inititate_effect = { WHO = root inititate_type = 2 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate2 }

			regula_create_inititate_effect = { WHO = root inititate_type = 3 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate3 }

			regula_create_inititate_effect = { WHO = root inititate_type = 4 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate4 }

			regula_create_inititate_effect = { WHO = root inititate_type = 5 inititate_rarity = 2}
			scope:created_character = { save_scope_as = initiate5 }
		}
		else_if = {
			limit = {
				regula_num_holy_order_counties >= 30
			}

			regula_create_inititate_effect = { WHO = root inititate_type = 1 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate1 }

			regula_create_inititate_effect = { WHO = root inititate_type = 2 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate2 }

			regula_create_inititate_effect = { WHO = root inititate_type = 3 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate3 }

			regula_create_inititate_effect = { WHO = root inititate_type = 4 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate4 }

			regula_create_inititate_effect = { WHO = root inititate_type = 5 inititate_rarity = 3}
			scope:created_character = { save_scope_as = initiate5 }
		}
	}

	# Now choose
	option = {
		name = regula_take_initiates_from_holy_order.a
		add_courtier = scope:initiate1
		# Remove others
		hidden_effect = {
			scope:initiate2 = {	death = {death_reason = death_disappearance}}
			scope:initiate3 = {	death = {death_reason = death_disappearance}}
			scope:initiate4 = {	death = {death_reason = death_disappearance}}
			scope:initiate5 = {	death = {death_reason = death_disappearance}}
		}
	}

	option = {
		name = regula_take_initiates_from_holy_order.b
		add_courtier = scope:initiate2
		# Remove others
		hidden_effect = {
			scope:initiate1 = {	death = {death_reason = death_disappearance}}
			scope:initiate3 = {	death = {death_reason = death_disappearance}}
			scope:initiate4 = {	death = {death_reason = death_disappearance}}
			scope:initiate5 = {	death = {death_reason = death_disappearance}}
		}
	}

	option = {
		name = regula_take_initiates_from_holy_order.c
		add_courtier = scope:initiate3
		# Remove others
		hidden_effect = {
			scope:initiate1 = {	death = {death_reason = death_disappearance}}
			scope:initiate2 = {	death = {death_reason = death_disappearance}}
			scope:initiate4 = {	death = {death_reason = death_disappearance}}
			scope:initiate5 = {	death = {death_reason = death_disappearance}}
		}
	}

	option = {
		name = regula_take_initiates_from_holy_order.d
		add_courtier = scope:initiate4
		# Remove others
		hidden_effect = {
			scope:initiate1 = {	death = {death_reason = death_disappearance}}
			scope:initiate2 = {	death = {death_reason = death_disappearance}}
			scope:initiate3 = {	death = {death_reason = death_disappearance}}
			scope:initiate5 = {	death = {death_reason = death_disappearance}}
		}
	}

	option = {
		name = regula_take_initiates_from_holy_order.e
		add_courtier = scope:initiate5
		# Remove others
		hidden_effect = {
			scope:initiate1 = {	death = {death_reason = death_disappearance}}
			scope:initiate2 = {	death = {death_reason = death_disappearance}}
			scope:initiate3 = {	death = {death_reason = death_disappearance}}
			scope:initiate4 = {	death = {death_reason = death_disappearance}}
		}
	}
}


code:
namespace = regula_tradition
# 0000-0999: Eligibility events
# 1000-1999: Magister events
# 2000-2999: Generic events

######################################################
# ELIGIBILITY EVENTS
# 0000-0999
######################################################

regula_tradition.1001 = { # Combat Pillar and Famuli Warriors tradition
	type = character_event
	title = regula_tradition.1001.t
	desc = regula_tradition.1001.desc

	theme = regula_theme
	override_background = {
		event_background = battlefield
	}
	right_portrait = {
		character = global_var:magister_character
		animation = personality_bold
	}

	immediate = {
		hidden_effect = {
			global_var:magister_character.culture = {
				set_culture_pillar = martial_custom_regula
				add_culture_tradition = tradition_famuli_warriors
			}
		}
		global_var:magister_character = {
			add_character_modifier = {
				modifier = martial_custom_regula_implemented
				years = 10
			}
		}
	}

	option = { # Great!
		name = regula_tradition.1001.a
	}

	after = {
	}
}


code:
namespace = regula_virus

regula_virus.1000 = {
	hidden = yes

	trigger = {
		has_trait = regula_virus
		is_imprisoned = no
	}

	immediate = {
		save_scope_as = disease_spreader
		save_scope_as = last_patient
		if = {
			limit = {
				exists = court_owner
			}
			court_owner = {
				save_scope_as = contagion_court_owner
			}
		}

		if = {
			limit = { exists = scope:contagion_court_owner }

			scope:contagion_court_owner = {
				save_court_physician_as_effect = { SCOPE_NAME = physician }
			}
			#First, an available partner gets a shot at being infected.
			every_relation = {
				type = lover
				limit = {
					age >= 16
					is_male = no
					NOT = { has_trait = regula_virus }
				}
				add_to_temporary_list = potential_contagion_victims
			}
			every_relation = {
				type = soulmate
				limit = {
					age >= 16
					is_male = no
					NOT = { has_trait = regula_virus }
				}
				add_to_temporary_list = potential_contagion_victims
			}
			every_consort = {
				limit = {
					age >= 16
					is_male = no
					NOT = { has_trait = regula_virus }
				}
				add_to_temporary_list = potential_contagion_victims
			}
			if = {
				limit = {
					is_married = yes
				}
				scope:spouse = { # To account for polygamous societies.
					every_consort = {
						limit = {
							age >= 16
							is_male = no
							NOT = { has_trait = regula_virus }
						}
						add_to_temporary_list = potential_contagion_victims
					}
				}
			}
			### Regular Spread
			#Add everyone in the same court (ruler, prisoners, guests) and friendly scheme targets/owners to list
			create_regula_virus_list_effect = { SICK_CHARACTER = root CONTAGION_COURT_OWNER = scope:contagion_court_owner }

			random_list = {
				120 = { #Contagion successful
					random_in_list = {
						list = contagion_list
						weight = {
							base = 20

							modifier = {
								add = -5
								has_perk = wash_your_hands_perk
							}
							modifier = {
								add = -5
								has_trait = chaste
							}
							modifier = {
								add = -10
								has_trait = celibate
							}
							modifier = {
								add = -1000
								age < 16
							}
							modifier = { # Very high chance of landing on a female character. Most of the courts seem to be male.
								is_male = no
								add = 240
							}
							modifier = {
								is_imprisoned = yes
								add = -1000
							}
							modifier = { # Failsafe
								add = -1000
								has_trait = magister_trait_group
							}
							modifier = { # To stop the virus from looping between the converted.
								add = -1000
								faith = global_var:magister_character.faith
							}
						}
						contract_regula_virus_effect = yes
						save_scope_as = last_patient
						trigger_event = {
							id = regula_virus.1000
							days = { bubonic_plague_contagion_min bubonic_plague_contagion_max }
						}
					}
					remove_trait = regula_virus
				}
				0 = { #Contagion prevented by locking up the source
					modifier = {
						regula_virus_imprisonable_trigger = yes
						add = 10
					}
					modifier = {
						any_in_list = {
							list = contagion_list
							faith = global_var:magister_character.faith
						}
						add = -5
					}
					scope:contagion_court_owner = {
						imprison = {
							target = root
							type = dungeon
						}
					}
					save_scope_as = last_patient
					global_var:magister_character = {

						random_owned_story = {
							limit = {
								story_type = story_regula_infecta_chain
								var:patient_zero = scope:regula_patient_zero
							}
							save_scope_as = infecta_story
							hidden_effect = {
								set_variable = {
									name = infection_tally
									value = 0
								}
							}
							every_in_list = {
								variable = new_converts
								prev = {
									change_variable = {
										name = infection_tally
										add = 1
									}
								}
							}
						}
						send_interface_message = {  # Tells the player the outcome.
							type = event_spouse_task_good
							title = regula_virus_outcome_jail.t
							desc = regula_virus_outcome_jail.desc
							left_icon = scope:regula_patient_zero
							right_icon = scope:last_patient
						}
						random_owned_story = {
							limit = {
								story_type = story_regula_infecta_chain
								var:patient_zero = scope:regula_patient_zero
							}
							end_story = yes
						}
					}
					remove_trait = regula_virus
					#No contagion this time!
				}
				0 = { # Contagion doesn't occur.  This time.
					modifier = {
						regula_virus_imprisonable_trigger = no
						add = 40
					}
				}
				### Chain ends.
				40 = {
					remove_trait = regula_virus
					#Inform the player.
					global_var:magister_character = {
						random_owned_story = {
							limit = {
								story_type = story_regula_infecta_chain
								var:patient_zero = scope:regula_patient_zero
							}
							save_scope_as = infecta_story
							hidden_effect = {
								set_variable = {
									name = infection_tally
									value = 0
								}
							}
							every_in_list = {
								variable = new_converts
								prev = {
									change_variable = {
										name = infection_tally
										add = 1
									}
								}
							}
						}
						send_interface_message = {  # Tells the player the outcome.
							type = event_spouse_task_good
							title = regula_virus_outcome.t
							desc = regula_virus_outcome.desc
							left_icon = scope:regula_patient_zero
							right_icon = scope:last_patient
						}
						random_owned_story = {
							limit = {
								story_type = story_regula_infecta_chain
								var:patient_zero = scope:regula_patient_zero
							}
							end_story = yes
						}
					}
				}
			}
		}
		if = {
			limit = {
				is_imprisoned = no
			}
			random_list = {
				20 = { #Contagion hits relative/spouse.
					random_in_list = {
						list = potential_contagion_victims
						weight = {
							base = 50
							modifier = { #Who visits the captives, anyway?
								is_imprisoned = no
								add = 50
							}
							modifier = {
								add = -50
								has_perk = wash_your_hands_perk
							}
							modifier = {
								add = -200
								has_trait = chaste
							}
							modifier = {
								add = -1000
								has_trait = celibate
							}
							modifier = { # 80% chance of landing on a female character, if there is one.
								add = 400
								is_male = no
							}
							modifier = { # Failsafe
								add = -1000
								has_trait = magister_trait_group
							}
							modifier = { # To stop the virus from looping between the converted.
								add = -1000
								faith = global_var:magister_character.faith
							}
					}
					contract_regula_virus_relation_effect = yes
				}
			}
		}
		if = {
			limit = {
				has_trait = regula_virus
			}
			trigger_event = {
				id = regula_virus.1000
				days = { 15 60 }
			}
		}
	}
}