###TRAIT ADDING EFFECTS###
#Add new ones in alphabetical order.

#With notification
add_trait_ambitious_effect = {
	if = {
		limit = {
			NOR = {
				trait = ambitious
				trait = content
			}
		}
		add_trait = ambitious
		hidden_tooltip = { character_event = { id = 38278 } }
	}
}

add_trait_arbitrary_effect = {
	if = {
		limit = {
			NOR = {
				trait = arbitrary
				trait = just
			}
		}
		add_trait = arbitrary
		hidden_tooltip = { character_event = { id = 38266 } }
	}
}

add_trait_brave_effect  = {
	if = {
		limit = { 
			NOR = { 
				trait = brave 
				trait = craven
			}
		} 
		add_trait = brave
		hidden_tooltip = { character_event = { id = 38270 } }
	}
}


add_trait_charitable_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = charitable
				trait = greedy
			}
		} 
		add_trait = charitable
		hidden_tooltip = { character_event = { id = 38273 } } # Notify Charitable
	}
}

add_trait_chaste_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = chaste 
				trait = lustful
			}
		} 
		add_trait = chaste
		hidden_tooltip = { character_event = { id = 38274 } }
	}
}

add_trait_craven_effect  = {
	if = {
		limit = { 
			NOR = { 
				trait = brave 
				trait = craven
			}
		} 
		add_trait = craven
		hidden_tooltip = { character_event = { id = 38257 } }
	}
}

add_trait_cruel_effect  = {
	if = {
		limit = { 
			NOR = { 
				trait = cruel 
				trait = kind
			}
		} 
		add_trait = cruel
		hidden_tooltip = { character_event = { id = 38259 } }
	}
}

add_trait_cynical_effect = {
	if = {
		limit = {
			NOR = {
				trait = cynical
				trait = zealous
			}
		}
		add_trait = cynical
		hidden_tooltip = { character_event = { id = 38258 } } #notify cynical
	}
}

add_trait_deceitful_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = deceitful 
				trait = honest
			} 
		}
		add_trait = deceitful
		hidden_tooltip = { character_event = { id = 38255 } }
	}
}

add_trait_depressed_effect = {
	if = {
		limit = { NOT = { trait = depressed } }
		add_trait = depressed
		hidden_tooltip = { character_event = { id = 38288 } }
	}
}

add_trait_diligent_effect = {
	if = {
		limit = {
			NOR = {
				trait = diligent
				trait = slothful
			}
		}
		add_trait = diligent
		hidden_tooltip = { character_event = { id = 38256 } } #notify diligent
	}
}

add_trait_envious_effect = {
	if = {
		limit = {
			NOR = {
				trait = kind
				trait = envious
			}
		}
		add_trait = envious
		hidden_tooltip = { character_event = { id = 38271 } }
	}	
}

add_trait_gluttonous_effect = {
	if = {
		limit = {
			NOR = {
				trait = temperate
				trait = gluttonous
			}
		}
		add_trait = gluttonous
		hidden_tooltip = { character_event = { id = 38277 } } #Notify Gluttonous
	}
}

add_trait_greedy_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = greedy 
				trait = charitable
			}
		} 
		add_trait = greedy
		hidden_tooltip = { character_event = { id = 38252 } }
	}
}

add_trait_gregarious_effect = {
	if = {
		limit = {
			NOR = {
				trait = gregarious
				trait = shy
			}
		}
		add_trait = gregarious
		hidden_tooltip = { character_event = { id = 38265 } }
	}
}

add_trait_honest_effect = {
	if = {
		limit = {
			NOR = {
				trait = honest
				trait = deceitful
			}
		}
		add_trait = honest
		hidden_tooltip = { character_event = { id = 38262 } } #Notify Honest
	}
}

add_trait_kind_effect = {
	if = {
		limit = {
			NOR = {
				trait = kind
				trait = envious
				trait = cruel
			}
		}
		add_trait = kind
		hidden_tooltip = { character_event = { id = 38268 } }
	}	
}

add_trait_lustful_effect = {
	if = {
		limit = {
			NOR = {
				trait = lustful
				trait = chaste
			}
		}
		add_trait = lustful
		hidden_tooltip = { character_event = { id = 38272 } }
	}
}

add_trait_one_eyed_effect = {
	if = {
		limit = {
			NOR = {
				trait = one_eyed
				trait = blinded
			}
		}
		add_trait = one_eyed
		hidden_tooltip = { character_event = { id = RIP.11501 } }
		add_trait_severely_injured_effect = yes
		
	}
}

add_trait_one_handed_effect = {
	if = {
		limit = { NOT = { trait = one_handed } }
		add_trait = one_handed
		hidden_tooltip = { character_event = { id = RIP.11502 } }
		add_trait_severely_injured_effect = yes
	}
}

add_trait_paranoid_effect = {
	if = {
		limit = {
			NOR = {
				trait = trusting
				trait = paranoid
			}
		}
		add_trait = paranoid
		hidden_tooltip = { character_event = { id = 38275 } } #Notify Paranoid
	}
}

add_trait_patient_effect = {
	if = {
		limit = {
			NOR = {
				trait = patient
				trait = wroth
			}
		}
		add_trait = patient
		hidden_tooltip = { character_event = { id = 38264 } } # Notify Patient
	}
}

add_trait_possessed_effect = {
	if = {
		limit = {
			NOT = {
				trait = possessed
			}
		}
		add_trait = possessed
		hidden_tooltip = { character_event = { id = 38315 } } # Notify Possessed
	}
}

add_trait_proud_effect = {
	if = {
		limit = {
			NOR = {
				trait = proud
				trait = humble
			}
		}
		add_trait = proud
		hidden_tooltip = { character_event = { id = 38261 } } # Notify Proud
	}
}

add_trait_severely_injured_effect = {
	if = {
		limit = { NOT = { trait = severely_injured } }
		add_trait = severely_injured

		hidden_tooltip = {
			random_list = {
				75 = { #Get rid of severely_injured
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
				25 = { #Get rid of severely_injured but develop infection
					set_character_flag = pending_infection
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
			}
		}
	}
}

add_trait_shy_effect = {
	if = {
		limit = {
			NOR = {
				trait = gregarious
				trait = shy
			}
		}
		add_trait = shy
		hidden_tooltip = { character_event = { id = 38295 } }
	}
}

add_trait_slothful_effect = {
	if = {
		limit = {
			NOR = {
				trait = diligent
				trait = slothful
			}
		}
		add_trait = slothful
		hidden_tooltip = { character_event = { id = 38251 } } #notify slothful
	}
}

add_trait_stressed_effect = {
	if = {
		limit = {
			NOR = {
				trait = stressed
				trait = depressed
			}
		}
		add_trait = stressed
		hidden_tooltip = { character_event = { id = 38282 } } #notify stressed
	}
}

add_trait_temperate_effect = {
	if = {
		limit = {
			NOR = {
				trait = temperate
				trait = gluttonous
			}
		}
		add_trait = temperate
		hidden_tooltip = { character_event = { id = 38276 } } #Notify Temperate
	}
}

add_trait_trusting_effect = {
	if = {
		limit = {
			NOR = {
				trait = trusting
				trait = paranoid
			}
		}
		add_trait = trusting
		hidden_tooltip = { character_event = { id = 38250 } } #Notify Trusting
	}
}

add_trait_wounded_effect = {
	if = {
		limit = { NOT = { trait = wounded } }
		add_trait = wounded
		hidden_tooltip = { character_event = { id = 38280 } }
	}
}

add_trait_wroth_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = wroth 
				trait = patient
			}
		} 
		add_trait = wroth
		hidden_tooltip = { character_event = { id = 38254 } }
	}
}

add_trait_zealous_effect = {
	if = {
		limit = {
			NOR = {
				trait = cynical
				trait = zealous
			}
		}
		add_trait = zealous
		hidden_tooltip = { character_event = { id = 38269 } }
	}
}

#Without notification
add_trait_silently_ambitious_effect = {
	if = {
		limit = {
			NOR = {
				trait = ambitious
				trait = content
			}
		}
		add_trait = ambitious
	}
}

add_trait_silently_arbitrary_effect = {
	if = {
		limit = {
			NOR = {
				trait = arbitrary
				trait = just
			}
		}
		add_trait = arbitrary
	}
}

add_trait_silently_brave_effect  = {
	if = {
		limit = { 
			NOR = { 
				trait = brave 
				trait = craven
			}
		} 
		add_trait = brave
	}
}


add_trait_silently_charitable_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = charitable
				trait = greedy
			}
		} 
		add_trait = charitable
	}
}

add_trait_silently_chaste_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = chaste 
				trait = lustful
			}
		} 
		add_trait = chaste
	}
}

add_trait_silently_craven_effect  = {
	if = {
		limit = { 
			NOR = { 
				trait = brave 
				trait = craven
			}
		} 
		add_trait = craven
	}
}

add_trait_silently_cruel_effect  = {
	if = {
		limit = { 
			NOR = { 
				trait = cruel 
				trait = kind
			}
		} 
		add_trait = cruel
	}
}

add_trait_silently_cynical_effect = {
	if = {
		limit = {
			NOR = {
				trait = cynical
				trait = zealous
			}
		}
		add_trait = cynical
	}
}

add_trait_silently_deceitful_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = deceitful 
				trait = honest
			} 
		}
		add_trait = deceitful
	}
}

add_trait_silently_depressed_effect = {
	if = {
		limit = { NOT = { trait = depressed } }
		add_trait = depressed
	}
}

add_trait_silently_diligent_effect = {
	if = {
		limit = {
			NOR = {
				trait = diligent
				trait = slothful
			}
		}
		add_trait = diligent
	}
}

add_trait_silently_envious_effect = {
	if = {
		limit = {
			NOR = {
				trait = kind
				trait = envious
			}
		}
		add_trait = envious

	}	
}

add_trait_silently_gluttonous_effect = {
	if = {
		limit = {
			NOR = {
				trait = temperate
				trait = gluttonous
			}
		}
		add_trait = gluttonous
	}
}

add_trait_silently_greedy_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = greedy 
				trait = charitable
			}
		} 
		add_trait = greedy
	}
}

add_trait_silently_gregarious_effect = {
	if = {
		limit = {
			NOR = {
				trait = gregarious
				trait = shy
			}
		}
		add_trait = gregarious
	}
}

add_trait_silently_honest_effect = {
	if = {
		limit = {
			NOR = {
				trait = honest
				trait = deceitful
			}
		}
		add_trait = honest
	}
}

add_trait_silently_humble_effect = {
	if = {
		limit = {
			NOR = {
				trait = humble
				trait = proud
			}
		}
		add_trait = humble
	}
}

add_trait_silently_kind_effect = {
	if = {
		limit = {
			NOR = {
				trait = kind
				trait = envious
				trait = cruel
			}
		}
		add_trait = kind

	}	
}

add_trait_silently_lustful_effect = {
	if = {
		limit = {
			NOR = {
				trait = lustful
				trait = chaste
			}
		}
		add_trait = lustful
	}
}

add_trait_silently_one_eyed_effect = {
	if = {
		limit = {
			NOR = {
				trait = one_eyed
				trait = blinded
			}
		}
		add_trait = one_eyed

		add_trait_silently_severely_injured_effect = yes
		
	}
}

add_trait_silently_one_handed_effect = {
	if = {
		limit = { NOT = { trait = one_handed } }
		add_trait = one_handed

		add_trait_silently_severely_injured_effect = yes
	}
}

add_trait_silently_patient_effect = {
	if = {
		limit = {
			NOR = {
				trait = patient
				trait = wroth
			}
		}
		add_trait = patient
	}
}

add_trait_silently_possessed_effect = {
	if = {
		limit = {
			NOT = {
				trait = possessed
			}
		}
		add_trait = possessed
	}
}

add_trait_silently_proud_effect = {
	if = {
		limit = {
			NOR = {
				trait = proud
				trait = humble
			}
		}
		add_trait = proud
	}
}

add_trait_silently_severely_injured_effect = {
	if = {
		limit = { NOT = { trait = severely_injured } }
		add_trait = severely_injured

		hidden_tooltip = {
			random_list = {
				75 = { #Get rid of severely_injured
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
				25 = { #Get rid of severely_injured but develop infection
					set_character_flag = pending_infection
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
			}
		}
	}
}

add_trait_silently_shy_effect = {
	if = {
		limit = {
			NOR = {
				trait = gregarious
				trait = shy
			}
		}
		add_trait = shy
	}
}

add_trait_silently_slothful_effect = {
	if = {
		limit = {
			NOR = {
				trait = diligent
				trait = slothful
			}
		}
		add_trait = slothful
	}
}

add_trait_silently_temperate_effect = {
	if = {
		limit = {
			NOR = {
				trait = temperate
				trait = gluttonous
			}
		}
		add_trait = temperate
	}
}

add_trait_silently_wounded_effect = {
	if = {
		limit = { NOT = { trait = wounded } }
		add_trait = wounded
	}
}

add_trait_silently_wroth_effect = {
	if = {
		limit = { 
			NOR = { 
				trait = wroth 
				trait = patient
			}
		} 
		add_trait = wroth
	}
}

#TRAIT REMOVAL EFFECTS
#Add new ones in alphabetical order.

#Add with notification
remove_trait_charitable_effect = {
	if = {
		limit = { trait = charitable }
		remove_trait = charitable
	}
}

remove_trait_chaste_effect = {
	if = {
		limit = { trait = chaste }
		remove_trait = chaste
		hidden_tooltip = { character_event = {	id = 38303 } } #Notify Removed Chaste
	}
}

remove_trait_content_effect = {
	if = {
		limit = { trait = content }
		remove_trait = content
		hidden_tooltip = { character_event = {	id = 38299 } }
	}
}

remove_trait_craven_effect = {
	if = {
		limit = { trait = craven }
		remove_trait = craven
		hidden_tooltip = { character_event = { id = 38296 } }
	}	
}

remove_trait_cruel_effect = {
	if = {
		limit = { trait = cruel }
		remove_trait = cruel
	}	
}

remove_trait_depressed_effect = {
	if = {
		limit = { trait = depressed }
		remove_trait = depressed
		hidden_tooltip = { character_event = { id = 38314 } }
	}
}

remove_trait_diligent_effect = {
	if = {
		limit = { trait = diligent }
		remove_trait = diligent
		hidden_tooltip = { character_event = { id = 38319 } }
	}
}

remove_trait_envious_effect = {
	if = {
		limit = { trait = envious }
		remove_trait = envious
	}
}

remove_trait_gregarious_effect = {
	if = {
		limit = { trait = gregarious }
		remove_trait = gregarious
		hidden_tooltip = { character_event = { id = 38297 } }
	}
}

remove_trait_honest_effect = {
	if = {
		limit = { trait = honest }
		remove_trait = honest
		hidden_tooltip = { character_event = { id = 38311 } }
	}
}

remove_trait_humble_effect = {
	if = {
		limit = { trait = humble }
		remove_trait = humble
	}
}

remove_trait_just_effect = {
	if = {
		limit = { trait = just }
		remove_trait = just
		hidden_tooltip = { character_event = { id = 38317 } }
	}
}

remove_trait_kind_effect = {
	if = {
		limit = { trait = kind }
		remove_trait = kind
		hidden_tooltip = { character_event = { id = 38307 } }
	}	
}

remove_trait_patient_effect = {
	if = {
		limit = { trait = patient }
		remove_trait = patient
	}	
}

remove_trait_proud_effect = {
	if = {
		limit = { trait = proud }
		remove_trait = proud
	}	
}

remove_trait_shy_effect = {
	if = {
		limit = { trait = shy }
		remove_trait = shy
		hidden_tooltip = { character_event = { id = 38295 } }
	}
}

remove_trait_slothful_effect = {
	if = {
		limit = { trait = slothful }
		remove_trait = slothful
		hidden_tooltip = {
			character_event = {
				id = 38298 #Notify Remove Slothful
			}
		}
	}
}

remove_trait_temperate_effect = {
	if = {
		limit = { trait = temperate }
		remove_trait = temperate
		hidden_tooltip = { character_event = { id = 38311 } }
	}
}

remove_trait_trusting_effect = {
	if = {
		limit = { trait = trusting }
		remove_trait = trusting
	}
}

remove_trait_wroth_effect = {
	if = {
		limit = { trait = wroth }
		remove_trait = wroth
	}
}

remove_trait_zealous_effect = {
	if = {
		limit = { trait = zealous }
		remove_trait = zealous
		hidden_tooltip = { character_event = { id = 38310 } }
	}	
}

#Silently
remove_trait_silently_charitable_effect = {
	if = {
		limit = { trait = charitable }
		remove_trait = charitable
	}
}

remove_trait_silently_chaste_effect = {
	if = {
		limit = { trait = chaste }
		remove_trait = chaste
	}
}

remove_trait_silently_content_effect = {
	if = {
		limit = { trait = content }
		remove_trait = content
	}
}

remove_trait_silently_craven_effect = {
	if = {
		limit = { trait = craven }
		remove_trait = craven
	}	
}

remove_trait_silently_cruel_effect = {
	if = {
		limit = { trait = cruel }
		remove_trait = cruel
	}	
}

remove_trait_silently_diligent_effect = {
	if = {
		limit = { trait = diligent }
		remove_trait = diligent
	}
}

remove_trait_silently_gluttonous_effect = {
	if = {
		limit = { trait = gluttonous }
		remove_trait = gluttonous
	}
}

remove_trait_silently_greedy_effect = {
	if = {
		limit = { trait = greedy }
		remove_trait = greedy
	}
}

remove_trait_silently_gregarious_effect = {
	if = {
		limit = { trait = gregarious }
		remove_trait = gregarious
	}
}

remove_trait_silently_honest_effect = {
	if = {
		limit = { trait = honest }
		remove_trait = honest
	}
}

remove_trait_silently_humble_effect = {
	if = {
		limit = { trait = humble }
		remove_trait = humble
	}
}

remove_trait_silently_just_effect = {
	if = {
		limit = { trait = just }
		remove_trait = just
	}
}

remove_trait_silently_kind_effect = {
	if = {
		limit = { trait = kind }
		remove_trait = kind
	}	
}

remove_trait_silently_lustful_effect = {
	if = {
		limit = { trait = lustful }
		remove_trait = lustful
	}
}

remove_trait_silently_patient_effect = {
	if = {
		limit = { trait = patient }
		remove_trait = patient
	}	
}

remove_trait_silently_proud_effect = {
	if = {
		limit = { trait = proud }
		remove_trait = proud
	}	
}

remove_trait_silently_shy_effect = {
	if = {
		limit = { trait = shy }
		remove_trait = shy
	}
}

remove_trait_silently_slothful_effect = {
	if = {
		limit = { trait = slothful }
		remove_trait = slothful
	}
}

remove_trait_silently_temperate_effect = {
	if = {
		limit = { trait = temperate }
		remove_trait = temperate
	}
}

remove_trait_silently_trusting_effect = {
	if = {
		limit = { trait = trusting }
		remove_trait = trusting
	}
}

remove_trait_silently_wroth_effect = {
	if = {
		limit = { trait = wroth }
		remove_trait = wroth
	}
}

remove_trait_silently_zealous_effect = {
	if = {
		limit = { trait = zealous }
		remove_trait = zealous
	}	
}

###REAPER's DUE###
remove_patrons_effect = {
	remove_character_modifier = patron_shiva
	remove_character_modifier = patron_vishnu
	remove_character_modifier = patron_brahma
	remove_character_modifier = patron_kali
	remove_character_modifier = patron_ganesha
	remove_character_modifier = patron_ganga
}

increase_mercenary_troop_support_effect = {
	if = {
		limit = {
			has_mercenary_maintenance_modifier = maintaining_mercenary_band_6
		}
		set_mercenary_maintenance_modifier = maintaining_mercenary_band_7
		change_title_army_size = 0.3
	}
	if = {
		limit = {
			has_mercenary_maintenance_modifier = maintaining_mercenary_band_5
		}
		set_mercenary_maintenance_modifier = maintaining_mercenary_band_6
		change_title_army_size = 0.3
	}
	if = {
		limit = {
			has_mercenary_maintenance_modifier = maintaining_mercenary_band_4
		}
		set_mercenary_maintenance_modifier = maintaining_mercenary_band_5
		change_title_army_size = 0.3
	}
	if = {
		limit = {
			has_mercenary_maintenance_modifier = maintaining_mercenary_band_3
		}
		set_mercenary_maintenance_modifier = maintaining_mercenary_band_4
		change_title_army_size = 0.3
	}
	if = {
		limit = {
			has_mercenary_maintenance_modifier = maintaining_mercenary_band_2
		}
		set_mercenary_maintenance_modifier = maintaining_mercenary_band_3
		change_title_army_size = 0.3
	}
	if = {
		limit = {
			has_mercenary_maintenance_modifier = maintaining_mercenary_band
		}
		set_mercenary_maintenance_modifier = maintaining_mercenary_band_2
		change_title_army_size = 0.3
	}
}

increase_mercenary_ambition_level_effect = {
	if = {
		limit = {
			has_character_flag = mercenary_ambition_8
		}
		clr_character_flag = mercenary_ambition_8
		set_character_flag = mercenary_ambition_9
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_7
		}
		clr_character_flag = mercenary_ambition_7
		set_character_flag = mercenary_ambition_8
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_6
		}
		clr_character_flag = mercenary_ambition_6
		set_character_flag = mercenary_ambition_7
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_5
		}
		clr_character_flag = mercenary_ambition_5
		set_character_flag = mercenary_ambition_6
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_4
		}
		clr_character_flag = mercenary_ambition_4
		set_character_flag = mercenary_ambition_5
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_3
		}
		clr_character_flag = mercenary_ambition_3
		set_character_flag = mercenary_ambition_4
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_2
		}
		clr_character_flag = mercenary_ambition_2
		set_character_flag = mercenary_ambition_3
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_1
		}
		clr_character_flag = mercenary_ambition_1
		set_character_flag = mercenary_ambition_2
	}
}

decrease_mercenary_ambition_level_effect = {
	if = {
		limit = {
			has_character_flag = mercenary_ambition_2
		}
		clr_character_flag = mercenary_ambition_2
		set_character_flag = mercenary_ambition_1
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_3
		}
		clr_character_flag = mercenary_ambition_3
		set_character_flag = mercenary_ambition_2
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_4
		}
		clr_character_flag = mercenary_ambition_4
		set_character_flag = mercenary_ambition_3
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_5
		}
		clr_character_flag = mercenary_ambition_5
		set_character_flag = mercenary_ambition_4
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_6
		}
		clr_character_flag = mercenary_ambition_6
		set_character_flag = mercenary_ambition_5
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_7
		}
		clr_character_flag = mercenary_ambition_7
		set_character_flag = mercenary_ambition_6
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_8
		}
		clr_character_flag = mercenary_ambition_8
		set_character_flag = mercenary_ambition_7
	}
	if = {
		limit = {
			has_character_flag = mercenary_ambition_9
		}
		clr_character_flag = mercenary_ambition_9
		set_character_flag = mercenary_ambition_8
	}
}


add_symptom_effect = {
	custom_tooltip = {
		text = add_symptom_tooltip
		hidden_tooltip = {
			random_list = {
				10 = {
					modifier = {
						factor = 0
							trait = cough
					}
					character_event = { id = RIP.5000 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = fever

					}
					character_event = { id = RIP.5001 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = diarrhea

					}
					character_event = { id = RIP.5002 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = vomiting
					}
					character_event = { id = RIP.5003 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = headache
					}
					character_event = { id = RIP.5004 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = chest_pain
					}
					character_event = { id = RIP.5005 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = cramps
					}
					character_event = { id = RIP.5006 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = rash
					}
					character_event = { id = RIP.5007 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = abdominal_pain
					}
					character_event = { id = RIP.5008 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = fatigue
					}
					character_event = { id = RIP.5009 days = 1 }
				}
				10 = {
					modifier = {
						factor = 0
							trait = malaise
					}
					character_event = { id = RIP.5010 days = 1 }
				}
			}
		}
	}
}

add_maimed_trait_effect = {
	custom_tooltip = {
		text = maimed_effect_tooltip
		hidden_tooltip = {
			random_list = {
				10 = {
					modifier = {
						factor = 0
						has_dlc = "Reapers"
					}
					add_trait = maimed
					character_event = { id = 38281 }
				}
				15 = {
					modifier = {
						factor = 0
						OR = {
							trait = one_eyed
							trait = blinded
							NOT = { has_dlc = "Reapers" }
						}
					}
					add_trait = one_eyed
					character_event = { id = RIP.11501 }
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = one_legged
							NOT = { has_dlc = "Reapers" }
						}
					}
					add_trait = one_legged
					character_event = { id = RIP.11503 }
				}
				20 = {
					modifier = {
						factor = 0
						OR = {
							trait = one_handed
							NOT = { has_dlc = "Reapers" }
						}
					}
					add_trait = one_handed
					character_event = { id = RIP.11502 }
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = disfigured
							NOT = { has_dlc = "Reapers" }
						}
					}
					add_trait = disfigured
					character_event = { id = RIP.11504 }
				}
				5 = {
					modifier = {
						factor = 0
						OR = {
							trait = mangled
							NOT = { has_dlc = "Reapers" }
						}
					}
					add_trait = mangled
					character_event = { id = RIP.11505 }
				}
			}
		}
	}
	if = {
		limit = {
			AND = {
				has_dlc = "Reapers"
				NOT = { trait = severely_injured }
			}
		}
		add_trait = severely_injured
		hidden_tooltip = {
			random_list = {
				75 = { #Get rid of severely_injured
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
				25 = { #Get rid of severely_injured but develop infection
					set_character_flag = pending_infection
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
			}
		}
	}
}

add_plague_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = malaise
			}
			character_event = { id = RIP.5010 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = cramps
			}
			character_event = { id = RIP.5006 }
		}
	}
}

add_pneumonia_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = cough
			}
			character_event = { id = RIP.5000 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = chest_pain
			}
			character_event = { id = RIP.5005 }
		}
	}
}

add_syphilis_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = rash
			}
			character_event = { id = RIP.5007 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = headache
			}
			character_event = { id = RIP.5004 }
		}
	}
}

add_tuberculosis_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = cough
			}
			character_event = { id = RIP.5000 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = chest_pain
			}
			character_event = { id = RIP.5005 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fatigue
			}
			character_event = { id = RIP.5009 }
		}
	}
}

add_typhoid_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = diarrhea
			}
			character_event = { id = RIP.5002 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = abdominal_pain
			}
			character_event = { id = RIP.5008 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = malaise
			}
			character_event = { id = RIP.5010 }
		}
	}
}

add_typhus_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = diarrhea
			}
			character_event = { id = RIP.5002 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = abdominal_pain
			}
			character_event = { id = RIP.5008 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fatigue
			}
			character_event = { id = RIP.5009 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = rash
			}
			character_event = { id = RIP.5007 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = headache
			}
			character_event = { id = RIP.5004 }
		}
	}
}

add_measles_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = rash
			}
			character_event = { id = RIP.5007 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = cough
			}
			character_event = { id = RIP.5000 }
		}
	}
}

add_smallpox_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = rash
			}
			character_event = { id = RIP.5007 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = headache
			}
			character_event = { id = RIP.5004 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = malaise
			}
			character_event = { id = RIP.5010 }
		}
	}
}

add_flu_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = fatigue
			}
			character_event = { id = RIP.5009 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = headache
			}
			character_event = { id = RIP.5004 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = malaise
			}
			character_event = { id = RIP.5010 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = cough
			}
			character_event = { id = RIP.5000 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = abdominal_pain
			}
			character_event = { id = RIP.5008 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = diarrhea
			}
			character_event = { id = RIP.5002 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = vomiting
			}
			character_event = { id = RIP.5003 }
		}
	}
}

add_dysentery_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = diarrhea
			}
			character_event = { id = RIP.5002 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = abdominal_pain
			}
			character_event = { id = RIP.5008 }
		}
	}
}

add_gout_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = fatigue 
			}
			character_event = { id = RIP.5009 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
	}
}

