######################
# Epidemics
######################

#### OUTBREAK CHANCE ###
# Chance for an outbreak of this intensity to spawn on a province per year
# % from 0-100 inclusive
# root = potential province

### CONTROL VALUES ###
# These should be enough to change the balance of epidemics 

# Outbreak

outbreak_chance_base_extra_low = 0.0005
outbreak_chance_base_very_low = 0.001
outbreak_chance_base_low = 0.01
outbreak_chance_base_medium = 0.02
outbreak_chance_base_high = 0.04
outbreak_chance_base_very_high = 0.12

outbreak_increase_add_low = 0.004
outbreak_increase_add_medium = 0.008
outbreak_increase_add_high = 0.016
outbreak_increase_add_very_high = 0.032
outbreak_increase_add_extra_high = 0.064

outbreak_decrease_add_low = -0.003
outbreak_decrease_add_medium = -0.008
outbreak_decrease_add_high = -0.016
outbreak_decrease_add_very_high = -0.032
outbreak_decrease_add_unlikely = -0.064

outbreak_increase_mult_low = 0.1
outbreak_increase_mult_medium = 0.2
outbreak_increase_mult_high = 0.4
outbreak_increase_mult_very_high = 0.8

outbreak_decrease_mult_low = -0.2
outbreak_decrease_mult_medium = -0.35
outbreak_decrease_mult_high = -0.6
outbreak_decrease_mult_very_high = -0.8
outbreak_decrease_mult_unlikely = -0.995

# Spread

spread_chance_base_low = 3.5
spread_chance_base_medium = 5
spread_chance_base_high = 9 

spread_increase_add_low = 2
spread_increase_add_medium = 3
spread_increase_add_high = 4

spread_decrease_add_low = -0.5
spread_decrease_add_medium = -1
spread_decrease_add_high = -2
spread_decrease_add_very_high = -3

spread_increase_mult_low = 0.25
spread_increase_mult_medium = 0.75
spread_increase_mult_high = 1
spread_increase_mult_very_high = 1.5

spread_decrease_mult_low = -0.25
spread_decrease_mult_medium = -0.5
spread_decrease_mult_high = -0.75
spread_decrease_mult_unlikely = -0.991


