code:
guest_management = {
	# Can this character visit a specific court? Each ruler with free guest slots checks this once a month for each local pool character.
	# root, scope:guest = the potential guest
	# scope:host = the potential host
	guest_can_arrive = {
		any_traveling_family_member = { # the whole family must be allowed to arrive
			count = all
			guest_allowed_to_arrive_trigger = { HOST = scope:host }
		}
		#If claimant, make sure that they don't have a claim on the new host.
		trigger_if = {
			limit = { is_claimant = yes }
			any_claim = {
				courtier_or_guest_claim_trigger = { RULER = scope:host }
			}
		}
	}

	# If guest_can_arrive is true, the host decides which guests arrive using this weight. Will randomly select a few of the best candidates.
	# root, scope:guest = the potential guest
	# scope:host = the potential host
	guest_score = {
		base = 100

		###GENERAL WEIGHTS###

		modifier = {
			NOT = {
				culture = scope:host.culture
			}
			add = -20
		}
		modifier = {
			NOT = { faith = scope:host.faith }
			add = -30
		}
		modifier = {
			is_adult = no
			add = -80
		}
		modifier = {
			age >= 65
			add = -50
		}
		modifier = {
			scope:host = { has_imprisonment_reason = scope:guest }
			NOT = {
				reverse_opinion = {
					target = scope:host
					value >= medium_positive_opinion
				}
				OR = {
					has_relation_friend = scope:host
					has_relation_lover = scope:host
					is_close_or_extended_family_of = scope:host
					AND = {
						exists = dynasty
						dynasty = scope:host.dynasty
					}
				}
			}
			add = -1000
		}

		###CLAIMANTS###
		#Max: 2000 (6000 with perk)
		modifier = { #Best useful claim is county
			any_claim = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
			}
			add = {
				if = {
					limit = {
						any_claim = {
							useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
							tier >= tier_kingdom
						}
					}
					add = 2000
				}
				else_if = {
					limit = {
						any_claim = {
							useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
							tier >= tier_duchy
						}
					}
					add = 1500
				}
				else = {
					add = 1000
				}
				if = { #Invitation decision bonus
					limit = { scope:host = { has_character_flag = invite_claimants_decision_active } }
					multiply = 2
				}
				if = {
					limit = {
						exists = scope:host.dynasty
						scope:host.dynasty = {
							has_dynasty_perk = erudition_legacy_1
						}
					}
					multiply = 3
				}
			}
		}

		###MARRIAGE CANDIDATES###
		#Max: 2000 (+300 extra opinion bonus max from general weights section)
		modifier = {
			guest_marriage_candidate_trigger = yes
			add = {
				add = 0
				#Genetic traits
				if = {
					limit = {  num_of_good_genetic_traits >= 1  }
					if = {
						limit = { num_of_good_genetic_traits = 1 }
						add = 250
					}
					else_if = {
						limit = { num_of_good_genetic_traits = 2 }
						add = 250
					}
					else = {
						add = 300
					}
				}

				#Dynasty
				if = {
					limit = { exists = dynasty }
					add = {
						value = dynasty.dynasty_prestige_level #0-10
						max = {
							value = scope:host.dynasty.dynasty_prestige_level
							add = 3
						}
						multiply = 75 #Max 750
					}
				}

				#Fertility
				if = {
					limit = { fertility >= high_fertility }
					add = 200
				}

				#Claims
				if = {
					limit = { has_useful_potential_spouse_claim_trigger = { RULER = scope:host } } #Claims, no matter their level, as long as they're strong
					add = 750
				}
			}
		}

		###COMMANDER CANDIDATES###
		#Max: 500
		compare_modifier = {
			trigger = { guest_commander_candidate_trigger = { HOST = scope:host } }
			value = martial
			multiplier = 17.5
			max = 350
		}
		modifier = {
			guest_commander_candidate_trigger = { HOST = scope:host }
			number_of_commander_traits >= 1
			add = {
				if = {
					limit = { number_of_commander_traits = 1 }
					add = 100
				}
				else_if = {
					limit = { number_of_commander_traits = 2 }
					add = 125
				}
				else = {
					add = 150
				}
			}
		}

		###VASSAL CANDIDATES###
		#Max: 500 (+150 extra opinion bonus max from general weights section)
		modifier = {
			guest_vassal_candidate_trigger = yes
			add = {
				if = {
					limit = { guest_vassal_candidate_good_traits_trigger = yes } #Gives +opinion of liege
					add = 100
				}
				if = {
					limit = { domain_size > domain_limit }
					add = 100
				}
				add = {
					value = stewardship
					multiply = 7.5
					max = 150
				}
				add = {
					value = martial
					multiply = 7.5
					max = 150
				}
			}
		}

		###KNIGHT CANDIDATES###
		#Max: 300 (600 with perk)
		modifier = {
			trigger = {
				guest_knight_candidate_trigger = { HOST = root }
			}
			add = {
				value = prowess
				multiply = 15
				max = 300
				if = { #Invitation decision bonus
					limit = { scope:host = { has_character_flag = invite_knights_decision_active } }
					multiply = 1.5
				}
				if = {
					limit = {
						exists = scope:host.dynasty
						scope:host.dynasty = {
							has_dynasty_perk = erudition_legacy_1
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						prowess >= high_skill_rating
						NOT = { culture = scope:host.culture }
						scope:host.culture = { has_cultural_parameter = powerful_foreign_knights_find_you_attractive }
					}
					# Oh yeah, you're gonna get you a Cid.
					multiply = 4
				}
			}
		}

		###COURT PHYSICIAN CANDIDATES###
		#Max: 200
		compare_modifier = {
			trigger = { guest_physician_candidate_trigger = yes }
			value = learning
			multiplier = 5
			max = 100
		}
		modifier = {
			guest_physician_candidate_trigger = yes
			OR = {
				has_trait = lifestyle_mystic
				has_trait = lifestyle_physician
				has_trait = lifestyle_herbalist
			}
			add = 100
		}

		###RELATIONS###
		#Max: 3500 (if you have an obscenely strong connection to them)
		modifier = {
			exists = dynasty
			dynasty = scope:host.dynasty
			NOT = { is_close_or_extended_family_of = scope:host }
			add = 300
		}
		modifier = {
			is_extended_family_of = scope:host
			add = 450
		}
		modifier = {
			is_close_family_of = scope:host
			add = 600
		}
		modifier = {
			has_relation_friend = scope:host
			add = 500
		}
		modifier = {
			has_relation_lover = scope:host
			add = 1000
		}
		modifier = {
			has_relation_ward = scope:host
			add = 800
		}
		modifier = {
			has_relation_guardian = scope:host
			add = 800
		}
		modifier = { #The enemy of my enemy...
			any_relation = {
				type = rival
				any_relation = {
					type = rival
					this = scope:host
				}
			}
			add = 600
		}

		###INTERESTING CHARACTERS### (player only)
		#Between 50 and 200 per interesting aspect
		modifier = {
			scope:host = { is_ai = no }
			add = {
				value = 0
				#SECRETS
				if = {
					limit = {
						any_secret = {
							NOT = { is_known_by = scope:host }
						}
					}
					add = 200
				}
				#LIFESTYLE TRAITS
				if = {
					limit = { has_trait = lifestyle_reveler }
					add = 50
				}
				if = {
					limit = { has_trait = seducer }
					add = 50
				}
				if = {
					limit = { has_trait = lifestyle_blademaster }
					add = 50
				}
				if = {
					limit = { has_trait = lifestyle_hunter }
					add = 50
				}
				if = {
					limit = {
						guest_physician_candidate_trigger = no #No double herbalist bonus
						has_trait = lifestyle_herbalist
					}
					add = 50
				}
				if = {
					limit = { has_trait = torturer }
					add = 50
				}
				if = {
					limit = { has_trait = gallant }
					add = 50
				}
				#CRIME/SHUNNED TRAITS
				if = {
					limit = {
						has_trait = deviant
						NOT = { trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = scope:host.faith GENDER_CHARACTER = scope:guest } }
					}
					add = 50
				}
				if = {
					limit = {
						has_trait = cannibal
						NOT = { trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = scope:host.faith GENDER_CHARACTER = scope:guest } }
					}
					add = 50
				}
				if = {
					limit = {
						has_trait = witch
						NOT = { trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = scope:host.faith GENDER_CHARACTER = scope:guest } }
					}
					add = 50
				}
				if = {
					limit = {
						is_witch_trigger = yes
						scope:host = { is_witch_trigger = yes }
					}
					add = 200
				}
				#MISC TRAITS
				if = {
					limit = {
						OR = {
							has_trait = lunatic
							has_trait = possessed
						}
					}
					add = 200
				}
				if = {
					limit = { has_a_stress_coping_trait_trigger = yes }
					add = 50
				}
				if = {
					limit = { has_interesting_portrait_altering_trait_trigger = yes }
					add = 50
				}
			}
		}

		###SKILLS###
		#All skills 10: 150
		#Max: 300
		compare_modifier = {
			trigger = { diplomacy >= mediocre_skill_rating }
			value = diplomacy
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = {
				martial >= mediocre_skill_rating
				NOR = { #no double martial bonus
					NOT = { guest_commander_candidate_trigger = { HOST = scope:host } }
					guest_vassal_candidate_trigger = no
				}
			}
			value = martial
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = {
				stewardship >= mediocre_skill_rating
				guest_vassal_candidate_trigger = no #no double stewardship bonus
			}
			value = stewardship
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = { intrigue >= mediocre_skill_rating }
			value = intrigue
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = {
				learning >= mediocre_skill_rating
				guest_physician_candidate_trigger = no #no double learning bonus
			}
			value = learning
			multiplier = 3
			max = 60
		}

		###MALE/FEMALE BALANCE###
		#Max = 200
		modifier = {
			guest_male_female_balance_trigger = yes
			scope:host.faith = { has_dominant_ruling_gender = scope:guest }
			add = 75
		}
		modifier = {
			guest_male_female_balance_trigger = yes
			NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:host } }  #Can't be commander/knight
			add = 125
		}

		min = 0
		#Max value is increased with tiers, to make it less likely for low tier rulers to get great characters
		max = {
			value = { #Yes double value is the way (for script math)
				value = 0 #Roughly the highest value for all general categories + the most expensive role category maxed
				if = {
					limit = { scope:host = { highest_held_title_tier = tier_empire } }
					add = 3000
				}
				else_if = {
					limit = { scope:host = { highest_held_title_tier = tier_kingdom } }
					add = 2500
				}
				else_if = {
					limit = { scope:host = { highest_held_title_tier = tier_duchy } }
					add = 1500
				}
				else_if = {
					limit = { scope:host = { highest_held_title_tier = tier_county } }
					add = 500
				}
			}
		}
	}

	# Can a guest leave the court? Checked once a year for each ruler.
	# root, scope:guest = the guest
	# scope:host = their host
	can_leave = {
		any_traveling_family_member = {
			count = all
			guest_allowed_to_leave_trigger = yes
		}
	}

	# Chance that the guest decides to leave in ‰ (= 10 x the likelihood in %). While can_leave is true this is evaluated every month.
	#We strive to keep this value around 50 (min 20 max 100). Guests should have an average chance of leaving each month of 5%. This equals a ~50% chance of leaving after 1 year (once they have passed their minimum visit time and as long as they're allowed to leave)
	# root, scope:guest = the guest
	# scope:host = their host
	monthly_leave_chance_x10 = {
		base = 50

		#Claimants wants to stay and have claims pressed
		modifier = {
			any_claim = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
			}
			add = -20
		}

		#Energetic characters are more likely to move, lazy characters less likely
		ai_energy_target_modifier = { VALUE = -20 }

		#More likely to stay if they like host, less likely if they dislike host
		opinion_modifier = {
			opinion_target = scope:host
			multiplier = -0.2
			min = -15
			max = 15
		}
		modifier = {
			has_relation_friend = scope:host
			add = -5
		}
		modifier = {
			has_relation_lover = scope:host
			add = -10
		}
		modifier = {
			is_close_family_of = scope:host
			add = -5
		}
		modifier = {
			has_relation_rival = scope:host
			add = 30
		}

		#Pregnant women don't want to travel
		modifier = {
			has_trait = pregnant
			add = -30
		}

		#Unhealthy characters don't want to travel
		modifier = {
			health <= poor_health
			add = -20
		}

		#Married people are less likely to move (because spouse also does calculations)
		modifier = {
			exists = primary_spouse
			primary_spouse = { is_pool_guest_of = scope:host }
			add = -15
		}

		#Lodging amenities encourage guests to stay longer
		modifier = {
			add = {
				if = {
					limit = {
						scope:host = { has_royal_court = yes has_dlc_feature = royal_court }
					}
					if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = medium_amenity_level }
								}
							}
						}
						add = -5
					}
					else_if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = high_amenity_level }
								}
							}
						}
						add = -10
					}
					else_if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = very_high_amenity_level }
								}
							}
						}
						add = -15
					}
					else_if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = max_amenity_level }
								}
							}
						}
						add = -20
					}
				}
			}
		}

		# Capping min and max to avoid extreme values
		min = {
			value = {
			#Lodging affects the min value
				add = 20
				scope:host = {
					if = {
						limit = {
							has_royal_court = yes
							has_dlc_feature = royal_court
						}
						if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = medium_amenity_level }
								}
							}
							add = -4
						}
						else_if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = high_amenity_level }
								}
							}
							add = -6
						}
						else_if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = very_high_amenity_level }
								}
							}
							add = -8
						}
						else_if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = max_amenity_level }
								}
							}
							add = -10
						}
					}
				}
			}
		}
		max = {
			value = {
				add = 100
				if = {
					limit = { is_adult = no }
					multiply = 0 #Children shouldn't try to leave on their own
				}
				#Lodging affects the max value
				add = {
					scope:host = {
						if = {
							limit = {
								has_royal_court = yes
								has_dlc_feature = royal_court
							}
							if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = medium_amenity_level }
									}
								}
								subtract = 4
							}
							else_if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = high_amenity_level }
									}
								}
								subtract = 6
							}
							else_if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = very_high_amenity_level }
									}
								}
								subtract = 8
							}
							else_if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = max_amenity_level }
									}
								}
								subtract = 10
							}
						}
					}
				}
			}
		}
	}

	# Description shown to the player's pool guests to indicate what they could be useful for.
	# The first entry with a valid limit and the highest weight will be shown. If no entry is valid, nothing will be shown.
	# Syntax:
	# guest_description = {
	#	 description = {
	#		 limit = {}	# trigger, default: always = yes	root/scope:guest = the guest, scope:host = the host
	#		 weight = {}	# MTTH, default: base = 1			root/scope:guest = the guest, scope:host = the host
	#		 desc = {}		# dynamic description				root/scope:guest = the guest, scope:host = the host
	#	 }
	#	 description = { ... }
	# }
	guest_description = {

		###Claims###
		description = {
			limit = { any_claim = { useful_courtier_or_guest_claim_trigger = { RULER = scope:host } } }
			weight = {
				base = 1000
			}
			desc = {
				desc = guest_description.claim_start.desc
				first_valid = {
					triggered_desc = {
						trigger = {
							any_claim = {
								useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
								tier = tier_kingdom
							}
						}
						desc = guest_description.kingdom_claim.desc
					}
					triggered_desc = {
						trigger = {
							any_claim = {
								useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
								tier = tier_duchy
							}
						}
						desc = guest_description.duchy_claim.desc
					}
					desc = guest_description.claim_claim.desc
				}
			}
		}

		###Genetic trait###

		# Carnalitas: Edited to also show Carnalitas's unique genetic traits.

		description = {
			limit = {
				num_of_good_genetic_traits > this.num_of_bad_genetic_traits
				fertility > low_fertility
				can_marry_trigger = yes
				#To account for a person marrying their concubines
				trigger_if = {
					limit = {
						is_concubine = yes
					}
					is_concubine_of = scope:host
				}
			}
			weight = {
				base = 200
				modifier = {
					factor = { add = genetic_character_value }
				}
			}
			desc = {
				desc = guest_description.gentic_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { has_trait = intellect_good_3 }
						desc = guest_description.intellect_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = physique_good_3 }
						desc = guest_description.physique_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = beauty_good_3 }
						desc = guest_description.beauty_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = intellect_good_2 }
						desc = guest_description.intellect_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = physique_good_2 }
						desc = guest_description.physique_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = beauty_good_2 }
						desc = guest_description.beauty_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = intellect_good_1 }
						desc = guest_description.intellect_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = physique_good_1 }
						desc = guest_description.physique_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = beauty_good_1 }
						desc = guest_description.beauty_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = fecund }
						desc = guest_description.fecund.desc
					}
					# Carnalitas body part traits
					triggered_desc = {
						trigger = { has_trait = tits_big_good_3 }
						desc = guest_description.tits_big_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = dick_big_good_3 }
						desc = guest_description.dick_big_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = tits_small_good_3 }
						desc = guest_description.tits_small_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = dick_small_good_3 }
						desc = guest_description.dick_small_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = tits_big_good_2 }
						desc = guest_description.tits_big_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = dick_big_good_2 }
						desc = guest_description.dick_big_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = tits_small_good_2 }
						desc = guest_description.tits_small_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = dick_small_good_2 }
						desc = guest_description.dick_small_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = tits_big_good_1 }
						desc = guest_description.tits_big_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = dick_big_good_1 }
						desc = guest_description.dick_big_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = tits_small_good_1 }
						desc = guest_description.tits_small_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = dick_small_good_1 }
						desc = guest_description.dick_small_good_1.desc
					}
				}
				desc = guest_description.gentic_end.desc
			}
		}

		###SKILLS###

		#Prowess
		description = {
			limit = {
				prowess >= decent_skill_rating
				can_be_knight_trigger = { ARMY_OWNER = scope:host }
			}
			weight = {
				base = 150
				modifier = {
					add = {
						value = prowess
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { prowess >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { prowess >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.prowess.desc
			}
		}

		#Martial
		description = {
			limit = {
				martial >= decent_skill_rating
				OR = {
					can_be_marshal_trigger = { COURT_OWNER = scope:host }
					can_be_commander_basic_trigger = { ARMY_OWNER = scope:host }
				}
			}
			weight = {
				base = 120
				modifier = {
					add = {
						value = martial
						subtract = decent_skill_rating
						multiply = 10
					}
				}
				modifier = {
					add = {
						value = number_of_commander_traits
						multiply = 15
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								martial >= extremely_high_skill_rating
								AND = {
									martial >= high_skill_rating
									number_of_commander_traits >= 2
								}
							}
						}
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = {
							OR = {
								martial >= high_skill_rating
								number_of_commander_traits >= 2
							}
						}
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.martial_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { number_of_commander_traits = 3 }
						desc = guest_description.martial_3_commander_traits.desc
					}
					triggered_desc = {
						trigger = { number_of_commander_traits = 2 }
						desc = guest_description.martial_2_commander_traits.desc
					}
					triggered_desc = {
						trigger = { number_of_commander_traits = 1 }
						desc = guest_description.martial_1_commander_traits.desc
					}
					desc = guest_description.martial_0_commander_traits.desc
				}
			}
		}

		#Diplomacy
		description = {
			limit = {
				diplomacy >= decent_skill_rating
				can_be_chancellor_trigger = { COURT_OWNER = scope:host }
			}
			weight = {
				base = 100
				modifier = {
					add = {
						value = diplomacy
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { diplomacy >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { diplomacy >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.diplomacy.desc
			}
		}

		#Stewardship
		description = {
			limit = {
				stewardship >= decent_skill_rating
				can_be_steward_trigger = { COURT_OWNER = scope:host }
			}
			weight = {
				base = 100
				modifier = {
					add = {
						value = stewardship
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { stewardship >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { stewardship >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.stewardship.desc
			}
		}

		#Intrigue
		description = {
			limit = {
				intrigue >= decent_skill_rating
				can_be_spymaster_trigger = { COURT_OWNER = scope:host }
			}
			weight = {
				base = 70
				modifier = {
					add = {
						value = intrigue
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { intrigue >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { intrigue >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.intrigue.desc
			}
		}

		#Learning
		description = {
			limit = { learning >= decent_skill_rating } # 2019/05/08: No current restrictions on court physician
			weight = {
				base = 70
				modifier = {
					add = {
						value = learning
						subtract = decent_skill_rating
						multiply = 10
					}
				}
				modifier = {
					OR = {
						has_trait = lifestyle_herbalist
						has_trait = lifestyle_physician
						has_trait = lifestyle_mystic
					}
					add = 50
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								learning >= extremely_high_skill_rating
								AND = {
									learning >= high_skill_rating
									OR = {
										has_trait = lifestyle_herbalist
										has_trait = lifestyle_physician
										has_trait = lifestyle_mystic
									}
								}
							}
						}
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = {
							OR = {
								learning >= high_skill_rating
								OR = {
									has_trait = lifestyle_herbalist
									has_trait = lifestyle_physician
									has_trait = lifestyle_mystic
								}
							}
						}
						trigger = { learning >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.learning_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { has_trait = lifestyle_physician }
						desc = guest_description.learning_physician_trait_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = lifestyle_mystic }
						desc = guest_description.learning_mystic_trait_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = lifestyle_herbalist }
						desc = guest_description.learning_herbalist_trait.desc
					}
					desc = guest_description.learning_no_trait.desc
				}
			}
		}

		###Vassal###
		description = {
			limit = {
				guest_vassal_candidate_trigger = yes
				opinion = {
					target = scope:host
					value > 0
				}
				OR = {
					guest_vassal_candidate_good_traits_trigger = yes
					stewardship >= decent_skill_rating
					martial >= decent_skill_rating
				}
			}
			weight = {
				base = 70
				opinion_modifier = {
					opinion_target = scope:host
					who = scope:guest
					multiplier = 0.5
				}
			}
			desc = {
				desc = guest_description.vassal_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { has_trait = content }
						desc = guest_description.vassal_content.desc
					}
					triggered_desc = {
						trigger = { has_trait = humble }
						desc = guest_description.vassal_humble.desc
					}
					triggered_desc = {
						trigger = { has_trait = trusting }
						desc = guest_description.vassal_trusting.desc
					}
					triggered_desc = {
						trigger = { stewardship >= this.martial }
						desc = guest_description.vassal_stewardship.desc
					}
					desc = guest_description.vassal_martial.desc
				}
			}
		}
	}
}


code:
guest_management = {
	# Can this character visit a specific court? Each ruler with free guest slots checks this once a month for each local pool character.
	# root, scope:guest = the potential guest
	# scope:host = the potential host
	guest_can_arrive = {
		any_traveling_family_member = { # the whole family must be allowed to arrive
			count = all
			guest_allowed_to_arrive_trigger = { HOST = scope:host }
		}
		#If claimant, make sure that they don't have a claim on the new host.
		trigger_if = {
			limit = { is_claimant = yes }
			any_claim = {
				courtier_or_guest_claim_trigger = { RULER = scope:host }
			}
		}
	}

	# If guest_can_arrive is true, the host decides which guests arrive using this weight. Will randomly select a few of the best candidates.
	# root, scope:guest = the potential guest
	# scope:host = the potential host
	guest_score = {
		base = 100

		###GENERAL WEIGHTS###
		#Max: 150 (450 if marriage candidate, 300 if vassal candidate)
		#Min: -1230
		opinion_modifier = {
			opinion_target = scope:host
			multiplier = {
				value = 1.5
				if = {
					limit = { guest_marriage_candidate_trigger = yes }
					multiply = 3
				}
				else_if = {
					limit = { guest_vassal_candidate_trigger = yes }
					multiply = 2
				}
			}
		}
		modifier = {
			NOT = {
				culture = scope:host.culture
			}
			add = -20
		}
		modifier = {
			NOT = { faith = scope:host.faith }
			add = -30
		}
		modifier = {
			is_adult = no
			add = -80
		}
		modifier = {
			age >= 65
			add = -50
		}
		modifier = {
			scope:host = { has_imprisonment_reason = scope:guest }
			NOT = {
				reverse_opinion = {
					target = scope:host
					value >= medium_positive_opinion
				}
				OR = {
					has_relation_friend = scope:host
					has_relation_lover = scope:host
					is_close_or_extended_family_of = scope:host
					AND = {
						exists = dynasty
						dynasty = scope:host.dynasty
					}
				}
			}
			add = -1000
		}

		###CLAIMANTS###
		#Max: 2000 (6000 with perk)
		modifier = { #Best useful claim is county
			any_claim = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
			}
			add = {
				if = {
					limit = {
						any_claim = {
							useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
							tier >= tier_kingdom
						}
					}
					add = 2000
				}
				else_if = {
					limit = {
						any_claim = {
							useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
							tier >= tier_duchy
						}
					}
					add = 1500
				}
				else = {
					add = 1000
				}
				if = { #Invitation decision bonus
					limit = { scope:host = { has_character_flag = invite_claimants_decision_active } }
					multiply = 2
				}
				if = {
					limit = {
						exists = scope:host.dynasty
						scope:host.dynasty = {
							has_dynasty_perk = erudition_legacy_1
						}
					}
					multiply = 3
				}
			}
		}

		###MARRIAGE CANDIDATES###
		#Max: 2000 (+300 extra opinion bonus max from general weights section)
		modifier = {
			guest_marriage_candidate_trigger = yes
			add = {
				add = 0
				#Genetic traits
				if = {
					limit = {  num_of_good_genetic_traits >= 1  }
					if = {
						limit = { num_of_good_genetic_traits = 1 }
						add = 250
					}
					else_if = {
						limit = { num_of_good_genetic_traits = 2 }
						add = 250
					}
					else = {
						add = 300
					}
				}

				#Dynasty
				if = {
					limit = { exists = dynasty }
					add = {
						value = dynasty.dynasty_prestige_level #0-10
						max = {
							value = scope:host.dynasty.dynasty_prestige_level
							add = 3
						}
						multiply = 75 #Max 750
					}
				}

				#Fertility
				if = {
					limit = { fertility >= high_fertility }
					add = 200
				}

				#Claims
				if = {
					limit = { has_useful_potential_spouse_claim_trigger = { RULER = scope:host } } #Claims, no matter their level, as long as they're strong
					add = 750
				}
			}
		}

		###COMMANDER CANDIDATES###
		#Max: 500
		compare_modifier = {
			trigger = { guest_commander_candidate_trigger = { HOST = scope:host } }
			value = martial
			multiplier = 17.5
			max = 350
		}
		modifier = {
			guest_commander_candidate_trigger = { HOST = scope:host }
			number_of_commander_traits >= 1
			add = {
				if = {
					limit = { number_of_commander_traits = 1 }
					add = 100
				}
				else_if = {
					limit = { number_of_commander_traits = 2 }
					add = 125
				}
				else = {
					add = 150
				}
			}
		}

		###VASSAL CANDIDATES###
		#Max: 500 (+150 extra opinion bonus max from general weights section)
		modifier = {
			guest_vassal_candidate_trigger = yes
			add = {
				if = {
					limit = { guest_vassal_candidate_good_traits_trigger = yes } #Gives +opinion of liege
					add = 100
				}
				if = {
					limit = { domain_size > domain_limit }
					add = 100
				}
				add = {
					value = stewardship
					multiply = 7.5
					max = 150
				}
				add = {
					value = martial
					multiply = 7.5
					max = 150
				}
			}
		}

		###KNIGHT CANDIDATES###
		#Max: 300 (600 with perk)
		modifier = {
			trigger = {
				guest_knight_candidate_trigger = { HOST = root }
			}
			add = {
				value = prowess
				multiply = 15
				max = 300
				if = { #Invitation decision bonus
					limit = { scope:host = { has_character_flag = invite_knights_decision_active } }
					multiply = 1.5
				}
				if = {
					limit = {
						exists = scope:host.dynasty
						scope:host.dynasty = {
							has_dynasty_perk = erudition_legacy_1
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						prowess >= high_skill_rating
						NOT = { culture = scope:host.culture }
						scope:host.culture = { has_cultural_parameter = powerful_foreign_knights_find_you_attractive }
					}
					# Oh yeah, you're gonna get you a Cid.
					multiply = 4
				}
			}
		}

		###COURT PHYSICIAN CANDIDATES###
		#Max: 200
		compare_modifier = {
			trigger = { guest_physician_candidate_trigger = yes }
			value = learning
			multiplier = 5
			max = 100
		}
		modifier = {
			guest_physician_candidate_trigger = yes
			OR = {
				has_trait = lifestyle_mystic
				has_trait = lifestyle_physician
				has_trait = lifestyle_herbalist
			}
			add = 100
		}

		###RELATIONS###
		#Max: 3500 (if you have an obscenely strong connection to them)
		modifier = {
			exists = dynasty
			dynasty = scope:host.dynasty
			NOT = { is_close_or_extended_family_of = scope:host }
			add = 300
		}
		modifier = {
			is_extended_family_of = scope:host
			add = 450
		}
		modifier = {
			is_close_family_of = scope:host
			add = 600
		}
		modifier = {
			has_relation_friend = scope:host
			add = 500
		}
		modifier = {
			has_relation_lover = scope:host
			add = 1000
		}
		modifier = {
			has_relation_ward = scope:host
			add = 800
		}
		modifier = {
			has_relation_guardian = scope:host
			add = 800
		}
		modifier = { #The enemy of my enemy...
			any_relation = {
				type = rival
				any_relation = {
					type = rival
					this = scope:host
				}
			}
			add = 600
		}

		###INTERESTING CHARACTERS### (player only)
		#Between 50 and 200 per interesting aspect
		modifier = {
			scope:host = { is_ai = no }
			add = {
				value = 0
				#SECRETS
				if = {
					limit = {
						any_secret = {
							NOT = { is_known_by = scope:host }
						}
					}
					add = 200
				}
				#LIFESTYLE TRAITS
				if = {
					limit = { has_trait = lifestyle_reveler }
					add = 50
				}
				if = {
					limit = { has_trait = seducer }
					add = 50
				}
				if = {
					limit = { has_trait = lifestyle_blademaster }
					add = 50
				}
				if = {
					limit = { has_trait = lifestyle_hunter }
					add = 50
				}
				if = {
					limit = {
						guest_physician_candidate_trigger = no #No double herbalist bonus
						has_trait = lifestyle_herbalist
					}
					add = 50
				}
				if = {
					limit = { has_trait = torturer }
					add = 50
				}
				if = {
					limit = { has_trait = gallant }
					add = 50
				}
				#CRIME/SHUNNED TRAITS
				if = {
					limit = {
						has_trait = deviant
						NOT = { trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = scope:host.faith GENDER_CHARACTER = scope:guest } }
					}
					add = 50
				}
				if = {
					limit = {
						has_trait = cannibal
						NOT = { trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = scope:host.faith GENDER_CHARACTER = scope:guest } }
					}
					add = 50
				}
				if = {
					limit = {
						has_trait = witch
						NOT = { trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = scope:host.faith GENDER_CHARACTER = scope:guest } }
					}
					add = 50
				}
				if = {
					limit = {
						is_witch_trigger = yes
						scope:host = { is_witch_trigger = yes }
					}
					add = 200
				}
				#MISC TRAITS
				if = {
					limit = {
						OR = {
							has_trait = lunatic
							has_trait = possessed
						}
					}
					add = 200
				}
				if = {
					limit = { has_a_stress_coping_trait_trigger = yes }
					add = 50
				}
				if = {
					limit = { has_interesting_portrait_altering_trait_trigger = yes }
					add = 50
				}
			}
		}

		###SKILLS###
		#All skills 10: 150
		#Max: 300
		compare_modifier = {
			trigger = { diplomacy >= mediocre_skill_rating }
			value = diplomacy
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = {
				martial >= mediocre_skill_rating
				NOR = { #no double martial bonus
					NOT = { guest_commander_candidate_trigger = { HOST = scope:host } }
					guest_vassal_candidate_trigger = no
				}
			}
			value = martial
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = {
				stewardship >= mediocre_skill_rating
				guest_vassal_candidate_trigger = no #no double stewardship bonus
			}
			value = stewardship
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = { intrigue >= mediocre_skill_rating }
			value = intrigue
			multiplier = 3
			max = 60
		}
		compare_modifier = {
			trigger = {
				learning >= mediocre_skill_rating
				guest_physician_candidate_trigger = no #no double learning bonus
			}
			value = learning
			multiplier = 3
			max = 60
		}

		###MALE/FEMALE BALANCE###
		#Max = 200
		modifier = {
			guest_male_female_balance_trigger = yes
			scope:host.faith = { has_dominant_ruling_gender = scope:guest }
			add = 75
		}
		modifier = {
			guest_male_female_balance_trigger = yes
			NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:host } }  #Can't be commander/knight
			add = 125
		}

		min = 0
		#Max value is increased with tiers, to make it less likely for low tier rulers to get great characters
		max = {
			value = { #Yes double value is the way (for script math)
				value = 0 #Roughly the highest value for all general categories + the most expensive role category maxed
				if = {
					limit = { scope:host = { highest_held_title_tier = tier_empire } }
					add = 3000
				}
				else_if = {
					limit = { scope:host = { highest_held_title_tier = tier_kingdom } }
					add = 2500
				}
				else_if = {
					limit = { scope:host = { highest_held_title_tier = tier_duchy } }
					add = 1500
				}
				else_if = {
					limit = { scope:host = { highest_held_title_tier = tier_county } }
					add = 500
				}
			}
		}
	}

	# Can a guest leave the court? Checked once a year for each ruler.
	# root, scope:guest = the guest
	# scope:host = their host
	can_leave = {
		any_traveling_family_member = {
			count = all
			guest_allowed_to_leave_trigger = yes
		}
	}

	# Chance that the guest decides to leave in ‰ (= 10 x the likelihood in %). While can_leave is true this is evaluated every month.
	#We strive to keep this value around 50 (min 20 max 100). Guests should have an average chance of leaving each month of 5%. This equals a ~50% chance of leaving after 1 year (once they have passed their minimum visit time and as long as they're allowed to leave)
	# root, scope:guest = the guest
	# scope:host = their host
	monthly_leave_chance_x10 = {
		base = 50

		#Claimants wants to stay and have claims pressed
		modifier = {
			any_claim = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
			}
			add = -20
		}

		#Energetic characters are more likely to move, lazy characters less likely
		ai_energy_target_modifier = { VALUE = -20 }

		#More likely to stay if they like host, less likely if they dislike host
		opinion_modifier = {
			opinion_target = scope:host
			multiplier = -0.2
			min = -15
			max = 15
		}
		modifier = {
			has_relation_friend = scope:host
			add = -5
		}
		modifier = {
			has_relation_lover = scope:host
			add = -10
		}
		modifier = {
			is_close_family_of = scope:host
			add = -5
		}
		modifier = {
			has_relation_rival = scope:host
			add = 30
		}

		#Pregnant women don't want to travel
		modifier = {
			has_trait = pregnant
			add = -30
		}

		#Unhealthy characters don't want to travel
		modifier = {
			health <= poor_health
			add = -20
		}

		#Married people are less likely to move (because spouse also does calculations)
		modifier = {
			exists = primary_spouse
			primary_spouse = { is_pool_guest_of = scope:host }
			add = -15
		}

		#Lodging amenities encourage guests to stay longer
		modifier = {
			add = {
				if = {
					limit = {
						scope:host = { has_royal_court = yes has_dlc_feature = royal_court }
					}
					if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = medium_amenity_level }
								}
							}
						}
						add = -5
					}
					else_if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = high_amenity_level }
								}
							}
						}
						add = -10
					}
					else_if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = very_high_amenity_level }
								}
							}
						}
						add = -15
					}
					else_if = {
						limit = {
							scope:host = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = max_amenity_level }
								}
							}
						}
						add = -20
					}
				}
			}
		}

		# Capping min and max to avoid extreme values
		min = {
			value = {
			#Lodging affects the min value
				add = 20
				scope:host = {
					if = {
						limit = {
							has_royal_court = yes
							has_dlc_feature = royal_court
						}
						if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = medium_amenity_level }
								}
							}
							add = -4
						}
						else_if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = high_amenity_level }
								}
							}
							add = -6
						}
						else_if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = very_high_amenity_level }
								}
							}
							add = -8
						}
						else_if = {
							limit = {
								court_owner = {
									amenity_level = { type = court_lodging_standards value = max_amenity_level }
								}
							}
							add = -10
						}
					}
				}
			}
		}
		max = {
			value = {
				add = 100
				if = {
					limit = { is_adult = no }
					multiply = 0 #Children shouldn't try to leave on their own
				}
				#Lodging affects the max value
				add = {
					scope:host = {
						if = {
							limit = {
								has_royal_court = yes
								has_dlc_feature = royal_court
							}
							if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = medium_amenity_level }
									}
								}
								subtract = 4
							}
							else_if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = high_amenity_level }
									}
								}
								subtract = 6
							}
							else_if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = very_high_amenity_level }
									}
								}
								subtract = 8
							}
							else_if = {
								limit = {
									court_owner = {
										amenity_level = { type = court_lodging_standards value = max_amenity_level }
									}
								}
								subtract = 10
							}
						}
					}
				}
			}
		}
	}

	# Description shown to the player's pool guests to indicate what they could be useful for.
	# The first entry with a valid limit and the highest weight will be shown. If no entry is valid, nothing will be shown.
	# Syntax:
	# guest_description = {
	#	 description = {
	#		 limit = {}	# trigger, default: always = yes	root/scope:guest = the guest, scope:host = the host
	#		 weight = {}	# MTTH, default: base = 1			root/scope:guest = the guest, scope:host = the host
	#		 desc = {}		# dynamic description				root/scope:guest = the guest, scope:host = the host
	#	 }
	#	 description = { ... }
	# }
	guest_description = {

		###Claims###
		description = {
			limit = { any_claim = { useful_courtier_or_guest_claim_trigger = { RULER = scope:host } } }
			weight = {
				base = 1000
			}
			desc = {
				desc = guest_description.claim_start.desc
				first_valid = {
					triggered_desc = {
						trigger = {
							any_claim = {
								useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
								tier = tier_kingdom
							}
						}
						desc = guest_description.kingdom_claim.desc
					}
					triggered_desc = {
						trigger = {
							any_claim = {
								useful_courtier_or_guest_claim_trigger = { RULER = scope:host }
								tier = tier_duchy
							}
						}
						desc = guest_description.duchy_claim.desc
					}
					desc = guest_description.claim_claim.desc
				}
			}
		}

		###Genetic trait###
		description = {
			limit = {
				num_of_good_genetic_traits > this.num_of_bad_genetic_traits
				fertility > low_fertility
				can_marry_trigger = yes
				#To account for a person marrying their concubines
				trigger_if = {
					limit = {
						is_concubine = yes
					}
					is_concubine_of = scope:host
				}
			}
			weight = {
				base = 200
				modifier = {
					factor = { add = genetic_character_value }
				}
			}
			desc = {
				desc = guest_description.gentic_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { has_trait = intellect_good_3 }
						desc = guest_description.intellect_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = physique_good_3 }
						desc = guest_description.physique_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = beauty_good_3 }
						desc = guest_description.beauty_good_3.desc
					}
					triggered_desc = {
						trigger = { has_trait = intellect_good_2 }
						desc = guest_description.intellect_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = physique_good_2 }
						desc = guest_description.physique_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = beauty_good_2 }
						desc = guest_description.beauty_good_2.desc
					}
					triggered_desc = {
						trigger = { has_trait = intellect_good_1 }
						desc = guest_description.intellect_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = physique_good_1 }
						desc = guest_description.physique_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = beauty_good_1 }
						desc = guest_description.beauty_good_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = fecund }
						desc = guest_description.fecund.desc
					}
				}
				desc = guest_description.gentic_end.desc
			}
		}

		###SKILLS###

		#Prowess
		description = {
			limit = {
				prowess >= decent_skill_rating
				can_be_knight_trigger = { ARMY_OWNER = scope:host }
			}
			weight = {
				base = 150
				modifier = {
					add = {
						value = prowess
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { prowess >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { prowess >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.prowess.desc
			}
		}

		#Martial
		description = {
			limit = {
				martial >= decent_skill_rating
				OR = {
					can_be_marshal_trigger = { COURT_OWNER = scope:host }
					can_be_commander_basic_trigger = { ARMY_OWNER = scope:host }
				}
			}
			weight = {
				base = 120
				modifier = {
					add = {
						value = martial
						subtract = decent_skill_rating
						multiply = 10
					}
				}
				modifier = {
					add = {
						value = number_of_commander_traits
						multiply = 15
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								martial >= extremely_high_skill_rating
								AND = {
									martial >= high_skill_rating
									number_of_commander_traits >= 2
								}
							}
						}
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = {
							OR = {
								martial >= high_skill_rating
								number_of_commander_traits >= 2
							}
						}
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.martial_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { number_of_commander_traits = 3 }
						desc = guest_description.martial_3_commander_traits.desc
					}
					triggered_desc = {
						trigger = { number_of_commander_traits = 2 }
						desc = guest_description.martial_2_commander_traits.desc
					}
					triggered_desc = {
						trigger = { number_of_commander_traits = 1 }
						desc = guest_description.martial_1_commander_traits.desc
					}
					desc = guest_description.martial_0_commander_traits.desc
				}
			}
		}

		#Diplomacy
		description = {
			limit = {
				diplomacy >= decent_skill_rating
				can_be_chancellor_trigger = { COURT_OWNER = scope:host }
			}
			weight = {
				base = 100
				modifier = {
					add = {
						value = diplomacy
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { diplomacy >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { diplomacy >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.diplomacy.desc
			}
		}

		#Stewardship
		description = {
			limit = {
				stewardship >= decent_skill_rating
				can_be_steward_trigger = { COURT_OWNER = scope:host }
			}
			weight = {
				base = 100
				modifier = {
					add = {
						value = stewardship
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { stewardship >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { stewardship >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.stewardship.desc
			}
		}

		#Intrigue
		description = {
			limit = {
				intrigue >= decent_skill_rating
				can_be_spymaster_trigger = { COURT_OWNER = scope:host }
			}
			weight = {
				base = 70
				modifier = {
					add = {
						value = intrigue
						subtract = decent_skill_rating
						multiply = 10
					}
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { intrigue >= extremely_high_skill_rating }
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = { intrigue >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.intrigue.desc
			}
		}

		#Learning
		description = {
			limit = { learning >= decent_skill_rating } # 2019/05/08: No current restrictions on court physician
			weight = {
				base = 70
				modifier = {
					add = {
						value = learning
						subtract = decent_skill_rating
						multiply = 10
					}
				}
				modifier = {
					OR = {
						has_trait = lifestyle_herbalist
						has_trait = lifestyle_physician
						has_trait = lifestyle_mystic
					}
					add = 50
				}
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							OR = {
								learning >= extremely_high_skill_rating
								AND = {
									learning >= high_skill_rating
									OR = {
										has_trait = lifestyle_herbalist
										has_trait = lifestyle_physician
										has_trait = lifestyle_mystic
									}
								}
							}
						}
						desc = guest_description.outstanding_skill.desc
					}
					triggered_desc = {
						trigger = {
							OR = {
								learning >= high_skill_rating
								OR = {
									has_trait = lifestyle_herbalist
									has_trait = lifestyle_physician
									has_trait = lifestyle_mystic
								}
							}
						}
						trigger = { learning >= high_skill_rating }
						desc = guest_description.experienced_skill.desc
					}
					desc = guest_description.competent_skill.desc
				}
				desc = guest_description.learning_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { has_trait = lifestyle_physician }
						desc = guest_description.learning_physician_trait_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = lifestyle_mystic }
						desc = guest_description.learning_mystic_trait_1.desc
					}
					triggered_desc = {
						trigger = { has_trait = lifestyle_herbalist }
						desc = guest_description.learning_herbalist_trait.desc
					}
					desc = guest_description.learning_no_trait.desc
				}
			}
		}

		###Vassal###
		description = {
			limit = {
				guest_vassal_candidate_trigger = yes
				opinion = {
					target = scope:host
					value > 0
				}
				OR = {
					guest_vassal_candidate_good_traits_trigger = yes
					stewardship >= decent_skill_rating
					martial >= decent_skill_rating
				}
			}
			weight = {
				base = 70
				opinion_modifier = {
					opinion_target = scope:host
					who = scope:guest
					multiplier = 0.5
				}
			}
			desc = {
				desc = guest_description.vassal_start.desc
				first_valid = {
					triggered_desc = {
						trigger = { has_trait = content }
						desc = guest_description.vassal_content.desc
					}
					triggered_desc = {
						trigger = { has_trait = humble }
						desc = guest_description.vassal_humble.desc
					}
					triggered_desc = {
						trigger = { has_trait = trusting }
						desc = guest_description.vassal_trusting.desc
					}
					triggered_desc = {
						trigger = { stewardship >= this.martial }
						desc = guest_description.vassal_stewardship.desc
					}
					desc = guest_description.vassal_martial.desc
				}
			}
		}
	}
}

repo_name: Synthael/carnalitas

license: mit


code:
#Adopted From Carnalitas Slavery Reimagined
#Parameters can be used as a trigger for effect/event
#lustful_trait_more_common = yes is used in carn_childhood event
#carn_no_consequences_for_extramarital_sex_with_me,carn_no_consequences_for_extramarital_sex_with_others = yes,carn_prostitution_accepted,
#and carn_more_good_prostitution_events has been used in random prostitution event, prostitution job

carn_tradition_placeholder = {
	category = regional

	is_shown = { always = no }
	can_pick = { always = no }
	can_pick_for_hybridization = { always = no }

	parameters = {
		lustful_trait_more_common = yes
		carn_no_consequences_for_extramarital_sex_with_me = yes
		carn_no_consequences_for_extramarital_sex_with_others = yes
		carn_prostitution_accepted = yes
		carn_more_good_prostitution_events = yes
		allows_polygamy = yes
		allows_concubinage = yes
	}
}


code:
CarnFutaTraitName = {
	# must be in a character scope due to engine limitation
	# just use GetPlayer.Custom('CarnFutaTraitName')
	type = character
	text = {
		trigger = { has_game_rule = carn_futa_trait_name_hermaphrodite }
		localization_key = carn_hermaphrodite
	}
	text = {
		localization_key = carn_futanari
	}
}

# "futanari" / "hermaphrodites"
CarnFutaTraitNamePlural = {
	type = character
	text = {
		trigger = { has_game_rule = carn_futa_trait_name_hermaphrodite }
		localization_key = carn_hermaphrodite_plural
	}
	text = {
		localization_key = carn_futanari_plural
	}
}

# "futanari's" / "hermaphrodite's"
CarnFutaTraitNamePossessive = {
	type = character
	text = {
		trigger = { has_game_rule = carn_futa_trait_name_hermaphrodite }
		localization_key = carn_hermaphrodite_possessive
	}
	text = {
		localization_key = carn_futanari_possessive
	}
}

# "a" futanari / "a" hermaphrodite
# mainly for other languages where the article might be different
CarnFutaTraitNameArticle = {
	type = character
	text = {
		trigger = { has_game_rule = carn_futa_trait_name_hermaphrodite }
		localization_key = carn_hermaphrodite_article
	}
	text = {
		localization_key = carn_futanari_article
	}
}

CarnGetWomanManFuta = {
	type = character
	text = {
		trigger = {
			carn_is_futa_trigger = yes
			has_game_rule = carn_futa_trait_name_hermaphrodite
		}
		localization_key = carn_hermaphrodite
	}
	text = {
		trigger = { carn_is_futa_trigger = yes }
		localization_key = carn_futanari
	}
	text = {
		trigger = { is_female = yes }
		localization_key = CHARACTER_WOMAN
	}
	text = {
		localization_key = CHARACTER_MAN
	}
}

CarnGetWomanManFutaPossessive = {
	type = character
	text = {
		trigger = {
			carn_is_futa_trigger = yes
			has_game_rule = carn_futa_trait_name_hermaphrodite
		}
		localization_key = carn_hermaphrodite_possessive
	}
	text = {
		trigger = { carn_is_futa_trigger = yes }
		localization_key = carn_futanari_possessive
	}
	text = {
		trigger = { is_female = yes }
		localization_key = CHARACTER_WOMAN_POSSESSIVE
	}
	text = {
		localization_key = CHARACTER_MAN_POSSESSIVE
	}
}


code:
CarnMilkProductionDescription = {
	type = character
	text = {
		trigger = { carn_has_extreme_milk_production_trigger = yes }
		localization_key = carn_extreme_milk_production_description
	}
	text = {
		trigger = { carn_has_very_high_milk_production_trigger = yes }
		localization_key = carn_very_high_milk_production_description
	}
	text = {
		trigger = { carn_has_high_milk_production_trigger = yes }
		localization_key = carn_high_milk_production_description
	}
	text = {
		trigger = { carn_has_average_milk_production_trigger = yes }
		localization_key = carn_average_milk_production_description
	}
	text = {
		trigger = { carn_has_low_milk_production_trigger = yes }
		localization_key = carn_low_milk_production_description
	}
	text = {
		localization_key = carn_very_low_milk_production_description
	}
}

CarnShortMilkProductionDescription = {
	type = character
	text = {
		trigger = { carn_has_extreme_milk_production_trigger = yes }
		localization_key = carn_extreme
	}
	text = {
		trigger = { carn_has_very_high_milk_production_trigger = yes }
		localization_key = carn_very_high
	}
	text = {
		trigger = { carn_has_high_milk_production_trigger = yes }
		localization_key = carn_high
	}
	text = {
		trigger = { carn_has_average_milk_production_trigger = yes }
		localization_key = carn_average
	}
	text = {
		trigger = { carn_has_low_milk_production_trigger = yes }
		localization_key = carn_low
	}
	text = {
		localization_key = carn_very_low
	}
}


code:
carn_start_birth_control_decision = {
	ai_check_interval = 0
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_carn_birth_control.dds"
	}

	desc = carn_start_birth_control_decision_desc

	selection_tooltip = carn_start_birth_control_decision_tooltip

	is_shown = {
		is_adult = yes
		OR = {
			has_game_rule = carn_birth_control_any_gender
			AND = {
				carn_gender_can_impregnate_trigger = yes
				has_game_rule = carn_birth_control_male_only
			}
			AND = {
				is_female = yes
				has_game_rule = carn_birth_control_female_only
			}
			AND = {
				is_ai = no
				has_game_rule = carn_birth_control_player_only
			}
		}
		NOR = {
			has_character_modifier = carn_using_birth_control_modifier
			has_character_flag = carn_cannot_use_birth_control
			has_trait_with_flag = carn_cannot_use_birth_control
		}
	}

	is_valid_showing_failures_only = {
		NOT = { faith = { has_doctrine = tenet_natural_primitivism } }
	}

	effect = {
		send_interface_toast = {
			type = event_toast_effect_neutral
			title = msg_carn_started_birth_control
			left_icon = root
			add_character_modifier = carn_using_birth_control_modifier
		}
		trigger_event = { on_action = carn_on_start_birth_control }
	}

	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}
}

carn_stop_birth_control_decision = {
	ai_check_interval = 0
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_carn_birth_control.dds"
	}

	desc = carn_stop_birth_control_decision_desc

	selection_tooltip = carn_stop_birth_control_decision_tooltip

	is_shown = {
		has_character_modifier = carn_using_birth_control_modifier
	}

	effect = {
		send_interface_toast = {
			type = event_toast_effect_neutral
			title = msg_carn_stopped_birth_control
			left_icon = root
			remove_character_modifier = carn_using_birth_control_modifier
		}
		trigger_event = { on_action = carn_on_stop_birth_control }
	}

	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}
}