add_food_poisoning_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = diarrhea
			}
			character_event = { id = RIP.5002 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = cramps
			}
			character_event = { id = RIP.5006 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = vomiting
			}
			character_event = { id = RIP.5003 }
		}
	}
}

add_rabies_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = malaise
			}
			character_event = { id = RIP.5010 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fever
			}
			character_event = { id = RIP.5001 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = fatigue
			}
			character_event = { id = RIP.5009 }
		}
	}
}

add_cancer_symptom_effect = {
	random_list = {
		10 = {
			modifier = {
				factor = 0
				trait = fatigue
			}
			character_event = { id = RIP.5009 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = chest_pain
			}
			character_event = { id = RIP.5005 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = headache
			}
			character_event = { id = RIP.5004 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = malaise
			}
			character_event = { id = RIP.5010 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = cough
			}
			character_event = { id = RIP.5000 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = abdominal_pain
			}
			character_event = { id = RIP.5008 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = diarrhea
			}
			character_event = { id = RIP.5002 }
		}
		10 = {
			modifier = {
				factor = 0
				trait = vomiting
			}
			character_event = { id = RIP.5003 }
		}
	}
}

increase_depopulation_effect = {
	if = {
		limit = {
			has_province_modifier = depopulated_2
		}
		random_list = {		
			40 = {
				modifier = {
					factor = 1.5
					any_province_holding = {
						OR = {
							holding_type = nomad
							holding_type = tribal
						}
					}
					NOT = { num_of_settlements = 3 }
				}
				modifier = {
					factor = 1.2
					hospital_level = 1
				}
				modifier = {
					factor = 1.2
					hospital_level = 2
				}
				modifier = {
					factor = 1.2
					hospital_level = 3
				}
				modifier = {
					factor = 1.2
					hospital_level = 4
				}
				modifier = {
					factor = 1.2
					hospital_level = 5
				}
				modifier = {
					factor = 1.2
					hospital_level = 6
				}
			}
			60 = {
				modifier = {
					factor = 0
					any_province_holding = {
						NOR = {
							holding_type = city
							holding_type = temple
							holding_type = castle
							holding_type = tribal
						}
					}
				}
				remove_province_modifier = depopulated_2
				add_province_modifier = {
					name = depopulated_3
					duration = -1
				}
				clr_province_flag = recent_depopulation_2
				set_province_flag = recent_depopulation_3
			}
		}
	}
	if = {
		limit = {
			has_province_modifier = depopulated_1
		}
		random_list = {		
			20 = {
				modifier = {
					factor = 4
					any_province_holding = {
						OR = {
							holding_type = nomad
							holding_type = tribal
						}
					}
					NOT = { num_of_settlements = 3 }
				}
				modifier = {
					factor = 1.4
					hospital_level = 1
				}
				modifier = {
					factor = 1.4
					hospital_level = 2
				}
				modifier = {
					factor = 1.4
					hospital_level = 3
				}
				modifier = {
					factor = 1.4
					hospital_level = 4
				}
				modifier = {
					factor = 1.4
					hospital_level = 5
				}
				modifier = {
					factor = 1.4
					hospital_level = 6
				}
			}
			80 = {
				modifier = {
					factor = 0
					any_province_holding = {
						NOR = {
							holding_type = city
							holding_type = temple
							holding_type = castle
							holding_type = tribal
						}
					}
				}
				remove_province_modifier = depopulated_1
				add_province_modifier = {
					name = depopulated_2
					duration = -1
				}
				clr_province_flag = recent_depopulation_1
				set_province_flag = recent_depopulation_2
			}
		}
		
	}
	if = {
		limit = {
			NOR = {
				has_province_modifier = depopulated_1
				has_province_modifier = depopulated_2
				has_province_modifier = depopulated_3
			}
		}
		random_list = {		
			5 = {
				modifier = {
					factor = 15
					any_province_holding = {
						OR = {
							holding_type = nomad
							holding_type = tribal
						}
					}
					NOT = { num_of_settlements = 3 }
				}
				modifier = {
					factor = 1.5
					hospital_level = 1
				}
				modifier = {
					factor = 1.5
					hospital_level = 2
				}
				modifier = {
					factor = 1.5
					hospital_level = 3
				}
				modifier = {
					factor = 1.5
					hospital_level = 4
				}
				modifier = {
					factor = 1.5
					hospital_level = 5
				}
				modifier = {
					factor = 1.5
					hospital_level = 6
				}
			}
			95 = {
				modifier = {
					factor = 0
					any_province_holding = {
						NOR = {
							holding_type = city
							holding_type = temple
							holding_type = castle
							holding_type = tribal
						}
					}
				}
				set_variable = { which = prosperity_value value = 0 }
				remove_province_modifier = prosperity_modifier_1
				remove_province_modifier = prosperity_modifier_2
				remove_province_modifier = prosperity_modifier_3
				add_province_modifier = {
					name = depopulated_1
					duration = -1
				}
				set_province_flag = recent_depopulation_1
			}
		}
	}
}

decrease_depopulation_effect = {
	if = {
		limit = {
			has_province_modifier = depopulated_1
		}
		remove_province_modifier = depopulated_1
	}
	if = {
		limit = {
			has_province_modifier = depopulated_2
		}
		remove_province_modifier = depopulated_2
		add_province_modifier = {
			name = depopulated_1
			duration = -1
		}
	}
	if = {
		limit = {
			has_province_modifier = depopulated_3
		}
		remove_province_modifier = depopulated_3
		add_province_modifier = {
			name = depopulated_2
			duration = -1
		}
	}
}

prisoner_mutilate_effect = {

	random = {
		chance = 20
		if = {
				limit = { NOR = { trait = craven trait = berserker } }
				add_trait = craven
				hidden_tooltip = { character_event = { id = 38257 } }
			}
	}
	
	random_list = {
		80 = {
			if = {
					limit = { NOT = { trait = stressed } }
					add_trait = stressed
					hidden_tooltip = { character_event = { id = 38282 } }
				}
		}
		10 = {
			if = {
					limit = { NOT = { trait = lunatic } }
					add_trait = lunatic
					hidden_tooltip = { character_event = { id = 38304 } }
				}
		}
		10 = {
			#no effect
		}
	}

	add_trait = severely_injured
	hidden_tooltip = {
		random_list = {
			75 = { #Get rid of severely_injured
				character_event = { id = RIP.11000 days = 90 random = 275}
			}
			25 = { #Get rid of severely_injured but develop infection
				set_character_flag = pending_infection
				character_event = { id = RIP.11000 days = 90 random = 275}
			}
		}
	}	
}

jailor_mutilate_effect = {
	
	if = {
		limit = { NOR = { trait = craven trait = berserker } }
		random = {
			chance = 20
			add_trait = craven
			hidden_tooltip = { character_event = { id = 38257 } } # Notify craven
		}
	}

	add_trait = severely_injured
	hidden_tooltip = {
		random_list = {
			75 = { #Get rid of severely_injured
				character_event = { id = RIP.11000 days = 90 random = 275}
			}
			25 = { #Get rid of severely_injured but develop infection
				set_character_flag = pending_infection
				character_event = { id = RIP.11000 days = 90 random = 275}
			}
		}
	}
	
	custom_tooltip = { text = might_affect_mental_health_tt }
	hidden_effect = {
		random_list = {
			80 = {
				add_trait = stressed
			}
			10 = {
				add_trait = lunatic
			}
			10 = {
				#no effect
			}
		}
	}
}

prisoner_torture_effect = {
	add_character_modifier = { name = tortured years = 2 }

	random_list = {
		80 = {
			if = {
				limit = { NOT = { trait = stressed } }
				add_trait = stressed
				hidden_tooltip = { character_event = { id = 38282 } }
			}
		}
		10 = {
			if = {
				limit = { NOR = { trait = craven trait = berserker } }
				add_trait = craven
				hidden_tooltip = { character_event = { id = 38257 } }
			}
		}
		5 = {
			if = {
				limit = { NOT = { trait = lunatic } }
				add_trait = lunatic
				hidden_tooltip = { character_event = { id = 38304 } }
			}
		}
		5 = {
			#nothing
		}
	}
}

jailor_torture_effect = {
	add_character_modifier = { name = tortured years = 2 }
	
	random_list = {
		80 = {
				add_trait = stressed
			}
		10 = {
			if = {
				limit = { NOR = { trait = craven trait = berserker } }
				add_trait = craven
			}
		}
		5 = {
				add_trait = lunatic
		}
		5 = {
			#nothing
		}
	}
}

jailor_humiliation_effect = {
	random_list = {
		15 = {
			add_trait = stressed
		}
		30 = {
			add_trait = humble
		}
		30 = {
			add_trait = shy
		}
		25 = {
			#nothing happens
		}
	}
}

prisoner_humiliation_effect = {
	random_list = {
		15 = {
			modifier = {
				factor = 0
				trait = stressed
			}
			add_trait = stressed
			hidden_tooltip = { 
				character_event = { id = 38282 } # Notify Stressed
			}
		}
		30 = {
			modifier = {
				factor = 0
				trait = humble
			}
			add_trait = humble
			hidden_tooltip = { 
				character_event = { id = 38260 } # Notify Humble
			}
		}
		30 = {
			modifier = {
				factor = 0
				trait = shy
			}
			add_trait = shy
			hidden_tooltip = { 
				character_event = { id = 38263 } # Notify Shy
			}
		}
		25 = {
			#nothing happens
		}
	}
}

maim_hand_effect = {
	if = {
		limit = {
			NOT = {
				has_dlc = "Reapers"
			}
		}
		add_trait = maimed
	}
	if = {
		limit = {
			has_dlc = "Reapers"
		}
		if = {
			limit = {
				trait = one_handed
				NOT = { trait = mangled }
			}
			add_trait = mangled
			hidden_tooltip = { character_event = { id = RIP.11505 } }
		}
		if = {
			limit = {
				NOT = { trait = one_handed }
			}
			add_trait = one_handed
			hidden_tooltip = { character_event = { id = RIP.11502 } }
		}
	}
	add_trait = severely_injured
	hidden_tooltip = {
		hidden_tooltip = {
			random_list = {
				75 = { #Get rid of severely_injured
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
				25 = { #Get rid of severely_injured but develop infection
					set_character_flag = pending_infection
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
			}
		}
	}
}

mangle_effect = {
	if = {
		limit = {
			NOT = {
				has_dlc = "Reapers"
			}
		}
		add_trait = maimed
	}
	if = {
		limit = {
			has_dlc = "Reapers"
		}
		if = {
			limit = {
				NOT = { trait = mangled }
			}
			add_trait = mangled
			hidden_tooltip = { character_event = { id = RIP.11505 } }
		}
	}
	add_trait = severely_injured
	hidden_tooltip = {
		hidden_tooltip = {
			random_list = {
				75 = { #Get rid of severely_injured
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
				25 = { #Get rid of severely_injured but develop infection
					set_character_flag = pending_infection
					character_event = { id = RIP.11000 days = 90 random = 275}
				}
			}
		}
	}
}

remove_treatment_modifiers_effect = {
	remove_character_modifier = successful_treatment_1
	remove_character_modifier = successful_treatment_2
	remove_character_modifier = successful_treatment_3
	remove_character_modifier = failed_treatment_1
	remove_character_modifier = failed_treatment_2
	remove_character_modifier = mystic_treatment_decent
	remove_character_modifier = mystic_treatment_poor
	remove_character_modifier = mystic_treatment_terrible
	remove_character_modifier = symptom_treatment_1
	remove_character_modifier = symptom_treatment_2
	remove_character_modifier = symptom_treatment_3
	remove_character_modifier = symptom_treatment_4
}

remove_disease_flags_effect = {
	clr_character_flag = developing_illness
	clr_character_flag = got_syphilis
	clr_character_flag = got_tuberculosis
	clr_character_flag = got_typhoid_fever
	clr_character_flag = got_typhus
	clr_character_flag = got_bubonic_plague
	clr_character_flag = got_measles
	clr_character_flag = got_smallpox
	clr_character_flag = got_aztec_disease
	clr_character_flag = got_flu
	clr_character_flag = got_dysentery
	clr_character_flag = got_gout
	clr_character_flag = got_food_poisoning
	clr_character_flag = got_rabies
	clr_character_flag = got_cancer
	clr_character_flag = got_pneumonia
	clr_character_flag = manifest_syphilis
	clr_character_flag = manifest_tuberculosis
	clr_character_flag = manifest_typhoid_fever
	clr_character_flag = manifest_typhus
	clr_character_flag = manifest_bubonic_plague
	clr_character_flag = manifest_measles
	clr_character_flag = manifest_small_pox
	clr_character_flag = manifest_aztec_disease
	clr_character_flag = manifest_flu
	clr_character_flag = manifest_dysentery
	clr_character_flag = manifest_gout
	clr_character_flag = manifest_food_poisoning
	clr_character_flag = manifest_rabies
	clr_character_flag = manifest_cancer
	clr_character_flag = manifest_pneumonia
}

leave_court_effect = {
	reverse_opinion = {
		modifier = opinion_leave
		who = ROOT
	}

	banish = yes

	reverse_remove_opinion = {
		modifier = opinion_leave
		who = ROOT
	}
}

leave_court_and_die_effect = {
	death = { death_reason = death_missing }
}

give_epidemic_disease_effect = {
	if = {
		limit = {
			location = { disease = tuberculosis }
			NOT = { has_character_flag = immune_tuberculosis }
		}

		set_character_flag = got_tuberculosis
		set_character_flag = developing_illness

		character_event = { id = RIP.5015 }

		break = yes
	}
	if = {
		limit = {
			location = { disease = typhoid_fever }
			NOT = { has_character_flag = immune_typhoid_fever }
		}

		set_character_flag = got_typhoid_fever
		set_character_flag = developing_illness

		character_event = { id = RIP.5016 }

		break = yes
	}
	if = {
		limit = {
			location = { disease = typhus }
			NOT = { has_character_flag = immune_typhus }
		}

		set_character_flag = got_typhus
		set_character_flag = developing_illness

		character_event = { id = RIP.5017 }

		break = yes
	}
	if = {
		limit = { 
			location = { disease = bubonic_plague }
			NOT = { has_character_flag = immune_bubonic_plague }
		}

		set_character_flag = got_bubonic_plague
		set_character_flag = developing_illness

		character_event = { id = RIP.5012 }

		break = yes
	}
	if = {
		limit = { 
			location = { disease = measles }
			NOT = { has_character_flag = immune_measles }
		}

		set_character_flag = got_measles
		set_character_flag = developing_illness

		character_event = { id = RIP.5018 }

		break = yes
	}
	if = {
		limit = {
			location = { disease = small_pox }
			NOT = { has_character_flag = immune_smallpox }
		}

		set_character_flag = got_small_pox
		set_character_flag = developing_illness

		character_event = { id = RIP.5019 }

		break = yes
	}
	if = {
		limit = { 
			location = { disease = syphilis }
			NOT = { has_character_flag = immune_syphilis }
		}

		set_character_flag = got_syphilis
		set_character_flag = developing_illness

		character_event = { id = RIP.5014 }

		break = yes
	}
}

blessing_removes_disease_effect = {
	if = {
		limit = {
			has_dlc = "The Old Gods"
			has_character_flag = old_gods_blessing
			has_character_modifier = blessing_of_health 
		}
		hidden_tooltip = { character_event = { id = TOG.7015 days = 30 } }
	}
	if = {
		limit = {
			has_dlc = "Sons of Abraham"
			has_character_flag = pilgrim_blessing
			has_character_modifier = blessing_of_health 
		}
		hidden_tooltip = { character_event = { id = SoA.5068 days = 30 } }
	}
}

deaths_gift_removes_disease_effect = {
	if = {
		limit = {
			has_dlc = "Reapers"
			has_character_modifier = deaths_gift 
		}
		hidden_tooltip = { character_event = { id = RIP.30233 days = 30 } }
	}
}

remove_disease_trait_effect = {
	if = {
	 	limit = { trait = ill }
	 	remove_trait = ill
	}
	if = {
	 	limit = { trait = has_tuberculosis }
	 	remove_trait = has_tuberculosis
	}
	if = {
	 	limit = { trait = has_typhoid_fever }
	 	remove_trait = has_typhoid_fever
	}
	if = {
	 	limit = { trait = has_typhus }
	 	remove_trait = has_typhus
	}
	if = {
	 	limit = { trait = has_bubonic_plague }
	 	remove_trait = has_bubonic_plague
	}
	if = {
	 	limit = { trait = has_measles }
	 	remove_trait = has_measles
	}
	if = {
	 	limit = { trait = has_small_pox }
	 	remove_trait = has_small_pox
	}
	if = {
	 	limit = { trait = has_aztec_disease }
	 	remove_trait = has_aztec_disease
	}
	if = {
	 	limit = { trait = syphilitic }
	 	remove_trait = syphilitic
	}
	if = {
	 	limit = { trait = flu }
	 	remove_trait = flu
	}
	if = {
	 	limit = { trait = dysentery }
	 	remove_trait = dysentery
	}
	if = {
	 	limit = { trait = gout }
	 	remove_trait = gout
	}
	if = {
	 	limit = { trait = food_poisoning }
	 	remove_trait = food_poisoning
	}
	if = {
	 	limit = { trait = rabies }
	 	remove_trait = rabies
	}
	if = {
	 	limit = { trait = cancer }
	 	remove_trait = cancer
	}
	if = {
	 	limit = { trait = pneumonic }
	 	remove_trait = pneumonic
	}
	if = {
	 	limit = { trait = scurvy }
	 	remove_trait = scurvy
	}
	if = {
	 	limit = { trait = dancing_plague }
	 	remove_trait = dancing_plague
	}
	if = {
	 	limit = { trait = leper }
	 	remove_trait = leper
	}
	clear_disease_level_effect = yes
}

resolve_severely_injured_effect = {
	hidden_tooltip = {
		random_list = {
			70 = { #Get rid of severely_injured
				character_event = { id = RIP.11000 days = 100 random = 300 }
			}
			30 = { #Get rid of severely_injured but develop infection
				set_character_flag = pending_infection
				character_event = { id = RIP.11000 days = 100 random = 300 }
			}
		}
	}
}

leave_council_position_effect = {
	if = {
		limit = { has_job_title = job_chancellor }
		remove_title = job_chancellor
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
	if = {
		limit = { has_job_title = job_marshal }
		remove_title = job_marshal
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
	if = {
		limit = { has_job_title = job_treasurer }
		remove_title = job_treasurer
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
	if = {
		limit = { has_job_title = job_spymaster }
		remove_title = job_spymaster
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
	if = {
		limit = { has_job_title = job_spiritual }
		remove_title = job_spiritual
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
	if = {
		limit = { has_minor_title = title_councilmember_king }
		remove_title = title_councilmember_king
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
	if = {
		limit = { has_minor_title = title_councilmember_emperor }
		remove_title = title_councilmember_emperor
		add_character_modifier = {
			modifier = resigned_in_anger
			years = 2
			hidden = yes
		}
	}
}

increase_prosperity_effect = {
	if = {
		limit = { 
			NOR = {
				has_province_modifier = prosperity_modifier_1
				has_province_modifier = prosperity_modifier_2
				has_province_modifier = prosperity_modifier_3
				has_province_modifier = depopulated_1
				has_province_modifier = depopulated_2
				has_province_modifier = depopulated_3
			}
		}

		add_province_modifier = { name = prosperity_modifier_1 duration = -1 }
		hidden_tooltip = { set_variable = { which = prosperity_value value = 100 } }
		break = yes
	}

	if = {
		limit = { has_province_modifier = prosperity_modifier_1 }

		hidden_tooltip = { remove_province_modifier = prosperity_modifier_1 }
		add_province_modifier = { name = prosperity_modifier_2 duration = -1 }
		hidden_tooltip = { set_variable = { which = prosperity_value value = 250 } }
		break = yes
	}

	if = {
		limit = { has_province_modifier = prosperity_modifier_2 }

		hidden_tooltip = { remove_province_modifier = prosperity_modifier_2 }
		add_province_modifier = { name = prosperity_modifier_3 duration = -1 }
		hidden_tooltip = { set_variable = { which = prosperity_value value = 500 } }
		break = yes
	}
}

add_disease_level_effect = {
		random_list = {
			65 = { 
				custom_tooltip = {
					text = become_normal_ill
				}
			}
			20 = { 
				modifier = {
					factor = 2
					trait = strong
				}
				modifier = {
					factor = 2
					trait = robust
				}
				custom_tooltip = {
					text = become_mild_ill
					hidden_tooltip = { 
						add_character_modifier = { name = mild_illness duration = -1 }
					}
				}
			}
			10 = { 
				modifier = {
					factor = 1.5
					trait = feeble
				}
				modifier = {
					factor = 1.5
					trait = weak
				}
				modifier = {
					factor = 0.5
					trait = strong
				}
				modifier = {
					factor = 0.5
					trait = robust
				}
				modifier = {
					factor = 1.5
					age = 50
				}
				modifier = {
					factor = 1.5
					age = 60
				}
				modifier = {
					factor = 1.5
					age = 70
				}
				modifier = {
					factor = 1.5
					age = 80
				}
				custom_tooltip = {
					text = become_severe_ill
					hidden_tooltip = { 
						add_character_modifier = { name = severe_illness duration = -1 }
					}
				}
			}
			5= { 
				modifier = {
					factor = 0
					immortal = yes
				}
				modifier = {
					factor = 2
					trait = feeble
				}
				modifier = {
					factor = 2
					trait = weak
				}
				modifier = {
					factor = 0.5
					trait = strong
				}
				modifier = {
					factor = 0.5
					trait = robust
				}
				 modifier = {
					factor = 2
					age = 50
				}
				modifier = {
					factor = 2
					age = 60
				}
				modifier = {
					factor = 2
					age = 70
				}
				modifier = {
					factor = 2
					age = 80
				}
				custom_tooltip = {
					text = become_bedridden_ill
					hidden_tooltip = { 
						add_character_modifier = { name = bedridden_illness duration = -1 }
						add_trait = sick_incapable
					}
				}
			}
		}
}

clear_disease_level_effect = {
	if = {
		limit = { has_character_modifier = mild_illness }
		remove_character_modifier = mild_illness
	}
	if = {
		limit = { has_character_modifier = severe_illness }
		remove_character_modifier = severe_illness
	}
	if = {
		limit = { has_character_modifier = bedridden_illness }
		remove_character_modifier = bedridden_illness
		hidden_tooltip = {
			remove_trait = sick_incapable
		}
	}
}

end_inaccessibility_effect = {
	if = {
		limit = { trait = in_hiding }
		remove_trait = in_hiding

		remove_do_not_disturb_effect = yes
		
		add_character_modifier = {
			name = went_out_of_hiding_timer
			duration = 180
			hidden = yes
		}
		hidden_tooltip = { character_event = { id = CM.6400 } } # Notify plotters and family
	}
	if = { 
		limit = { has_character_modifier = in_seclusion }

		remove_character_modifier = in_seclusion

		if = {
			limit = { is_ruler = yes }
			remove_do_not_disturb_effect = yes
			clr_character_flag = exposed_to_outside
			clr_character_flag = seclusion_piling_corpses
			clr_character_flag = seclusion_lazy_seduction
			clr_character_flag = seclusion_nightmares
			clr_character_flag = seclusion_gained_friend
			clr_character_flag = seclusion_child_has_lover
			clr_character_flag = seclusion_tunnel
			clr_character_flag = seclusion_food_events

			custom_tooltip = { text = open_the_gates_info_tooltip }
			
			add_character_modifier = {
				name = recently_opened_gates
				duration = 365
			}
			hidden_tooltip = {
				clr_character_flag = seclusion_events_on
				character_event = { id = RIP.11557 days = 40 random = 20} #clears starvation modifiers
				any_courtier = {
					clr_character_flag = seclusion_events_on
					remove_character_modifier = in_seclusion
					character_event = { id = RIP.11557 days = 40 random = 20} #clears starvation modifiers
				}
				any_vassal = {
					limit = {
						OR = {
							is_councillor = yes
							has_minor_title = title_councilmember_king
							has_minor_title = title_councilmember_emperor
						}
						is_landed = yes
						liege = { character = ROOT }
						NOT = {
							has_character_modifier = in_seclusion
						}
						host = { NOT = { character = ROOT } }
					}
					force_host = ROOT
				}
			}
			if = { # Rejoin your liege's court if both of you are not in seclusion
				limit = {
					OR = {
						is_councillor = yes
						has_minor_title = title_councilmember_king
						has_minor_title = title_councilmember_emperor
					}
					NOT = {
						liege = {
							has_character_modifier = in_seclusion
						}
					}
				}
				liege = {
					ROOT = {
						force_host = PREV
					}
				}
			}
		}
	}
}

#Effects for adding diseases
give_pneumonic_effect = {
	if = {
		limit = { NOT = { trait = pneumonic } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			tooltip = { add_trait = pneumonic }
			set_character_flag = got_pneumonia
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5011 days = 3 random = 10 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = pneumonic
		}
	}
}


give_has_tuberculosis_effect = {
	if = {
		limit = { NOT = { trait = has_tuberculosis } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_tuberculosis
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5015 days = 3 random = 40 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = has_tuberculosis
		}
	}
}

give_has_typhoid_fever_effect = {
	if = {
		limit = { NOT = { trait = has_typhoid_fever } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_typhoid_fever
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5016 days = 3 random = 10 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = has_typhoid_fever
		}
	}
}

give_has_bubonic_plague_effect = {
	if = {
		limit = { NOT = { trait = has_bubonic_plague } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_bubonic_plague
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5012 days = 3 random = 10 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = has_bubonic_plague
		}
	}
}

give_has_measles_effect = {
	if = {
		limit = { NOT = { trait = has_measles } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_measles
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5018 days = 3 random = 10 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = has_measles
		}
	}
}

give_has_small_pox_effect = {
	if = {
		limit = { NOT = { trait = has_small_pox } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_smallpox
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5019 days = 3 random = 10 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = has_small_pox
		}
	}
}

give_has_aztec_disease_effect = {
	if = {
		limit = { NOT = { trait = has_aztec_disease } }

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_aztec_disease
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5014 days = 3 random = 40 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = has_aztec_disease
		}
	}
}

give_syphilitic_effect = {
	if = {
		limit = { 
			NOT = { trait = syphilitic } 
		}

		if = {
			limit = { 
				has_dlc = "Reapers"
				NOT = { has_character_flag = developing_illness }
				NOT = { has_character_flag = disease_not_serious } 
			}
			set_character_flag = got_syphilis
			set_character_flag = developing_illness
			hidden_tooltip = { character_event = { id = RIP.5014 days = 3 random = 40 } }
		}
		if = {
			limit = { NOT = { has_dlc = "Reapers" } }
			add_trait = syphilitic
		}
	}
}

give_flu_effect = {
	if = {
		limit = { 
			NOT = { trait = flu } 
			has_dlc = "Reapers"
			NOT = { has_character_flag = developing_illness }
			NOT = { has_character_flag = disease_not_serious }
		}

		set_character_flag = got_flu
		set_character_flag = developing_illness
		hidden_tooltip = { character_event = { id = RIP.5020 days = 3 random = 3 } }
	}
}

give_dysentery_effect = {
	if = {
		limit = { 
			NOT = { trait = dysentery } 
			has_dlc = "Reapers"
			NOT = { has_character_flag = developing_illness }
			NOT = { has_character_flag = disease_not_serious }
		}

		set_character_flag = got_dysentery
		set_character_flag = developing_illness
		hidden_tooltip = { character_event = { id = RIP.5021 days = 3 random = 10 } }
	}
}

give_gout_effect = {
	if = {
		limit = { 
			NOT = { trait = gout } 
			has_dlc = "Reapers"
			NOT = { has_character_flag = developing_illness }
			NOT = { has_character_flag = disease_not_serious }
		}

		set_character_flag = got_gout
		set_character_flag = developing_illness
		hidden_tooltip = { character_event = { id = RIP.5022 days = 30 random = 60 } }
	}
}

give_food_poisoning_effect = {
	if = {
		limit = { 
			NOT = { trait = food_poisoning } 
			has_dlc = "Reapers"
			NOT = { has_character_flag = developing_illness }
			NOT = { has_character_flag = disease_not_serious }
		}

		set_character_flag = got_food_poisoning
		set_character_flag = developing_illness
		hidden_tooltip = { character_event = { id = RIP.5023 days = 1 random = 2 } }
	}
}

give_rabies_effect = {
	if = {
		limit = { 
			NOT = { trait = rabies } 
			has_dlc = "Reapers"
			NOT = { has_character_flag = developing_illness }
			NOT = { has_character_flag = disease_not_serious }
		}

		set_character_flag = got_rabies
		set_character_flag = developing_illness
		hidden_tooltip = { character_event = { id = RIP.5024 days = 30 random = 60 } }
	}
}

give_cancer_effect = {
	if = {
		limit = { 
			NOT = { trait = cancer } 
			has_dlc = "Reapers"
			NOT = { has_character_flag = developing_illness }
			NOT = { has_character_flag = disease_not_serious }
		}

		set_character_flag = got_cancer
		set_character_flag = developing_illness
		hidden_tooltip = { character_event = { id = RIP.5025 days = 30 random = 60 } }
	}
}

give_ill_effect = {
	if = {
		limit = { 
			NOR = { 
				has_dlc = "Reapers" 
				trait = ill
			} 
		}
		add_trait = ill
		hidden_tooltip = {
			character_event = {
				days = 3
				id = 38290 #Notify Ill
			}
		}
	}
	if = {
		limit = { has_dlc = "Reapers" }
		tooltip = { add_trait = flu }
		give_flu_effect = yes
	}
}

#Impregnation and venereal disease handling between event_target:sex_partner and THIS. Used in THIS scope.
unprotected_sex_effect_event_target = {
	random = {
		chance = 50
		venereal_disease_effect_event_target = yes
	}
	random = {
		chance = 10
		modifier = {
			factor = 2
			is_fertile_trigger = yes
		}
		modifier = {
			factor = 2
			event_target:sex_partner = { is_fertile_trigger = yes }
		}
		modifier = {
			factor = 0.5
			is_infertile_trigger = yes
		}
		modifier = {
			factor = 0.5
			event_target:sex_partner = { is_infertile_trigger = yes }
		}
		impregnate_effect_event_target = yes
	}
}

#Transfers venereal diseases between event_target:sex_partner and THIS.
venereal_disease_effect_event_target = {
	#Great pox and aztec disease for sex_partner
	if = {
		limit = {
			NOR = {
				event_target:sex_partner = { has_character_flag = developing_illness }
				event_target:sex_partner = { has_character_flag = disease_not_serious }
			}
		}

		if = {
			limit = { trait = syphilitic }
			event_target:sex_partner = { give_syphilitic_effect = yes }			
		}
		if = {
			limit = { trait = has_aztec_disease }
			event_target:sex_partner = { give_has_aztec_disease_effect = yes }			
		}
	}

	#Great pox and aztec disease for THIS
	if = {
		limit = {
			NOR = {
				has_character_flag = developing_illness
				has_character_flag = disease_not_serious 
			}
		}

		if = {
			limit = { event_target:sex_partner = { trait = syphilitic } }
			give_syphilitic_effect = yes		
		}
		if = {
			limit = { event_target:sex_partner = { trait = has_aztec_disease } }
			give_has_aztec_disease_effect = yes		
		}
	}

	#Lover's pox
	if = {
		limit = { 
			OR = {
				trait = lovers_pox 
				has_character_modifier = minor_disease_herpes 
			}
			NOR = { 
				event_target:sex_partner = { trait = lovers_pox }
				event_target:sex_partner = { has_character_modifier = minor_disease_herpes }
			}
		}
		hidden_tooltip = { event_target:sex_partner = { character_event = { id = 6359 days = 15 random = 5 } } }
	}
	if = {
		limit = { 
			OR = {
				event_target:sex_partner = { trait = lovers_pox }
				event_target:sex_partner = { has_character_modifier = minor_disease_herpes }
			}
			NOR = { 
				trait = lovers_pox
				has_character_modifier = minor_disease_herpes
			}
		}
		hidden_tooltip = { character_event = { id = 6359 days = 15 random = 5 } } 
	}
}

#Tries to impregnate either event_target:sex_partner or THIS if all conditions are met
impregnate_effect_event_target = {
	if = {
		limit = { is_opposite_sex = event_target:sex_partner }

		#If THIS is a female which can get pregnant
		if = {
			limit = {
				is_female = yes
				NOT = { age = 45 }
				is_pregnant = no
				health = 3
				event_target:sex_partner = { NOT = { trait = eunuch } }
			}

			#THIS is not consort/spouse of anyone or is consort/spouse of event_target:sex_partner
			if = {
				limit = {
					OR = {
						AND = {
							is_married = no
							is_consort = no
						}
						AND = {
							is_consort = yes
							consort = { character = event_target:sex_partner }
						}
						AND = {
							is_married = yes
							spouse = { character = event_target:sex_partner }
						}
					}
				}
				event_target:sex_partner = { impregnate = PREV }
			}

			#THIS is consort/spouse of someone else than event_target:sex_partner
			if = {
				limit = { 
					OR = {
					 	AND = {
					 		is_married = yes
					 		NOT = { spouse = { character = event_target:sex_partner } }
					 	}
					 	AND = {
					 		is_consort = yes
					 		NOT = { consort = { character = event_target:sex_partner } }
					 	}
					}
				}
				event_target:sex_partner = { impregnate_cuckoo = PREV }
			}
		}

		#If event_target:sex_partner is a female which can get pregnant
		if = {
			limit = {
				event_target:sex_partner = {
					is_female = yes
					NOT = { age = 45 }
					is_pregnant = no
					health = 3
					PREV = { NOT = { trait = eunuch } }
				}
			}

			#event_target:sex_partner is not consort/spouse of anyone or is consort/spouse of THIS
			if = {
				limit = {
					event_target:sex_partner = {
						OR = {
							AND = {
								is_married = no
								is_consort = no
							}
							AND = {
								is_consort = yes
								consort = { character = PREVPREV }
							}
							AND = {
								is_married = yes
								spouse = { character = PREVPREV }
							}
						}
					}
				}
				impregnate = event_target:sex_partner
			}

			#event_target:sex_partner is consort/spouse of someone else than THIS
			if = {
				limit = {
					event_target:sex_partner = {
						OR = {
						 	AND = {
						 		is_married = yes
						 		NOT = { spouse = { character = PREVPREV } }
						 	}
						 	AND = {
						 		is_consort = yes
						 		NOT = { consort = { character = PREVPREV } }
						 	}
						}
					}
				}

				impregnate_cuckoo = event_target:sex_partner
			}
		}
	}
}

#Impregnation and venereal disease handling between FROM and ROOT. Used in ROOT scope.
unprotected_sex_effect = {
	random = {
		chance = 50
		venereal_disease_effect = yes
	}
	random = {
		chance = 10
		modifier = {
			factor = 2
			is_fertile_trigger = yes
		}
		modifier = {
			factor = 2
			FROM = { is_fertile_trigger = yes }
		}
		modifier = {
			factor = 0.5
			is_infertile_trigger = yes
		}
		modifier = {
			factor = 0.5
			FROM = { is_infertile_trigger = yes }
		}
		impregnate_effect = yes
	}
}
			
#Transfers venereal diseases between FROM and ROOT
venereal_disease_effect = {
	#Great pox and aztec disease for FROM
	if = {
		limit = {
			NOR = {
				FROM = { has_character_flag = developing_illness }
				FROM = { has_character_flag = disease_not_serious }
			}
		}

		if = {
			limit = { trait = syphilitic }
			FROM = { give_syphilitic_effect = yes }			
		}
		if = {
			limit = { trait = has_aztec_disease }
			FROM = { give_has_aztec_disease_effect = yes }			
		}
	}

	#Great pox and aztec disease for ROOT
	if = {
		limit = {
			NOR = {
				has_character_flag = developing_illness
				has_character_flag = disease_not_serious 
			}
		}

		if = {
			limit = { FROM = { trait = syphilitic } }
			give_syphilitic_effect = yes		
		}
		if = {
			limit = { FROM = { trait = has_aztec_disease } }
			give_has_aztec_disease_effect = yes		
		}
	}

	#Lover's pox
	if = {
		limit = { 
			OR = {
				trait = lovers_pox 
				has_character_modifier = minor_disease_herpes 
			}
			NOR = { 
				FROM = { trait = lovers_pox }
				FROM = { has_character_modifier = minor_disease_herpes }
			}
		}
		hidden_tooltip = { FROM = { character_event = { id = 6359 days = 15 random = 5 } } }
	}
	if = {
		limit = { 
			OR = {
				FROM = { trait = lovers_pox }
				FROM = { has_character_modifier = minor_disease_herpes }
			}
			NOR = { 
				trait = lovers_pox
				has_character_modifier = minor_disease_herpes
			}
		}
		hidden_tooltip = { character_event = { id = 6359 days = 15 random = 5 } } 
	}
}

#Tries to impregnate either ROOT or FROM if all conditions are met
impregnate_effect = {
	if = {
		limit = { is_opposite_sex = FROM }

		#If ROOT is a female which can get pregnant
		if = {
			limit = {
				is_female = yes
				NOT = { age = 45 }
				is_pregnant = no
				health = 3
				FROM = { NOT = { trait = eunuch } }
			}

			#ROOT is not consort/spouse of anyone or is consort/spouse of FROM
			if = {
				limit = {
					OR = {
						AND = {
							is_married = no
							is_consort = no
						}
						AND = {
							is_consort = yes
							consort = { character = FROM }
						}
						AND = {
							is_married = yes
							spouse = { character = FROM }
						}
					}
				}
				FROM = { impregnate = ROOT }
			}

			#ROOT is consort/spouse of someone else than FROM
			if = {
				limit = { 
					OR = {
					 	AND = {
					 		is_married = yes
					 		NOT = { spouse = { character = FROM } }
					 	}
					 	AND = {
					 		is_consort = yes
					 		NOT = { consort = { character = FROM } }
					 	}
					}
				}
				FROM = { impregnate_cuckoo = ROOT }
			}
		}

		#If FROM is a female which can get pregnant
		if = {
			limit = {
				FROM = {
					is_female = yes
					NOT = { age = 45 }
					is_pregnant = no
					health = 3
					ROOT = { NOT = { trait = eunuch } }
				}
			}

			#FROM is not consort/spouse of anyone or is consort/spouse of ROOT
			if = {
				limit = {
					FROM = {
						OR = {
							AND = {
								is_married = no
								is_consort = no
							}
							AND = {
								is_consort = yes
								consort = { character = ROOT }
							}
							AND = {
								is_married = yes
								spouse = { character = ROOT }
							}
						}
					}
				}
				impregnate = FROM
			}

			#FROM is consort/spouse of someone else than ROOT
			if = {
				limit = {
					FROM = {
						OR = {
						 	AND = {
						 		is_married = yes
						 		NOT = { spouse = { character = ROOT } }
						 	}
						 	AND = {
						 		is_consort = yes
						 		NOT = { consort = { character = ROOT } }
						 	}
						}
					}
				}

				impregnate_cuckoo = FROM
			}
		}
	}
}

will_not_marry_effect = {
	add_character_modifier = {
		modifier = will_not_marry
		duration = -1
	}
	add_trait = cannot_marry
}

female_councilor_effect_1 = {
	reverse_opinion = { 
		modifier = opinion_given_council_position_1
		who = FROM 
		years = 5 
	}
	add_character_modifier = {
		name = scandalous_councillor_1
		months = 60
	}
}

female_councilor_effect_2 = {
	reverse_opinion = { 
		modifier = opinion_given_council_position_2
		who = FROM 
		years = 5 
	}
	add_character_modifier = {
		name = scandalous_councillor_2
		months = 60
	}
}

female_councilor_effect_3 = {
	reverse_opinion = { 
		modifier = opinion_given_council_position_3 
		who = FROM 
		years = 5 
	}
	add_character_modifier = {
		name = scandalous_councillor_3
		months = 60
	}
}

#Use to remove any opinion giving a prison reason. Must set appropriate event targets before using this effect.
remove_prison_reason_effect = {
	event_target:remove_prison_reason_effect_accuser = {
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_traitor }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_rebel_traitor }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_dishonorable }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_regicide_traitor }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_fatwa_target }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_refused_order }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_witch }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_takfir }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_unfaithful_wife }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_cuckolded }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_charge_heresiarch }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_charge_infidel }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_charge_deviant }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_charge_illegitimate }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_charge_traitor }
		remove_opinion = { who = event_target:remove_prison_reason_effect_accused modifier = opinion_charge_slanderer }
	}	
}