outbreak_chance_minor_default_value = {
	value = outbreak_chance_base_low
	#Buildings
	if = {
		limit = {
			num_buildings >= 4
		}
		add = {
			value = num_buildings
			multiply = outbreak_increase_add_low
		}
	}

	#Tradeports
	if = {
		limit = {
			has_building_or_higher = common_tradeport_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_02
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_03
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_04
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_05
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_06
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_07
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_08
		}
		add = outbreak_increase_add_high
	}

	#Markets
	if = {
		limit = {
			has_building_or_higher = market_villages_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = market_villages_02
		}
		add = outbreak_increase_add_low
	}

	#Guild Halls
	if = {
		limit = {
			has_building_or_higher = guild_halls_01
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_04
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_06
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_08
		}
		add = outbreak_increase_add_high
	}

	if = {
		limit = {
			OR = {
				has_global_variable = is_in_tutorial
				AND = {
					has_global_variable = start_epidemic_grace
					OR = {
						county.holder = { is_ai = no }
						county.holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		multiply = 0
	}
}

outbreak_chance_minor_mult_value = {
	value = 1

	# Game rules
	if = {
		limit = {
			has_game_rule = epidemic_frequency_often
		}
		add = outbreak_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_often
		}
		add = outbreak_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_doomsday
		}
		add = outbreak_increase_mult_high
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_rare
		}
		add = outbreak_decrease_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_rare
		}
		add = outbreak_decrease_mult_high
	}

	#Development
	add = {
		value = county.development_level
		multiply = 0.002
	}

	#Era pacing
	if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_late_medieval
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_high_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_early_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_tribal
			}
		}
		add = outbreak_decrease_mult_low
	}

	#Terrain
	if = {
		limit = {
			OR = {
				terrain = hills
				terrain = forest
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = outbreak_increase_mult_low
	}

	#Developed places
	if = {
		limit = {
			has_holding = yes
		}
		add = outbreak_increase_mult_low
	}
	if = {
		limit = {
			has_holding_type = city_holding
		}
		add = outbreak_increase_mult_low
	}
	
	multiply = 0.8
	min = 0.001
}

outbreak_chance_major_default_value = {
	value = outbreak_chance_base_very_low 

	#Buildings
	if = {
		limit = {
			num_buildings >= 6
		}
		add = {
			value = num_buildings
			multiply = outbreak_increase_add_low
		}
	}

	#Tradeports
	if = {
		limit = {
			has_building_or_higher = common_tradeport_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_02
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_03
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_04
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_05
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_06
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_07
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_08
		}
		add = outbreak_increase_add_medium
	}

	#Markets
	if = {
		limit = {
			has_building_or_higher = market_villages_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = market_villages_02
		}
		add = outbreak_increase_add_low
	}

	#Guild Halls
	if = {
		limit = {
			has_building_or_higher = guild_halls_01
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_02
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_03
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_04
		}
		add = outbreak_increase_add_medium
	}

	if = {
		limit = {
			OR = {
				has_global_variable = is_in_tutorial
				AND = {
					has_global_variable = start_epidemic_grace
					OR = {
						county.holder = { is_ai = no }
						county.holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		multiply = 0
	}
}

outbreak_chance_major_mult_value = {
	value = 0.8

	# Game rules
	if = {
		limit = {
			has_game_rule = epidemic_frequency_often
		}
		add = outbreak_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_often
		}
		add = outbreak_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_doomsday
		}
		add = outbreak_increase_mult_high
	}
	else_if = {
		limit = {
			OR = {
				has_game_rule = epidemic_frequency_rare
				has_game_rule = easy_difficulty
			}
		}
		add = outbreak_decrease_mult_medium
	}
	else_if = {
		limit = {
			OR = {
				has_game_rule = epidemic_frequency_very_rare
				has_game_rule = very_easy_difficulty
			}
		}
		add = outbreak_decrease_mult_high
	}

	#Development
	add = {
		value = county.development_level
		multiply = 0.008
	}

	#Era pacing
	if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_late_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_high_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_early_medieval
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_tribal
			}
		}
		add = outbreak_decrease_mult_medium
	}

	#Terrain
	if = {
		limit = {
			OR = {
				terrain = hills
				terrain = forest
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = outbreak_increase_mult_low
	}

	#Developed places
	if = {
		limit = {
			has_holding = yes
		}
		add = outbreak_increase_mult_low
	}
	if = {
		limit = {
			has_holding_type = city_holding
		}
		add = outbreak_increase_mult_low
	}
	
	multiply = 1.05
	
	min = 0.001
}

outbreak_chance_apocalyptic_default_value = {
	value = outbreak_chance_base_extra_low
	
	#Buildings
	if = {
		limit = {
			num_buildings >= 10
		}
		add = {
			value = num_buildings
			multiply = outbreak_increase_add_low
		}
	}

	#Tradeports
	if = {
		limit = {
			has_building_or_higher = common_tradeport_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_02
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_03
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_04
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_05
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_06
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_07
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_08
		}
		add = outbreak_increase_add_medium
	}

	#Markets
	if = {
		limit = {
			has_building_or_higher = market_villages_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = market_villages_02
		}
		add = outbreak_increase_add_low
	}

	#Guild Halls
	if = {
		limit = {
			has_building_or_higher = guild_halls_01
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_02
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_03
		}
		add = outbreak_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_04
		}
		add = outbreak_increase_add_low
	}

	if = {
		limit = {
			OR = {
				has_global_variable = is_in_tutorial
				AND = {
					has_global_variable = start_epidemic_grace
					OR = {
						county.holder = { is_ai = no }
						county.holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		multiply = 0
	}
}

outbreak_chance_apocalyptic_mult_value = {
	value = 0.5

	# Game rules
	if = {
		limit = {
			has_game_rule = epidemic_frequency_often
		}
		add = outbreak_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_often
		}
		add = outbreak_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_doomsday
		}
		add = outbreak_increase_mult_high
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_rare
		}
		add = outbreak_decrease_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_rare
		}
		add = outbreak_decrease_mult_high
	}

	#Development
	add = {
		value = county.development_level
		multiply = 0.008
	}

	#Era pacing
	if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_late_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_high_medieval
			}
		}
		add = outbreak_decrease_mult_medium
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_early_medieval
			}
		}
		add = outbreak_decrease_mult_unlikely
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_tribal
			}
		}
		add = outbreak_decrease_mult_unlikely
	}

	#Terrain
	if = {
		limit = {
			OR = {
				terrain = hills
				terrain = forest
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = outbreak_increase_mult_low
	}

	#Developed places
	if = {
		limit = {
			has_holding = yes
		}
		add = outbreak_increase_mult_low
	}
	if = {
		limit = {
			has_holding_type = city_holding
		}
		add = outbreak_increase_mult_low
	}
	
	multiply = 1.05
	
	min = 0.0005
}


outbreak_chance_dysentery_default_value = {

	value = outbreak_chance_base_low #Shouldn't happen unless there's an army present	
	if = {
		limit = {
			any_army_in_location ?= {
				OR = {
					is_army_in_combat = yes
					is_army_in_raid = yes
				}
			}
		}
		add = outbreak_increase_add_extra_high
	}
	if = {
		limit = {
			any_army_in_location ?= {
				count >= 1
			}
		}
		add = outbreak_increase_add_very_high

	}
	if = {
		limit = {
			any_army_in_location ?= {
				is_army_in_siege = yes
			}
		}
		add = outbreak_increase_add_extra_high
		if = {
			limit = {
				fort_level >= 12
			}
			add = outbreak_increase_add_very_high
		}
		if = {
			limit = {
				fort_level >= 10
			}
			add = outbreak_increase_add_high
		}
		if = {
			limit = {
				fort_level >= 8
			}
			add = outbreak_increase_add_high
		}
		if = {
			limit = {
				fort_level >= 4
			}
			add = outbreak_increase_add_medium
		}
		if = {
			limit = {
				fort_level > 2
			}
			add = outbreak_increase_add_low
		}
	}

	if = {
		limit = {
			OR = {
				has_global_variable = is_in_tutorial
				AND = {
					has_global_variable = start_epidemic_grace
					OR = {
						county.holder = { is_ai = no }
						county.holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		multiply = 0
	}
}

outbreak_chance_dysentery_mult_value = {
	value = 1
	min = 0.001
	# Game rules
	if = {
		limit = {
			has_game_rule = epidemic_frequency_often
		}
		add = outbreak_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_often
		}
		add = outbreak_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_doomsday
		}
		add = outbreak_increase_mult_high
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_rare
		}
		add = outbreak_decrease_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_rare
		}
		add = outbreak_decrease_mult_high
	}

	#Era pacing
	if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_late_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_high_medieval
			}
		}
		add = 0
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_early_medieval
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_tribal
			}
		}
		add = outbreak_decrease_mult_medium
	}

	#Terrain
	if = {
		limit = {
			OR = {
				terrain = hills
				terrain = forest
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = outbreak_increase_mult_low
	}

	#Developed places
	if = {
		limit = {
			has_holding = yes
		}
		add = outbreak_increase_mult_low
	}
	if = {
		limit = {
			has_holding_type = city_holding
		}
		add = outbreak_increase_mult_low
	}
}

outbreak_chance_black_plague_default_value = {
	value = outbreak_chance_base_extra_low

	#Buildings
	if = {
		limit = {
			num_buildings >= 20
		}
		add = {
			value = num_buildings
			multiply = outbreak_increase_add_medium
		}
	}

	if = {
		limit = {
			has_building_or_higher = common_tradeport_03
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_04
		}
		add = outbreak_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_05
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_06
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_07
		}
		add = outbreak_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_08
		}
		add = outbreak_increase_add_high
	}
	
	if = {
		limit = {
			has_game_rule = epidemic_frequency_disabled
		}
		multiply = 0
	}

	if = {
		limit = {
			has_game_rule = bd_occurrence_random
		}
		add = outbreak_increase_add_high
	}

	if = {
		limit = {
			OR = {
				has_global_variable = is_in_tutorial
				AND = {
					has_global_variable = start_epidemic_grace
					OR = {
						county.holder = { is_ai = no }
						county.holder = {
							any_liege_or_above = { is_ai = no }
						}
					}
				}
			}
		}
		multiply = 0
	}
}

