code:
# Old effects preserved for backward compatibility
# These are DEPRECATED, please use the new effects

#################################################################################
# carn_sex_scene_effect
# Written by Cheri, it that likes warm drinks, Ernie Collins
#################################################################################
#
# carn_sex_scene_effect is the general purpose scripted effect to trigger a sex scene event through Carnalitas.
#
# First, use the scripted effects to request flags for the sex scene, such as "vaginal", "noncon", or "bdsm".
#
# Second, call carn_sex_scene_effect with the following arguments:
#
# PLAYER is the character who the event will be shown to.
#
# TARGET is the character that PLAYER is having sex with.
#
# STRESS_EFFECTS is yes or no, whether you want the sex scene to affect stress.
#
# DRAMA is yes or no, whether you want the sex scene to trigger adultery and peasant affair storylines. (Note: This doesn't stop a relationship from being adulterous, or a child from being born a bastard. It just affects whether the story cycles will happen.)
#
# (Cheri recommends setting STRESS_EFFECTS = yes and DRAMA = yes unless you have a really good reason.)
#
# The sex scene generator triggers an on_action with a list of random_events that match all of the requested tags.
#
# The sex scene events themselves will define the triggers for those events to be shown, i.e. a consensual lesbian sex event should check that both participants are female and carn_sex_scene_is_consensual = yes
#
# If no event is eligible to be shown, the default paradox sex scene generator will be used.
#
# An example of using carn_sex_scene_effect to trigger a dominant rape scene:
#
# effect = {
# 	carn_sex_scene_request_giving_player = yes
# 	carn_sex_scene_request_dom_player = yes
# 	carn_sex_scene_request_vaginal = yes
# 	carn_sex_scene_request_cum_inside = yes
# 	carn_sex_scene_request_noncon = yes
# 	carn_sex_scene_effect = {
# 		PLAYER = root
#		TARGET = scope:target
#		STRESS_EFFECTS = yes
#		DRAMA = yes
# 	}
# }
#
# You can also exclude certain flags with the syntax `carn_sex_scene_exclude_*` where `*` is the name of the flag.

carn_sex_scene_effect = {
	$PLAYER$ = {
		# Set stress and drama
		if = {
			limit = { $STRESS_EFFECTS$ = no }
			carn_sex_scene_no_stress_effect = yes
		}
		if = {
			limit = { $DRAMA$ = no }
			carn_sex_scene_no_drama_effect = yes
		}

		# Execute the new effect
		carn_sex_scene_effect_v2 = {
			PARTNER = $TARGET$
		}

		# Cleanup sex scene flags
		# This must happen in a delayed event after the sex scene had already fired
		trigger_event = {
			id = carn_sex_scene_cleanup.0001
			delayed = yes
		}
	}
}

# Use these to REQUEST a sex scene with the appropriate flag.

carn_sex_scene_request_giving_player = {
	carn_sex_scene_character_request_flag = { FLAG = giving_player }
}

carn_sex_scene_request_receiving_player = {
	carn_sex_scene_character_request_flag = { FLAG = receiving_player }
}

carn_sex_scene_request_dom_player = {
	carn_sex_scene_character_request_flag = { FLAG = dom_player }
}

carn_sex_scene_request_sub_player = {
	carn_sex_scene_character_request_flag = { FLAG = sub_player }
}

carn_sex_scene_request_oral = {
	carn_sex_scene_request_flag = { FLAG = oral }
}

carn_sex_scene_request_vaginal = {
	carn_sex_scene_request_flag = { FLAG = vaginal }
}

carn_sex_scene_request_anal = {
	if = {
		limit = { has_game_rule = carn_content_anal_enabled }
		carn_sex_scene_request_flag = { FLAG = anal }
	}
}

carn_sex_scene_request_handjob = {
	carn_sex_scene_request_flag = { FLAG = handjob }
}

carn_sex_scene_request_masturbation = {
	carn_sex_scene_request_flag = { FLAG = masturbation }
}

carn_sex_scene_request_orgy = {
	carn_sex_scene_request_flag = { FLAG = orgy }
}

carn_sex_scene_request_cum_inside = {
	carn_sex_scene_request_flag = { FLAG = cum_inside }
}

carn_sex_scene_request_cum_outside = {
	carn_sex_scene_request_flag = { FLAG = cum_outside }
}

carn_sex_scene_request_consensual = {
	carn_sex_scene_request_flag = { FLAG = consensual }
}

carn_sex_scene_request_noncon = {
	if = {
		limit = { has_game_rule = carn_content_consent_noncon }
		carn_sex_scene_request_flag = { FLAG = noncon }
	}
	else_if = {
		limit = { has_game_rule = carn_content_consent_dubcon }
		carn_sex_scene_request_flag = { FLAG = dubcon }
	}
}

carn_sex_scene_request_dubcon = {
	if = {
		limit = { NOT = { has_game_rule = carn_content_consent_always } }
		carn_sex_scene_request_flag = { FLAG = dubcon }
	}
}

carn_sex_scene_request_painful = {
	if = {
		limit = { has_game_rule = carn_content_painful_enabled }
		carn_sex_scene_request_flag = { FLAG = painful }
	}
}

carn_sex_scene_request_bdsm = {
	carn_sex_scene_request_flag = { FLAG = bdsm }
}

carn_sex_scene_request_bestiality = {
	if = {
		limit = { has_game_rule = carn_content_bestiality_enabled }
		carn_sex_scene_request_flag = { FLAG = bestiality }
	}
}

carn_sex_scene_request_petplay = {
	carn_sex_scene_request_flag = { FLAG = petplay }
}

carn_sex_scene_request_bondage = {
	carn_sex_scene_request_flag = { FLAG = bondage }
}

carn_sex_scene_request_toy = {
	carn_sex_scene_request_flag = { FLAG = toy }
}

carn_sex_scene_request_watersports = {
	if = {
		limit = { has_game_rule = carn_content_watersports_enabled }
		carn_sex_scene_request_flag = { FLAG = watersports }
	}
}

carn_sex_scene_request_scat = {
	if = {
		limit = { has_game_rule = carn_content_scat_enabled }
		carn_sex_scene_request_flag = { FLAG = scat }
	}
}

carn_sex_scene_request_gore = {
	if = {
		limit = { has_game_rule = carn_content_gore_enabled }
		carn_sex_scene_request_flag = { FLAG = gore }
	}
}

# Use these to exclude a specific flag when requesting a sex scene.

carn_sex_scene_exclude_giving_player = {
	carn_sex_scene_character_exclude_flag = { FLAG = giving_player }
}

carn_sex_scene_exclude_receiving_player = {
	carn_sex_scene_character_exclude_flag = { FLAG = receiving_player }
}

carn_sex_scene_exclude_dom_player = {
	carn_sex_scene_character_exclude_flag = { FLAG = dom_player }
}

carn_sex_scene_exclude_sub_player = {
	carn_sex_scene_character_exclude_flag = { FLAG = sub_player }
}

carn_sex_scene_exclude_oral = {
	carn_sex_scene_exclude_flag = { FLAG = oral }
}

carn_sex_scene_exclude_vaginal = {
	carn_sex_scene_exclude_flag = { FLAG = vaginal }
}

carn_sex_scene_exclude_anal = {
	if = {
		limit = { has_game_rule = carn_content_anal_enabled }
		carn_sex_scene_exclude_flag = { FLAG = anal }
	}
}

carn_sex_scene_exclude_handjob = {
	carn_sex_scene_exclude_flag = { FLAG = handjob }
}

carn_sex_scene_exclude_masturbation = {
	carn_sex_scene_exclude_flag = { FLAG = masturbation }
}

carn_sex_scene_exclude_orgy = {
	carn_sex_scene_exclude_flag = { FLAG = orgy }
}

carn_sex_scene_exclude_cum_inside = {
	carn_sex_scene_exclude_flag = { FLAG = cum_inside }
}

carn_sex_scene_exclude_cum_outside = {
	carn_sex_scene_exclude_flag = { FLAG = cum_outside }
}

carn_sex_scene_exclude_consensual = {
	carn_sex_scene_exclude_flag = { FLAG = consensual }
}

carn_sex_scene_exclude_noncon = {
	if = {
		limit = { has_game_rule = carn_content_consent_noncon }
		carn_sex_scene_exclude_flag = { FLAG = noncon }
	}
	else_if = {
		limit = { has_game_rule = carn_content_consent_dubcon }
		carn_sex_scene_exclude_flag = { FLAG = dubcon }
	}
}

carn_sex_scene_exclude_dubcon = {
	if = {
		limit = { NOT = { has_game_rule = carn_content_consent_always } }
		carn_sex_scene_exclude_flag = { FLAG = dubcon }
	}
}

carn_sex_scene_exclude_painful = {
	if = {
		limit = { has_game_rule = carn_content_painful_enabled }
		carn_sex_scene_exclude_flag = { FLAG = painful }
	}
}

carn_sex_scene_exclude_bdsm = {
	carn_sex_scene_exclude_flag = { FLAG = bdsm }
}

carn_sex_scene_exclude_bestiality = {
	if = {
		limit = { has_game_rule = carn_content_bestiality_enabled }
		carn_sex_scene_exclude_flag = { FLAG = bestiality }
	}
}

carn_sex_scene_exclude_petplay = {
	carn_sex_scene_exclude_flag = { FLAG = petplay }
}

carn_sex_scene_exclude_bondage = {
	carn_sex_scene_exclude_flag = { FLAG = bondage }
}

carn_sex_scene_exclude_toy = {
	carn_sex_scene_exclude_flag = { FLAG = toy }
}

carn_sex_scene_exclude_watersports = {
	if = {
		limit = { has_game_rule = carn_content_watersports_enabled }
		carn_sex_scene_exclude_flag = { FLAG = watersports }
	}
}

carn_sex_scene_exclude_scat = {
	if = {
		limit = { has_game_rule = carn_content_scat_enabled }
		carn_sex_scene_exclude_flag = { FLAG = scat }
	}
}

carn_sex_scene_exclude_gore = {
	if = {
		limit = { has_game_rule = carn_content_gore_enabled }
		carn_sex_scene_exclude_flag = { FLAG = gore }
	}
}

# Use these to DEFINE a sex scene event in the immediate block, so that events triggering from carn_on_sex will know what flags the event has.

carn_sex_scene_is_giving_player = {
	carn_sex_scene_character_is_flag = { FLAG = giving_player }
}

carn_sex_scene_is_receiving_player = {
	carn_sex_scene_character_is_flag = { FLAG = receiving_player }
}

carn_sex_scene_is_dom_player = {
	carn_sex_scene_character_is_flag = { FLAG = dom_player }
}

carn_sex_scene_is_sub_player = {
	carn_sex_scene_character_is_flag = { FLAG = sub_player }
}

carn_sex_scene_is_oral = {
	carn_sex_scene_is_flag = { FLAG = oral }
}

carn_sex_scene_is_vaginal = {
	carn_sex_scene_is_flag = { FLAG = vaginal }
}

carn_sex_scene_is_anal = {
	carn_sex_scene_is_flag = { FLAG = anal }
}

carn_sex_scene_is_handjob = {
	carn_sex_scene_is_flag = { FLAG = handjob }
}

carn_sex_scene_is_masturbation = {
	carn_sex_scene_is_flag = { FLAG = masturbation }
}

carn_sex_scene_is_orgy = {
	carn_sex_scene_is_flag = { FLAG = orgy }
}

carn_sex_scene_is_cum_inside = {
	carn_sex_scene_is_flag = { FLAG = cum_inside }
}

carn_sex_scene_is_cum_outside = {
	carn_sex_scene_is_flag = { FLAG = cum_outside }
}

carn_sex_scene_is_consensual = {
	carn_sex_scene_is_flag = { FLAG = consensual }
}

carn_sex_scene_is_noncon = {
	carn_sex_scene_is_flag = { FLAG = noncon }
}

carn_sex_scene_is_dubcon = {
	carn_sex_scene_is_flag = { FLAG = dubcon }
}

carn_sex_scene_is_painful = {
	carn_sex_scene_is_flag = { FLAG = painful }
}

carn_sex_scene_is_bdsm = {
	carn_sex_scene_is_flag = { FLAG = bdsm }
}

carn_sex_scene_is_bestiality = {
	carn_sex_scene_is_flag = { FLAG = bestiality }
}

carn_sex_scene_is_petplay = {
	carn_sex_scene_is_flag = { FLAG = petplay }
}

carn_sex_scene_is_bondage = {
	carn_sex_scene_is_flag = { FLAG = bondage }
}

carn_sex_scene_is_toy = {
	carn_sex_scene_is_flag = { FLAG = toy }
}

carn_sex_scene_is_watersports = {
	carn_sex_scene_is_flag = { FLAG = watersports }
}

carn_sex_scene_is_scat = {
	carn_sex_scene_is_flag = { FLAG = scat }
}

carn_sex_scene_is_gore = {
	carn_sex_scene_is_flag = { FLAG = gore }
}

# Internal effects

