﻿#health effects list#

###################
# DISEASE EFFECTS #
###################

### GENERAL CONTRACT/RECOVER EFFECTS ###
# contract_disease_effect 			- Adds disease trait, sends treatment and notification events etc. NO contraction event. Needs argument DISEASE (trait name) and TREATMENT_EVENT (yes/no).
# contract_disease_notify_effect	- Sends a "contracted disease" event in 5-15 days. The event checks if the disease is valid and runs contract_disease_effect to apply the disease trait. Needs argument DISEASE (trait name).
# recover_from_disease_effect 		- Checks if has disease, removes it and sets any immunity, and sends appropriate notifications to other characters. Needs argument DISEASE (trait name). Does not send event to character who contracts disease.
#recover_from_disease_notify_effect	- Checks if has disease, removes it and sets any immunity in an event for the character in question, and sends appropriate notifications to other characters. Needs argument DISEASE (trait name).

### STD EFFECTS ###
# contract_lovers_pox_from 	- sends the scoped character "contracted lover's pox" event if argument PARTNER has lover's pox. Uses PARTNER in event.
# contract_great_pox_from	- sends the scoped character "contracted early lover's pox" event if argument PARTNER has great pox. Uses PARTNER in event.
# risk_of_std_from_effect 	- 50% chance of running contract_lovers_pox_from effect and 30% chance of running contract_great_pox_from effect

### CONTAGIOUS DISEASE ###
# create_contagion_list_effect	- Creates a list of characters who might contract contagious disease (smallpox/plague) from scope

### SIDE EFFECTS ###
# epilepsy_fever_risk_effect
# epilepsy_brain_trauma_risk_effect



###############################
# GAIN/INCREASE WOUND EFFECTS #
###############################

# increase_wounds_no_death_effect 	- increases wound level without killing
# increase_wounds_effect 			- increases wound level with chance of death
# maimed_in_battle_effect


########################################
#EFFECTS FOR WEIGHT GAIN/LOSS			#
########################################

#target_weight_modifier_effect		- Increases character variable that's used in the weight balancing


########################################
#EFFECTS FOR COURT PHYSICIAN TREATMENT #
########################################

### COURT PHYSICIAN MANAGEMENT ###
# set_court_physician_effect
# fire_court_physician_effect
# save_court_physician_as
# invalidate_physician_effect

### COURT PHYSICIAN RANK UP ###
#physician_level_up_chance_effect
#mystic_level_up_chance_effect
#physician_rank_up_tooltip_effect

### DISEASE TREATMENT OPTIONS ###
# safe_disease_treatment_effect
# risky_disease_treatment_effect
# mystic_disease_treatment_effect
# no_disease_treatment_effect
# find_court_physician_effect
# deny_disease_treatment_effect

### WOUND TREATMENT OPTIONS ###
# safe_wound_treatment_effect
# risky_wound_treatment_effect

### DISEASE TREATMENT OUTCOMES ###
# set_worst_disease_effect
# add_disease_treatment_modifier_effect
# disease_treatment_results_effect
# disease_treatment_result_tooltip_effect
# remove_disease_treatment_effect

### WOUND TREATMENT OUTCOMES ###
# add_wound_treatment_modifier_effect
# wound_treatment_result_tooltip_effect
# wound_treatment_results_effect

### DISEASE TREATMENT LOGIC ###
# save_health_court_owner_effect
# pick_own_disease_treatment_effect
# decide_who_picks_disease_treatment_effect
# liege_picks_treatment_effect

### WOUND LOGIC ###
# pick_own_wound_treatment_effect
# decide_who_picks_wound_treatment_effect

### FAILED TREAMENT EFFECTS ###
# add_failed_treatment_of_me_opinions_effect
# add_failed_treatment_of_kin_opinions_effect
# downgrade_failed_treatment_of_me_opinions_effect
# downgrade_failed_treatment_of_kin_opinions_effect
# execute_physician_effect
# imprison_physician_effect
# chastise_physician_effect
# forgive_physician_effect


### DISEASE MESSAGES ###
# inform_liege_about_disease_treatment_effect
# activate_outbreak_story_effect

### WOUND MESSAGES ###
# inform_liege_about_wound_treatment_effect


######################
#EFFECTS FOR SUICIDE #
######################
# committed_suicide_effect
# attempted_suicide_effect


##############################################################################################
# LIST ENDS HERE


####################
# DISEASE EFFECTS  #
####################

#Adds the disease in question and sends notifications to everyone who should know. Checks validity and sends treatment event. Needs the arguments DISEASE (trait name, only exception is early_great_pox - it should be added as great_pox and then the effect will figure out whether the character should have early_great_pox first) and TREATMENT_EVENT (yes/no). Does NOT send an event to the character who gets the disease.
contract_disease_effect = {
	if = { #Is the disease valid?
		limit = { can_contract_disease_trigger = { DISEASE = $DISEASE$ } }

		hidden_effect = {
			#SET SCOPES
			save_scope_as = sick_character

			save_scope_value_as = {
				name = disease_type
				value = flag:$DISEASE$
			}

			save_temporary_scope_value_as = {
				name = treatment_event
				value = flag:$TREATMENT_EVENT$
			}

			if = {
				limit = { #Should I get early great pox instead of great pox?
					scope:disease_type = flag:great_pox
					NOR = {
						has_trait = lovers_pox
						has_trait = early_great_pox
					}
				}
				save_scope_value_as = {
					name = disease_type
					value = flag:early_great_pox
				}
			}

			#Data collection
			disease_data_save_contraction_effect = { DISEASE = $DISEASE$ }


			#TREATMENT EVENT
			if = {
				limit = {
					scope:treatment_event = flag:yes
				}

				trigger_event = {
					id = health.3100
					days = 5
				}
			}
			else_if = {
				limit = { scope:treatment_event = flag:no } #This is just here to stop errors
			}
		}


		#NON-CONTAGIOUS DISEASES
		if = {
			limit = {
				OR = {
					scope:disease_type = flag:ill
					scope:disease_type = flag:pneumonic
					scope:disease_type = flag:gout_ridden
					scope:disease_type = flag:leper
					scope:disease_type = flag:cancer
					scope:disease_type = flag:ergotism
				}
			}

			if = { #Removes ill if progressing to pneumonia
				limit = {
					scope:disease_type = flag:pneumonic
					has_trait = ill
				}
				remove_trait = ill
			}

			add_trait_force_tooltip = $DISEASE$
		}
		
		#CONTAGIOUS DISEASES
		if = {
			limit = {
				OR = {
					scope:disease_type = flag:smallpox
					scope:disease_type = flag:measles
					scope:disease_type = flag:dysentery
					scope:disease_type = flag:bubonic_plague
					scope:disease_type = flag:typhus
					scope:disease_type = flag:consumption
				}
			}

			add_trait_force_tooltip = $DISEASE$
		}

		#STD DISEASES
		else_if = { #Lover's pox
			limit = { scope:disease_type = flag:lovers_pox }
			add_trait_force_tooltip = lovers_pox

			hidden_effect = {
				#Trigger regular contagion checks
				trigger_event = {
					id = health.1200
					days = { 60 1000 } #This first one can happen quite fast, the following checks are delayed 250-10000 days depending on traits
				}
			}
		}
		else_if = { #Early great pox
			limit = { scope:disease_type = flag:early_great_pox }
			add_trait_force_tooltip = early_great_pox
			
			hidden_effect = {
				trigger_event = {
					id = health.1013 #Reveals the true disease
					days = { 90 150 }
				}
			}
		}
		else_if = { #Great pox
			limit = {  scope:disease_type = flag:great_pox }

			hidden_effect = {
				remove_trait = lovers_pox #If you get Great Pox and already have lover's pox, we pretend that lover's pox was the first symptoms
				remove_trait = early_great_pox
			}
			add_trait_force_tooltip = great_pox

			hidden_effect = {
				#Trigger regular contagion checks
				trigger_event = {
					id = health.1201
					days = { 250 1500 } #This first one can happen quite fast, the following checks are delayed 350-10000 days depending on traits
				}
			}
		}

		#RECOVERY
		if = { #Ill
			limit = { scope:disease_type = flag:ill }
			trigger_event = {
				id = health.1101
				days = { ill_recovery_min ill_recovery_max }
			}
		}
		else_if = { #Pneumonic
			limit = { scope:disease_type = flag:pneumonic }
			trigger_event = {
				id = health.1102
				days = { pneumonic_recovery_min pneumonic_recovery_max }
			}
		}
		else_if = { #Gout
			limit = { scope:disease_type = flag:gout_ridden }
			random = {
				chance = 25
				modifier = {
					has_trait = gluttonous
					add = -15
				}
				modifier = {
					has_trait = temperate
					add = 15
				}
				trigger_event = {
					id = health.1103
					days = { gout_ridden_recovery_min gout_ridden_recovery_max } #1 to 30 years
				}
			}
		}
		else_if = { #Typhus
			limit = { scope:disease_type = flag:typhus }
			trigger_event = {
				id = health.1105
				days = { 45 150 }
			}
		}
		else_if = { #Consumption
			limit = { scope:disease_type = flag:consumption }
			trigger_event = {
				id = health.1106
				days = { 365 2190 } #1 to 6 years
			}
		}
		else_if = { #Cancer
			limit = { scope:disease_type = flag:cancer }
			random = {
				chance = 1
				trigger_event = {
					id = health.1107
					days = { 365 3650 } #1 to 10 years
				}
			}
		}
		else_if = { #Great pox
			limit = {
				OR = {
					scope:disease_type = flag:early_great_pox
					scope:disease_type = flag:great_pox
				}
			}
			trigger_event = {
				id = health.1109
				days = { 730 5475 } #2 to 15 years (note that early pox progresses into great pox in 60-150 days and great pox leads to lunacy after 5 to 15 years)
			}
		}
		else_if = { #Smallpox
			limit = { scope:disease_type = flag:smallpox }
			trigger_event = {
				id = health.1110
				days = { smallpox_min_recovery_time smallpox_max_recovery_time }
			}
		}
		else_if = { #Bubonic Plague
			limit = { scope:disease_type = flag:bubonic_plague }
			trigger_event = {
				id = health.1111
				days = { bubonic_plague_min_recovery_time bubonic_plague_max_recovery_time }
			}
		}
		else_if = { #Measles
			limit = { scope:disease_type = flag:measles }
			trigger_event = {
				id = health.1112
				days = { measles_min_recovery_time measles_max_recovery_time }
			}
		}
		else_if = { #Dysentery
			limit = { scope:disease_type = flag:dysentery }
			trigger_event = {
				id = health.1113
				days = { dysentery_min_recovery_time dysentery_max_recovery_time }
			}
		}
		else_if = { #Ergotism
			limit = { scope:disease_type = flag:ergotism }
			trigger_event = {
				id = health.1114
				days = { ergotism_min_recovery_time ergotism_max_recovery_time }
			}
		}
		#No recovery for leper and lover's pox


		#EPILEPSY RISK
		if = {
			limit = { scope:disease_type = flag:ill }
			epilepsy_fever_risk_effect = { CHANCE = 1 }
		}
		else_if = {
			limit = {
				OR = {
					scope:disease_type = flag:pneumonic
					scope:disease_type = flag:typhus
					scope:disease_type = flag:consumption
					scope:disease_type = flag:measles
					scope:disease_type = flag:dysentery
					scope:disease_type = flag:smallpox
					scope:disease_type = flag:bubonic_plague
				}
			}
			epilepsy_fever_risk_effect = { CHANCE = 5 }
		}

		#NOTIFICATIONS: CONTAGIOUS DISEASE, FAMILY & SEX PARTNER STD, NOTIFICATIONS & LIEGE TREATMENT EVENTS

		#List creation:
		#Imprisoner/court owner if contagious
		if = {
			limit = {
				OR = {
					scope:disease_type = flag:smallpox
					scope:disease_type = flag:bubonic_plague
					scope:disease_type = flag:measles
					scope:disease_type = flag:dysentery
					scope:disease_type = flag:typhus
					scope:disease_type = flag:consumption
				}
				is_ruler = no
				has_health_court_owner_trigger = yes #Imprisoner or court owner
			}
			save_health_court_owner_effect = { SCOPE_NAME = health_court_owner }#Imprisoner or court owner

			scope:health_court_owner = {
				add_to_temporary_list = disase_notification_list
			}
		}
		#Sex partners if STD
		if = {
			limit = {
				OR = {
					scope:disease_type = flag:lovers_pox
					scope:disease_type = flag:early_great_pox
					scope:disease_type = flag:great_pox
				}
			}
			every_consort = {
				add_to_temporary_list = disase_notification_list
			}
			every_relation = {
				type = lover
				add_to_temporary_list = disase_notification_list
			}
		}
		#Family if the disease is somewhat dangerous
		if = {
			limit = {
				sick_enough_for_relative_to_care_trigger = yes
			}
			every_parent = {
				limit = {
					is_playable_character = yes
				}
				add_to_temporary_list = disase_notification_list
			}
			every_spouse = {
				limit = {
					is_playable_character = yes
				}
				add_to_temporary_list = disase_notification_list
			}
			every_heir_title = {
				limit = {
					exists = holder
				}
				holder = {
					if = {
						limit = {
							player_heir = scope:sick_character
						}
						add_to_temporary_list = disase_notification_list
					}
				}
			}
		}

		#Go through list and send notifications
		every_in_list = {
			list = disase_notification_list

			#Send a STD warning event
			if = {
				limit = {
					OR = {
						scope:disease_type = flag:lovers_pox
						scope:disease_type = flag:early_great_pox
						scope:disease_type = flag:great_pox
					}
					OR = {
						is_consort_of = scope:sick_character
						has_relation_lover = scope:sick_character
					}
				}
				scope:sick_character = { save_scope_as = std_partner }
				if = {
					limit = { scope:disease_type = flag:great_pox }
					trigger_event = {
						id = health.2002 #Partner has great pox
						days = { 7 14 }
					}
				}
				else = {
					trigger_event = {
						id = health.2001 #Partner has lover's pox/early great great pox
						days = { 7 14 }
					}
				}
			}
			#Send a notification/treatment event to family
			else_if = {
				limit = {
					OR = {
						#It's a player heir
						trigger_if = {
							limit = { exists = player_heir }
							player_heir = scope:sick_character
						}
						#Or a child/spouse who is really sick or this character has to pick their treatment
						AND = {
							is_spouse_of = scope:sick_character #we only send you your spouse and primary heir to avoid event spam with plagues
							OR = {
								#The sick character is dying
								health < death_chance_dying_health
								#This character gets to pick sick character's treatment
								trigger_if = {
									limit = { exists = scope:sick_character.liege }
									this = scope:sick_character.liege
									scope:sick_character = { liege_picks_treatment_trigger = yes }
								}
							}
						}
					}
				}
				trigger_event = {
					id = health.2201 #Important character is sick
					days = 3
				}
				#set a variable, so you are sure to get a follow-up
				if = {
					limit = { is_ai = no }
					scope:sick_character = {
						add_to_variable_list = {
							name = recovery_event_receivers
							target = prev
						}
					}
				}
			}
			else_if = {
				limit = {
					exists = scope:epidemic
					is_target_in_variable_list = {
						name = notified_of_epidemics
						target = scope:epidemic
					}
				}
				# Don't get spammed by courtiers and guests falling sick during epidemics
			}
			#Send a feed message
			else = {	
				send_interface_message = {
					type = msg_disease_contraction
					left_icon = scope:sick_character
					localization_values = {
						disease_trait = trait:$DISEASE$
						message_receiver = this
					}
					show_as_tooltip = {
						scope:sick_character = {	
							if = {
								limit = { scope:disease_type = flag:early_great_pox }
								add_trait_force_tooltip = early_great_pox
							}
							else = {
								add_trait_force_tooltip = $DISEASE$
							}
						}
					}
				}
				if = {
					limit = { is_ai = no }
					add_to_variable_list = {
						name = notified_of_epidemics
						target = scope:epidemic
					}
				}
			}
		}
	}
	hidden_effect = {
		if = {
			limit = {
				exists = scope:epidemic
			}
			give_epidemic_immunity = { EPIDEMIC = scope:epidemic }
			# Give appropriate memory
			if = {
				limit = {
					scope:disease_type ?= flag:bubonic_plague
				}
				create_character_memory = {
					type = ce1_contracted_black_death
				}
			}
			else = {
				create_character_memory = {
					type = ce1_contracted_epidemic
				}
				scope:new_memory = {
					if = {
						limit = {
							NOT = { exists = var:epidemic_infected }
						}
						set_variable = {
							name = epidemic_infected
							value = scope:epidemic.epidemic_type.epidemic_trait
						}
					}
				}
			}
		}
	}
}