add_cat_effect = {
	if = {
		limit =  { NOT = { has_character_modifier = pet_cat } }
		add_character_modifier = {
			name = pet_cat
			duration = -1
		}
		hidden_tooltip = { character_event = { id = 77802 days = 3000 random = 2000 } } # Cat dies
		hidden_tooltip = { character_event = { id = 77861 days = 30 random = 100 } } # Cat & dog 
	}
}

add_crusade_trait_effect = {
	if = {
		limit = {
			OR = {
				religion = celtic_pagan
				religion = celtic_pagan_reformed
				religion_group = egyptian_pagan_group
			}
		}
		add_trait = holy_crusader
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = norse_pagan
				religion = norse_pagan_reformed
				religion = german_pagan
				religion = german_pagan_reformed
			}
		}
		add_trait = valhalla_bound
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = tengri_pagan
				religion = tengri_pagan_reformed
			}
		}
		add_trait = tengri_warrior
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = baltic_pagan
				religion = baltic_pagan_reformed
			}
		}
		add_trait = romuvas_own
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = finnish_pagan
				religion = finnish_pagan_reformed
			}
		}
		add_trait = ukkos_shield
		break = yes
	}
	if = {
		limit = {
			religion = aztec
		}
		add_trait = eagle_warrior
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = slavic_pagan
				religion = slavic_pagan_reformed
			}
		}
		add_trait = peruns_chosen
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = west_african_pagan
				religion = west_african_pagan_reformed
			}
		}
		add_trait = nyames_shield
		break = yes
	}
	if = {
		limit = {
			OR = {
				religion = zun_pagan
				religion = zun_pagan_reformed
			}
		}
		add_trait = sun_warrior
		break = yes
	}
	if = {
		limit = {
			religion_group = hellenic_pagan_group
		}
		add_trait = ares_own
		break = yes
	}
	if = {
		limit = {
			religion_group = muslim
		}
		add_trait = mujahid
		break = yes
	}
	if = {
		limit = {
			religion_group = christian
		}
		add_trait = crusader
		break = yes
	}
	if = {
		limit = {
			religion_group = zoroastrian_group
		}
		add_trait = gondi_shahansha
		break = yes
	}
	if = {
		limit = {
			religion_group = jewish_group
		}
		add_trait = shaddai
	}
}

###MONKS & MYSTICS###
remove_assassins_debt_effect = {
	if = {
		limit = { has_character_modifier = assassins_debt }
		remove_character_modifier = assassins_debt
		hidden_tooltip = {
			set_variable = { which = assassins_debt value = 0 } 
		}
		clr_character_flag = assassins_target_debt
		clear_delayed_event = { id = MNM.6009 }
	}
}

remove_secret_religion_trait_effect = {
	clear_secret_religion = yes
}

pay_back_assassins_effect = {
	if = {
		limit = { is_variable_equal = { which = assassins_debt value = 50 } }
		wealth = -50
		hidden_tooltip = {
			event_target:grand_master  = {
				if = {
					limit = {
						ai = yes
						primary_title = { title = d_hashshashin } 
					}
					wealth = 50
				}
			}
		}
	}
	if = {
		limit = { is_variable_equal = { which = assassins_debt value = 250 } }
		wealth = -250	
		hidden_tooltip = {
			event_target:grand_master  = {
				if = {
					limit = {
						ai = yes
						primary_title = { title = d_hashshashin } 
					}
					wealth = 250
				}
			}
		}
	}
	if = {
		limit = { is_variable_equal = { which = assassins_debt value = 300 } }
		wealth = -300
		hidden_tooltip = {
			event_target:grand_master  = {
				if = {
					limit = {
						ai = yes
						primary_title = { title = d_hashshashin } 
					}
					wealth = 300
				}
			}
		}
	}
	if = {
		limit = { is_variable_equal = { which = assassins_debt value = 500 } }
		wealth = -500
		hidden_tooltip = {
			event_target:grand_master = {
				if = {
					limit = {
						ai = yes
						primary_title = { title = d_hashshashin } 
					}
					wealth = 500
				}
			}
		}
	}
}

major_soul_corruption_effect = {
	custom_tooltip = { 
		text = major_soul_corruption_effect_tooltip
	}
	hidden_effect = {
		if = {
			limit = {
				NAND = {
					trait = cruel
					trait = arbitrary
					trait = deceitful
					trait = possessed
				}
			}
			random_list = {
				20 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = kind }
							trait = cruel
							has_character_flag = corruption_remove_kind 
						}
					}
					set_character_flag = corruption_remove_kind
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				20 = {
					modifier = {
						factor = 0
						OR = {
							trait = kind
							trait = cruel
							has_character_flag = corruption_add_cruel 
						}
					}
					set_character_flag = corruption_add_cruel
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				15 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = just }
							trait = arbitrary
							has_character_flag = corruption_remove_just
						} 
					}
					set_character_flag = corruption_remove_just
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				15 = {
					modifier = {
						factor = 0
						OR = {
							trait = just
							trait = arbitrary
							has_character_flag = corruption_add_arbitrary
						} 
					}
					set_character_flag = corruption_add_arbitrary
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = honest }
							trait = deceitful
							has_character_flag = corruption_remove_honest
						} 
					}
					set_character_flag = corruption_remove_honest	
					character_event = { id = MNM.7050 days = 3 random = 27 }		
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							trait = honest
							trait = deceitful
							has_character_flag = corruption_add_deceitful
						} 
					}
					set_character_flag = corruption_add_deceitful
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				5 = { 
					modifier = {
						factor = 0
						trait = possessed
						has_character_flag = corruption_add_possessed
					}
					set_character_flag = corruption_add_possessed
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				50 = { }
			}
		}
		random_list = { #Risk of getting weaker
			10 = {
				trigger = { NOT = { trait = stressed } }
				character_event = { id = MNM.7051 days = 32 random = 5 }
			}
			5 = {
				trigger = { NOT = { trait = lunatic } }
				character_event = { id = MNM.7052 days = 32 random = 5 }
			}
			5 = {
				trigger = { NOR = { trait = stutter } }
				character_event = { id = MNM.7053 days = 32 random = 5 }
			}
			5 = {
				trigger = { NOR = { trait = clubfooted } }
				character_event = { id = MNM.7054 days = 32 random = 5} 
			}
			5 = {
				trigger = { NOR = { trait = hunchback } }
				character_event = { id = MNM.7055 days = 32 random = 5 }
			}
			5 = {
				trigger = { NOR = { trait = ugly } }
				character_event = { id = MNM.7056 days = 32 random = 5 }
			}
			5 = {
				trigger = {
					NOR = {
						trait = feeble
						trait = weak
						trait = strong
					}
				}
				character_event = { id = MNM.7059 days = 32 random = 5 }
			}
			20 = {
				trigger = { 
					NOR = { 
						NOT = { health = 3 }
						has_character_modifier = corrupting_magic_minor
						has_character_modifier = corrupting_magic_major
					}
				}
				character_event = { id = MNM.7057 days = 32 random = 5 }
			}
			220 = { # High visibility (ability abuse) increases the risk of getting weaker
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 10 }
				}
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 15 }
				}
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 20 }
				}
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 25 }
				}
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 30 }
				}
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 35 }
				}
				modifier = {
					factor = 0.9
					check_variable = { which = visibility_value value = 40 }
				}
			}
		}
	}
}

minor_soul_corruption_effect = {
	custom_tooltip = { 
		text = minor_soul_corruption_effect_tooltip
	}
	hidden_effect = {
		if = {
			limit = {
				NAND = {
					trait = cruel
					trait = arbitrary
					trait = deceitful
					trait = possessed
				}
			}
			random_list = {
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = kind }
							trait = cruel
							has_character_flag = corruption_remove_kind 
						}
					}
					set_character_flag = corruption_remove_kind
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				5 = {
					modifier = {
						factor = 0
						OR = {
							trait = kind
							trait = cruel
							has_character_flag = corruption_add_cruel 
						}
					}
					set_character_flag = corruption_add_cruel
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = just }
							trait = arbitrary
							has_character_flag = corruption_remove_just
						}
					}
					set_character_flag = corruption_remove_just
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				5 = {
					modifier = {
						factor = 0
						OR = {
							trait = just
							trait = arbitrary
							has_character_flag = corruption_add_arbitrary
						} 
					}
					set_character_flag = corruption_add_arbitrary
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				10 = {
					modifier = {
						factor = 0
						OR = {
							NOT = { trait = honest }
							trait = deceitful
							has_character_flag = corruption_remove_honest
						} 
					}
					set_character_flag = corruption_remove_honest
					character_event = { id = MNM.7050 days = 3 random = 27 }			
				}
				5 = {
					modifier = {
						factor = 0
						OR = {
							trait = honest
							trait = deceitful
							has_character_flag = corruption_add_deceitful
						} 
					}
					set_character_flag = corruption_add_deceitful
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				5 = { 
					modifier = {
						factor = 0
						trait = possessed
						has_character_flag = corruption_add_possessed
					}
					set_character_flag = corruption_add_possessed
					character_event = { id = MNM.7050 days = 3 random = 27 }
				}
				80 = { }
			}
			random_list = { #Risk of getting weaker
				15 = {
					trigger = { NOT = { trait = stressed } }
					character_event = { id = MNM.7051 days = 32 random = 5 }
				}
				5 = {
					trigger = { NOT = { trait = lunatic } }
					character_event = { id = MNM.7052 days = 32 random = 5 }
				}
				5 = {
					trigger = { NOR = { trait = stutter } }
					character_event = { id = MNM.7053 days = 32 random = 5 }
				}
				5 = {
					trigger = { NOR = { trait = clubfooted } }
					character_event = { id = MNM.7054 days = 32 random = 5 }
				}
				5 = {
					trigger = { NOR = { trait = hunchback } }
					character_event = { id = MNM.7055 days = 32 random = 5 }
				}
				5 = {
					trigger = { NOR = { trait = ugly } }
					character_event = { id = MNM.7056 days = 32 random = 5 }
				}
				5 = {
					trigger = {
						NOR = {
							trait = feeble
							trait = weak
							trait = strong
						}
					}
					character_event = { id = MNM.7059 days = 32 random = 5 }
				}
				30 = {
					trigger = { 
						NOR = { 
							NOT = { health = 3 }
							has_character_modifier = corrupting_magic_minor
							has_character_modifier = corrupting_magic_major
						}
					}
					character_event = { id = MNM.7058 days = 32 random = 5 }
				}
				450 = {  # High visibility (ability abuse) increases the risk of getting weaker
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 10 }
					}
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 15 }
					}
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 20 }
					}
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 25 }
					}
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 30 }
					}
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 35 }
					}
					modifier = {
						factor = 0.9
						check_variable = { which = visibility_value value = 40 }
					}
				}
			}
		}
	}
}

add_society_currency_trivial_effect = {
	change_society_currency = 10
}

add_society_currency_minor_effect = {
	change_society_currency = 100
}

add_society_currency_medium_effect = {
	change_society_currency = 200
}

add_society_currency_major_effect = {
	change_society_currency = 300
}

add_society_currency_massive_effect = {
	change_society_currency = 1000
}

detract_society_currency_trivial_effect = {
	change_society_currency = -15
}

detract_society_currency_tiny_effect = {
	change_society_currency = -50
}

detract_society_currency_minor_effect = {
	change_society_currency = -150
}

detract_society_currency_medium_effect = {
	change_society_currency = -300
}

detract_society_currency_major_effect = {
	change_society_currency = -500
}

remove_random_maimed_effect = { #remember to clear flags if using this effect :D
	random_list = {
		40 = {
			modifier = {
				NOT = { trait = maimed }
				factor = 0
			}
			set_character_flag = removed_maimed
		}
		40 = {
			modifier = {
				NOT = {trait = mangled}
				factor = 0
			}
			set_character_flag = removed_mangled
		}
		10 = {
			modifier = {
				NOT = {trait = one_eyed}
				factor = 0
			}
			set_character_flag = removed_one_eyed
		}
		10 = {
			modifier = {
				NOT = {trait = one_handed}
				factor = 0
			}
			set_character_flag = removed_one_handed
		}
		10 = {
			modifier = {
				NOT = {trait = one_legged}
				factor = 0
			}
			set_character_flag = removed_one_legged
		}
		5 = {
			modifier = {
				NOT = {trait = disfigured}
				factor = 0
			}
			set_character_flag = removed_disfigured
		}
	}
}

remove_random_disease_effect = { # Do actual trait removal in event. This is a clunky solution, but communication to player has been prioritised for the sake of event MNM.7119
	random_list = {
		40 = {
			modifier = {
				NOT = { trait = flu }
				factor = 0
			}
			set_character_flag = removing_flu
		}
		20 = {
			modifier = {
				NOT = { trait = has_measles }
				factor = 0
			}
			set_character_flag = removing_measles
		}
		40 = {
			modifier = {
				NOT = {
					trait = food_poisoning
				}
				factor = 0
			}
			set_character_flag = removing_food_poisoning
		}
		20 = {
			modifier = {
				NOT = { trait = gout }
				factor = 0
			}
			set_character_flag = removing_gout
		}
		40 = {
			modifier = {
				NOT = { trait = scurvy }
				factor = 0
			}
			set_character_flag = removing_scurvy
		}
		20 = {
			modifier = {
				NOT = { trait = lovers_pox }
				factor = 0
			}
			set_character_flag = removing_lovers_pox
		}
		5 = {
			modifier = {
				NOT = { trait = cancer }
				factor = 0
			}
			set_character_flag = removing_cancer
		}
		10 = {
			modifier = {
				NOT = { trait = pneumonic }
				factor = 0
			}
			set_character_flag = removing_pneumonic
		}
		10 = {
			modifier = {
				NOT = { trait = syphilitic }
				factor = 0
			}
			set_character_flag = removing_syphilitic
		}
		5 = {
			modifier = {
				NOT = { trait = leper }
				factor = 0
			}
			set_character_flag = removing_leper
		}
	}
}

remove_random_epidemic_disease_effect = {
	random_list = {
		10 = {
			modifier = {
				NOT = { trait = has_tuberculosis}
				factor = 0
			}
			set_character_flag = removing_has_tuberculosis
		}
		10 = {
			modifier = {
				NOT = { trait = has_aztec_disease}
				factor = 0
			}
			set_character_flag = removing_has_aztec_disease
		}
		10 = {
			modifier = {
				NOT = { trait = has_small_pox}
				factor = 0
			}
			set_character_flag = removing_has_small_pox
		}
		10 = {
			modifier = {
				NOT = { trait = has_bubonic_plague}
				factor = 0
			}
			set_character_flag = removing_has_bubonic_plague
		}
		10 = {
			modifier = {
				NOT = { trait = has_typhus}
				factor = 0
			}
			set_character_flag = removing_has_typhus
		}
		10 = {
			modifier = {
				NOT = { trait = has_typhoid_fever}
				factor = 0
			}
			set_character_flag = removing_has_typhoid_fever
		}
		10 = {
			modifier = {
				NOT = { trait = has_measles}
				factor = 0
			}
			set_character_flag = removing_measles
		}

	}
}