carn_sex_scene_character_request_flag = {
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:$FLAG$
	}
}

carn_sex_scene_request_flag = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:$FLAG$
	}
}

carn_sex_scene_character_exclude_flag = {
	add_to_variable_list = {
		name = carn_sex_scene_character_excluded_flag_list
		target = flag:$FLAG$
	}
}

carn_sex_scene_exclude_flag = {
	add_to_variable_list = {
		name = carn_sex_scene_excluded_flag_list
		target = flag:$FLAG$
	}
}

carn_sex_scene_character_is_flag = {
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:$FLAG$
	}
}

carn_sex_scene_is_flag = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:$FLAG$
	}
}

carn_clear_sex_scene_flags_effect = {
	scope:carn_sex_player = {
		carn_sex_scene_clean_up_flags_effect = yes
		carn_sex_scene_clean_up_character_flags_effect = yes
	}
	scope:carn_sex_partner = {
		carn_sex_scene_clean_up_character_flags_effect = yes
	}
}

carn_set_sex_scene = {
	carn_sex_scene_is_$SEXSCENE$ = yes
}

carn_clean_up_player_variables = {
}


code:
# carn_enslave_effect
# carn_enslave_interaction_effect
# carn_free_slave_effect
# carn_free_illegal_slaves_effect
# carn_free_slave_interaction_effect
# carn_buy_slave_effect
# carn_try_create_demand_free_illegal_slaves_important_action_effect

# enslaves SLAVE to OWNER
# will also incur opinion, tyranny, piety effects if DRAMA is true
carn_enslave_effect = {
	$SLAVE$ = { save_temporary_scope_as = new_slave }
	$OWNER$ = { save_temporary_scope_as = new_owner }

	scope:new_slave = {
		if = {
			limit = { is_ruler = yes }
			every_character_war = {
				if = {
					limit = {
						primary_attacker = scope:new_slave
					}
					end_war = invalidated
				}
				else_if = {
					limit = {
						primary_defender = scope:new_slave
					}
					if = {
						limit = { primary_attacker = scope:new_owner }
						end_war = attacker
					}
					else = {
						end_war = invalidated
					}
				}
				else = {
					remove_participant = scope:new_slave
				}
			}
			depose = yes
		}
		hidden_effect = {
			remove_trait = former_slave
			add_trait = slave
			# their gold is removed, representing their treasury being lost, and also to prevent abuse
			if = {
				limit = {gold > 0}
				remove_short_term_gold = gold
			}
			if = {
				limit = { is_married = yes }
				every_spouse = {
					divorce = scope:new_slave
				}
			}
			if = {
				limit = { exists = betrothed }
				break_betrothal = betrothed
			}
			every_concubine = {
				scope:new_slave = { remove_concubine = prev }
			}
			every_relation = {
				type = guardian
				remove_relation_ward = prev
			}
			if = {
				# By default, randomly generated peasant leaders will disappear if captured in battle
				limit = {
					has_character_flag =  peasant_faction_random_peasant
				}
				add_character_flag = peasant_revolt_do_not_kill
			}
		}
	}

	scope:new_owner = {
		set_relation_slave = scope:new_slave
		if = {
			limit = {
				scope:new_slave = { NOT = { is_courtier_of = scope:new_owner } }
			}
			hidden_effect = { add_courtier = scope:new_slave }
		}
	}

	if = {
		limit = { $DRAMA$ = yes }

		scope:new_slave = {
			# Victim hates slaver
			add_prestige_level = -1
			if = {
				limit = {
					NOT = { has_trait = contrite }
				}
				if = {
					limit = {
						scope:new_owner = {
							has_execute_reason = scope:new_slave
						}
					}
					add_opinion = {
						target = scope:new_owner
						modifier = carn_enslaved_me_opinion
					}
				}
				else = {
					add_opinion = {
						target = scope:new_owner
						modifier = carn_enslaved_me_crime_opinion
					}
				}
			}

			# Victim's family & spouse hates slaver
			every_close_family_member = {
				limit = { NOT = { this = scope:new_owner } }
				add_to_temporary_list = victim_family_list
			}
			every_spouse = {
				limit = {
					NOR = {
						this = scope:new_owner
						is_in_list = victim_family_list
					}
				}
				add_to_temporary_list = victim_family_list
			}

			if = {
				limit = {
					any_in_list = {
						list = victim_family_list
						count > 0
					}
				}
				if = {
					limit = {
						scope:new_owner = {
							has_execute_reason = scope:new_slave
						}
					}
					every_in_list = {
						list = victim_family_list
						custom = all_close_family_and_spouses
						add_opinion = {
							target = scope:new_owner
							modifier = carn_enslaved_close_family_opinion
						}
					}
				}
				else = {
					every_in_list = {
						list = victim_family_list
						custom = all_close_family_and_spouses
						add_opinion = {
							target = scope:new_owner
							modifier = carn_enslaved_close_family_crime_opinion
						}
					}
				}
			}

			# Victim's dynasty hates new_owner
			if = {
				limit = {
					exists = dynasty
					exists = scope:new_owner.dynasty
					NOT = { dynasty = scope:new_owner.dynasty }
					NOT = {
						scope:new_owner = {
							has_execute_reason = scope:new_slave
						}
					}
				}
				dynasty = {
					every_dynasty_member = {
						limit = {
							NOR = {
								this = scope:new_slave
								is_in_list = victim_family_list
							}
						}
						custom = all_dynasty_members
						add_to_temporary_list = victim_dynasty_list
						add_opinion = {
							target = scope:new_owner
							modifier = carn_enslaved_dynasty_member_opinion
						}
					}
				}
			}

			# Victim's friends and lovers
			every_relation = {
				type = friend
				limit = {
					NOR = {
						this = scope:new_slave
						is_in_list = victim_family_list
						is_in_list = victim_dynasty_list
					}
				}
				add_to_list = victim_close_relations_list
			}
			every_relation = {
				type = lover
				limit = {
					NOR = {
						this = scope:new_slave
						is_in_list = victim_family_list
						is_in_list = victim_dynasty_list
						is_in_list = victim_close_relations_list
					}
				}
				add_to_list = victim_close_relations_list
			}
			if = {
				limit = {
					any_in_list = {
						list = victim_close_relations_list
						always = yes
					}
				}
				every_in_list = {
					list = victim_close_relations_list
					custom = all_friends_and_lovers
					add_opinion = {
						target = scope:new_owner
						modifier = carn_enslaved_close_relation_opinion
					}
				}
			}
		}

		scope:new_owner = {
			# UI notification for new owner
			hidden_effect = {
				send_interface_message = {
					type = event_generic_neutral
					title = carn_msg_enslave
					right_icon = scope:new_slave
					custom_tooltip = carn_msg_scope_new_slave_becomes_your_slave_desc
				}
			}

			# stress effects
			if = {
				limit = {
					has_execute_reason = scope:new_slave
				}
				consume_execute_reasons = scope:new_slave
				stress_impact = {
					compassionate = medium_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
			else = {
				stress_impact = {
					compassionate = medium_stress_impact_gain
					just = medium_stress_impact_gain
				}
			}

			if = {
				limit = {
					scope:new_slave = {
						time_in_prison = { years > 15 } # No one even remembers who they are anymore
					}
				}
				# No dread for you
			}
			else_if = { # Executing Emperors/HoF is quite dreadful
				limit = {
					scope:new_slave = {
						OR = {
							highest_held_title_tier >= tier_empire
							scope:new_owner.faith.religious_head = scope:new_slave # Your head of faith
						}
					}
				}
				add_dread = execute_interaction_massive_dread_gain
			}
			else_if = {
				limit = {
					scope:new_slave = {
						OR = {
							highest_held_title_tier >= tier_kingdom
							tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_empire }
							is_powerful_vassal_of = scope:new_owner # Is your powerful vassal
							target_is_vassal_or_below = scope:new_owner # Your liege/s
							is_close_family_of = scope:new_owner
						}
					}
				}
				add_dread = execute_interaction_major_dread_gain
			}
			else_if = {
				limit = {
					scope:new_slave = {
						OR = {
							highest_held_title_tier >= tier_duchy
							tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_kingdom }
							AND = { # Is your vassal, and higher than Baron
								is_vassal_of = scope:new_owner
								primary_title.tier > tier_barony
							}
							AND = { # Peer Vassals
								exists = primary_title
								primary_title.tier > tier_barony
								exists = liege
								liege = scope:new_owner.liege
							}
							has_trait = peasant_leader
						}
					}
				}
				add_dread = execute_interaction_medium_dread_gain
			}
			else_if = {
				limit = {
					scope:new_slave = {
						OR = {
							highest_held_title_tier >= tier_county
							tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_duchy }
							is_vassal_of = scope:new_owner # Is your Baron vassal
							is_close_or_extended_family_of = scope:new_owner

							scope:new_owner = { # Executing close family of your vassals is dreadful...
								any_vassal = {
									is_close_family_of = scope:new_slave
								}
							}
							scope:new_owner = { # Executing close family of your liege/s is the same...
								any_liege_or_above = {
									is_close_family_of = scope:new_slave
								}
							}
						}
					}
				}
				add_dread = execute_interaction_minor_dread_gain
			}

			if = {
				limit = {
					OR = {
						faith = {
							NOT = { has_doctrine = carn_doctrine_same_slavery_accepted }
							faith_hostility_level = {
								target = scope:new_slave.faith
								value < faith_hostile_level
							}
						}
						faith = {
							NOT = { has_doctrine = carn_doctrine_other_slavery_accepted }
							faith_hostility_level = {
								target = scope:new_slave.faith
								value >= faith_hostile_level
							}
						}
					}
				}
				add_piety = medium_piety_loss
				add_piety_level = -1
				stress_impact = {
					zealous = medium_stress_impact_gain
				}
			}

			# Stress loss
			if = {
				limit = {
					has_trait = sadistic
				}
				stress_impact = {
					sadistic = medium_stress_impact_loss
				}
			}
			if = {
				limit = {
					has_relation_rival = scope:new_slave
				}
				add_prestige = medium_prestige_gain
				if = {
					limit = {
						NOR = {
							has_trait = vengeful
							has_trait = forgiving
						}
					}
					add_stress = major_stress_loss
				}
				else = {
					stress_impact = {
						vengeful = massive_stress_impact_loss
						forgiving = 0 #No stress reduction
					}
				}
			}

			#Tyranny
			if = {
				limit = {
					exists = scope:recipient
					has_execute_reason = scope:new_slave
				}
				custom_tooltip = carn_is_allowed_to_enslave_desc
			}
			else_if = {
				limit = {
					OR = {
						AND = {
							has_execute_reason = scope:new_slave
							NOT = { exists = scope:recipient }
						}
						is_at_war_with = scope:new_slave
					}
				}
				custom_tooltip = IS_ALLOWED_TO_EXECUTE_NO_RECIPIENT_DESC
			}
			else_if = {
				limit = {
					scope:new_slave = {
						OR = {
							is_playable_character = no
							NOT = { is_of_major_or_minor_interest_trigger = { CHARACTER = scope:new_owner } }
						}
					}
					scope:new_owner.faith = {
						faith_hostility_level = {
							target = scope:new_slave.faith
							value > faith_astray_level
						}
					}
				}
				custom_tooltip = carn_is_allowed_to_enslave_hostile_religion_desc
			}
			else_if = {
				limit = {
					scope:new_slave = { target_is_liege_or_above = prev }
				}
				add_tyranny = execution_tyranny_gain
			}
			else_if = {
				limit = {
					scope:new_slave = {
						NOT = { exists = liege }
						exists = host
					}
					any_pool_guest = { count > 0 }
				}
				every_pool_guest = {
					limit = {
						NOR = {
							this = scope:new_slave
							is_in_list = guest_list
						}
					}
					add_to_temporary_list = guest_list
				}
				every_in_list = {
					list = guest_list
					custom = all_your_guests
					add_opinion = {
						target = prev
						modifier = carn_enslaved_guest_opinion
					}
				}
			}
			else = {
				if = {
					limit = {
						scope:new_slave.liege = {
							NOT = { this = scope:new_slave }
						}
					}
					scope:new_slave.liege = {
						add_opinion = {
							target = prev
							modifier = carn_enslaved_my_countryman_opinion
						}
					}
				}
			}
		}
	}

	hidden_effect = {
		scope:new_slave = {
			if = {
				limit = { is_imprisoned_by = scope:new_owner }
				release_from_prison = yes
			}
			trigger_event = {
				on_action = carn_on_slave_enslaved
			}
		}
	}
}

# frees the scoped character if they are a slave
# does not have any opinion effects, this is just for unsetting the relation and doing the busywork only.
carn_free_slave_effect = {
	every_relation = {
		type = slave_owner
		remove_relation_slave = prev
		hidden_effect = {
			add_opinion = {
				target = prev
				modifier = carn_former_slave_or_slave_owner_opinion
			}
			reverse_add_opinion = {
				target = prev
				modifier = carn_former_slave_or_slave_owner_opinion
			}
		}
		save_scope_as = former_owner
	}
	hidden_effect = {
		remove_trait = slave
		add_trait = former_slave
		trigger_event = {
			on_action = carn_on_slave_freed
		}
	}
}