#Triggers an event giving you the disease (if you meet the conditions) and notifying everyone who should know. Needs the arguments DISEASE trait name, only exception is early_great_pox - it should be added as great_pox and then the effect will figure out whether the character should have early_great_pox first)
contract_disease_notify_effect = {
	save_scope_value_as = {
		name = disease_type
		value = flag:$DISEASE$
	}
	
	#Ill
	if = {
		limit = { scope:disease_type = flag:ill }
		trigger_event = { id = health.1001 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:pneumonic }
		trigger_event = { id = health.1002 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:gout_ridden }
		trigger_event = { id = health.1003 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:leper }
		trigger_event = { id = health.1004 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:typhus }
		trigger_event = { id = health.1005 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:consumption }
		trigger_event = { id = health.1006 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:cancer }
		trigger_event = { id = health.1007 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:lovers_pox }
		trigger_event = { id = health.1008 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:great_pox }
		trigger_event = { id = health.1009 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:smallpox }
		trigger_event = { id = health.1010 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:measles }
		trigger_event = { id = health.1015 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:dysentery }
		trigger_event = { id = health.1016 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:ergotism }
		trigger_event = { id = health.1017 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:bubonic_plague }
		trigger_event = { id = health.1011 days = { 5 15 } }
	}
}

#Removes the disease in question and sends notifications to everyone who should know. Needs the arguments DISEASE (trait name, only exception is early_great_pox - it should be removed as great_pox). Does NOT send an event to the character who gets the disease.
recover_from_disease_effect = {
	hidden_effect = {
		save_scope_value_as = {
			name = disease_type
			value = flag:$DISEASE$
		}

		if = {
			limit = {
				has_trait = early_great_pox
				scope:disease_type = flag:great_pox
			}
			save_scope_value_as = {
				name = disease_type
				value = flag:early_great_pox
			}
		}	
	}

	if = { #They actually have the disease you want to remove
		limit = { has_trait = $DISEASE$ }

		save_scope_as = sick_character

		#Notifications (first, because some notifications need to check health which are changed when traits are removed)
		hidden_effect = {

			#IMPORTANT CHARACTER (add to list)
			if = {
				limit = { #The disease has to be somewhat dangerous
					OR = {
						health < death_chance_dying_health
						NOR = {
							scope:disease_type = flag:ill
							scope:disease_type = flag:gout_ridden
							scope:disease_type = flag:lovers_pox
							scope:disease_type = flag:early_great_pox
						}
					}
				}
				every_parent = {
					limit = { is_playable_character = yes }
					add_to_temporary_list = disase_notification_list
				}
				every_child = {
					limit = { is_playable_character = yes }
					add_to_temporary_list = disase_notification_list
				}
				every_spouse = {
					limit = {
						is_playable_character = yes
						NOT = { is_in_list = disase_notification_list }
					}
					add_to_temporary_list = disase_notification_list
				}
				every_heir_title = {
					limit = {
						exists = holder
					}
					holder = {
						if = {
							limit = {
								player_heir ?= scope:sick_character
								NOT = { is_in_list = disase_notification_list }
							}
							add_to_temporary_list = disase_notification_list
						}
					}
				}
			}

			#PARTNERS WHO WANT TO KNOW ABOUT STDS (add to list)
			if = {
				limit = {
					OR = {
						scope:disease_type = flag:great_pox
						scope:disease_type = flag:lovers_pox
						scope:disease_type = flag:early_great_pox
					}
				}
				every_relation = {
					type = lover
					limit = {
						is_playable_character = yes
						NOT = { is_in_list = disase_notification_list }
					}
					add_to_temporary_list = disase_notification_list
				}
				every_concubine = {
					limit = {
						is_playable_character = yes
						NOT = { is_in_list = disase_notification_list }
					}
					add_to_temporary_list = disase_notification_list
				}
			}

			#IMPOTANT CHARACTER NOTIFICATION EVENT
			every_parent = {
				limit = {
					inform_about_relative_recovery_trigger = yes
				}
				add_to_temporary_list = disase_notification_list
			}
			every_spouse = {
				limit = {
					inform_about_relative_recovery_trigger = yes
					NOT = { is_in_list = disase_notification_list }
				}
				add_to_temporary_list = disase_notification_list
			}
			every_heir_title = {
				limit = {
					exists = holder
				}
				holder = {
					if = {
						limit = {
							player_heir = scope:sick_character
							inform_about_relative_recovery_trigger = yes
							NOT = { is_in_list = disase_notification_list }
						}
						add_to_temporary_list = disase_notification_list
					}
				}
			}

			#Go through list and send notifications
			every_in_list = {
				list = disase_notification_list
				
				if = {
					limit = {
						OR = {
							#This character received an event when
							scope:sick_character = {
								is_target_in_variable_list = {
									name = recovery_event_receivers
									target = prev
								}
							}
							#It's your player heir
							trigger_if = {
								limit = { exists = player_heir }
								player_heir = scope:sick_character
							}
						}
					}
					trigger_event = health.2202
				}
				else = {
					save_scope_as = message_receiver
					send_interface_message = {
						type = msg_disease_recovery
						left_icon = scope:sick_character
						title = disease_recovery_feed_message.t
						show_as_tooltip = {
							scope:sick_character = {	
								if = {
									limit = { scope:disease_type = flag:early_great_pox }
									remove_trait_force_tooltip = early_great_pox
								}
								else = {
									remove_trait_force_tooltip = $DISEASE$
								}
							}
						}
					}
				}
			}
		}

		clear_variable_list = recovery_event_receivers

		#TRAIT REMOVAL
		remove_trait = $DISEASE$

		#IMMUNITY
		hidden_effect = {
			if = {
				limit = { scope:disease_type = flag:smallpox }
				add_character_flag = disease_immunity_smallpox
			}
			else_if = {
				limit = { scope:disease_type = flag:measles }
				add_character_flag = disease_immunity_measles
			}
			else_if = {
				limit = { scope:disease_type = flag:bubonic_plague }
				add_character_flag = disease_immunity_bubonic_plague
			}
		}
	}
}


#Triggers an event removing the disease (if you meet the conditions) and notifying everyone who should know. Needs the arguments DISEASE trait name. No events exist for leper, lovers_pox and early_great_pox.

recover_from_disease_notify_effect = {
	save_scope_value_as = {
		name = disease_type
		value = flag:$DISEASE$
	}
	
	if = {
		limit = { scope:disease_type = flag:ill }
		trigger_event = { id = health.1101 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:pneumonic }
		trigger_event = { id = health.1102 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:gout_ridden }
		trigger_event = { id = health.1103 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:typhus }
		trigger_event = { id = health.1105 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:consumption }
		trigger_event = { id = health.1106 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:cancer }
		trigger_event = { id = health.1107 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:great_pox }
		trigger_event = { id = health.1109 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:smallpox }
		trigger_event = { id = health.1110 days = { 5 15 } }
	}
	else_if = {
		limit = { scope:disease_type = flag:bubonic_plague }
		trigger_event = { id = health.1111 days = { 5 15 } }
	}
}

#If partner has lover's pox, the character gets it through an event. Needs argument PARTNER
contract_lovers_pox_from = {
	$PARTNER$ = { save_scope_as = infecting_partner }
	if = {
		limit = { scope:infecting_partner = { has_trait = lovers_pox } }
		contract_disease_notify_effect = { DISEASE = lovers_pox }
	}
}

#If partner has great pox, the character gets it through an event. Needs argument PARTNER
contract_great_pox_from = {
	$PARTNER$ = { save_scope_as = infecting_partner }
	if = {
		limit = {
			scope:infecting_partner = {
				OR = {
					has_trait = early_great_pox
					has_trait = great_pox
				}
			}
		}
		contract_disease_notify_effect = { DISEASE = great_pox }
	}
}