remove_symptoms_effect = {
	if = {
		limit = { trait = cough}
		remove_trait = cough
	}
	if = {
		limit = { trait = fever}
		remove_trait = fever
	}
	if = {
		limit = { trait = diarrhea}
		remove_trait = diarrhea
	}
	if = {
		limit = { trait = vomiting}
		remove_trait = vomiting
	}
	if = {
		limit = { trait = chest_pain}
		remove_trait = chest_pain
	}
	if = {
		limit = { trait = cramps}
		remove_trait = cramps
	}
	if = {
		limit = { trait = rash}
		remove_trait = rash
	}
	if = {
		limit = { trait = headache}
		remove_trait = headache
	}
	if = {
		limit = { trait = abdominal_pain}
		remove_trait = abdominal_pain
	}
	if = {
		limit = { trait = fatigue}
		remove_trait = fatigue
	}
	if = {
		limit = { trait = malaise}
		remove_trait = malaise
	}
}

remove_random_negative_congenital_effect = {
	random_list = {
		10 = {
			modifier = {
				NOT = { trait = clubfooted }
				factor = 0
			}
			remove_trait = clubfooted
		}
		10 = {
			modifier = {
				NOT = { trait = harelip }
				factor = 0
			}
			remove_trait = harelip
		}
		10 = {
			modifier = {
				NOT = { trait = hunchback }
				factor = 0
			}
			remove_trait = hunchback
		}
		10 = {
			modifier = {
				NOT = { trait = lisp }
				factor = 0
			}
			remove_trait = lisp
		}
		10 = {
			modifier = {
				NOT = { trait = stutter }
				factor = 0
			}
			remove_trait = stutter
		}
		10 = {
			modifier = {
				NOT = { trait = ugly }
				factor = 0
			}
			remove_trait = ugly
		}
		10 = {
			modifier = {
				NOT = { trait = dwarf }
				factor = 0
			}
			remove_trait = dwarf
		}
		10 = {
			modifier = {
				NOT = { trait = slow }
				factor = 0
			}
			remove_trait = slow
		}
		10 = {
			modifier = {
				NOT = { trait = imbecile }
				factor = 0
			}
			remove_trait = imbecile
		}
		10 = {
			modifier = {
				NOT = { trait = inbred }
				factor = 0
			}
			remove_trait = inbred
		}
		10 = {
			modifier = {
				NOT = { trait = weak }
				factor = 0
			}
			remove_trait = weak
		}
	}
}

join_from_devil_worshiper_society_effect = {
	FROM = {
		if = {
			limit = {
				society_member_of = the_satanists
			}
			ROOT = {
				join_society = the_satanists
			}
		}
		if = {
			limit = {
				society_member_of = the_cold_ones
			}
			ROOT = {
				join_society = the_cold_ones
			}
		}
		if = {
			limit = {
				society_member_of = the_plaguebringers
			}
			ROOT = {
				join_society = the_plaguebringers
			}
		}
		if = {
			limit = {
				society_member_of = the_cult_of_kali
			}
			ROOT = {
				join_society = the_cult_of_kali
			}
		}
		if = {
			limit = {
				society_member_of = the_cult_of_balor
			}
			ROOT = {
				join_society = the_cult_of_balor
			}
		}
		if = {
			limit = {
				society_member_of = cult_of_angra_mainyu
			}
			ROOT = {
				join_society = cult_of_angra_mainyu
			}
		}
		if = {
			limit = {
				society_member_of = the_trollcrafters
			}
			ROOT = {
				join_society = the_trollcrafters
			}
		}
		if = {
			limit = {
				society_member_of = arab_jinn_sorcerers
			}
			ROOT = {
				join_society = arab_jinn_sorcerers
			}
		}
		if = {
			limit = {
				society_member_of = cult_of_titan
			}
			ROOT = {
				join_society = cult_of_titan
			}
		}
		if = {
			limit = {
				society_member_of = cult_of_apep
			}
			ROOT = {
				join_society = cult_of_apep
			}
		}
	}
}

remove_demonic_blessing_effect = {
	if = { limit = { has_character_modifier = blessing_of_azazel }
		remove_character_modifier = blessing_of_azazel
	}
	if = { limit = { has_character_modifier = blessing_of_avnas }
		remove_character_modifier = blessing_of_avnas
	}
	if = { limit = { has_character_modifier = blessing_of_belial }
		remove_character_modifier = blessing_of_belial
	}
	if = { limit = { has_character_modifier = blessing_of_mammon }
		remove_character_modifier = blessing_of_mammon
	}
	if = { limit = { has_character_modifier = blessing_of_vetis }
		remove_character_modifier = blessing_of_vetis
	}
}

add_prolong_life_effect = {
	if = {
		limit = {
			NOR = {
				has_character_modifier = stolen_life_minor
				has_character_modifier = stolen_life_medium
				has_character_modifier = stolen_life_major
			}
		}
		random_list = {
			10 = {
				add_character_modifier = {
					name = stolen_life_minor
					days = 3650
				}			
			}
			10 = {
				add_character_modifier = {
					name = stolen_life_medium
					days = 3650
				}
			}
			10 = {
				add_character_modifier = {
					name = stolen_life_major
					days = 3650
				}
			}
		}
		break = yes
	}
	if = {
		limit = {
			OR = {
				has_character_modifier = stolen_life_minor
				has_character_modifier = stolen_life_medium
			}
		}
		hidden_effect = {
			remove_character_modifier = stolen_life_minor
			remove_character_modifier = stolen_life_medium
		}
		add_character_modifier = {
					name = stolen_life_major
					days = 3650
		}
		break = yes
	}
	add_character_modifier = {
		name = stolen_life_major
		days = 3650
	}
}

join_prev_devil_worshiper_society_effect = {
	if = {
		limit = { PREV = { society_member_of = the_satanists } }
		join_society = the_satanists
	}
	if = {
		limit = { PREV = { society_member_of = the_cold_ones } }
		join_society = the_cold_ones
	}
	if = {
		limit = { PREV = { society_member_of = the_plaguebringers } }
		join_society = the_plaguebringers
	}
	if = {
		limit = { PREV = { society_member_of = the_cult_of_balor } }
		join_society = the_cult_of_balor
	}
	if = {
		limit = { PREV = { society_member_of = cult_of_angra_mainyu } }
		join_society = cult_of_angra_mainyu
	}
	if = {
		limit = { PREV = { society_member_of = the_cult_of_kali } }
		join_society = the_cult_of_kali
	}
	if = {
		limit = { PREV = { society_member_of = the_trollcrafters } }
		join_society = the_trollcrafters
	}
	if = {
		limit = { PREV = { society_member_of = arab_jinn_sorcerers } }
		join_society = arab_jinn_sorcerers
	}
	if = {
		limit = { PREV = { society_member_of = cult_of_titan } }
		join_society = cult_of_titan
	}
	if = {
		limit = { PREV = { society_member_of = cult_of_apep } }
		join_society = cult_of_apep
	}
}

remove_education_effect = {
	remove_trait = naive_appeaser
	remove_trait = underhanded_rogue
	remove_trait = charismatic_negotiator
	remove_trait = grey_eminence
	remove_trait = misguided_warrior
	remove_trait = tough_soldier
	remove_trait = skilled_tactician
	remove_trait = brilliant_strategist
	remove_trait = indulgent_wastrel
	remove_trait = thrifty_clerk
	remove_trait = fortune_builder
	remove_trait = midas_touched
	remove_trait = amateurish_plotter
	remove_trait = flamboyant_schemer
	remove_trait = intricate_webweaver
	remove_trait = elusive_shadow
	remove_trait = detached_priest
	remove_trait = martial_cleric
	remove_trait = scholarly_theologian
	remove_trait = mastermind_theologian
}

remove_lifestyle_trait_effect = {
	remove_trait = hedonist
	remove_trait = scholar
	remove_trait = gardener
	remove_trait = mystic
	remove_trait = impaler
	remove_trait = duelist
	remove_trait = hunter
	remove_trait = seducer
	remove_trait = seductress
	remove_trait = administrator
	remove_trait = architect
	remove_trait = strategist
	remove_trait = socializer
	remove_trait = schemer
	remove_trait = theologian
	remove_trait = gamer
}

monastic_order_purity_effect = {
	if = {
		limit = {
			is_monastic_member_trigger = yes
			OR = {
				trait = cynical
				trait = gluttonous
				trait = greedy
				trait = slothful
				trait = envious
				trait = wroth
				trait = proud
				trait = deceitful
				trait = cruel
				AND = {
					trait = lustful
					NOT = { religion = hindu }
				}
				trait = ambitious
				NOT = { trait = humble }
				NOT = { trait = charitable }
				NOT = { trait = kind }
				NOT = { trait = temperate }
				NOT = { trait = honest }
				NAND = {
					trait = chaste
					NOT = { religion = hindu }
				}
				NOT = { trait = patient }
				NOT = { trait = diligent }
				NOT = { trait = content }
			}
		}

		random = {
			chance = 20
			modifier = {
				factor = 1.3
				society_rank == 2
			}
			modifier = {
				factor = 1.5
				society_rank == 3
			}
			modifier = {
				factor = 1.7
				society_rank == 4
			}
			modifier = {
				factor = 1.1
				piety = 100
			}
			modifier = {
				factor = 1.3
				piety = 300
			}
			modifier = {
				factor = 1.5
				piety = 500
			}
			modifier = {
				factor = 2
				piety = 1000
			}
			modifier = {
				factor = 3
				OR = {
					society_member_of = monastic_order_jain
					society_member_of = monastic_order_buddhist
				}
			}
			character_event = { id = MNM.4400 days = 10 random = 10 }
		}
	}
}

join_prev_monastic_order_society = {
	if = {
		limit = { PREV = { society_member_of = monastic_order_orthodox } }
		join_society = monastic_order_orthodox
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_benedictine } }
		join_society = monastic_order_benedictine
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_dominican } }
		join_society = monastic_order_dominican
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_nestorian } }
		join_society = monastic_order_nestorian
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_monophysite } }
		join_society = monastic_order_monophysite
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_apostolic } }
		join_society = monastic_order_apostolic
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_hindu } }
		join_society = monastic_order_hindu
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_buddhist } }
		join_society = monastic_order_buddhist
	}
	if = {
		limit = { PREV = { society_member_of = monastic_order_jain } }
		join_society = monastic_order_jain
	}
}

clr_artifact_flagsmodifiers_effect = {
	event_target:relic_ruler = { 
		if = {
			limit = { has_character_modifier = relic_rumor_minor }
			remove_character_modifier = relic_rumor_minor
		}
		if = {
			limit = { has_character_modifier = relic_rumor_medium }
			remove_character_modifier = relic_rumor_medium
		}
		if = {
			limit = { has_character_modifier = relic_rumor_major }
			remove_character_modifier = relic_rumor_major
		}	
	}
	clr_artifact_searcher_effect = yes
}

clr_artifact_searcher_effect = {
	event_target:relic_ruler = { 
		if = {
			limit = { has_character_modifier = pays_for_artifact_hunt_minor }
			remove_character_modifier = pays_for_artifact_hunt_minor
		}
		if = {
			limit = { has_character_modifier = pays_for_artifact_hunt_medium }
			remove_character_modifier = pays_for_artifact_hunt_medium
		}
		if = {
			limit = { has_character_modifier = pays_for_artifact_hunt_major }
			remove_character_modifier = pays_for_artifact_hunt_major
		}
		# from the progress events....
		if = {
			limit = { has_character_modifier = treasure_hunting_diplomats }
			remove_character_modifier = treasure_hunting_diplomats
		}
		if = {
			limit = { has_character_modifier = treasure_hunting_soldiers }
			remove_character_modifier = treasure_hunting_soldiers
		}
		if = {
			limit = { has_character_modifier = treasure_hunting_stewards }
			remove_character_modifier = treasure_hunting_stewards
		}
		if = {
			limit = { has_character_modifier = treasure_hunting_spies }
			remove_character_modifier = treasure_hunting_spies
		}
		if = {
			limit = { has_character_modifier = treasure_hunting_scholars }
			remove_character_modifier = treasure_hunting_scholars
		}
		clr_character_flag = they_asked_for_your_help
	}
	hidden_effect = {
		event_target:relic_hunter = { clr_character_flag = relic_hunter }
	}
}

add_artifact_search_payment_effect = {
	if = {
		limit = { has_character_modifier = relic_rumor_minor }
		add_character_modifier =  { name = pays_for_artifact_hunt_minor duration = -1 }
	}
	if = {
		limit = { has_character_modifier = relic_rumor_medium }
		add_character_modifier =  { name = pays_for_artifact_hunt_medium duration = -1 }
	}
	if = {
		limit = { has_character_modifier = relic_rumor_major }
		add_character_modifier =  { name = pays_for_artifact_hunt_major duration = -1 }
	}
}

random_accident_death_effect = {
	tooltip = { death = { death_reason = death_accident } }
	hidden_effect = {
		random_list = {
			10 = { 
				modifier = { factor = 0 host = { capital_scope = { region = world_africa } } }
				death = { death_reason = death_accident_drowning }
			}
			10 = { 
				modifier = { factor = 0 host = { capital_scope = { region = world_africa } } }
				death = { death_reason = death_accident_bear }
			}
			10 = { 
				death = { death_reason = death_accident_boar }
			}
			10 = {
				death = { death_reason = death_accident_fall }
			}
			10 = {
				death = { death_reason = death_accident_arrow }
			}
			10 = {
				death = { death_reason = death_accident_snakes }
			}
			10 = {
				modifier = { factor = 0 host = { capital_scope = { region = world_india } } }
				death = { death_reason = death_accident_tiger }
			}
		}
	}
}

spawn_peasant_army_effect = {
	random_list = {
		17 = {
			
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 0.8
				troops = {
					archers = { 6 6 }
					light_cavalry = { 4 4 }
					light_infantry = { 10 10 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		17 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 0.5
				troops = {
					archers = { 6 6 }
					light_cavalry = { 4 4 }
					light_infantry = { 10 10 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		16 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 0.8
				troops = {
					archers = { 6 6 }
					light_cavalry = { 3 3 }
					light_infantry = { 11 11 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		17 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 0.5
				troops = {
					archers = { 6 6 }
					light_cavalry = { 3 3 }
					light_infantry = { 11 11 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		16 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 0.8
				troops = {
					archers = { 6 6 }
					light_infantry = { 14 14 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		17 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 0.5
				troops = {
					archers = { 6 6 }
					light_infantry = { 14 14 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}
}

spawn_peasant_reinforcements_effect = {
	random_list = {
		17 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		17 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		16 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		17 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_cavalry = { 3 3 }
						light_infantry = { 11 11 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		16 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.8
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		17 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 31
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 0.5
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}
}

spawn_heretic_army_effect = {
	random_list = {
		34 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.1
				troops = {
					archers = { 6 6 }
					light_cavalry = { 4 4 }
					light_infantry = { 10 10 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.1
				troops = {
					archers = { 6 6 }
					light_cavalry = { 2 2 }
					light_infantry = { 12 12 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.1
				troops = {
					archers = { 6 6 }
					light_infantry = { 14 14 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}
}

spawn_heretic_reinforcements_effect = {
	random_list = {
		34 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}
}

spawn_nationalist_army_effect = {
	random_list = {
		30 = {
			spawn_unit = {
				province = PREV
				home = PREV
				owner = ROOT
				#leader = THIS
				scaled_by_biggest_garrison = 1.6
				troops = {
					archers = { 6 6 }
					light_cavalry = { 3 3 }
					knights = { 1 1 }
					light_infantry = { 7 7 }
					heavy_infantry = { 3 3 }
				}
				disband_on_peace = yes
				attrition = 0.5
				maintenance_multiplier = 0
				earmark = nationalist_rebels
			}
		}
		30 = {
			spawn_unit = {
				province = PREV
				home = PREV
				owner = ROOT
				#leader = THIS
				scaled_by_biggest_garrison = 1.3
				troops = {
					archers = { 6 6 }
					light_cavalry = { 3 3 }
					knights = { 1 1 }
					light_infantry = { 7 7 }
					heavy_infantry = { 3 3 }
				}
				disband_on_peace = yes
				attrition = 0.5
				maintenance_multiplier = 0
				earmark = nationalist_rebels
			}
		}
		30 = {
			spawn_unit = {
				province = PREV
				home = PREV
				owner = ROOT
				#leader = THIS
				scaled_by_biggest_garrison = 1
				troops = {
					archers = { 6 6 }
					light_cavalry = { 3 3 }
					knights = { 1 1 }
					light_infantry = { 7 7 }
					heavy_infantry = { 3 3 }
				}
				disband_on_peace = yes
				attrition = 0.5
				maintenance_multiplier = 0
				earmark = nationalist_rebels
			}
		}
	}
}

spawn_nationalist_reinforcements_effect = {
	create_character = {
		random_traits = yes
		dynasty = none
		religion = ROOT
		culture = ROOT
		female = no
		age = 24
		attributes = {
			martial = 7
		}
		trait = skilled_tactician
	}
	new_character = {
		spawn_unit = {
			province = ROOT
			home = ROOT
			owner = PREV
			#leader = THIS
			scaled_by_biggest_garrison = 1.6
			troops = {
				archers = { 6 6 }
				light_cavalry = { 3 3 }
				knights = { 1 1 }
				light_infantry = { 7 7 }
				heavy_infantry = { 3 3 }
			}
			disband_on_peace = yes
		}
	}
	create_character = {
		random_traits = yes
		dynasty = none
		religion = ROOT
		culture = ROOT
		female = no
		age = 27
		attributes = {
			martial = 7
		}
		trait = skilled_tactician
	}
	new_character = {
		spawn_unit = {
			province = ROOT
			home = ROOT
			owner = PREV
			#leader = THIS
			scaled_by_biggest_garrison = 1.6
			troops = {
				archers = { 6 6 }
				light_cavalry = { 3 3 }
				knights = { 1 1 }
				light_infantry = { 7 7 }
				heavy_infantry = { 3 3 }
			}
			disband_on_peace = yes
		}
	}
	create_character = {
		random_traits = yes
		dynasty = none
		religion = ROOT
		culture = ROOT
		female = no
		age = 30
		attributes = {
			martial = 7
		}
		trait = skilled_tactician
	}
	new_character = {
		spawn_unit = {
			province = ROOT
			home = ROOT
			owner = PREV
			#leader = THIS
			scaled_by_biggest_garrison = 1.6
			troops = {
				archers = { 6 6 }
				light_cavalry = { 3 3 }
				knights = { 1 1 }
				light_infantry = { 7 7 }
				heavy_infantry = { 3 3 }
			}
			disband_on_peace = yes
		}
	}
}

spawn_religious_army_effect = {
	random_list = {
		34 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.1
				troops = {
					archers = { 6 6 }
					light_cavalry = { 4 4 }
					light_infantry = { 10 10 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.1
				troops = {
					archers = { 6 6 }
					light_cavalry = { 2 2 }
					light_infantry = { 12 12 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.1
				troops = {
					archers = { 6 6 }
					light_infantry = { 14 14 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}
}

spawn_religious_reinforcements_effect = {
	random_list = {
		34 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 25
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					cannot_inherit = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.1
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}	
}

spawn_decadence_army_effect = {
	random_list = {
		34 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.2
				troops = {
					archers = { 6 6 }
					light_cavalry = { 4 4 }
					light_infantry = { 10 10 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.2
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.2
					troops = {
						archers = { 6 6 }
						light_cavalry = { 4 4 }
						light_infantry = { 10 10 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.2
				troops = {
					archers = { 6 6 }
					light_cavalry = { 2 2 }
					light_infantry = { 12 12 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.2
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.2
					troops = {
						archers = { 6 6 }
						light_cavalry = { 2 2 }
						light_infantry = { 12 12 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
		33 = {
			spawn_unit = {
				province = ROOT
				home = ROOT
				owner = THIS
				#leader = THIS
				scaled_by_biggest_garrison = 1.2
				troops = {
					archers = { 6 6 }
					light_infantry = { 14 14 }
				}
				attrition = 1.0
				cannot_inherit = yes
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 30
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.2
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
			create_character = {
				random_traits = yes
				dynasty = none
				religion = THIS
				culture = THIS
				female = no
				age = 23
				trait = peasant_leader
				trait = tough_soldier
			}
			new_character = {
				spawn_unit = {
					province = ROOT
					home = ROOT
					owner = PREV
					scaled_by_biggest_garrison = 1.2
					troops = {
						archers = { 6 6 }
						light_infantry = { 14 14 }
					}
					attrition = 1.0
					disband_on_peace = yes
				}
			}
		}
	}
}

spawn_decadence_reinforcements_effect = {
	create_character = {
		random_traits = yes
		dynasty = none
		religion = ROOT
		culture = ROOT
		female = no
		age = 24
		attributes = {
			martial = 7
		}
		trait = skilled_tactician
	}
	new_character = {
		spawn_unit = {
			province = ROOT
			home = ROOT
			owner = PREV
			#leader = THIS
			scaled_by_biggest_garrison = 1
			troops = {
				archers = { 6 6 }
				light_cavalry = { 3 3 }
				knights = { 1 1 }
				light_infantry = { 7 7 }
				heavy_infantry = { 3 3 }
			}
			disband_on_peace = yes
		}
	}
	create_character = {
		random_traits = yes
		dynasty = none
		religion = ROOT
		culture = ROOT
		female = no
		age = 27
		attributes = {
			martial = 7
		}
		trait = skilled_tactician
	}
	new_character = {
		spawn_unit = {
			province = ROOT
			home = ROOT
			owner = PREV
			#leader = THIS
			scaled_by_biggest_garrison = 1
			troops = {
				archers = { 6 6 }
				light_cavalry = { 3 3 }
				knights = { 1 1 }
				light_infantry = { 7 7 }
				heavy_infantry = { 3 3 }
			}
			disband_on_peace = yes
		}
	}
	create_character = {
		random_traits = yes
		dynasty = none
		religion = ROOT
		culture = ROOT
		female = no
		age = 30
		attributes = {
			martial = 7
		}
		trait = skilled_tactician
	}
	new_character = {
		spawn_unit = {
			province = ROOT
			home = ROOT
			owner = PREV
			#leader = THIS
			scaled_by_biggest_garrison = 1
			troops = {
				archers = { 6 6 }
				light_cavalry = { 3 3 }
				knights = { 1 1 }
				light_infantry = { 7 7 }
				heavy_infantry = { 3 3 }
			}
			disband_on_peace = yes
		}
	}
}

add_ascetic_trait_effect = {
	if = {
		limit = { is_female = yes }
		if = {
			limit = {
				religion_group = christian
				NOR = {
					religion = miaphysite
					religion = monophysite
					religion = cathar
					religion = bogomilist
				}
			}
			add_trait = nun
			set_character_flag = title_nun
			set_special_character_title = NUN_SISTER
		}
		if = {
			limit = {
				OR = {
					religion = miaphysite
					religion = monophysite
				}
			}
			add_trait = desert_mother
			set_character_flag = title_desert_mother
			set_special_character_title = DESERT_MOTHER_TITLE
		}
		if = {
			limit = {
				OR = {
					religion = cathar
					religion = bogomilist
				}
			}
			remove_trait = cynical
			remove_trait = lustful
			remove_trait = hedonist
			remove_trait = seducer
			remove_trait = seductress
			add_trait = zealous
			add_trait = perfecti
			set_character_flag = consolamentum_taken
			set_character_flag = title_nun
			set_special_character_title = NUN_SISTER
		}
		if = {
			limit = { religion = jain }
			add_trait = aryika
		}
		if = {
			limit = { religion = buddhist }
			add_trait = bhikkhuni
		}
		if = {
			limit = { religion = hindu }
			add_trait = sanyasini
		}
	}
	if = {
		limit = { is_female = no }
		if = {
			limit = {
				religion_group = christian
				NOR = {
					religion = miaphysite
					religion = monophysite
					religion = cathar
					religion = bogomilist
				}
			}
			add_trait = monk
			set_character_flag = title_monk
			set_special_character_title = MONK_BROTHER
		}
		if = {
			limit = {
				OR = {
					religion = miaphysite
					religion = monophysite
				}
			}
			add_trait = desert_father
			set_character_flag = title_desert_father
			set_special_character_title = DESERT_FATHER_TITLE
		}
		if = {
			limit = {
				OR = {
					religion = cathar
					religion = bogomilist
				}
			}
			remove_trait = cynical
			remove_trait = lustful
			remove_trait = hedonist
			remove_trait = seducer
			remove_trait = seductress
			add_trait = zealous
			add_trait = perfecti
			set_character_flag = consolamentum_taken
			set_character_flag = title_monk
			set_special_character_title = MONK_BROTHER
		}
		if = {
			limit = { religion = jain }
			add_trait = muni
		}
		if = {
			limit = { religion = buddhist }
			add_trait = bhikkhu
		}
		if = {
			limit = { religion = hindu }
			add_trait = sanyasi
		}
		if = {
			limit = {
				OR = {
					religion = celtic_pagan
					religion = celtic_pagan_reformed
				}
			}
			add_trait = druid
		}
	}
}

print_scope_effect = {
	log = "------------------------------"
	log = "- Printing the current scope -"
	log = "- This: [This.GetName][This.GetBestName]"
	log = "- Root: [Root.GetName][Root.GetBestName]"
	log = "- Prev: [Prev.GetName][Prev.GetBestName]"
	log = "- PrevPrev: [PrevPrev.GetName][PrevPrev.GetBestName]"
	log = "- PrevPrevPrev: [PrevPrevPrev.GetName][PrevPrevPrev.GetBestName]"
	log = "- PrevPrevPrevPrev: [PrevPrevPrevPrev.GetName][PrevPrevPrevPrev.GetBestName]"
	log = "- From: [From.GetName][From.GetBestName]"
	log = "- FromFrom: [FromFrom.GetName][FromFrom.GetBestName]"
	log = "- FromFromFrom: [FromFromFrom.GetName][FromFromFrom.GetBestName]"
	log = "- FromFromFromFrom: [FromFromFromFrom.GetName][FromFromFromFrom.GetBestName]"
	log = "- Event_target:test_target1: [test_target1.GetName][test_target1.GetBestName]"
	log = "- Event_target:test_target2: [test_target2.GetName][test_target2.GetBestName]"
	log = "- Event_target:test_target3: [test_target3.GetName][test_target3.GetBestName]"
	log = "------------------------------"
}

add_sympathy_for_prevs_true_religion_effect = {
	if = {
		limit = {
			PREV = { true_religion_group_christian_trigger = yes }
			NOT = { religion_group = christian }
		}
		add_trait = sympathy_christendom
	}
	if = {
		limit = {
			PREV = { true_religion_group_muslim_trigger = yes }
			NOT = { religion_group = muslim }
		}
		add_trait = sympathy_islam
	}
	if = {
		limit = { 
			PREV = { true_religion_is_pagan = yes }
			NOT = { is_pagan_religion = yes }
		}
		add_trait = sympathy_pagans
	}
	if = {
		limit = {
			PREV = { true_religion_group_zoroastrian_group_trigger = yes }
			NOT = { religion_group = zoroastrian_group}
		}
		add_trait = sympathy_zoroastrianism
	}
	if = {
		limit = {
			PREV = { true_religion_group_jewish_group_trigger = yes }
			NOT = { religion_group = jewish_group }
		}
		add_trait = sympathy_judaism
	}
	if = {
		limit = {
			PREV = { true_religion_group_indian_group_trigger = yes }
			NOT = { religion_group = indian_group }
		}
		add_trait = sympathy_indian
	}
}

add_sympathy_for_prevs_open_religion_effect = {
	if = {
		limit = { 
			PREV = { religion_group = christian } 
			NOT = { religion_group = christian }
		}
		add_trait = sympathy_christendom
	}
	if = {
		limit = { 
			PREV = { religion_group = muslim } 
			NOT = { religion_group = muslim }
		}
		add_trait = sympathy_islam
	}
	if = {
		limit = { 
			PREV = { true_religion_is_pagan = yes } 
			NOT = { is_pagan_religion = yes }
		}
		add_trait = sympathy_pagans
	}
	if = {
		limit = { 
			PREV = { religion_group = zoroastrian_group } 
			NOT = { religion_group = zoroastrian_group }
		}
		add_trait = sympathy_zoroastrianism
	}
	if = {
		limit = { 
			PREV = { religion_group = jewish_group } 
			NOT = { religion_group = jewish_group }
		}
		add_trait = sympathy_judaism
	}
	if = {
		limit = { 
			PREV = { religion_group = indian_group } 
			NOT = { religion_group = indian_group }
		}
		add_trait = sympathy_indian
	}
}

add_trait_for_prevs_secret_religion_society_effect = {
	set_secret_religion = PREV
}
flip_to_secret_religion_effect = {
	convert_to_secret_religion = yes
}


add_prevs_secret_religion_trait_effect = {
	set_secret_religion = PREV
}

#Used in different sutiation, there conditions on effect. Flag has precedence over religion.
add_secret_religion_trait_trigger_is_religion_or_old_religion_flag_clear_flag_after_effect_is_run_this_name_is_a_tribute_to_m_effect = {
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = catholic
				}
				has_character_flag = character_was_catholic
			}
		}
		set_secret_religion = catholic	
		clr_character_flag = character_was_catholic
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = cathar
				}
				has_character_flag = character_was_cathar
			}
		}
		set_secret_religion = cathar	
		clr_character_flag = character_was_cathar
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = fraticelli
				}
				has_character_flag = character_was_fraticelli
			}
		}
		set_secret_religion = fraticelli	
		clr_character_flag = character_was_fraticelli
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = waldensian
				}
				has_character_flag = character_was_waldensian
			}
		}
		set_secret_religion = waldensian	
		clr_character_flag = character_was_waldensian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = lollard
				}
				has_character_flag = character_was_lollard
			}
		}
		set_secret_religion = lollard	
		clr_character_flag = character_was_lollard
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = adoptionist
				}
				has_character_flag = character_was_adoptionist
			}
		}
		set_secret_religion = adoptionist	
		clr_character_flag = character_was_adoptionist
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = chalcedonian
				}
				has_character_flag = character_was_chalcedonian
			}
		}
		set_secret_religion = chalcedonian
		clr_character_flag = character_was_chalcedonian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = orthodox
				}
				has_character_flag = character_was_orthodox
			}
		}
		set_secret_religion = orthodox
		clr_character_flag = character_was_orthodox
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = bogomilist
				}
				has_character_flag = character_was_bogomilist
			}
		}
		set_secret_religion = bogomilist
		clr_character_flag = character_was_bogomilist
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = monothelite
				}
				has_character_flag = character_was_monothelite
			}
		}
		set_secret_religion = monothelite
		clr_character_flag = character_was_monothelite
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = iconoclast
				}
				has_character_flag = character_was_iconoclast
			}
		}
		set_secret_religion = iconoclast
		clr_character_flag = character_was_iconoclast
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = nestorian
				}
				has_character_flag = character_was_nestorian
			}
		}
		set_secret_religion = nestorian	
		clr_character_flag = character_was_nestorian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = messalian
				}
				has_character_flag = character_was_messalian
			}
		}
		set_secret_religion = messalian	
		clr_character_flag = character_was_messalian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = miaphysite
				}
				has_character_flag = character_was_miaphysite
			}
		}
		set_secret_religion = miaphysite	
		clr_character_flag = character_was_miaphysite
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = monophysite
				}
				has_character_flag = character_was_monophysite
			}
		}
		set_secret_religion = monophysite	
		clr_character_flag = character_was_monophysite
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = apostolic
				}
				has_character_flag = character_was_apostolic
			}
		}
		set_secret_religion = apostolic
		clr_character_flag = character_was_apostolic
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = paulician
				}
				has_character_flag = character_was_paulician
			}
		}
		set_secret_religion = paulician
		clr_character_flag = character_was_paulician
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = tondrakian
				}
				has_character_flag = character_was_tondrakian
			}
		}
		set_secret_religion = tondrakian
		clr_character_flag = character_was_tondrakian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = ibadi
				}
				has_character_flag = character_was_ibadi
			}
		}
		set_secret_religion = ibadi
		clr_character_flag = character_was_ibadi
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = kharijite
				}
				has_character_flag = character_was_kharijite
			}
		}
		set_secret_religion = kharijite
		clr_character_flag = character_was_kharijite
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = manichean
				}
				has_character_flag = character_was_manichean
			}
		}
		set_secret_religion = manichean
		clr_character_flag = character_was_manichean
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = khurmazta
				}
				has_character_flag = character_was_khurmazta
			}
		}
		set_secret_religion = khurmazta
		clr_character_flag = character_was_khurmazta
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = taoist
				}
				has_character_flag = character_was_taoist
			}
		}
		set_secret_religion = taoist
		clr_character_flag = character_was_taoist
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = bon
				}
				has_character_flag = character_was_bon
			}
		}
		set_secret_religion = bon
		clr_character_flag = character_was_bon
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = tibetan_pagan
				}
				has_character_flag = character_was_tibetan_pagan
			}
		}
		set_secret_religion = tibetan_pagan
		clr_character_flag = character_was_tibetan_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = sunni
				}
				has_character_flag = character_was_sunni
			}
		}
		set_secret_religion = sunni
		clr_character_flag = character_was_sunni
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = zikri
				}
				has_character_flag = character_was_zikri
			}
		}
		set_secret_religion = zikri
		clr_character_flag = character_was_zikri
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = quranist
				}
				has_character_flag = character_was_quranist
			}
		}
		set_secret_religion = quranist
		clr_character_flag = character_was_quranist
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = shiite
				}
				has_character_flag = character_was_shiite
			}
		}
		set_secret_religion = shiite
		clr_character_flag = character_was_shiite
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = bektashi
				}
				has_character_flag = character_was_bektashi
			}
		}
		set_secret_religion = bektashi
		clr_character_flag = character_was_bektashi
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = druze
				}
				has_character_flag = character_was_druze
			}
		}
		set_secret_religion = druze
		clr_character_flag = character_was_druze
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = hurufi
				}
				has_character_flag = character_was_hurufi
			}
		}
		set_secret_religion = hurufi
		clr_character_flag = character_was_hurufi
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = qarmatian
				}
				has_character_flag = character_was_qarmatian
			}
		}
		set_secret_religion = qarmatian
		clr_character_flag = character_was_qarmatian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = jewish
				}
				has_character_flag = character_was_jewish
			}
		}
		set_secret_religion = jewish
		clr_character_flag = character_was_jewish
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = samaritan
				}
				has_character_flag = character_was_samaritan
			}
		}
		set_secret_religion = samaritan
		clr_character_flag = character_was_samaritan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = karaite
				}
				has_character_flag = character_was_karaite
			}
		}
		set_secret_religion = karaite
		clr_character_flag = character_was_karaite
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = zoroastrian
				}
				has_character_flag = character_was_zoroastrian
			}
		}
		set_secret_religion = zoroastrian
		clr_character_flag = character_was_zoroastrian
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = mazdaki
				}
				has_character_flag = character_was_mazdaki
			}
		}
		set_secret_religion = mazdaki
		clr_character_flag = character_was_mazdaki
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = zurvanist
				}
				has_character_flag = character_was_zurvanist
			}
		}
		set_secret_religion = zurvanist
		clr_character_flag = character_was_zurvanist
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = mandaean
				}
				has_character_flag = character_was_mandaean
			}
		}
		set_secret_religion = mandaean
		clr_character_flag = character_was_mandaean
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = yazidi
				}
				has_character_flag = character_was_yazidi
			}
		}
		set_secret_religion = yazidi
		clr_character_flag = character_was_yazidi
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = hindu
				}
				has_character_flag = character_was_hindu
			}
		}
		set_secret_religion = hindu
		clr_character_flag = character_was_hindu
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = buddhist
				}
				has_character_flag = character_was_buddhist
			}
		}
		set_secret_religion = buddhist
		clr_character_flag = character_was_buddhist
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = jain
				}
				has_character_flag = character_was_jain
			}
		}
		set_secret_religion = jain
		clr_character_flag = character_was_jain
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = norse_pagan_reformed
				}
				has_character_flag = character_was_norse_pagan_reformed
			}
		}
		set_secret_religion = norse_pagan_reformed
		clr_character_flag = character_was_norse_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = norse_pagan
				}
				has_character_flag = character_was_norse_pagan
			}
		}
		set_secret_religion = norse_pagan
		clr_character_flag = character_was_norse_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = german_pagan_reformed
				}
				has_character_flag = character_was_german_pagan_reformed
			}
		}
		set_secret_religion = german_pagan_reformed
		clr_character_flag = character_was_german_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = german_pagan
				}
				has_character_flag = character_was_german_pagan
			}
		}
		set_secret_religion = german_pagan
		clr_character_flag = character_was_german_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = roman_pagan
				}
				has_character_flag = character_was_roman_pagan
			}
		}
		set_secret_religion = roman_pagan
		clr_character_flag = character_was_roman_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = hellenic_pagan
				}
				has_character_flag = character_was_hellenic_pagan
			}
		}
		set_secret_religion = hellenic_pagan
		clr_character_flag = character_was_hellenic_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = celtic_pagan_reformed
				}
				has_character_flag = character_was_celtic_pagan_reformed
			}
		}
		set_secret_religion = celtic_pagan_reformed
		clr_character_flag = character_was_celtic_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = celtic_pagan
				}
				has_character_flag = character_was_celtic_pagan
			}
		}
		set_secret_religion = celtic_pagan
		clr_character_flag = character_was_celtic_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = slavic_pagan_reformed
				}
				has_character_flag = character_was_slavic_pagan_reformed
			}
		}
		set_secret_religion = slavic_pagan_reformed
		clr_character_flag = character_was_slavic_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = slavic_pagan
				}
				has_character_flag = character_was_slavic_pagan
			}
		}
		set_secret_religion = slavic_pagan
		clr_character_flag = character_was_slavic_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = tengri_pagan_reformed
				}
				has_character_flag = character_was_tengri_pagan_reformed
			}
		}
		set_secret_religion = tengri_pagan_reformed
		clr_character_flag = character_was_tengri_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = tengri_pagan
				}
				has_character_flag = character_was_tengri_pagan
			}
		}
		set_secret_religion = tengri_pagan
		clr_character_flag = character_was_tengri_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = baltic_pagan_reformed
				}
				has_character_flag = character_was_baltic_pagan_reformed
			}
		}
		set_secret_religion = baltic_pagan_reformed
		clr_character_flag = character_was_baltic_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = baltic_pagan
				}
				has_character_flag = character_was_baltic_pagan
			}
		}
		set_secret_religion = baltic_pagan
		clr_character_flag = character_was_baltic_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = egyptian_pagan
				}
				has_character_flag = character_was_egyptian_pagan
			}
		}
		set_secret_religion = egyptian_pagan
		clr_character_flag = character_was_egyptian_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = finnish_pagan_reformed
				}
				has_character_flag = character_was_finnish_pagan_reformed
			}
		}
		set_secret_religion = finnish_pagan_reformed
		clr_character_flag = character_was_finnish_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = finnish_pagan
				}
				has_character_flag = character_was_finnish_pagan
			}
		}
		set_secret_religion = finnish_pagan
		clr_character_flag = character_was_finnish_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = west_african_pagan_reformed
				}
				has_character_flag = character_was_west_african_pagan_reformed
			}
		}
		set_secret_religion = west_african_pagan_reformed
		clr_character_flag = character_was_west_african_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = west_african_pagan
				}
				has_character_flag = character_was_west_african_pagan
			}
		}
		set_secret_religion = west_african_pagan
		clr_character_flag = character_was_west_african_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = zun_pagan_reformed
				}
				has_character_flag = character_was_zun_pagan_reformed
			}
		}
		set_secret_religion = zun_pagan_reformed
		clr_character_flag = character_was_zun_pagan_reformed
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = zun_pagan
				}
				has_character_flag = character_was_zun_pagan
			}
		}
		set_secret_religion = zun_pagan
		clr_character_flag = character_was_zun_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = arab_pagan
				}
				has_character_flag = character_was_arab_pagan
			}
		}
		set_secret_religion = arab_pagan
		clr_character_flag = character_was_arab_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = berber_pagan
				}
				has_character_flag = character_was_berber_pagan
			}
		}
		set_secret_religion = berber_pagan
		clr_character_flag = character_was_berber_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = jewish_pagan
				}
				has_character_flag = character_was_jewish_pagan
			}
		}
		set_secret_religion = jewish_pagan
		clr_character_flag = character_was_jewish_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = aten_pagan
				}
				has_character_flag = character_was_aten_pagan
			}
		}
		set_secret_religion = aten_pagan
		clr_character_flag = character_was_aten_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = promethean_pagan
				}
				has_character_flag = character_was_promethean_pagan
			}
		}
		set_secret_religion = promethean_pagan
		clr_character_flag = character_was_promethean_pagan
	}
	if = {
		limit = { 
			OR = {
				AND = {
					has_former_religion_flag_trigger = no
					religion = aztec
				}
				has_character_flag = character_was_aztec
			}
		}
		set_secret_religion = aztec
		clr_character_flag = character_was_aztec
	}
}