outbreak_chance_black_plague_mult_value = {
	value = 1
	min = 0.001
	#Development
	add = {
		value = county.development_level
		multiply = 0.08
	}

	# Game rules
	if = {
		limit = {
			has_game_rule = epidemic_frequency_often
		}
		add = outbreak_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_often
		}
		add = outbreak_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_doomsday
		}
		add = outbreak_increase_mult_high
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_rare
		}
		add = outbreak_decrease_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_rare
		}
		add = outbreak_decrease_mult_high
	}

	#Era pacing
	if = {
		limit = {
			NOR = {
				has_game_rule = bd_occurrence_random
				has_game_rule = bd_frequency_unlimited
			}
		}
		if = {
			limit = {
				culture = {
					has_cultural_era_or_later = culture_era_late_medieval
				}
			}
			add = outbreak_decrease_mult_low
		}
		else_if = {
			limit = {
				culture = {
					has_cultural_era_or_later = culture_era_high_medieval
				}
			}
			add = outbreak_decrease_mult_medium
		}
		else_if = {
			limit = {
				culture = {
					has_cultural_era_or_later = culture_era_early_medieval
				}
			}
			add = outbreak_decrease_mult_high
		}
		else_if = {
			limit = {
				culture = {
					has_cultural_era_or_later = culture_era_tribal
				}
			}
			add = outbreak_decrease_mult_unlikely
		}
	}

	#Terrain
	if = {
		limit = {
			OR = {
				terrain = hills
				terrain = forest
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = outbreak_decrease_mult_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = outbreak_increase_mult_low
	}

	#Developed places
	if = {
		limit = {
			has_holding = yes
		}
		add = outbreak_increase_mult_low
	}
	if = {
		limit = {
			has_holding_type = city_holding
		}
		add = outbreak_increase_mult_low
	}
}

#### SPREAD CHANCE ###
#Controls the spread of the epidemic
#root = potential_province

spread_chance_epidemics_default_value = {
	if = {
		limit = {
			scope:epidemic = {
				outbreak_intensity = apocalyptic
			}
		}
		add = spread_chance_base_high
	}
	else_if = {
		limit = {
			scope:epidemic = {
				outbreak_intensity = major
			}
		}
		add = spread_chance_base_medium
	}
	else = { #minor
		add = spread_chance_base_low
	}
	
	#less patchy, add
	if = {
		limit = {
			county = {
				any_county_province = {
					any_province_epidemic = {
						this.epidemic_type = scope:epidemic.epidemic_type
					}
				}
			}
		}
		add = spread_increase_add_high
	}

	#Dysentery spreads to armies and forts
	if = {
		limit = { scope:epidemic.epidemic_type = epidemic_type:dysentery }
		add = {
			if = {
				limit = {
					any_army_in_location ?= {
						is_army_in_siege = yes
					}
				}
				add = spread_increase_add_high
			}
			if = {
				limit = {
					any_army_in_location ?= {
						OR = {
							is_army_in_combat = yes
							is_army_in_raid = yes
						}
					}
				}
				add = spread_increase_add_medium
			}
			if = {
				limit = {
					any_army_in_location ?= {
						count >= 1
					}
				}
				add = spread_increase_add_high
			}			
		}
		add = {
			value = fort_level
			multiply = spread_increase_mult_low
		}
	}
	
	#Buildings
	add = {
		value = num_buildings
		multiply = spread_increase_mult_low
	}

	#Tradeports
	if = {
		limit = {
			has_building_or_higher = common_tradeport_01
		}
		add = spread_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_02
		}
		add = spread_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_03
		}
		add = spread_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_04
		}
		add = spread_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_05
		}
		add = spread_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_06
		}
		add = spread_increase_add_medium
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_07
		}
		add = spread_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = common_tradeport_08
		}
		add = spread_increase_add_high
	}

	#Markets
	if = {
		limit = {
			has_building_or_higher = market_villages_01
		}
		add = spread_increase_add_low
	}
	if = {
		limit = {
			has_building_or_higher = market_villages_02
		}
		add = spread_increase_add_low
	}

	#Guild Halls
	if = {
		limit = {
			has_building_or_higher = guild_halls_02
		}
		add = spread_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_04
		}
		add = spread_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_06
		}
		add = spread_increase_add_high
	}
	if = {
		limit = {
			has_building_or_higher = guild_halls_08
		}
		add = spread_increase_add_high
	}


	#Terrain
	if = {
		limit = {
			terrain = farmlands
		}
		add = spread_increase_add_medium
	}
	else_if = {
		limit = {
			OR = {
				terrain = floodplains
				terrain = wetlands
			}
		}
		add = spread_increase_add_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = plains
				terrain = steppe
			}
		}
		add = spread_increase_add_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = hills
				terrain = drylands
				terrain = oasis
				terrain = forest
			}
		}
		add = spread_decrease_add_low
	}
	else_if = {
		limit = {
			OR = {
				terrain = jungle
				terrain = taiga
			}
		}
		add = spread_decrease_add_medium
	}
	else_if = {
		limit = {
			OR = {
				terrain = desert
				terrain = desert_mountains
				terrain = mountains
			}
		}
		add = spread_decrease_add_medium
	}
	#Island?
	if = {
		limit = {
			geographical_region = divergence_island_regions
		}
		add = spread_decrease_add_medium
	}
	#Cultural Traditions
	if = {
		limit = {
			county.culture = {
				OR = {
					has_cultural_tradition = tradition_city_keepers
					has_cultural_tradition = tradition_maritime_mercantilism
				}
			}
		}
		add = spread_increase_add_medium
	}
	else_if = {
		limit = {
			county.culture = {
				OR = {
					has_cultural_tradition = tradition_esteemed_hospitality
					has_cultural_tradition = tradition_horse_lords
					has_cultural_tradition = tradition_caravaneers
					has_cultural_tradition = tradition_seafaring
				}
			}
		}
		add = spread_increase_add_low
	}
	else_if = {
		limit = {
			county.culture = {
				OR = {
					has_cultural_tradition = tradition_practiced_pirates
					has_cultural_tradition = tradition_parochialism
				}
			}
		}
		add = spread_increase_add_low
	}
	if = {
		limit = {
			county.culture = {
				has_cultural_tradition = tradition_hidden_cities
			}
		}
		add = spread_decrease_add_high
	}
	else_if = {
		limit = {
			county.culture = {
				has_cultural_parameter = less_plague_spread_culture
			}
		}
		add = spread_decrease_add_high
	}
	
	#Reinfection shouldn't happen often
	if = {
		limit = {
			scope:epidemic = {
				is_target_in_variable_list = {
					name = epidemic_cooldown
				}
			}
		}
		add = spread_decrease_add_very_high
	}
}