#50% risk of herpes (if partner has it) and 30% risk of great pox (if partner has it). Added through event. Needs argument PARTNER
risk_of_std_from_effect = {
	random = {
		chance = 50
		modifier = {
			add = -30
			has_perk = wash_your_hands_perk
		}
		contract_lovers_pox_from = { PARTNER = $PARTNER$ }
	}
	random = {
		chance = 30
		modifier = {
			add = -10
			has_perk = wash_your_hands_perk
		}
		modifier = {
			add = -30
			has_character_flag = contraction_cooldown_great_pox
		}
		contract_great_pox_from = { PARTNER = $PARTNER$ }
	}
}

#Creates a list of characters which might contract a disease from you (for plague and smallpox)
create_contagion_list_effect = {
	$CONTAGION_COURT_OWNER$ = {
		if = {
			limit = {
				NOR = {
					this = $SICK_CHARACTER$
					is_in_list = contagion_list
				}
			}
			add_to_temporary_list = contagion_list
		}
		every_courtier_or_guest = {
			limit = {
				NOR = {
					this = $SICK_CHARACTER$
					is_in_list = contagion_list
				}
			}
			add_to_temporary_list = contagion_list
		}
		every_prisoner = {
			limit = {
				NOR = {
					this = $SICK_CHARACTER$
					is_in_list = contagion_list
				}
			}
			add_to_temporary_list = contagion_list
		}
	}
	$SICK_CHARACTER$ = {
		every_scheme = {
			limit = {
				friendly_scheme_trigger = yes
				NOT = { scheme_target_character = { is_in_list = contagion_list } }
			}
			scheme_target_character = { add_to_temporary_list = contagion_list }
		}
		every_targeting_scheme = {
			limit = {
				friendly_scheme_trigger = yes
				NOT = { scheme_owner = { is_in_list = contagion_list } }
			}
			scheme_owner = { add_to_temporary_list = contagion_list }
		}
	}
}

### SIDE EFFECTS ###
epilepsy_fever_risk_effect = {
	hidden_effect = {
		if = {
			limit = { age <= 12 }
			random = { 	
				chance = $CHANCE$
				modifier = {
					age >= 9
					factor = 0.7
				}
				debug_log = "Epilepsy: fever"
				trigger_event = {
					id = trait_specific.2001 #Gain "possessed"
					days = { 30 300 }
				}
			}
		}
	}
}

epilepsy_brain_trauma_risk_effect = {
	hidden_effect = {
		random = {
			chance = $CHANCE$
			debug_log = "Epilepsy: brain trauma"
			trigger_event = {
				id = trait_specific.2001 #Gain "possessed"
				days = { 30 300 }
			}
		}
	}
}


###############################
###############################
# GAIN/INCREASE WOUND EFFECTS #
###############################
###############################


increase_wounds_no_death_effect = {
	save_temporary_scope_value_as = {
		name = treatment_type
		value = flag:$REASON$
	}

	change_trait_rank = {
		trait = wounded
		rank = 1
		max = 3
	}

	if = { #Wounds from treatments give no infection and no additional treatment
		limit = { NOT = { scope:treatment_type = flag:treatment } }

		#CHANCE OF INFECTION
		hidden_effect = {
			random = {
				chance = 10
				trigger_event = {
					id = health.0201
					days = { 30 60 }
				}
			}
		}

		#HANDLE TREATMENT
		if = { #To send notification message or trigger the right event
			limit = {
				has_trait_rank = {
					trait = wounded
					rank = 1
				}
				court_physician_available_trigger = yes
			}
			save_scope_as = sick_character
			safe_wound_treatment_effect = yes #Wounded 1 only gives a "result of treatment" notification" if you have a physician, i.e. you get no events about it.
		}
		else_if = {
			limit = {
				has_trait_rank = {
					trait = wounded
					rank = 2
				}
				has_recent_wound_treatment_trigger = no
			}
			#A "real" event if you're not receiving treatment
			#Nothing happens if you're already being treated for wounds
			trigger_event = {
				id = health.0102
				days = { 2 3 }
			}
		}
		else_if = {
			limit = {
				has_trait_rank = {
					trait = wounded
					rank = 3
				}
				has_recent_wound_treatment_trigger = no
			}
			#A "real" event if you're not receiving treatment
			#Nothing happens if you're already being treated for wounds
			trigger_event = {
				id = health.0104
				days = { 2 3 }
			}

			#Epilepsy risk
			epilepsy_brain_trauma_risk_effect = { CHANCE = 5 }
		}
	}

	# To stop the game from complaining about unused character flags since we only specifically check
	# the treatment reason for risk of further or infection
	if = {
		limit = {
			exists = flag:$REASON$
		}
	}
}


increase_wounds_children_no_death_effect = {
	hidden_effect = {
		random_list = {
			75 = {
				if = {
					limit = {
						has_character_modifier = scratched_and_bruised
					}
					remove_character_modifier = scratched_and_bruised
				}
				add_character_modifier = {
					modifier = scratched_and_bruised
					years = 3
				}
			}
			25 = {
				increase_wounds_no_death_effect = { REASON = wounds }
			}
		}
	}
}

#increase_wounds_effect
increase_wounds_effect = {
	if = {
		limit = {
			has_trait_rank = {
				trait = wounded
				rank < 3
			}
		}
		increase_wounds_no_death_effect = { REASON = $REASON$ }
	}
	else_if = { #Using an if because this needs to never go wrong
		limit = {
			has_trait_rank = {
				trait = wounded
				rank = 3
			}
		}
		death = {
			death_reason = death_$REASON$
		}
	}
}

maimed_in_battle_effect = {
	random_list = {
		4 = {
			trigger = {
				NOT = {
					has_trait = one_legged
				}
			}
			add_trait_force_tooltip = one_legged
			increase_wounds_effect = { REASON = fight }
		}
		2 = {
			trigger = {
				NOT = {
					has_trait = disfigured
				}
			}
			add_trait_force_tooltip = disfigured
			increase_wounds_effect = { REASON = fight }
			epilepsy_brain_trauma_risk_effect = { CHANCE = 5 }
		}
		4 = {
			trigger = {
				NOT = {
					has_trait = one_eyed
				}
			}
			add_trait_force_tooltip = one_eyed
			increase_wounds_effect = { REASON = fight }
			epilepsy_brain_trauma_risk_effect = { CHANCE = 5 }
		}
		4 = {
			trigger = {
				NOT = {
					has_trait = maimed
				}
			}
			apply_maimed_trait_and_modifier_effect = yes
			epilepsy_brain_trauma_risk_effect = { CHANCE = 5 }
		}
	}
}

apply_maimed_trait_and_modifier_effect = {
	add_trait = maimed
	add_character_modifier = {
		modifier = recently_maimed_modifier
		years = 1
	}
}


#########################################
# EFFECTS FOR WEIGHT GAIN/LOSS			#
#########################################

target_weight_modifier_effect = {
	if = {
		limit = {
			NOT = { has_variable = character_weight_variable }
		}
		set_variable = {
			name = character_weight_variable
			value = 0
		}
	}
	change_variable = {
		name = character_weight_variable
		add = $VALUE$
	}
}


#########################################
# EFFECTS FOR COURT PHYSICIAN TREATMENT #
#########################################



### COURT PHYSICIAN MANAGEMENT ###

set_court_physician_effect = {
	$PHYSICIAN$ = {
		if = {
			limit = { 
				NOT = { liege = $EMPLOYER$ }
			}
			$EMPLOYER$ = { add_courtier = $PHYSICIAN$ }
		}
	}
	$EMPLOYER$ = {
		#Replace existing court physician if one exists
		if = {
			limit = {
				employs_court_position = court_physician_court_position
				any_court_position_holder = {
					type = court_physician_court_position
					count > 0
				}
			}
			every_court_position_holder = {
				type = court_physician_court_position
				save_temporary_scope_as = old_physician

				$EMPLOYER$ = {
					replace_court_position = {
						recipient = $PHYSICIAN$
						holder = scope:old_physician
						court_position = court_physician_court_position
					}
					reverse_add_opinion = {
						target = scope:old_physician
						modifier = disappointed_opinion
						opinion = -15
					}
					reverse_add_opinion = {
						target = $PHYSICIAN$
						modifier = hired_me_opinion
					}
				}
			}
		}
		#Else just straight up appoint
		else = {
			appoint_court_position = {
				recipient = $PHYSICIAN$
				court_position = court_physician_court_position
			}
			reverse_add_opinion = {
				target = $PHYSICIAN$
				modifier = hired_me_opinion
			}
		}
	
		#Trigger treatments if needed
		hidden_effect = {
			if = {
				limit = {
					has_treatable_disease_trigger = yes
					has_recent_treatment_trigger = no
				}
				save_scope_as = sick_character
				trigger_event = {
					id = health.3101
					days = { physician_treatment_delay_ruler_min physician_treatment_delay_ruler_max }
				}
			}
			else_if = {
				limit = {
					has_recent_wound_treatment_trigger = no
					has_wounds_trigger = yes
				}
				save_scope_as = sick_character
				trigger_event = {
					id = health.4001
					days = { physician_treatment_delay_ruler_min physician_treatment_delay_ruler_max }
				}
			}
			every_courtier_or_guest = {
				if = {
					limit = {
						has_treatable_disease_trigger = yes
						has_recent_treatment_trigger = no
					}
					set_worst_disease_effect = yes
					save_scope_as = sick_character
					decide_who_picks_disease_treatment_effect = yes #Sends health.3101 to them or 3102 to liege (you)
				}
				else_if = {
					limit = {
						has_recent_wound_treatment_trigger = no
						has_wounds_trigger = yes
					}
					save_scope_as = sick_character
					decide_who_picks_wound_treatment_effect = yes
				}
			}
		}
	}
}

save_court_physician_as_effect = {
	hidden_effect = {
		if = { 	
			limit = { exists = court_owner }
			court_owner = {
				random_court_position_holder = {
					type = court_physician_court_position
					limit = {
						is_physically_able = yes
					}
					save_scope_as = $SCOPE_NAME$
				}
			}
		}
	}
}



###COURT PHYSICIAN RANK UP###

physician_rank_up_tooltip_effect = {
	scope:physician = {
		if = {
			limit = {
				exists = var:physician_level_up
			}
			show_as_tooltip = {
				if = {
					limit = { var:physician_level_up = flag:physician }
					if = {
						limit = {
							has_trait_xp = {
								trait = lifestyle_physician
								value > 5
							}
						}
						add_trait_xp = {
							trait = lifestyle_physician
							value = 10
						}
					}
					else = { add_trait_force_tooltip = lifestyle_physician }
				}
				else_if = {
					limit = { var:physician_level_up = flag:mystic }
					if = {
						limit = {
							has_trait_xp = {
								trait = lifestyle_mystic
								value > 5
							}
						}
						add_trait_xp = {
							trait = lifestyle_mystic
							value = 10
						}
					}
					else = { add_trait_force_tooltip = lifestyle_mystic }
				}
			}
		}
	}
}

#Needs argument CHANCE
physician_level_up_chance_effect = {
	if = {
		limit = {
			is_alive = yes
			NAND = {
				has_trait = lifestyle_physician
				has_trait_xp = {
					trait = lifestyle_physician
					value >= 100
				}
			}
		}
		random = {
			chance = $CHANCE$
			physician_lifestyle_rank_up_effect = yes

			#Used by physician_rank_up_tooltip_effect, to be shown in treatment outcome...
			set_variable = { name = physician_level_up value = flag:physician days = 15 }

			#...or in notification
			if = {
				limit = {
					liege ?= { this != scope:sick_character }
				}
				liege = {
					send_interface_message = { #Should be feed message, because it's not hugely important
						type = event_court_physician_good
						title = physician_level_up_chance_effect.t
						left_icon = scope:physician
						physician_rank_up_tooltip_effect = yes
					}
				}
			}
		}
	}
}

