code:
had_sex_with_effect = {
	save_scope_as = had_sex_root_character
	$CHARACTER$ = { save_scope_as = had_sex_with_effect_partner }

	# Error logging
	## Children should never run this effect.
	if = {
		limit = {
			OR = {
				scope:had_sex_root_character = { is_adult = no }
				scope:had_sex_with_effect_partner = { is_adult = no }
			}
		}
		error_log = "Trying to run had_sex_with_effect but one or more partners is a child"
	}
	## Did you forget to run the check for whether adultery was valid?
	if = {
		limit = {
			# Rarely, we may also want to block this check (e.g., seduction schemes or monogamous threesomes).
			NOT = { exists = scope:ignore_cheating_error_check }
		}
		# Check whether the root char is cheating.
		if = {
			limit = {
				scope:had_sex_root_character = {
					NOR = {
						is_consort_of = scope:had_sex_with_effect_partner
						has_relation_lover = scope:had_sex_with_effect_partner
					}
					might_cheat_on_every_partner_trigger = no
				}
			}
			# The weird structure here is so that we can use prev scope in loc to grab both chars.
			scope:had_sex_with_effect_partner = {
				scope:had_sex_root_character = { error_log = had_sex_with_effect.log.root_cheated_inappropriately }
			}
		}
		# Check whether their partner is cheating.
		## Though this does lead to potential duplication in the error log, where you'll get an entry for X cheating with Y _and_ for Y cheating with X, it is necessary: it's perfectly possible for one char to be cheating but the other not.
		if = {
			limit = {
				scope:had_sex_with_effect_partner = {
					NOR = {
						is_consort_of = scope:had_sex_root_character
						has_relation_lover = scope:had_sex_root_character
					}
					might_cheat_on_every_partner_trigger = no
				}
			}
			# The weird structure here is so that we can use prev scope in loc to grab both chars.
			scope:had_sex_root_character = {
				scope:had_sex_with_effect_partner = { error_log = had_sex_with_effect.log.target_cheated_inappropriately }
			}
		}
	}
	### Plus, remove the blocking scope we might have.
	clear_saved_scope = ignore_cheating_error_check

	if = {
		limit = { this = root }
		custom_tooltip = had_sex_with_effect.first_person.tt
	}
	else_if = {
		limit = { root = scope:had_sex_with_effect_partner }
		custom_tooltip = had_sex_with_effect.other_person.tt
	}
	else = {
		custom_tooltip = had_sex_with_effect.third_person.tt
	}

	create_character_memory = {
		type = had_sex
		participants = {
			sex_partner = scope:had_sex_with_effect_partner
		}
	}

	#Stress
	if = {
		limit = { # For use with events that add/remove more stress than these values, to avoid ugly tooltips
			NOT = {
				has_character_flag = no_sex_stress_loss
			}
		}
		$CHARACTER$ = {
			if = {
				limit = { this = root }
				stress_impact = {
					lustful = minor_stress_impact_loss
					rakish = minor_stress_impact_loss
				}
			}
			else = {
				hidden_effect = {
					stress_impact = {
						lustful = minor_stress_impact_loss
						rakish = minor_stress_impact_loss
					}
				}
			}
		}
		if = {
			limit = { this = root }
			stress_impact = {
				lustful = minor_stress_impact_loss
				rakish = minor_stress_impact_loss
			}
		}
		else = {
			hidden_effect = {
				stress_impact = {
					lustful = minor_stress_impact_loss
					rakish = minor_stress_impact_loss
				}
			}
		}
	}

	#Pregnancy & story cycles
	hidden_effect = {
		if = {
			limit = {
				is_female = yes
				$CHARACTER$ = { is_male = yes }
				possible_pregnancy_after_sex_with_character_trigger = { CHARACTER = scope:had_sex_with_effect_partner }
			}
			add_to_variable_list = {
				name = potential_father_variable_list
				target = $CHARACTER$
			}
			random = {
				chance = $PREGNANCY_CHANCE$
				make_pregnant = {
					father = $CHARACTER$
				}
			}
			if = {
				limit = {
					NOT = { has_character_flag = had_story_cycle_peasant_affair }
					is_ruler = yes
					$CHARACTER$ = {
						is_lowborn = yes
						is_playable_character = no
						is_courtier = no
					}
					NOT = {
						any_scheme = {
							scheme_target_character = $CHARACTER$
						}
					}
				}
				set_variable = {
					name = story_peasant_affair_target
					value = $CHARACTER$
				}
				create_story = story_peasant_affair
			}
		}
		else_if = {
			limit = {
				is_male = yes
				$CHARACTER$ = { is_female = yes }
				possible_pregnancy_after_sex_with_character_trigger = { CHARACTER = scope:had_sex_with_effect_partner }
			}
			$CHARACTER$ = {
				add_to_variable_list = {
					name = potential_father_variable_list
					target = scope:had_sex_with_effect_partner
				}
			}
			if = {
				limit = {
					NOT = { has_character_flag = had_story_cycle_peasant_affair }
					is_ruler = yes
					$CHARACTER$ = {
						is_lowborn = yes
						is_playable_character = no
						is_courtier = no
					}
					NOT = {
						any_scheme = {
							scheme_target_character ?= $CHARACTER$
						}
					}
				}
				set_variable = {
					name = story_peasant_affair_target
					value = $CHARACTER$
				}
				$CHARACTER$ = {
					if = {
						limit = {
							is_pregnant = no
							fertility >= 0.1
							is_visibly_fertile = yes
						}
						random = {
							chance = $PREGNANCY_CHANCE$
							add_character_flag = {
								flag = peasant_is_pregnant
								days = 560
							}
						}
					}
				}
				create_story = story_peasant_affair
			}
			else = {
				$CHARACTER$ = {
					random = {
						chance = $PREGNANCY_CHANCE$
						make_pregnant = {
							father = scope:had_sex_root_character
						}
					}
				}
			}
		}

		#STD transmission
		risk_of_std_from_effect = { PARTNER = $CHARACTER$ }
		hidden_effect = {
			$CHARACTER$ = { risk_of_std_from_effect = { PARTNER = scope:had_sex_root_character } }
		}

		#Adultery suspicion
		hidden_effect = {
			if = {
				limit = {
					OR = {
						is_married = yes
						is_concubine = yes
					}
					NOT = { any_consort = { this = $CHARACTER$ } }
				}
				set_variable = {
					name = had_recent_sex_with
					value = $CHARACTER$
					days = 1000
				}
				random = {
					chance = 50 #This should be quite high as there is a chance that adultery.0001 "fails" i.e. spouse doesn't realize
					every_relation = {
						type = soulmate
						limit = {
							NOT = { this = $CHARACTER$ } #Soulmates should not grow suspicous of adulterous affairs after sleeping with their lover
						}
						add_to_temporary_list = partners_1
					}
					every_consort = {
						add_to_temporary_list = partners_1
					}
					random_in_list = {
						list = partners_1
						limit = { is_ai = no }
						alternative_limit = { always = yes }
						trigger_event = {
							id = adultery.0001
							days = { 14 365 }
						}
					}
				}
			}
			$CHARACTER$ = {
				if = {
					limit = {
						OR = {
							is_married = yes
							is_concubine = yes
						}
						NOT = { any_consort = { this = scope:had_sex_root_character }}
					}
					set_variable = {
						name = had_recent_sex_with
						value = scope:had_sex_root_character
						days = 1000
					}
					random = {
						chance = 50 #This should be quite high as there is a chance that adultery.0001 "fails" i.e. spouse doesn't realize
						every_relation = {
							type = soulmate
							limit = {
								NOT = { this = scope:had_sex_root_character } #Soulmates should not grow suspicous of adulterous affairs after sleeping with their lover
							}
							add_to_temporary_list = partners_2
						}
						every_consort = {
							add_to_temporary_list = partners_2
						}
						random_in_list = {
							list = partners_2
							limit = { is_ai = no }
							alternative_limit = { always = yes }
							trigger_event = {
								id = adultery.0001
								days = { 14 365 }
							}
						}
					}
				}
			}
		}

		#Incestuous Relations
		give_incest_secret_or_nothing_with_target_effect = { CHARACTER = $CHARACTER$ }
		hidden_effect = {
			$CHARACTER$ = { give_incest_secret_or_nothing_with_target_effect = { CHARACTER = scope:had_sex_root_character } }
		}

		#Homosexuality
		give_homosexual_secret_or_nothing_with_target_effect = { CHARACTER = $CHARACTER$ }
		hidden_effect = {
			$CHARACTER$ = { give_homosexual_secret_or_nothing_with_target_effect = { CHARACTER = scope:had_sex_root_character } }
		}
	}

	#Violet Poet trait
	if = {
		limit = {
			scope:had_sex_root_character = {
				has_trait = violet_poet
			}
		}
		scope:had_sex_root_character = {
			add_trait_xp = {
				trait = violet_poet
				value = {
					integer_range = {
						min = 5
						max = 10
					}
				}
			}
		}
	}
	if = {
		limit = {
			scope:had_sex_with_effect_partner = {
				has_trait = violet_poet
			}
		}
		scope:had_sex_with_effect_partner = {
			add_trait_xp = {
				trait = violet_poet
				value = {
					integer_range = {
						min = 5
						max = 10
					}
				}
			}
		}
	}

	# Achievements
	fp2_had_friend_with_benefits = yes # FP2 History's Best Friend
}


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