# frees all slaves of this character that are unlawfully enslaved under this character's faith
carn_free_illegal_slaves_effect = {
  scope:recipient = {
    if = {
      limit = { faith = { has_doctrine = carn_doctrine_same_slavery_crime } }
      every_relation = {
        type = slave
        limit = {
			scope:recipient.faith = {
				faith_hostility_level = {
					target = prev.faith
					value < faith_hostile_level
				}
			}
		}
        carn_free_slave_effect = yes
      }
    }
    if = {
      limit = { faith = { has_doctrine = carn_doctrine_other_slavery_crime } }
      every_relation = {
        type = slave
        limit = {
			scope:recipient.faith = {
				faith_hostility_level = {
					target = prev.faith
					value >= faith_hostile_level
				}
			}
		}
        carn_free_slave_effect = yes
      }
    }
  }
}

# carn_free_slave_interaction_effect
# scopes: slave and owner

carn_free_slave_interaction_effect = {

	scope:slave = {

		carn_free_slave_effect = yes

		# Demand Gold
		if = {
			limit = {
				scope:gold = yes
			}
			pay_short_term_gold = {
				gold = scope:slave.carn_slave_price_value
				target = scope:owner
			}
		}

		# Demand Gold (not enough to pay)
		if = {
			limit = {
				scope:current_gold = yes
			}
			pay_short_term_gold = {
				gold = scope:slave.current_gold_value
				target = scope:owner
			}
		}

		# Demand Conversion
		if = {
			limit = {
				scope:demand_conversion = yes
			}
			set_character_faith = scope:actor.faith
			add_opinion = {
				modifier = demanded_my_conversion_opinion
				target = scope:owner
			}
		}

		# Renounce Claims
		if = {
			limit = {
				scope:renounce_claims = yes
			}
			add_opinion = {
				modifier = demanded_claim_renouncement
				target = scope:owner
			}
			scope:slave = {
				every_claim = {
					explicit = yes
					limit = {
						save_temporary_scope_as = temp_claim
						OR = {
							holder = scope:owner
							AND = {
								exists = holder
								NOT = { prev = { target_is_liege_or_above = scope:owner } }
								holder = { target_is_liege_or_above = scope:owner }
							}
							scope:owner = {
								any_held_title = {
									is_de_jure_liege_or_above_target = scope:temp_claim
								}
							}
						}
					}
					scope:slave = { remove_claim = prev }
				}
			}
		}

		# Gain Hook
		if = {
			limit = {
				scope:gain_hook = yes
			}
			add_opinion = {
				modifier = demanded_hook
				target = scope:owner
			}
			scope:owner = {
				add_hook = { #Hook effect must match gain_hook option condition
					target = scope:slave
					type = favor_hook
				}
			}
		}

		# No Demands Added
		if = {
			limit = {
				scope:gold = no
				scope:current_gold = no
				scope:demand_conversion = no
				scope:renounce_claims = no
				scope:gain_hook = no
			}
			scope:slave = {
				add_opinion = {
					modifier = carn_freed_me_from_slavery_opinion
					target = scope:owner
				}
			}
			scope:owner = {
				add_dread = minor_dread_loss
				if = {
					limit = {
						faith = {
							NOR = {
								AND = {
									faith_hostility_level = {
										target = scope:slave.faith
										value < faith_hostile_level
									}
									has_doctrine = carn_doctrine_same_slavery_accepted
								}
								AND = {
									faith_hostility_level = {
										target = scope:slave.faith
										value >= faith_hostile_level
									}
									has_doctrine = carn_doctrine_other_slavery_accepted
								}
							}
						}
					}
					add_piety = medium_piety_gain
					stress_impact = {
						zealous = minor_stress_impact_loss
					}
				}
				stress_impact = {
					compassionate = medium_stress_impact_loss
					sadistic = medium_stress_impact_gain
					callous = minor_stress_impact_gain
				}
			}
		}
	}

	scope:owner = {
		hidden_effect = {
			send_interface_message = {
				type = event_generic_neutral
				title = carn_msg_slave_freed
				right_icon = scope:slave
				custom_tooltip = carn_msg_scope_slave_is_no_longer_your_slave_desc
			}
		}
	}
}

carn_buy_slave_effect = {
	save_scope_value_as = {
		name = slave_price
		value = $SLAVE_PRICE$
	}
	scope:slave = {
		hidden_effect = {
			every_relation = {
				type = slave_owner
				remove_relation_slave = prev
				add_opinion = {
					target = prev
					modifier = carn_former_slave_or_slave_owner_opinion
				}
				reverse_add_opinion = {
					target = prev
					modifier = carn_former_slave_or_slave_owner_opinion
				}
			}
			if = {
				limit = { is_imprisoned_by = scope:seller }
				release_from_prison = yes
			}
		}
	}
	scope:buyer = {
		if = {
			limit = {
				gold >= scope:slave_price
			}
			pay_short_term_gold = {
				gold = scope:slave_price
				target = scope:seller
			}
		}
		else = {
			custom_tooltip = carn_buyer_not_enough_gold_for_slave_price_tooltip
			hidden_effect = {
				pay_short_term_gold = {
					gold = current_gold_value
					target = scope:seller
				}
			}
		}
		set_relation_slave = scope:slave
		hidden_effect = {
			if = {
				limit = {
					scope:slave = { NOT = { is_courtier_of = scope:buyer } }
				}
				add_courtier = scope:slave
			}
			send_interface_message = {
				type = event_generic_neutral
				title = carn_msg_enslave
				right_icon = scope:slave
				custom_tooltip = carn_msg_scope_slave_becomes_your_slave_desc
			}
		}
	}
	scope:seller = {
		hidden_effect = {
			send_interface_message = {
				type = event_generic_neutral
				title = carn_msg_slave_sold
				right_icon = scope:slave
				custom_tooltip = carn_msg_scope_slave_is_no_longer_your_slave_desc
			}
		}
	}
}

carn_try_create_demand_free_illegal_slaves_important_action_effect = {
	save_temporary_scope_as = potential_recipient
	if = {
		limit = {
			target_is_liege_or_above = root
			is_ai = yes
			OR = {
				AND = {
					faith = {
						has_doctrine = carn_doctrine_same_slavery_crime
					}
					any_relation = {
						type = slave
						scope:potential_recipient.faith = {
							faith_hostility_level = {
								target = prev.faith
								value < faith_hostile_level
							}
						}
					}
				}
				AND = {
					faith = {
						has_doctrine = carn_doctrine_other_slavery_crime
					}
					any_relation = {
						type = slave
						scope:potential_recipient.faith = {
							faith_hostility_level = {
								target = prev.faith
								value >= faith_hostile_level
							}
						}
					}
				}
			}
		}
		try_create_important_action = {
			important_action_type = action_carn_can_demand_free_illegal_slaves_interaction
			actor = root
			recipient = this
		}
	}
}

repo_name: Synthael/carnalitas

license: mit


code:
# carn_seed_slavery_doctrines_effect
# if game rule is off, removes slavery doctrines from all faiths
# otherwise, seeds a faith's religious doctrines for slavery
carn_seed_slavery_doctrines_effect = {
	if = {
		limit = { has_game_rule = carn_slavery_content_disabled }
		if = {
			limit = { has_doctrine = carn_doctrine_same_slavery_crime }
			remove_doctrine = carn_doctrine_same_slavery_crime
		}
		if = {
			limit = { has_doctrine = carn_doctrine_same_slavery_shunned }
			remove_doctrine = carn_doctrine_same_slavery_shunned
		}
		if = {
			limit = { has_doctrine = carn_doctrine_same_slavery_accepted }
			remove_doctrine = carn_doctrine_same_slavery_accepted
		}
		if = {
			limit = { has_doctrine = carn_doctrine_other_slavery_crime }
			remove_doctrine = carn_doctrine_other_slavery_crime
		}
		if = {
			limit = { has_doctrine = carn_doctrine_other_slavery_shunned }
			remove_doctrine = carn_doctrine_other_slavery_shunned
		}
		if = {
			limit = { has_doctrine = carn_doctrine_other_slavery_accepted }
			remove_doctrine = carn_doctrine_other_slavery_accepted
		}
	}
	else = {
		if = {
			limit = {
				NOR = {
					has_doctrine = carn_doctrine_same_slavery_crime
					has_doctrine = carn_doctrine_same_slavery_shunned
					has_doctrine = carn_doctrine_same_slavery_accepted
				}
			}
			if = {
				limit = {
					OR = {
						has_game_rule = carn_slavery_default_religious_doctrine_historical
						has_game_rule = carn_slavery_default_religious_doctrine_criminal
					}
				}
				add_doctrine = carn_doctrine_same_slavery_crime
			}
			else_if = {
				limit = {
					has_game_rule = carn_slavery_default_religious_doctrine_shunned
				}
				add_doctrine = carn_doctrine_same_slavery_shunned
			}
			else = {
				add_doctrine = carn_doctrine_same_slavery_accepted
			}
		}
		if = {
			limit = {
				NOR = {
					has_doctrine = carn_doctrine_other_slavery_crime
					has_doctrine = carn_doctrine_other_slavery_shunned
					has_doctrine = carn_doctrine_other_slavery_accepted
				}
			}
			if = {
				limit = {
					OR = {
						has_game_rule = carn_slavery_default_religious_doctrine_historical
						has_game_rule = carn_slavery_default_religious_doctrine_accepted
					}
				}
				add_doctrine = carn_doctrine_other_slavery_accepted
			}
			else_if = {
				limit = {
					has_game_rule = carn_slavery_default_religious_doctrine_shunned
				}
				add_doctrine = carn_doctrine_other_slavery_shunned
			}
			else = {
				add_doctrine = carn_doctrine_other_slavery_crime
			}
		}
	}
}


code:
extramarital_sex_exposure_consequences_effect = {
	save_temporary_scope_as = sex_character
	save_temporary_scope_value_as = {
		name = spouse_event
		value = $SPOUSE_EVENT$
	}

	#APPLY TRAITS & REMOVE PIETY LEVELS
	add_adulterer_fornicator_trait_or_nothing_effect = yes
	remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = adulterer } #Fornicator falls under same doctrine
	if = {
		limit = {
			OR = {
				AND = {
					exists = scope:sex_partner
					relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = scope:sex_partner }
				}
				AND = {
					exists = scope:unknown_sex_partner
					relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = scope:unknown_sex_partner }
				}
			}
		}
		add_trait = sodomite
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = sodomite }
	}
	if = {
		limit = {
			exists = scope:sex_partner
			relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = scope:sex_partner }
		}
		add_trait = incestuous
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = incestuous }
	}
	#Family Feud
	house_feud_lover_exposure_effect = yes

	#APPLY UNFAITHFUL OPINIONS TOWARDS SPOUSES AND LOVERS (only visible for directly relevant exposure)
	if = {
		limit = {
			always = yes #TODO_CD: commented out until TIT-16673 has been resolved due to errors
			#OR = {
			#	scope:sex_character = root
			#	AND = {
			#		exists = scope:sex_partner
			#		scope:sex_partner = root
			#	}
			#	any_spouse = {
			#		this = root
			#	}
			#	any_relation = {
			#		type = soulmate
			#		this = root
			#	}
			#}
		}
		every_relation = {
			type = soulmate
			limit = {
				soulmate_relation_is_exclusive_trigger = yes
				NOT = { #So we don't add it both at discovery and exposure
					has_opinion_modifier = {
						target = scope:sex_character
						modifier = betrayed_our_promise
					}
				}
			}
			add_opinion = {
				target = scope:sex_character
				modifier = betrayed_our_promise
			}
		}

		every_spouse = {
			if = {
				limit = {
					NOT = { faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active } }
				}
				add_opinion = {
					target = scope:sex_character
					modifier = unfaithful_spouse_exposed_opinion
				}
			}
		}
	}
	else = {
		hidden_effect = {
			every_relation = {
				type = soulmate
				limit = {
					soulmate_relation_is_exclusive_trigger = yes
					NOT = { #So we don't add it both at discovery and exposure
						has_opinion_modifier = {
							target = scope:sex_character
							modifier = betrayed_our_promise
						}
					}
				}
				add_opinion = {
					target = scope:sex_character
					modifier = betrayed_our_promise
				}
			}

			every_spouse = {
				if = {
					limit = {
						NOT = { faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }  }
					}
					add_opinion = {
						target = scope:sex_character
						modifier = unfaithful_spouse_exposed_opinion
					}
				}
			}
		}
	}
	every_spouse = {
		hidden_effect = {
			#Remove duplicate opinion from discovery
			if = {
				limit = {
					has_opinion_modifier = {
						target = scope:sex_character
						modifier = unfaithful_spouse_discovered_opinion
					}
				}
				remove_opinion = {
					target = scope:sex_character
					modifier = unfaithful_spouse_discovered_opinion
				}
			}
		}

		#NOTIFY SPOUSE (SHOULD ALWAYS BE "NO" IF EFFECT IS USED ON SECRET EXPOSURE)
		if = {
			limit = {
				scope:spouse_event = yes
				NOT = { faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active } }
			}

			scope:sex_character = { save_scope_as = adultery_spouse }
			trigger_event = adultery.4001
		}
	}
}