#Needs argument CHANCE
mystic_level_up_chance_effect = {
	if = {
		limit = {
			NAND = {	
				has_trait = lifestyle_mystic
				has_trait_xp = {
					trait = lifestyle_mystic
					value >= 100
				}
			}
			is_alive = yes
		}
		random = {
			chance = $CHANCE$
			ai_mystic_lifestyle_rank_up_effect = yes

			#Used by physician_rank_up_tooltip_effect, to be shown in treatment outcome...
			set_variable = { name = physician_level_up value = flag:mystic days = 15 }

			#...or in notification
			if = {
				limit = {
					liege ?= { this != scope:sick_character }
				}
				liege = {
					send_interface_message = {
						type = event_court_physician_good
						title = physician_level_up_chance_effect.t
						left_icon = scope:physician
						physician_rank_up_tooltip_effect = yes
					}
				}
			}

			#Have a tiny chance to become witch
			hidden_effect = {
				if = {
					limit = {
						is_ai = yes
						NOR = {
							any_secret = { type = secret_witch }
							has_trait = witch
						}
					}
					random = {
						modifier = {
							factor = 0
							ai_zeal >= medium_positive_ai_value
						}
						modifier = {
							factor = 2
							ai_zeal <= high_negative_ai_value #high and not medium because mystic traits already remove some ai_zeal
						}
						chance = 5
						give_witch_secret_or_trait_effect = yes
					}
				}
			}
		}
	}
}




###DISEASE TREATMENT OPTIONS###

safe_disease_treatment_effect = {
	$TREATMENT_PICKER$ = { save_scope_as = treatment_picker }
	$PATIENT$ = {
		custom_tooltip = safe_diseaste_treatment.tt

		hidden_effect = {
			save_court_physician_as_effect = { SCOPE_NAME = physician }

			if = {
				limit = {
					NOT = { exists = scope:sick_character }
				}
				save_scope_as = sick_character
			} #If a sick character was not already saved we save the patient as Sick Character here

			if = {
				limit = {
					exists = scope:physician
					court_physician_available_trigger = yes
				}

				#Physician skill up
				scope:physician = {
					random_list = {
						90 = {  #physician
							trigger = {
								NAND = {
									has_trait = lifestyle_physician
									has_trait_xp = {
										trait = lifestyle_physician
										value >= 100
									}
								}
							}
							physician_level_up_chance_effect = { CHANCE = 10 }
						}
						10 = { #Mystic
							trigger = {
								NOR = {
									AND = {
										has_trait = lifestyle_mystic
										has_trait_xp = {
											trait = lifestyle_mystic
											value >= 100
										}
									}
									AND = { #Because then this would be the only option which is weird
										has_trait = lifestyle_physician
										has_trait_xp = {
											trait = lifestyle_physician
											value >= 100
										}
									}
								}
								OR = {
									NAND = { #Either, this is my first rank up
										has_trait = lifestyle_physician
										has_trait = lifestyle_mystic
									}
									has_trait = lifestyle_mystic #I have already chosen this path
								}
							}
							modifier = {
								has_trait = lifestyle_mystic
								factor = 2
							}
							modifier = {
								ai_zeal >= medium_positive_ai_value
								factor = 0
							}
							mystic_level_up_chance_effect = { CHANCE = 10 }
						}
					}
				}

				# OUTCOME RANDOMIZATION
				random_list = {
					70 = { # Success
						modifier = {
							factor = scope:physician.physician_safe_treatment_skill_factor
							# 1 for an average learning skill character without traits
							# 0.2 min for low learning
							# ~3 for high skill character without traits
							# ~12 for high skill character with best trait (physician_3)
						}
						modifier = { # Bump the death numbers a bit
							$PATIENT$ = { is_ruler = no }
							factor = 0.8
						}
						modifier = { # Pool characters should die more
							$PATIENT$ = { is_pool_character = yes }
							factor = 0.2
						}
						trigger_event = health.3103 #Safe treatment sucess
					}
					30 = { # Failure
						trigger_event = health.3104 #Safe treatment failure
					}
					70 = { # Failure on purpose
						trigger = {
							court_physician_can_fail_on_purpose_trigger = yes
						}
						opinion_modifier = {
							who = scope:physician
							opinion_target = scope:sick_character
							multiplier = -1 # Adds 100 for -100 opinion
						}
						modifier = {
							factor = { #To keep it scaling with success
								add = scope:physician.physician_safe_treatment_skill_factor
								divide = 2
							}
						}
						modifier = { #Are they already trying to kill you?
							add = 40
							scope:sick_character = {
								any_targeting_scheme = {
									scheme_type = murder
									OR = {
										scheme_owner = scope:physician
										any_scheme_agent_character = { this = scope:physician }
									}
								}
							}
						}

						trigger_event = health.3104 #Safe treatment failure
					}	
				}
			}
		}
	}
}


risky_disease_treatment_effect = {
	$TREATMENT_PICKER$ = { save_scope_as = treatment_picker }
	$PATIENT$ = {
		custom_tooltip = risky_diseaste_treatment.tt

		scope:treatment_picker = {
			stress_impact = {
				craven = medium_stress_impact_gain
				content = minor_stress_impact_gain
			}
		}

		hidden_effect = {
			save_court_physician_as_effect = { SCOPE_NAME = physician }

			if = {
				limit = {
					exists = scope:physician
					court_physician_available_trigger = yes
				}

				#Physician skill up
				scope:physician = {
					physician_level_up_chance_effect = { CHANCE = 10 }
				}

				random_list = {
					1 = { #Success
						modifier = {
							scope:physician = {
								learning >= mediocre_skill_rating
								learning < medium_skill_rating
							}
							factor = 2
						}
						modifier = {
							scope:physician = {
								learning >= medium_skill_rating
								learning < decent_skill_rating
							}
							factor = 4
						}
						modifier = {
							scope:physician = {
								learning >= decent_skill_rating
								learning < high_skill_rating
							}
							factor = 7
						}
						modifier = {
							scope:physician = {
								learning >= high_skill_rating
							}
							factor = 10
						}
						modifier = {
							scope:physician = { has_trait = lifestyle_physician }
							factor = 2
						}
						modifier = {
							scope:physician = {
								has_trait = lifestyle_physician
								has_trait_xp = {
									trait = lifestyle_physician
									value >= 50
								}
							}
							factor = 5
						}
						modifier = {
							scope:physician = {
								has_trait = lifestyle_physician
								has_trait_xp = {
									trait = lifestyle_physician
									value >= 100
								}
							}
							factor = 5
						}
						# Liege Perk bonus
						modifier = {
							exists = scope:physician.liege
							scope:physician.liege = {
								has_perk = anatomical_studies_perk
							}
							factor = 2
						}
						modifier = { # Bump the death numbers a bit
							$PATIENT$ = { is_ruler = no }
							factor = 0.8
						}
						modifier = { # Pool characters should die more
							$PATIENT$ = { is_pool_character = yes }
							factor = 0.2
						}

						#Critical or normal success?
						random_list = {
							1 = {
								modifier = {
									scope:physician = { has_trait = lifestyle_physician }
									factor = 2
								}
								modifier = {
									scope:physician = {
										has_trait = lifestyle_physician
										has_trait_xp = {
											trait = lifestyle_physician
											value >= 50
										}
									}
									factor = 2
								}
								modifier = {
									scope:physician = {
										has_trait = lifestyle_physician
										has_trait_xp = {
											trait = lifestyle_physician
											value >= 100
										}
									}
									factor = 2
								}
								modifier = {
									scope:disease_type = flag:leper
									factor = 0
								}
								modifier = {
									scope:disease_type = flag:cancer
									factor = 0.2
								}
								# Liege Perk bonus
								modifier = {
									exists = scope:physician.liege
									scope:physician.liege = {
										has_perk = anatomical_studies_perk
									}
									factor = 2
								}
								trigger_event = health.3105 #Critical success
							}
							5 = {
								trigger_event = health.3106 #Normal success
							}
						}
					}
					10 = { #Failure
						trigger_event = health.3107 #Failure
					}
					5 = { #Failure on purpose
						trigger = {
							court_physician_can_fail_on_purpose_trigger = yes
						}
						modifier = {	
							OR = {
								has_relation_rival = scope:physician
								reverse_opinion = {
									target = scope:physician
									value <= -20
								}
							}
							factor = 2
						}
						modifier = { #Are they already trying to kill you?
							add = 40
							scope:sick_character = {
								any_targeting_scheme = {
									scheme_type = murder
									OR = {
										scheme_owner = scope:physician
										any_scheme_agent_character = { this = scope:physician }
									}
								}
							}
						}
						trigger_event = health.3107 #Risky treatment failure
					}
				}
			}
		}
	}
}

mystic_disease_treatment_effect = {
	$TREATMENT_PICKER$ = { save_scope_as = treatment_picker }
	$PATIENT$ = {
		custom_tooltip = mystic_diseaste_treatment.tt

		scope:treatment_picker = {
			stress_impact = {
				paranoid = minor_stress_impact_gain
				zealous = major_stress_impact_gain
				craven = medium_stress_impact_gain
			}
		}

		hidden_effect = {
			save_court_physician_as_effect = { SCOPE_NAME = physician }

			if = {
				limit = {
					exists = scope:physician
					court_physician_available_trigger = yes
				}
				#Physician skill up
				scope:physician = {
					mystic_level_up_chance_effect = { CHANCE = 15 }
				}
			}
			else = {
				debug_log = "No Physician existed in a mystic_treatment_effect! Why was the option even available?"
			}

			random_list = {
				1 = { #Success
					modifier = {
						scope:physician = {
							learning >= mediocre_skill_rating
							learning < medium_skill_rating
						}
						factor = 2
					}
					modifier = {
						scope:physician = {
							learning >= medium_skill_rating
							learning < decent_skill_rating
						}
						factor = 4
					}
					modifier = {
						scope:physician = {
							learning >= decent_skill_rating
							learning < high_skill_rating
						}
						factor = 7
					}
					modifier = {
						scope:physician = {
							learning >= high_skill_rating
						}
						factor = 10
					}
					modifier = {
						scope:physician = { has_trait = lifestyle_mystic }
						factor = 2
					}
					modifier = {
						scope:physician = {
							has_trait = lifestyle_mystic
							has_trait_xp = {
								trait = lifestyle_mystic
								value >= 50
							}
						}
						factor = 5
					}
					modifier = {
						scope:physician = {
							has_trait = lifestyle_mystic
							has_trait_xp = {
								trait = lifestyle_mystic
								value >= 50
							}
						}
						factor = 5
					}
					# Liege Perk bonus
					modifier = {
						scope:physician.liege = {
							has_perk = anatomical_studies_perk
						}
						factor = 2
					}
					modifier = { # Bump the death numbers a bit
						$PATIENT$ = { is_ruler = no }
						factor = 0.8
					}
					modifier = { # Pool characters should die more
						$PATIENT$ = { is_pool_character = yes }
						factor = 0.2
					}

					#Critical or normal success?
					random_list = {
						1 = {
							modifier = {
								scope:physician = { has_trait = lifestyle_physician }
								factor = 1.5
							}
							modifier = {
								scope:physician = {
									has_trait = lifestyle_physician
									has_trait_xp = {
										trait = lifestyle_physician
										value >= 50
									}
								}
								factor = 2
							}
							modifier = {
								scope:physician = {
									has_trait = lifestyle_physician
									has_trait_xp = {
										trait = lifestyle_physician
										value >= 50
									}
								}
								factor = 3
							}
							modifier = {
								is_adult = no
								factor = 0
							}
							modifier = {
								scope:disease_type = flag:leper
								factor = 0
							}
							modifier = {
								scope:disease_type = flag:cancer
								factor = 0.1
							}	
							
							# Liege Perk bonus
							modifier = {
								scope:physician.liege = {
									has_perk = anatomical_studies_perk
								}
								factor = 2
							}
							
							trigger_event = health.3108 #Critical success
						}
						5 = {
							trigger_event = health.3109 #Normal success
						}
					}
				}
				10 = { #Failure
					trigger_event = health.3110 #Failure
				}
				5 = { #Failure on purpose
					trigger = {
						court_physician_can_fail_on_purpose_trigger = yes
					}
					modifier = {	
						OR = {
							has_relation_rival = scope:physician
							reverse_opinion = {
								target = scope:physician
								value <= -20
							}
						}
						factor = 2
					}
					modifier = { #Are they already trying to kill you?
						add = 40
						scope:sick_character = {
							any_targeting_scheme = {
								scheme_type = murder
								OR = {
									scheme_owner = scope:physician
									any_scheme_agent_character = { this = scope:physician }
								}
							}
						}
					}
					trigger_event = health.3110 #Failure
				}	
			}
		}
	}
}