spread_chance_epidemics_mult_value = {
	value = 1
	min = 0.001
	#Coastal Statistics Squash
	if = {
		limit = {
			OR = {
				is_coastal = yes
				is_riverside_province = yes
			}
			NOR = {
				has_building_or_higher = common_tradeport_04
				num_buildings > 4
			}
		}
		add = spread_decrease_mult_medium
	}

	#Making sure that England gets properly rekted by the Black Plague
	if = {
		limit = {
			has_global_variable = black_death
			scope:epidemic = global_var:black_death
			OR = {
				is_coastal = yes
				is_riverside_province = yes
			}
			has_building_or_higher = common_tradeport_06
			num_buildings > 10
		}
		add = spread_increase_mult_very_high
	}

	#less patchy, mult
	if = {
		limit = {
			county = {
				any_county_province = {
					any_province_epidemic = {
						this.epidemic_type = scope:epidemic.epidemic_type
					}
				}
			}
		}
		add = spread_increase_mult_very_high
	}

	#Development
	add = {
		value = county.development_level
		multiply = 0.025
	}


	# Game rules
	if = {
		limit = {
			has_game_rule = epidemic_frequency_doomsday
		}
		add = spread_increase_mult_very_high
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_often
		}
		add = spread_increase_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_often
		}
		add = spread_increase_mult_low
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_very_rare
		}
		add = spread_decrease_mult_medium
	}
	else_if = {
		limit = {
			has_game_rule = epidemic_frequency_rare
		}
		add = spread_decrease_mult_low
	}

	#Intensity mult

	if = {
		limit = { 
			scope:epidemic = {
				outbreak_intensity = apocalyptic
			}
		}
		add = spread_increase_mult_high
	}
	else_if = {
		limit = { 
			scope:epidemic = {
				outbreak_intensity = major
			}
		}
		add = spread_increase_mult_medium
	}

	#Recent Epidemics
	if = {
		limit = {
			is_target_in_variable_list = {
				name = epidemic_cooldown #Average lifespan
				target = scope:epidemic.epidemic_type
			}
		}
		if = {
			limit = {
				has_game_rule = epidemic_frequency_often
			}
			add = spread_decrease_mult_high
		}
		else_if = {
			limit = {
				has_game_rule = epidemic_frequency_very_often
			}
			add = spread_decrease_mult_medium
		}
		else_if = {
			limit = {
				has_game_rule = epidemic_frequency_doomsday
			}
			add = spread_decrease_mult_low
		}
		else = {
			add = spread_decrease_mult_unlikely
		}	
	}

	#People still remember how to social distance in general
	if = {
		limit = {
			has_variable = epidemic_cooldown_general #Average social memory
		}
		if = {
			limit = {
				has_game_rule = epidemic_frequency_very_often
			}
			add = spread_decrease_mult_medium
		}
		else_if = {
			limit = {
				has_game_rule = epidemic_frequency_doomsday
			}
			add = spread_decrease_mult_low
		}
		else = {
			add = spread_decrease_mult_high
		}
	}

	#Developed places
	if = {
		limit = {
			has_holding = yes
		}
		add = spread_increase_mult_low
	}
	if = {
		limit = {
			OR = {
				has_holding_type = castle_holding
				has_holding_type = church_holding
			}
		}
		add = spread_increase_mult_low
	}
	if = {
		limit = {
			has_holding_type = city_holding
		}
		add = spread_increase_mult_medium
	}
}