code:
extramarital_sex_exposure_consequences_effect = {
	save_temporary_scope_as = sex_character
	save_temporary_scope_value_as = {
		name = spouse_event
		value = $SPOUSE_EVENT$
	}

	#APPLY TRAITS & REMOVE PIETY LEVELS
	add_adulterer_fornicator_trait_or_nothing_effect = yes
	remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = adulterer } #Fornicator falls under same doctrine
	if = {
		limit = {
			OR = {
				AND = {
					exists = scope:sex_partner
					relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = scope:sex_partner }
				}
				AND = {
					exists = scope:unknown_sex_partner
					relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = scope:unknown_sex_partner }
				}
			}
		}
		add_trait = sodomite
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = sodomite }
	}
	if = {
		limit = {
			exists = scope:sex_partner
			relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = scope:sex_partner }
		}
		add_trait = incestuous
		remove_piety_level_for_shunned_or_criminal_trait_effect = { TRAIT = incestuous }
	}
	#Family Feud
	house_feud_lover_exposure_effect = yes

	#APPLY UNFAITHFUL OPINIONS TOWARDS SPOUSES AND LOVERS (only visible for directly relevant exposure)
	if = {
		limit = {
			always = yes #TODO_CD: commented out until TIT-16673 has been resolved due to errors
			#OR = {
			#	scope:sex_character = root
			#	AND = {
			#		exists = scope:sex_partner
			#		scope:sex_partner = root
			#	}
			#	any_spouse = {
			#		this = root
			#	}
			#	any_relation = {
			#		type = soulmate
			#		this = root
			#	}
			#}
		}
		every_relation = {
			type = soulmate
			limit = {
				soulmate_relation_is_exclusive_trigger = yes
				NOT = { #So we don't add it both at discovery and exposure
					has_opinion_modifier = {
						target = scope:sex_character
						modifier = betrayed_our_promise
					}
				}
			}
			add_opinion = {
				target = scope:sex_character
				modifier = betrayed_our_promise
			}
		}

		every_spouse = {
			if = {
				limit = {
					NOR = {
						scope:sex_character = {
							carn_should_have_no_consequences_for_extramarital_sex_trigger = yes
						}
						faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
					}
				}
				add_opinion = {
					target = scope:sex_character
					modifier = unfaithful_spouse_exposed_opinion
				}
			}
		}
	}
	else = {
		hidden_effect = {
			every_relation = {
				type = soulmate
				limit = {
					soulmate_relation_is_exclusive_trigger = yes
					NOT = { #So we don't add it both at discovery and exposure
						has_opinion_modifier = {
							target = scope:sex_character
							modifier = betrayed_our_promise
						}
					}
				}
				add_opinion = {
					target = scope:sex_character
					modifier = betrayed_our_promise
				}
			}

			every_spouse = {
				if = {
					limit = {
						NOR = {
							scope:sex_character = {
								carn_should_have_no_consequences_for_extramarital_sex_trigger = yes
							}
							faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
						}
					}
					add_opinion = {
						target = scope:sex_character
						modifier = unfaithful_spouse_exposed_opinion
					}
				}
			}
		}
	}
	every_spouse = {
		hidden_effect = {
			#Remove duplicate opinion from discovery
			if = {
				limit = {
					has_opinion_modifier = {
						target = scope:sex_character
						modifier = unfaithful_spouse_discovered_opinion
					}
				}
				remove_opinion = {
					target = scope:sex_character
					modifier = unfaithful_spouse_discovered_opinion
				}
			}
		}

		#NOTIFY SPOUSE (SHOULD ALWAYS BE "NO" IF EFFECT IS USED ON SECRET EXPOSURE)
		if = {
			limit = {
				scope:spouse_event = yes
				NOR = {
					scope:sex_character = {
						carn_should_have_no_consequences_for_extramarital_sex_trigger = yes
					}
					faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
				}
			}

			scope:sex_character = { save_scope_as = adultery_spouse }
			trigger_event = adultery.4001
		}
	}
}


code:
had_sex_with_effect = {
	# Use carn_had_sex_with_effect to be able to set the pregnancy chances,
	# since some vanilla events that use this effect use custom pregnancy chances
	save_temporary_scope_as = carn_had_sex_with_effect_character
	carn_had_sex_with_effect = {
		CHARACTER_1 = scope:carn_had_sex_with_effect_character
		CHARACTER_2 = $CHARACTER$
		C1_PREGNANCY_CHANCE = $PREGNANCY_CHANCE$
		C2_PREGNANCY_CHANCE = $PREGNANCY_CHANCE$
		STRESS_EFFECTS = yes
		DRAMA = yes
	}
}


code:
give_deviant_secret_or_trait_effect = {
	save_temporary_scope_as = deviant_character
	if = {
		limit = { #Not already a deviant
			is_adult = yes
			NOR = {
				has_trait = deviant
				any_secret = { secret_type = secret_deviant }
			}
		}
		if = {
			limit = {
				trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = deviant GENDER_CHARACTER = scope:deviant_character }
			}
			add_secret = {
				type = secret_deviant
			}
		}
		else_if = {
			limit = {
				is_adult = yes
			}
			add_trait = deviant
		}
	}
}

add_adulterer_trait_or_nothing_effect = {
	save_scope_as = adulterer_check
	if = {
		limit = {
			is_married = yes
			trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = adulterer GENDER_CHARACTER = scope:adulterer_check }
		}
		add_trait_force_tooltip = adulterer
	}
}

add_fornicator_trait_or_nothing_effect = {
	save_scope_as = fornicator_check
	if = {
		limit = {
			is_adult = yes
			is_married = no
			trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = fornicator GENDER_CHARACTER = scope:fornicator_check }
		}
		add_trait_force_tooltip = fornicator
	}
}

remove_piety_level_for_shunned_or_criminal_trait_effect = {
	save_temporary_scope_as = piety_character
	if = {
		limit = {
			OR = {
				trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:piety_character.faith GENDER_CHARACTER = scope:piety_character }
				trait_is_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:piety_character.faith GENDER_CHARACTER = scope:piety_character }
			}
		}
		add_piety_level = -1

		# LEGITIMACY LOSS FROM CRIME EXPOSURE
		if = {
			limit = {
				is_valid_for_legitimacy_change = yes
				NOT = { exists = scope:suppress_legitimacy_from_crime }
			}
			if = {
				limit = {
					trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:piety_character.faith GENDER_CHARACTER = scope:piety_character }
				}
				add_legitimacy = minor_legitimacy_loss
			}
			else = { add_legitimacy = medium_legitimacy_loss }
			# Flag that we might not always want to apply future legitimacy losses down the line.
			save_scope_value_as = {
				name = suppress_legitimacy_from_crime
				value = yes
			}
		}
	}
}

# Creates a story about confrontations/choices after discovered infidelity (lover secret discovery)
start_infidelity_confrontation_story_discovery_effect = {
	if = {
		limit = {
			NOR = {
				$DISCOVERER$ = $LOVER_2$
				$DISCOVERER$ = $LOVER_1$
			}
			$DISCOVERER$ = {
				OR = {
					has_relation_lover = $LOVER_1$
					is_spouse_of = $LOVER_1$
					has_relation_lover = $LOVER_2$
					is_spouse_of = $LOVER_2$
				}
			}
			NOR = {
				$LOVER_1$ = {
					any_owned_story = {
						story_type = story_cycle_infidelty_confronter
						var:lover_2 = $LOVER_2$ #var:lover_2 is the secret target i.e. the other person
					}
				}
				$LOVER_2$ = {
					any_owned_story = {
						story_type = story_cycle_infidelty_confronter
						var:lover_2 = $LOVER_1$ #var:lover_2 is the secret target i.e. the other person
					}
				}
			}
			#Exempt marriages to polyamorous spouses.
			NOR = {
				$LOVER_1$ = {
					OR = {
						any_spouse = {
							count = all
							faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
						}
						has_character_flag = block_infidelity_flag
					}
				}
				$LOVER_2$ = {
					OR = {
						any_spouse = {
							count = all
							faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
						}
						has_character_flag = block_infidelity_flag
					}
				}
			}
		}
		infidelity_confrontation_story_creation_effect = { LOVER_1 = $LOVER_1$ LOVER_2 = $LOVER_2$ }
		scope:infidelity_story = {
			add_to_variable_list = {
				name = confronting_partners
				target = $DISCOVERER$
			}
		}
		#Certain changes to desc in event if the secret was revealed through investigation
		if = {
			limit = { $DISCOVERER$ = { is_ai = no } } #Text changes are only relevant to players

			#Save the secrets so we can check them
			$LOVER_1$ = {
				random_secret = {
					limit = {
						secret_type = secret_lover
						secret_target = $LOVER_2$
					}
					add_to_temporary_list = secrets_for_desc
				}
			}
			$LOVER_2$ = {
				random_secret = {
					limit = {
						secret_type = secret_lover
						secret_target = $LOVER_1$
					}
					add_to_temporary_list = secrets_for_desc
				}
			}

			#infidelity_confrontation_1000_investigation_desc
			if = {
				limit = {
					any_in_list = {
						list = secrets_for_desc
						exists = var:revealed_through_investigation_by_desc
						var:revealed_through_investigation_by_desc = $DISCOVERER$
					}
				}
				scope:infidelity_story = {
					set_variable = {
						name = infidelity_confrontation_1000_investigation_desc
						value = yes
					}
				}
			}

			#revealed_through_confession_to_desc
			if = {
				limit = {
					any_in_list = {
						list = secrets_for_desc
						exists = var:revealed_through_confession_to_desc
						var:revealed_through_confession_to_desc = $DISCOVERER$
					}
				}
				scope:infidelity_story = {
					set_variable = {
						name = infidelity_confrontation_1000_confession_desc
						value = yes
					}
				}
			}
		}
	}
}


code:
give_deviant_secret_or_trait_effect = {
	carn_give_deviant_secret_or_trait_no_fetish_effect = yes
	carn_add_random_fetish_effect = yes
}

add_adulterer_trait_or_nothing_effect = {
	save_scope_as = adulterer_check
	if = {
		limit = {
			is_married = yes
			trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = adulterer GENDER_CHARACTER = scope:adulterer_check }
			carn_should_have_no_consequences_for_extramarital_sex_trigger = no
		}
		add_trait_force_tooltip = adulterer
	}
}

add_fornicator_trait_or_nothing_effect = {
	save_scope_as = fornicator_check
	if = {
		limit = {
			is_adult = yes
			is_married = no
			trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = { TRAIT = fornicator GENDER_CHARACTER = scope:fornicator_check }
			carn_should_have_no_consequences_for_extramarital_sex_trigger = no
		}
		add_trait_force_tooltip = fornicator
	}
}

remove_piety_level_for_shunned_or_criminal_trait_effect = {
	save_temporary_scope_as = piety_character
	save_temporary_scope_value_as = {
		name = shunned_trait_check
		value = flag:$TRAIT$
	}
	if = {
		limit = {
			OR = {
				trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:piety_character.faith GENDER_CHARACTER = scope:piety_character }
				trait_is_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:piety_character.faith GENDER_CHARACTER = scope:piety_character }
			}
			NAND = {
				OR = {
					scope:shunned_trait_check = flag:adulterer
					scope:shunned_trait_check = flag:fornicator
				}
				carn_should_have_no_consequences_for_extramarital_sex_trigger = yes
			}
		}
		add_piety_level = -1

		# LEGITIMACY LOSS FROM CRIME EXPOSURE
		if = {
			limit = {
				is_valid_for_legitimacy_change = yes
				NOT = { exists = scope:suppress_legitimacy_from_crime }
			}
			if = {
				limit = {
					trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:piety_character.faith GENDER_CHARACTER = scope:piety_character }
				}
				add_legitimacy = minor_legitimacy_loss
			}
			else = { add_legitimacy = medium_legitimacy_loss }
			# Flag that we might not always want to apply future legitimacy losses down the line.
			save_scope_value_as = {
				name = suppress_legitimacy_from_crime
				value = yes
			}
		}
	}
}