no_disease_treatment_effect = {
	custom_tooltip = no_treatment_effect.tt
}

find_court_physician_effect = {
	custom_tooltip = health.3101.e.tt
	hidden_effect = {
		# Stop AI taking physicians via event, since they've got an AI prioritisation system to work with.
		## We do this in the effect rather than elsewhere for script hygiene.
		if = {
			limit = { is_ai = no }
			add_character_flag = { flag = already_sick days = 30 }
			add_character_flag = { flag = searching_for_physician days = court_physician_search_max } 
			trigger_event = {
				id = health.3001 days = { court_physician_search_min court_physician_search_max }
			}
		}
	}
}

deny_treatment_effect = {
	$TREATMENT_PICKER$ = { save_scope_as = treatment_picker }
	$PATIENT$ = {
		custom_tooltip = deny_treatment_effect.tt

		add_opinion = {
			target = root
			modifier = cruelty_opinion
			opinion = -20
		}
	}
}


###WOUND TREATMENT OPTIONS###

safe_wound_treatment_effect = {
	custom_tooltip = safe_wound_treatment.tt

	hidden_effect = {
		save_court_physician_as_effect = { SCOPE_NAME = physician }

		if = {
			limit = { 
				exists = scope:physician 
				court_physician_available_trigger = yes
			}

			#Physician skill up
			scope:physician = {
				if = {
					limit = {
						NAND = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 100
							}
						}
					}
					physician_level_up_chance_effect = { CHANCE = 10 }
				}
			}

			random_list = {
				10 = { #Success
					modifier = {
						scope:physician = {
							learning >= mediocre_skill_rating
							learning < medium_skill_rating
						}
						factor = 2
					}
					modifier = {
						scope:physician = {
							learning >= medium_skill_rating
							learning < decent_skill_rating
						}
						factor = 4
					}
					modifier = {
						scope:physician = {
							learning >= decent_skill_rating
							learning < high_skill_rating
						}
						factor = 7
					}
					modifier = {
						scope:physician = {
							learning >= high_skill_rating
						}
						factor = 10
					}
					modifier = {
						scope:physician = { has_trait = lifestyle_physician }
						factor = 2
					}
					modifier = {
						scope:physician = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 50
							}
						}
						factor = 2
					}
					modifier = {
						scope:physician = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 100
							}
						}
						factor = 4
					}
					if = {
						limit = {
							has_trait = wounded_1
						}
						trigger_event = {
							id = health.0100
							days = { 2 3 }
						}
					}
					else = {
						trigger_event = health.4101 #Safe treatment success
					}
				}
				50 = { #Failure
					if = {
						limit = {
							has_trait = wounded_1
						}
						trigger_event = {
							id = health.0101
							days = { 2 3 }
						}
					}
					else = {
						trigger_event = health.4102 #Safe treatment failure
					}
				}	
			}
		}
	}
}


risky_wound_treatment_effect = {
	custom_tooltip = risky_wound_treatment.tt

	hidden_effect = {
		save_court_physician_as_effect = { SCOPE_NAME = physician }

		if = {
			limit = { 
				exists = scope:physician 
				court_physician_available_trigger = yes
			}

			#Physician skill up
			scope:physician = {
				physician_level_up_chance_effect = { CHANCE = 10 }
			}

			random_list = {
				1 = { #Success
					modifier = {
						scope:physician = {
							learning >= mediocre_skill_rating
							learning < medium_skill_rating
						}
						factor = 2
					}
					modifier = {
						scope:physician = {
							learning >= medium_skill_rating
							learning < decent_skill_rating
						}
						factor = 4
					}
					modifier = {
						scope:physician = {
							learning >= decent_skill_rating
							learning < high_skill_rating
						}
						factor = 7
					}
					modifier = {
						scope:physician = {
							learning >= high_skill_rating
						}
						factor = 10
					}
					modifier = {
						scope:physician = { has_trait = lifestyle_physician }
						factor = 2
					}
					modifier = {
						scope:physician = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 50
							}
						}
						factor = 2
					}
					modifier = {
						scope:physician = {
							has_trait = lifestyle_physician
							has_trait_xp = {
								trait = lifestyle_physician
								value >= 100
							}
						}
						factor = 4
					}

					modifier = { #Gangrene! Lower chance of success
						factor = 0.5
						has_character_modifier = gangrene_modifier
					}

					#Critical or normal success?
					random_list = {
						1 = {
							modifier = {
								scope:physician = { has_trait = lifestyle_physician }
								factor = 2
							}
							modifier = {
								scope:physician = {
									has_trait = lifestyle_physician
									has_trait_xp = {
										trait = lifestyle_physician
										value >= 50
									}
								}
								factor = 2
							}
							modifier = {
								scope:physician = {
									has_trait = lifestyle_physician
									has_trait_xp = {
										trait = lifestyle_physician
										value >= 100
									}
								}
								factor = 2
							}
							modifier = {
								has_character_modifier = infected_wound_modifier
								factor = 0.7
							}
							modifier = { #Gangrene! Lower chance of critical success
								has_character_modifier = gangrene_modifier
								factor = 0.7
							}
							trigger_event = health.4103 #Critical success
						}
						5 = {
							trigger_event = health.4104 #Normal success
						}
					}
				}
				10 = { #Failure
					trigger_event = health.4105 #Failure
				}
			}
		}
	}
}



###DISEASE TREATMENT OUTCOMES###

set_worst_disease_effect = {
	if = {
		limit = { has_trait = bubonic_plague }
		save_scope_value_as = {
			name = disease_type
			value = flag:bubonic_plague
		}
	}
	else_if = {
		limit = { has_trait = cancer }
		save_scope_value_as = {
			name = disease_type
			value = flag:cancer
		}
	}
	else_if = {
		limit = { has_trait = smallpox }
		save_scope_value_as = {
			name = disease_type
			value = flag:smallpox
		}
	}
	else_if = {
		limit = { has_trait = measles }
		save_scope_value_as = {
			name = disease_type
			value = flag:measles
		}
	}
	else_if = {
		limit = { has_trait = dysentery }
		save_scope_value_as = {
			name = disease_type
			value = flag:dysentery
		}
	}
	else_if = {
		limit = { has_trait = ergotism }
		save_scope_value_as = {
			name = disease_type
			value = flag:ergotism
		}
	}
	else_if = {
		limit = { has_trait = consumption }
		save_scope_value_as = {
			name = disease_type
			value = flag:consumption
		}
	}
	else_if = {
		limit = { has_trait = typhus }
		save_scope_value_as = {
			name = disease_type
			value = flag:typhus
		}
	}
	else_if = {
		limit = { has_trait = great_pox }
		save_scope_value_as = {
			name = disease_type
			value = flag:great_pox
		}
	}
	else_if = {
		limit = { has_trait = pneumonic }
		save_scope_value_as = {
			name = disease_type
			value = flag:pneumonic
		}
	}
	else_if = {
		limit = { has_trait = leper }
		save_scope_value_as = {
			name = disease_type
			value = flag:leper
		}
	}
	else_if = {
		limit = { has_trait = gout_ridden }
		save_scope_value_as = {
			name = disease_type
			value = flag:gout_ridden
		}
	}
	else_if = {
		limit = { has_trait = ill }
		save_scope_value_as = {
			name = disease_type
			value = flag:ill
		}
	}
}

add_disease_treatment_modifier_effect = {	
	#Treatment length depends on whether the disease has a short or long duration
	#Successful treatments come in two strengths per treatment type, low for diseases with low health penalty and high for diseases with high health penalty
	#Negative treatments only have one strength per treatment type
	#Successful safe treatments remove most of the penalty for low -health diseases but only 1/2-1/4 of penalty for high -health diseases
	#Successful risky/mystic treatments remove almost all of the penalty for all diseases (with plague being the main exception, that penalty is roughly halved)
	#Safe treatment:success

	save_temporary_scope_value_as = {
		name = treatment_result_treatment
		value = flag:$TREATMENT$
	}
	save_temporary_scope_value_as = {
		name = treatment_result_outcome
		value = flag:$OUTCOME$
	}

	#SAFE TREATMENT: SUCCESS
	if = {
		limit = {
			scope:treatment_result_treatment = flag:safe
			scope:treatment_result_outcome = flag:success
		}
		if = {
			limit = {
				has_short_disease_type_trigger = yes
				has_high_health_penalty_disease_type_trigger = yes
			}
			add_character_modifier = { modifier = safe_disease_treatment_success_high_modifier days = disease_treatment_short_duration }
		}
		else_if = {
			limit = {
				has_short_disease_type_trigger = no
				has_high_health_penalty_disease_type_trigger = yes
			}
			add_character_modifier = { modifier = safe_disease_treatment_success_high_modifier days = disease_treatment_long_duration }
		}
		else_if = {
			limit = {
				has_short_disease_type_trigger = yes
				has_high_health_penalty_disease_type_trigger = no
			}
			add_character_modifier = { modifier = safe_disease_treatment_success_low_modifier days = disease_treatment_short_duration }
		}
		else_if = {
			limit = {
				has_short_disease_type_trigger = no
				has_high_health_penalty_disease_type_trigger = no
			}
			add_character_modifier = { modifier = safe_disease_treatment_success_low_modifier days = disease_treatment_long_duration }
		}
	}
	#SAFE TREATMENT: FAILURE
	else_if = {
		limit = {
			scope:treatment_result_treatment = flag:safe
			scope:treatment_result_outcome = flag:failure
		}
		if = {
			limit = { has_short_disease_type_trigger = yes }
			add_character_modifier = { modifier = safe_disease_treatment_failure_modifier days = disease_treatment_short_duration }
		}
		else_if = {
			limit = { has_short_disease_type_trigger = no }
			add_character_modifier = { modifier = safe_disease_treatment_failure_modifier days = disease_treatment_long_duration }
		}
	}
	#RISKY & MYSTIC TREATMENT: CRITICAL SUCCESS
	else_if = {
		limit = {
			OR = {
				scope:treatment_result_treatment = flag:risky
				scope:treatment_result_treatment = flag:mystic #A succcessful mystic treatment shouldn't be noticeable from the outside, so using same modifiers
			}
			scope:treatment_result_outcome = flag:critical_success
		}

		#General cooldown
		add_character_flag = {
			flag = contraction_cooldown_general
			years = 2
		}

		if = {
			limit = { scope:disease_type = flag:consumption }
			remove_trait_force_tooltip = consumption
			add_character_flag = { flag = contraction_cooldown_consumption years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:cancer }
			remove_trait_force_tooltip = cancer
			add_character_flag = { flag = contraction_cooldown_cancer years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:great_pox }
			remove_trait_force_tooltip = great_pox
			add_character_flag = { flag = contraction_cooldown_great_pox years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:gout_ridden }
			remove_trait_force_tooltip = gout_ridden
			add_character_flag = { flag = contraction_cooldown_gout_ridden years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:ill }
			remove_trait_force_tooltip = ill
			#No cooldown, common disease
		}
		else_if = {
			limit = { scope:disease_type = flag:pneumonic }
			remove_trait_force_tooltip = pneumonic
			add_character_flag = { flag = contraction_cooldown_pneumonic years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:typhus }
			remove_trait_force_tooltip = typhus
			add_character_flag = { flag = contraction_cooldown_typhus years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:measles }
			remove_trait_force_tooltip = measles
			#No cooldown, immunity
		}
		else_if = {
			limit = { scope:disease_type = flag:dysentery }
			remove_trait_force_tooltip = dysentery
			add_character_flag = { flag = contraction_cooldown_dysentery years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:ergotism }
			remove_trait_force_tooltip = ergotism
			add_character_flag = { flag = contraction_cooldown_ergotism years = 20 }
		}
		else_if = {
			limit = { scope:disease_type = flag:smallpox }
			remove_trait_force_tooltip = smallpox
			#No cooldown, immunity
		}
		else_if = {
			limit = { scope:disease_type = flag:bubonic_plague }
			remove_trait_force_tooltip = bubonic_plague
			#No cooldown, immunity
		}
	}

	#RISKY & MYSTIC TREATMENT: SUCCESS
	else_if = {
		limit = {
			OR = {
				scope:treatment_result_treatment = flag:risky
				scope:treatment_result_treatment = flag:mystic #A succcessful mystic treatment shouldn't be noticeable from the outside, so using same modifiers
			}
			scope:treatment_result_outcome = flag:success
		}
		if = {
			limit = {
				has_short_disease_type_trigger = yes
				has_high_health_penalty_disease_type_trigger = yes
			}
			add_character_modifier = { modifier = risky_disease_treatment_success_high_modifier days = disease_treatment_short_duration }
		}
		else_if = {
			limit = {
				has_short_disease_type_trigger = no
				has_high_health_penalty_disease_type_trigger = yes
			}
			add_character_modifier = { modifier = risky_disease_treatment_success_high_modifier days = disease_treatment_long_duration }
		}
		else_if = {
			limit = {
				has_short_disease_type_trigger = yes
				has_high_health_penalty_disease_type_trigger = no
			}
			add_character_modifier = { modifier = risky_disease_treatment_success_low_modifier days = disease_treatment_short_duration }
		}
		else_if = {
			limit = {
				has_short_disease_type_trigger = no
				has_high_health_penalty_disease_type_trigger = no
			}
			add_character_modifier = { modifier = risky_disease_treatment_success_low_modifier days = disease_treatment_long_duration }
		}
	}
	# RISKY TREATMENT FAILURE
	else_if = {
		limit = {
			scope:treatment_result_treatment = flag:risky
			scope:treatment_result_outcome = flag:failure
		}
		if = {
			limit = { has_short_disease_type_trigger = yes }
			add_character_modifier = { modifier = risky_disease_treatment_failure_modifier days = disease_treatment_short_duration }
		}
		else_if = {
			limit = { has_short_disease_type_trigger = no }
			add_character_modifier = { modifier = risky_disease_treatment_failure_modifier days = disease_treatment_long_duration }
		}
	}
}