# better version of had_sex_with_effect
#
# CHARACTER_1: the character doing the laying with.
# CHARACTER_2: the character getting laid.
# C1_PREGNANCY_CHANCE: the chance for Character 1 to get pregnant.
# C2_PREGNANCY_CHANCE: the chance for Character 2 to get pregnant.
# STRESS_EFFECTS: if yes, enables stress effects
# DRAMA: if yes, enables adultery suspicion and story cycles
#
# sends scope:carn_sex_char_1 and scope:carn_sex_char_2 to carn_on_sex
#
# returns scope:carn_sex_char_1_could_be_impregnated, scope:carn_sex_char_2_could_be_impregnated
# these are yes if the character had a pregnancy chance greater than 0 through this sex effect, and no otherwise
#
# returns scope:carn_sex_char_1_impregnated, scope:carn_sex_char_2_impregnated
# these are yes if the character was impregnated through this sex effect, and no otherwise

carn_had_sex_with_effect = {
	$CHARACTER_1$ = {
		# 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
		}

		# Save additional scopes for backward compatibility
		# These are required also here if pregnancy chances are dynamic values using them
		save_scope_as = had_sex_root_character
		$CHARACTER_2$ = {
			save_scope_as = had_sex_with_effect_partner
		}

		# Set pregnancy chances
		set_variable = {
			name = carn_pregnancy_chance
			value = $C1_PREGNANCY_CHANCE$
		}
		$CHARACTER_2$ = {
			set_variable = {
				name = carn_pregnancy_chance
				value = $C2_PREGNANCY_CHANCE$
			}
		}

		# Set default sex scene flags if not already set
		if = {
			limit = {
				NOR = {
					carn_sex_scene_character_is_giving_player_trigger = yes
					carn_sex_scene_character_is_receiving_player_trigger = yes
				}
			}
			carn_sex_scene_character_is_giving_player_effect = yes
		}
		if = {
			limit = {
				NOR = {
					carn_sex_scene_is_consensual_trigger = yes
					carn_sex_scene_is_dubcon_trigger = yes
					carn_sex_scene_is_noncon_trigger = yes
				}
			}
			carn_sex_scene_is_consensual_effect = yes
		}
		if = {
			limit = {
				NOR = {
					carn_sex_scene_is_oral_trigger = yes
					carn_sex_scene_is_vaginal_trigger = yes
					carn_sex_scene_is_anal_trigger = yes
					carn_sex_scene_is_handjob_trigger = yes
					carn_sex_scene_is_masturbation_trigger = yes
				}
			}
			carn_sex_scene_is_vaginal_effect = yes
		}
		if = {
			limit = {
				NOT = {
					carn_sex_scene_is_cum_inside_trigger = yes
					carn_sex_scene_is_cum_outside_trigger = yes
				}
			}
			carn_sex_scene_is_cum_inside_effect = yes
		}

		# Execute the new effect
		carn_had_sex_with_effect_v2 = {
			PARTNER = $CHARACTER_2$
		}

		# Cleanup flags if the effect was not executed in a sex scene
		# For sex scenes, this cleanup should happen either in the sex scene itself
		# or in carn_sex_scene_effect
		if = {
			limit = { NOT = { exists = scope:carn_sex_scene } }
			carn_sex_scene_clean_up_flags_effect = yes
			carn_sex_scene_clean_up_character_flags_effect = yes
			$CHARACTER_2$ = {
				carn_sex_scene_clean_up_character_flags_effect = yes
			}
		}

		# Remove pregnancy chances
		remove_variable = carn_pregnancy_chance
		$CHARACTER_2$ = {
			remove_variable = carn_pregnancy_chance
		}
	}
}

repo_name: Synthael/carnalitas

license: mit


code:
# carn_increase_beauty_one_step_effect
# carn_decrease_beauty_one_step_effect
# carn_increase_intellect_one_step_effect
# carn_decrease_intellect_one_step_effect
# carn_increase_physique_one_step_effect
# carn_decrease_physique_one_step_effect
# carn_remove_random_negative_congenital_trait_effect
# carn_remove_all_negative_congenital_traits_effect
# carn_heal_wounds_one_step_effect
# carn_remove_all_wounds_effect
# carn_remove_random_minor_disfigurement_effect
# carn_remove_all_minor_disfigurements_effect
# carn_remove_random_major_disfigurement_effect
# carn_remove_all_major_disfigurements_effect
# carn_recover_from_all_diseases_effect

carn_increase_beauty_one_step_effect = {
	if = {
		limit = { has_trait = beauty_good_2 }
		remove_trait = beauty_good_2
		add_trait = beauty_good_3
	}
	else_if = {
		limit = { has_trait = beauty_good_1 }
		remove_trait = beauty_good_1
		add_trait = beauty_good_2
	}
	else_if = {
		limit = { has_trait = beauty_bad_3 }
		remove_trait = beauty_bad_3
		add_trait = beauty_bad_2
	}
	else_if = {
		limit = { has_trait = beauty_bad_2 }
		remove_trait = beauty_bad_2
		add_trait = beauty_bad_1
	}
	else_if = {
		limit = { has_trait = beauty_bad_1 }
		remove_trait = beauty_bad_1
	}
	else = {
		add_trait = beauty_good_1
	}
}

carn_decrease_beauty_one_step_effect = {
	if = {
		limit = { has_trait = beauty_good_3 }
		remove_trait = beauty_good_3
		add_trait = beauty_good_2
	}
	else_if = {
		limit = { has_trait = beauty_good_2 }
		remove_trait = beauty_good_2
		add_trait = beauty_good_1
	}
	else_if = {
		limit = { has_trait = beauty_good_1 }
		remove_trait = beauty_good_1
	}
	else_if = {
		limit = { has_trait = beauty_bad_1 }
		remove_trait = beauty_bad_1
		add_trait = beauty_bad_2
	}
	else_if = {
		limit = { has_trait = beauty_bad_2 }
		remove_trait = beauty_bad_2
		add_trait = beauty_bad_3
	}
	else = {
		add_trait = beauty_bad_1
	}
}

carn_increase_intellect_one_step_effect = {
	if = {
		limit = { has_trait = intellect_good_2 }
		remove_trait = intellect_good_2
		add_trait = intellect_good_3
	}
	else_if = {
		limit = { has_trait = intellect_good_1 }
		remove_trait = intellect_good_1
		add_trait = intellect_good_2
	}
	else_if = {
		limit = { has_trait = intellect_bad_3 }
		remove_trait = intellect_bad_3
		add_trait = intellect_bad_2
	}
	else_if = {
		limit = { has_trait = intellect_bad_2 }
		remove_trait = intellect_bad_2
		add_trait = intellect_bad_1
	}
	else_if = {
		limit = { has_trait = intellect_bad_1 }
		remove_trait = intellect_bad_1
	}
	else = {
		add_trait = intellect_good_1
	}
}

carn_decrease_intellect_one_step_effect = {
	if = {
		limit = { has_trait = intellect_good_3 }
		remove_trait = intellect_good_3
		add_trait = intellect_good_2
	}
	else_if = {
		limit = { has_trait = intellect_good_2 }
		remove_trait = intellect_good_2
		add_trait = intellect_good_1
	}
	else_if = {
		limit = { has_trait = intellect_good_1 }
		remove_trait = intellect_good_1
	}
	else_if = {
		limit = { has_trait = intellect_bad_1 }
		remove_trait = intellect_bad_1
		add_trait = intellect_bad_2
	}
	else_if = {
		limit = { has_trait = intellect_bad_2 }
		remove_trait = intellect_bad_2
		add_trait = intellect_bad_3
	}
	else = {
		add_trait = intellect_bad_1
	}
}

carn_increase_physique_one_step_effect = {
	if = {
		limit = { has_trait = physique_good_2 }
		remove_trait = physique_good_2
		add_trait = physique_good_3
	}
	else_if = {
		limit = { has_trait = physique_good_1 }
		remove_trait = physique_good_1
		add_trait = physique_good_2
	}
	else_if = {
		limit = { has_trait = physique_bad_3 }
		remove_trait = physique_bad_3
		add_trait = physique_bad_2
	}
	else_if = {
		limit = { has_trait = physique_bad_2 }
		remove_trait = physique_bad_2
		add_trait = physique_bad_1
	}
	else_if = {
		limit = { has_trait = physique_bad_1 }
		remove_trait = physique_bad_1
	}
	else = {
		add_trait = physique_good_1
	}
}

carn_decrease_physique_one_step_effect = {
	if = {
		limit = { has_trait = physique_good_3 }
		remove_trait = physique_good_3
		add_trait = physique_good_2
	}
	else_if = {
		limit = { has_trait = physique_good_2 }
		remove_trait = physique_good_2
		add_trait = physique_good_1
	}
	else_if = {
		limit = { has_trait = physique_good_1 }
		remove_trait = physique_good_1
	}
	else_if = {
		limit = { has_trait = physique_bad_1 }
		remove_trait = physique_bad_1
		add_trait = physique_bad_2
	}
	else_if = {
		limit = { has_trait = physique_bad_2 }
		remove_trait = physique_bad_2
		add_trait = physique_bad_3
	}
	else = {
		add_trait = physique_bad_1
	}
}