code:
carn_work_as_prostitute_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_carn_prostitution.dds"
	}

	desc = carn_work_as_prostitute_decision_desc

	selection_tooltip = carn_work_as_prostitute_decision_tooltip

	is_shown = {
		carn_can_be_prostitute_trigger = yes
		carn_is_working_as_prostitute_trigger = no
	}

	is_valid_showing_failures_only = {
		carn_can_have_sex_trigger = yes
	}

	is_valid = {
		custom_description = {
			text = "carn_effective_age_under_value_cutoff"
			value = carn_prostitution_age_cutoff
			effective_age < carn_prostitution_age_cutoff
		}
	}

	effect = {

		if = {
			limit = {
				carn_is_prostitute_trigger = no
				carn_accepts_prostitution_trigger = no
			}
			add_piety_level = -1
		}

		send_interface_toast = {
			type = event_toast_effect_neutral
			title = msg_carn_started_working_as_prostitute
			left_icon = root
			carn_start_working_as_prostitute_effect = yes
		}

		if = {
			limit = {
				carn_accepts_prostitution_trigger = no
			}
			stress_impact = {
				zealous = major_stress_impact_gain
				arrogant = medium_stress_impact_gain
				chaste = major_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				arrogant = medium_stress_impact_gain
				chaste = major_stress_impact_gain
			}
		}
	}

	ai_check_interval = 60

	ai_potential = {
		faith = { has_doctrine = carn_doctrine_prostitution_accepted }
		OR = {
			has_trait = greedy
			has_trait = lustful
		}
		NOR = {
			has_trait = arrogant
			has_trait = chaste
		}
	}

	ai_will_do = {
		base = 0
		ai_value_modifier = {
			ai_greed = 5
		}
		modifier = {
			add = 50
			faith = { trait_is_virtue = lustful }
		}
		modifier = {
			add = 50
			faith = { trait_is_virtue = lifestyle_prostitute }
		}
	}
}

