@default_tile_multiplier = 0.009702

smallpox = {
	trait = smallpox
	color = { 88 12 31 }
	priority = 3

	shader_data = {
		strength = 0.8
		edge_fade = 0.25
		tile_multiplier = 0.004702
		texture_index = 0
		channel = alpha
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:3045
				}
				desc = epidemic_bonifacy_gift
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:7596
				}
				desc = epidemic_raqguul_plague
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							geographical_region = ghw_region_egypt
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_eleventh_plague
				}
				desc = epidemic_rulers_pox
				desc = epidemic_titled_rulers_pox
				desc = epidemic_animal_pox # Monkeypox, chickenpox and the like
				desc = epidemic_realm_pox
				desc = epidemic_holder_pox
				desc = epidemic_culture_pox
				desc = epidemic_location_pox
			}
			desc = trait_smallpox
		}
	}
	
	on_start = {
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_smallpox_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_smallpox_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_smallpox_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_smallpox_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_smallpox_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_smallpox_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_smallpox_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_smallpox_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_smallpox_minor
		#			add = 1
		#		}
		#	}
		#}
	}

	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}

	character_infection_chance = {
		value = character_infection_chance_default_value
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = smallpox }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = smallpox }
		if = {
			limit = {
				is_commanding_army = yes
			}
			trigger_event = epidemic_events.0001 #we infect your army
		}
	}

	infection_levels = {
		10 = {
			province_modifier = {
				county_opinion_add = -2
				epidemic_travel_danger = 10
				development_decline = -1
			}	
		}
		50 = {
			province_modifier = {
				county_opinion_add = -3
				epidemic_travel_danger = 20
				development_decline = -2
			}	
		}
		80 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.1
				supply_limit_mult = -0.2
				county_opinion_add = -5
				epidemic_travel_danger = 30
				development_decline = -3
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_minor_default_value
				multiply = outbreak_chance_minor_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 2
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 30 55 }

			infection_duration = {
				months = { 6 8 }
			}

			infection_progress_duration = {
				days = { 80 120 }
			}

			infection_recovery_duration = {
				days = { 15 22 }
			}
		}

		major = {
			outbreak_chance = {
				value = outbreak_chance_major_default_value
				multiply = outbreak_chance_major_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 1.5
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 85 130 }

			infection_duration = {
				months = { 10 20 }
			}

			infection_progress_duration = {
				days = { 40 60 }
			}

			infection_recovery_duration = {
				days = 25
			}
		}

		apocalyptic = {
			outbreak_chance = {
				value = outbreak_chance_apocalyptic_default_value
				multiply = outbreak_chance_apocalyptic_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 1.25
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 220 325 }

			infection_duration = {
				months = { 22 40 }
			}
			
			infection_progress_duration = {
				days = { 15 20 }
			}

			infection_recovery_duration = {
				days = { 25 35 }
			}
		}
	}
	
	on_province_infected = {
		county = {
			apply_infection_development_loss = { BASE = 5 }
		}
		cant_touch_this_achievement_effect = yes
	}
	
	on_province_recovered = {
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}

