###############################
# Disease events
#
# ds.1 -> ds.9 Quarantine events
# ds.10 -> ds.29 Justinian plague
###############################

namespace = ds

# Quarantine placed
character_event = {
	id = ds.1
	desc = EVTDESC_ds_1
	picture = GFX_evt_plague_doctor
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	hide_from = yes
	
	option = {
		name = EVTOPTA_ds_1
		wealth = -200
		prestige = -100
		any_realm_province = {
			add_province_modifier = {
				name = quarantined_province
			}
		}
		hidden_tooltip = {
			any_realm_lord = {
				limit = { ai = no }
				character_event = { id = ds.3 }
			}
		}
	}
}

# Quarantine removed
character_event = {
	id = ds.2
	desc = EVTDESC_ds_2
	picture = GFX_evt_jewish_market
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	hide_from = yes
	
	option = {
		name = EVTOPTA_ds_2
		prestige = 150
		any_realm_province = {
			remove_province_modifier = quarantined_province 
		}
		hidden_tooltip = {
			any_realm_lord = {
				limit = { ai = no }
				character_event = { id = ds.4 }
			}
		}
	}
}

# Quarantine placed (Notifier for Vassals)
character_event = {
	id = ds.3
	desc = EVTDESC_ds_3
	picture = GFX_evt_plague_doctor
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_ds_3
		trigger = {
			NOT = { has_character_modifier = borrowed_from_jews }
		}
			
	}
}

# Quarantine removed (Notifier for Vassals)
character_event = {
	id = ds.4
	desc = EVTDESC_ds_4
	picture = GFX_evt_jewish_market
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_ds_4
	}
}

# Quaranta placed Republic
character_event = {
	id = ds.5
	desc = EVTDESC_ds_5
	picture = GFX_evt_busy_trading_dock_republic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	hide_from = yes
	
	option = {
		name = EVTOPTA_ds_5
		wealth = -200
		prestige = -50
		any_realm_province = {
			limit = { has_trade_post = yes }
			add_province_modifier = {
				name = quaranta
			} 
		}
	}
}

# Quaranta Removed Republic
character_event = {
	id = ds.6
	desc = EVTDESC_ds_6
	picture = GFX_evt_busy_trading_dock_republic
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	hide_from = yes
	
	option = {
		name = EVTOPTA_ds_6
		prestige = 150
		any_realm_province = {
			remove_province_modifier = quaranta
		}
		hidden_tooltip = {
			any_realm_lord = {
				limit = { ai = no }
				character_event = { id = ds.4 }
			}
		}
	}
}

# Roma Quarantines
character_event = {
	id = ds.7
	desc = EVTDESC_ds_7
	picture = GFX_evt_cathedral
	border = GFX_event_normal_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = EVTOPTA_ds_7
		prestige = 50
	}
}

###############################
# Justinian Plague
#
# Written by Romulien
###############################

# Arrival of the plague

# Plague arrives in the realm
# Checks if any province in the realm has the plague
character_event = {
	id = ds.10
	hide_window = yes
	
	only_rulers = yes
	only_independent = yes

	trigger = {
		primary_title = {
			OR = {
				NOT = { has_title_flag = flag_justinian_plague_arrived_in_realm } # Initial outbreak
				had_title_flag = { flag = flag_justinian_plague_arrived_in_realm days = 365 } # Recurrence of the plague
			}
		}
		any_realm_province = {
			disease = bubonic_plague
		}
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		primary_title = {
			clr_title_flag = flag_justinian_plague_arrived_in_realm # Reset the counter
			set_title_flag = flag_justinian_plague_arrived_in_realm
		}
	}
	
	option = {
		name = OK
		
		if = {
			limit = {
				had_global_flag = { flag = flag_justinian_plague_arrived days = 3650 } # Recurrence of the plague
				primary_title = {
					is_titular = no # Let the notification fire for a landed title
				}
			}
			any_playable_ruler = {
				limit = { 
					ai = no
					NOT = { character = ROOT }
				}
				narrative_event = { id = ds.15 days = 30 }
			}
			clr_global_flag = flag_justinian_plague_arrived # Reset counter
			set_global_flag = flag_justinian_plague_arrived
		}

		else_if = {
			limit = {
				NOT = { has_global_flag = flag_justinian_plague_arrived } # Initial outbreak
				primary_title = {
					is_titular = no # Let the notification fire for a landed title
				}
			}
			any_playable_ruler = {
				limit = { 
					ai = no
					NOT = { character = ROOT }
				}
				narrative_event = { id = ds.11 days = 30 }
			}
			# Note: global flag is also set via e_byzantium title history
			# With a start date 542-600, the initial outbreak will just be considered a recurrence of the plague.
			set_global_flag = flag_justinian_plague_arrived
		}
		
		narrative_event = { id = ds.12 }
		any_realm_character = {
			limit = { 
				ai = no
			}
			narrative_event = { id = ds.12 }
		}
	}
}