# Creates a story about confrontations/choices after discovered infidelity (lover secret discovery)
start_infidelity_confrontation_story_discovery_effect = {
	if = {
		limit = {
			NOR = {
				$DISCOVERER$ = $LOVER_2$
				$DISCOVERER$ = $LOVER_1$
			}
			$DISCOVERER$ = {
				OR = {
					has_relation_lover = $LOVER_1$
					is_spouse_of = $LOVER_1$
					has_relation_lover = $LOVER_2$
					is_spouse_of = $LOVER_2$
				}
			}
			NOR = {
				$LOVER_1$ = {
					any_owned_story = {
						story_type = story_cycle_infidelty_confronter
						var:lover_2 = $LOVER_2$ #var:lover_2 is the secret target i.e. the other person
					}
				}
				$LOVER_2$ = {
					any_owned_story = {
						story_type = story_cycle_infidelty_confronter
						var:lover_2 = $LOVER_1$ #var:lover_2 is the secret target i.e. the other person
					}
				}
			}
			#Exempt marriages to polyamorous spouses.
			NOR = {
				$LOVER_1$ = {
					OR = {
						any_spouse = {
							count = all
							faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
						}
						has_character_flag = block_infidelity_flag
					}
				}
				$LOVER_1$ = {
					carn_should_have_no_consequences_for_extramarital_sex_with_partner_trigger = {
						PARTNER = $LOVER_2$
					}
				}
				$LOVER_2$ = {
					OR = {
						any_spouse = {
							count = all
							faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
						}
						has_character_flag = block_infidelity_flag
					}
				}
				$LOVER_2$ = {
					carn_should_have_no_consequences_for_extramarital_sex_with_partner_trigger = {
						PARTNER = $LOVER_1$
					}
				}
			}
		}
		infidelity_confrontation_story_creation_effect = { LOVER_1 = $LOVER_1$ LOVER_2 = $LOVER_2$ }
		scope:infidelity_story = {
			add_to_variable_list = {
				name = confronting_partners
				target = $DISCOVERER$
			}
		}
		#Certain changes to desc in event if the secret was revealed through investigation
		if = {
			limit = { $DISCOVERER$ = { is_ai = no } } #Text changes are only relevant to players

			#Save the secrets so we can check them
			$LOVER_1$ = {
				random_secret = {
					limit = {
						secret_type = secret_lover
						secret_target = $LOVER_2$
					}
					add_to_temporary_list = secrets_for_desc
				}
			}
			$LOVER_2$ = {
				random_secret = {
					limit = {
						secret_type = secret_lover
						secret_target = $LOVER_1$
					}
					add_to_temporary_list = secrets_for_desc
				}
			}

			#infidelity_confrontation_1000_investigation_desc
			if = {
				limit = {
					any_in_list = {
						list = secrets_for_desc
						exists = var:revealed_through_investigation_by_desc
						var:revealed_through_investigation_by_desc = $DISCOVERER$
					}
				}
				scope:infidelity_story = {
					set_variable = {
						name = infidelity_confrontation_1000_investigation_desc
						value = yes
					}
				}
			}

			#revealed_through_confession_to_desc
			if = {
				limit = {
					any_in_list = {
						list = secrets_for_desc
						exists = var:revealed_through_confession_to_desc
						var:revealed_through_confession_to_desc = $DISCOVERER$
					}
				}
				scope:infidelity_story = {
					set_variable = {
						name = infidelity_confrontation_1000_confession_desc
						value = yes
					}
				}
			}
		}
	}
}


code:
carn_button_prison_enslave = {
	scope = character

	is_shown = {
		NOT = { has_game_rule = carn_slavery_content_disabled }
	}
	is_valid = {
		imprisoner = {
			is_character_interaction_potentially_accepted = {
				recipient = prev
				interaction = carn_enslave_interaction
			}
		}
	}
	effect = {
		imprisoner = {
			open_interaction_window = {
				interaction = carn_enslave_interaction
				actor = this
				recipient = prev
			}
		}
	}
}


code:
carn_button_prison_mass_enslave = {
	scope = character
	is_shown = {
		NOT = { has_game_rule = carn_slavery_content_disabled }
	}
	is_valid = {
		any_prisoner = {
			imprisoner = {
				is_character_interaction_potentially_accepted = {
					recipient = prev
					interaction = carn_enslave_interaction
				}
			}
			OR = {
				imprisoner.faith = {
					has_doctrine = carn_doctrine_same_slavery_accepted
					faith_hostility_level = {
						target = prev.faith
						value < faith_hostile_level
					}
				}
				imprisoner.faith = {
					has_doctrine = carn_doctrine_other_slavery_accepted
					faith_hostility_level = {
						target = prev.faith
						value >= faith_hostile_level
					}
				}
			}
		}
	}
	effect = {
		open_interaction_window = {
			interaction = carn_mass_enslave_interaction
			actor = this
			recipient = this
			secondary_actor = this
		}
	}
}


code:
carn_fetish_gui = {
	scope = character
	saved_scopes = {
		player
	}
	is_shown = {
		OR = {
			has_trait = deviant
			AND = {
				exists = scope:player
				OR = {
					root = scope:player # Show own fetishes even without deviant trait or secret
					scope:player = {
						any_known_secret = {
							secret_type = secret_deviant
							secret_owner = root
						}
					}
				}
			}
		}
		carn_has_any_fetish_trigger = yes
	}
}

carn_fetish_gui_list = {
	scope = character
	is_shown = {
		carn_has_any_fetish_trigger = yes
	}
	effect = {
		every_in_list = {
			variable = carn_active_fetishes
			carn_fetish_tooltip_effect = {
				FETISH = this
			}
		}
	}
}


code:
carn_lactation_gui = {
	scope = character
	is_shown = {
		carn_is_lactating_trigger = yes
	}
}


code:
carn_prostitution_bad_event_modifier = {

	modifier = {
		add = {
			value = diplomacy
			add = -10
			multiply = -2
		}
	}

	modifier = {
		add = {
			value = intrigue
			add = -10
			multiply = -2
		}
	}

	modifier = {
		factor = 0.8
		has_trait = seducer
	}

	modifier = {
		factor = 0.9
		has_trait_xp = {
			trait = lifestyle_prostitute
			value >= 50
		}
	}

	modifier = {
		factor = 0.9
		has_trait_xp = {
			trait = lifestyle_prostitute
			value >= 100
		}
	}
}


code:
carn_prostitution_good_event_modifier = {

	modifier = {
		add = {
			value = diplomacy
			add = -10
			multiply = 2
		}
	}

	modifier = {
		add = {
			value = intrigue
			add = -10
			multiply = 2
		}
	}

	modifier = {
		factor = 1.2
		has_trait = seducer
	}

	modifier = {
		factor = 1.1
		has_trait_xp = {
			trait = lifestyle_prostitute
			value >= 50
		}
	}

	modifier = {
		factor = 1.1
		has_trait_xp = {
			trait = lifestyle_prostitute
			value >= 100
		}
	}

	modifier = {
		factor = 2
		culture = {
			has_cultural_parameter = carn_more_good_prostitution_events
		}
	}
}


code:
carn_prostitution_rank_up_chance_modifier = {

	modifier = {
		add = {
			value = diplomacy
			add = -10
			multiply = 2
		}
	}

	modifier = {
		add = {
			value = intrigue
			add = -10
			multiply = 2
		}
	}

	modifier = {
		factor = 1.1
		has_trait = lustful
	}

	modifier = {
		factor = 1.1
		has_trait = diligent
	}

	modifier = {
		factor = 1.1
		has_trait = gregarious
	}

	modifier = {
		factor = 0.9
		has_trait = chaste
	}

	modifier = {
		factor = 0.9
		has_trait = lazy
	}

	modifier = {
		factor = 0.9
		has_trait = shy
	}

	modifier = {
		factor = 2
		has_trait = beauty_good_1
	}

	modifier = {
		factor = 3
		has_trait = beauty_good_2
	}

	modifier = {
		factor = 4
		has_trait = beauty_good_3
	}

	modifier = {
		factor = 1.25
		has_trait = intellect_good_1
	}

	modifier = {
		factor = 1.5
		has_trait = intellect_good_2
	}

	modifier = {
		factor = 2
		has_trait = intellect_good_3
	}

	modifier = {
		factor = 3
		has_trait = seducer
	}

	modifier = {
		factor = 2
		effective_age <= 21
	}

	modifier = {
		factor = 0.75
		effective_age > 30
	}

	modifier = {
		factor = 0.5
		effective_age > 40
	}

	modifier = {
		factor = 0.5
		has_trait_xp = {
			trait = lifestyle_prostitute
			value >= 50
		}
	}

	modifier = {
		factor = 0
		has_trait_xp = {
			trait = lifestyle_prostitute
			value >= 100
		}
	}

	modifier = {
		factor = 0
		OR = {
			has_trait = beauty_bad
			has_trait = intellect_bad
		}
	}

	modifier = {
		factor = 2
		culture = {
			has_cultural_parameter = carn_more_good_prostitution_events
		}
	}
}


code:
# a dominant has a submissive, and vice-versa
dominant = {
  corresponding = submissive
  opinion = 10
}

submissive = {
  corresponding = dominant
  opinion = 10
}


code:
# a slave has a owner

slave = {
  corresponding = slave_owner
	special_guest = yes
}

slave_owner = {
  corresponding = slave
  opinion = -10 # slave's opinion of slave owner
}


code:
carn_normal_or_custom_pregnancy_can_be_aborted_trigger = {
	OR = {
		carn_normal_pregnancy_can_be_aborted_trigger = yes
		carn_custom_pregnancy_can_be_aborted_trigger = yes
	}
}

carn_normal_pregnancy_can_be_aborted_trigger = {
	carn_has_normal_pregnancy_no_absolute_birth_control_trigger = yes
	NOR = {
		has_character_flag = carn_block_aborting_any_pregnancy
		has_trait_with_flag = carn_block_aborting_any_pregnancy
		has_character_flag = carn_block_aborting_any_normal_pregnancy
		has_trait_with_flag = carn_block_aborting_any_normal_pregnancy
		has_character_flag = carn_block_aborting_next_normal_pregnancy
	}
}


code:
carn_has_absolute_birth_control_trigger = {
	OR = {
		has_character_flag = carn_absolute_birth_control
		has_trait_with_flag = carn_absolute_birth_control
	}
}

carn_has_normal_pregnancy_no_absolute_birth_control_trigger = {
	is_pregnant = yes
	carn_has_absolute_birth_control_trigger = no
}


code:
# this only makes the spouses and lovers of the no_consequences character happy
# anyone they cuckold will always get angry unless they have polyamory -- this is intended behavior.
carn_should_have_no_consequences_for_extramarital_sex_trigger = {
	trigger_if = {
		limit = { exists = scope:partner }
		carn_should_have_no_consequences_for_extramarital_sex_with_partner_trigger = {
			PARTNER = scope:partner
		}
	}
	trigger_else = {
		carn_should_have_no_consequences_for_extramarital_sex_with_no_partner_trigger = yes
	}
}

carn_should_have_no_consequences_for_extramarital_sex_with_partner_trigger = {
	OR = {
		# they are exempt from adultery in and of itself
		carn_should_have_no_consequences_for_extramarital_sex_with_no_partner_trigger = yes

		# it's a slave owner fucking their slave
		has_relation_slave_owner = $PARTNER$
		has_relation_slave = $PARTNER$

		# special mod flags
		$PARTNER$ = { has_character_flag = carn_no_consequences_for_extramarital_sex_with_me }
		$PARTNER$ = { has_trait_with_flag = carn_no_consequences_for_extramarital_sex_with_me }
		$PARTNER$ = {
			culture = { has_cultural_parameter = carn_no_consequences_for_extramarital_sex_with_me }
		}
	}
}

carn_should_have_no_consequences_for_extramarital_sex_with_no_partner_trigger = {
	OR = {
		# special mod flags
		has_character_flag = carn_no_consequences_for_extramarital_sex_with_others
		has_trait_with_flag = carn_no_consequences_for_extramarital_sex_with_others
		culture = { has_cultural_parameter = carn_no_consequences_for_extramarital_sex_with_others }
	}
}


code:
# The two triggers below are intended as an extensible means of checking for libido-altering traits, either
# originating in the base game or introduced by submods (something like "insatiable" in CK2)
carn_has_high_arousal_trigger = {
	OR = {
		has_trait = lustful
		has_trait = rakish
		has_character_flag = carn_has_high_arousal
		has_trait_with_flag = carn_has_high_arousal
	}
}

carn_has_low_arousal_trigger = {
	OR = {
		has_trait = chaste
		has_trait = celibate
		has_character_flag = carn_has_low_arousal
		has_trait_with_flag = carn_has_low_arousal
	}
}


code:
# checks that a character is a reasonable target for a sex scene
carn_can_have_sex_trigger = {
	OR = {
		custom_description = {
			text = "carn_can_always_have_sex"
			OR = {
				has_trait_with_flag = carn_can_always_have_sex
				has_character_flag = carn_can_always_have_sex
			}
		}
		AND = {
			custom_description = {
				text = "carn_is_busy_in_events_localised"
            	is_busy_in_events_localised = yes
			}
			is_adult = yes
			is_alive = yes
			#is_in_an_activity = no
			is_imprisoned = no
			has_wounds_trigger = no
			carn_has_sex_blocking_disease_trigger = no
			NOR = {
				has_trait = incapable
				has_trait = celibate
				custom_description = {
					text = "carn_cannot_have_sex"
					has_trait_with_flag = carn_cannot_have_sex
					has_character_flag = carn_cannot_have_sex
				}
			}
		}
	}
}