carn_remove_random_negative_congenital_trait_effect = {
	random_list = {
		1 = {
			trigger = { has_trait = beauty_bad }
			carn_increase_beauty_one_step_effect = yes
		}
		1 = {
			trigger = { has_trait = intellect_bad }
			carn_increase_intellect_one_step_effect = yes
		}
		1 = {
			trigger = { has_trait = physique_bad }
			carn_increase_physique_one_step_effect = yes
		}
		1 = {
			trigger = { has_trait = clubfooted }
			remove_trait = clubfooted
		}
		1 = {
			trigger = { has_trait = hunchbacked }
			remove_trait = hunchbacked
		}
		1 = {
			trigger = { has_trait = lisping }
			remove_trait = lisping
		}
		1 = {
			trigger = { has_trait = stuttering }
			remove_trait = stuttering
		}
		1 = {
			trigger = { has_trait = dwarf }
			remove_trait = dwarf
		}
		1 = {
			trigger = { has_trait = giant }
			remove_trait = giant
		}
		1 = {
			trigger = { has_trait = spindly }
			remove_trait = spindly
		}
		1 = {
			trigger = { has_trait = scaly }
			remove_trait = scaly
		}
		1 = {
			trigger = { has_trait = wheezing }
			remove_trait = wheezing
		}
		1 = {
			trigger = { has_trait = bleeder }
			remove_trait = bleeder
		}
		1 = {
			trigger = { has_trait = infertile }
			remove_trait = infertile
		}
		1 = {
			trigger = { has_trait = possessed_genetic }
			remove_trait = possessed_genetic
		}
		1 = {
			trigger = { has_trait = depressed_genetic }
			remove_trait = depressed_genetic
		}
	}
}

carn_remove_all_negative_congenital_traits_effect = {
	remove_trait = beauty_bad_1
	remove_trait = beauty_bad_2
	remove_trait = beauty_bad_3
	remove_trait = intellect_bad_1
	remove_trait = intellect_bad_2
	remove_trait = intellect_bad_3
	remove_trait = physique_bad_1
	remove_trait = physique_bad_2
	remove_trait = physique_bad_3
	remove_trait = clubfooted
	remove_trait = hunchbacked
	remove_trait = lisping
	remove_trait = stuttering
	remove_trait = dwarf
	remove_trait = giant
	remove_trait = inbred
	remove_trait = spindly
	remove_trait = scaly
	remove_trait = wheezing
	remove_trait = bleeder
	remove_trait = infertile
	remove_trait = possessed_genetic
	remove_trait = depressed_genetic
}

carn_heal_wounds_one_step_effect = {
	if = {
		limit = { has_character_modifier = infected_wound_modifier }
		remove_character_modifier = infected_wound_modifier
	}
	if = {
		limit = { has_character_modifier = gangrene_modifier }
		remove_character_modifier = gangrene_modifier
	}
	if = {
		limit = { has_trait = wounded_1 }
		remove_trait = wounded_1
	}
	else_if = {
		limit = { has_trait = wounded_2 }
		remove_trait = wounded_2 #We do it like this so you can see the trait you've lost
		add_trait_force_tooltip = wounded_1
	}
	else_if = {
		limit = { has_trait = wounded_3 }
		remove_trait = wounded_3
		add_trait_force_tooltip = wounded_2
	}
}

carn_remove_all_wounds_effect = {
	if = {
		limit = { has_character_modifier = infected_wound_modifier }
		remove_character_modifier = infected_wound_modifier
	}
	if = {
		limit = { has_character_modifier = gangrene_modifier }
		remove_character_modifier = gangrene_modifier
	}
	remove_trait = wounded_1
	remove_trait = wounded_2
	remove_trait = wounded_3
}

carn_remove_random_minor_disfigurement_effect = {
	random_list = {
		1 = {
			trigger = { has_trait = one_eyed }
			remove_trait = one_eyed
		}
		1 = {
			trigger = { has_trait = scarred }
			remove_trait = scarred
		}
		1 = {
			trigger = { carn_has_any_minor_disfigurement_trigger = no }
			# fallback
		}
	}
}

carn_remove_all_minor_disfigurements_effect = {
	remove_trait = one_eyed
	remove_trait = scarred
}

carn_remove_random_major_disfigurement_effect = {
	random_list = {
		1 = {
			trigger = { has_trait = maimed }
			remove_trait = maimed
		}
		1 = {
			trigger = { has_trait = one_legged }
			remove_trait = one_legged
		}
		1 = {
			trigger = { has_trait = disfigured }
			remove_trait = disfigured
		}
		1 = {
			trigger = { has_trait = eunuch_1 }
			remove_trait = eunuch_1
		}
		1 = {
			trigger = { has_trait = beardless_eunuch }
			remove_trait = beardless_eunuch
		}
		1 = {
			trigger = { has_trait = blind }
			remove_trait = blind
		}
		1 = {
			trigger = { carn_has_any_major_disfigurement_trigger = no }
			# fallback
		}
	}
}

carn_remove_all_major_disfigurements_effect = {
	remove_trait = maimed
	remove_trait = one_legged
	remove_trait = disfigured
	remove_trait = eunuch_1
	remove_trait = beardless_eunuch
	remove_trait = blind
}

carn_recover_from_all_diseases_effect = {
	remove_trait = sickly
	recover_from_disease_effect = { DISEASE = ill }
	recover_from_disease_effect = { DISEASE = pneumonic }
	recover_from_disease_effect = { DISEASE = gout_ridden }
	recover_from_disease_effect = { DISEASE = typhus }
	recover_from_disease_effect = { DISEASE = consumption }
	recover_from_disease_effect = { DISEASE = cancer }
	recover_from_disease_effect = { DISEASE = great_pox }
	recover_from_disease_effect = { DISEASE = smallpox }
	recover_from_disease_effect = { DISEASE = bubonic_plague }
	recover_from_disease_effect = { DISEASE = lovers_pox }
	recover_from_disease_effect = { DISEASE = great_pox }
}


code:
###################################################################
# LACTATION EFFECTS
# by Cheri
#
# These effects are meant for modders to manipulate a character's milk production.
#
# First, use `carn_create_milk_production_change_effect = yes`
# This will initialize necessary variables
#
# Then use any of the following scripted effects:
# `carn_set_milk_production_effect` (requires VALUE)
# `carn_change_milk_production_effect` (requires VALUE)
# `carn_set_milk_production_minimum_effect` (requires MINIMUM)
# `carn_set_milk_production_maximum_effect` (requires MAXIMUM)
#
# Finally, use `carn_resolve_milk_production_change_effect` to commit the effect and show an appropriate tooltip, trigger on_actions, etc.
# Takes argument `SEND_NOTIFICATION` which can be yes or no
#
# refer to script_values/carn_lactation_values.txt for what different lactation values roughly correspond to
#
# Here is an example that increases the character's milk production by 10
#
# effect = {
#	carn_create_milk_production_change_effect = yes
#	carn_change_milk_production_effect = {
#		VALUE = 10
#	}
#	carn_resolve_milk_production_change_effect = {
#		SEND_NOTIFICATION = yes
#	}
# }
#
###################################################################

# carn_create_milk_production_change_effect
# carn_resolve_milk_production_change_effect

# carn_set_milk_production_effect
# carn_stop_milk_production_effect
# carn_change_milk_production_effect
# carn_set_milk_production_minimum_effect
# carn_set_milk_production_maximum_effect

# carn_send_milk_production_change_notification_effect

# carn_create_milk_production_change_effect
carn_create_milk_production_change_effect = {

	# initialize variables if they don't exist yet
	if = {
		limit = {
			NOT = { exists = var:carn_milk_production }
		}
		set_variable = {
			name = carn_milk_production
			value = 0
		}
	}
	set_variable = {
		name = carn_old_milk_production
		value = var:carn_milk_production
	}
	set_variable = {
		name = carn_new_milk_production
		value = var:carn_milk_production
	}
}

# carn_resolve_milk_production_change_effect
# requires SEND_NOTIFICATION = yes or no
carn_resolve_milk_production_change_effect = {
	if = {
		limit = {
			carn_can_lactate_trigger = yes
		}

		### ACTUALLY CHANGING THE VARIABLE

		set_variable = {
			name = carn_milk_production
			value = var:carn_new_milk_production
		}

		### NOTIFICATIONS AND ON_ACTIONS ###

		if = {
			limit = {
				var:carn_old_milk_production != var:carn_new_milk_production
			}
			trigger_event = {
				on_action = carn_on_milk_production_change
			}
		}

		if = {
			limit = {
				var:carn_old_milk_production <= 0
				var:carn_new_milk_production > 0
			}
			trigger_event = {
				on_action = carn_on_start_lactating
			}
			custom_tooltip = carn_starts_lactating_tooltip
		}
		else_if = {
			limit = {
				var:carn_old_milk_production > 0
				var:carn_new_milk_production <= 0
			}
			trigger_event = {
				on_action = carn_on_stop_lactating
			}
			custom_tooltip = carn_stops_lactating_tooltip
		}
		else_if = {
			# milk production increased
			limit = {
				var:carn_old_milk_production < var:carn_new_milk_production
			}
			custom_tooltip = carn_milk_production_increases_tooltip
		}
		else_if = {
			# milk production decreased
			limit = {
				var:carn_old_milk_production > var:carn_new_milk_production
			}
			custom_tooltip = carn_milk_production_decreases_tooltip
		}

		hidden_effect = {
			if = {
				limit = { $SEND_NOTIFICATION$ = yes }
				carn_send_milk_production_change_notification_effect = yes
			}
		}

		# free up memory
		remove_variable = carn_old_milk_production
		remove_variable = carn_new_milk_production
	}
}

# carn_set_milk_production_effect
# requires VALUE (integer)
carn_set_milk_production_effect = {
	set_variable = {
		name = carn_new_milk_production
		value = $VALUE$
	}
	carn_set_milk_production_minimum_effect = {
		MINIMUM = 0
	}
}