carn_stop_work_as_prostitute_decision = {
	ai_check_interval = 0

	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_carn_prostitution.dds"
	}

	desc = carn_stop_work_as_prostitute_decision_desc

	selection_tooltip = carn_stop_work_as_prostitute_decision_tooltip

	is_shown = {
		carn_is_working_as_prostitute_trigger = yes
		NOR = {
			has_character_flag = carn_cannot_stop_work_as_prostitute
			has_trait_with_flag = carn_cannot_stop_work_as_prostitute
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
	}

	effect = {

		send_interface_toast = {
			type = event_toast_effect_neutral
			title = msg_carn_stopped_working_as_prostitute
			left_icon = root
			carn_stop_working_as_prostitute_effect = yes
		}

		stress_impact = {
			arrogant = medium_stress_impact_loss
			chaste = major_stress_impact_loss
		}
	}

	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}
}


code:
carn_add_random_fetish_effect = {
	first = carn_i_gain_fetish
	first_past = carn_i_gained_fetish
	third = carn_they_gain_fetish
	third_past = carn_they_gained_fetish
	global = carn_gains_fetish
	global_past = carn_gained_fetish
}

carn_add_fetish_anal_effect = {
	first = carn_i_gain_fetish_anal_effect
	first_past = carn_i_gained_fetish_anal_effect
	third = carn_they_gain_fetish_anal_effect
	third_past = carn_they_gained_fetish_anal_effect
	global = carn_gain_fetish_anal_effect
	global_past = carn_gained_fetish_anal_effect
}