carn_can_be_raped_trigger = {
	custom_description = {
		text = "carn_cannot_be_raped"
		NOR = {
			has_trait_with_flag = carn_cannot_be_raped
			has_character_flag = carn_cannot_be_raped
		}
	}
	OR = {
		custom_description = {
			text = "carn_can_always_have_sex"
			OR = {
				has_trait_with_flag = carn_can_always_have_sex
				has_character_flag = carn_can_always_have_sex
			}
		}
		AND = {
			custom_description = {
				text = "carn_is_busy_in_events_localised"
            	is_busy_in_events_localised = yes
			}
			is_adult = yes
			is_alive = yes
			has_wounds_trigger = no
			carn_has_sex_blocking_disease_trigger = no
			NOR = {
				has_trait = incapable
				custom_description = {
					text = "carn_cannot_have_sex"
					has_trait_with_flag = carn_cannot_have_sex
					has_character_flag = carn_cannot_have_sex
				}
			}
		}
	}
}

carn_has_sex_blocking_disease_trigger = {
	OR = {
		has_trait = consumption
		has_trait = ill
		has_trait = pneumonic
		has_trait = typhus
		has_trait = smallpox
		has_trait = bubonic_plague
		has_trait = leper
	}
}


code:
# carn_is_pregnant_trigger
# carn_is_visibly_pregnant_trigger
# carn_has_any_custom_pregnancy_trigger
# carn_has_custom_pregnancy_type_trigger (requires `PREGNANCY_TYPE`)
# carn_custom_pregnancy_stage_equals_trigger (requires `STAGE`)
# carn_custom_pregnancy_can_be_aborted_trigger

# this checks whether a character is pregnant at all, even if it doesn't show
carn_is_pregnant_trigger = {
	OR = {
		carn_has_normal_pregnancy_no_absolute_birth_control_trigger = yes
		carn_has_any_custom_pregnancy_trigger = yes
	}
}

# this checks whether a character has a trait that shows they are clearly pregnant
carn_is_visibly_pregnant_trigger = {
	OR = {
		has_trait = pregnant
		has_trait_with_flag = carn_custom_pregnancy
	}
}

carn_has_any_custom_pregnancy_trigger = {
	exists = var:carn_custom_pregnancy
}

carn_has_custom_pregnancy_type_trigger = { # requires `PREGNANCY_TYPE`
	exists = var:carn_custom_pregnancy
	var:carn_custom_pregnancy = flag:$PREGNANCY_TYPE$
}

carn_custom_pregnancy_stage_equals_trigger = { # requires `STAGE`
	exists = var:carn_custom_pregnancy_stage
	var:carn_custom_pregnancy_stage = $STAGE$
}

# if this is true, the pregnancy can't be overwritten by other pregnancies
# other mods can also check this as a condition for whether a custom pregnancy should be abortable by decision, etc.
carn_custom_pregnancy_can_be_aborted_trigger = {
	NOR = {
		has_character_flag = carn_block_aborting_any_pregnancy
		has_trait_with_flag = carn_block_aborting_any_pregnancy
		has_character_flag = carn_block_aborting_any_custom_pregnancy
		has_trait_with_flag = carn_block_aborting_any_custom_pregnancy
		has_character_flag = carn_block_aborting_next_custom_pregnancy
	}
}


code:
# carn_should_have_dick_trigger
# carn_should_have_tits_trigger

# carn_has_any_dick_gene_trigger
# carn_has_any_tits_gene_trigger
# carn_has_small_dick_trigger
# carn_has_big_dick_trigger
# carn_has_small_tits_trigger
# carn_has_big_tits_trigger
# card_has_bad_dick_trigger
# card_has_good_dick_trigger
# card_has_bad_tits_trigger
# card_has_good_tits_trigger

# carn_has_bigger_dick_than_character_trigger
# carn_has_smaller_dick_than_character_trigger
# carn_has_bigger_tits_than_character_trigger
# carn_has_smaller_tits_than_character_trigger

# carn_has_dick_small_1_trigger
# carn_has_dick_small_2_trigger
# carn_has_dick_small_3_trigger
# carn_has_dick_big_1_trigger
# carn_has_dick_big_2_trigger
# carn_has_dick_big_3_trigger
# carn_has_tits_small_1_trigger
# carn_has_tits_small_2_trigger
# carn_has_tits_small_3_trigger
# carn_has_tits_big_1_trigger
# carn_has_tits_big_2_trigger
# carn_has_tits_big_3_trigger

carn_should_have_dick_trigger = {
	carn_gender_can_impregnate_trigger = yes
}

carn_should_have_tits_trigger = {
	is_female = yes
}

# returns true if this character has any congenital dick trait, active or inactive
carn_has_any_dick_gene_trigger = {
	OR = {
		carn_has_small_dick_trigger = yes
		carn_has_big_dick_trigger = yes
		has_inactive_trait = dick_small_good_1
		has_inactive_trait = dick_small_good_2
		has_inactive_trait = dick_small_good_3
		has_inactive_trait = dick_small_bad_1
		has_inactive_trait = dick_small_bad_2
		has_inactive_trait = dick_small_bad_3
		has_inactive_trait = dick_big_good_1
		has_inactive_trait = dick_big_good_2
		has_inactive_trait = dick_big_good_3
		has_inactive_trait = dick_big_bad_1
		has_inactive_trait = dick_big_bad_2
		has_inactive_trait = dick_big_bad_3
	}
}

# returns true if this character has any congenital tits trait, active or inactive
carn_has_any_tits_gene_trigger = {
	OR = {
		carn_has_small_tits_trigger = yes
		carn_has_big_tits_trigger = yes
		has_inactive_trait = tits_small_good_1
		has_inactive_trait = tits_small_good_2
		has_inactive_trait = tits_small_good_3
		has_inactive_trait = tits_small_bad_1
		has_inactive_trait = tits_small_bad_2
		has_inactive_trait = tits_small_bad_3
		has_inactive_trait = tits_big_good_1
		has_inactive_trait = tits_big_good_2
		has_inactive_trait = tits_big_good_3
		has_inactive_trait = tits_big_bad_1
		has_inactive_trait = tits_big_bad_2
		has_inactive_trait = tits_big_bad_3
	}
}

# returns true if this character has any active small dick trait
carn_has_small_dick_trigger = {
	OR = {
		has_trait = dick_small_good
		has_trait = dick_small_bad
	}
}

# returns true if this character has any active big dick trait
carn_has_big_dick_trigger = {
	OR = {
		has_trait = dick_big_good
		has_trait = dick_big_bad
	}
}

# returns true if this character has any active small tits trait
carn_has_small_tits_trigger = {
	OR = {
		has_trait = tits_small_good
		has_trait = tits_small_bad
	}
}

# returns true if this character has any active big tits trait
carn_has_big_tits_trigger = {
	OR = {
		has_trait = tits_big_good
		has_trait = tits_big_bad
	}
}

# returns true if this character has any active bad dick trait
carn_has_bad_dick_trigger = {
	OR = {
		has_trait = dick_small_bad
		has_trait = dick_big_bad
	}
}

# returns true if this character has any active good dick trait
carn_has_good_dick_trigger = {
	OR = {
		has_trait = dick_small_good
		has_trait = dick_big_good
	}
}

# returns true if this character has any active bad tits trait
carn_has_bad_tits_trigger = {
	OR = {
		has_trait = tits_small_bad
		has_trait = tits_big_bad
	}
}

# returns true if this character has any active good tits trait
carn_has_good_tits_trigger = {
	OR = {
		has_trait = tits_small_good
		has_trait = tits_big_good
	}
}

# requires CHARACTER
carn_has_bigger_dick_than_character_trigger = {
	$CHARACTER$ = { save_temporary_scope_as = compared_character }
	carn_dick_size_value > scope:compared_character.carn_dick_size_value
}

# requires CHARACTER
carn_has_smaller_dick_than_character_trigger = {
	$CHARACTER$ = { save_temporary_scope_as = compared_character }
	carn_dick_size_value < scope:compared_character.carn_dick_size_value
}

# requires CHARACTER
carn_has_bigger_tits_than_character_trigger = {
	$CHARACTER$ = { save_temporary_scope_as = compared_character }
	carn_tits_size_value > scope:compared_character.carn_tits_size_value
}

# requires CHARACTER
carn_has_smaller_tits_than_character_trigger = {
	$CHARACTER$ = { save_temporary_scope_as = compared_character }
	carn_tits_size_value < scope:compared_character.carn_tits_size_value
}

carn_has_dick_small_1_trigger = {
	OR = {
		has_trait = dick_small_good_1
		has_trait = dick_small_bad_1
	}
}

carn_has_dick_small_2_trigger = {
	OR = {
		has_trait = dick_small_good_2
		has_trait = dick_small_bad_2
	}
}

carn_has_dick_small_3_trigger = {
	OR = {
		has_trait = dick_small_good_3
		has_trait = dick_small_bad_3
	}
}

carn_has_dick_big_1_trigger = {
	OR = {
		has_trait = dick_big_good_1
		has_trait = dick_big_bad_1
	}
}

carn_has_dick_big_2_trigger = {
	OR = {
		has_trait = dick_big_good_2
		has_trait = dick_big_bad_2
	}
}

carn_has_dick_big_3_trigger = {
	OR = {
		has_trait = dick_big_good_3
		has_trait = dick_big_bad_3
	}
}

carn_has_tits_small_1_trigger = {
	OR = {
		has_trait = tits_small_good_1
		has_trait = tits_small_bad_1
	}
}

carn_has_tits_small_2_trigger = {
	OR = {
		has_trait = tits_small_good_2
		has_trait = tits_small_bad_2
	}
}

carn_has_tits_small_3_trigger = {
	OR = {
		has_trait = tits_small_good_3
		has_trait = tits_small_bad_3
	}
}

carn_has_tits_big_1_trigger = {
	OR = {
		has_trait = tits_big_good_1
		has_trait = tits_big_bad_1
	}
}

carn_has_tits_big_2_trigger = {
	OR = {
		has_trait = tits_big_good_2
		has_trait = tits_big_bad_2
	}
}

carn_has_tits_big_3_trigger = {
	OR = {
		has_trait = tits_big_good_3
		has_trait = tits_big_bad_3
	}
}


code:
carn_has_any_fetish_trigger = {
	has_variable_list = carn_active_fetishes
	variable_list_size = {
		name = carn_active_fetishes
		value > 0
	}
}

carn_has_fetish_trigger = {
	is_target_in_variable_list = {
		name = carn_active_fetishes
		target = flag:$FETISH$
	}
}


code:
# Whether this character is futanari
carn_is_futa_trigger = {
	OR = {
		has_trait = futa
		has_trait = futa_genetic
	}
}

# Whether this character is a non-futanari female
carn_is_female_not_futa_trigger = {
	is_female = yes
	carn_is_futa_trigger = no
}

# Whether this character has a cock and can impregnate female characters
carn_gender_can_impregnate_trigger = {
	OR = {
		is_male = yes
		carn_is_futa_trigger = yes
	}
}

carn_character_genders_can_produce_children_trigger = {
	OR = {
		AND = {
			$CHARACTER_1$ = {
				is_female = yes
			}
			$CHARACTER_2$ = {
				carn_gender_can_impregnate_trigger = yes
			}
		}
		AND = {
			$CHARACTER_1$ = {
				carn_gender_can_impregnate_trigger = yes
			}
			$CHARACTER_2$ = {
				is_female = yes
			}
		}
	}
}

carn_possible_pregnancy_after_sex_with_character_trigger = {
	trigger_if = {
		limit = {
			carn_gender_can_impregnate_trigger = yes
			$CHARACTER$ = { is_female = yes }
		}
		effective_age >= define:NChildbirth|MIN_MALE_REPRODUCTION_AGE
		fertility >= 0.1

		$CHARACTER$ ={
			effective_age >= define:NChildbirth|MIN_FEMALE_REPRODUCTION_AGE
			effective_age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
			fertility >= 0.1
			is_pregnant = no
		}
	}

	trigger_if = {
		limit = {
			is_female = yes
			$CHARACTER$ = { carn_gender_can_impregnate_trigger = yes }
		}
		effective_age >= define:NChildbirth|MIN_FEMALE_REPRODUCTION_AGE
		effective_age < define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
		fertility >= 0.1
		is_pregnant = no

		$CHARACTER$ = {
			effective_age >= define:NChildbirth|MIN_MALE_REPRODUCTION_AGE
			fertility >= 0.1
		}
	}
}


code:
carn_can_be_granted_titles_trigger = {
	custom_description = {
		text = carn_can_be_granted_titles
		NOR = {
			has_character_flag = can_not_be_granted_titles
			has_trait_with_flag = can_not_be_granted_titles
		}
	}
}


code:
# carn_has_any_negative_congenital_trait_trigger
# carn_has_any_minor_disfigurement_trigger
# carn_has_any_major_disfigurement_trigger
# carn_has_any_disease_trigger
# carn_has_any_wound_trigger
# carn_should_have_no_pregnancy_complications_trigger