# Notify players of the arrival of the plague in the world
# FROM is the independent liege of the initial outbreak
narrative_event = {
	id = ds.11
	desc = ds.11.desc
	title = EVTTITLE_bubonic_plague

	picture = GFX_evt_plague_doctor
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	
	immediate = {
		primary_title = {
			clr_title_flag = flag_justinian_plague_arrived_in_realm # Reset the counter
			set_title_flag = flag_justinian_plague_arrived_in_realm
		}
	}
	
	option = {
		name = ds.11.a
		trigger = {
			NOT = { trait = zealous }
		}
	}
	
	option = {
		name = ds.11.b
		tooltip_info = zealous
		trigger = {
			trait = zealous
		}
	}
}

# Notify rulers that plague arrived in the realm
# FROM is the top liege
narrative_event = {
	id = ds.12
	desc = ds.12.desc
	title = EVTTITLE_bubonic_plague
	
	picture = GFX_evt_plague_doctor
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = ds.12.a
		
		random = {
			chance = 10
			modifier = {
				factor = 3
				trait = zealous
			}
			add_trait = depressed
		}
	}
}



# Religious head gets the plague
character_event = {
	id = ds.13
	desc = ds.13.desc
	
	picture = GFX_evt_plague_doctor
	border = GFX_event_normal_frame_religion
	
	only_rulers = yes
	
	trigger = {
		controls_religion = yes
		trait = has_bubonic_plague
		NOT = { intrigue = 12 } # Unsuccessful at concealing it
		NOT = { has_character_flag = flag_affected_by_pestilence }
		OR = { # Either not had it for more than five years or never had it
			any_demesne_title = {
				controls_religion = yes
				had_title_flag = { 
					flag = flag_religious_head_affected_by_pestilence
					days = 1825 # 5 years
				}
			}
			NOT = {
				any_demesne_title = {
					controls_religion = yes
					has_title_flag = flag_religious_head_affected_by_pestilence
				}
			}
		} 
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	immediate = {
		set_character_flag = flag_affected_by_pestilence
		any_demesne_title = { # Limit event from firing repeatedly for a quick sucession of heads
			limit = { 
				controls_religion = yes
			}
			set_title_flag = flag_religious_head_affected_by_pestilence
		}
	}
	
	option = {
		name = ds.13.a
		religion_authority = { modifier = affected_by_pestilence }
		
		any_playable_ruler = {
			limit = {
				ai = no
				NOT = { character = ROOT }
				OR = {
					religion = ROOT
					is_heresy_of = ROOT
				}
			}
			narrative_event = { id = ds.14 }
		}
	}
}

# Notify the player
# FROM is the religious head
narrative_event = {
	id = ds.14
	desc = ds.14.desc
	title = EVTTITLE_bubonic_plague
	
	picture = GFX_evt_plague_doctor
	border = GFX_event_narrative_frame_religion
	
	is_triggered_only = yes
	
	option = {
		name = ds.14.a
		trigger = {
			religion = FROM
		}
	}
	
	option = {
		name = ds.14.b
		trigger = {
			is_heresy_of = FROM
		}
	}
}

# Notify players of the recurrence of the plague in the world
# FROM is the independent liege of the initial outbreak
narrative_event = {
	id = ds.15
	desc = ds.15.desc
	title = EVTTITLE_bubonic_plague

	picture = GFX_evt_plague_doctor
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	
	option = {
		name = ds.11.a
		trigger = {
			NOT = { trait = zealous }
		}
	}
	
	option = {
		name = ds.11.b
		tooltip_info = zealous
		trigger = {
			trait = zealous
		}
	}
}