# carn_stop_milk_production_effect
carn_stop_milk_production_effect = {
	set_variable = {
		name = carn_new_milk_production
		value = 0
	}
}

# carn_change_milk_production_effect
# requires VALUE (integer)
carn_change_milk_production_effect = {
	change_variable = {
		name = carn_new_milk_production
		add = $VALUE$
	}
	carn_set_milk_production_minimum_effect = {
		MINIMUM = 0
	}
}

# carn_set_milk_production_minimum_effect
# requires MINIMUM (integer)
carn_set_milk_production_minimum_effect = {
	if = {
		limit = {
			var:carn_new_milk_production < $MINIMUM$
		}
		set_variable = {
			name = carn_new_milk_production
			value = $MINIMUM$
		}
	}
}

# carn_set_milk_production_maximum_effect
# requires MAXIMUM (integer)
carn_set_milk_production_maximum_effect = {
	if = {
		limit = {
			var:carn_new_milk_production > $MAXIMUM$
		}
		set_variable = {
			name = carn_new_milk_production
			value = $MAXIMUM$
		}
	}
}

# carn_send_milk_production_change_notification_effect
# used internally
carn_send_milk_production_change_notification_effect = {
	if = {
		# started lactating
		limit = {
			var:carn_old_milk_production <= 0
			var:carn_new_milk_production > 0
		}
		send_interface_message = {
			type = event_generic_neutral
			title = carn_msg_started_lactating
			right_icon = this
			custom_tooltip = carn_milk_production_notification_desc
		}
	}
	else_if = {
		# stopped lactating
		limit = {
			var:carn_old_milk_production > 0
			var:carn_new_milk_production <= 0
		}
		send_interface_message = {
			type = event_generic_neutral
			title = carn_msg_stopped_lactating
			right_icon = this
			custom_tooltip = carn_stopped_lactating_notification_desc
		}
	}
	else_if = {
		# milk production increased one or more tiers
		limit = {
			OR = {
				AND = {
					var:carn_old_milk_production < carn_very_low_milk_production_amount
					var:carn_new_milk_production >= carn_very_low_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production < carn_low_milk_production_amount
					var:carn_new_milk_production >= carn_low_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production < carn_average_milk_production_amount
					var:carn_new_milk_production >= carn_average_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production < carn_high_milk_production_amount
					var:carn_new_milk_production >= carn_high_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production < carn_very_high_milk_production_amount
					var:carn_new_milk_production >= carn_very_high_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production < carn_extreme_milk_production_amount
					var:carn_new_milk_production >= carn_extreme_milk_production_amount
				}
			}
		}
		send_interface_message = {
			type = event_generic_neutral
			title = carn_msg_milk_production_increased
			right_icon = this
			custom_tooltip = carn_milk_production_notification_desc
		}
	}
	else_if = {
		# milk production decreased one or more tiers
		limit = {
			OR = {
				AND = {
					var:carn_old_milk_production >= carn_very_low_milk_production_amount
					var:carn_new_milk_production < carn_very_low_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production >= carn_low_milk_production_amount
					var:carn_new_milk_production < carn_low_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production >= carn_average_milk_production_amount
					var:carn_new_milk_production < carn_average_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production >= carn_high_milk_production_amount
					var:carn_new_milk_production < carn_high_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production >= carn_very_high_milk_production_amount
					var:carn_new_milk_production < carn_very_high_milk_production_amount
				}
				AND = {
					var:carn_old_milk_production >= carn_extreme_milk_production_amount
					var:carn_new_milk_production < carn_extreme_milk_production_amount
				}
			}
		}
		send_interface_message = {
			type = event_generic_neutral
			title = carn_msg_milk_production_decreased
			right_icon = this
			custom_tooltip = carn_milk_production_notification_desc
		}
	}
}


code:
#####################################################################################
# carn_exclude_trait_from_personality_replacement_effect (requires TRAIT)
# carn_create_personality_replacement_effect (requires NEW_TRAIT)
# carn_resolve_personality_replacement_effect
# carn_clear_personality_replacement_effect
#####################################################################################

# This is a group of scripted effects for changing the personality of a character (slave training, hypnosis, corruption, etc.) without breaking the rule of only having 3 personality traits.

# Run in the scope of the character whose personality you want to replace.

# Does not work on children.

#####################################################################################
# STEP 1
#####################################################################################

# First use `carn_exclude_trait_from_personality_replacement_effect` to exclude any traits that you don't want to be replaced (e.g. if the trait is already desirable)
# TRAIT is the trait you want to exclude (`TRAIT = compassionate`)

# For example:
# carn_exclude_trait_from_personality_replacement_effect = {
#	TRAIT = compassionate
# }

#####################################################################################
# STEP 2
#####################################################################################

# Then use `carn_create_personality_replacement_effect` to set up a personality replacement.
# NEW_TRAIT is the trait you want to add ("NEW_TRAIT = lustful")

# For example:
# carn_create_personality_replacement_effect = {
#	NEW_TRAIT = lustful
# }

# This will pick a trait to remove and set it as `scope:carn_replaced_trait`
# If the character has the opposite trait it will prioritize flipping that, otherwise it just replaces a random other personality trait

# You can reference this in triggers, for example, `scope:carn_replaced_trait = flag:compassionate`
# It also creates a reference for `scope:carn_new_trait`, for example, `scope:carn_new_trait = flag:lustful`

# If no trait was picked (perhaps because all eligible traits were excluded) it will return `scope:carn_replaced_trait = flag:none`

#####################################################################################
# STEP 3
#####################################################################################

# Once you have excluded the traits you don't want to replace, and set up a personality replacement effect, you can use one of two different scripted effects:

# `carn_resolve_personality_replacement_effect` will make the replacement happen, then clear scopes

# `carn_clear_personality_replacement_effect` will clear scopes without doing anything.

#####################################################################################
#####################################################################################

#####################################################################################
# carn_exclude_trait_from_personality_replacement_effect
# Run in the scope of the character whose personality you want to replace.
# TRAIT is the trait you want to exclude ("TRAIT = lustful")
#####################################################################################

carn_exclude_trait_from_personality_replacement_effect = {
	add_to_variable_list = {
		name = carn_personality_replacement_excluded_traits
		target = flag:$TRAIT$
	}
}

#####################################################################################
# carn_create_personality_replacement_effect
# Run in the scope of the character whose personality you want to replace.
# NEW_TRAIT is the trait you want to add ("NEW_TRAIT = lustful")
#####################################################################################

carn_create_personality_replacement_effect = {
	save_scope_value_as = {
		name = carn_new_trait
		value = flag:$NEW_TRAIT$
	}

	# prioritize flipping oppozite trait to this trait
	carn_try_create_personality_replacement_effect_by_flipping_opposite_trait = yes

	# if no opposite trait, pick a random trait to replace
	if = {
		limit = {
			NOT = { exists = scope:carn_replaced_trait }
		}
		carn_try_create_personality_replacement_effect_by_random_replacement = yes
	}

	if = {
		limit = {
			NOT = { exists = scope:carn_replaced_trait }
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:none
		}
	}
}

carn_try_create_personality_replacement_effect_by_flipping_opposite_trait = {
	if = {
		limit = {
			scope:carn_new_trait = flag:lustful
			has_trait = chaste
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:chaste
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:chaste
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:chaste
			has_trait = lustful
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:lustful
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:lustful
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:gluttonous
			has_trait = temperate
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:temperate
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:temperate
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:temperate
			has_trait = gluttonous
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:gluttonous
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:gluttonous
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:greedy
			has_trait = generous
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:generous
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:generous
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:generous
			has_trait = greedy
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:greedy
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:greedy
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:lazy
			has_trait = diligent
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:diligent
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:diligent
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:diligent
			has_trait = lazy
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:lazy
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:lazy
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:wrathful
			has_trait = calm
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:calm
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:calm
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:calm
			has_trait = wrathful
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:wrathful
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:wrathful
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:patient
			has_trait = impatient
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:impatient
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:impatient
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:impatient
			has_trait = patient
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:patient
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:patient
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:arrogant
			has_trait = humble
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:humble
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:humble
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:humble
			has_trait = arrogant
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:arrogant
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:arrogant
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:deceitful
			has_trait = honest
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:honest
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:honest
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:honest
			has_trait = deceitful
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:deceitful
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:deceitful
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:craven
			has_trait = brave
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:brave
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:brave
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:brave
			has_trait = craven
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:craven
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:craven
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:shy
			has_trait = gregarious
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:gregarious
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:gregarious
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:gregarious
			has_trait = shy
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:shy
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:shy
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:ambitious
			has_trait = content
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:content
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:content
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:content
			has_trait = ambitious
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:ambitious
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:ambitious
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:arbitrary
			has_trait = just
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:just
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:just
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:just
			has_trait = arbitrary
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:arbitrary
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:arbitrary
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:cynical
			has_trait = zealous
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:zealous
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:zealous
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:zealous
			has_trait = cynical
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:cynical
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:cynical
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:paranoid
			has_trait = trusting
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:trusting
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:trusting
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:trusting
			has_trait = paranoid
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:paranoid
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:paranoid
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:compassionate
			has_trait = sadistic
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:sadistic
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:sadistic
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:compassionate
			has_trait = callous
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:callous
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:callous
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:callous
			has_trait = compassionate
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:compassionate
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:compassionate
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:callous
			has_trait = sadistic
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:sadistic
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:sadistic
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:sadistic
			has_trait = callous
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:callous
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:callous
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:sadistic
			has_trait = compassionate
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:compassionate
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:compassionate
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:stubborn
			has_trait = fickle
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:fickle
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:fickle
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:fickle
			has_trait = stubborn
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:stubborn
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:stubborn
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:vengeful
			has_trait = forgiving
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:forgiving
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:forgiving
		}
	}
	else_if = {
		limit = {
			scope:carn_new_trait = flag:forgiving
			has_trait = vengeful
			NOT = {
				is_target_in_variable_list = {
					name = carn_personality_replacement_excluded_traits
					target = flag:vengeful
				}
			}
		}
		save_scope_value_as = {
			name = carn_replaced_trait
			value = flag:vengeful
		}
	}
}