# we use this to check the specific traits
# since the game will count small dicks/tits as "negative"
carn_has_any_negative_congenital_trait_trigger = {
	OR = {
		has_trait = beauty_bad
		has_trait = intellect_bad
		has_trait = physique_bad
		has_trait = clubfooted
		has_trait = hunchbacked
		has_trait = lisping
		has_trait = stuttering
		has_trait = dwarf
		has_trait = giant
		has_trait = inbred
		has_trait = spindly
		has_trait = scaly
		has_trait = wheezing
		has_trait = bleeder
		has_trait = infertile
		has_trait = possessed_genetic
		has_trait = depressed_genetic
	}
}

carn_has_any_minor_disfigurement_trigger = {
	OR = {
		has_trait = one_eyed
		has_trait = scarred
	}
}

carn_has_any_major_disfigurement_trigger = {
	OR = {
		has_trait = maimed
		has_trait = one_legged
		has_trait = disfigured
		has_trait = eunuch_1
		has_trait = beardless_eunuch
		has_trait = blind
	}
}

carn_has_any_disease_trigger = {
	OR = {
		has_trait = sickly
		has_std_trigger = yes
		has_treatable_disease_trigger = yes
	}
}

carn_should_have_no_pregnancy_complications_trigger = {
	OR = {
		has_game_rule = carn_pregnancy_complications_never
		has_character_flag = carn_no_pregnancy_complications
		has_trait_with_flag = carn_no_pregnancy_complications
	}
}


code:
# carn_can_lactate_trigger
# can_is_lactating_trigger
# carn_milk_production_decreases_yearly_trigger
# carn_has_very_low_milk_production_trigger
# carn_has_low_milk_production_trigger
# carn_has_average_milk_production_trigger
# carn_has_high_milk_production_trigger
# carn_has_very_high_milk_production_trigger
# carn_has_extreme_milk_production_trigger

carn_can_lactate_trigger = {
	NOT = { has_game_rule = carn_lactation_disabled }
	is_adult = yes
	trigger_if = {
		limit = {
			NOR = {
				has_character_flag = carn_lactation_ignores_effective_age
				has_trait_with_flag = carn_lactation_ignores_effective_age
			}
		}
		custom_description = {
			text = "carn_effective_age_under_value_cutoff"
			value = carn_lactation_age_cutoff
			effective_age < carn_lactation_age_cutoff
		}
	}
	OR = {
		AND = {
			is_female = yes
			NOT = { has_game_rule = carn_lactation_male_only }
		}
		AND = {
			is_male = yes
			NOT = { has_game_rule = carn_lactation_female_only }
		}
	}
}

carn_is_lactating_trigger = {
	custom_description = {
		text = "carn_is_lactating_trigger"
		exists = var:carn_milk_production
		var:carn_milk_production > 0
	}
}

carn_milk_production_decreases_yearly_trigger = {
	NOR = {
		carn_is_visibly_pregnant_trigger = yes
		has_character_flag = carn_block_yearly_milk_production_decrease
		has_trait_with_flag = carn_block_yearly_milk_production_decrease
	}
}

#############################################################
# Very Low milk production
#############################################################
# after a lot of coaxing, a few droplets come out

carn_has_very_low_milk_production_trigger = {
	exists = var:carn_milk_production
	var:carn_milk_production > carn_very_low_milk_production_amount
}

#############################################################
# Low milk production
#############################################################
# after some coaxing, a thin stream of milk comes out

carn_has_low_milk_production_trigger = {
	exists = var:carn_milk_production
	var:carn_milk_production > carn_low_milk_production_amount
}

#############################################################
# Average milk production
#############################################################
# after some coaxing, a regular flow of milk comes out
# your breasts get sore and leak milk if you don't milk them
# this is the default human level of lactation following pregnancy

carn_has_average_milk_production_trigger = {
	exists = var:carn_milk_production
	var:carn_milk_production > carn_average_milk_production_amount
}

#############################################################
# High milk production
#############################################################
# your breasts are sensitive and prone to let down milk, and get swollen if you don't milk them
# this is the realistic maximum for humans irl

carn_has_high_milk_production_trigger = {
	exists = var:carn_milk_production
	var:carn_milk_production > carn_high_milk_production_amount
}

#############################################################
# Very High milk production
#############################################################
# superhuman levels of milk production
# milk is constantly oozing from your breasts, you need to be milked regularly
# this is how the average "hucow" is depicted

carn_has_very_high_milk_production_trigger = {
	exists = var:carn_milk_production
	var:carn_milk_production > carn_very_high_milk_production_amount
}

#############################################################
# Extreme milk production
#############################################################
# milk is constantly running from your breasts, it's hard to have a normal life
# you're basically a pair of milk factories attached to a girl

carn_has_extreme_milk_production_trigger = {
	exists = var:carn_milk_production
	var:carn_milk_production > carn_extreme_milk_production_amount
}


code:
carn_should_suppress_on_pregnancy_maintenance_trigger = {
	OR = {
		has_character_flag = carn_suppress_all_on_pregnancy_maintenance
		has_character_flag = carn_suppress_next_on_pregnancy_maintenance
		has_trait_with_flag = carn_suppress_all_on_pregnancy_maintenance
	}
}

carn_should_suppress_on_pregnancy_notification_trigger = {
	OR = {
		has_character_flag = carn_suppress_all_on_pregnancy_notification
		has_character_flag = carn_suppress_next_on_pregnancy_notification
		has_trait_with_flag = carn_suppress_all_on_pregnancy_notification
	}
}

carn_should_suppress_on_birth_notification_trigger = {
	OR = {
		has_character_flag = carn_suppress_all_on_birth_notification
		has_character_flag = carn_suppress_next_on_birth_notification
		has_trait_with_flag = carn_suppress_all_on_birth_notification
	}
}


code:
carn_is_prostitute_trigger = {
	OR = {
		has_trait = lifestyle_prostitute
		has_character_flag = carn_is_prostitute
		has_trait_with_flag = carn_is_prostitute
	}
}

carn_is_working_as_prostitute_trigger = {
	OR = {
		has_character_modifier = carn_working_as_prostitute_1_modifier
		has_character_modifier = carn_working_as_prostitute_2_modifier
		has_character_modifier = carn_working_as_prostitute_3_modifier
	}
}

carn_accepts_prostitution_trigger = {
	OR = {
		faith = { has_doctrine = carn_doctrine_prostitution_accepted }
		culture = { has_cultural_parameter = carn_prostitution_accepted }
	}
}

carn_legal_prostitution_trigger = {
	OR = {
		faith = { NOT = { has_doctrine = carn_doctrine_prostitution_crime } }
		culture = { has_cultural_parameter = carn_prostitution_accepted }
	}
}

carn_can_be_prostitute_trigger = {
	is_adult = yes
	OR = {
		has_game_rule = carn_prostitution_content_any_gender
		AND = {
			is_male = yes
			has_game_rule = carn_prostitution_content_male_only
		}
		AND = {
			is_female = yes
			has_game_rule = carn_prostitution_content_female_only
		}
	}
	OR = {
		carn_legal_prostitution_trigger = yes
		trigger_if = {
			limit = {
				any_relation = {
					type = slave_owner
					is_alive = yes
				}
			}
			any_relation = {
				type = slave_owner
				carn_legal_prostitution_trigger = yes
			}
		}
	}
	NOR = {
		has_character_flag = carn_cannot_be_prostitute
		has_trait_with_flag = carn_cannot_be_prostitute
	}
}


code:
### BDSM ###

## dominant and submissive relations are mutually-exclusive between the same two
## characters, i.e. character A cannot be both the dominant and submissive of
## character B

can_set_relation_dominant_trigger = {
	is_adult = yes
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
	NOR = {
    has_relation_dominant = $CHARACTER$
    has_relation_submissive = $CHARACTER$
  }
}

can_set_relation_submissive_trigger = {
	is_adult = yes
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
	NOR = {
    has_relation_dominant = $CHARACTER$
    has_relation_submissive = $CHARACTER$
  }
}


code:
# used in carn_sex_interaction
# requires PARTNER
carn_relationship_allows_free_sex_trigger = {
	OR = {
		is_consort_of = $PARTNER$
		has_relation_lover = $PARTNER$
		has_relation_soulmate = $PARTNER$
		AND = {
			has_relation_slave = $PARTNER$
			NOT = {
				relation_with_character_is_incestuous_in_my_faith_trigger = {
					CHARACTER = $PARTNER$
				}
			}
		}
	}
}


code:
# Old triggers preserved for compatibility
# These are DEPRECATED, please use the new triggers above

carn_sex_scene_matches_requested_flags_trigger = {
	# Add default sex scene flags if not already added
	trigger_if = {
		limit = {
			NOT = {
				any_in_list = {
					list = carn_sex_scene_flags
					OR = {
						this = flag:giving_player
						this = flag:receiving_player
					}
				}
			}
		}
		carn_sex_scene_is_giving_player = yes
	}
	trigger_if = {
		limit = {
			NOT = {
				any_in_list = {
					list = carn_sex_scene_flags
					OR = {
						this = flag:consensual
						this = flag:dubcon
						this = flag:noncon
					}
				}
			}
		}
		carn_sex_scene_is_consensual = yes
	}
	trigger_if = {
		limit = {
			NOT = {
				any_in_list = {
					list = carn_sex_scene_flags
					OR = {
						this = flag:oral
						this = flag:vaginal
						this = flag:anal
						this = flag:handjob
						this = flag:masturbation
					}
				}
			}
		}
		carn_sex_scene_is_vaginal = yes
	}
	trigger_if = {
		limit = {
			NOT = {
				any_in_list = {
					list = carn_sex_scene_flags
					OR = {
						this = flag:cum_inside
						this = flag:cum_outside
					}
				}
			}
		}
		carn_sex_scene_is_cum_inside = yes
	}

	NOR = {
		any_in_list = {
			variable = carn_sex_scene_flag_list
			NOT = { is_in_list = carn_sex_scene_flags }
		}
		any_in_list = {
			variable = carn_sex_scene_character_flag_list
			NOT = { is_in_list = carn_sex_scene_flags }
		}
		any_in_list = {
			variable = carn_sex_scene_excluded_flag_list
			is_in_list = carn_sex_scene_flags
		}
		any_in_list = {
			variable = carn_sex_scene_character_excluded_flag_list
			is_in_list = carn_sex_scene_flags
		}
	}
}

carn_sex_scene_is_giving_player = {
	carn_sex_scene_character_is_flag = { FLAG = giving_player }
}

carn_sex_scene_is_receiving_player = {
	carn_sex_scene_character_is_flag = { FLAG = receiving_player }
}

carn_sex_scene_is_dom_player = {
	carn_sex_scene_character_is_flag = { FLAG = dom_player }
}

carn_sex_scene_is_sub_player = {
	carn_sex_scene_character_is_flag = { FLAG = sub_player }
}

carn_sex_scene_is_oral = {
	carn_sex_scene_is_flag = { FLAG = oral }
}

carn_sex_scene_is_vaginal = {
	carn_sex_scene_is_flag = { FLAG = vaginal }
}

carn_sex_scene_is_anal = {
	has_game_rule = carn_content_anal_enabled
	carn_sex_scene_is_flag = { FLAG = anal }
}

carn_sex_scene_is_handjob = {
	carn_sex_scene_is_flag = { FLAG = handjob }
}

carn_sex_scene_is_masturbation = {
	carn_sex_scene_is_flag = { FLAG = masturbation }
}

carn_sex_scene_is_orgy = {
	carn_sex_scene_is_flag = { FLAG = orgy }
}

carn_sex_scene_is_cum_inside = {
	carn_sex_scene_is_flag = { FLAG = cum_inside }
}

carn_sex_scene_is_cum_outside = {
	carn_sex_scene_is_flag = { FLAG = cum_outside }
}

carn_sex_scene_is_consensual = {
	carn_sex_scene_is_flag = { FLAG = consensual }
}

carn_sex_scene_is_noncon = {
	has_game_rule = carn_content_consent_noncon
	carn_sex_scene_is_flag = { FLAG = noncon }
}

carn_sex_scene_is_dubcon = {
 	NOT = { has_game_rule = carn_content_consent_always }
	carn_sex_scene_is_flag = { FLAG = dubcon }
}

carn_sex_scene_is_painful = {
	has_game_rule = carn_content_painful_enabled
	carn_sex_scene_is_flag = { FLAG = painful }
}

carn_sex_scene_is_bdsm = {
	carn_sex_scene_is_flag = { FLAG = bdsm }
}

carn_sex_scene_is_bestiality = {
	has_game_rule = carn_content_bestiality_enabled
	carn_sex_scene_is_flag = { FLAG = bestiality }
}

carn_sex_scene_is_petplay = {
	carn_sex_scene_is_flag = { FLAG = petplay }
}

carn_sex_scene_is_bondage = {
	carn_sex_scene_is_flag = { FLAG = petplay }
}