bubonic_plague = {
	trait = bubonic_plague
	color = black
	priority = 5

	shader_data = {
		strength = 0.8
		edge_fade = 0.4
		tile_multiplier = 0.005
		texture_index = 0
		channel = red
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_province = province:1580
					outbreak_intensity = apocalyptic
				}
				desc = epidemic_mitcheldean_malaise
			}
			triggered_desc = {
				trigger = {
					outbreak_province = province:8748
					outbreak_intensity = apocalyptic
				}
				desc = epidemic_green_death
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
				}
				desc = epidemic_black_death
			}
			triggered_desc = {
				trigger = {
					has_ep3_dlc_trigger = yes 
					outbreak_province.county.holder = {
						is_roman_emperor_primary_title_excluding_byzantium_trigger = yes
						any_owned_story = { type = ep3_story_cycle_restoring_rome }
					}
				}
				desc = epidemic_ruler_plague
			}
			triggered_desc = {
				trigger = {
					OR = {
						outbreak_province.county.faith = faith:catholic
						outbreak_province.county.faith = faith:orthodox
						outbreak_province.county.faith = faith:nestorian
						outbreak_province.county.faith = faith:coptic
						outbreak_province.county.faith = faith:armenian_apostolic
						outbreak_province.county.faith = faith:insular_celtic
					}
				}
				desc = epidemic_random_saint_plague
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = major
				}
				desc = epidemic_reapers_will
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = major
				}
				desc = epidemic_reapers_due
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = major
				}
				desc = epidemic_wicked_blight
			}
			random_valid = {
				desc = epidemic_realm_plague
				desc = epidemic_culture_plague
				desc = epidemic_location_plague
				desc = epidemic_ruler_plague
				desc = epidemic_titled_ruler_plague
				desc = epidemic_evil_god_plague
				desc = epidemic_bubonic_plague
			}
		}
	}
	
	on_start = {
		if = {
			limit = {
				outbreak_intensity = apocalyptic
			}

			set_global_variable = black_death_happened

			set_global_variable = {
				name = black_death
				value = root
			}
		}
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_bubonic_plague_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_bubonic_plague_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_bubonic_plague_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_bubonic_plague_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_bubonic_plague_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_bubonic_plague_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_bubonic_plague_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_bubonic_plague_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_bubonic_plague_minor
		#			add = 1
		#		}
		#	}
		#}
	}

	on_end = {
		if = {
			limit = {
				outbreak_intensity = apocalyptic
			}
			remove_global_variable = black_death
		}
	}
	
	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}

	character_infection_chance = {
		value = character_infection_chance_default_value
		multiply = 0.02 #The only way we can make it not kill every single character in the game
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = bubonic_plague }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = bubonic_plague }
	}

	infection_levels = {
		10 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.6
				development_decline = -3
				levy_reinforcement_rate = -0.3
				levy_size = -0.25
				supply_limit_mult = -0.2
				county_opinion_add = -10
				epidemic_travel_danger = 25
			}	
		}
		50 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.8
				development_decline = -6
				levy_reinforcement_rate = -0.5
				levy_size = -0.4
				supply_limit_mult = -0.5
				county_opinion_add = -25
				epidemic_travel_danger = 40
			}	
		}
		80 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.8
				development_decline = -8
				levy_reinforcement_rate = -1
				levy_size = -0.5
				supply_limit_mult = -1
				county_opinion_add = -25
				epidemic_travel_danger = 60
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_minor_default_value
				multiply = outbreak_chance_minor_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.0005 #should almost never be minor
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 180 360 }

			infection_duration = {
				months = { 6 12 }
			}

			infection_progress_duration = {
				days = { 40 60 }
			}

			infection_recovery_duration = {
				days = { 25 35 }
			}
		}

		major = {
			outbreak_chance = {
				value = outbreak_chance_major_default_value
				multiply = outbreak_chance_major_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.005 #should almost never be major
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}

			max_provinces = { 540 900 }

			infection_duration = {
				months = { 12 24 }
			}

			infection_progress_duration = {
				days = { 25 35 }
			}

			infection_recovery_duration = {
				days = { 50 70 }
			}
		}

		apocalyptic = { #The Black Death
			# We trigger the event specially for Black Death
			notification = {
				global = yes
				holder_event = ""
				liege_event = ""
				realm_event = ""
			}
			
			outbreak_chance = {
				value = {
					value = outbreak_chance_black_plague_default_value
					multiply = outbreak_chance_black_plague_mult_value
					multiply = recent_epidemics_outbreak_mult_value
				}
				if = {
					limit = {
						current_date >= 1346.1.1
						has_game_rule = bd_occurrence_historical
						NOT = {
							has_global_variable = black_death_happened
						}
						geographical_region = world_central_asia
					}
					add = 100
				}

				if = {
					limit = {
						# Currently happening
						has_global_variable = black_death
					}
					value = 0
				}
				if = {
					limit = { #it can only happen once per game
						has_global_variable = black_death_happened
						has_game_rule = bd_frequency_once
					}
					value = 0
				}
				if = {
					limit = { #it can never happen
						has_game_rule = bd_frequency_never
					}
					value = 0
				}

				#Historical exemption
				if = {
					limit = {
						has_game_rule = bd_occurrence_historical
						OR = {
							current_date < 1346.1.1
							NOT = {
								geographical_region = world_central_asia
							}
						}
					}
					value = 0
				}
				multiply = 0.1

			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value

				#Exclusions for historical Milan and Poland, husariaaaa
				if = {
					limit = {
						has_game_rule = bd_occurrence_historical
						OR = {
							geographical_region = ghw_region_poland
							geographical_region = custom_polabia
							geographical_region = world_tibet
							county.duchy = title:d_lombardia
							county.duchy = title:d_aragon
							county.duchy = title:d_armagnac
							county.duchy = title:d_bohemia
						}
					}
					multiply = 0.02
				}				
			}
			max_provinces = { 12000 13100 }

			infection_duration = {
				months = { 24 48 }
			}
			
			infection_progress_duration = {
				days = { 5 9 }
			}

			infection_recovery_duration = {
				days = { 80 120 }
			}
		}
	}
	
	on_province_infected = {
		county = {
			apply_infection_development_loss = { BASE = 10 }
		}
		every_player = {
			if = {
				limit = {
					NOR = {
						any_owned_story = {
							type = story_cycle_black_death
						}
						has_character_flag = black_death_splash #black plague is in your realm
					}
				}
				create_story = story_cycle_black_death
				trigger_event = { #time-based fallback to notify the players that the black death is here.
					id = epidemic_events.5999
					years = { 4 6 } #Average time for Black Death to move from Siberia to Europe
				}
			}
		}
		every_player = {
			if = {
				limit = {
					has_dlc_feature = legends_of_the_dead
					is_landless_ruler = yes
					location = {
						any_province_epidemic = {
							intensity = apocalyptic
							epidemic_type.epidemic_trait = trait:bubonic_plague
						}
					}
				}
				trigger_event = epidemic_events.6000
			}
		}
		cant_touch_this_achievement_effect = yes
	}
	
	on_province_recovered = {
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15 
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}