disease_treatment_result_tooltip_effect = {
	save_temporary_scope_value_as = {
		name = treatment_result_treatment
		value = flag:$TREATMENT$
	}
	save_temporary_scope_value_as = {
		name = treatment_result_outcome
		value = flag:$OUTCOME$
	}
	#Show death or treatment outcome
	if = {
		limit = { scope:sick_character = { is_alive = no } }
		custom_tooltip = health.3200.death.tt
	}
	else = {
		show_as_tooltip = {
			scope:sick_character = {
				add_disease_treatment_modifier_effect = { TREATMENT = $TREATMENT$ OUTCOME = $OUTCOME$ }

				#Risky
				if = {
					limit = { has_variable = treatment_strategy }
					if = {
						limit = { var:treatment_strategy = flag:amputation }
						add_trait_force_tooltip = one_legged
					}
					else_if = {
						limit = { var:treatment_strategy = flag:disfigurement }
						add_trait_force_tooltip = disfigured
					}
					else_if = {
						limit = { var:treatment_strategy = flag:eye }
						add_trait_force_tooltip = one_eyed
					}
					else_if = {
						limit = {
							var:treatment_strategy = flag:castration
							age >= 12
						}
						add_trait_force_tooltip = eunuch_1
					}
					else_if = {
						limit = {
							var:treatment_strategy = flag:castration
							age < 12
						}
						add_trait_force_tooltip = beardless_eunuch
					}
				}
				if = {
					limit = { has_variable = mystic_side_effect }
					#Mystic
					if = {
						limit = { var:mystic_side_effect = flag:lunatic }
						add_trait_force_tooltip = lunatic_1
					}
					else_if = {
						limit = { var:mystic_side_effect = flag:possessed }
						add_trait_force_tooltip = possessed_1
					}
					else_if = {
						limit = { var:mystic_side_effect = flag:dull }
						add_trait_force_tooltip = dull
					}
					else_if = {
						limit = { var:mystic_side_effect = flag:craven }
						add_trait_force_tooltip = craven
					}
					else_if = {
						limit = { var:mystic_side_effect = flag:paranoid }
						add_trait_force_tooltip = paranoid
					}
					else_if = {
						limit = { var:mystic_side_effect = flag:massive_stress_gain }
						add_stress = massive_stress_gain
					}
				}
			}
		}
	}
}