carn_add_fetish_sadism_effect = {
	first = carn_i_gain_fetish_sadism_effect
	first_past = carn_i_gained_fetish_sadism_effect
	third = carn_they_gain_fetish_sadism_effect
	third_past = carn_they_gained_fetish_sadism_effect
	global = carn_gain_fetish_sadism_effect
	global_past = carn_gained_fetish_sadism_effect
}

carn_add_fetish_masochism_effect = {
	first = carn_i_gain_fetish_masochism_effect
	first_past = carn_i_gained_fetish_masochism_effect
	third = carn_they_gain_fetish_masochism_effect
	third_past = carn_they_gained_fetish_masochism_effect
	global = carn_gain_fetish_masochism_effect
	global_past = carn_gained_fetish_masochism_effect
}

carn_add_fetish_bestiality_effect = {
	first = carn_i_gain_fetish_bestiality_effect
	first_past = carn_i_gained_fetish_bestiality_effect
	third = carn_they_gain_fetish_bestiality_effect
	third_past = carn_they_gained_fetish_bestiality_effect
	global = carn_gain_fetish_bestiality_effect
	global_past = carn_gained_fetish_bestiality_effect
}

carn_add_fetish_watersports_effect = {
	first = carn_i_gain_fetish_watersports_effect
	first_past = carn_i_gained_fetish_watersports_effect
	third = carn_they_gain_fetish_watersports_effect
	third_past = carn_they_gained_fetish_watersports_effect
	global = carn_gain_fetish_watersports_effect
	global_past = carn_gained_fetish_watersports_effect
}