carn_sex_scene_is_toy = {
	carn_sex_scene_is_flag = { FLAG = toy }
}

carn_sex_scene_is_watersports = {
	has_game_rule = carn_content_watersports_enabled
	carn_sex_scene_is_flag = { FLAG = watersports }
}

carn_sex_scene_is_scat = {
	has_game_rule = carn_content_scat_enabled
	carn_sex_scene_is_flag = { FLAG = scat }
}

carn_sex_scene_is_gore = {
	has_game_rule = carn_content_gore_enabled
	carn_sex_scene_is_flag = { FLAG = gore }
}

# These triggers are for events in carn_on_sex to check the flags of the sex scene from which it was called.

carn_sex_scene_was_giving_player = {
	carn_sex_scene_character_was_flag = { FLAG = giving_player }
}

carn_sex_scene_was_receiving_player = {
	carn_sex_scene_character_was_flag = { FLAG = receiving_player }
}

carn_sex_scene_was_dom_player = {
	carn_sex_scene_character_was_flag = { FLAG = dom_player }
}

carn_sex_scene_was_sub_player = {
	carn_sex_scene_character_was_flag = { FLAG = sub_player }
}

carn_sex_scene_was_oral = {
	carn_sex_scene_was_flag = { FLAG = oral }
}

carn_sex_scene_was_vaginal = {
	carn_sex_scene_was_flag = { FLAG = vaginal }
}

carn_sex_scene_was_anal = {
	carn_sex_scene_was_flag = { FLAG = anal }
}

carn_sex_scene_was_handjob = {
	carn_sex_scene_was_flag = { FLAG = handjob }
}

carn_sex_scene_was_masturbation = {
	carn_sex_scene_was_flag = { FLAG = masturbation }
}

carn_sex_scene_was_orgy = {
	carn_sex_scene_was_flag = { FLAG = orgy }
}

carn_sex_scene_was_cum_inside = {
	carn_sex_scene_was_flag = { FLAG = cum_inside }
}

carn_sex_scene_was_cum_outside = {
	carn_sex_scene_was_flag = { FLAG = cum_outside }
}

carn_sex_scene_was_consensual = {
	carn_sex_scene_was_flag = { FLAG = consensual }
}

carn_sex_scene_was_noncon = {
	carn_sex_scene_was_flag = { FLAG = noncon }
}

carn_sex_scene_was_dubcon = {
	carn_sex_scene_was_flag = { FLAG = dubcon }
}

carn_sex_scene_was_painful = {
	carn_sex_scene_was_flag = { FLAG = painful }
}

carn_sex_scene_was_bdsm = {
	carn_sex_scene_was_flag = { FLAG = bdsm }
}

carn_sex_scene_was_bestiality = {
	carn_sex_scene_was_flag = { FLAG = bestiality }
}

carn_sex_scene_was_petplay = {
	carn_sex_scene_was_flag = { FLAG = petplay }
}

carn_sex_scene_was_bondage = {
	carn_sex_scene_was_flag = { FLAG = bondage }
}

carn_sex_scene_was_toy = {
	carn_sex_scene_was_flag = { FLAG = toy }
}

carn_sex_scene_was_watersports = {
	carn_sex_scene_was_flag = { FLAG = watersports }
}

carn_sex_scene_was_scat = {
	carn_sex_scene_was_flag = { FLAG = scat }
}

carn_sex_scene_was_gore = {
	carn_sex_scene_was_flag = { FLAG = gore }
}

# Internal triggers

carn_sex_scene_character_is_flag = {
	# Flags can't be added directly to temporary lists
	# e.g. flag:<flag> = { add_to_temporary_list = ... } doesn't work
	# Hoewever, they can be saved as a temporary scope value and then added
	save_temporary_scope_value_as = { name = flag value = flag:$FLAG$ }
	scope:flag = { add_to_temporary_list = carn_sex_scene_flags }
}

carn_sex_scene_is_flag = {
	save_temporary_scope_value_as = { name = flag value = flag:$FLAG$ }
	scope:flag = { add_to_temporary_list = carn_sex_scene_flags }
}

carn_sex_scene_character_was_flag = {
	is_target_in_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:$FLAG$
	}
}

carn_sex_scene_was_flag = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:$FLAG$
	}
}

carn_can_get_pregnant_scenes = {
	NOR = {
		carn_sex_scene_was_anal = yes
		carn_sex_scene_was_bestiality = yes
		carn_sex_scene_was_cum_outside = yes
		carn_sex_scene_was_handjob = yes
		carn_sex_scene_was_masturbation = yes
		carn_sex_scene_was_oral = yes
		carn_sex_scene_was_toy = yes
	}
}


code:
###############################################################################################################
# carn_sex_scene_triggers                                                                                #
###############################################################################################################
#                                                                                #
# These scripted triggers are meant for sex scene events to check which flags have been set for the sex scene.#
#                                                                                #
###############################################################################################################
#carn_had_sex_with_effect triggers

carn_sex_scene_no_pregnancy_trigger = {
	OR = {
		is_target_in_variable_list = {
			name = carn_sex_scene_option_flag_list
			target = flag:no_pregnancy
		}
		exists = scope:carn_sex_no_pregnancy
	}
}

carn_sex_scene_no_stress_trigger = {
	OR = {
		is_target_in_variable_list = {
			name = carn_sex_scene_option_flag_list
			target = flag:no_stress
		}
		exists = scope:carn_sex_no_stress
	}
}

carn_sex_scene_no_drama_trigger = {
	OR = {
		is_target_in_variable_list = {
			name = carn_sex_scene_option_flag_list
			target = flag:no_drama
		}
		exists = scope:carn_sex_no_drama
	}
}

carn_sex_scene_no_memory_trigger = {
	OR = {
		is_target_in_variable_list = {
			name = carn_sex_scene_option_flag_list
			target = flag:no_memory
		}
		exists = scope:carn_sex_no_memory
	}
}

carn_sex_scene_no_std_trigger = {
	OR = {
		is_target_in_variable_list = {
			name = carn_sex_scene_option_flag_list
			target = flag:no_std
		}
		exists = scope:carn_sex_no_std
	}
}

# Here is a list of supported sex scene flags.
# It is possible for mods to add more flags, but these will not be supported and have no guarantee of working with other mods.
#
# carn_sex_scene_character_is_giving_player_trigger
# carn_sex_scene_character_is_receiving_player_trigger
# carn_sex_scene_character_is_dom_player_trigger
# carn_sex_scene_character_is_sub_player_trigger
# carn_sex_scene_is_vaginal_trigger
# carn_sex_scene_is_anal_trigger
# carn_sex_scene_is_oral_trigger
# carn_sex_scene_is_handjob_trigger
# carn_sex_scene_is_masturbation_trigger
# carn_sex_scene_is_orgy_trigger
# carn_sex_scene_is_cum_inside_trigger
# carn_sex_scene_is_cum_outside_trigger
# carn_sex_scene_is_consensual_trigger
# carn_sex_scene_is_noncon_trigger
# carn_sex_scene_is_dubcon_trigger
# carn_sex_scene_is_painful_trigger
# carn_sex_scene_is_bdsm_trigger
# carn_sex_scene_is_bestiality_trigger
# carn_sex_scene_is_petplay_trigger
# carn_sex_scene_is_bondage_trigger
# carn_sex_scene_is_toy_trigger
# carn_sex_scene_is_watersports_trigger
# carn_sex_scene_is_scat_trigger
# carn_sex_scene_is_gore_trigger
#

carn_sex_scene_character_is_giving_player_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:giving_player
	}
}

carn_sex_scene_character_is_receiving_player_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:receiving_player
	}
}

carn_sex_scene_character_is_dom_player_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:dom_player
	}
}

carn_sex_scene_character_is_sub_player_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:sub_player
	}
}

carn_sex_scene_is_oral_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:oral
	}
}

carn_sex_scene_is_vaginal_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:vaginal
	}
}

carn_sex_scene_is_anal_trigger = {
	has_game_rule = carn_content_anal_enabled
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:anal
	}
}

carn_sex_scene_is_handjob_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:handjob
	}
}

carn_sex_scene_is_masturbation_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:masturbation
	}
}

carn_sex_scene_is_orgy_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:orgy
	}
}

carn_sex_scene_is_cum_inside_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:cum_inside
	}
}

carn_sex_scene_is_cum_outside_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:cum_outside
	}
}

carn_sex_scene_is_consensual_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:consensual
	}
}

carn_sex_scene_is_noncon_trigger = {
	has_game_rule = carn_content_consent_noncon
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:noncon
	}
}

carn_sex_scene_is_dubcon_trigger = {
 	NOT = { has_game_rule = carn_content_consent_always }
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:dubcon
	}
}

carn_sex_scene_is_painful_trigger = {
	has_game_rule = carn_content_painful_enabled
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:painful
	}
}

carn_sex_scene_is_bdsm_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:bdsm
	}
}

carn_sex_scene_is_bestiality_trigger = {
	has_game_rule = carn_content_bestiality_enabled
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:bestiality
	}
}

carn_sex_scene_is_petplay_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:petplay
	}
}

carn_sex_scene_is_bondage_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:bondage
	}
}

carn_sex_scene_is_toy_trigger = {
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:toy
	}
}

carn_sex_scene_is_watersports_trigger = {
	has_game_rule = carn_content_watersports_enabled
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:watersports
	}
}

carn_sex_scene_is_scat_trigger = {
	has_game_rule = carn_content_scat_enabled
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:scat
	}
}

carn_sex_scene_is_gore_trigger = {
	has_game_rule = carn_content_gore_enabled
	is_target_in_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:gore
	}
}


code:
carn_slave_can_be_sold_trigger = {
	NOR = {
		has_treatable_disease_trigger = yes
		has_contagious_disease_trigger = yes
		has_wounds_trigger = yes
		is_incapable = yes
		has_character_flag = carn_slave_cannot_be_sold
		has_trait_with_flag = carn_slave_cannot_be_sold
	}
	trigger_if = {
		limit = { exists = imprisoner }
		has_relation_slave_owner = imprisoner
	}
}

carn_candidate_to_sell_slave_to_trigger = {
	is_ai = yes
	NOT = { this = scope:actor }
	highest_held_title_tier >= tier_county
	is_busy_in_events_localised = yes
	in_diplomatic_range = scope:actor
	gold > 0
	NOT = { is_at_war_with = scope:actor }
	is_imprisoned = no
}

carn_any_consort_or_slave_or_slave_owner_is_character_trigger = {
	OR = {
		any_consort = {
			this = $CHARACTER$
		}
		any_relation = {
			type = slave
			this = $CHARACTER$
		}
		any_relation = {
			type = slave_owner
			this = $CHARACTER$
		}
	}
}

carn_real_father_is_former_slave_or_slave_owner_trigger = {
	has_opinion_modifier = {
		target = scope:real_father
		modifier = carn_former_slave_or_slave_owner_opinion
	}
}


code:
should_be_naked_trigger = {
	# Character must be an adult.
	exists = this
	is_adult = yes

	# Character must have a valid reasion to be naked.
	OR = {
		faith = {
			has_doctrine_parameter = naked_adherents_active
		}
		AND = {
			faith = {
				has_doctrine_parameter = naked_priests_active
			}
			OR = {
				ai_zeal >= 50
				has_trait = devoted
				has_trait = zealous
				government_has_flag = government_is_theocracy
				has_council_position = councillor_court_chaplain
			}
		}
		has_character_modifier = diplomacy_majesty_4090_no_raiment_modifier # Lunatic event where character goes naked instead of buying new clothes.
		has_character_flag = is_naked # Special flag used in certain events.
	}

}


code:
should_be_naked_trigger = {
	# Character must be an adult.
	exists = this
	is_adult = yes

	# Character must have a valid reasion to be naked.
	OR = {
		faith = {
			has_doctrine_parameter = naked_adherents_active
		}
		AND = {
			is_female = yes
			faith = {
				has_doctrine_parameter = naked_females_active
			}
		}
		AND = {
			is_male = yes
			faith = {
				has_doctrine_parameter = naked_males_active
			}
		}
		AND = {
			OR = {
				faith = {
					has_doctrine_parameter = naked_priests_active
				}
				AND = {
					is_male = yes
					OR = {
						faith = {
							has_doctrine_parameter = naked_malepriest_active
						}
						faith = {
							has_doctrine_parameter = naked_malepriests_active
						}
					}
				}
				AND = {
					is_female = yes
					OR = {
						faith = {
							has_doctrine_parameter = naked_femalepriest_active
						}
						faith = {
							has_doctrine_parameter = naked_femalepriests_active
						}
					}
				}
			}
			OR = {
				ai_zeal >= 50
				has_trait = devoted
				has_trait = zealous
				government_has_flag = government_is_theocracy
				has_council_position = councillor_court_chaplain
			}
		}
		has_character_modifier = diplomacy_majesty_4090_no_raiment_modifier # Lunatic event where character goes naked instead of buying new clothes.
		has_character_flag = is_naked # Special flag used in certain events.
		has_trait_with_flag = is_naked
	}

}