disease_treatment_results_effect = {
	save_temporary_scope_value_as = {
		name = treatment_result_treatment
		value = flag:$TREATMENT$
	}
	save_temporary_scope_value_as = {
		name = treatment_result_outcome
		value = flag:$OUTCOME$
	}

	#APPLY MODIFIERS (OR REMOVE TRAITS)
	add_disease_treatment_modifier_effect = { TREATMENT = $TREATMENT$ OUTCOME = $OUTCOME$ }

	#RISKY TREATMENT: DETERMINING TREATMENT STRATEGY AND REMOVING BODY PART
	if = {
		limit = { scope:treatment_result_treatment = flag:risky }
		random_list = {
			1 = { #Medicine
				trigger = {
					OR = { #Only use for cancer if no body part can be removed
						NOT = { scope:disease_type ?= flag:cancer }
						AND = {
							scope:disease_type ?= flag:cancer
							has_trait = one_eyed
							has_trait = one_legged
							has_trait = disfigured
							OR = {
								is_female = yes
								is_eunuch_trigger = yes
							}
						}
					}
				}
				set_variable = {
					name = treatment_strategy
					value = flag:medicine
					days = 30
				}
			}
			1 = { #Amputation
				trigger = {
					NOT = { has_trait = one_legged }
					OR = {
						has_amputation_type_disease_trigger = yes
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				add_trait_force_tooltip = one_legged
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:amputation
					days = 30
				}
				if = {
					limit = { has_amputation_type_disease_trigger = no }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
			1 = { #Disfigurement
				trigger = {
					NOT = { has_trait = disfigured }
					OR = {
						has_disfigurement_type_disease_trigger = yes
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				add_trait_force_tooltip = disfigured
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:disfigurement
					days = 30
				}
				if = {
					limit = { has_disfigurement_type_disease_trigger = no }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
			1 = { #Castration
				trigger = {
					is_male = yes
					is_eunuch_trigger = no
					OR = {
						scope:disease_type ?= flag:cancer
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				if = {
					limit = {
						age >= 12
					}
					add_trait_force_tooltip = eunuch_1
				}
				else = {
					add_trait_force_tooltip = beardless_eunuch
				}
				
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:castration
					days = 30
				}
				if = {
					limit = { NOT = { scope:disease_type ?= flag:cancer } }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
			1 = { #Remove eye
				trigger = {
					NOT = { has_trait = one_eyed }
					OR = {
						scope:disease_type ?= flag:cancer
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				add_trait_force_tooltip = one_eyed
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:eye
					days = 30
				}
				if = {
					limit = { NOT = { scope:disease_type ?= flag:cancer } }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
		}
	}

	#RISKY TREATMENT FAILURE: DEATH?
	if = {
		limit = {
			scope:treatment_result_treatment = flag:risky
			scope:treatment_result_outcome = flag:failure
		}
		if = {
			limit = {
				OR = {
					AND = { #Dies from wound upgrading past lvl 3
						has_trait = wounded_3
						AND = {
							has_variable = treatment_strategy
							OR = {
								var:treatment_strategy = flag:amputation
								var:treatment_strategy = flag:disfigurement
								var:treatment_strategy = flag:eye
								var:treatment_strategy = flag:castration
							}
						}
					}
					AND = {
						is_ai = yes
						health <= 0
					}
				}
			}
			add_character_flag = die_risky_treatment
		}
	}

	#MYSTIC TREATMENT: OCCULT OR SIMPLY QUESTIONABLE TREATMENT
	if = {
		limit = { scope:treatment_result_treatment = flag:mystic }
		random_list = {
			100 = { #Occult
				modifier = {
					scope:physician = {
						OR = {
							any_secret = { type = secret_witch }
							has_trait = witch
						}
					}
					factor = 10
				}
				random_list = {
					10 = { #Regular occult
						hidden_effect = {
							set_variable = {
								name = treatment_strategy
								value = flag:occult
								days = 30
							}
						}
					}
					2 = { #Cannibal occult
						trigger = {
							NOR = {
								has_trait = cannibal
								any_secret = { type = secret_cannibal }
							}
						}
						hidden_effect = {
							set_variable = {
								name = treatment_strategy
								value = flag:occult_cannibal
								days = 30
							}
						}
						give_cannibal_secret_or_trait_effect = yes
					}
					2 = { #Deviant occult
						trigger = {
							is_adult = yes
							NOR = {
								has_trait = deviant
								any_secret = { type = secret_deviant }
							}
							NOT = { scope:treatment_result_outcome = flag:failure }
						}
						hidden_effect = {
							set_variable = {
								name = treatment_strategy
								value = flag:occult_deviant
								days = 30
							}
						}
						give_deviant_secret_or_trait_effect = yes
					}
				}
			}
			50 = { #Questionable
				hidden_effect = {
					set_variable = {
						name = treatment_strategy
						value = flag:questionable
						days = 30
					}
				}
			}	
		}

	#MYSTIC TREATMENT: SPECIAL EFFECTS
		if = {
			limit = { scope:treatment_result_outcome = flag:failure }
			random_list = {
				10 = {
					trigger = { NOT = { has_trait = lunatic } }
					set_variable = {
						name = mystic_side_effect
						value = flag:lunatic
						days = 30
					}
					add_trait_force_tooltip = lunatic_1
				}
				10 = {
					trigger = { NOT = { has_trait = possessed } }
					set_variable = {
						name = mystic_side_effect
						value = flag:possessed
						days = 30
					}
					add_trait_force_tooltip = possessed_1
				}
				10 = {
					trigger = {
						NOR = {
							has_trait = dull
							has_trait = intellect_good
							has_trait = shrewd
						}
					}
					set_variable = {
						name = mystic_side_effect
						value = flag:dull
						days = 30
					}
					add_trait_force_tooltip = dull
				}
				10 = {
					trigger = { NOT = { has_trait = craven } }
					set_variable = {
						name = mystic_side_effect
						value = flag:craven
						days = 30
					}
					add_trait_force_tooltip = craven
				}
				10 = {
					trigger = { NOT = { has_trait = paranoid } }
					set_variable = {
						name = mystic_side_effect
						value = flag:paranoid
						days = 30
					}
					add_trait_force_tooltip = paranoid
				}
				15 = {
					set_variable = {
						name = mystic_side_effect
						value = flag:massive_stress_gain
						days = 30
					}
					add_stress = massive_stress_gain
				}
			}
		}

		#Stress for occult treatments
		if = {
			limit = { has_variable = treatment_strategy }
			if = {
				limit = { var:treatment_strategy = flag:occult }
				stress_impact = {
					zealous = major_stress_impact_gain
				}
			}
			else_if = {
				limit = { var:treatment_strategy = flag:occult_cannibal }
				stress_impact = {
					zealous = major_stress_impact_gain
					compassionate = major_stress_impact_gain
				}
			}
			else_if = {
				limit = { var:treatment_strategy = flag:occult_deviant }
				stress_impact = {
					zealous = major_stress_impact_gain
					chaste = major_stress_impact_gain
				}
			}
		}
	}

	#RETURN VISIT TO THE DOCTOR!
	hidden_effect = {
		if = {
			limit = {
				NOT = { #Risky/mystic critical success cures completely, no need for another visit
					scope:treatment_result_outcome = flag:critical_success
				}
			}
			if = {
				limit = { has_short_disease_type_trigger = yes }
				trigger_event = {
					id = health.3100 #Sends health.3101 to me or 3102 to liege
					days = disease_treatment_short_duration_plus_1
				}
			}
			else = {
				trigger_event = {
					id = health.3100 #Sends health.3101 to me or 3102 to liege
					days = disease_treatment_long_duration_plus_1
				}
			}
		}
	}

	#FAILED TREATMENT OPINIONS
	if = {
		limit = {
			scope:treatment_result_outcome = flag:failure
			OR = {
				scope:treatment_result_treatment = flag:risky
				scope:treatment_result_treatment = flag:mystic
			}
		}
		add_failed_treatment_of_kin_opinions_effect = yes
	}

	physician_rank_up_tooltip_effect = yes #Shows trait gain if physician ranked up
}





###WOUND TREATMENT OUTCOMES###

add_wound_treatment_modifier_effect = {	
	save_temporary_scope_value_as = {
		name = treatment_result_treatment
		value = flag:$TREATMENT$
	}
	save_temporary_scope_value_as = {
		name = treatment_result_outcome
		value = flag:$OUTCOME$
	}


	###SUCCESS###
	if = {
		limit = {
			OR = {
				scope:treatment_result_outcome = flag:success
				scope:treatment_result_outcome = flag:critical_success
			}
		}
		#Infection is always removed
		if = {
			limit = { has_character_modifier = infected_wound_modifier }
			remove_character_modifier = infected_wound_modifier
			save_scope_value_as = {
				name = infection
				value = yes
			}
		}
		#Gangrene is removed if you picked risky
		else_if = {
			limit = {
				has_character_modifier = gangrene_modifier
				scope:treatment_result_treatment = flag:risky
			}
			remove_character_modifier = gangrene_modifier
			save_scope_value_as = {
				name = gangrene
				value = yes
			}
		}


		#Applying correct modifier or removing correct trait (unless there's still an active treatment, could happen if you got treated for a wound and then got infection/gangrene)
		if = {
			limit = { has_recent_wound_treatment_trigger = no }

			#Safe treatment
			if = {
				limit = { scope:treatment_result_treatment = flag:safe }

				#Add modifier or remove wounded_1 trait
					if = {
					limit = { has_character_modifier = gangrene_modifier }
					add_character_modifier = { modifier = safe_wound_treatment_success_high_modifier days = wound_treatment_success_duration }
				}
				else_if = {
					limit = { has_trait = wounded_1 }
					remove_trait = wounded_1
				}
				else_if = {
					limit = {
						OR = {
							has_trait = wounded_2
							has_trait = wounded_3
						}
					}
					add_character_modifier = { modifier = safe_wound_treatment_success_low_modifier days = wound_treatment_success_duration }
				}
			}

			#Risky treatment critical success
			else_if = {
				limit = {
					scope:treatment_result_treatment = flag:risky
					scope:treatment_result_outcome = flag:critical_success
				}
				#Remove a trait level
				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 = wounded_1
				}
				else_if = {
					limit = { has_trait = wounded_3 }
					remove_trait = wounded_3
					add_trait = wounded_2
				}
			}

			#Risky treatment regular success
			else_if = {
				limit = {
					scope:treatment_result_treatment = flag:risky
					scope:treatment_result_outcome = flag:critical_success
				}
				add_character_modifier = { modifier = risky_wound_treatment_success_modifier days = wound_treatment_success_duration }
			}
		}
	}
	###FAILURE###
	else_if = {
		limit = { scope:treatment_result_outcome = flag:failure }

		#Safe treatment failure
		if = {
			limit = { scope:treatment_result_treatment = flag:safe }
			add_character_modifier = { modifier = safe_wound_treatment_failure_modifier days = wound_treatment_failure_duration }
		}
		if = {
			limit = { scope:treatment_result_treatment = flag:risky }
			add_character_modifier = { modifier = risky_wound_treatment_failure_modifier days = wound_treatment_failure_duration }
		}
	}
}



wound_treatment_result_tooltip_effect = {
	save_temporary_scope_value_as = {
		name = treatment_result_treatment
		value = flag:$TREATMENT$
	}
	save_temporary_scope_value_as = {
		name = treatment_result_outcome
		value = flag:$OUTCOME$
	}
	#Show death or treatment outcome
	if = {
		limit = { scope:sick_character = { is_alive = no } }
		custom_tooltip = health.3200.death.tt
	}
	else = {
		show_as_tooltip = {
			scope:sick_character = {
				add_wound_treatment_modifier_effect = { TREATMENT = $TREATMENT$ OUTCOME = $OUTCOME$ }

				if = {
					limit = { has_variable = treatment_strategy }
					if = {
						limit = { var:treatment_strategy = flag:amputation }
						add_trait_force_tooltip = one_legged
					}
					else_if = {
						limit = { var:treatment_strategy = flag:disfigurement }
						add_trait_force_tooltip = disfigured
					}
					else_if = {
						limit = { var:treatment_strategy = flag:eye }
						add_trait_force_tooltip = one_eyed
					}
					else_if = {
						limit = { 
							var:treatment_strategy = flag:castration
							age >= 12
						}
						add_trait_force_tooltip = eunuch_1
					}
					else_if = {
						limit = { 
							var:treatment_strategy = flag:castration
							age < 12
						}
						add_trait_force_tooltip = beardless_eunuch
					}
				}
			}
		}
	}
}

wound_treatment_results_effect = {
	save_temporary_scope_value_as = {
		name = treatment_result_treatment
		value = flag:$TREATMENT$
	}
	save_temporary_scope_value_as = {
		name = treatment_result_outcome
		value = flag:$OUTCOME$
	}

	#APPLY MODIFIERS (OR REMOVE TRAITS)
	add_wound_treatment_modifier_effect = { TREATMENT = $TREATMENT$ OUTCOME = $OUTCOME$ }

	#RISKY TREATMENT: DETERMINING TREATMENT STRATEGY AND REMOVING BODY PART
	if = {
		limit = { scope:treatment_result_treatment = flag:risky }
		random_list = {
			1 = { #Medicine
				trigger = {
					OR = { #Only use for gangrene if no body part can be removed
						NOT = { has_character_modifier = gangrene_modifier }
						AND = {
							has_character_modifier = gangrene_modifier
							has_trait = one_eyed
							has_trait = one_legged
							has_trait = disfigured
							OR = {
								is_female = yes
								is_eunuch_trigger = yes
							}
						}
					}
				}
				set_variable = {
					name = treatment_strategy
					value = flag:medicine
					days = 30
				}
			}
			1 = { #Amputation
				trigger = {
					NOT = { has_trait = one_legged }
					OR = {
						has_infected_or_gangrenous_wound_trigger = yes
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				add_trait_force_tooltip = one_legged
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:amputation
					days = 30
				}
				if = {
					limit = { has_infected_or_gangrenous_wound_trigger = no }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
			1 = { #Disfigurement
				trigger = {
					NOT = { has_trait = disfigured }
					scope:treatment_result_outcome = flag:failure
					scope:physician = { NOT = { has_trait = lifestyle_physician } }
				}
				add_trait_force_tooltip = disfigured
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:disfigurement
					days = 30
				}
			}
			1 = { #Castration
				trigger = {
					is_male = yes
					is_eunuch_trigger = no
					OR = {
						has_infected_or_gangrenous_wound_trigger = yes
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				if = {
					limit = {
						age >= 12
					}
					add_trait_force_tooltip = eunuch_1
				}
				else = {
					add_trait_force_tooltip = beardless_eunuch
				}
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:castration
					days = 30
				}
				if = {
					limit = { has_infected_or_gangrenous_wound_trigger = no }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
			1 = { #Remove eye
				trigger = {
					NOT = { has_trait = one_eyed }
					OR = {
						has_infected_or_gangrenous_wound_trigger = yes
						AND = {
							scope:treatment_result_outcome = flag:failure
							scope:physician = { NOT = { has_trait = lifestyle_physician } }
						}
					}
				}
				add_trait_force_tooltip = one_eyed
				increase_wounds_no_death_effect = { REASON = treatment }
				set_variable = {
					name = treatment_strategy
					value = flag:eye
					days = 30
				}
				if = {
					limit = { has_infected_or_gangrenous_wound_trigger = no }
					add_character_flag = { flag = physician_used_wrong_method days = 30 }
				}
			}
		}

		#Fallback
		if = {
			limit = { NOT = { exists = var:treatment_strategy } }
			set_variable = {
				name = treatment_strategy
				value = flag:medicine
				days = 30
			}
		}
	}

	#RISKY TREATMENT FAILURE: DEATH?
	if = {
		limit = {
			scope:treatment_result_treatment = flag:risky
			scope:treatment_result_outcome = flag:failure
			OR = {
				AND = { #Dies from wound upgrading past lvl 3
					has_trait = wounded_3
					OR = {
						var:treatment_strategy = flag:amputation
						var:treatment_strategy = flag:disfigurement
						var:treatment_strategy = flag:eye
						var:treatment_strategy = flag:castration
					}
				}
				AND = { #AIs die immediately if their health is reduced to 0 or below
					is_ai = yes
					health <= 0
				}
			}
		}
		add_character_flag = die_surgery
	}

	#RETURN VISIT TO THE DOCTOR!
	hidden_effect = {
		if = {
			limit = {
				has_trait = wounded
				NOT = { has_character_flag = die_surgery }
			}
			if = {
				limit = { scope:treatment_result_outcome = flag:failure  }
				trigger_event = {
					id = health.4999 #Sends health.4001 to me or 4002 to liege
					days = wound_treatment_failure_duration_plus_1
				}
			}
			else = {
				trigger_event = {
					id = health.4999 #Sends health.4001 to me or 4002 to liege
					days = wound_treatment_success_duration_plus_1
				}
			}
		}
	}

	#FAILED TREATMENT OPINIONS
	if = {
		limit = {
			scope:treatment_result_outcome = flag:failure
			OR = {
				scope:treatment_result_treatment = flag:risky
				scope:treatment_result_treatment = flag:mystic
			}
		}
		add_failed_treatment_of_kin_opinions_effect = yes
	}

	physician_rank_up_tooltip_effect = yes #Shows trait gain if physician ranked up
}








###DISEASE TREATMENT LOGIC###
save_health_court_owner_effect = { #Should match has_health_court_owner_trigger
	if = {
		limit = { exists = imprisoner }
		imprisoner = { save_scope_as = $SCOPE_NAME$ }
	}
	else_if = {
		limit = { exists = court_owner } #Courtiers: liege. Guest: host. Ruler: themselves.
		court_owner = { save_scope_as = $SCOPE_NAME$ }
	}
}

pick_own_disease_treatment_effect = {
	if = {
		limit = { is_adult = yes }
		custom_tooltip = pick_own_treatment_effect.adult.tt
	}
	else = {
		custom_tooltip = pick_own_treatment_effect.child.tt
	}

	hidden_effect = {
		trigger_event = {
			id = health.3101
			days = { 5 10 }
		}	
	}
}

#Who treats a sick character?
decide_who_picks_disease_treatment_effect = {
	if = {
		limit = {
			liege_picks_treatment_trigger = yes
		}
		liege = {
			trigger_event = {
				id = health.3102 #Liege decides
				days = { physician_treatment_delay_subject_min physician_treatment_delay_subject_max }
			}
		}
	}
	else = {
		trigger_event = {
			id = health.3101 #I decide
			days = { physician_treatment_delay_ruler_min physician_treatment_delay_ruler_max }
		}
	}
}

liege_picks_treatment_effect = {
	if = {
		limit = {
			liege_picks_treatment_trigger = yes
		}
		liege = {
			trigger_event = {
				id = health.3102 #Liege decides
				days = { 5 10 }
			}
		}
	}
}

remove_disease_treatment_effect = {
	hidden_effect = {
		if = {
			limit = {
				has_treatable_disease_trigger = no
			}
			remove_character_modifier = safe_disease_treatment_success_high_modifier
			remove_character_modifier = safe_disease_treatment_success_low_modifier
			remove_character_modifier = safe_disease_treatment_failure_modifier
			remove_character_modifier = risky_disease_treatment_success_high_modifier
			remove_character_modifier = risky_disease_treatment_success_low_modifier
			remove_character_modifier = risky_disease_treatment_failure_modifier

		}
	}
}

###WOUNDS TREATMENT LOGIC###

pick_own_wound_treatment_effect = {
	if = {
		limit = { is_adult = yes }
		custom_tooltip = pick_own_treatment_effect.adult.tt
	}
	else = {
		custom_tooltip = pick_own_treatment_effect.child.tt
	}

	hidden_effect = {
		trigger_event = {
			id = health.4001
			days = { 5 10 }
		}	
	}
}

decide_who_picks_wound_treatment_effect = {
	if = {
		limit = {
			liege_picks_treatment_trigger = yes
		}
		liege = {
			trigger_event = {
				id = health.4002 #Liege decides
				days = { 10 20 }
			}
		}
	}
	else = {
		trigger_event = {
			id = health.4001 #I decide
			days = { 5 15 }
		}
	}
}



###FAILED TREAMENT EFFECTS###

add_failed_treatment_of_me_opinions_effect = {
#Physician scope is set in the events that reference this effect
	if = {
		limit = {
			scope:physician = {
				is_alive = yes
			}
			court_physician_available_trigger = yes
			this != scope:physician
		}
		if = {
			limit = {
				OR = {
					has_character_flag = physician_used_wrong_method
					scope:physician = { has_character_modifier = chastised_physician_modifier }
					scope:sick_character = {
						exists = var:treatment_strategy
						OR = {
							var:treatment_strategy = flag:amputation
							var:treatment_strategy = flag:disfigurement
							var:treatment_strategy = flag:eye
							var:treatment_strategy = flag:castration
						}
					}
				}
			}
			hidden_effect = {
				add_opinion = {
					target = scope:physician
					modifier = botched_my_treatment_crime_opinion
				}
			}
			show_as_tooltip = {
				add_opinion = {
					target = scope:physician
					modifier = botched_my_treatment_crime_opinion
				}
			}
		}
		else = {
			hidden_effect = {
				add_opinion = {
					target = scope:physician
					modifier = failed_to_treat_me_crime_opinion
				}
			}
			show_as_tooltip = {
				add_opinion = {
					target = scope:physician
					modifier = failed_to_treat_me_opinion
				}
			}
		}
	}
}

add_failed_treatment_of_kin_opinions_effect = {
#Physician scope is set in the events that reference this effect
	hidden_effect = {
		if = {
			limit = {
				scope:physician = {
					is_alive = yes
				}
				court_physician_available_trigger = yes
				this != scope:physician
			}
			every_close_family_member = {
				add_to_temporary_list = failed_treatment_opinion
			}
			every_heir_title = {
				limit = {
					exists = holder
				}
				holder = {
					if = {
						limit = {
							player_heir = scope:sick_character
							NOT = { is_in_list = failed_treatment_opinion }
						}
						add_to_temporary_list = failed_treatment_opinion
					}
				}
			}
			every_in_list = {
				list = failed_treatment_opinion
				limit = {
					this != scope:physician
				}
				if = {
					limit = {
						scope:sick_character = {
							has_character_flag = die_risky_treatment
							is_alive = no
							has_character_flag = physician_used_wrong_method
							scope:physician = { has_character_modifier = chastised_physician_modifier }
							trigger_if = {
								limit = { has_variable = treatment_strategy }
								OR = {
									var:treatment_strategy = flag:amputation
									var:treatment_strategy = flag:disfigurement
									var:treatment_strategy = flag:eye
									var:treatment_strategy = flag:castration
									var:treatment_strategy = flag:occult
									var:treatment_strategy = flag:occult_cannibal
									var:treatment_strategy = flag:occult_deviant
								}
							}
						}
					}
					
					add_opinion = {
						target = scope:physician
						modifier = botched_treatment_of_kin_crime_opinion
					}
				}
				else = {
					add_opinion = {
						target = scope:physician
						modifier = failed_to_treat_kin_crime_opinion
					}
				}
			}
		}
	}
}


downgrade_failed_treatment_of_me_opinions_effect = {
	#Physician scope is set in the events that reference this effect
	hidden_effect = {
		if = {
			limit = {
				scope:physician = {
					is_alive = yes
				}
				court_physician_available_trigger = yes
			}
			if = {
				limit = {
					has_opinion_modifier = {
						target = scope:physician
						modifier = botched_my_treatment_crime_opinion
					}
				}
				remove_opinion = {
					target = scope:physician
					modifier = botched_my_treatment_crime_opinion
				}
				add_opinion = {
					#add nice opinion version
					target = scope:physician
					modifier = botched_my_treatment_crime_opinion
				}
			}
			if = {
				limit = {
					has_opinion_modifier = {
						target = scope:physician
						modifier = failed_to_treat_me_crime_opinion
					}
				}
				remove_opinion = {
					target = scope:physician
					modifier = failed_to_treat_me_crime_opinion
				}
				add_opinion = {
					target = scope:physician
					modifier = failed_to_treat_me_opinion
				}
			}
		}
	}
}

downgrade_failed_treatment_of_kin_opinions_effect = {
	hidden_effect = {
		if = {
			limit = {
				has_opinion_modifier = {
					target = scope:physician
					modifier = botched_treatment_of_kin_crime_opinion
				}
			}
			remove_opinion = {
				target = scope:physician
				modifier = botched_treatment_of_kin_crime_opinion
			}
			add_opinion = {
				#add nice opinion version
				target = scope:physician
				modifier = botched_treatment_of_kin_opinion
			}
		}
		if = {
			limit = {
				has_opinion_modifier = {
					target = scope:physician
					modifier = failed_to_treat_kin_crime_opinion
				}
			}
			remove_opinion = {
				target = scope:physician
				modifier = failed_to_treat_kin_crime_opinion
			}
			add_opinion = {
				target = scope:physician
				modifier = failed_to_treat_kin_opinion
			}
		}
	}
}


execute_physician_effect = {
	execute_prisoner_effect = {
		VICTIM = scope:physician
		EXECUTIONER = root
	}

	
	stress_impact = {
		compassionate = major_stress_impact_gain
		just = minor_stress_impact_gain
		forgiving = medium_stress_impact_gain
	}
}

imprison_physician_effect = {
	custom_tooltip = health.3107.d.tt
		
	imprison_character_effect = {
		TARGET = scope:physician
		IMPRISONER = root
	}

	root = { remove_relation_court_physician = scope:physician }

	stress_impact = {
		compassionate = medium_stress_impact_gain
		just = minor_stress_impact_gain
		forgiving = minor_stress_impact_gain
	}
}

chastise_physician_effect = {
	scope:physician = {
		add_character_modifier = {
			modifier = chastised_physician_modifier
			years = 5
		}
	}
	if = {
		limit = {
			exists = scope:sick_character
			scope:sick_character = { this = root }
		}
		downgrade_failed_treatment_of_me_opinions_effect = yes #You can no longer punish them
	}
	else_if = {
		limit = {
			exists = scope:sick_character
		}
		downgrade_failed_treatment_of_kin_opinions_effect = yes #You can no longer punish them
	}

	stress_impact = {
		vengeful = medium_stress_impact_gain
	}
}

forgive_physician_effect = {
	if = {
		limit = {
			exists = scope:sick_character
			scope:sick_character = { this = root }
		}
		downgrade_failed_treatment_of_me_opinions_effect = yes #You can no longer punish them
	}
	else_if = {
		limit = {
			exists = scope:sick_character
		}
		downgrade_failed_treatment_of_kin_opinions_effect = yes #You can no longer punish them
	}

	reverse_add_opinion = {
		target = scope:physician
		modifier = grateful_opinion
		opinion = 15
	}
	
	stress_impact = {
		vengeful = major_stress_impact_gain
		wrathful = medium_stress_impact_gain
	}
}

###DISEASE MESSAGES###

inform_liege_about_disease_treatment_effect = {
	hidden_effect = {
		save_scope_value_as = {
			name = treatment
			value = flag:$TREATMENT$
		}
		save_scope_value_as = {
			name = outcome
			value = flag:$OUTCOME$
		}

		#To save scope for portrait
		if = {
			limit = {
				scope:physician != scope:sick_character
			}
			scope:physician = { save_scope_as = portrait }
		}
		
		#Is liege generally responsible for our treatment?
		if = {
			limit = { liege_is_responsible_for_treatment_trigger = yes }

			#Toast messages for success and minor failures: only if liege actually picked the treatment
			#Event for major failures and death: always

			liege = {
				#CRITICAL SUCCESS & SUCCESS (TOAST)
				if = {
					limit = {
						exists = scope:treatment_picker
						this = scope:treatment_picker
						OR = {
							scope:outcome = flag:success
							scope:outcome = flag:critical_success
						}
					}
					send_interface_toast = {
						title = court_physician_treatment_success_message_title
						left_icon = scope:sick_character
						right_icon = scope:portrait
						disease_treatment_result_tooltip_effect = { TREATMENT = $TREATMENT$ OUTCOME = $OUTCOME$ }
					}
				}
				#FAILURE
				else_if = {
					limit = { scope:outcome = flag:failure }
					#SAFE FAILURE (TOAST)
					if = {
						limit = {
							exists = scope:treatment_picker
							this = scope:treatment_picker
							scope:treatment = flag:safe
						}
						send_interface_toast = {
							title = court_physician_treatment_failure_message_title
							left_icon = scope:sick_character
							right_icon = scope:portrait
							wound_treatment_result_tooltip_effect = { TREATMENT = $TREATMENT$ OUTCOME = $OUTCOME$ }
						}
					}
					#RISKY FAILURE (EVENT)
					else_if = {
						limit = { scope:treatment = flag:risky }
						save_scope_value_as = {
							name = disease_or_wound
							value = flag:disease
						}
						trigger_event = health.3200
					}
					#MYSTIC FAILURE (EVENT)
					else_if = {
						limit = { scope:treatment = flag:mystic }
						trigger_event = health.3201 
						#reveal secret in this event
					}
				}
				#DEATH (EVENT)
				else_if = {
					limit = { scope:outcome = flag:death }

					add_character_flag = {
						flag = sent_relevant_death_event #This blocks further death events triggered by death_management.0001
						days = 5
					}
					trigger_event = health.3200
				}
			}
		}
	}
}

### WOUND MESSAGES ###

inform_liege_about_wound_treatment_effect = {
	hidden_effect = {
		save_scope_value_as = {
			name = treatment
			value = flag:$TREATMENT$
		}
		save_scope_value_as = {
			name = outcome
			value = flag:$OUTCOME$
		}
		
		
		#Is liege generally responsible for our treatment?
		if = {
			limit = { liege_is_responsible_for_treatment_trigger = yes }

			#Success and minor failure: no message
			#Major failure and death: event

			liege = {
				#RISKY FAILURE
				if = {
					limit = {
						scope:outcome = flag:failure
						scope:treatment = flag:risky
					}
					save_scope_value_as = {
						name = disease_or_wound
						value = flag:wound
					}
					trigger_event = health.3200
				}
				#RISKY DEATH
				else_if = {
					limit = { scope:outcome = flag:death }
					
					save_scope_value_as = {
						name = disease_or_wound
						value = flag:wound
					}
					add_character_flag = {
						flag = sent_relevant_death_event #This blocks further death events triggered by death_management.0001
						days = 5
					}
					trigger_event = health.3200
				}
			}
		}
	}
}

#Currently no message to liege because liege never picks wound treatment and safe success is not noteworthy


#Effect run when you commit suicide
committed_suicide_effect = {
	if = {
		limit = {
			any_vassal = { }
		}
		every_vassal = {
			custom = all_vassals
			add_opinion = {
				modifier = suicide_opinion
				target = root
				opinion = -30
			}
		}
	}
	if = {
		limit = {
			is_ai = yes
			exists = dynasty
		}
		dynasty = {
			add_dynasty_prestige = medium_dynasty_prestige_loss
		}
	}
	else_if = {
		limit = { exists = dynasty }
		dynasty = {
			add_dynasty_prestige_level = -1
		}
	}
	add_piety_level = -1
	death = {
		death_reason = death_suicide
	}
}

#Effect run when you attempt to commit suicide
attempted_suicide_effect = {
	add_piety_level = -1
}

# Remove infirm when adding incapable so that the player doesn't just immediately die.
upgrade_infirm_to_incapable_effect = {
	# Stealthily remove infirm
	hidden_effect = {
		if = {
			limit = { has_trait = infirm }
			remove_trait = infirm
		}
	}
	# And add in capable.
	add_trait = incapable
	# Logging.
	log_harm_event_incapability_as_variable_effect = yes
}