carn_try_create_personality_replacement_effect_by_random_replacement = {
	random_list = {
		10 = {
			trigger = {
				has_trait = lustful
				NOR = {
					scope:carn_new_trait = flag:lustful
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:lustful
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:lustful
			}
		}

		10 = {
			trigger = {
				has_trait = chaste
				NOR = {
					scope:carn_new_trait = flag:chaste
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:chaste
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:chaste
			}
		}

		10 = {
			trigger = {
				has_trait = gluttonous
				NOR = {
					scope:carn_new_trait = flag:gluttonous
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:gluttonous
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:gluttonous
			}
		}

		10 = {
			trigger = {
				has_trait = temperate
				NOR = {
					scope:carn_new_trait = flag:temperate
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:temperate
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:temperate
			}
		}

		10 = {
			trigger = {
				has_trait = greedy
				NOR = {
					scope:carn_new_trait = flag:greedy
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:greedy
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:greedy
			}
		}

		10 = {
			trigger = {
				has_trait = generous
				NOR = {
					scope:carn_new_trait = flag:generous
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:generous
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:generous
			}
		}

		10 = {
			trigger = {
				has_trait = lazy
				NOR = {
					scope:carn_new_trait = flag:lazy
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:lazy
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:lazy
			}
		}

		10 = {
			trigger = {
				has_trait = diligent
				NOR = {
					scope:carn_new_trait = flag:diligent
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:diligent
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:diligent
			}
		}

		10 = {
			trigger = {
				has_trait = wrathful
				NOR = {
					scope:carn_new_trait = flag:wrathful
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:wrathful
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:wrathful
			}
		}

		10 = {
			trigger = {
				has_trait = calm
				NOR = {
					scope:carn_new_trait = flag:calm
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:calm
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:calm
			}
		}

		10 = {
			trigger = {
				has_trait = patient
				NOR = {
					scope:carn_new_trait = flag:patient
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:patient
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:patient
			}
		}

		10 = {
			trigger = {
				has_trait = impatient
				NOR = {
					scope:carn_new_trait = flag:impatient
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:impatient
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:impatient
			}
		}

		10 = {
			trigger = {
				has_trait = arrogant
				NOR = {
					scope:carn_new_trait = flag:arrogant
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:arrogant
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:arrogant
			}
		}

		10 = {
			trigger = {
				has_trait = humble
				NOR = {
					scope:carn_new_trait = flag:humble
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:humble
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:humble
			}
		}

		10 = {
			trigger = {
				has_trait = deceitful
				NOR = {
					scope:carn_new_trait = flag:deceitful
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:deceitful
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:deceitful
			}
		}

		10 = {
			trigger = {
				has_trait = honest
				NOR = {
					scope:carn_new_trait = flag:honest
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:honest
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:honest
			}
		}

		10 = {
			trigger = {
				has_trait = craven
				NOR = {
					scope:carn_new_trait = flag:craven
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:craven
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:craven
			}
		}

		10 = {
			trigger = {
				has_trait = brave
				NOR = {
					scope:carn_new_trait = flag:brave
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:brave
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:brave
			}
		}

		10 = {
			trigger = {
				has_trait = shy
				NOR = {
					scope:carn_new_trait = flag:shy
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:shy
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:shy
			}
		}

		10 = {
			trigger = {
				has_trait = gregarious
				NOR = {
					scope:carn_new_trait = flag:gregarious
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:gregarious
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:gregarious
			}
		}

		10 = {
			trigger = {
				has_trait = ambitious
				NOR = {
					scope:carn_new_trait = flag:ambitious
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:ambitious
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:ambitious
			}
		}

		10 = {
			trigger = {
				has_trait = content
				NOR = {
					scope:carn_new_trait = flag:content
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:content
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:content
			}
		}

		10 = {
			trigger = {
				has_trait = arbitrary
				NOR = {
					scope:carn_new_trait = flag:arbitrary
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:arbitrary
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:arbitrary
			}
		}

		10 = {
			trigger = {
				has_trait = just
				NOR = {
					scope:carn_new_trait = flag:just
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:just
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:just
			}
		}

		10 = {
			trigger = {
				has_trait = cynical
				NOR = {
					scope:carn_new_trait = flag:cynical
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:cynical
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:cynical
			}
		}

		10 = {
			trigger = {
				has_trait = zealous
				NOR = {
					scope:carn_new_trait = flag:zealous
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:zealous
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:zealous
			}
		}

		10 = {
			trigger = {
				has_trait = paranoid
				NOR = {
					scope:carn_new_trait = flag:paranoid
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:paranoid
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:paranoid
			}
		}

		10 = {
			trigger = {
				has_trait = trusting
				NOR = {
					scope:carn_new_trait = flag:trusting
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:trusting
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:trusting
			}
		}

		10 = {
			trigger = {
				has_trait = compassionate
				NOR = {
					scope:carn_new_trait = flag:compassionate
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:compassionate
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:compassionate
			}
		}

		10 = {
			trigger = {
				has_trait = callous
				NOR = {
					scope:carn_new_trait = flag:callous
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:callous
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:callous
			}
		}

		10 = {
			trigger = {
				has_trait = sadistic
				NOR = {
					scope:carn_new_trait = flag:sadistic
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:sadistic
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:sadistic
			}
		}

		10 = {
			trigger = {
				has_trait = stubborn
				NOR = {
					scope:carn_new_trait = flag:stubborn
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:stubborn
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:stubborn
			}
		}

		10 = {
			trigger = {
				has_trait = fickle
				NOR = {
					scope:carn_new_trait = flag:fickle
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:fickle
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:fickle
			}
		}

		10 = {
			trigger = {
				has_trait = vengeful
				NOR = {
					scope:carn_new_trait = flag:vengeful
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:vengeful
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:vengeful
			}
		}

		10 = {
			trigger = {
				has_trait = forgiving
				NOR = {
					scope:carn_new_trait = flag:forgiving
					is_target_in_variable_list = {
						name = carn_personality_replacement_excluded_traits
						target = flag:forgiving
					}
				}
			}
			save_scope_value_as = {
				name = carn_replaced_trait
				value = flag:forgiving
			}
		}
	}
}

#####################################################################################
# carn_resolve_personality_replacement_effect
# Run in the scope of the character whose personality you want to replace.
# Requires `scope:carn_new_trait` and `scope:carn_replaced_trait`
#####################################################################################

carn_resolve_personality_replacement_effect = {
	### remove the replaced trait
	if = {
		limit = { scope:carn_replaced_trait = flag:lustful }
		remove_trait = lustful
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:chaste }
		remove_trait = chaste
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:gluttonous }
		remove_trait = gluttonous
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:temperate }
		remove_trait = temperate
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:greedy }
		remove_trait = greedy
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:generous }
		remove_trait = generous
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:lazy }
		remove_trait = lazy
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:diligent }
		remove_trait = diligent
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:wrathful }
		remove_trait = wrathful
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:calm }
		remove_trait = calm
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:patient }
		remove_trait = patient
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:impatient }
		remove_trait = impatient
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:arrogant }
		remove_trait = arrogant
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:humble }
		remove_trait = humble
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:deceitful }
		remove_trait = deceitful
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:honest }
		remove_trait = honest
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:craven }
		remove_trait = craven
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:brave }
		remove_trait = brave
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:shy }
		remove_trait = shy
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:gregarious }
		remove_trait = gregarious
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:ambitious }
		remove_trait = ambitious
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:content }
		remove_trait = content
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:arbitrary }
		remove_trait = arbitrary
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:just }
		remove_trait = just
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:cynical }
		remove_trait = cynical
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:zealous }
		remove_trait = zealous
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:paranoid }
		remove_trait = paranoid
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:trusting }
		remove_trait = trusting
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:compassionate }
		remove_trait = compassionate
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:callous }
		remove_trait = callous
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:sadistic }
		remove_trait = sadistic
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:stubborn }
		remove_trait = stubborn
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:fickle }
		remove_trait = fickle
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:vengeful }
		remove_trait = vengeful
	}
	else_if = {
		limit = { scope:carn_replaced_trait = flag:forgiving }
		remove_trait = forgiving
	}

	### add the new trait
	if = {
		limit = { scope:carn_new_trait = flag:lustful }
		add_trait = lustful
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:chaste }
		add_trait = chaste
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:gluttonous }
		add_trait = gluttonous
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:temperate }
		add_trait = temperate
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:greedy }
		add_trait = greedy
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:generous }
		add_trait = generous
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:lazy }
		add_trait = lazy
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:diligent }
		add_trait = diligent
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:wrathful }
		add_trait = wrathful
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:calm }
		add_trait = calm
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:patient }
		add_trait = patient
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:impatient }
		add_trait = impatient
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:arrogant }
		add_trait = arrogant
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:humble }
		add_trait = humble
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:deceitful }
		add_trait = deceitful
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:honest }
		add_trait = honest
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:craven }
		add_trait = craven
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:brave }
		add_trait = brave
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:shy }
		add_trait = shy
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:gregarious }
		add_trait = gregarious
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:ambitious }
		add_trait = ambitious
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:content }
		add_trait = content
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:arbitrary }
		add_trait = arbitrary
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:just }
		add_trait = just
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:cynical }
		add_trait = cynical
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:zealous }
		add_trait = zealous
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:paranoid }
		add_trait = paranoid
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:trusting }
		add_trait = trusting
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:compassionate }
		add_trait = compassionate
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:callous }
		add_trait = callous
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:sadistic }
		add_trait = sadistic
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:stubborn }
		add_trait = stubborn
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:fickle }
		add_trait = fickle
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:vengeful }
		add_trait = vengeful
	}
	else_if = {
		limit = { scope:carn_new_trait = flag:forgiving }
		add_trait = forgiving
	}

	carn_clear_personality_replacement_effect = yes
}