#### DAILY INFECTION RATE ###
#The velocity at which the infection rate goes up in a province

infection_rate_change_value = {
	
}

#### CHARACTER INFECTION CHANCE ###
#Monthly chance for an epidemic to infect a character in the province

would_follow_social_distancing_value = {
	value = -1 #let's assume medieval people wouldn't by default
	if = {
		limit = { has_perk = wash_your_hands_perk }
		add = 10
	}
	if = {
		limit = { has_trait = shy }
		add = 1
	}
	if = {
		limit = { has_trait = paranoid }
		add = 2
	}
	if = {
		limit = { has_trait = reclusive }
		add = 4
	}
	if = {
		limit = { has_trait = shrewd }
		add = 1
	}
	if = {
		limit = { has_trait = lifestyle_physician }
		add = 4
	}
	if = {
		limit = { has_trait = lifestyle_herbalist }
		add = 2
	}
	if = {
		limit = { has_trait = diligent }
		add = 1
	}
	if = {
		limit = { has_trait = craven }
		add = 1
	}
	if = {
		limit = { has_trait = temperate }
		add = 1
	}
	if = {
		limit = { has_trait = arbitrary }
		add = -1
	}
	if = {
		limit = { has_trait = brave }
		add = -1
	}
	if = {
		limit = { has_trait = impatient }
		add = -2
	}
	if = {
		limit = { has_trait = gregarious }
		add = -4
	}
	if = {
		limit = { has_trait = dull }
		add = -2
	}
	#Would your culture be touchy?/take this seriously
	if = {
		limit = { culture = { has_cultural_tradition = tradition_fp2_ritualised_friendship } }
		add = -1
	}
	if = {
		limit = { culture = { has_cultural_tradition = tradition_life_is_just_a_joke } }
		add = -1
	}
	if = {
		limit = { culture = { has_cultural_parameter = better_disease_resistance } }
		add = 20
	}
}