add_religion_char_flag_effect = {
	if = {
		limit = { religion = catholic }
		set_character_flag = character_was_catholic
	}
	if = {
		limit = { religion = cathar }
		set_character_flag = character_was_cathar
	}
	if = {
		limit = { religion = fraticelli }
		set_character_flag = character_was_fraticelli
	}
	if = {
		limit = { religion = waldensian }
		set_character_flag = character_was_waldensian
	}
	if = {
		limit = { religion = lollard }
		set_character_flag = character_was_lollard
	}
	if = {
		limit = { religion = adoptionist }
		set_character_flag = character_was_adoptionist
	}
	if = {
		limit = { religion = chalcedonian }
		set_character_flag = character_was_chalcedonian
	}
	if = {
		limit = { religion = orthodox }
		set_character_flag = character_was_orthodox
	}
	if = {
		limit = { religion = bogomilist }
		set_character_flag = character_was_bogomilist
	}
	if = {
		limit = { religion = monothelite }
		set_character_flag = character_was_monothelite
	}
	if = {
		limit = { religion = iconoclast }
		set_character_flag = character_was_iconoclast
	}
	if = {
		limit = { religion = nestorian }
		set_character_flag = character_was_nestorian
	}
	if = {
		limit = { religion = messalian }
		set_character_flag = character_was_messalian
	}
	if = {
		limit = { religion = miaphysite }
		set_character_flag = character_was_miaphysite
	}
	if = {
		limit = { religion = monophysite }
		set_character_flag = character_was_monophysite
	}
	if = {
		limit = { religion = apostolic }
		set_character_flag = character_was_apostolic
	}
	if = {
		limit = { religion = paulician }
		set_character_flag = character_was_paulician
	}
	if = {
		limit = { religion = tondrakian }
		set_character_flag = character_was_tondrakian
	}
	if = {
		limit = { religion = ibadi }
		set_character_flag = character_was_ibadi
	}
	if = {
		limit = { religion = kharijite }
		set_character_flag = character_was_kharijite
	}
	if = {
		limit = { religion = manichean }
		set_character_flag = character_was_manichean
	}
	if = {
		limit = { religion = khurmazta }
		set_character_flag = character_was_khurmazta
	}
	if = {
		limit = { religion = taoist }
		set_character_flag = character_was_taoist
	}
	if = {
		limit = { religion = bon }
		set_character_flag = character_was_bon
	}
	if = {
		limit = { religion = sunni }
		set_character_flag = character_was_sunni
	}
	if = {
		limit = { religion = tibetan_pagan }
		set_character_flag = character_was_tibetan_pagan
	}
	if = {
		limit = { religion = zikri }
		set_character_flag = character_was_zikri
	}
	if = {
		limit = { religion = quranist }
		set_character_flag = character_was_quranist
	}
	if = {
		limit = { religion = shiite }
		set_character_flag = character_was_shiite
	}
	if = {
		limit = { religion = bektashi }
		set_character_flag = character_was_bektashi
	}
	if = {
		limit = { religion = druze }
		set_character_flag = character_was_druze
	}
	if = {
		limit = { religion = hurufi }
		set_character_flag = character_was_hurufi
	}
	if = {
		limit = { religion = qarmatian }
		set_character_flag = character_was_qarmatian
	}
	if = {
		limit = { religion = jewish }
		set_character_flag = character_was_jewish
	}
	if = {
		limit = { religion = samaritan }
		set_character_flag = character_was_samaritan
	}
	if = {
		limit = { religion = karaite }
		set_character_flag = character_was_karaite
	}
	if = {
		limit = { religion = zoroastrian }
		set_character_flag = character_was_zoroastrian
	}
	if = {
		limit = { religion = mazdaki }
		set_character_flag = character_was_mazdaki
	}
	if = {
		limit = { religion = zurvanist }
		set_character_flag = character_was_zurvanist
	}
	if = {
		limit = { religion = mandaean }
		set_character_flag = character_was_mandaean
	}
	if = {
		limit = { religion = yazidi }
		set_character_flag = character_was_yazidi
	}
	if = {
		limit = { religion = hindu }
		set_character_flag = character_was_hindu
	}
	if = {
		limit = { religion = buddhist }
		set_character_flag = character_was_buddhist
	}
	if = {
		limit = { religion = jain }
		set_character_flag = character_was_jain
	}
	if = {
		limit = { religion = norse_pagan_reformed }
		set_character_flag = character_was_norse_pagan_reformed
	}
	if = {
		limit = { religion = german_pagan_reformed }
		set_character_flag = character_was_german_pagan_reformed
	}
	if = {
		limit = { religion = celtic_pagan_reformed }
		set_character_flag = character_was_celtic_pagan_reformed
	}
	if = {
		limit = { religion = slavic_pagan_reformed }
		set_character_flag = character_was_slavic_pagan_reformed
	}
	if = {
		limit = { religion = tengri_pagan_reformed }
		set_character_flag = character_was_tengri_pagan_reformed
	}
	if = {
		limit = { religion = baltic_pagan_reformed }
		set_character_flag = character_was_baltic_pagan_reformed
	}
	if = {
		limit = { religion = finnish_pagan_reformed }
		set_character_flag = character_was_finnish_pagan_reformed
	}
	if = {
		limit = { religion = west_african_pagan_reformed }
		set_character_flag = character_was_west_african_pagan_reformed
	}
	if = {
		limit = { religion = zun_pagan_reformed }
		set_character_flag = character_was_zun_pagan_reformed
	}
	if = {
		limit = { religion = norse_pagan }
		set_character_flag = character_was_norse_pagan
	}
	if = {
		limit = { religion = german_pagan }
		set_character_flag = character_was_german_pagan
	}
	if = {
		limit = { religion = celtic_pagan }
		set_character_flag = character_was_celtic_pagan
	}
	if = {
		limit = { religion = slavic_pagan }
		set_character_flag = character_was_slavic_pagan
	}
	if = {
		limit = { religion = tengri_pagan }
		set_character_flag = character_was_tengri_pagan
	}
	if = {
		limit = { religion = baltic_pagan }
		set_character_flag = character_was_baltic_pagan
	}
	if = {
		limit = { religion = finnish_pagan }
		set_character_flag = character_was_finnish_pagan
	}
	if = {
		limit = { religion = west_african_pagan }
		set_character_flag = character_was_west_african_pagan
	}
	if = {
		limit = { religion = zun_pagan }
		set_character_flag = character_was_zun_pagan
	}
	if = {
		limit = { religion = roman_pagan }
		set_character_flag = character_was_roman_pagan
	}
	if = {
		limit = { religion = hellenic_pagan }
		set_character_flag = character_was_hellenic_pagan
	}
	if = {
		limit = { religion = egyptian_pagan }
		set_character_flag = character_was_egyptian_pagan
	}
	if = {
		limit = { religion = arab_pagan }
		set_character_flag = character_was_arab_pagan
	}
	if = {
		limit = { religion = berber_pagan }
		set_character_flag = character_was_berber_pagan
	}
	if = {
		limit = { religion = jewish_pagan }
		set_character_flag = character_was_jewish_pagan
	}
	if = {
		limit = { religion = aten_pagan }
		set_character_flag = character_was_aten_pagan
	}
	if = {
		limit = { religion = promethean_pagan }
		set_character_flag = character_was_promethean_pagan
	}
	if = {
		limit = { religion = aztec }
		set_character_flag = character_was_aztec
	}
}

clr_religion_char_flag_effect = {
	clr_character_flag = character_was_catholic
	clr_character_flag = character_was_cathar
	clr_character_flag = character_was_fraticelli
	clr_character_flag = character_was_waldensian
	clr_character_flag = character_was_lollard
	clr_character_flag = character_was_adoptionist
	clr_character_flag = character_was_chalcedonian
	clr_character_flag = character_was_orthodox
	clr_character_flag = character_was_bogomilist
	clr_character_flag = character_was_monothelite
	clr_character_flag = character_was_iconoclast
	clr_character_flag = character_was_nestorian
	clr_character_flag = character_was_messalian
	clr_character_flag = character_was_miaphysite
	clr_character_flag = character_was_monophysite
	clr_character_flag = character_was_apostolic
	clr_character_flag = character_was_paulician
	clr_character_flag = character_was_tondrakian
	clr_character_flag = character_was_ibadi
	clr_character_flag = character_was_kharijite
	clr_character_flag = character_was_manichean
	clr_character_flag = character_was_khurmazta
	clr_character_flag = character_was_taoist
	clr_character_flag = character_was_bon
	clr_character_flag = character_was_tibetan_pagan
	clr_character_flag = character_was_sunni
	clr_character_flag = character_was_zikri
	clr_character_flag = character_was_quranist
	clr_character_flag = character_was_shiite
	clr_character_flag = character_was_bektashi
	clr_character_flag = character_was_druze
	clr_character_flag = character_was_hurufi
	clr_character_flag = character_was_qarmatian
	clr_character_flag = character_was_jewish
	clr_character_flag = character_was_samaritan
	clr_character_flag = character_was_karaite
	clr_character_flag = character_was_zoroastrian
	clr_character_flag = character_was_mazdaki
	clr_character_flag = character_was_zurvanist
	clr_character_flag = character_was_mandaean
	clr_character_flag = character_was_yazidi
	clr_character_flag = character_was_hindu
	clr_character_flag = character_was_buddhist
	clr_character_flag = character_was_jain
	clr_character_flag = character_was_norse_pagan_reformed
	clr_character_flag = character_was_german_pagan_reformed
	clr_character_flag = character_was_celtic_pagan_reformed
	clr_character_flag = character_was_slavic_pagan_reformed
	clr_character_flag = character_was_tengri_pagan_reformed
	clr_character_flag = character_was_baltic_pagan_reformed
	clr_character_flag = character_was_finnish_pagan_reformed
	clr_character_flag = character_was_west_african_pagan_reformed
	clr_character_flag = character_was_zun_pagan_reformed
	clr_character_flag = character_was_norse_pagan
	clr_character_flag = character_was_german_pagan
	clr_character_flag = character_was_celtic_pagan
	clr_character_flag = character_was_slavic_pagan
	clr_character_flag = character_was_tengri_pagan
	clr_character_flag = character_was_baltic_pagan
	clr_character_flag = character_was_finnish_pagan
	clr_character_flag = character_was_west_african_pagan
	clr_character_flag = character_was_zun_pagan
	clr_character_flag = character_was_roman_pagan
	clr_character_flag = character_was_hellenic_pagan
	clr_character_flag = character_was_egyptian_pagan
	clr_character_flag = character_was_arab_pagan
	clr_character_flag = character_was_berber_pagan
	clr_character_flag = character_was_jewish_pagan
	clr_character_flag = character_was_aten_pagan
	clr_character_flag = character_was_promethean_pagan
	clr_character_flag = character_was_aztec
}