carn_add_fetish_scat_effect = {
	first = carn_i_gain_fetish_scat_effect
	first_past = carn_i_gained_fetish_scat_effect
	third = carn_they_gain_fetish_scat_effect
	third_past = carn_they_gained_fetish_scat_effect
	global = carn_gain_fetish_scat_effect
	global_past = carn_gained_fetish_scat_effect
}

carn_add_fetish_gore_effect = {
	first = carn_i_gain_fetish_gore_effect
	first_past = carn_i_gained_fetish_gore_effect
	third = carn_they_gain_fetish_gore_effect
	third_past = carn_they_gained_fetish_gore_effect
	global = carn_gain_fetish_gore_effect
	global_past = carn_gained_fetish_gore_effect
}

carn_add_fetish_foot_play_effect = {
	first = carn_i_gain_fetish_foot_play_effect
	first_past = carn_i_gained_fetish_foot_play_effect
	third = carn_they_gain_fetish_foot_play_effect
	third_past = carn_they_gained_fetish_foot_play_effect
	global = carn_gain_fetish_foot_play_effect
	global_past = carn_gained_fetish_foot_play_effect
}

carn_add_fetish_bondage_effect = {
	first = carn_i_gain_fetish_bondage_effect
	first_past = carn_i_gained_fetish_bondage_effect
	third = carn_they_gain_fetish_bondage_effect
	third_past = carn_they_gained_fetish_bondage_effect
	global = carn_gain_fetish_bondage_effect
	global_past = carn_gained_fetish_bondage_effect
}