typhus = {
	trait = typhus
	color = { 37 90 57 }
	priority = 4

	shader_data = {
		strength = 0.6
		edge_fade = 0.25
		tile_multiplier = 0.01
		texture_index = 1
		channel = red
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:4921
				}
				desc = epidemic_bydgoszczanka
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:3199
				}
				desc = epidemic_torunianka
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:1527
				}
				desc = epidemic_penge_plague
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_rulers_fever
				}
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_titled_rulers_fever
				}
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_realm_fever
				}
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_devils_fever
				}
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							geographical_region = ghw_region_egypt
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_eleventh_plague
				}
				triggered_desc = {
					trigger = {
						NOT = {
							outbreak_province = {
								terrain = jungle # Yeah, no, we're not calling it that
							}
						}
					}
					desc = epidemic_terrain_fever
				}
				desc = epidemic_camp_fever
				desc = epidemic_province_fever
				desc = epidemic_province_sweats
				desc = epidemic_culture_sweats
				desc = epidemic_famine_fever
				desc = epidemic_spotted_fever
			}
			desc = trait_typhus
		}
	}
	
	on_start = {
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_typhus_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_typhus_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_typhus_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_typhus_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_typhus_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_typhus_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_typhus_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_typhus_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_typhus_minor
		#			add = 1
		#		}
		#	}
		#}
	}
	
	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}
	
	character_infection_chance = {
		value = character_infection_chance_default_value
		if = {
			limit = {
				is_commanding_army = yes
			}
			multiply = 4
		}
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = typhus }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = typhus }
	}

	infection_levels = {
		10 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.3
				development_decline = -1
				levy_reinforcement_rate = -0.2
				county_opinion_add = -2
				epidemic_travel_danger = 20
			}	
		}
		50 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.4
				development_decline = -2
				levy_reinforcement_rate = -0.2
				garrison_size = -0.1
				county_opinion_add = -3
				epidemic_travel_danger = 30
			}	
		}
		80 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.5
				development_decline = -3
				levy_reinforcement_rate = -0.2
				garrison_size = -0.2
				county_opinion_add = -5
				epidemic_travel_danger = 40
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_minor_default_value
				multiply = outbreak_chance_minor_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 2
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 30 55 }

			infection_duration = {
				months = { 6 12 }
			}

			infection_progress_duration = {
				days = 100
			}

			infection_recovery_duration = {
				days = 30
			}
		}

		major = {
			outbreak_chance = {
				value = outbreak_chance_major_default_value
				multiply = outbreak_chance_major_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.75
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 1.5
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 75 90 }

			infection_duration = {
				months = { 12 24 }
			}

			infection_progress_duration = {
				days = { 45 55 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}

		apocalyptic = {
			outbreak_chance = {
				value = outbreak_chance_apocalyptic_default_value
				multiply = outbreak_chance_apocalyptic_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.5
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 1.25
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 145 220 }

			infection_duration = {
				months = { 24 48 }
			}
			
			infection_progress_duration = {
				days = { 15 22 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}
	}
	
	on_province_infected = {
		county = {
			apply_infection_development_loss = { BASE = 5 }
		}
		cant_touch_this_achievement_effect = yes
	}
	
	on_province_recovered = {
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15 
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}

consumption = { #Tuberculosis
	trait = consumption
	color = { 84 171 176 }
	priority = 1

	shader_data = {
		strength = 0.35
		edge_fade = 0.28
		tile_multiplier = 0.00538
		texture_index = 0
		channel = green
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:527
				}
				desc = epidemic_napolna_zaraza
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:369
				}
				desc = epidemic_gannholm_grievance
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
						outbreak_province = {
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_curse_of_canaan # Named for a section in the Old Testament
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							geographical_region = world_india
						}
					}
					desc = epidemic_yaksma
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							county.culture = {
								OR = {
									has_cultural_pillar = heritage_chinese
									has_cultural_pillar = language_chinese
								}
							}
						}
					}
					desc = epidemic_shizhai
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							county.faith.religion = {
								is_in_family = rf_pagan
								NOT = { this = religion:north_african_religion } # Canary islanders believed dogs were sacred
							}
						}
					}
					desc = epidemic_demon_dog_disease
				}
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_titles_evil #King's evil
				}
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							geographical_region = ghw_region_egypt
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_eleventh_plague
				}
				desc = epidemic_cold_humor
				desc = epidemic_cold_humor
				desc = epidemic_white_plague
				desc = epidemic_realm_flu
				desc = epidemic_realm_coughs
				desc = epidemic_ruler_flu
				desc = epidemic_ruler_coughs
				desc = epidemic_titled_ruler_flu
				desc = epidemic_romantic_plague
				desc = epidemic_holder_flu
				desc = epidemic_holder_coughs
			}
			desc = trait_consumption
		}
	}
	
	on_start = {
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_consumption_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_consumption_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_consumption_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_consumption_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_consumption_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_consumption_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_consumption_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_consumption_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_consumption_minor
		#			add = 1
		#		}
		#	}
		#}
	}

	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}

	character_infection_chance = {
		value = character_infection_chance_default_value
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = consumption }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = consumption }
	}

	infection_levels = {
		10 = {
			province_modifier = {
				development_decline = -2
				epidemic_travel_danger = 20
			}
		}
		50 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.05
				development_decline = -3
				county_opinion_add = -2
				epidemic_travel_danger = 40
			}	
		}
		80 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.1
				development_decline = -4
				county_opinion_add = -3
				epidemic_travel_danger = 60
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_minor_default_value

				#Are you in the consumption zone?
				if = {
					limit = {
						geographical_region = world_atlantic
					}
					add = outbreak_increase_add_low
				}

				#Endemism
				if = {
					limit = { has_variable = consumption_endemic_variable }
					add = outbreak_increase_add_high
				}
				
				multiply = outbreak_chance_minor_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 2
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
				multiply = recent_epidemics_outbreak_mult_value
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 30 55 }

			infection_duration = {
				months = { 12 18 } #stays around for a long time
			}

			infection_progress_duration = {
				days = { 80 100 }
			}

			infection_recovery_duration = {
				days = { 30 60 } #stays around for a long time
			}
		}

		major = {
			outbreak_chance = {
				value = outbreak_chance_major_default_value

				#Are you in the consumption zone?
				if = {
					limit = {
						geographical_region = world_atlantic
					}
					add = outbreak_increase_add_medium
				}

				#Endemism
				if = {
					limit = { has_variable = consumption_endemic_variable }
					add = outbreak_increase_add_low
				}
				
				multiply = outbreak_chance_major_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 1.5
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
				multiply = recent_epidemics_outbreak_mult_value
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 75 90 }

			infection_duration = {
				months = { 20 25 }
			}

			infection_progress_duration = {
				days = { 40 60 }
			}

			infection_recovery_duration = {
				days = { 60 80 }
			}
		}

		apocalyptic = {
			outbreak_chance = {
				value = outbreak_chance_apocalyptic_default_value

				#Endemism
				if = {
					limit = { has_variable = consumption_endemic_variable }
					add = outbreak_increase_add_low
				}

				#Are you in the consumption zone?
				if = {
					limit = {
						geographical_region = world_atlantic
					}
					add = outbreak_increase_add_low
				}
				
				multiply = outbreak_chance_apocalyptic_mult_value
				
				### NO DLC - We increase the chance to make up for the locked diseases ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					multiply = 2
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
				multiply = recent_epidemics_outbreak_mult_value
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 145 220 }

			infection_duration = {
				months = { 30 45 }
			}
			
			infection_progress_duration = {
				days = { 15 30 }
			}

			infection_recovery_duration = {
				days = { 80 100 }
			}
		}
	}
	
	on_province_infected = {
		county = {
			apply_infection_development_loss = { BASE = 7 }
		}
		cant_touch_this_achievement_effect = yes
	}
	
	on_province_recovered = {
		random = { #Endemism
			chance = 10
			set_variable = {
				name = consumption_endemic_variable
				years = 2
			}
		}
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50 #can come back quite fast
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}