event_target_old_religion_from_flag_effect = {
	if = {
		limit = { has_character_flag = character_was_catholic }
		random_character = {
			limit = { religion = catholic }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_cathar }
		random_character = {
			limit = { religion = cathar }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_fraticelli }
		random_character = {
			limit = { religion = fraticelli }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_waldensian }
		random_character = {
			limit = { religion = waldensian }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_lollard }
		random_character = {
			limit = { religion = lollard }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_adoptionist }
		random_character = {
			limit = { religion = adoptionist }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_chalcedonian }
		random_character = {
			limit = { religion = chalcedonian }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_orthodox }
		random_character = {
			limit = { religion = orthodox }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_bogomilist }
		random_character = {
			limit = { religion = bogomilist }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_monothelite }
		random_character = {
			limit = { religion = monothelite }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_iconoclast }
		random_character = {
			limit = { religion = iconoclast }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_nestorian }
		random_character = {
			limit = { religion = nestorian }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_messalian }
		random_character = {
			limit = { religion = messalian }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_miaphysite }
		random_character = {
			limit = { religion = miaphysite }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_monophysite }
		random_character = {
			limit = { religion = monophysite }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_apostolic }
		random_character = {
			limit = { religion = apostolic }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_ibadi }
		random_character = {
			limit = { religion = ibadi }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_kharijite }
		random_character = {
			limit = { religion = ibadi }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_manichean }
		random_character = {
			limit = { religion = manichean }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_khurmazta }
		random_character = {
			limit = { religion = khurmazta }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_taoist }
		random_character = {
			limit = { religion = taoist }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_bon }
		random_character = {
			limit = { religion = bon }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_tibetan_pagan }
		random_character = {
			limit = { religion = tibetan_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_sunni }
		random_character = {
			limit = { religion = sunni }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_zikri }
		random_character = {
			limit = { religion = zikri }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_quranist }
		random_character = {
			limit = { religion = quranist }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_shiite }
		random_character = {
			limit = { religion = shiite }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_bektashi }
		random_character = {
			limit = { religion = bektashi }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_druze }
		random_character = {
			limit = { religion = druze }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_hurufi }
		random_character = {
			limit = { religion = hurufi }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_qarmatian }
		random_character = {
			limit = { religion = qarmatian }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_jewish }
		random_character = {
			limit = { religion = jewish }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_samaritan }
		random_character = {
			limit = { religion = samaritan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_karaite }
		random_character = {
			limit = { religion = karaite }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_zoroastrian }
		random_character = {
			limit = { religion = zoroastrian }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_zurvanist }
		random_character = {
			limit = { religion = zurvanist }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_mazdaki }
		random_character = {
			limit = { religion = mazdaki }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_mandaean }
		random_character = {
			limit = { religion = mandaean }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_yazidi }
		random_character = {
			limit = { religion = yazidi }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_hindu }
		random_character = {
			limit = { religion = hindu }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_buddhist }
		random_character = {
			limit = { religion = buddhist }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_jain }
		random_character = {
			limit = { religion = jain }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_norse_pagan_reformed }
		random_character = {
			limit = { religion = norse_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_german_pagan_reformed }
		random_character = {
			limit = { religion = german_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_celtic_pagan_reformed }
		random_character = {
			limit = { religion = celtic_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_slavic_pagan_reformed }
		random_character = {
			limit = { religion = slavic_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_tengri_pagan_reformed }
		random_character = {
			limit = { religion = tengri_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_baltic_pagan_reformed }
		random_character = {
			limit = { religion = baltic_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_finnish_pagan_reformed }
		random_character = {
			limit = { religion = finnish_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_west_african_pagan_reformed }
		random_character = {
			limit = { religion = west_african_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_zun_pagan_reformed }
		random_character = {
			limit = { religion = zun_pagan_reformed }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_norse_pagan }
		random_character = {
			limit = { religion = norse_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_german_pagan }
		random_character = {
			limit = { religion = german_pagan}
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_celtic_pagan }
		random_character = {
			limit = { religion = celtic_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_slavic_pagan }
		random_character = {
			limit = { religion = slavic_pagan}
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_tengri_pagan }
		random_character = {
			limit = { religion = tengri_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_baltic_pagan }
		random_character = {
			limit = { religion = baltic_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_finnish_pagan }
		random_character = {
			limit = { religion = finnish_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_west_african_pagan }
		random_character = {
			limit = { religion = west_african_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_zun_pagan }
		random_character = {
			limit = { religion = zun_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_arab_pagan }
		random_character = {
			limit = { religion = arab_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_berber_pagan }
		random_character = {
			limit = { religion = berber_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_roman_pagan }
		random_character = {
			limit = { religion = roman_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_hellenic_pagan }
		random_character = {
			limit = { religion = hellenic_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_egyptian_pagan }
		random_character = {
			limit = { religion = egyptian_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_jewish_pagan }
		random_character = {
			limit = { religion = jewish_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_aten_pagan }
		random_character = {
			limit = { religion = aten_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_promethean_pagan }
		random_character = {
			limit = { religion = promethean_pagan }
			save_event_target_as = old_religion
		}
	}
	if = {
		limit = { has_character_flag = character_was_aztec }
		random_character = {
			limit = { religion = aztec }
			save_event_target_as = old_religion
		}
	}
}

increase_visibility_effect = {
	#custom_tooltip = { text = debug_vis }
	hidden_effect = {
		change_variable = { which = visibility_value value = 5 } 
		if = {
			limit = {
				check_variable = { which = visibility_value value = 15 }
				NOR = {
					has_character_modifier = under_suspicion
					has_character_modifier = highly_suspect
				}
			}
			add_character_modifier = {
				name = under_suspicion
				duration = -1
			}
			character_event = { id = MNM.6662 days = 1 }
		}
		if = {
			limit = {
				check_variable = { which = visibility_value value = 25 }
				NOT = {
					has_character_modifier = highly_suspect
				}
			}
			remove_character_modifier = under_suspicion
			add_character_modifier = {
				name = highly_suspect duration = -1 
			}
			character_event = { id = MNM.6663 days = 1 }
			liege = {
				set_character_flag = secret_societies_interference
				character_event = { id = MNM.6661 days = 1095 random = 1095 }
			}
		}
		if = { # Too visible? You auto-reveal yourself if you are independent
			limit = {
				independent = yes
				is_ruler = yes
				check_variable = { which = visibility_value value = 40 }
				NOT = {
					has_character_flag = self_reveal
				}
			}
			set_character_flag = self_reveal
			character_event = { id = MNM.6668 days = 1 }
		}
	}
}

increase_visibility_minor_effect = {
	#custom_tooltip = { text = debug_vis }
	hidden_effect = {
		change_variable = { which = visibility_value value = 2 } 
		if = {
			limit = {
				check_variable = { which = visibility_value value = 15 }
				NOR = {
					has_character_modifier = under_suspicion
					has_character_modifier = highly_suspect
				}
			}
			add_character_modifier = {
				name = under_suspicion
				duration = -1
			}
			character_event = { id = MNM.6662 days = 1 }
		}
		if = {
			limit = {
				check_variable = { which = visibility_value value = 25 }
				NOT = {
					has_character_modifier = highly_suspect
				}
			}
			remove_character_modifier = under_suspicion
			add_character_modifier = {
				name = highly_suspect duration = -1 
			}
			character_event = { id = MNM.6663 days = 1 }
			liege = {
				set_character_flag = secret_societies_interference
				character_event = { id = MNM.6661 days = 1095 random = 1095 }
			}
		}
		if = { # Too visible? You auto-reveal yourself if you are independent
			limit = {
				independent = yes
				is_ruler = yes
				check_variable = { which = visibility_value value = 40 }
				NOT = {
					has_character_flag = self_reveal
				}
			}
			set_character_flag = self_reveal
			if = {
				limit = {
					is_devil_worshiper_trigger = yes
				}
				add_character_modifier = {
					name = known_satanist
					duration = -1
				}
			}
			if = {
				limit = {
					is_devil_worshiper_trigger = no
				}
				add_character_modifier = {
					name = accused_apostate
					duration = -1
				}
			}
			if = {
				limit = {
					controls_religion = no
					OR = {
						religion = catholic
						religion = fraticelli
						religion = orthodox
						religion = miaphysite
						religion = monophysite
						religion = monothelite
						religion = paulician
						religion = nestorian
						religion = yazidi
					}
				}
				add_trait = excommunicated
			}
			character_event = { id = MNM.6668 days = 1 }
		}
	}
}

decrease_visibility_effect = {
	hidden_effect = {
		if = {
			limit = {
				check_variable = { which = visibility_value value = 1 }
			}
			random_list = {
				50 = {
					change_variable = { which = visibility_value value = -1 }
				}
				20 = {
					change_variable = { which = visibility_value value = -2 }
					modifier = {
						factor = 1.5
						OR = {
							trait = schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}
					modifier = {
						factor = 1.25
						intrigue = 12
					}
					modifier = {
						factor = 1.25
						intrigue = 14
					}
					modifier = {
						factor = 1.25
						intrigue = 16
					}
				}
				15 = {
					change_variable = { which = visibility_value value = -3 }
					modifier = {
						factor = 1.5
						OR = {
							trait = schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}
					modifier = {
						factor = 1.25
						intrigue = 12
					}
					modifier = {
						factor = 1.25
						intrigue = 14
					}
					modifier = {
						factor = 1.25
						intrigue = 16
					}
				}
				10 = {
					change_variable = { which = visibility_value value = -4 }
					modifier = {
						factor = 1.5
						OR = {
							trait = schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}
					modifier = {
						factor = 1.25
						intrigue = 12
					}
					modifier = {
						factor = 1.25
						intrigue = 14
					}
					modifier = {
						factor = 1.25
						intrigue = 16
					}
				}
				5 = {
					change_variable = { which = visibility_value value = -5 }
					modifier = {
						factor = 1.5
						OR = {
							trait = schemer
							trait = deceitful
							trait = patient
							trait = paranoid
						}
					}
					modifier = {
						factor = 1.25
						intrigue = 12
					}
					modifier = {
						factor = 1.25
						intrigue = 14
					}
					modifier = {
						factor = 1.25
						intrigue = 16
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { check_variable = { which = visibility_value value = 0 } } #safety 
			}
			set_variable = { which = visibility_value value = 0 }
		}
	}
	if = {
		limit = {
			NOT = { check_variable = { which = visibility_value value = 25 } }
			has_character_modifier = highly_suspect
		}
		remove_character_modifier = highly_suspect
		add_character_modifier = {
			name = under_suspicion
			duration = -1
		}
		character_event = { id = MNM.6664 }
	}
	if = {
		limit = {
			NOT = { check_variable = { which = visibility_value value = 15 } }
			has_character_modifier = under_suspicion
		}
		remove_character_modifier = under_suspicion
		character_event = { id = MNM.6665 }
	}
}

hermetic_add_herbal_ingredient_effect = {
	hidden_effect = {
		random_list = {
			50 = {
				add_artifact = ingredient_herb1
			}
			50 = {
				add_artifact = ingredient_herb2
			}
			50 = {
				add_artifact = ingredient_herb3
			}
			50 = {
				add_artifact = ingredient_herb4
			}
			50 = {
				add_artifact = ingredient_herb5
			}
			50 = {
				add_artifact = ingredient_herb6
			}
			50 = {
				add_artifact = ingredient_herb7
			}
			50 = {
				add_artifact = ingredient_herb8
			}
			50 = {
				add_artifact = ingredient_herb9
			}
		}
	}
}

hermetic_add_animal_ingredient_effect = {
	hidden_effect = {
		random_list = {
			50 = {
				add_artifact = ingredient_animal1
			}
			50 = {
				add_artifact = ingredient_animal2
			}
			50 = {
				add_artifact = ingredient_animal3
			}
			50 = {
				add_artifact = ingredient_animal4
			}
			50 = {
				add_artifact = ingredient_animal5
			}
			50 = {
				add_artifact = ingredient_animal6
			}
			50 = {
				add_artifact = ingredient_animal7
			}
			50 = {
				add_artifact = ingredient_animal8
			}
			50 = {
				add_artifact = ingredient_animal9
			}
		}
	}
}

hermetic_add_misc_ingredient_effect = {
	hidden_effect = {
		random_list = {
			50 = {
				add_artifact = ingredient_metal_exotic1
			}
			50 = {
				add_artifact = ingredient_metal_exotic2
			}
			50 = {
				add_artifact = ingredient_metal_exotic3
			}
			50 = {
				add_artifact = ingredient_metal_exotic4
			}
			50 = {
				add_artifact = ingredient_metal_exotic5
			}
			50 = {
				add_artifact = ingredient_metal_exotic6
			}
			50 = {
				add_artifact = ingredient_metal_exotic7
			}
			50 = {
				add_artifact = ingredient_metal_exotic8
			}
			50 = {
				add_artifact = ingredient_metal_exotic9
			}
		}
	}
}

remove_scrying_omen_modifiers_effect = { #For cleaning up end-states of the Hermetics Scrying Power
	if = {
		limit = { has_character_modifier = good_battle_omen }
		remove_character_modifier = good_battle_omen
	}
	if = {
		limit = { has_character_modifier = bad_battle_omen }
		remove_character_modifier = bad_battle_omen
	}
	if = {
		limit = { has_character_modifier = good_relationship_omen }
		remove_character_modifier = good_relationship_omen
	}
	if = {
		limit = { has_character_modifier = bad_relationship_omen }
		remove_character_modifier = bad_relationship_omen
	}
	if = {
		limit = { has_character_modifier = good_power_omen }
		remove_character_modifier = good_power_omen
	}
	if = {
		limit = { has_character_modifier = bad_power_omen }
		remove_character_modifier = bad_power_omen
	}
	hidden_effect = { remove_character_modifier = scrying_cooldown }
	clr_character_flag = positive_reaction_to_scrying_flag
	clr_character_flag = negative_reaction_to_scrying_flag
	clr_character_flag = positive_event_flag
	clr_character_flag = negative_event_flag
	clear_delayed_event = { id = MNM.1225 }
	clear_delayed_event = { id = MNM.1226 }
	clear_delayed_event = { id = MNM.1227 }
}

calculate_scrying_outcome_effect = { # the positive_event_flag/negative_event_flag need to be set somewhere in the target event in order for this to work...
	custom_tooltip = { text = tooltip_info_omen_tt }

	if = {
		limit = {
			OR = {
				AND = {
					has_positive_omen_modifier_trigger = yes
					has_character_flag = positive_event_flag
				}
				AND = {
					has_negative_omen_modifier_trigger = yes
					has_character_flag = negative_event_flag
				}
			}
		}
		upgrade_seer_modifier_effect = yes
	}
	if = {
		limit = {
			OR = {
				AND = {
					has_positive_omen_modifier_trigger = yes
					has_character_flag = negative_event_flag
				}
				AND = {
					has_negative_omen_modifier_trigger = yes
					has_character_flag = positive_event_flag
				}
			}
		}
		downgrade_seer_modifier_effect = yes
	}
	clr_character_flag = positive_event_flag
	clr_character_flag = negative_event_flag
}

upgrade_seer_modifier_effect = { # Modifiers gotten at end-states of the Hermetics Scrying Power
	if = {
		limit = {
			has_a_seer_modifier_trigger = yes
		}
		trigger_switch = {
			on_trigger = has_character_modifier
			fulfilled_vision_worst = {
				remove_character_modifier = fulfilled_vision_worst
				add_character_modifier = {
					name = fulfilled_vision_bad
					duration = 2555
				}
			}
			fulfilled_vision_bad = {
				remove_character_modifier = fulfilled_vision_bad
				add_character_modifier = {
					name = fulfilled_vision_ok
					duration = 2555
				}
			}
			fulfilled_vision_ok = {
				remove_character_modifier = fulfilled_vision_ok
				add_character_modifier = {
					name = fulfilled_vision_great
					duration = 2555
				}
			}
			fulfilled_vision_great = {
				add_character_modifier = {
					name = fulfilled_vision_great
					duration = 2555
				}
			}
		}
	}
	if = {
		limit = {
			has_a_seer_modifier_trigger = no
		}
		add_character_modifier = {
			name = fulfilled_vision_ok
			duration = 2555
		}
	}
}

downgrade_seer_modifier_effect = { # Modifiers gotten at end-states of the Hermetics Scrying Power
	if = {
		limit = {
			has_a_seer_modifier_trigger = yes
		}
		trigger_switch = {
			on_trigger = has_character_modifier
			fulfilled_vision_great = {
				remove_character_modifier = fulfilled_vision_great
				add_character_modifier = {
					name = fulfilled_vision_ok
					duration = 2555
				}
			}
			fulfilled_vision_ok = {
				remove_character_modifier = fulfilled_vision_ok
				add_character_modifier = {
					name = fulfilled_vision_bad
					duration = 2555
				}
			}
			fulfilled_vision_bad = {
				remove_character_modifier = fulfilled_vision_bad
				add_character_modifier = {
					name = fulfilled_vision_worst
					duration = 2555
				}
			}
			fulfilled_vision_worst = {
				add_character_modifier = {
					name = fulfilled_vision_worst
					duration = 2555
				}
			}
		}
	}
	if = {
		limit = {
			has_a_seer_modifier_trigger = no
		}
		add_character_modifier = {
			name = fulfilled_vision_bad
			duration = 2555
		}
	}
}

scrying_omen_fulfilled_by_gaining_disease_effect = { #scrying result are sent if someone gets sick and you are carrying an omen (fired from rip_symptom_events)
	hidden_effect = {
		host = {
			if = {
				limit = {
					OR = {
						is_close_relative = ROOT
						is_friend = ROOT
					}
					OR = {
						has_character_modifier = bad_relationship_omen
						has_character_modifier = good_relationship_omen
					}
				}
				character_event = { id = MNM.1221 days = 5 random = 5 } #to the host of sick character
			}
		}
		father = {
			if = {
				limit = { 
					is_liege_of = ROOT
					OR = {
						has_character_modifier = bad_relationship_omen
						has_character_modifier = good_relationship_omen
					}
				}
				character_event = { id = MNM.1221 days = 5 random = 5 }
			}
		}
		mother = {
			if = {
				limit = { 
					is_liege_of = ROOT
					OR = {
						has_character_modifier = bad_relationship_omen
						has_character_modifier = good_relationship_omen
					}
				}
				character_event = { id = MNM.1221 days = 5 random = 5 }
			}
		}
		spouse = {
			if = {
				limit = {
					is_liege_of = ROOT
					OR = {
						has_character_modifier = bad_relationship_omen
						has_character_modifier = good_relationship_omen
					}
				}
				character_event = { id = MNM.1221 days = 5 random = 5 }
			}
		}
		random_lover = {
			if = {
				limit = {
					is_liege_of = ROOT
					OR = {
						has_character_modifier = bad_relationship_omen
						has_character_modifier = good_relationship_omen
					}
				}
				character_event = { id = MNM.1221 days = 5 random = 5 }
			}
		}

		if = {
			limit = {
				OR = {
					has_character_modifier = bad_power_omen
					has_character_modifier = good_power_omen
				}
			}
			character_event = { id = MNM.1220 days = 5 random = 5 } #to the sick character themselves
		}
	}
}

scrying_omen_fulfilled_by_removing_disease_effect = { #scrying result are sent if someone gets sick and you are carrying an omen (fired from rip_symptom_events)
	hidden_effect = {
		host = {
			if = {
				limit = {
					OR = {
						is_close_relative = ROOT
						is_friend = ROOT
					}
					OR = {
						has_character_modifier = good_relationship_omen
						has_character_modifier = bad_relationship_omen
					}
				}
				character_event = { id = MNM.1223 days = 5 random = 5 } #to the host of sick character
			}
		}
		father = {
			if = {
				limit = { 
					is_liege_of = ROOT
					OR = {
						has_character_modifier = good_relationship_omen
						has_character_modifier = bad_relationship_omen
					}
				}
				character_event = { id = MNM.1223 days = 5 random = 5 }
			}
		}
		mother = {
			if = {
				limit = { 
					is_liege_of = ROOT
					OR = {
						has_character_modifier = good_relationship_omen
						has_character_modifier = bad_relationship_omen
					}
				}
				character_event = { id = MNM.1223 days = 5 random = 5 }
			}
		}
		spouse = {
			if = {
				limit = {
					is_liege_of = ROOT
					OR = {
						has_character_modifier = good_relationship_omen
						has_character_modifier = bad_relationship_omen
					}
				}
				character_event = { id = MNM.1223 days = 5 random = 5 }
			}
		}
		random_lover = {
			if = {
				limit = {
					is_liege_of = ROOT
					OR = {
						has_character_modifier = good_relationship_omen
						has_character_modifier = bad_relationship_omen
					}
				}
				character_event = { id = MNM.1223 days = 5 random = 5 }
			}
		}

		if = {
			limit = {
				OR = {
					has_character_modifier = good_power_omen
					has_character_modifier = bad_power_omen
				}
			}
			character_event = { id = MNM.1222 days = 5 random = 5 } #to the sick character themselves
		}
	}
}

add_pet_owl_effect = {
	add_character_modifier = {
		name = pet_owl
		duration = -1
	}
	hidden_tooltip = { character_event = { id = 77800 days = 3500 random = 2000 } } # Owl dies
}

add_mission_succeed_influence_effect = { 
	add_society_modifier = 	{
		modifier = successful_mission
		years = 10
	}
}

add_mission_fail_influence_effect = { 
	add_society_modifier = 	{
		modifier = failed_mission
		years = 10
	}
}

add_mission_decline_influence_effect = { 
	add_society_modifier = 	{
		modifier = declined_mission
		years = 2
	}
}

clean_up_horoscope_effect = {
	clr_character_flag = avoided_destiny
	clr_character_flag = horoscope_maker_died
	clr_character_flag = destined_artist
	clr_character_flag = destined_fighter
	clr_character_flag = destined_diplomat
	clr_character_flag = destined_schemer
	clr_character_flag = destined_scholar
	clr_character_flag = encouraged_horoscope_pattern
	clr_character_flag = discouraged_horoscope_pattern
	clr_character_flag = horoscope_child_evaluate
	clr_character_flag = horoscope_path_1
	clr_character_flag = horoscope_maker_is_mother
	clr_character_flag = horoscope_maker_is_father
	remove_character_modifier = horoscope_cooldown
}

upgrade_education_effect = {
	custom_tooltip = { text = CURRENT_EDUCATION_UPGRADED_TT }
	hidden_tooltip = {
		trigger_switch = {
			on_trigger = trait

			### Intrigue ###
			amateurish_plotter = {
				remove_trait = amateurish_plotter
				add_trait = flamboyant_schemer
			}
			flamboyant_schemer = {
				remove_trait = flamboyant_schemer
				add_trait = intricate_webweaver 
			}
			intricate_webweaver = {
				remove_trait = intricate_webweaver
				add_trait = elusive_shadow 
			}
			elusive_shadow = {
				# already maxed
			}
			
			### Diplomacy ###
			naive_appeaser = {
				remove_trait = naive_appeaser
				add_trait = underhanded_rogue
			}
			underhanded_rogue = {
				remove_trait = underhanded_rogue
				add_trait = charismatic_negotiator 
			}
			charismatic_negotiator = {
				remove_trait = charismatic_negotiator
				add_trait = grey_eminence 
			}
			grey_eminence = {
				# already maxed
			}

			### Stewardship ###
			indulgent_wastrel = {
				remove_trait = indulgent_wastrel
				add_trait = thrifty_clerk
			}
			thrifty_clerk = {
				remove_trait = thrifty_clerk
				add_trait = fortune_builder 
			}
			fortune_builder = {
				remove_trait = fortune_builder
				add_trait = midas_touched 
			}
			midas_touched = {
				# already maxed
			}

			### Martial ###
			misguided_warrior = {
				remove_trait = misguided_warrior
				add_trait = tough_soldier
			}
			tough_soldier = {
				remove_trait = tough_soldier
				add_trait = skilled_tactician 
			}
			skilled_tactician = {
				remove_trait = skilled_tactician
				add_trait = brilliant_strategist 
			}
			brilliant_strategist = {
				# already maxed
			}
			
			### Learning ###
			detached_priest = {
				remove_trait = detached_priest
				add_trait = martial_cleric
			}
			martial_cleric = {
				remove_trait = martial_cleric
				add_trait = scholarly_theologian 
			}
			scholarly_theologian = {
				remove_trait = scholarly_theologian
				add_trait = mastermind_theologian 
			}
			mastermind_theologian = {
				# already maxed
			}
		}
	}
}

set_horoscope_modifier_effect = { # Modifiers received by target during the Hermetics Horoscope Power
	if = {
		limit = {
			has_childhood_horoscope_modifier_trigger = yes
			NOT = { has_character_flag = avoided_destiny }
		}
		trigger_switch = {
			on_trigger = has_character_modifier
			guided_by_horoscope_diplomacy = {
				remove_character_modifier = guided_by_horoscope_diplomacy
				add_character_modifier = {
					name = guided_by_horoscope_diplomacy_adult
					duration = 2555
				}
			}
			guided_by_horoscope_martial = {
				remove_character_modifier = guided_by_horoscope_martial
				add_character_modifier = {
					name = guided_by_horoscope_martial_adult
					duration = 2555
				}
			}
			guided_by_horoscope_stewardship = {
				remove_character_modifier = guided_by_horoscope_stewardship
				add_character_modifier = {
					name = guided_by_horoscope_stewardship_adult
					duration = 2555
				}
			}
			guided_by_horoscope_intrigue = {
				remove_character_modifier = guided_by_horoscope_intrigue
				add_character_modifier = {
					name = guided_by_horoscope_intrigue_adult
					duration = 2555
				}
			}
			guided_by_horoscope_learning = {
				remove_character_modifier = guided_by_horoscope_learning
				add_character_modifier = {
					name = guided_by_horoscope_learning_adult
					duration = 2555
				}
			}
		}
		break = yes
	}

	if = {
		limit = {
			has_childhood_horoscope_modifier_trigger = no
			is_adult = no
			NOT = { has_character_flag = avoided_destiny }
		}
		trigger_switch = {
			on_trigger = has_character_flag
			destined_steward = {
				add_character_modifier = {
					name = guided_by_horoscope_stewardship
					duration =-1
				}
			}
			destined_fighter = {
				add_character_modifier = {
					name = guided_by_horoscope_martial
					duration =-1
				}
			}
			destined_diplomat = {
				add_character_modifier = {
					name = guided_by_horoscope_diplomacy
					duration =-1
				}
			}
			destined_schemer = {
				add_character_modifier = {
					name = guided_by_horoscope_intrigue
					duration =-1
				}
			}
			destined_scholar = {
				add_character_modifier = {
					name = guided_by_horoscope_learning
					duration =-1
				}
			}
		}
		break = yes
	}	

	if = {
		limit = {
			has_childhood_horoscope_modifier_trigger = no
			has_character_flag = avoided_destiny
		}
		trigger_switch = {
			on_trigger = has_character_flag
			destined_steward = {
				add_character_modifier = {
					name = horoscope_outcome_jittery
					years = 15
				}
			}
			destined_fighter = {
				add_character_modifier = {
					name = horoscope_outcome_brute
					years = 15
				}
			}
			destined_diplomat = {
				add_character_modifier = {
					name = horoscope_outcome_artist
					years = 15
				}
			}
			destined_schemer = {
				add_character_modifier = {
					name = horoscope_outcome_arrogant
					years = 15
				}
			}
			destined_scholar = {
				add_character_modifier = {
					name = horoscope_outcome_scatterbrain
					years = 15
				}
			}
		}
		break = yes
	}

	if = {
		limit = {
			has_childhood_horoscope_modifier_trigger = yes
			has_character_flag = avoided_destiny
		}
		trigger_switch = {
			on_trigger = has_character_flag
			destined_steward = {
				if = { limit = { has_character_modifier = guided_by_horoscope_stewardship }
					remove_character_modifier = guided_by_horoscope_stewardship
				}
				add_character_modifier = {
					name = horoscope_outcome_jittery
					years = 15
				}
			}
			destined_fighter = {
				if = { limit = { has_character_modifier = guided_by_horoscope_martial }
					remove_character_modifier = guided_by_horoscope_martial
				}
				add_character_modifier = {
					name = horoscope_outcome_brute
					years = 15
				}
			}
			destined_diplomat = {
				if = { limit = { has_character_modifier = guided_by_horoscope_diplomacy }
					remove_character_modifier = guided_by_horoscope_diplomacy
				}
				add_character_modifier = {
					name = horoscope_outcome_artist
					years = 15
				}
			}
			destined_schemer = {
				if = { limit = { has_character_modifier = guided_by_horoscope_intrigue }
					remove_character_modifier = guided_by_horoscope_intrigue
				}
				add_character_modifier = {
					name = horoscope_outcome_arrogant
					years = 15
				}
			}
			destined_scholar = {
				if = { limit = { has_character_modifier = guided_by_horoscope_learning }
					remove_character_modifier = guided_by_horoscope_learning
				}
				add_character_modifier = {
					name = horoscope_outcome_scatterbrain
					years = 15
				}
			}
		}
		break = yes
	}
}

increase_astronomical_insights_modifier_effect = {
	custom_tooltip = { text = increase_astronomical_insight_tt }
	trigger_switch = {
		on_trigger = has_character_modifier
		astronomical_insights_1 = { 
			hidden_effect = {
				remove_character_modifier = astronomical_insights_1 
			}
			add_character_modifier = {
				modifier = astronomical_insights_2
				duration = -1
			}
		}
		astronomical_insights_2 = { 
			hidden_effect = {
				remove_character_modifier = astronomical_insights_2
			}
			add_character_modifier = {
				modifier = astronomical_insights_3
				duration = -1
			}
		}
		astronomical_insights_3 = { 
			hidden_effect = {
				remove_character_modifier = astronomical_insights_3
			}
			add_character_modifier = {
				modifier = astronomical_insights_4
				duration = -1
			}
		}
	}
	if = {
		limit = {
			NOR = {
				has_character_modifier = astronomical_insights_1
				has_character_modifier = astronomical_insights_2
				has_character_modifier = astronomical_insights_3
				has_character_modifier = astronomical_insights_4
			}
		}
		add_character_modifier = {
			modifier = astronomical_insights_1
			duration = -1
		}
	}
}

remove_astronomical_insight_modifier_effect = {
	hidden_effect = {
		remove_character_modifier = astronomical_insights_1
		remove_character_modifier = astronomical_insights_2
		remove_character_modifier = astronomical_insights_3
		remove_character_modifier = astronomical_insights_4
	}
}

add_Aries_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = stubborn
		}
		10 = {
			add_trait = ambitious
		}
	}
}

add_Taurus_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = content
		}
		10 = {
			add_trait = patient
		}
	}
}
add_Gemini_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = wroth
		}
		10 = {
			add_trait = diligent
		}
	}
}
add_Cancer_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = honest
		}
		10 = {
			add_trait = kind
		}
	}
}
add_Leo_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = cruel
		}
		10 = {
			add_trait = gregarious
		}
	}
}
add_Virgo_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = shy
		}
		10 = {
			add_trait = humble
		}
	}
}
add_Libra_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = trusting
		}
		10 = {
			add_trait = temperate
		}
	}
}
add_Scorpius_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = deceitful
		}
		10 = {
			add_trait = lustful
		}
	}
}
add_Sagittarius_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = wroth
		}
		10 = {
			add_trait = charitable
		}
	}
}
add_Capricorn_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = proud
		}
		10 = {
			add_trait = temperate
		}
	}
}
add_Aquarius_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = slothful
		}
		10 = {
			add_trait = ambitious
		}
	}
}
add_Pisces_sign_trait_effect = {
	random_list = {
		10 = {
			add_trait = trusting
		}
		10 = {
			add_trait = kind
		}
	}
}

add_western_zodiac_trait_effect = {
	custom_tooltip = {
		text = gain_zodiac_trait_effect_tt
	}
	if = { limit = { is_born_under_Aries_trigger = yes }
		add_Aries_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Taurus_trigger = yes }
		add_Taurus_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Gemini_trigger = yes }
		add_Gemini_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Cancer_trigger = yes }
		add_Cancer_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Leo_trigger = yes }
		add_Leo_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Virgo_trigger = yes }
		add_Virgo_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Libra_trigger = yes }
		add_Libra_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Scorpius_trigger = yes }
		add_Scorpius_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Sagittarius_trigger = yes }
		add_Sagittarius_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Capricorn_trigger = yes }
		add_Capricorn_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Aquarius_trigger = yes }
		add_Aquarius_sign_trait_effect = yes
	}
	if = { limit = { is_born_under_Pisces_trigger = yes }
		add_Pisces_sign_trait_effect = yes
	}
}