carn_add_fetish_domination_effect = {
	first = carn_i_gain_fetish_domination_effect
	first_past = carn_i_gained_fetish_domination_effect
	third = carn_they_gain_fetish_domination_effect
	third_past = carn_they_gained_fetish_domination_effect
	global = carn_gain_fetish_domination_effect
	global_past = carn_gained_fetish_domination_effect
}

carn_add_fetish_submission_effect = {
	first = carn_i_gain_fetish_submission_effect
	first_past = carn_i_gained_fetish_submission_effect
	third = carn_they_gain_fetish_submission_effect
	third_past = carn_they_gained_fetish_submission_effect
	global = carn_gain_fetish_submission_effect
	global_past = carn_gained_fetish_submission_effect
}

carn_add_fetish_raping_effect = {
	first = carn_i_gain_fetish_raping_effect
	first_past = carn_i_gained_fetish_raping_effect
	third = carn_they_gain_fetish_raping_effect
	third_past = carn_they_gained_fetish_raping_effect
	global = carn_gain_fetish_raping_effect
	global_past = carn_gained_fetish_raping_effect
}

carn_add_fetish_being_raped_effect = {
	first = carn_i_gain_fetish_being_raped_effect
	first_past = carn_i_gained_fetish_being_raped_effect
	third = carn_they_gain_fetish_being_raped_effect
	third_past = carn_they_gained_fetish_being_raped_effect
	global = carn_gain_fetish_being_raped_effect
	global_past = carn_gained_fetish_being_raped_effect
}

carn_add_fetish_lactation_effect = {
	first = carn_i_gain_fetish_lactation_effect
	first_past = carn_i_gained_fetish_lactation_effect
	third = carn_they_gain_fetish_lactation_effect
	third_past = carn_they_gained_fetish_lactation_effect
	global = carn_gain_fetish_lactation_effect
	global_past = carn_gained_fetish_lactation_effect
}

carn_remove_all_fetishes_effect = {
	first = carn_i_lose_fetishes_effect
	first_past = carn_i_lost_fetishes_effect
	third = carn_they_lose_fetishes_effect
	third_past = carn_they_lost_fetishes_effect
	global = carn_lose_fetishes_effect
	global_past = carn_lost_fetishes_effect
}

carn_remove_fetish_effect = {
	first = carn_i_lose_fetish_effect
	first_past = carn_i_lost_fetish_effect
	third = carn_they_lose_fetish_effect
	third_past = carn_they_lost_fetish_effect
	global = carn_lose_fetish_effect
	global_past = carn_lost_fetish_effect
}


code:
set_relation_slave = {
	first = carn_i_gain_slave
	third = carn_they_gain_slave
	global = carn_they_gain_slave
	first_past = carn_i_got_slave
	third_past = carn_they_got_slave
	global_past = carn_they_got_slave
}

set_relation_slave_owner = {
	first = carn_i_gain_slave_owner
	third = carn_they_gain_slave_owner
	global = carn_they_gain_slave_owner
	first_past = carn_i_got_slave_owner
	third_past = carn_they_got_slave_owner
	global_past = carn_they_got_slave_owner
}

remove_relation_slave = {
	first = carn_i_lose_slave
	third = carn_they_lose_slave
	global = carn_they_lose_slave
	first_past = carn_i_lost_slave
	third_past = carn_they_lost_slave
	global_past = carn_they_lost_slave
}

remove_relation_slave_owner = {
	first = carn_i_lose_slave_owner
	third = carn_they_lose_slave_owner
	global = carn_they_lose_slave_owner
	first_past = carn_i_lost_slave_owner
	third_past = carn_they_lost_slave_owner
	global_past = carn_they_lost_slave_owner
}

set_relation_dominant = {
	first = carn_i_gain_dominant
	third = carn_they_gain_dominant
	global = carn_they_gain_dominant
	first_past = carn_i_got_dominant
	third_past = carn_they_got_dominant
	global_past = carn_they_got_dominant
}

remove_relation_dominant = {
	first = carn_i_lose_dominant
	third = carn_they_lose_dominant
	global = carn_they_lose_dominant
	first_past = carn_i_lost_dominant
	third_past = carn_they_lost_dominant
	global_past = carn_they_lost_dominant
}

set_relation_submissive = {
	first = carn_i_gain_submissive
	third = carn_they_gain_submissive
	global = carn_they_gain_submissive
	first_past = carn_i_got_submissive
	third_past = carn_they_got_submissive
	global_past = carn_they_got_submissive
}

remove_relation_submissive = {
	first = carn_i_lose_submissive
	third = carn_they_lose_submissive
	global = carn_they_lose_submissive
	first_past = carn_i_lost_submissive
	third_past = carn_they_lost_submissive
	global_past = carn_they_lost_submissive
}


code:
dominant = {
	alias = { dominant_short dominants dominant_possessive dominants_possessive }
	parent = relation
}

fetish = {
	alias = { fetishes }
}

lactation = {
	alias = { lactating milk milk_production }
}

prostitute = {
	texture = "gfx/interface/icons/traits/prostitute.dds"
	alias = { prostitutes prostitution prostitute_possessive prostitutes_possessive }
}

slave = {
	texture = "gfx/interface/icons/traits/slave.dds"
	alias = { slaves slavery slave_possessive slaves_possessive }
	parent = relation
}

slave_market = {
}

slave_owner = {
	texture = "gfx/interface/icons/icon_carn_slave_owner.dds"
	alias = { slave_owners slave_owner_possessive slave_owners_possessive }
	parent = relation
}

submissive = {
	alias = { submissive_short submissives submissive_possessive submissives_possessive }
	parent = relation
}

anal = {
	parent = fetish
}

sadism = {
	parent = fetish
}

masochism = {
	parent = fetish
}

bestiality = {
	parent = fetish
}

watersports = {
	parent = fetish
}

scat = {
	parent = fetish
}

gore = {
	parent = fetish
}

foot_play = {
	parent = fetish
}

bondage = {
	parent = fetish
}

domination = {
	parent = fetish
}

submission = {
	parent = fetish
}

raping = {
	parent = fetish
}

being_raped = {
	parent = fetish
}

lactation_fetish = {
	parent = fetish
}

unknown_fetish = {
	parent = fetish
}


code:
carn_sex_interaction = {
	default = carn_sex_interaction_enabled
	carn_sex_interaction_disabled = {
		flag = GG_can_change_rule
	}
	carn_sex_interaction_enabled = {
		flag = GG_can_change_rule
	}
	carn_sex_interaction_no_cd = {
		flag = GG_can_change_rule
	}
}

carn_arousal_stress = {
	default = carn_arousal_stress_enabled
	carn_arousal_stress_disabled = {
		flag = GG_can_change_rule
	}
	carn_arousal_stress_enabled = {
		flag = GG_can_change_rule
	}
}

carn_slavery_content = {
	default = carn_slavery_content_enabled
	carn_slavery_content_disabled = {
		flag = GG_can_change_rule
	}
	carn_slavery_content_enabled = {
		flag = GG_can_change_rule
	}
	carn_slavery_content_require_acceptance = {
		flag = GG_can_change_rule
	}
	carn_slavery_content_consensual_only = {
		flag = GG_can_change_rule
	}
}

carn_slavery_default_religious_doctrine = {
	default = carn_slavery_default_religious_doctrine_historical
	carn_slavery_default_religious_doctrine_historical = {}
	carn_slavery_default_religious_doctrine_accepted = {}
	carn_slavery_default_religious_doctrine_shunned = {}
	carn_slavery_default_religious_doctrine_criminal = {}
	carn_slavery_default_religious_doctrine_inverted = {}
}

carn_prostitution_content = {
	default = carn_prostitution_content_female_only
	carn_prostitution_content_disabled = {
		flag = GG_can_change_rule
	}
	carn_prostitution_content_any_gender = {
		flag = GG_can_change_rule
	}
	carn_prostitution_content_female_only = {
		flag = GG_can_change_rule
	}
	carn_prostitution_content_male_only = {
		flag = GG_can_change_rule
	}
}

carn_prostitution_default_religious_doctrine = {
	default = carn_prostitution_default_religious_doctrine_shunned
	carn_prostitution_default_religious_doctrine_shunned = {}
	carn_prostitution_default_religious_doctrine_accepted = {}
	carn_prostitution_default_religious_doctrine_criminal = {}
}

carn_dt = {
	default = carn_dt_enabled
	carn_dt_disabled = {
		flag = GG_can_change_rule
	}
	carn_dt_enabled = {
		flag = GG_can_change_rule
	}
}

carn_dt_trait_names = {
	default = carn_dt_trait_names_default
	carn_dt_trait_names_default = {
		flag = GG_can_change_rule
	}
	carn_dt_trait_names_immersive = {
		flag = GG_can_change_rule
	}
}

carn_dt_dick_small = {
	default = carn_dt_dick_small_bad
	carn_dt_dick_small_good = {
		flag = GG_can_change_rule
	}
	carn_dt_dick_small_bad = {
		flag = GG_can_change_rule
	}
}

carn_dt_dick_big = {
	default = carn_dt_dick_big_good
	carn_dt_dick_big_good = {
		flag = GG_can_change_rule
	}
	carn_dt_dick_big_bad = {
		flag = GG_can_change_rule
	}
}

carn_dt_tits_small = {
	default = carn_dt_tits_small_bad
	carn_dt_tits_small_good = {
		flag = GG_can_change_rule
	}
	carn_dt_tits_small_bad = {
		flag = GG_can_change_rule
	}
}

carn_dt_tits_big = {
	default = carn_dt_tits_big_good
	carn_dt_tits_big_good = {
		flag = GG_can_change_rule
	}
	carn_dt_tits_big_bad = {
		flag = GG_can_change_rule
	}
}

carn_futa_content = {
	default = carn_futa_content_very_rare
	carn_futa_content_disabled = {
		flag = GG_can_change_rule
	}
	carn_futa_content_no_seeding = {
		flag = GG_can_change_rule
	}
	carn_futa_content_very_rare = {
		flag = GG_can_change_rule
	}
	carn_futa_content_rare = {
		flag = GG_can_change_rule
	}
	carn_futa_content_uncommon = {
		flag = GG_can_change_rule
	}
	carn_futa_content_common = {
		flag = GG_can_change_rule
	}
	carn_futa_content_very_common = {
		flag = GG_can_change_rule
	}
	carn_futa_content_always = {
		flag = GG_can_change_rule
	}
}

carn_futa_trait_name = {
	default = carn_futa_trait_name_futa
	carn_futa_trait_name_futa = {
		flag = GG_can_change_rule
	}
	carn_futa_trait_name_hermaphrodite = {
		flag = GG_can_change_rule
	}
}

carn_futa_trait_inheritance = {
	default = carn_futa_trait_inheritance_enabled
	carn_futa_trait_inheritance_disabled = {
		flag = GG_can_change_rule
	}
	carn_futa_trait_inheritance_enabled = {
		flag = GG_can_change_rule
	}
}