#####################################################################################
# carn_clear_personality_replacement_effect
# Run in the scope of the character whose personality you (don't) want to replace.
#####################################################################################

carn_clear_personality_replacement_effect = {
	clear_saved_scope = carn_replaced_trait
	clear_saved_scope = carn_new_trait
	clear_variable_list = carn_personality_replacement_excluded_traits
}


code:
# carn_seed_prostitution_doctrines_effect
# if game rule is off, removes prostitution doctrines from all faiths
# otherwise, seeds a faith's religious doctrines for prostitution
carn_seed_prostitution_doctrines_effect = {
	if = {
		limit = { has_game_rule = carn_prostitution_content_disabled }
		if = {
			limit = { has_doctrine = carn_doctrine_prostitution_crime }
			remove_doctrine = carn_doctrine_prostitution_crime
		}
		if = {
			limit = { has_doctrine = carn_doctrine_prostitution_shunned }
			remove_doctrine = carn_doctrine_prostitution_shunned
		}
		if = {
			limit = { has_doctrine = carn_doctrine_prostitution_accepted }
			remove_doctrine = carn_doctrine_prostitution_accepted
		}
	}
	else = {
		if = {
			limit = {
				NOR = {
					has_doctrine = carn_doctrine_prostitution_crime
					has_doctrine = carn_doctrine_prostitution_shunned
					has_doctrine = carn_doctrine_prostitution_accepted
				}
			}
			if = {
				limit = {
					has_game_rule = carn_prostitution_default_religious_doctrine_shunned
				}
				add_doctrine = carn_doctrine_prostitution_shunned
			}
			else_if = {
				limit = {
					has_game_rule = carn_prostitution_default_religious_doctrine_accepted
				}
				add_doctrine = carn_doctrine_prostitution_accepted
			}
			else = {
				add_doctrine = carn_doctrine_prostitution_crime
			}
		}
	}
}


code:
# carn_start_working_as_prostitute_effect
# carn_stop_working_as_prostitute_effect
# carn_update_working_as_prostitute_modifier_effect
# carn_upgrade_lifestyle_prostitute_effect

carn_start_working_as_prostitute_effect = {
	if = {
		limit = { has_trait = celibate }
		remove_trait = celibate
	}
	if = {
		limit = { NOT = { has_trait = lifestyle_prostitute } }
		hidden_effect = { add_trait = lifestyle_prostitute }
	}
	carn_update_working_as_prostitute_modifier_effect = yes
	trigger_event = { on_action = carn_on_start_working_as_prostitute }
}

carn_stop_working_as_prostitute_effect = {
	if = {
		limit = { has_character_modifier = carn_working_as_prostitute_1_modifier }
		remove_character_modifier = carn_working_as_prostitute_1_modifier
	}
	if = {
		limit = { has_character_modifier = carn_working_as_prostitute_2_modifier }
		remove_character_modifier = carn_working_as_prostitute_2_modifier
	}
	if = {
		limit = { has_character_modifier = carn_working_as_prostitute_3_modifier }
		remove_character_modifier = carn_working_as_prostitute_3_modifier
	}
	trigger_event = { on_action = carn_on_stop_working_as_prostitute }
}

carn_update_working_as_prostitute_modifier_effect = {
	if = {
		limit = { has_character_modifier = carn_working_as_prostitute_1_modifier }
		remove_character_modifier = carn_working_as_prostitute_1_modifier
	}
	if = {
		limit = { has_character_modifier = carn_working_as_prostitute_2_modifier }
		remove_character_modifier = carn_working_as_prostitute_2_modifier
	}
	if = {
		limit = { has_character_modifier = carn_working_as_prostitute_3_modifier }
		remove_character_modifier = carn_working_as_prostitute_3_modifier
	}
	if = {
		limit = {
			has_trait_xp = {
				trait = lifestyle_prostitute
				value >= 100
			}
		}
		add_character_modifier = {
			modifier = carn_working_as_prostitute_3_modifier
		}
	}
	else_if = {
		limit = {
			has_trait_xp = {
				trait = lifestyle_prostitute
				value >= 50
			}
		}
		add_character_modifier = {
			modifier = carn_working_as_prostitute_2_modifier
		}
	}
	else = {
		add_character_modifier = {
			modifier = carn_working_as_prostitute_1_modifier
		}
	}
}

carn_upgrade_lifestyle_prostitute_effect = {
	if = {
		limit = { NOT = { has_trait = lifestyle_prostitute } }
		add_trait = lifestyle_prostitute
	}
	add_trait_xp = {
		trait = lifestyle_prostitute
		value = 50
	}
	hidden_effect = {
		if = {
			limit = { carn_is_working_as_prostitute_trigger = yes }
			carn_update_working_as_prostitute_modifier_effect = yes
		}
	}
}


code:
######################################################################
# RAPE EFFECTS
# by Cheri
#
# - `carn_rape_effect_v2`
# - `carn_rape_opinion_effects_effect`
# - `carn_rape_victim_stress_effect`
#
# These effects are meant for modders to have consistent outcomes for rape.
#
# `carn_rape_effect_v2` will apply all relevant consequences, we strongly recommend that you use this effect in any rape event/decision
# Requires VICTIM (character)
#
# `carn_rape_opinion_effects_effect` and `carn_rape_victim_stress_effect` are triggered by `carn_rape_effect`, however they are separate so that they can be shown as tooltips in noncon sub scenes
######################################################################

# carn_rape_effect_v2
# requires VICTIM (character)