character_infection_chance_default_value = {
	value = 10
	#If you're already sick/weak you're screwed
	if = { 
		limit = { 
			OR = {
				has_trait = sickly
				has_trait = inbred
				health <= poor_health
			}
		}
		add = 20
	}
	#Epidemic Intensity
	if = {
		limit = {
			scope:epidemic ?= {
				outbreak_intensity = apocalyptic
				epidemic_type.epidemic_trait = trait:bubonic_plague
			}
		}
		add = 40
	}
	else_if = {
		limit = {
			scope:epidemic ?= {
				outbreak_intensity = apocalyptic
				NOT = { epidemic_type.epidemic_trait = trait:bubonic_plague }
			}
		}
		add = 30
	}
	else_if = {
		limit = {
			scope:epidemic ?= {
				outbreak_intensity = major
			}
		}
		add = 20
	}
	else = { #minor
		add = 10
	}
	#Let's see if you have any advantageous traits/perks / Wash your hands is included in the social distancing calculation, these are purely health related
	if = {
		limit = {
			has_trait = athletic
		}
		add = -4
	}
	if = {
		limit = {
			has_perk = iron_constitution_perk
		}
		add = -6
	}
	if = {
		limit = {
			has_perk = healthy_perk
		}
		add = -8
	}
	if = {
		limit = {
			has_trait = whole_of_body
		}
		add = -10
	}
	#Things to bump the numbers
	if = {
		limit = {
			is_foreign_court_or_pool_guest = yes
		}
		add = 40
	}
	if = {
		limit = {
			is_ruler = no
		}
		add = 10
	}
	#Children getting hit with measles
	if = {
		limit = {
			scope:epidemic.epidemic_type.epidemic_trait = trait:measles
			is_adult = no
		}
		add = 20
	}
	#"Old" people get hit more in general
	if = {
		limit = {
			age >= 65
		}
		add = 40
	}
	else_if = {
		limit = {
			age >= 50
		}
		add = 20
	}
	# Camp resistance.
	if = {
		limit = {
			host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_1 }
		}
		# Max buff.
		if = {
			limit = {
				host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_6 }
			}
			add = -40
		}
		# Very high buff.
		else_if = {
			limit = {
				host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_5 }
			}
			add = -30
		}
		# High buff.
		else_if = {
			limit = {
				host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_4 }
			}
			add = -25
		}
		# Medium buff.
		else_if = {
			limit = {
				host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_3 }
			}
			add = -20
		}
		# Small buff.
		else_if = {
			limit = {
				host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_2 }
			}
			add = -15
		}
		# Slight buff.
		else_if = {
			limit = {
				host.domicile ?= { has_domicile_parameter = camp_infection_chance_buff_1 }
			}
			add = -10
		}
	}
	#Would you follow social distancing?
	#your numerical social distance value gets transformed here into a bonus/malus
	add = {
		value = would_follow_social_distancing_value
		multiply = -1 #inverted value
	}
	#How infected is your location?
	#Follows the infection rate thresholds set for the barony/county modifiers
	if = {
		limit = {
			location = { epidemic_resistance > 80 }
		}
		multiply = 0.25
	}
	else_if = {
		limit = {
			location = { epidemic_resistance > 50 }
		}
		multiply = 0.5
	}
	else_if = {
		limit = {
			location = { epidemic_resistance > 10 }
		}
		multiply = 0.75
	}
	#Are you taking proper measures?
	if = {
		limit = {
			has_character_modifier = isolating_modifier
		}
		multiply = 0.25 #75% less likely
	}
	#How infected is your location?
	#Follows the infection rate thresholds set for the barony/county modifiers
	if = {
		limit = {
			scope:province = { epidemic_resistance > 80 }
		}
		multiply = 0.25
	}
	else_if = {
		limit = {
			scope:province = { epidemic_resistance > 50 }
		}
		multiply = 0.5
	}
	else_if = {
		limit = {
			scope:province = { epidemic_resistance > 10 }
		}
		multiply = 0.75
	}
	min = 1 # Never totally immune
}