carn_lactation = {
	default = carn_lactation_female_only
	carn_lactation_disabled = {
		flag = GG_can_change_rule
	}
	carn_lactation_female_only = {
		flag = GG_can_change_rule
	}
	carn_lactation_male_only = {
		flag = GG_can_change_rule
	}
	carn_lactation_any_gender = {
		flag = GG_can_change_rule
	}
}

carn_std = {
	default = carn_std_enabled
	carn_std_enabled = {
		flag = GG_can_change_rule
	}
	carn_std_disabled = {
		flag = GG_can_change_rule
	}
}

carn_pregnancy_complications = {
	default = carn_pregnancy_complications_default
	carn_pregnancy_complications_default = {
		flag = GG_can_change_rule
	}
	carn_pregnancy_complications_never = {
		flag = GG_can_change_rule
	}
}

carn_birth_control = {
	default = carn_birth_control_any_gender
	carn_birth_control_disabled = {
		flag = GG_can_change_rule
	}
	carn_birth_control_any_gender = {
		flag = GG_can_change_rule
	}
	carn_birth_control_female_only = {
		flag = GG_can_change_rule
	}
	carn_birth_control_male_only = {
		flag = GG_can_change_rule
	}
    carn_birth_control_player_only = {
		flag = GG_can_change_rule
	}
}

carn_fetishes = {
	default = carn_fetishes_disabled
	carn_fetishes_disabled = {
		flag = GG_can_change_rule
	}
	carn_fetishes_enabled = {
		flag = GG_can_change_rule
	}
}

carn_content_consent = {
	default = carn_content_consent_dubcon
	carn_content_consent_dubcon = {
		flag = GG_can_change_rule
	}
	carn_content_consent_noncon = {
		flag = GG_can_change_rule
	}
	carn_content_consent_always = {
		flag = GG_can_change_rule
	}
}

carn_content_anal = {
	default = carn_content_anal_disabled
	carn_content_anal_disabled = {
		flag = GG_can_change_rule
	}
	carn_content_anal_enabled = {
		flag = GG_can_change_rule
	}
}

carn_content_painful = {
	default = carn_content_painful_disabled
	carn_content_painful_disabled = {
		flag = GG_can_change_rule
	}
	carn_content_painful_enabled = {
		flag = GG_can_change_rule
	}
}

carn_content_bestiality = {
	default = carn_content_bestiality_disabled
	carn_content_bestiality_disabled = {
		flag = GG_can_change_rule
	}
	carn_content_bestiality_enabled = {
		flag = GG_can_change_rule
	}
}

carn_content_watersports = {
	default = carn_content_watersports_disabled
	carn_content_watersports_disabled = {
		flag = GG_can_change_rule
	}
	carn_content_watersports_enabled = {
		flag = GG_can_change_rule
	}
}

carn_content_scat = {
	default = carn_content_scat_disabled
	carn_content_scat_disabled = {
		flag = GG_can_change_rule
	}
	carn_content_scat_enabled = {
		flag = GG_can_change_rule
	}
}

carn_content_gore = {
	default = carn_content_gore_disabled
	carn_content_gore_disabled = {
		flag = GG_can_change_rule
	}
	carn_content_gore_enabled = {
		flag = GG_can_change_rule
	}
}


code:
carn_slave_hook = {
	strong = yes
}