carn_rape_effect_v2 = {
	save_scope_as = carn_rape_rapist
	$VICTIM$ = { save_scope_as = carn_rape_victim }

	scope:carn_rape_rapist = {

		### STRESS ###
		if = {
			limit = {
				is_attracted_to_gender_of = scope:carn_rape_victim
			}
			if = {
				limit = { has_relation_rival = scope:carn_rape_victim }
				stress_impact = {
					base = 0
					chaste = minor_stress_impact_gain
					sadistic = major_stress_impact_loss
					vengeful = major_stress_impact_loss
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
			else = {
				stress_impact = {
					base = 0
					chaste = minor_stress_impact_gain
					sadistic = minor_stress_impact_loss
					compassionate = massive_stress_impact_gain
					just = medium_stress_impact_gain
					forgiving = medium_stress_impact_gain
					generous = medium_stress_impact_gain
					trusting = minor_stress_impact_gain
					content = minor_stress_impact_gain
				}
			}
		}
		else = {
			custom_tooltip = carn_rape_effect_not_attracted_to_warning_tt
			stress_impact = {
				base = major_stress_impact_gain
				chaste = minor_stress_impact_gain
				sadistic = minor_stress_impact_loss
				compassionate = massive_stress_impact_gain
				just = medium_stress_impact_gain
				forgiving = medium_stress_impact_gain
				generous = medium_stress_impact_gain
				trusting = minor_stress_impact_gain
				content = minor_stress_impact_gain
			}
		}

		### DREAD (same effects as torturing)
		if = {
			limit = {
				scope:carn_rape_victim = {
					OR = {
						is_powerful_vassal_of = scope:carn_rape_rapist # Is your powerful vassal
						AND = { # Is an Emperor
							exists = primary_title
							primary_title.tier >= tier_empire
						}
						target_is_vassal_or_below = scope:carn_rape_rapist # Your liege/s
						scope:carn_rape_rapist.faith.religious_head = scope:carn_rape_victim # Your head of faith
					}
				}
			}
			add_dread = torture_interaction_massive_dread_gain
		}
		else_if = {
			limit = {
				scope:carn_rape_victim = {
					OR = {
						AND = { # Is your vassal, and higher than Baron
							is_vassal_of = scope:carn_rape_rapist
							primary_title.tier > tier_barony
						}
						AND = { # Is a King
							exists = primary_title
							primary_title.tier >= tier_kingdom
						}
					}
				}
			}
			add_dread = torture_interaction_major_dread_gain
		}
		else_if = {
			limit = {
				scope:carn_rape_victim = {
					OR = {
						scope:carn_rape_rapist = { # Torturing close family of your vassals is dreadful...
							any_vassal = {
								is_close_family_of = scope:carn_rape_victim
							}
						}
						scope:carn_rape_rapist = { # Torturing close family of your liege/s is the same...
							any_liege_or_above = {
								is_close_family_of = scope:carn_rape_victim
							}
						}
						AND = { # Peer Vassals
							exists = primary_title
							primary_title.tier > tier_barony
							exists = liege
							liege = scope:carn_rape_rapist.liege
						}
						AND = { # Is a Duke
							exists = primary_title
							primary_title.tier >= tier_duchy
						}
					}
				}
			}
			add_dread = torture_interaction_medium_dread_gain
		}
		else_if = {
			limit = {
				scope:carn_rape_victim = {
					OR = {
						is_spouse_of = scope:carn_rape_rapist # Your own spouse
						is_close_or_extended_family_of = scope:carn_rape_rapist # Your own family
						AND = {
							exists = primary_title
							primary_title.tier >= tier_county # Is a Count
						}
						scope:carn_rape_rapist = { # Torturing extended family of your vassals is dreadful...
							any_vassal = {
								is_extended_family_of = scope:carn_rape_victim
							}
						}
						scope:carn_rape_rapist = { # Torturing extended family of your liege/s is the same...
							any_liege_or_above = {
								is_extended_family_of = scope:carn_rape_victim
							}
						}
					}
				}
			}
			add_dread = torture_interaction_minor_dread_gain
		}

		carn_rape_opinion_effects_effect = yes
		carn_rape_victim_stress_effect = yes

		###CHURCH OPINION & PIETY###
		if = {
        	limit = {
            	NOT = { has_perk = divine_retribution_perk }
            }
            add_piety = medium_piety_loss

			if = {
				limit = {
					any_learning_councillor = {
						opinion = {
							target = scope:carn_rape_victim
							value >= -50
						}
					}
				}
				random_learning_councillor = {
					add_opinion = {
						modifier = impious_opinion
						opinion = -20
						target = scope:carn_rape_rapist
					}
				}
			}
        }
	}
}

carn_rape_opinion_effects_effect = {
	scope:carn_rape_victim = {
		if = {
			limit = {
				NOT = {
					carn_has_fetish_trigger = {
						FETISH = being_raped
					}
				}
			}
			add_opinion = {
				modifier = carn_raped_me
				target = scope:carn_rape_rapist
			}
		}
		every_close_family_member = {
			limit = { NOT = { this = scope:carn_rape_rapist } }
			add_to_list = family_of_tortured
		}
		every_in_list = {
			list = family_of_tortured
			add_opinion = {
				target = scope:carn_rape_rapist
				modifier = carn_raped_family_member
			}
		}
		every_relation = {
			type = friend
			limit = { NOT = { this = scope:carn_rape_rapist } }
			add_to_list = friends_of_tortured
		}
		every_in_list = {
			list = friends_of_tortured
			add_opinion = {
				target = scope:carn_rape_rapist
				modifier = carn_raped_my_friend
			}
		}
		every_spouse = {
			limit = { NOT = { this = scope:carn_rape_rapist } }
			add_to_list = lovers_of_tortured
		}
		every_relation = {
			type = lover
			limit = { NOT = { this = scope:carn_rape_rapist } }
			add_to_list = lovers_of_tortured
		}
		if = {
			limit = {
				exists = concubinist
				concubinist = {
					NOT = { this = scope:carn_rape_rapist }
				}
			}
			concubinist = {
				add_to_list = lovers_of_tortured
			}
		}
		every_in_list = {
			list = lovers_of_tortured
			add_opinion = {
				target = scope:carn_rape_rapist
				modifier = carn_raped_my_lover
			}
		}
	}
}

carn_rape_victim_stress_effect = {
	scope:carn_rape_victim = {
		add_character_modifier = {
			modifier = carn_recently_raped
			years = 5
		}
		if = {
			limit = {
				NOT = {
					carn_has_fetish_trigger = {
						FETISH = being_raped
					}
				}
			}
			if = {
				limit = {
					NOR = {
						has_trait = craven
						has_trait = chaste
						has_trait = celibate
						has_trait = brave
					}
				}
				add_stress = massive_stress_impact_gain
			}
			else = {
				stress_impact = {
					base = 0
					craven = monumental_stress_gain
					chaste = monumental_stress_gain
					celibate = monumental_stress_gain
					brave = medium_stress_impact_gain
				}
			}
			random = {
				chance = 50
				add_trait_force_tooltip = depressed_1
			}
		}
	}
}


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

######################################################################
# RAPE EFFECTS
# by Cheri
#
# - `carn_rape_effect`
# - `carn_rape_opinion_effects_effect`
# - `carn_rape_victim_stress_effect`
#
# These effects are meant for modders to have consistent outcomes for rape.
#
# `carn_rape_effect` will apply all relevant consequences, we strongly recommend that you use this effect in any rape event/decision
# Requires RAPIST (character), VICTIM (character), TRIGGER_SEX_SCENE (boolean)
# Will trigger a noncon sex scene if TRIGGER_SEX_SCENE is yes
#
# `carn_rape_opinion_effects_effect` and `carn_rape_victim_stress_effect` are triggered by `carn_rape_effect`, however they are separate so that they can be shown as tooltips in noncon sub scenes
######################################################################

# carn_rape_effect
# requires RAPIST (character), VICTIM (character), TRIGGER_SEX_SCENE (boolean)
# Will trigger a noncon sex scene if TRIGGER_SEX_SCENE is yes

carn_rape_effect = {
	$RAPIST$ = { save_scope_as = carn_rape_rapist }
	$VICTIM$ = { save_scope_as = carn_rape_victim }

	if = {
		limit = { $TRIGGER_SEX_SCENE$ = yes }
		show_as_tooltip = {
			carn_had_sex_with_effect = {
				CHARACTER_1 = scope:carn_rape_rapist
				CHARACTER_2 = scope:carn_rape_victim
				C1_PREGNANCY_CHANCE = pregnancy_chance
				C2_PREGNANCY_CHANCE = pregnancy_chance
				STRESS_EFFECTS = no
				DRAMA = yes
			}
		}
		if = {
			limit = { scope:carn_rape_rapist = { is_ai = no } }
			carn_sex_scene_request_noncon = yes
			carn_sex_scene_request_dom_player = yes
			carn_sex_scene_effect = {
				PLAYER = scope:carn_rape_rapist
				TARGET = scope:carn_rape_victim
				STRESS_EFFECTS = no
				DRAMA = yes
			}
		}
		if = {
			limit = { scope:carn_rape_victim = { is_ai = no } }
			carn_sex_scene_request_noncon = yes
			carn_sex_scene_request_sub_player = yes
			carn_sex_scene_effect = {
				PLAYER = scope:carn_rape_victim
				TARGET = scope:carn_rape_rapist
				STRESS_EFFECTS = no
				DRAMA = yes
			}
		}
	}

	$RAPIST$ = {
		carn_rape_effect_v2 = {
			VICTIM = $VICTIM$
		}
	}
}


code:
carn_give_deviant_secret_or_trait_no_fetish_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
		}
	}
}


code:
#################################################################################
# carn_sex_scene_effect_v2
#################################################################################
#
# carn_sex_scene_effect_v2 is a 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_v2 in the player scope with the following arguments:
#
# * PARTNER is the character that PLAYER is having sex with.
#
# In addition, you can set the same options as for carn_had_sex_with_effect_v2:
#
# carn_sex_scene_no_pregnancy_effect = yes for no pregnancy check, default is to check
# carn_sex_scene_no_stress_effect = yes for no stress check, default is to check
# carn_sex_scene_no_drama_effect = yes for no drama check, default is to check
# carn_sex_scene_no_memory_effect = yes for no memory check, default is to check
# carn_sex_scene_no_std_effect = yes for no std check, default is to check
#
# This effect triggers the carn_sex_scene on_action with a list of random_events. This list can be modified
# by mods by adding more events. A single random event from this list is fired if allowed by its trigger.
#
# The sex scene events themselves should check in their triggers if the passed sex scene flags
# are applicable to them, i.e. a consensual lesbian sex event should check that both participants are female
# and carn_sex_scene_is_consensual_trigger = yes.
#
# If no other event is allowed to fire by its trigger, the default Carnalitas sex scene event will be fired.
#
# An example of using carn_sex_scene_effect_v2 to trigger a dominant rape scene without drama or memories:
#
# effect = {
#	carn_sex_scene_no_drama_effect = yes
#	carn_sex_scene_no_memory_effect = yes
#
#	carn_sex_scene_character_is_giving_player_effect = yes
#	carn_sex_scene_character_is_dom_player_effect = yes
#	carn_sex_scene_is_vaginal_effect = yes
#	carn_sex_scene_is_cum_inside_effect = yes
#	carn_sex_scene_is_noncon_effect = yes
#
# 	carn_sex_scene_effect_v2 = {
#		PARTNER = scope:partner
# 	}
# }
#
# Note that you should not clean any of the flags after executing carn_sex_scene_effect_v2, because this will
# cause them to be cleaned before the event had actually fired. Instead, you should clean them in the
# `after` or `option` sections of the sex scene events themselves.
#

carn_sex_scene_effect_v2 = {
	save_scope_as = carn_sex_player
	$PARTNER$ = {
		save_scope_as = carn_sex_partner
		save_scope_as = carn_sex_target
	}

	# Save additional scope values for backward compatibility
	if = {
		limit = { carn_sex_scene_no_stress_trigger = yes }
		save_scope_value_as = { name = carn_sex_stress_effects value = no }
	}
	else = {
		save_scope_value_as = { name = carn_sex_stress_effects value = yes }
	}
	if = {
		limit = { carn_sex_scene_no_drama_trigger = yes }
		save_scope_value_as = { name = carn_sex_drama value = no }
	}
	else = {
		save_scope_value_as = { name = carn_sex_drama value = yes }
	}

	# Set this additional scope value to prevent carn_had_sex_with_effect
	# from cleaning variables too early
	save_scope_value_as = { name = carn_sex_scene value = yes }

	# Trigger carn_sex_scene instead of carn_sex_scene_on_action for backward compatibility
	trigger_event = {
		on_action = carn_sex_scene
	}
}