flip_secret_religious_community_provinces = {
	trigger_switch = {
		on_trigger = secret_religion
		catholic = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_catholic_community
					}
					religion = catholic
					remove_province_modifier = secret_catholic_community
				}
			}
		}
		cathar = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_cathar_community
					}
					religion = cathar
					remove_province_modifier = secret_cathar_community
				}
			}
		}
		fraticelli = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_fraticelli_community
					}
					religion = fraticelli
					remove_province_modifier = secret_fraticelli_community
				}
			}
		}
		waldensian = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_waldensian_community
					}
					religion = waldensian
					remove_province_modifier = secret_waldensian_community
				}
			}
		}
		lollard = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_lollard_community
					}
					religion = lollard
					remove_province_modifier = secret_lollard_community
				}
			}
		}
		adoptionist = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_adoptionist_community
					}
					religion = adoptionist
					remove_province_modifier = secret_adoptionist_community
				}
			}
		}
		chalcedonian = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_chalcedonian_community
					}
					religion = chalcedonian
					remove_province_modifier = secret_chalcedonian_community
				}
			}
		}
		orthodox = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_orthodox_community
					}
					religion = orthodox
					remove_province_modifier = secret_orthodox_community
				}
			}
		}
		bogomilist = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_bogomilist_community
					}
					religion = bogomilist
					remove_province_modifier = secret_bogomilist_community
				}
			}
		}
		monothelite = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_monothelite_community
					}
					religion = monothelite
					remove_province_modifier = secret_monothelite_community
				}
			}
		}
		iconoclast = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_iconoclast_community
					}
					religion = iconoclast
					remove_province_modifier = secret_iconoclast_community
				}
			}
		}
		nestorian = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_nestorian_community
					}
					religion = nestorian
					remove_province_modifier = secret_nestorian_community
				}
			}
		}
		messalian = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_messalian_community
					}
					religion = messalian
					remove_province_modifier = secret_messalian_community
				}
			}
		}
		miaphysite = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_miaphysite_community
					}
					religion = miaphysite
					remove_province_modifier = secret_miaphysite_community
				}
			}
		}
		monophysite = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_monophysite_community
					}
					religion = monophysite
					remove_province_modifier = secret_monophysite_community
				}
			}
		}
		apostolic = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_apostolic_community
					}
					religion = apostolic
					remove_province_modifier = secret_apostolic_community
				}
			}
		}
		paulician = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_paulician_community
					}
					religion = paulician
					remove_province_modifier = secret_paulician_community
				}
			}
		}
		tondrakian = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_tondrakian_community
					}
					religion = tondrakian
					remove_province_modifier = secret_tondrakian_community
				}
			}
		}
		ibadi = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_ibadi_community
					}
					religion = ibadi
					remove_province_modifier = secret_ibadi_community
				}
			}
		}
		kharijite = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_kharijite_community
					}
					religion = kharijite
					remove_province_modifier = secret_kharijite_community
				}
			}
		}
		manichean = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_manichean_community
					}
					religion = manichean
					remove_province_modifier = secret_manichean_community
				}
			}
		}
		khurmazta = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_khurmazta_community
					}
					religion = khurmazta
					remove_province_modifier = secret_khurmazta_community
				}
			}
		}
		taoist = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_taoist_community
					}
					religion = taoist
					remove_province_modifier = secret_taoist_community
				}
			}
		}
		bon = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_bon_community
					}
					religion = bon
					remove_province_modifier = secret_bon_community
				}
			}
		}
		tibetan_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_tibetan_pagan_community
					}
					religion = tibetan_pagan
					remove_province_modifier = secret_tibetan_pagan_community
				}
			}
		}
		sunni = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_sunni_community
					}
					religion = sunni
					remove_province_modifier = secret_sunni_community
				}
			}
		}
		zikri = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_zikri_community
					}
					religion = zikri
					remove_province_modifier = secret_zikri_community
				}
			}
		}
		quranist = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_quranist_community
					}
					religion = quranist
					remove_province_modifier = secret_quranist_community
				}
			}
		}
		shiite = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_shiite_community
					}
					religion = shiite
					remove_province_modifier = secret_shiite_community
				}
			}
		}
		bektashi = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_bektashi_community
					}
					religion = bektashi
					remove_province_modifier = secret_bektashi_community
				}
			}
		}
		druze = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_druze_community
					}
					religion = druze
					remove_province_modifier = secret_druze_community
				}
			}
		}
		hurufi = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_hurufi_community
					}
					religion = hurufi
					remove_province_modifier = secret_hurufi_community
				}
			}
		}
		qarmatian = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_qarmatian_community
					}
					religion = qarmatian
					remove_province_modifier = secret_qarmatian_community
				}
			}
		}
		jewish = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_jewish_community
					}
					religion = jewish
					remove_province_modifier = secret_jewish_community
				}
			}
		}
		samaritan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_samaritan_community
					}
					religion = samaritan
					remove_province_modifier = secret_samaritan_community
				}
			}
		}
		karaite = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_karaite_community
					}
					religion = karaite
					remove_province_modifier = secret_karaite_community
				}
			}
		}
		zoroastrian = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_zoroastrian_community
					}
					religion = zoroastrian
					remove_province_modifier = secret_zoroastrian_community
				}
			}
		}
		mazdaki = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_mazdaki_community
					}
					religion = mazdaki
					remove_province_modifier = secret_mazdaki_community
				}
			}
		}
		zurvanist = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_zurvanist_community
					}
					religion = zurvanist
					remove_province_modifier = secret_zurvanist_community
				}
			}
		}
		mandaean = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_mandaean_community
					}
					religion = mandaean
					remove_province_modifier = secret_mandaean_community
				}
			}
		}
		yazidi = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_yazidi_community
					}
					religion = yazidi
					remove_province_modifier = secret_yazidi_community
				}
			}
		}
		hindu = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_hindu_community
					}
					religion = hindu
					remove_province_modifier = secret_hindu_community
				}
			}
		}
		buddhist = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_buddhist_community
					}
					religion = buddhist
					remove_province_modifier = secret_buddhist_community
				}
			}
		}
		jain = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_jain_community
					}
					religion = jain
					remove_province_modifier = secret_jain_community
				}
			}
		}
		norse_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_norse_pagan_reformed_community
					}
					religion = norse_pagan_reformed
					remove_province_modifier = secret_norse_pagan_reformed_community
				}
			}
		}
		german_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_german_pagan_reformed_community
					}
					religion = german_pagan_reformed
					remove_province_modifier = secret_german_pagan_reformed_community
				}
			}
		}
		celtic_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_celtic_pagan_reformed_community
					}
					religion = celtic_pagan_reformed
					remove_province_modifier = secret_celtic_pagan_reformed_community
				}
			}
		}
		slavic_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_slavic_pagan_reformed_community
					}
					religion = slavic_pagan_reformed
					remove_province_modifier = secret_slavic_pagan_reformed_community
				}
			}
		}
		tengri_pagan_reformed = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_tengri_pagan_reformed_community
					}
					religion = tengri_pagan_reformed
					remove_province_modifier = secret_tengri_pagan_reformed_community
				}
			}
		}
		baltic_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_baltic_pagan_reformed_community
					}
					religion = baltic_pagan_reformed
					remove_province_modifier = secret_baltic_pagan_reformed_community
				}
			}
		}
		finnish_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_finnish_pagan_reformed_community
					}
					religion = finnish_pagan_reformed
					remove_province_modifier = secret_finnish_pagan_reformed_community
				}
			}
		}
		west_african_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_west_african_pagan_reformed_community
					}
					religion = west_african_pagan_reformed
					remove_province_modifier = secret_west_african_pagan_reformed_community
				}
			}
		}
		zun_pagan_reformed = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_zun_pagan_reformed_community
					}
					religion = zun_pagan_reformed 
					remove_province_modifier = secret_zun_pagan_reformed_community
				}
			}
		}
		norse_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_norse_pagan_community
					}
					religion = norse_pagan
					remove_province_modifier = secret_norse_pagan_community
				}
			}
		}
		german_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_german_pagan_community
					}
					religion = german_pagan
					remove_province_modifier = secret_german_pagan_community
				}
			}
		}
		celtic_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_celtic_pagan_community
					}
					religion = celtic_pagan
					remove_province_modifier = secret_celtic_pagan_community
				}
			}
		}
		slavic_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_slavic_pagan_community
					}
					religion = slavic_pagan
					remove_province_modifier = secret_slavic_pagan_community
				}
			}
		}
		tengri_pagan = {
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_tengri_pagan_community
					}
					religion = tengri_pagan
					remove_province_modifier = secret_tengri_pagan_community
				}
			}
		}
		baltic_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_baltic_pagan_community
					}
					religion = baltic_pagan
					remove_province_modifier = secret_baltic_pagan_community
				}
			}
		}
		finnish_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_finnish_pagan_community
					}
					religion = finnish_pagan
					remove_province_modifier = secret_finnish_pagan_community
				}
			}
		}
		west_african_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_west_african_pagan_community
					}
					religion = west_african_pagan
					remove_province_modifier = secret_west_african_pagan_community
				}
			}
		}
		zun_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_zun_pagan_community
					}
					religion = zun_pagan
					remove_province_modifier = secret_zun_pagan_community
				}
			}
		}
		arab_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_arab_pagan_community
					}
					religion = arab_pagan
					remove_province_modifier = secret_arab_pagan_community
				}
			}
		}
		berber_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_berber_pagan_community
					}
					religion = berber_pagan
					remove_province_modifier = secret_berber_pagan_community
				}
			}
		}
		roman_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_roman_pagan_community
					}
					religion = roman_pagan
					remove_province_modifier = secret_roman_pagan_community
				}
			}
		}
		egyptian_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_egyptian_pagan_community
					}
					religion = egyptian_pagan
					remove_province_modifier = secret_egyptian_pagan_community
				}
			}
		}
		jewish_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_jewish_pagan_community
					}
					religion = jewish_pagan
					remove_province_modifier = secret_jewish_pagan_community
				}
			}
		}
		aten_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_aten_pagan_community
					}
					religion = aten_pagan
					remove_province_modifier = secret_aten_pagan_community
				}
			}
		}
		promethean_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_promethean_pagan_community
					}
					religion = promethean_pagan
					remove_province_modifier = secret_promethean_pagan_community
				}
			}
		}
		aztec = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_aztec_community
					}
					religion = aztec
					remove_province_modifier = secret_aztec_community
				}
			}
		}
		hellenic_pagan = { 
			ROOT = {
				any_demesne_province = {
					limit = {
						has_province_modifier = secret_hellenic_pagan_community
					}
					religion = hellenic_pagan
					remove_province_modifier = secret_hellenic_pagan_community
				}
			}
		}
	}
}

clean_up_after_leaving_society_effect = {
	hidden_effect = {
		remove_do_not_disturb_effect = yes
		remove_character_modifier = quest_cooldown_timer
		
		#Powers, Missions and Interactions: the Assassins
		#quest_the_assassins_assassination
		#quest_the_assassins_collect_debt
		#quest_the_assassins_convert_province
		#quest_the_assassins_occupy_holding
		#quest_the_assassins_protege
		clr_character_flag = ongoing_recruitment
		clr_character_flag = approves_of_shia
		clr_character_flag = disapproves_of_shia
		clr_character_flag = willing_to_join
		clr_character_flag = unwilling_to_join
		clr_character_flag = assassins_attempted_recruitment
		clr_character_flag = escape_successful
		clr_character_flag = escape_injured
		clr_character_flag = escape_death
		clr_character_flag = escape_bribe 
		
		#Powers, Missions and Interactions: Devil Worshipers
		clr_character_flag = attempted_corrupt_priest
		clr_character_flag = possessing_courtier
		clr_character_flag = desecration_in_progress
		clr_character_flag = desecration_violent
		clr_character_flag = desecration_at_home
		clr_character_flag = desecration_plotting
		clr_character_flag = approves_of_satanism
		clr_character_flag = disapproves_of_satanism
		clr_character_flag = has_ill_lover_loc
		clr_character_flag = has_ill_spouse_loc
		clr_character_flag = has_ill_child_loc
		clr_character_flag = has_money_troubles_loc
		clr_character_flag = has_some_illness_loc
		clr_character_flag = has_need_of_winning_battles_loc
		clr_character_flag = has_a_rival_loc
		clr_character_flag = is_weak_loc
		clr_character_flag = is_dumb_loc
		clr_character_flag = being_recruited_by_the_satanists
		clr_character_flag = being_recruited_by_the_trollcrafters
		clr_character_flag = being_recruited_by_the_cult_of_kali
		clr_character_flag = being_recruited_by_the_cold_ones
		clr_character_flag = being_recruited_by_the_plaguebringers

		#Powers, Missions and Interactions: Secret Religious	
		clr_character_flag = sr_too_honest
		clr_character_flag = sr_too_wroth
		clr_character_flag = sr_too_slothful
		clr_character_flag = sr_too_trusting
		clr_character_flag = sr_too_indiscreet
		clr_character_flag = free_help
		clr_character_flag = help_for_cost
		clr_character_flag = conduct_secret_ceremony_timer
		remove_character_modifier = attempting_to_blend_in
		clr_character_flag = blending_in_timer
		clr_character_flag = attempting_to_convince_stubborn_courtier
		clr_character_flag = attempting_to_convince_concerned_friend
		clr_character_flag = blend_in_struggled_with_trait
		clr_character_flag = blend_in_attended_house_of_worship
		clr_character_flag = blend_in_general_progress
		#quest_secret_religious_societies_induct_ruler
		#quest_secret_religious_societies_sympathy_ruler
		
		#Powers, Missions and Interactions: Monastic orders
		clr_character_flag = monastic_orders_holy_seclusion
		clr_character_flag = monastic_orders_mission_charity
		clr_character_flag = monastic_orders_mission_theology
 		clr_character_flag = monastic_orders_mission_christian_pilgrimage
		clr_character_flag = monastic_orders_mission_dharmic_pilgrimage
		clr_character_flag = monastic_orders_mission_temple
		clr_character_flag = ascetic_arriving
		clr_character_flag = monastic_artifact_lover
		clr_character_flag = monastic_artifact_seamless_robe_of_jesus
		clr_character_flag = monastic_artifact_crown_of_thorns
		clr_character_flag = monastic_artifact_fragment_of_true_cross
		clr_character_flag = monastic_artifact_holy_foreskin
		clr_character_flag = monastic_artifact_image_of_edessa
		clr_character_flag = monastic_artifact_elaborate_danda
		clr_character_flag = monastic_artifact_sariraka_actual_body_part
		clr_character_flag = monastic_artifact_sarira
		clr_character_flag = suggestion_A_flag
		clr_character_flag = suggestion_B_flag
		clr_character_flag = 3264_deceitful_flag
		clr_character_flag = 3264_publish_flag
		clr_character_flag = 3264_depressed_flag
		clr_character_flag = 4202_visit_monastery_flag
		clr_character_flag = 4202_hire_someone_flag
		clr_character_flag = 4202_send_my_own_samples_flag
		clr_character_flag = 4212_woke_them_up_flag
		clr_character_flag = 4212_let_them_sleep_flag
		clr_character_flag = 4212_pranked_them_flag
		remove_character_modifier = in_meditation
		remove_character_modifier = doing_penance
		clr_character_flag = holy_seclusion_timer
		clr_character_flag = holy_seclusion_struggled_with_vice
		clr_character_flag = holy_seclusion_lustful
		clr_character_flag = holy_seclusion_gluttonous
		clr_character_flag = holy_seclusion_greedy
		clr_character_flag = holy_seclusion_slothful
		clr_character_flag = holy_seclusion_struggled_with_loneliness
		clr_character_flag = holy_seclusion_scripture_reading
		clr_character_flag = holy_seclusion_interrupting_child
		clr_character_flag = success_seculison_desc_A
		clr_character_flag = success_seculison_desc_B
		clr_character_flag = success_seculison_desc_C

		#Powers, Missions and Interactions: Hermetics
		clr_character_flag = power_hungry_scrying_flag
		clr_character_flag = relationship_focused_scrying_flag
		clr_character_flag = battle_focused_scrying_flag
		remove_character_modifier = writing_magnum_opus
		remove_character_modifier = acquire_ingredients_decision_cooldown_timer
		clr_character_flag = building_laboratory
		clr_character_flag = decided_on_glass
		clr_character_flag = decided_on_crucibles
		clr_character_flag = decided_on_tools
		clr_character_flag = decided_on_books
		clr_character_flag = bribed_guards
		clr_character_flag = guards_wake_up
		clr_character_flag = distraction_failed
		clr_character_flag = caught_stealing
		clr_character_flag = caught_destroying
		remove_scrying_omen_modifiers_effect = yes
		clr_character_flag = lab_destruction
		clr_character_flag = lab_damage
		clr_character_flag = lab_explosion_death
	}
}

increase_council_power_effect = {
	custom_tooltip = {
		text = council_power_increased
		hidden_tooltip = {
			set_variable = { which = "laws" value = 0 }
			if = {
				limit = {
					has_law = law_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = law_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			if = {
				limit = {
					has_law = war_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = war_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			if = {
				limit = {
					has_law = revoke_title_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = revoke_title_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			if = {
				limit = {
					has_law = imprison_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = imprison_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			if = {
				limit = {
					has_law = grant_title_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = grant_title_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			if = {
				limit = {
					has_law = banish_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = banish_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			if = {
				limit = {
					has_law = execution_voting_power_0
					NOT = {
						check_variable = { which = "laws" value = 2 }
					}
				}
				add_law_w_cooldown = execution_voting_power_1
				change_variable = { which = "laws" value = 1 }
			}
			set_variable = { which = "laws" value = 0 }
		}
	}
}

increase_vassal_freedom_effect = {
	if = {
		limit = {
			has_law = kings_peace_1
		}
		add_law_w_cooldown = kings_peace_0
	}
	if = {
		limit = {
			has_law = kings_peace_2
		}
		add_law_w_cooldown = kings_peace_1
	}
}

spawn_good_commander_effect = {
	create_random_soldier = {
		random_traits = yes
		dynasty = random
		female = no
		attributes = {
			diplomacy = 2
			learning = 2
			stewardship = 2
			intrigue = 2
			martial = 8
		}
	}
	new_character = {
		remove_trait = weak
		remove_trait = slow
		remove_trait = imbecile
		remove_trait = dull
		
		remove_trait = mystic
		remove_trait = socializer
		remove_trait = gamer
		remove_trait = hedonist
		remove_trait = duelist
		remove_trait = hunter
		remove_trait = strategist
		remove_trait = administrator
		remove_trait = architect
		remove_trait = gardener
		remove_trait = schemer
		remove_trait = impaler
		remove_trait = seducer
		remove_trait = seductress
		remove_trait = theologian
		remove_trait = scholar
		
		random_list = { # Flavor Randomization
			35 = { 
				# Nothing
			}
			15 = {
				change_martial = 2
			}
			10 = {
				add_trait = robust
			}
			10 = {
				add_trait = duelist
			}
			10 = {
				add_trait = hunter
			}
			5 = {
				add_trait = strategist
			}
			5 = {
				change_martial = 4
			}
			5 = {
				if = {
					limit = {
						has_dlc = "Reapers"
					}
					add_trait = one_eyed
				}
			}
			5 = { 
				add_trait = shrewd
			}
		}
		hidden_tooltip = {
			if = {
				limit = {
					has_dharmic_religion_trigger = yes
					NOT = { religion = bon }
				}
				add_trait = kshatriya
				character_event = { id = RoI.30121 }
			}
		}
		set_character_flag = invited_soldier
		save_event_target_as = invited_character
	}
}

select_random_hermetic_ingredient_herb_effect = { # If run once, this will set a flag on ONE herbal ingredient. If run twice, it will set a second flag on another herbal ingredient...
	if = {
		limit = {
			any_artifact = {
				has_artifact_flag = selected_ingredient_1
			}
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_2
				}
			}
		}
		random_artifact = {
			limit = {
				is_ingredient_herb_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_2
		}
	}
	if = {
		limit = {
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_1
				}
			}	
		}
		random_artifact = {
			limit = {
				is_ingredient_herb_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_1
		}
	}
}

select_random_hermetic_ingredient_animal_part_effect = { 
	if = {
		limit = {
			any_artifact = {
				has_artifact_flag = selected_ingredient_1
			}
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_2
				}
			}
		}
		random_artifact = {
			limit = {
				is_ingredient_animal_part_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_2
		}
	}
	if = {
		limit = {
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_1
				}
			}	
		}
		random_artifact = {
			limit = {
				is_ingredient_animal_part_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_1
		}
	}
}

select_random_hermetic_ingredient_powder_effect = {
	if = {
		limit = {
			any_artifact = {
				has_artifact_flag = selected_ingredient_1
			}
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_2
				}
			}
		}
		random_artifact = {
			limit = {
				is_ingredient_powder_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_2
		}
	}
	if = {
		limit = {
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_1
				}
			}	
		}
		random_artifact = {
			limit = {
				is_ingredient_powder_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_1
		}
	}
}

select_random_hermetic_ingredient_liquid_effect = {
	if = {
		limit = {
			any_artifact = {
				has_artifact_flag = selected_ingredient_1
			}
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_2
				}
			}
		}
		random_artifact = {
			limit = {
				is_ingredient_liquid_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_2
		}
	}
	if = {
		limit = {
			NOT = {
				any_artifact = {
					has_artifact_flag = selected_ingredient_1
				}
			}	
		}
		random_artifact = {
			limit = {
				is_ingredient_liquid_trigger = yes
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
			}
			set_artifact_flag = selected_ingredient_1
		}
	}
}

select_random_hermetic_ingredient_effect = { #when it doesn't matter if it's a herb/animal part/metal/liquid
	if = {
		limit = {
			has_selected_ingredient_1_trigger = yes
			has_selected_ingredient_2_trigger = no
		}
		random_artifact = {
			limit = {
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
				has_artifact_flag = ingredient
			}
			set_artifact_flag = selected_ingredient_2
		}
	}
	if = {
		limit = {
			has_selected_ingredient_1_trigger = no
			any_artifact = {
				has_artifact_flag = ingredient
			}
		}
		random_artifact = {
			limit = {
				NOT = { has_artifact_flag = selected_ingredient_1 }
				NOT = { has_artifact_flag = selected_ingredient_2 }
				has_artifact_flag = ingredient
			}
			set_artifact_flag = selected_ingredient_1
		}
	}
}

remove_selection_of_ingredients_effect = { #for clearing selection of ingredients
	hidden_effect = {
		any_artifact = {
			clr_artifact_flag = selected_ingredient_1
			clr_artifact_flag = selected_ingredient_2
		}
	}
}

destroy_selected_ingredient_1_effect = { #for removing the ingredient in question
	custom_tooltip = { text = destroy_selected_ingredient_1_tt }
	hidden_effect = {
		random_artifact = {
			limit = { has_artifact_flag = selected_ingredient_1 }
			destroy_artifact = yes
		}
	}
}

destroy_selected_ingredient_2_effect = { #for removing the ingredient in question
	custom_tooltip = { text = destroy_selected_ingredient_2_tt }
	hidden_effect = {
		random_artifact = {
			limit = { has_artifact_flag = selected_ingredient_2 }
			destroy_artifact = yes
		}
	}
}

destroy_selected_ingredient_1_and_2_effect = { #for removing both selected ingredients
	custom_tooltip = { text = destroy_selected_ingredient_1_and_2_tt }
	hidden_effect = {
		random_artifact = {
			limit = { has_artifact_flag = selected_ingredient_1 }
			destroy_artifact = yes
		}
		random_artifact = {
			limit = { has_artifact_flag = selected_ingredient_2 }
			destroy_artifact = yes
		}
	}
}

destroy_selected_ingredient_1_plus_random_other_ingredient_effect = { #for removing the ingredient in question PLUS a random other one (unnamed in tooltip)
	custom_tooltip = { text = destroy_selected_ingredient_1_plus_random_other_ingredient_tt }
	hidden_effect = {
		random_artifact = {
			limit = { has_artifact_flag = selected_ingredient_1 }
			destroy_artifact = yes
		}
		random_artifact = {
			limit = {
				has_artifact_flag = ingredient
			}
			destroy_artifact = yes
		}
	}
}

destroy_random_herb_ingredient_effect = {
	random_artifact = {
		limit = {
			has_artifact_flag = ingredient
			is_ingredient_herb_trigger = yes
		}
		destroy_artifact = yes
	}
}

destroy_random_animal_part_ingredient_effect = {
	random_artifact = {
		limit = {
			has_artifact_flag = ingredient
			is_ingredient_animal_part_trigger = yes
		}
		destroy_artifact = yes
	}
}

destroy_random_powder_ingredient_effect = {
	random_artifact = {
		limit = {
			has_artifact_flag = ingredient
			is_ingredient_powder_trigger = yes
		}
		destroy_artifact = yes
	}
}

destroy_random_liquid_ingredient_effect = {
	random_artifact = {
		limit = {
			has_artifact_flag = ingredient
			is_ingredient_liquid_trigger = yes
		}
		destroy_artifact = yes
	}
}

destroy_random_herb_or_animal_part_ingredients_effect = {
	hidden_effect = {
		random_list = {
			5 = {
				trigger = { has_a_herb_ingredient_trigger = yes }
				destroy_random_herb_ingredient_effect = yes
			}
			5 = {
				trigger = { has_an_animal_part_ingredient_trigger = yes }
				destroy_random_animal_part_ingredient_effect = yes
			}
			20 = {
				trigger = {
					any_artifact = {
						count = 2
						is_ingredient_herb_trigger = yes
						has_artifact_flag = ingredient
					}
				}
				destroy_random_herb_ingredient_effect = yes
				destroy_random_herb_ingredient_effect = yes
			}
			20 = {
				trigger = {
					any_artifact = {
						count = 2
						is_ingredient_animal_part_trigger = yes
						has_artifact_flag = ingredient
					}
				}
				destroy_random_animal_part_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
			}
			20 = {
				trigger = {
					has_a_herb_ingredient_trigger = yes
					has_an_animal_part_ingredient_trigger = yes
				}
				destroy_random_herb_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
			}
			20 = {
				trigger = {
					any_artifact = {
						count = 3
						is_ingredient_herb_trigger = yes
						has_artifact_flag = ingredient
					}
				}
				destroy_random_herb_ingredient_effect = yes
				destroy_random_herb_ingredient_effect = yes
				destroy_random_herb_ingredient_effect = yes
			}
			20 = {
				trigger = {
					any_artifact = {
						count = 3
						is_ingredient_animal_part_trigger = yes
						has_artifact_flag = ingredient
					}
				}
				destroy_random_animal_part_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
			}
			50 = {
				trigger = {
					any_artifact = {
						count = 2
						is_ingredient_herb_trigger = yes
						has_artifact_flag = ingredient
					}
					has_an_animal_part_ingredient_trigger = yes
				}
				destroy_random_herb_ingredient_effect = yes
				destroy_random_herb_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
			}
			50 = {
				trigger = {								
					any_artifact = {
						count = 2
						is_ingredient_animal_part_trigger = yes
						has_artifact_flag = ingredient
					}
					has_a_herb_ingredient_trigger = yes
				}
				destroy_random_herb_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
				destroy_random_animal_part_ingredient_effect = yes
			}
		}
	}
}

destroy_random_ingredients_effect = {
	custom_tooltip = { text = random_ingredients_are_destroyed_tt }
	hidden_effect = {
		random_list = {
			5 = {
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
			}
			50 = {
				trigger = {
					any_artifact = {
						count = 2
						has_artifact_flag = ingredient
					}
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
			}
			100 = {
				trigger = {
					any_artifact = {
						count = 3
						has_artifact_flag = ingredient
					}
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
			}
			150 = {
				trigger = {
					any_artifact = {
						count = 4
						has_artifact_flag = ingredient
					}
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
				random_artifact = {
					limit = { has_artifact_flag = ingredient }
					destroy_artifact = yes
				}
			}
		}
	}
}

destroy_all_ingredients_effect = {
	custom_tooltip = { text = destroy_all_ingredients_tt }
	hidden_effect = {
		if = {
			limit = {
				any_artifact = {
					has_artifact_flag = ingredient
				}
			}
			any_artifact = {
				limit = { has_artifact_flag = ingredient }
				destroy_artifact = yes
			}
		}
	}
}


calculate_health_level_of_ingredient_1_effect = {
	hidden_effect = {
		set_variable = { # Reset potion quality
			which = current_potion_quality
			value = 0
		}
		if = {
			limit = {
				any_artifact = { has_artifact_flag = selected_ingredient_1 }
				selected_ingredient_is_perceived_healthy_trigger = yes
			}
 			ROOT = {
				change_variable = {
					which = current_potion_quality
					value = 1
				}
			}
		}
		if = {
			limit = {
				any_artifact = { has_artifact_flag = selected_ingredient_1 }
				selected_ingredient_is_unhealthy_trigger = yes
			}
 			ROOT = {
				change_variable = {
					which = current_potion_quality
					value = -1
				}
			}
		}
	}
}

calculate_health_level_of_ingredient_2_effect = {
	hidden_effect = {
		set_variable = { # Reset potion quality
			which = current_potion_quality
			value = 0
		}
		if = {
			limit = {
				any_artifact = { has_artifact_flag = selected_ingredient_2 }
				selected_ingredient_is_perceived_healthy_trigger = yes
			}
 			ROOT = {
				change_variable = {
					which = current_potion_quality
					value = 1
				}
			}
		}
		if = {
			limit = {
				any_artifact = { has_artifact_flag = selected_ingredient_2 }
				selected_ingredient_is_unhealthy_trigger = yes
			}
 			ROOT = {
				change_variable = {
					which = current_potion_quality
					value = -1
				}
			}
		}
	}
}

calculate_health_level_of_ingredient_1_and_2_effect = {
	hidden_effect = {
		set_variable = { # Reset potion quality
			which = current_potion_quality
			value = 0
		}
		while = {
			limit = {
				any_artifact = {
					OR = {
						has_artifact_flag = selected_ingredient_1
						has_artifact_flag = selected_ingredient_2
					}
					NOT = { has_artifact_flag = ingredient_counted }
				}
			}
			random_artifact = {
				limit = {
					OR = {
						has_artifact_flag = selected_ingredient_1
						has_artifact_flag = selected_ingredient_2
					}
					NOT = { has_artifact_flag = ingredient_counted }
				}
				set_artifact_flag = ingredient_counted
				if = {
					limit = {
						ingredient_is_perceived_healthy_trigger = yes
					}
					ROOT = {
						change_variable = {
							which = current_potion_quality
							value = 1
						}
					}
				}
				if = {
					limit = {
						ingredient_is_unhealthy_trigger = yes
					}
					ROOT = {
						change_variable = {
							which = current_potion_quality
							value = -1
						}
					}
				}
			}
		}
		any_artifact = {
			clr_artifact_flag = ingredient_counted
		}
	}
}

calculate_health_level_of_all_ingredients_effect = {
	hidden_effect = {
		while = {
			limit = {
				any_artifact = {
					has_artifact_flag = ingredient
					NOT = { has_artifact_flag = ingredient_counted }
				}
			}
			random_artifact = {
				limit = {
					has_artifact_flag = ingredient
					NOT = { has_artifact_flag = ingredient_counted }
				}
				set_artifact_flag = ingredient_counted
				if = {
					limit = {
						ingredient_is_perceived_healthy_trigger = yes
					}
					ROOT = {
						change_variable = {
							which = current_potion_quality
							value = 1
						}
					}
				}
				if = {
					limit = {
						ingredient_is_unhealthy_trigger = yes
					}
					ROOT = {
						change_variable = {
							which = current_potion_quality
							value = -1
						}
					}
				}
			}
		}
		any_artifact = {
			clr_artifact_flag = ingredient_counted
		}
	}
}

#Raiding adventurer war declaration effect
raiding_adventurer_war_declaration_effect = {
	custom_tooltip = { text = raiding_adventurer_war_declaration_tooltip }

	event_target:selling_province = {
		event_target:raiding_adventurer = {
			unsafe_war = {
				target = PREVPREV
				casus_belli = duchy_adventure
				thirdparty_title = PREV
				tier = DUKE
			}
			any_army = {
				set_can_toggle_looting = yes
				set_looting = no
			}
		}
	}
	
	clr_character_flag = adventurer_unsafe_duchy_war
	clr_character_flag = adventurer_safe_duchy_war
	clr_character_flag = negotiating_with_adventurer

	hidden_effect = {
		event_target:raiding_adventurer = {
			clr_character_flag = raiding_adventurer
		}
	}
}


#Grace effects
add_grace_trivial_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = 100
	}
}

add_grace_minor_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = 200
	}
}

add_grace_medium_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = 300
	}	
}

add_grace_major_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = 500
	}
}