#How contagious is this character?
character_contagious_value = {
	add = { #would they follow social distancing?
		value = would_follow_social_distancing_value
		multiply = -1 #inverted
	}
	if = {
		limit = {
			has_trait = wheezing
		}
		add = 4
	}
}

recent_epidemics_outbreak_mult_value = {
	value = 1
	min = 0.001
	#Recently recovered from this epidemic
	if = {
		limit = {
			is_target_in_variable_list = {
				name = epidemic_cooldown #Average lifespan
				target = scope:epidemic_type
			}
		}
		if = {
			limit = {
				has_game_rule = epidemic_frequency_very_often
			}
			value = outbreak_decrease_mult_high
		}
		else_if = {
			limit = {
				has_game_rule = epidemic_frequency_doomsday
			}
			value = outbreak_decrease_mult_medium
		}
		else = {
			value = outbreak_decrease_mult_unlikely
		}
		
	}

	#People still remember how to social distance in general
	else_if = {
		limit = {
			has_variable = epidemic_cooldown_general #Average social memory
		}
		if = {
			limit = {
				has_game_rule = epidemic_frequency_very_often
			}
			value = outbreak_decrease_mult_medium
		}
		else_if = {
			limit = {
				has_game_rule = epidemic_frequency_doomsday
			}
			value = outbreak_decrease_mult_low
		}
		else = {
			value = outbreak_decrease_mult_high
		}
	}
}

#How badly effected is a county's development?
epidemic_development_loss_value = {
	subtract = scope:base_loss

	#This feeds into the change_development_progress in 00_epidemics
	#Bear in mind that minimal_development_progress_loss is 10
	#and massive_development_progress_loss is 100
	#Aim for something between those two extremes generally (in minus)

	#Since we have widespread development loss handled by modifier, we
	#now use this figure to 'chunk' down places with very high development
	#so they are disproportionately affected

	scope:epidemic = {
		switch = {
			trigger = outbreak_intensity
			minor = { subtract = 2.5 }
			major = { subtract = 5 }
			apocalyptic = { subtract = 7.5 }
		}
	}

	# Development
	subtract = {
		value = development_level
		multiply = 0.3
	}

	multiply = {
		value = 6
		divide = num_county_holdings
	}

	multiply = {
		value = 100
		subtract = title_province.epidemic_resistance
		multiply = 0.005
		add = 1
	}
}

epidemic_fromdust_value = {
	value = minor_gold_value
	multiply = former_infected_county_count
}

former_infected_county_count = {
	value = 1
	every_in_list = {
		variable = formerly_infected_counties
		add = 0.1
	}
}