carn_sex_scene_no_pregnancy_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_option_flag_list
		target = flag:no_pregnancy
	}
	save_scope_as = carn_sex_no_pregnancy
}

carn_sex_scene_no_stress_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_option_flag_list
		target = flag:no_stress
	}
	save_scope_as = carn_sex_no_stress
}

carn_sex_scene_no_drama_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_option_flag_list
		target = flag:no_drama
	}
	save_scope_as = carn_sex_no_drama
}

carn_sex_scene_no_memory_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_option_flag_list
		target = flag:no_memory
	}
	save_scope_as = carn_sex_no_memory
}

carn_sex_scene_no_std_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_option_flag_list
		target = flag:no_std
	}
	save_scope_as = carn_sex_no_std
}

carn_transfer_sex_scene_flag_from_partner = {
	every_in_list = {
		variable = $PARTNER$.var:carn_sex_scene_flag_list
		add_to_variable_list = carn_sex_scene_flag_list
	}
	$PARTNER$ = {carn_sex_scene_clean_up_flags_effect = yes}
}

# 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_effect
# carn_sex_scene_character_is_receiving_player_effect
# carn_sex_scene_character_is_dom_player_effect
# carn_sex_scene_character_is_sub_player_effect
# carn_sex_scene_is_vaginal_effect
# carn_sex_scene_is_anal_effect
# carn_sex_scene_is_oral_effect
# carn_sex_scene_is_handjob_effect
# carn_sex_scene_is_masturbation_effect
# carn_sex_scene_is_orgy_effect
# carn_sex_scene_is_cum_inside_effect
# carn_sex_scene_is_cum_outside_effect
# carn_sex_scene_is_consensual_effect
# carn_sex_scene_is_noncon_effect
# carn_sex_scene_is_dubcon_effect
# carn_sex_scene_is_painful_effect
# carn_sex_scene_is_bdsm_effect
# carn_sex_scene_is_bestiality_effect
# carn_sex_scene_is_petplay_effect
# carn_sex_scene_is_bondage_effect
# carn_sex_scene_is_toy_effect
# carn_sex_scene_is_watersports_effect
# carn_sex_scene_is_scat_effect
# carn_sex_scene_is_gore_effect
#

carn_sex_scene_character_is_giving_player_effect = {
	# can't be giving and receiving at the same time
	if = {
		limit = {
			carn_sex_scene_character_is_receiving_player_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_character_flag_list
			target = flag:receiving_player
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:giving_player
	}
}

carn_sex_scene_character_is_receiving_player_effect = {
	# can't be giving and receiving at the same time
	if = {
		limit = {
			carn_sex_scene_character_is_giving_player_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_character_flag_list
			target = flag:giving_player
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:receiving_player
	}
}

carn_sex_scene_character_is_dom_player_effect = {
	# can't be dom and sub at the same time
	if = {
		limit = {
			carn_sex_scene_character_is_sub_player_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_character_flag_list
			target = flag:sub_player
		}
	}
	#dom will always take charge
	if = {
		limit = {
			carn_sex_scene_character_is_receiving_player_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_character_flag_list
			target = flag:receiving_player
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:dom_player
	}
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:giving_player
	}
}

carn_sex_scene_character_is_sub_player_effect = {
	# can't be dom and sub at the same time
	if = {
		limit = {
			carn_sex_scene_character_is_dom_player_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_character_flag_list
			target = flag:dom_player
		}
	}
	# sub can't take charge
	if = {
		limit = {
			carn_sex_scene_character_is_giving_player_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_character_flag_list
			target = flag:giving_player
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:sub_player
	}
	add_to_variable_list = {
		name = carn_sex_scene_character_flag_list
		target = flag:receiving_player
	}
}

carn_sex_scene_is_oral_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:oral
	}
}

carn_sex_scene_is_vaginal_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:vaginal
	}
}

carn_sex_scene_is_anal_effect = {
	if = {
		limit = { has_game_rule = carn_content_anal_enabled }
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:anal
		}
	}
}

carn_sex_scene_is_handjob_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:handjob
	}
}

carn_sex_scene_is_masturbation_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:masturbation
	}
}

carn_sex_scene_is_orgy_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:orgy
	}
}

carn_sex_scene_is_cum_inside_effect = {
	if = {
		limit = {
			carn_sex_scene_is_cum_outside_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_flag_list
			target = flag:cum_outside
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:cum_inside
	}
}

carn_sex_scene_is_cum_outside_effect = {
	if = {
		limit = {
			carn_sex_scene_is_cum_inside_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_flag_list
			target = flag:cum_inside
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:cum_outside
	}
}

carn_sex_scene_is_consensual_effect = {
	if = {
		limit = {
			carn_sex_scene_is_noncon_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_flag_list
			target = flag:noncon
		}
	}
	if = {
		limit = {
			carn_sex_scene_is_dubcon_trigger = yes
		}
		remove_list_variable = {
			name = carn_sex_scene_flag_list
			target = flag:dubcon
		}
	}
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:consensual
	}
}

carn_sex_scene_is_noncon_effect = {
	if = {
		limit = { has_game_rule = carn_content_consent_noncon }
		if = {
			limit = {
				carn_sex_scene_is_consensual_trigger = yes
			}
			remove_list_variable = {
				name = carn_sex_scene_flag_list
				target = flag:consensual
			}
		}
		if = {
			limit = {
				carn_sex_scene_is_dubcon_trigger = yes
			}
			remove_list_variable = {
				name = carn_sex_scene_flag_list
				target = flag:dubcon
			}
		}
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:noncon
		}
	}
}

carn_sex_scene_is_dubcon_effect = {
	if = {
		limit = {
			NOT = { has_game_rule = carn_content_consent_always }
		}
		if = {
			limit = {
				carn_sex_scene_is_consensual_trigger = yes
			}
			remove_list_variable = {
				name = carn_sex_scene_flag_list
				target = flag:consensual
			}
		}
		if = {
			limit = {
				carn_sex_scene_is_noncon_trigger = yes
			}
			remove_list_variable = {
				name = carn_sex_scene_flag_list
				target = flag:noncon
			}
		}
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:dubcon
		}
	}
}

carn_sex_scene_is_painful_effect = {
	if = {
		limit = { has_game_rule = carn_content_painful_enabled }
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:painful
		}
	}
}

carn_sex_scene_is_bdsm_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:bdsm
	}
}

carn_sex_scene_is_bestiality_effect = {
	if = {
		limit = { has_game_rule = carn_content_bestiality_enabled }
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:bestiality
		}
	}
}

carn_sex_scene_is_petplay_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:petplay
	}
}

carn_sex_scene_is_bondage_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:bondage
	}
}

carn_sex_scene_is_toy_effect = {
	add_to_variable_list = {
		name = carn_sex_scene_flag_list
		target = flag:toy
	}
}

carn_sex_scene_is_watersports_effect = {
	if = {
		limit = { has_game_rule = carn_content_watersports_enabled }
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:watersports
		}
	}
}

carn_sex_scene_is_scat_effect = {
	if = {
		limit = { has_game_rule = carn_content_scat_enabled }
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:scat
		}
	}
}

carn_sex_scene_is_gore_effect = {
	if = {
		limit = { has_game_rule = carn_content_gore_enabled }
		add_to_variable_list = {
			name = carn_sex_scene_flag_list
			target = flag:gore
		}
	}
}

# These effects are meant for streamlining sex events
carn_undress_character_effect = {
	if = {
		limit = {
			NOT = { has_character_flag = is_naked }
		}
		add_character_flag = {
			flag = is_naked
			days = 180 # So character won't stay naked forever when something goes wrong
		}
	}
	else = {
		add_character_flag = {
			flag = character_was_already_naked
			days = 1
		}
	}
}

carn_dress_character_effect = {
	if = {
		limit = {
			NOT = { has_character_flag = character_was_already_naked }
		}
		remove_character_flag = is_naked
	}
	else = {
		remove_character_flag = character_was_already_naked
	}
}

carn_make_root_and_sex_partner_naked_for_this_event_effect = {
	if = {
		limit = { is_ai = no }
		carn_undress_character_effect = yes
		scope:carn_sex_partner = {
			carn_undress_character_effect = yes
		}
	}
}

carn_make_root_and_sex_partner_no_longer_naked_effect = {
	carn_dress_character_effect = yes
	scope:carn_sex_partner = {
		carn_dress_character_effect = yes
	}
}

carn_sex_scene_clean_up_flags_effect = {
	clear_variable_list = carn_sex_scene_flag_list
	clear_variable_list = carn_sex_scene_excluded_flag_list
	clear_variable_list = carn_sex_scene_option_flag_list

	clear_saved_scope = carn_sex_no_pregnancy
	clear_saved_scope = carn_sex_no_stress
	clear_saved_scope = carn_sex_no_drama
	clear_saved_scope = carn_sex_no_memory
	clear_saved_scope = carn_sex_no_std
}

carn_sex_scene_clean_up_character_flags_effect = {
	clear_variable_list = carn_sex_scene_character_flag_list
	clear_variable_list = carn_sex_scene_character_excluded_flag_list
}