code:
action_carn_can_demand_free_illegal_slaves_interaction = {
	combine_into_one = yes

	check_create_action = {
		every_vassal_or_below = {
			carn_try_create_demand_free_illegal_slaves_important_action_effect = yes
		}
	}

	unimportant = {
		scope:recipient = {
			has_important_relationship_with_root_trigger = no
			is_close_family_or_spouse_of_root_trigger = no
			trigger_if = {
				limit = {
					is_landed = yes
					target_is_liege_or_above = root
				}
				NOT = {
					liege = root #Direct vassal
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = carn_demand_free_illegal_slaves_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}


code:
action_carn_can_sex_interaction = {
	combine_into_one = yes
	check_create_action = {
		if = {
			limit = {
        		NOR = {
					has_game_rule = carn_sex_interaction_disabled
					has_character_flag = carn_sex_interaction_effect_cd
				}
				carn_can_have_sex_trigger = yes
				OR = {
					any_consort = {
						root = { is_attracted_to_gender_of = prev }
						is_busy_in_events_localised = yes
						carn_can_have_sex_trigger = yes
					}
					any_relation = {
						type = lover
						root = { is_attracted_to_gender_of = prev }
						is_busy_in_events_localised = yes
						carn_can_have_sex_trigger = yes
					}
				}
			}
			every_consort = {
				limit = {
					root = { is_attracted_to_gender_of = prev }
            		is_busy_in_events_localised = yes
					carn_can_have_sex_trigger = yes
				}
				add_to_temporary_list = sexable_partner_list
			}
			every_relation = {
				type = lover
				limit = {
					root = { is_attracted_to_gender_of = prev }
					is_busy_in_events_localised = yes
					carn_can_have_sex_trigger = yes
				}
				add_to_temporary_list = sexable_partner_list
			}
			every_in_list = {
				list = sexable_partner_list
				try_create_important_action = {
					important_action_type = action_carn_can_sex_interaction
					actor = root
					recipient = this
				}
			}
		}
	}

	effect = {
		open_interaction_window = {
			interaction = carn_sex_interaction
			actor = scope:actor
			recipient = scope:recipient
		}
	}
}


code:
@msg_good_soundeffect = "event:/SFX/UI/Notifications/Messages/sfx_ui_message_theme_positive"
@msg_bad_soundeffect = "event:/SFX/UI/Notifications/Messages/sfx_ui_message_theme_negative"

carn_event_arousal = {
	icon = "icon_stress_gain"
	title = carn_msg_arousal
	desc = event_message_effect
	style = bad
	soundeffect = @msg_bad_soundeffect
}

carn_prostitute_random_event_good = {
	icon = "prostitution"
	title = event_message_title
	desc = event_message_effect
	style = good
	soundeffect = @msg_good_soundeffect
}

carn_prostitute_random_event_bad = {
	icon = "prostitution"
	title = event_message_title
	desc = event_message_effect
	style = bad
	soundeffect = @msg_bad_soundeffect
}


code:
carn_using_birth_control_modifier = {
	icon = fertility_positive
	fertility = -1.0
	monthly_income = -0.1
	monthly_piety = -0.05
}


code:
carn_working_as_prostitute_1_modifier = {
	icon = prostitution_positive
	spouse_opinion = -10
	monthly_income = 0.5
	monthly_prestige = -0.5
	dread_loss_mult = 1.0
}

carn_working_as_prostitute_2_modifier = {
	icon = prostitution_positive
	spouse_opinion = -10
	monthly_income = 1.0
	monthly_prestige = -0.3
	dread_loss_mult = 0.5
}

carn_working_as_prostitute_3_modifier = {
	icon = prostitution_positive
	spouse_opinion = -10
	monthly_income = 2.0
	monthly_prestige = -0.1
}


code:
carn_recently_raped = {
	icon = health_negative
	health = -0.25
}


code:
on_birth_mother = {
	events = {
		carn_abortion.0001 # Clear carn_block_aborting_next_normal_pregnancy after pregnancy ends
	}
}

on_pregnancy_ended_mother = {
	events = {
		carn_abortion.0001 # Clear carn_block_aborting_next_normal_pregnancy after pregnancy ends
	}
}


code:
on_pregnancy_mother = {
	events = {
		carn_absolute_birth_control.0001
	}
}

# fires when a pregnancy is ended due to `carn_absolute_birth_control`
# no effects currently, meant for modders
carn_on_absolute_birth_control_end_pregnancy = {
	events = {
	}
}


code:
# Increase stress every year
yearly_playable_pulse = {
	events = {
		carn_arousal.0001
	}
}


code:
carn_on_start_birth_control = {
}

carn_on_stop_birth_control = {
}


code:
child_personality_gain = {
	random_events = {
		300 = carn_childhood.0001
	}
}


code:
############################################################################
# carn_on_custom_pregnancy_stage_change
############################################################################
# No events, meant for modders
# Fires when a custom pregnancy advances in stage
# Use `carn_has_custom_pregnancy_trigger` and `carn_custom_pregnancy_stage_equals_trigger` as conditions for your custom pregnancy stage event
# If you want multiple stages, use `carn_setup_delayed_custom_pregnancy_stage_change` to fire another event after a while
carn_on_custom_pregnancy_stage_change = {
	events = {
	}
}

############################################################################
# carn_on_start_custom_pregnancy
############################################################################
carn_on_start_custom_pregnancy = {
	events = {
	}
}

############################################################################
# carn_on_end_custom_pregnancy
############################################################################
# fires right before the custom pregnancy ends
carn_on_end_custom_pregnancy = {
	events = {
	}
}

############################################################################
# carn_on_custom_pregnancy_replace_normal_pregnancy
############################################################################
# fires when a modder starts a custom pregnancy on a character that is already pregnant with a normal pregnancy, ending the normal pregnancy
# custom pregnancy has been set, but normal pregnancy has not been ended
# scope:new_pregnancy_type - the new pregnancy type, i.e. "flag:dragon_egg"
carn_on_custom_pregnancy_replace_normal_pregnancy = {
	events = {
	}
}

############################################################################
# carn_on_custom_pregnancy_failed_to_replace_normal_pregnancy
############################################################################
# fires when a modder attempts to start a custom pregnancy on a character that is already pregnant with a normal pregnancy, but can't because the normal pregnancy cannot be aborted
# scope:new_pregnancy_type - the new pregnancy type, i.e. "flag:dragon_egg"
carn_on_custom_pregnancy_failed_to_replace_normal_pregnancy = {
	events = {
	}
}

############################################################################
# carn_on_custom_pregnancy_replace_custom_pregnancy
############################################################################
# fires when a modder overwrites a character's custom pregnancy with another one
# current custom pregnancy has not been changed yet
# scope:new_pregnancy_type - the new pregnancy type, i.e. "flag:dragon_egg"
carn_on_custom_pregnancy_replace_custom_pregnancy = {
	events = {
	}
}

############################################################################
# carn_on_custom_pregnancy_failed_to_replace_custom_pregnancy
############################################################################
# fires when a modder attempts to start a custom pregnancy on a character that is already pregnant with a custom pregnancy, but can't because the earlier pregnancy cannot be aborted
# scope:new_pregnancy_type - the new pregnancy type, i.e. "flag:dragon_egg"
carn_on_custom_pregnancy_failed_to_replace_custom_pregnancy = {
	events = {
	}
}


code:
# fired when a character gets the deviant trait
# each of these events should apply a new fetish
carn_on_new_random_fetish = {
	random_events = {
		30 = carn_fetish.1000 # Anal
		20 = carn_fetish.1001 # Sadism
		40 = carn_fetish.1002 # Masochism
		5 = carn_fetish.1003 # Bestiality
		5 = carn_fetish.1004 # Watersports
		5 = carn_fetish.1005 # Scat
		5 = carn_fetish.1006 # Gore
		5 = carn_fetish.1007 # Foot play
		45 = carn_fetish.1008 # Bondage
		45 = carn_fetish.1009 # Domination
		65 = carn_fetish.1010 # Submission
		15 = carn_fetish.1011 # Raping
		15 = carn_fetish.1012 # Being raped
		30 = carn_fetish.1013 # Lactation
	}
}

# currently does nothing, meant for modders
# use scope:carn_new_fetish to get the fetish flag
carn_on_gain_fetish = {
	events = {
	}
}

# currently does nothing, meant for modders
carn_on_lose_fetish = {
	events = {
	}
}


code:
carn_character_initialization_pulse = {
    events = {
		carn_fetish.0001 # set fetishes for characters that don't have them
	}
}


code:
random_yearly_everyone_pulse = {
	events = {
		carn_futa.0010 # futa impregnation
	}
}


code:
random_yearly_everyone_pulse = {
	events = {
		carn_lactation.0001 # Yearly milk production decrease
	}
}

on_pregnancy_mother = {
	events = {
		carn_lactation.0002 # Gain milk production on pregnancy
	}
}

carn_character_initialization_pulse = {
    events = {
		carn_lactation.0003 # Seed lactation from pregnancy on character initialization pulse
	}
}

# does nothing as of now, meant for modders to hook into
# triggered when a character that was not formerly lactating starts lactating
carn_on_start_lactating = {
	events = {
	}
}

# does nothing as of now, meant for modders to hook into
# triggered when a character that was lactating stops lactating
carn_on_stop_lactating = {
	events = {
	}
}

# does nothing as of now, meant for modders to hook into
# triggered whenever an effect modifies a character's milk production
carn_on_milk_production_change = {
	events = {
	}
}


code:
on_pregnancy_mother = {
	events = {
		carn_pregnancy_suppression.0001 # maintenance event suppressed
		carn_pregnancy_suppression.0002 # notification event suppressed
	}
}

on_pregnancy_ended_mother = {
	events = {
		carn_pregnancy_suppression.0003 # Clear next_on_pregnancy_* flags when pregnancy ends
	}
}

# This is called when the `carn_suppress_*_on_pregnancy_maintenance` flag causes pregnancy.0001 to be suppressed
# does nothing baseline, meant for modders to substitute their own maintenance event
carn_on_pregnancy_maintenance_suppressed = {
	events = {
	}
}

# This is called when the `carn_suppress_*_on_pregnancy_notification` flag causes a pregnancy notification event to be suppressed
# (any event in pregnancy_events.txt other than pregnancy.0001)
# does nothing baseline, meant for modders to substitute their own notification event
carn_on_pregnancy_notification_suppressed = {
	events = {
	}
}

# This is called when the `carn_suppress_*_on_birth_notification` flag causes a birth notification event to be suppressed
# (birth.1001 and similar events)
# does nothing baseline, meant for modders to substitute their own notification event
# uses on_birth_mother scopes, root is mother
# remember to trigger both mother and father events
carn_on_birth_notification_suppressed = {
	events = {
	}
}


code:
on_game_start_after_lobby = {
  events = {
    carn_prostitution_doctrine_seeding.0001
  }
}

on_faith_created = {
  events = {
    carn_prostitution_doctrine_seeding.0002
  }
}


code:
random_yearly_everyone_pulse = {
	on_actions = {
		carn_prostitution_yearly_maintenance_pulse
	}
}

carn_prostitution_yearly_maintenance_pulse = {
	trigger = {
		carn_is_working_as_prostitute_trigger = yes
	}
	effect = {
		save_scope_as = carn_prostitute
		if = {
			limit = {
				OR = {
					carn_can_be_prostitute_trigger = no
					carn_can_have_sex_trigger = no
					effective_age >= carn_prostitution_age_cutoff
				}
			}
			send_interface_message = {
				type = event_generic_neutral
				title = msg_carn_stopped_working_as_prostitute
				left_icon = scope:carn_prostitute
				custom_tooltip = carn_can_no_longer_work_as_prostitute_tooltip
			}
			every_relation = {
				type = slave_owner
				send_interface_message = {
					type = event_generic_neutral
					title = msg_carn_stopped_working_as_prostitute
					left_icon = scope:carn_prostitute
					custom_tooltip = carn_can_no_longer_work_as_prostitute_tooltip
				}
			}
			carn_stop_working_as_prostitute_effect = yes
		}
		else = {
			random_list = {
				200 = {
					# nothing
				}
				100 = {
					carn_prostitution_rank_up_chance_modifier = yes
					trigger_event = {
						id = carn_prostitution_random_events.0001
					}
				}
				700 = {
					trigger_event = { on_action = carn_prostitution_random_events_pulse }
				}
			}
		}
	}
}

carn_prostitution_random_events_pulse = {
	random_events = {
		100 = carn_prostitution_random_events.0002 # Lost prestige
		100 = carn_prostitution_random_events.0003 # Lost piety (shunned)
		100 = carn_prostitution_random_events.0004 # Got STD
		100 = carn_prostitution_random_events.0005 # Big tipper

		100 = carn_prostitution_random_events.0010 # Someone notable lays with you
	}
}

carn_on_start_working_as_prostitute = {
}

carn_on_stop_working_as_prostitute = {
}


code:
##################################################################################
# carn_on_sex_v2
##################################################################################

# Triggers whenever a character has sex via event or decision, in the scope of that character.

# root = the character that sees the sex scene event
# scope:carn_sex_partner = the other partner in the sex effect

# Unlike carn_on_sex, it triggers just once for both partners,
# instead of once for each of the partners

carn_on_sex_v2 = {
	events = {
	}
}

##################################################################################
# carn_sex_scene
##################################################################################
# Empty list of sex interactions. Modders should add their own scenes to this as random_events.
# You can adjust the random chance based on how often you think your event should appear.

carn_sex_scene = {
	random_events = {
		100 = carn_sex_scene.001
	}
}

##################################################################################
# carn_on_sex
##################################################################################

# Triggers whenever a character has sex via event or decision, in the scope of that character.

# DOES NOT trigger off random passive pregnancy with spouse/consort

# You can check the chance of pregnancy with
# scope:carn_sex_char_1_could_be_impregnated,
# scope:carn_sex_char_2_could_be_impregnated

# You can check whether impregnation happened with
# scope:carn_sex_char_1_impregnated,
# scope:carn_sex_char_2_impregnated

# You can check for specific sex acts with "carn_sex_scene_was_vaginal = yes", etc

# root = the character that sees the sex scene event
# scope:carn_sex_partner = the other partner in the sex effect

carn_on_sex = {
	events = {
	}
}

##################################################################################
# carn_on_pregnancy
##################################################################################

# Triggers whenever a character gets pregnant due to carn_had_sex_with_effect
# or carn_had_sex_with_effect_v2, in the scope of that character.

# scope:mother = the character that got pregnant (same as root)
# scope:father = the character responsible for the pregnancy

carn_on_pregnancy = {
	events = {
	}
}


code:
# on_set_relation_slave
# on_remove_relation_slave
# on_death_relation_slave (fired for the slaveowner when they die)
# on_set_relation_slave_owner
# on_remove_relation_slave_owner
# on_death_relation_slave_owner (fired for the slave when they die)
# carn_on_slave_enslaved
# carn_on_slave_freed

on_set_relation_slave = {
	effect = {
		if = {
			limit = {
				NOT = {
					has_hook_of_type = {
						type = carn_slave_hook
						target = scope:target
					}
				}
			}
			add_hook_no_toast = {
				type = carn_slave_hook
				target = scope:target
			}
		}
	}
}

on_remove_relation_slave = {
	effect = {
		if = {
			limit = {
				has_hook_of_type = {
					type = carn_slave_hook
					target = scope:target
				}
			}
			remove_hook = {
				type = carn_slave_hook
				target = scope:target
			}
		}
	}
}

on_death_relation_slave = { # fired for the slaveowner when they die
	effect = {
		# inheritance of slaves
		remove_relation_slave = scope:target
		reverse_add_opinion = {
			target = scope:target
			modifier = carn_former_slave_or_slave_owner_opinion
		}
		primary_heir = {
			set_relation_slave = scope:target
		}
	}
}

on_set_relation_slave_owner = {
	effect = {
		scope:target = {
			if = {
				limit = {
					NOT = {
						has_hook_of_type = {
							type = carn_slave_hook
							target = root
						}
					}
				}
				add_hook_no_toast = {
					type = carn_slave_hook
					target = root
				}
			}
		}
	}
}

on_remove_relation_slave_owner = {
	effect = {
		scope:target = {
			if = {
				limit = {
					has_hook_of_type = {
						type = carn_slave_hook
						target = root
					}
				}
				remove_hook = {
					type = carn_slave_hook
					target = root
				}
			}
		}
	}
}

on_death_relation_slave_owner = { # fired for the slave when they die
	effect = {
		remove_relation_slave_owner = scope:target
		reverse_add_opinion = {
			target = scope:target
			modifier = carn_former_slave_or_slave_owner_opinion
		}
	}
}

# not used in Carnalitas, exposed for mods
# ROOT is the slave
# scope:new_owner is the new owner
carn_on_slave_enslaved = {
}

# not used in Carnalitas, exposed for mods
# ROOT is the slave
# scope:former_owner is the former owner
carn_on_slave_freed = {
}

######################################################################
# vanilla on_actions
######################################################################

on_birth_child = {
	events = {
		carn_slave.0003 # Slave newborns get their owner relation
	}
}

on_title_gain = {
	events = {
		carn_slave.0002 # Slaves are freed when they gain land for any reason
	}
}


code:
yearly_playable_pulse = {
	events = {
		carn_slave_prostitution.0001 # owners earn money from their slave-prostitutes
	}
}


code:
on_game_start_after_lobby = {
  events = {
    carn_slavery_doctrine_seeding.0001
  }
}

on_faith_created = {
  events = {
    carn_slavery_doctrine_seeding.0002
  }
}


code:
carn_character_initialization_pulse = {
	events = {
		carn_futa.0001 # initialize this character with futa trait
		carn_dt.0001 # initialize this character with dt traits
	}
}

on_birth_child = {
	events = {
		carn_dt.0002 # turn off dt traits for newborns
	}
}

on_16th_birthday = {
	events = {
		carn_dt.0003 # activate dt traits for children coming of age
	}
}


code:
on_game_start = {
    on_actions = {
        on_carnalitas_start
    }
}
on_carnalitas_start = {
    effect = {
        set_global_variable = {
			name = carn_active
			value = yes
		}
    }
}


code:
# there's no way for us to easily catch every character that's generated
# so instead we have to do this horribly clunky workaround...

# "zzz" so that this on_game_start_after_lobby fires last after all pdx events (hopefully)

on_game_start_after_lobby = {
	events = {
		carn_character_initialization.0001
	}
}

on_join_court = {
	on_actions = { carn_character_initialization_pulse }
}

on_birthday = {
	on_actions = { carn_character_initialization_pulse }
}

on_title_gain = {
	on_actions = { carn_character_initialization_pulse }
}

on_birth_child = {
	on_actions = { carn_character_initialization_pulse }
}

carn_character_initialization_pulse = {
	events = {
	}
}


code:
carn_prostitution_crime_opinion = {
	opinion = -15
	imprisonment_reason = yes
	revoke_title_reason = yes
}

carn_prostitution_intolerant_opinion = {
	opinion = -15
}


code:
carn_raped_family_member = {
	opinion = -20
	years = 20
	decaying = yes
	imprisonment_reason = yes
}

carn_raped_my_friend = {
	opinion = -20
	years = 20
	decaying = yes
	imprisonment_reason = yes
}

carn_raped_my_lover = {
	opinion = -100
	decaying = yes
	years = 50
	imprisonment_reason = yes
	execute_reason = yes
}

carn_raped_me = {
	opinion = -50
	decaying = yes
	years = 50
	imprisonment_reason = yes
	execute_reason = yes
}


code:
carn_block_sex_interaction_to_opinion = {
	opinion = 0
}

carn_block_sex_interaction_from_opinion = {
	opinion = 0
}