add_grace_massive_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = 1000
	}
}

add_grace_super_huge_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = 2000
	}
}

detract_grace_trivial_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = -100
	}
}

detract_grace_minor_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = -200
	}
}

detract_grace_medium_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = -300
	}
}

detract_grace_major_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = -500
	}
}

detract_grace_massive_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = -1000
	}
}

detract_grace_super_huge_effect = {
	add_offmap_currency = {
		offmap = offmap_china
		value = -2000
	}
}

set_china_boon_cd_effect = {  #added via tribute to China decisions... Always one year.
	add_character_modifier = {
		hidden = yes
		name = jd_china_boon_cd
		days = 365 #If this is changed, edit  china_offmap_boon_decisions_enabled_trigger_cd_tt
	}
}

set_china_tribute_cd_effect = { #added via tribute to China decisions... Always one year.
	add_character_modifier = {
		hidden = yes
		name = jd_china_tribute_cd
		days = 365
	}
}

leave_court_for_china_effect = { # NOTE: this does not set a "killer", meaning if you want them to be ORDERED to go to China, a killer needs to be set (eg: "killer = ROOT")
	custom_tooltip = {
		text = will_leave_for_china_tt
	}
	set_character_flag = ignore_refund
	hidden_effect = { death = { death_reason = death_went_to_china } }
}

return_to_china_effect = { # NOTE: this does not set a "killer", meaning if you want them to be ORDERED to go to China, a killer needs to be set (eg: "killer = ROOT")
	custom_tooltip = {
		text = will_return_to_china_tt
	}
	set_character_flag = ignore_refund
	hidden_effect = { death = { death_reason = death_went_back_to_china } }
}

# Utilizes china_war_minimum_commander_martial variable on the current scope to spawn characters with at least that amount of martial skill.
china_spawn_commander_effect = {
	create_random_soldier = {
		random_traits = yes
		religion = liege
		culture = liege
		dynasty = none
		female = no
		age = 28
	}
	new_character = {
		unsafe_give_minor_title = title_commander
		
		set_variable = {
			which = china_war_minimum_commander_martial
			which = PREV
		}
		if = {
			limit = {
				NOT = { trait = brilliant_strategist }
			}
			remove_trait = misguided_warrior
			remove_trait = tough_soldier
			remove_trait = skilled_tactician
			add_trait = skilled_tactician
			# Make sure they have a tier 3 or tier 4 education
		}
		random_list = { # Give a chance to get Chinese commander traits
			30 = {
				trigger = {
					can_have_more_leadership_traits = yes
					NOT = { trait = master_of_flame }
				}
				add_trait = master_of_flame
			}
			30 = {
				trigger = {
					can_have_more_leadership_traits = yes
					NOT = { trait = logistics_expert }
				}
				add_trait = logistics_expert
			}
			30 = {
				trigger = {
					can_have_more_leadership_traits = yes
					NOT = { trait = levy_coordinator }
				}
				add_trait = levy_coordinator
			}
			30 = {
				trigger = {
					can_have_more_leadership_traits = yes
					NOT = { trait = sapper }
				}
				add_trait = sapper
			}
			90 = {}
		}
		while = { # Increase the martial skill with base or martial traits until the minimum is reached
			limit = {
				NOT = {
					martial = china_war_minimum_commander_martial
				}
			}
			random_list = {
				40 = {
					change_martial = 1
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = strong
							trait = robust
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = strong
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = strong
							trait = robust
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = robust
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = shrewd
							trait = genius
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = shrewd
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = duelist
							trait = hunter
							trait = strategist
							trait = architect
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = duelist
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = duelist
							trait = hunter
							trait = strategist
							trait = architect
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = hunter
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = duelist
							trait = hunter
							trait = strategist
							trait = architect
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = strategist
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = duelist
							trait = hunter
							trait = strategist
							trait = architect
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = architect
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = diligent
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = diligent
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = brave
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = brave
				}
				5 = {
					trigger = { 
						NOR = { 
							trait = ambitious
							calc_true_if = {
								amount = 3
								trait = strong 
								trait = robust 
								trait = shrewd 
								trait = duelist 
								trait = hunter 
								trait = strategist 
								trait = architect 
								trait = diligent 
								trait = brave 
								trait = ambitious
							}
						}
					}
					add_trait = ambitious
				}
			}
		}
	}
}

china_war_spawn_troops_effect = {
	# Requires the current things to function properly:
	# event_target:spawn_province
	# variable: china_war_troop_quality
	# variable: china_war_troop_quantity
	while = {
		limit = {
			check_variable = {
				which = china_war_troop_quantity
				value = 1
			}
		}
		change_variable = {	
			which = china_war_troop_quantity
			value = -1
		}
		
		random_list = { # Not really random but decent flow control
			10 = {
				trigger = {
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 2
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 168 168 }
						light_infantry = { 284 284 }
						heavy_infantry = { 0 0 }
						pikemen = { 0 0 }
						light_cavalry = { 41 41 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 2
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 3
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 148 148 }
						light_infantry = { 264 264 }
						heavy_infantry = { 0 0 }
						pikemen = { 0 0 }
						light_cavalry = { 81 81 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 3
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 4
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 144 144 }
						light_infantry = { 221 221 }
						heavy_infantry = { 49 49 }
						pikemen = { 0 0 }
						light_cavalry = { 79 79 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 4
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 5
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 144 144 }
						light_infantry = { 203 203 }
						heavy_infantry = { 66 66 }
						pikemen = { 19 19 }
						light_cavalry = { 61 61 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 5
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 6
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 136 136 }
						light_infantry = { 134 134 }
						heavy_infantry = { 102 102 }
						pikemen = { 41 41 }
						light_cavalry = { 80 80 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 6
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 7
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 122 122 }
						light_infantry = { 71 71 }
						heavy_infantry = { 85 85 }
						pikemen = { 78 78 }
						light_cavalry = { 113 113 }
						knights = { 24 24 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 7
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 107 107 }
						light_infantry = { 22 22 }
						heavy_infantry = { 106 106 }
						pikemen = { 96 96 }
						light_cavalry = { 111 111 }
						knights = { 51 51 }
					}
					attrition = 0.1
					disband_on_peace = yes
					merge = yes
				}
			}
		}
	}
}

china_war_spawn_troops_no_disband_effect = {
	# Requires the current things to function properly:
	# event_target:spawn_province
	# variable: china_war_troop_quality
	# variable: china_war_troop_quantity
	while = {
		limit = {
			check_variable = {
				which = china_war_troop_quantity
				value = 1
			}
		}
		change_variable = {	
			which = china_war_troop_quantity
			value = -1
		}
		
		random_list = { # Not really random but decent flow control
			10 = {
				trigger = {
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 2
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 168 168 }
						light_infantry = { 284 284 }
						heavy_infantry = { 0 0 }
						pikemen = { 0 0 }
						light_cavalry = { 41 41 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 2
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 3
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 148 148 }
						light_infantry = { 264 264 }
						heavy_infantry = { 0 0 }
						pikemen = { 0 0 }
						light_cavalry = { 81 81 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 3
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 4
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 144 144 }
						light_infantry = { 221 221 }
						heavy_infantry = { 49 49 }
						pikemen = { 0 0 }
						light_cavalry = { 79 79 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 4
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 5
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 144 144 }
						light_infantry = { 203 203 }
						heavy_infantry = { 66 66 }
						pikemen = { 19 19 }
						light_cavalry = { 61 61 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 5
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 6
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 136 136 }
						light_infantry = { 134 134 }
						heavy_infantry = { 102 102 }
						pikemen = { 41 41 }
						light_cavalry = { 80 80 }
						knights = { 0 0 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 6
					}
					NOT = {
						check_variable = {
							which = china_war_troop_quality
							value = 7
						}
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 122 122 }
						light_infantry = { 71 71 }
						heavy_infantry = { 85 85 }
						pikemen = { 78 78 }
						light_cavalry = { 113 113 }
						knights = { 24 24 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
			10 = {
				trigger = {
					check_variable = {
						which = china_war_troop_quality
						value = 7
					}
				}
				spawn_unit = {
					owner = THIS
					province = event_target:spawn_province
					home = event_target:spawn_province
					troops = {
						archers = { 107 107 }
						light_infantry = { 22 22 }
						heavy_infantry = { 106 106 }
						pikemen = { 96 96 }
						light_cavalry = { 111 111 }
						knights = { 51 51 }
					}
					attrition = 0.1
					disband_on_peace = no
					merge = yes
				}
			}
		}
	}
}

china_war_modify_variables_by_status_effect = {
	# variable: china_war_troop_quality
	# variable: china_war_troop_quantity
	# variable: china_war_minimum_commander_martial
	# variable: china_war_target_match_mult
	
	random_list = {
		1 = {
			trigger = {
				offmap_china = { has_status = china_stable }
			}
			change_variable = { which = china_war_troop_quality value = 1 }
			change_variable = { which = china_war_minimum_commander_martial value = 3 }
		}
		1 = {
			trigger = {
				offmap_china = { has_status = china_unrest }
			}
			change_variable = { which = china_war_troop_quantity value = -6 }
			change_variable = { which = china_war_target_match_mult value = -0.15 }
		}
		1 = {
			trigger = {
				offmap_china = { has_status = china_civil_war }
			}
			change_variable = { which = china_war_troop_quantity value = -6 }
			change_variable = { which = china_war_target_match_mult value = -0.25 }
			change_variable = { which = china_war_troop_quality value = -1 }
			change_variable = { which = china_war_minimum_commander_martial value = -6 }
		}
		1 = {
			trigger = {
				OR = {
					offmap_china = { has_status = china_jurchen_invasion }
					offmap_china = { has_status = china_mongol_invasion }
				}
			}
			change_variable = { which = china_war_troop_quantity value = -7 }
			change_variable = { which = china_war_target_match_mult value = -0.4 }
			change_variable = { which = china_war_troop_quality value = -1 }
			change_variable = { which = china_war_minimum_commander_martial value = -2 }
		}
		1 = {
			trigger = {
				offmap_china = { has_status = china_famine }
			}
			change_variable = { which = china_war_troop_quantity value = -4 }
			change_variable = { which = china_war_target_match_mult value = -0.30 }
			change_variable = { which = china_war_troop_quality value = -2 }
			change_variable = { which = china_war_minimum_commander_martial value = -2 }
		}
		1 = {
			trigger = {
				offmap_china = { has_status = china_plague }
			}
			change_variable = { which = china_war_troop_quantity value = -6 }
			change_variable = { which = china_war_target_match_mult value = -0.35 }
			change_variable = { which = china_war_troop_quality value = -1 }
			change_variable = { which = china_war_minimum_commander_martial value = -4 }
		}
		1 = {
			trigger = {
				offmap_china = { has_status = china_golden_age }
			}
			change_variable = { which = china_war_target_match_mult value = 0.65 }
			change_variable = { which = china_war_troop_quality value = 2 }
			change_variable = { which = china_war_minimum_commander_martial value = 5 }
		}
	}
}


#Checks whether the Emperor likes target and shows tooltips (used in event JD.10010)
check_likes_or_dislikes_THIS_effect = {
 	if = {  #If the current Emperor LIKES target
        limit = {
            is_liked_by_China_trigger = yes
        }
        offmap_china = {
			show_scope_change = no
            custom_tooltip = { text = emperor_likes_THIS_tt }
        }
    }

    if = { #If the current Emperor DISLIKES target
        limit = {
           is_disliked_by_China_trigger = yes
        }
        offmap_china = {
			show_scope_change = no
			custom_tooltip = { text = emperor_dislikes_THIS_tt }
        }
    }

    if = { #If the current Emperor LIKES *and* DISLIKES target
        limit = {
            is_liked_and_disliked_by_China = yes
        }
        offmap_china = {
			show_scope_change = no
            custom_tooltip = { text = emperor_has_ambiguous_feelings_of_THIS_tt }
        }
    }
}

print_china_status_update_effect = {
	log = "----------------"
	log = "China Logging:"
	log = "China's status of [This.GetPrevStatus] ended after [global_temp_status_years.GetValue] years."
	log = "China's new status is [This.GetStatus]."
	log = "----------------"
	set_variable = {
		which = global_temp_status_years
		value = 0
	}
	random_list = {
		10 = {
			trigger = {
				has_status = china_stable
			}
			change_variable = {
				which = global_amount_of_times_china_stable
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_unrest
			}
			change_variable = {
				which = global_amount_of_times_china_unrest
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_civil_war
			}
			change_variable = {
				which = global_amount_of_times_china_civil_war
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_mongol_invasion
			}
			change_variable = {
				which = global_amount_of_times_china_mongol_invasion
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_jurchen_invasion
			}
			change_variable = {
				which = global_amount_of_times_china_jurchen_invasion
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_famine
			}
			change_variable = {
				which = global_amount_of_times_china_famine
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_plague
			}
			change_variable = {
				which = global_amount_of_times_china_plague
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_golden_age
				NOT = { has_policy = china_expansionist }
			}
			change_variable = {
				which = global_amount_of_times_china_golden_age
				value = 1
			}
		}
		10 = {
			trigger = {
				has_status = china_golden_age
				has_policy = china_expansionist
			}
			change_variable = {
				which = global_amount_of_times_china_golden_age_expansionist
				value = 1
			}
		}
	}
}

print_china_policy_update_effect = {
	log = "----------------"
	log = "China Logging:"
	log = "China's policy of [This.GetPrevPolicy] ended after [global_temp_policy_years.GetValue] years."
	log = "China's new policy is [This.GetPolicy]."
	log = "----------------"
	set_variable = {
		which = global_temp_policy_years
		value = 0
	}
	random_list = {
		10 = {
			trigger = {
				has_policy = china_open
			}
		}
		10 = {
			trigger = {
				has_policy = china_isolationist
			}
			change_variable = {
				which = global_amount_of_times_china_isolationist_policy
				value = 1
			}
		}
		10 = {
			trigger = {
				has_policy = china_expansionist
			}
			change_variable = {
				which = global_amount_of_times_china_expansionist_policy
				value = 1
			}
		}
	}
}


china_war_modify_variables_by_century_effect = {
	random_list = {
		10 = {
			trigger = {
				year = 700
				NOT = { year = 800 }
			}
		}
		10 = {
			trigger = {
				year = 800
				NOT = { year = 900 }
			}
			change_variable = {
				which = china_war_troop_quantity
				value = 2
			}
		}
		10 = {
			trigger = {
				year = 900
				NOT = { year = 1000 }
			}
			change_variable = {
				which = china_war_troop_quantity
				value = 3
			}
		}
		10 = {
			trigger = {
				year = 1000
				NOT = { year = 1100 }
			}
			change_variable = {
				which = china_war_troop_quantity
				value = 4
			}
		}
		10 = {
			trigger = {
				year = 1100
				NOT = { year = 1200 }
			}
			change_variable = {
				which = china_war_troop_quantity
				value = 5
			}
			change_variable = {
				which = china_war_target_match_mult
				value = 0.05
			}
		}
		10 = {
			trigger = {
				year = 1200
				NOT = { year = 1300 }
			}
			change_variable = {
				which = china_war_troop_quantity
				value = 7
			}
			change_variable = {
				which = china_war_target_match_mult
				value = 0.05
			}
			change_variable = {
				which = china_war_troop_quality
				value = 1
			}
		}
		10 = {
			trigger = {
				year = 1300
			}
			change_variable = {
				which = china_war_troop_quantity
				value = 8
			}
			change_variable = {
				which = china_war_target_match_mult
				value = 0.05
			}
			change_variable = {
				which = china_war_troop_quality
				value = 1
			}
		}
	}
}

print_china_ruler_update_effect = {
	log = "----------------"
	log = "Ruler of China died at the age of [From.GetAgeYears]."
	log = "New Ruler of China is [Root.GetBestName] ([From.GetCulture], From.GetReligion])."
	log = "----------------"
}

# THIS is getting the trait added, the kinslayer_target target is the person dying
# Save the event target before running this effect any time you publicly kill someone, the effect automatically checks they are a relative so you don't need to
# The event target is cleared after the trait is added so re-save the target and re-run the effect to check for another character in the same event
# The traits will overwrite each other kinslayer > familial_kinslayer > dynastic_kinslayer
add_kinslayer_trait_effect = {
	if = { #Parents, children, direct ancestors or descendants 
		limit = {
			NOT = { trait = kinslayer }
			NOT = { religion_group = muslim }
			OR = {
				is_ancestor_of = event_target:kinslayer_target
				is_descendant_of = event_target:kinslayer_target
				sibling = event_target:kinslayer_target
			}
		}
		add_trait = kinslayer
		hidden_effect = {
			character_event = {
				id = 38287 #Notify Kinslayer
			}
		}
	}
	else_if = { #Cousins, aunts/uncles (blood ones only), nieces/nephews
		limit = {
			NOR = { 
				trait = kinslayer
				trait = familial_kinslayer
			}
			NOT = { religion_group = muslim }
			OR = {
				is_cousin_of = event_target:kinslayer_target
				is_aunt_uncle_of = event_target:kinslayer_target
				is_nibling_of = event_target:kinslayer_target
			}
		}
		add_trait = familial_kinslayer
		hidden_effect = {
			character_event = {
				id = 38287 #Notify Kinslayer
			}
		}
	}
	else_if = { #Dynasty members
		limit = { 
			NOR = { 
				trait = kinslayer
				trait = familial_kinslayer
				trait = dynastic_kinslayer
			}
			NOT = { religion_group = muslim }
			is_lowborn = no
			dynasty = event_target:kinslayer_target
		}
		add_trait = dynastic_kinslayer
		hidden_effect = {
			character_event = {
				id = 38287 #Notify Kinslayer
			}
		}
	}
	else = {
	}
	clear_event_target = kinslayer_target
}

set_higher_quality_of_book_flags_effect = {
	if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		clr_character_flag = good_book_potential
	}
	if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = great_book_potential
	}			
	if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		clr_character_flag = decent_book_potential
	}
	if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = great_book_potential
	}
	if = {
		limit = {
			has_character_flag = decent_book_potential
			NOT = { has_character_flag = good_book_potential }
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = good_book_potential
	}
}

set_lower_quality_of_book_flags_effect = {
	if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		clr_character_flag = good_book_potential
	}
	if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			NOT = { has_character_flag = great_book_potential }
		}
		set_character_flag = decent_book_potential
	}
	if = {
		limit = {
			has_character_flag = decent_book_potential
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		clr_character_flag = great_book_potential
	}
	if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			has_character_flag = good_book_potential
			has_character_flag = great_book_potential
		}
		set_character_flag = decent_book_potential
	}
	if = {
		limit = {
			NOT = { has_character_flag = decent_book_potential }
			NOT = { has_character_flag = good_book_potential }
			has_character_flag = great_book_potential
		}
		set_character_flag = good_book_potential
	}
}

send_final_book_outcome_event_effect = {
	#character_event = { id = JD.10070 days = 5 random = 10 } #Testing values...
	character_event = { id = JD.10070 days = 565 random = 3650 }
}

abort_kow_tow_effect = {
	if = {
		limit = {
			NOT = { has_character_flag = kow_tow_hide_abort_notification }
		}
		character_event = { id = JD.32299 }
	}
	clear_delayed_event = { id = JD.32005 }
	clear_delayed_event = { id = JD.32200 }
	clear_delayed_event = { id = JD.32113 }
	clear_delayed_event = { id = JD.32111 }
	clear_delayed_event = { id = JD.32210 }
	clear_delayed_event = { id = JD.32290 }
	clr_character_flag = went_on_kow_tow_pilgrimage
	clean_up_after_kow_tow_effect = yes
}

return_to_travel_tombola_effect = {
	hidden_effect = {
		event_target:kow_tow_traveler = {
			subtract_variable = {
				which = china_kow_tow_travel_events
				value = 1
			}
			character_event = {
				id = JD.32005
				days = 90
				random = 60
			}
		}
	}
}

return_to_china_tombola_effect = {
	hidden_effect = {
		event_target:kow_tow_traveler = {
			subtract_variable = {
				which = china_kow_tow_travel_events
				value = 1
			}
			character_event = {
				id = JD.32210
				days = 70
				random = 30
			}
		}
	}
}

clean_up_after_kow_tow_effect = {
	remove_trait = kow_tow_travels
	clr_character_flag = do_not_disturb
	
	clr_character_flag = read_the_guanzi
	clr_character_flag = missed_loved_one
	clr_character_flag = met_mercenaries
	clr_character_flag = met_traveling_merchant
	clr_character_flag = visited_market
	clr_character_flag = kow_tow_invited_by_local_lord
	clr_character_flag = kow_tow_heavy_rain
	clr_character_flag = kow_tow_played_go
	clr_character_flag = kow_tow_hide_abort_notification
	clr_character_flag = kow_tow_visited_temple
}

add_chinese_artifact_effect = { #Used in event JD.15016 (possible to use elsewhere!)
	hidden_effect = {
		random_list = {
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_artwork } } }
				add_artifact = chinese_artwork
				new_artifact = {
					set_name = chinese_artwork_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_calligraphy } } }
				add_artifact = chinese_calligraphy
				new_artifact = {
					set_name = chinese_calligraphy_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_sculpture } } }
				add_artifact = chinese_sculpture
				new_artifact = {
					set_name = chinese_sculpture_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_ceremonial_robes } } }
				add_artifact = chinese_ceremonial_robes
			}
			10 = {
				offmap_china = {
					offmap_prev_ruler = {
						save_event_target_as = prev_emperor
					}
				}
				add_artifact = chinese_prev_emperor_sculpture
				new_artifact = {
					set_name = chinese_figurine_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_arm_protector } } }
				add_artifact = chinese_arm_protector
				new_artifact = {
					set_name = chinese_arm_protector_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_serpent_spear } } }
				add_artifact = chinese_serpent_spear
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_ji } } }
				add_artifact = chinese_ji
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_crossbow } } }
				add_artifact = chinese_crossbow
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_bronze_sculpture } } }
				add_artifact = chinese_bronze_sculpture
				new_artifact = {
					set_name = chinese_bronze_sculpture_name 
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_book_health } } }
				add_artifact = chinese_book_health
				new_artifact = {
					set_name = chinese_book_health_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_book_law } } }
				add_artifact = chinese_book_law
				new_artifact = {
					set_name = chinese_book_law_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_book_history } } }
				add_artifact = chinese_book_history
				new_artifact = {
					set_name = chinese_book_history_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_book_economy } } }
				add_artifact = chinese_book_economy
				new_artifact = {
					set_name = chinese_book_economy_name
				}
			}
			1 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_painting_of_glitterhoof } } }
				add_artifact = chinese_painting_of_glitterhoof
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_tapestry } } }
				random_independent_ruler = {
					limit = {
						any_realm_province = {
							trade_route = silk_road
						}
					}
					random_realm_province = {
						limit = {
							trade_route = silk_road
						}
						save_event_target_as = tapestry_target
					}
				}
				add_artifact = chinese_tapestry
				new_artifact = {
					set_name = chinese_tapestry_name
				}
			}
			10 = {
				trigger = { ROOT = { NOT = { has_artifact = chinese_tapestry_grand } } }
				add_artifact = chinese_tapestry_grand
				new_artifact = {
					set_name = chinese_tapestry_grand_name
				}
				trigger = { ROOT = { NOT = { has_artifact = chinese_tapestry_grand } } }
			}
		}
		new_artifact = {
			save_event_target_as = chinese_artifact
		}
	}
}