measles = {
	trait = measles
	color = { 201 111 112 }
	priority = 2

	shader_data = {
		strength = 0.4
		edge_fade = 0.3
		tile_multiplier = 0.006
		texture_index = 0
		channel = blue
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_province = province:1626
					outbreak_intensity = apocalyptic
				}
				desc = epidemic_cooties
			}
			triggered_desc = {
				trigger = {
					outbreak_province = province:1787
					outbreak_intensity = apocalyptic
					outbreak_province.county.faith = { religion_tag = christianity_religion }
				}
				desc = epidemic_saint_veronica_evil
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_little_leprosy
				}
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_evil_god_pestilence
				}
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_titles_evil #King's evil
				}
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							geographical_region = ghw_region_egypt
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_eleventh_plague
				}
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							duchy = title:d_york
						}
					}
					desc = epidemic_crimson_horror
				}
				desc = epidemic_realm_boils
				desc = epidemic_rulers_boils
				desc = epidemic_titled_rulers_boils
				desc = epidemic_holder_boils
				desc = epidemic_culture_boils
				desc = epidemic_location_boils
			}
			desc = trait_measles
		}
	}
	
	on_start = {
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_measles_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_measles_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_measles_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_measles_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_measles_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_measles_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_measles_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_measles_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_measles_minor
		#			add = 1
		#		}
		#	}
		#}
	}

	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}

	character_infection_chance = {
		value = character_infection_chance_default_value
		multiply = 5 #highly infectious
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = measles }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = measles }
	}

	infection_levels = {
		10 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.1
				epidemic_travel_danger = 5
			}	
		}
		50 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.2
				development_decline = -0.25
				county_opinion_add = -2
				epidemic_travel_danger = 15
			}	
		}
		80 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.4
				development_decline = -0.5
				county_opinion_add = -5
				epidemic_travel_danger = 30
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_minor_default_value

				#Endemism
				if = {
					limit = { has_variable = measles_endemic_variable }
					add = outbreak_increase_add_high
				}
				
				multiply = outbreak_chance_minor_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				#Measles should be pretty common
				multiply = 1.25
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 55 75 }

			infection_duration = {
				months = { 3 6 }
			}

			infection_progress_duration = {
				days = { 20 40 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}

		major = {
			outbreak_chance = {
				value = outbreak_chance_major_default_value
				
				#Endemism
				if = {
					limit = { has_variable = measles_endemic_variable }
					add = outbreak_increase_add_medium
				}
				else = {
					multiply = 0.5
				}
				
				multiply = outbreak_chance_major_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 130 180 }

			infection_duration = {
				months = { 6 12 }
			}

			infection_progress_duration = {
				days = { 15 20 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}

		apocalyptic = {
			outbreak_chance = {
				value = outbreak_chance_apocalyptic_default_value

				#Endemism
				if = {
					limit = { has_variable = measles_endemic_variable }
					add = outbreak_increase_add_low
				}
				else = {
					multiply = 0.25
				}
				
				multiply = outbreak_chance_apocalyptic_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 270 405 }

			infection_duration = {
				months = { 12 24 }
			}
			
			infection_progress_duration = {
				days = { 7 14 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}
	}
	
	on_province_infected = {
		county = {
			apply_infection_development_loss = { BASE = 5 }
		}
		cant_touch_this_achievement_effect = yes
	}
	
	on_province_recovered = {
		random = {
			chance = 10
			set_variable = {
				name = measles_endemic_variable
				years = 2
			}
		}
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15 
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}

dysentery = {
	trait = dysentery
	color = { 102 0 0 }
	priority = 3

	shader_data = {
		strength = 0.7
		edge_fade = 0.25
		tile_multiplier = 0.01
		texture_index = 1
		channel = green
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					OR = {
						outbreak_province = province:2833
						outbreak_province = province:2830
					}
				}
				desc = epidemic_twin_cods_revenge
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:6253
				}
				desc = epidemic_ligma
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						OR = {
							outbreak_intensity = apocalyptic
							outbreak_intensity = major
						}
					}
					desc = epidemic_evil_god_flux
				}
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							geographical_region = ghw_region_egypt
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_eleventh_plague
				}
				desc = epidemic_realm_flux
				desc = epidemic_ruler_flux
				desc = epidemic_titled_ruler_flux
				desc = epidemic_holder_flux
				desc = epidemic_culture_flux
				desc = epidemic_terrain_flux
				desc = epidemic_location_flux
			}
			desc = trait_dysentery
		}
	}
	
	on_start = {
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_dysentery_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_dysentery_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_dysentery_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_dysentery_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_dysentery_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_dysentery_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_dysentery_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_dysentery_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_dysentery_minor
		#			add = 1
		#		}
		#	}
		#}
	}

	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}

	character_infection_chance = {
		value = character_infection_chance_default_value
		multiply = 3.5 #highly infectious
		if = {
			limit = {
				is_commanding_army = yes
			}
			multiply = 2
		}
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = dysentery }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = dysentery }
	}

	infection_levels = {
		10 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.15
				county_opinion_add = -2
				epidemic_travel_danger = 10
				development_decline = -1.5
			}	
		}
		50 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.3
				development_decline = -2.5
				supply_limit_mult = -0.1
				county_opinion_add = -3
				epidemic_travel_danger = 20
			}	
		}
		80 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.5
				development_decline = -4
				supply_limit_mult = -0.2
				county_opinion_add = -5
				epidemic_travel_danger = 30
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_dysentery_default_value #special values for armies here
				multiply = outbreak_chance_minor_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {  
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}

			max_provinces = { 20 30 }
			
			infection_duration = {
				months = { 2 4 }
			}

			infection_progress_duration = {
				days = { 15 20 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}

		major = {
			outbreak_chance = {
				value = outbreak_chance_dysentery_default_value #special values for armies here
				multiply = outbreak_chance_major_mult_value
				multiply = recent_epidemics_outbreak_mult_value 
				multiply = 0.25
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {  
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 40 55 }

			infection_duration = {
				months = { 8 16 }
			}

			infection_progress_duration = {
				days = { 18 22 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}

		apocalyptic = {
			outbreak_chance = {
				value = outbreak_chance_dysentery_default_value #special values for armies here
				multiply = outbreak_chance_apocalyptic_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.15
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {  
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
			}
			max_provinces = { 90 270 }

			infection_duration = {
				months = { 16 32 }
			}
			
			infection_progress_duration = {
				days = { 10 15 }
			}

			infection_recovery_duration = {
				days = { 28 32 }
			}
		}
	}
	
	on_province_infected = {
		county = {
			apply_infection_development_loss = { BASE = 3 }
		}
		cant_touch_this_achievement_effect = yes
	}
	
	on_province_recovered = {
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15 
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}

ergotism = { #dancing plague - not contagious
	trait = ergotism
	color = { 255 95 31 }
	priority = 2

	shader_data = {
		strength = 0.5
		edge_fade = 0.25
		tile_multiplier = 0.005
		texture_index = 1
		channel = alpha
	}

	name = {
		first_valid = {
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
					outbreak_province = province:2830
				}
				desc = epidemic_saturday_night_fever
			}
			triggered_desc = {
				trigger = {
					outbreak_intensity = apocalyptic
				}
				desc = epidemic_dance_of_death
			}
			random_valid = {
				triggered_desc = {
					trigger = {
						outbreak_province = {
							OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
						}
					}
					desc = epidemic_saint_anthonys_fire
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							OR = { faith.religion = religion:eastern_orthodox_religion faith.religion = religion:catholic_religion faith.religion = religion:protestant_religion }
						}
					}
					desc = epidemic_saint_anthonys_fire
				}
				triggered_desc = {
					trigger = {
						outbreak_intensity = apocalyptic
						outbreak_province = {
							geographical_region = ghw_region_egypt
							county.faith.religion = { is_in_family = rf_abrahamic }
						}
					}
					desc = epidemic_eleventh_plague
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							county = { development_level <= 5 }
						}
					}
					desc = epidemic_realm_dancing_plague
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							county = { development_level <= 5 }
						}
					}
					desc = epidemic_culture_dancing_plague
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							county = { development_level <= 5 }
						}
					}
					desc = epidemic_location_dancing_plague
				}
				triggered_desc = {
					trigger = {
						outbreak_province = {
							county = {
								OR = {
									faith = faith:catholic
									faith = faith:orthodox
									faith = faith:nestorian
									faith = faith:coptic
									faith = faith:armenian_apostolic
									faith = faith:insular_celtic
								}
							}
						}
					}
					desc = epidemic_random_saint_fire
				}
				desc = epidemic_realm_fire
				desc = epidemic_culture_fire
				desc = epidemic_location_fire
				desc = epidemic_ruler_fire
				desc = epidemic_holder_fire
				desc = epidemic_evil_god_fire
			}
		}
	}
	
	on_start = {
		# LEGITIMACY LOSS FROM EPIDEMIC OUTBREAK
		epidemic_outbreak_legitimacy_effect = { PROVINCE = root.outbreak_province }
		#if = {
		#	limit = {
		#		outbreak_intensity = apocalyptic
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_ergotism_apocalyptic
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_ergotism_apocalyptic
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_ergotism_apocalyptic
		#			add = 1
		#		}
		#	}
		#}
		#else_if = {
		#	limit = {
		#		outbreak_intensity = major
		#	}
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_ergotism_major
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_ergotism_major
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_ergotism_major
		#			add = 1
		#		}
		#	}
		#}
		#else = {
		#	if = {
		#		limit = {
		#			NOT = {
		#				exists = global_var:epidemic_ergotism_minor
		#			}
		#		}
		#		set_global_variable = {
		#			name = epidemic_ergotism_minor
		#			value = 1
		#		}
		#	}
		#	else = {
		#		change_global_variable = {
		#			name = epidemic_ergotism_minor
		#			add = 1
		#		}
		#	}
		#}
	}
	
	on_monthly = {
		trigger_event = {
			on_action = epidemic_ongoing_events
		}
	}

	character_infection_chance = {
		value = character_infection_chance_default_value
	}

	can_infect_character = {
		can_contract_disease_trigger = { DISEASE = ergotism }
		immune_to_epidemic = { EPIDEMIC = scope:epidemic }
	}

	on_character_infected = {
		contract_disease_notify_effect = { DISEASE = ergotism }
	}

	infection_levels = {
		10 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.1
				holding_build_speed = 0.5 #this is negative
				stationed_maa_toughness_mult = -0.1
				supply_limit_mult = -0.1 #food related
				epidemic_travel_danger = 5
			}	
		}
		50 = {
			province_modifier = {
				monthly_county_control_decline_add = -0.15
				holding_build_speed = 0.75
				stationed_maa_toughness_mult = -0.2
				supply_limit_mult = -0.2
				epidemic_travel_danger = 10
			}	
		}
		80 = {
			province_modifier = {
				development_decline = -0.5
				monthly_county_control_decline_add = -0.15
				holding_build_speed = 1
				stationed_maa_toughness_mult = -1
				supply_limit_mult = -0.3
				epidemic_travel_danger = 15
			}
		}
	}

	outbreak_intensities = {
		minor = {
			outbreak_chance = {
				value = outbreak_chance_minor_default_value
				multiply = outbreak_chance_minor_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.5 #shouldn't happen often
				if = { #Recent epidemics
					limit = {
						is_target_in_variable_list = {
							name = epidemic_cooldown
							target = epidemic_type:ergotism
						}
					}
					value = 0
				}
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
				if = {
					limit = {
						is_target_in_variable_list = {
							name = epidemic_cooldown
							target = scope:epidemic.epidemic_type
						}
					}
					value = 0
				}
			}

			max_provinces = { 20 30 }

			infection_duration = {
				months = { 6 12 }
			}

			infection_progress_duration = {
				days = { 20 40 }
			}

			infection_recovery_duration = {
				days = { 12 20 }
			}
		}
		major = { 
			outbreak_chance = {
				value = outbreak_chance_major_default_value
				multiply = outbreak_chance_major_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.2 #shouldn't happen often
				if = { #Recent epidemics
					limit = {
						is_target_in_variable_list = {
							name = epidemic_cooldown
							target = epidemic_type:ergotism
						}
					}
					value = 0
				}
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
				if = {
					limit = {
						is_target_in_variable_list = {
							name = epidemic_cooldown
							target = scope:epidemic.epidemic_type
						}
					}
					value = 0
				}
			}

			max_provinces = { 45 65 }

			infection_duration = {
				months = { 12 18 }
			}

			infection_progress_duration = {
				days = { 20 40 }
			}

			infection_recovery_duration = {
				days = { 12 20 }
			}
		}
		apocalyptic = { 
			outbreak_chance = {
				value = outbreak_chance_apocalyptic_default_value
				multiply = outbreak_chance_apocalyptic_mult_value
				multiply = recent_epidemics_outbreak_mult_value
				multiply = 0.1 #shouldn't happen often
				if = { #Recent epidemics
					limit = {
						is_target_in_variable_list = {
							name = epidemic_cooldown
							target = epidemic_type:ergotism
						}
					}
					value = 0
				}
				
				### DLC LOCKING ###
				if = {
					limit = {
						NOT = { has_dlc_feature = legends_of_the_dead }
					}
					value = 0
				}
				if = {
					limit = {
						has_game_rule = epidemic_frequency_disabled
					}
					multiply = 0
				}
			}
			spread_chance = {
				value = spread_chance_epidemics_default_value
				multiply = spread_chance_epidemics_mult_value
				if = {
					limit = {
						is_target_in_variable_list = {
							name = epidemic_cooldown
							target = scope:epidemic.epidemic_type
						}
					}
					value = 0
				}
			}

			max_provinces = { 85 90 }

			infection_duration = {
				months = { 24 30 }
			}

			infection_progress_duration = {
				days = { 20 40 }
			}

			infection_recovery_duration = {
				days = { 12 20 }
			}
		}
	}
	
	on_province_recovered = {
		county = {
			remove_isolated_capital_modifiers_effect = yes
		}
		add_to_variable_list = {
			name = epidemic_cooldown
			target = scope:epidemic.epidemic_type
			years = 50
		}
		set_variable = {
			name = epidemic_cooldown_general
			years = 15
		}
		# Prosperity event
		plague_recovery_event_effect = yes
	}
}
