namespace = HF
# Some additional flavor for Africa

#########################################

# Story-telling
character_event = {
	id = HF.15000
	title = EVTTITLE_HF_15000
	desc = EVTDESC_HF_15000
	picture = GFX_evt_moonlit_mountains_hf
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				any_owned_bloodline = {
					founder = {
						NOT = { character = ROOT }
					}
				}
			}

			random_owned_bloodline = {
				founder = {
					save_event_target_as = bloodline_founder
				}
			}
		}
	}

	option = { # Lunatic option
		name = EVTOPTA_HF_15000
		tooltip_info = lunatic

		trigger = { trait = lunatic }

		add_character_modifier = {
			name = told_story_nr_1
			years = 5
		}
	}

	option = { # Dumb option
		name = EVTOPTB_HF_15000
		tooltip_info_custom = available_because_dumb

		trigger = { is_dumb_trigger = yes }

		add_character_modifier = {
			name = told_story_nr_2
			years = 5
		}

		ai_chance = { factor = 100 }
	}

	option = { # Bloodline option (not dumb)
		name = EVTOPTC_HF_15000

		trigger = {
			event_target:bloodline_founder = { always = yes }
		}

		add_character_modifier = {
			name = told_story_nr_3
			years = 5
		}
	}

	option = { # About bravery
		name = EVTOPTD_HF_15000

		add_character_modifier = {
			name = told_story_nr_4
			years = 5
		}
	}

	option = { # About religion
		name = EVTOPTE_HF_15000

		add_character_modifier = {
			name = told_story_nr_5
			years = 5
		}
	}

	option = { # About your tribe
		name = EVTOPTF_HF_15000

		trigger = { is_tribal = yes }

		add_character_modifier = {
			name = told_story_nr_6
			years = 5
		}
	}

	after = {
		clr_character_flag = choosing_a_story_flag
	}
}

# Rains down in Africa (SETUP)
character_event = {
	id = HF.15099

	is_triggered_only = yes # on_startup
	hide_window = yes

	has_dlc = "Holy Fury"
	only_playable = yes

	trigger = {
		any_demesne_province = {
			region_africa_west_central_or_east_trigger = yes
			has_rain_or_drought_modifier_trigger = no
			owned_by = PREV
		}
	}

	immediate = {
		any_demesne_province = {
			limit = {
				region_africa_west_central_or_east_trigger = yes
				has_rain_or_drought_modifier_trigger = no
				owned_by = PREV
			}

			# Solid start... Activate this for more sunny weather from the get-go...
			add_province_modifier = {
				name = africa_light_rain
				duration = -1
			}

			change_rain_effect = yes # Activate this instead, if you want it more random...
		}
	}
}


# Rain development (on 5 year pulse)
character_event = {
	id = HF.15100

	is_triggered_only = yes
	hide_window = yes

	has_dlc = "Holy Fury"
	only_playable = yes

	trigger = {
		any_demesne_province = {
			region_africa_west_central_or_east_trigger = yes
			has_rain_or_drought_modifier_trigger = yes
			owned_by = PREV
		}
	}

	immediate = {
#		save_event_target_as = rain_liege

#			while = { # As long as there are some provinces left to change the weather of...
#			limit = {
#				any_demesne_province = {
#					region_africa_west_central_or_east_trigger = yes
#					NOT = { has_province_modifier = africa_weather_updated }
#				}
#			}

			### Current setup: Runs through all demesne provinces and chain-changes them (based on previous status and neighbor's status)
			any_demesne_province = { # Change weather...
				limit = {
					region_africa_west_central_or_east_trigger = yes
					NOT = { has_province_modifier = africa_weather_updated }
					owned_by = PREV
				}

				change_rain_effect = yes
#
#				preferred_limit = {
#					is_capital = yes # An attempt to make your capital the most important choice for the rain :p
#					region_africa_west_central_or_east_trigger = yes
#					NOT = { has_province_modifier = africa_weather_updated }
#				}
#
#				save_event_target_as = target_province
#
#				location = { duchy = { save_event_target_as = target_duchy_title } }
#
#				# Spread it to the duchy...
#				event_target:target_duchy_title = {
#					any_de_jure_vassal = {
#						location = {
#							if = {
#								limit = { NOT = { has_province_modifier = africa_weather_updated } }
#								event_target:target_province = { clone_weather_to_prev_effect = yes }
#							}
#						}
#					}
#				}
			}
#		}
	}
}


# Delay for the tombola below (from on bi_yearly_pulse)
character_event = {
	id = HF.15098

	hide_window = yes
	is_triggered_only = yes

	only_playable = yes
	has_dlc = "Holy Fury"
	min_age = 16
	only_capable = yes
	prisoner = no

	immediate = {
		character_event = { id = HF.15120 days = 5 }
	}
}

# Tombola for flavor/risks/bonuses related to the rain/drought... (from event above )
character_event = {
	id = HF.15120

	is_triggered_only = yes
	hide_window = yes

	only_playable = yes
	has_dlc = "Holy Fury"
	min_age = 16
	only_capable = yes
	prisoner = no

	trigger = {
		any_demesne_province = {
			region_africa_west_central_or_east_trigger = yes
			has_rain_or_drought_modifier_trigger = yes
			owned_by = PREV
		}
	}

	immediate = {
		calculate_weather_status_in_demesne_effect = yes # Run this in an effect file for testing individual events

		# The Winds over [PrimaryTitle] (Rain prep)......... HF.15110
		# Rain dances have effect (?) ...................... HF.15101
		# To dance or not to dance ......................... HF.15102

		# Landslide in province............................. HF.15121
		# Molding Library................................... HF.15123
		# Flooded Armory ................................... HF.15124

		# The Winds over [PrimaryTitle] (Drought prep)...... HF.15111
		# Drought causes starvation (notification only) .... HF.15125
		# Drought spreads disease .......................... HF.15122

		random_list = {
			### Any rain...
			10 = { # The Winds over [PrimaryTitle] (Rain)
				trigger = {
					OR = {
						has_character_flag = mostly_heavy_rain
						has_character_flag = mostly_light_rain
					}

					capital_scope = {
						OR = {
							has_province_modifier = africa_heavy_rain
							has_province_modifier = africa_light_rain
						}

						NOR = {
							has_province_modifier = africa_drought_risk
							has_province_modifier = africa_drought
						}
					}

					NOR = {
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				character_event = { id = HF.15110 }
			}

			10 = { # Rain dances have effect (?)
				trigger = {
					any_demesne_province = {
						owned_by = PREV

						OR = {
							has_province_modifier = africa_light_rain
							has_province_modifier = africa_heavy_rain
						}

						OR = {
							has_province_modifier = africa_rain_dance_1
							has_province_modifier = africa_rain_dance_2
						}
					}
				}

				mult_modifier = {
					factor = 1.5

					OR = {
						has_character_flag = mostly_heavy_rain
						has_character_flag = mostly_light_rain
					}

					NOR = {
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				mult_modifier = {
					factor = 1.5

					NOT = { # If there are is *no* drought at all
						any_demesne_province = {
							owned_by = PREV

							OR = {
								has_province_modifier = africa_drought_risk
								has_province_modifier = africa_drought
							}
						}
					}
				}

				character_event = { id = HF.15101 }
			}

			10 = { # To dance or not to dance
				trigger = {
					any_demesne_province = {
						has_province_modifier = africa_light_rain
						owned_by = PREV

						NOR = {
							has_province_modifier = africa_rain_dance_1
							has_province_modifier = africa_rain_dance_2
						}

						# You've had it great for way too long...
						had_province_flag = {
							flag = africa_light_rain_flag
							years < 50
						}
					}
				}

				mult_modifier = {
					factor = 1.5

					OR = {
						has_character_flag = mostly_heavy_rain
						has_character_flag = mostly_light_rain
					}

					NOR = {
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				character_event = { id = HF.15102 }
			}

			### Heavy Rain...
			10 = { # Landslide in a province...
				trigger = {
					has_character_flag = mostly_heavy_rain

					any_demesne_province = {
						has_province_modifier = africa_heavy_rain
						NOT = { has_province_modifier = africa_heavy_rain_cooldown_1 }
						owned_by = PREV

						any_province_holding = {
							num_of_buildings >= 1
						}

						any_province_holding = {
							holder_scope = {
								any_courtier = {
									count = 3
									ai = yes
								}
							}
						}
					}
				}

				mult_modifier = {
					factor = 1.5

					has_character_flag = mostly_heavy_rain

					NOR = {
						has_character_flag = mostly_light_rain
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				character_event = { id = HF.15121 }
			}

			10 = { # Rotting Library...
				trigger = {
					any_demesne_province = {
						has_province_modifier = africa_heavy_rain
						NOT = { has_province_modifier = africa_heavy_rain_cooldown_2 }
						owned_by = PREV
					}

					any_artifact = {
						has_artifact_flag = book
						is_indestructible = no
					}
				}

				mult_modifier = {
					factor = 1.5

					has_character_flag = mostly_heavy_rain

					NOR = {
						has_character_flag = mostly_light_rain
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				mult_modifier = {
					factor = 1.5
					capital_scope = { has_province_modifier = africa_heavy_rain }
				}

				mult_modifier = {
					factor = 0.1
					has_character_flag = had_book_event
				}

				character_event = { id = HF.15123 }
			}

			10 = { # Rusting Armory...
				trigger = {
					any_demesne_province = {
						has_province_modifier = africa_heavy_rain
						NOT = { has_province_modifier = africa_heavy_rain_cooldown_3 }
						owned_by = PREV
					}

					any_artifact = {
						OR = {
							has_artifact_flag = armor
							has_artifact_flag = combat_weapon
						}
						is_indestructible = no
					}
				}

				mult_modifier = {
					factor = 1.5

					has_character_flag = mostly_heavy_rain

					NOR = {
						has_character_flag = mostly_light_rain
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				mult_modifier = {
					factor = 1.5
					capital_scope = { has_province_modifier = africa_heavy_rain }
				}

				mult_modifier = {
					factor = 1.5
					num_of_artifacts >= 5
				}

				mult_modifier = {
					factor = 0.1
					has_character_flag = had_weapon_event
				}

				character_event = { id = HF.15124 }
			}

			### Any drought...
			10 = { # Rain dances maybe?
				trigger = {
					any_demesne_province = {
						has_province_modifier = africa_drought_risk
						owned_by = PREV

						NOR = {
							has_province_modifier = africa_rain_dance_1
							has_province_modifier = africa_rain_dance_2
						}
					}
				}

				mult_modifier = {
					factor = 1.5

					OR = {
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}
				}

				character_event = { id = HF.15103 }
			}

			10 = { # The Winds over [PrimaryTitle] (Drought)
				trigger = {
					OR = {
						has_character_flag = mostly_drought_risk
						has_character_flag = mostly_drought
					}

					NOR = {
						has_character_flag = mostly_heavy_rain
						has_character_flag = mostly_light_rain
					}

					any_realm_province = {
						OR = {
							has_province_modifier = africa_drought_risk
							has_province_modifier = africa_drought
						}

						is_capital = no
						NOT = { has_province_modifier = local_relief_efforts_food }
						held_under_PREV = yes
					}

					capital_scope = {
						NOR = {
							has_province_modifier = local_relief_efforts_food
							has_province_modifier = africa_drought # Can't be completely starving themselves
						}
					}
				}

				mult_modifier = {
					factor = 1.5
					NOT = { has_character_flag = mostly_drought } # Means you have more to share
				}

				character_event = { id = HF.15111 }
			}

			10 = { # Disease outbreak... (Requires Reaper's Due)
				trigger = {
					has_dlc = "Reapers"

					any_demesne_province = {
						has_province_modifier = africa_drought
						owned_by = PREV

						NOR = {
							disease = slow_fever
							has_province_modifier = africa_drought_cooldown_1
						}
					}
				}

				mult_modifier = {
					factor = 1.5

					has_character_flag = mostly_drought

					NOR = {
						has_character_flag = mostly_heavy_rain
						has_character_flag = mostly_light_rain
						has_character_flag = mostly_drought_risk
					}
				}

				mult_modifier = {
					factor = 0.5 # Less likely if all the affected areas have taken precautions earlier...

					NOT = {
						any_demesne_province = {
							has_province_modifier = africa_drought
							NOT = { has_province_modifier = africa_surplus_grain }
							owned_by = PREV
						}
					}
				}

				mult_modifier = {
					factor = 1.5 # More likely if an area has already suffered from extra starvation...

					any_demesne_province = {
						has_province_modifier = africa_drought
						has_province_modifier = africa_drought_cooldown_2
						owned_by = PREV
					}
				}

				character_event = { id = HF.15122 }
			}

			10 = { # Starvation... (notification only)
				trigger = {
					any_demesne_province = {
						has_province_modifier = africa_drought
						NOT = { has_province_modifier = africa_drought_cooldown_2 }
						owned_by = PREV
					}
				}

				mult_modifier = {
					factor = 2

					has_character_flag = mostly_drought

					NOR = {
						has_character_flag = mostly_heavy_rain
						has_character_flag = mostly_light_rain
						has_character_flag = mostly_drought_risk
					}
				}

				mult_modifier = {
					factor = 0.5 # Less likely if all the affected areas have taken precautions earlier...

					NOT = {
						any_demesne_province = {
							has_province_modifier = africa_drought
							NOT = { has_province_modifier = africa_surplus_grain }
							owned_by = PREV
						}
					}
				}

				mult_modifier = {
					factor = 0.5 # Less likely if all the affected areas have taken precautions earlier...

					NOT = {
						any_demesne_province = {
							has_province_modifier = africa_drought
							NOT = { has_province_modifier = local_relief_efforts_food }
							owned_by = PREV
						}
					}
				}

				character_event = { id = HF.15125 }
			}
		}
	}
}

# Positive news (Rain dances had an effect??)
character_event = {
	id = HF.15101
	title = africa_rain_positive_title
	picture = GFX_evt_west_african_ruler
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC_HF_15101_A # Light rain, rain dances
		trigger = {
			event_target:rain_dance_province = {
				has_province_modifier = africa_light_rain
				has_province_modifier = africa_rain_dance_1
			}
		}
	}
	desc = {
		text = EVTDESC_HF_15101_B # Light rain, prosperity festivals
		trigger = {
			event_target:rain_dance_province = {
				has_province_modifier = africa_light_rain
				has_province_modifier = africa_rain_dance_2
			}
		}
	}
	desc = {
		text = EVTDESC_HF_15101_C # Heavy rain, rain dances
		trigger = {
			event_target:rain_dance_province = {
				has_province_modifier = africa_heavy_rain
				has_province_modifier = africa_rain_dance_1
			}
		}
	}
	desc = {
		text = EVTDESC_HF_15101_D # Heavy rain, prosperity festivals
		trigger = {
			event_target:rain_dance_province = {
				has_province_modifier = africa_heavy_rain
				has_province_modifier = africa_rain_dance_2
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		# If things are looking up and you had rain dances...!
		random_demesne_province = {
			limit = {
				owned_by = PREV

				OR = {
					has_province_modifier = africa_light_rain
					has_province_modifier = africa_heavy_rain
				}

				OR = {
					has_province_modifier = africa_rain_dance_1
					has_province_modifier = africa_rain_dance_2
				}
			}

			save_event_target_as = rain_dance_province
		}
	}

	option = { # Our rituals have clearly had an effect!
		name = EVTOPTA_HF_15101

		piety = 25
	}

	option = { # This is all me
		name = EVTOPTB_HF_15101

		prestige = 50
	}

	after = {
		any_demesne_province = {
			show_scope_change = no

			limit = {
				owned_by = PREV

				OR = {
					has_province_modifier = africa_light_rain
					has_province_modifier = africa_heavy_rain
				}

				OR = {
					has_province_modifier = africa_rain_dance_1
					has_province_modifier = africa_rain_dance_2
				}
			}

			hidden_effect = {
				remove_province_modifier = africa_rain_dance_1
				remove_province_modifier = africa_rain_dance_2
			}

			add_province_modifier = {
				name = africa_rain_dance_successful
				years = 10
			}
		}
	}
}

# Positive news (Surprise, things are great - keep it going?)
character_event = {
	id = HF.15102
	title = africa_rain_positive_title
	desc = EVTDESC_HF_15102
	picture = GFX_evt_west_african_ruler
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		random_demesne_province = {
			limit = {
				has_province_modifier = africa_light_rain
				owned_by = PREV

				NOR = {
					has_province_modifier = africa_rain_dance_1
					has_province_modifier = africa_rain_dance_2
				}
			}

			save_event_target_as = rainy_province
		}
	}

	option = { # Hold a festival to make sure it keeps coming!
		name = EVTOPTA_HF_15102

		if = {
			limit = { is_tribal = yes }

			scaled_wealth = {
				value = -0.5
				min = -10
				max = -50
			}
		}
		else = {
			scaled_wealth = {
				value = -1
				min = -15
				max = -550
			}
		}

		piety = 5

		event_target:rainy_province = {
			show_scope_change = no

			add_province_modifier = {
				name = africa_rain_dance_2 # Keep it coming-dance
				years = 10
			}
		}
	}

	option = { # This is good news
		name = EVTOPTB_HF_15102
	}
}

# Negative news (Attempt a rain dance?)
character_event = {
	id = HF.15103
	title = africa_rain_negative_title
	picture = GFX_evt_desert
	border = GFX_event_normal_frame_religion

	desc = {
		text = EVTDESC_HF_15103_A # Risk of drought
		trigger = {
			event_target:drought_province = {
				has_province_modifier = africa_drought_risk
			}
		}
	}
	desc = {
		text = EVTDESC_HF_15103_B # Actual drought
		trigger = {
			event_target:drought_province = {
				has_province_modifier = africa_drought
			}
		}
	}

	is_triggered_only = yes

	immediate = {
		random_demesne_province = {
			limit = {
				owned_by = PREV

				OR = {
					has_province_modifier = africa_drought_risk
					has_province_modifier = africa_drought
				}

				NOR = {
					has_province_modifier = africa_rain_dance_1
					has_province_modifier = africa_rain_dance_2
				}
			}

			save_event_target_as = drought_province
		}
	}

	option = { # Perhaps a rain dance?
		name = EVTOPTA_HF_15103

		if = {
			limit = { is_tribal = yes }

			scaled_wealth = {
				value = -0.1
				min = -5
				max = -15
			}

			prestige = -25
		}

		else = {
			scaled_wealth = {
				value = -1
				min = -15
				max = -550
			}
		}

		event_target:drought_province = {
			show_scope_change = no

			add_province_modifier = {
				name = africa_rain_dance_1 # Praying for water
				duration = -1
			}
		}
	}

	option = { # Do nothing
		name = EVTOPTB_HF_15103
	}
}

# Rains: "The Winds Over <Realm>" (Choose to prepare for the future somehow)
character_event = {
	id = HF.15110
	title = africa_rain_status_title
	desc = EVTDESC_HF_15110
	picture = GFX_evt_market_hf
	border = GFX_event_normal_frame_religion
	portrait = event_target:my_steward

	is_triggered_only = yes

	immediate = {
		job_treasurer = { save_event_target_as = my_steward } # For loc...

		# Calculate how much prestige various options cost, if tribal
		set_variable = {
			which = local_provinces_without_irrigation
			value = 0
		}

		set_variable = {
			which = local_provinces_rivers_lakes
			value = 0
		}

		set_variable = {
			which = local_provinces_roads
			value = 0
		}

		set_variable = {
			which = local_provinces_grain
			value = 0
		}

		any_demesne_province = {
			limit = { owned_by = PREV }

			if = {
				limit = { NOT = { has_province_modifier = improved_irrigation } }

				change_variable = {
					which = local_provinces_without_irrigation
					value = -15
				}
			}

			if = {
				limit = { has_province_modifier = africa_heavy_rain }

				change_variable = {
					which = local_provinces_rivers_lakes
					value = -15
				}

				change_variable = {
					which = local_provinces_roads
					value = -15
				}
			}

			if = {
				limit = {
					OR = {
						has_province_modifier = africa_heavy_rain
						has_province_modifier = africa_light_rain
					}
				}

				change_variable = {
					which = local_provinces_grain
					value = -15
				}
			}
		}

		# Means you have fewer than 4 provinces this is happening to anyway
		if = {
			limit = {
				check_variable = {
					which = local_provinces_without_irrigation
					value > -60
				}
			}

			set_variable = {
				which = local_provinces_without_irrigation
				value = -35
			}
		}

		if = {
			limit = {
				check_variable = {
					which = local_provinces_rivers_lakes
					value > -60
				}
			}

			set_variable = {
				which = local_provinces_rivers_lakes
				value = -35
			}
		}

		if = {
			limit = {
				check_variable = {
					which = local_provinces_roads
					value > -60
				}
			}

			set_variable = {
				which = local_provinces_roads
				value = -35
			}
		}

		if = {
			limit = {
				check_variable = {
					which = local_provinces_grain
					value > -60
				}
			}

			set_variable = {
				which = local_provinces_grain
				value = -35
			}
		}
	}

	option = { # [ALWAYS VISIBLE] Make sure traders are well-stocked
		name = EVTOPTA_HF_15110

		if = {
			limit = { is_tribal = yes }

			scaled_wealth = {
				value = -0.2
				min = -10
				max = -25
			}

			prestige = -50
		}
		else = {
			scaled_wealth = {
				value = -1.5
				min = -20
				max = -700
			}
		}

		capital_scope = {
			show_scope_change = no

			add_province_modifier = {
				name = focused_traders
				years = 4
			}
		}

		remove_trait_silently_greedy_effect = yes
	}

	option = { # [LIGHT RAIN ONLY] Let's look into our irrigation
		name = EVTOPTB_HF_15110_light_rain

		trigger = {
			has_character_flag = mostly_light_rain
			NOT = { has_character_flag = mostly_heavy_rain }

			any_demesne_province = {
				is_capital = no
				NOT = { has_province_modifier = improved_irrigation }
				owned_by = PREV
			}
		}

		if = {
			limit = { is_tribal = yes }

			# Pay some Prestige instead, based around how many of these modifiers you're getting...
			prestige = local_provinces_without_irrigation

			scaled_wealth = { # Also pay less money
				value = -0.1
				min = -5
				max = -10
			}
		}
		else = {
			scaled_wealth = {
				value = -2
				min = -25
				max = -750
			}
		}

		any_demesne_province = {
			show_scope_change = no

			limit = {
				NOT = { has_province_modifier = improved_irrigation }
				owned_by = PREV
			}

			add_province_modifier = {
				name = improved_irrigation
				years = 5
			}
		}
	}

	option = { # [HEAVY RAIN ONLY] Keep an eye on rivers & lakes
		name = EVTOPTB_1_HF_15110

		trigger = {
			has_character_flag = mostly_heavy_rain
			NOT = { has_character_flag = mostly_light_rain }

			any_demesne_province = { # If you have lakes and stuff nearby
				owned_by = PREV

				OR = {
					borders_lake = yes
					borders_major_river = yes
					any_neighbor_province = { is_land = no }
				}
			}
		}

		if = {
			limit = { is_tribal = yes }

			# Pay some Prestige instead, based around how many of these modifiers you're getting...
			prestige = local_provinces_rivers_lakes
		}
		else = {
			scaled_wealth = {
				value = -1
				min = -15
				max = -650
			}
		}

		custom_tooltip = {
			text = water_watch_1_tt

			any_demesne_province = {
				limit = {
					has_province_modifier = africa_heavy_rain
					owned_by = PREV
				}

				add_province_modifier = {
					name = water_watch_1
					years = 5
				}
			}
		}
	}

	option = { # [HEAVY RAIN ONLY] Keep an eye on roads
		name = EVTOPTB_2_HF_15110

		trigger = {
			has_character_flag = mostly_heavy_rain
			NOT = { has_character_flag = mostly_light_rain }

			any_demesne_province = { # If you *don't* have lakes and stuff nearby
				borders_lake = no
				borders_major_river = no
				owned_by = PREV

				NOT = {
					any_neighbor_province = { is_land = no }
				}
			}
		}

		if = {
			limit = { is_tribal = yes }

			# Pay some Prestige instead, based around how many of these modifiers you're getting...
			prestige = local_provinces_roads
		}
		else = {
			scaled_wealth = {
				value = -1
				min = -15
				max = -650
			}
		}

		custom_tooltip = {
			text = water_watch_2_tt

			any_demesne_province = {
				limit = {
					has_province_modifier = africa_heavy_rain
					owned_by = PREV
				}

				add_province_modifier = {
					name = water_watch_2
					years = 5
				}
			}
		}
	}

	option = { # [ALWAYS VISIBLE] We should put away grain for the future
		name = EVTOPTC_HF_15110

		if = {
			limit = { is_tribal = yes }

			# Pay some Prestige instead, based around how many of these modifiers you're getting...
			prestige = local_provinces_grain
		}
		else = {
			scaled_wealth = {
				value = -1
				min = -10
				max = -550
			}
		}

		custom_tooltip = {
			text = africa_surplus_grain_tt

			any_demesne_province = {
				limit = {
					owned_by = PREV

					OR = {
						has_province_modifier = africa_heavy_rain
						has_province_modifier = africa_light_rain
					}
				}

				add_province_modifier = {
					name = africa_surplus_grain
					years = 10
					hidden = yes
				}
			}
		}
	}

	option = { # [ALWAYS VISIBLE] Do nothing
		name = SO_IT_IS
	}
}

# Drought: "The Winds Over <Realm>" (Choose a province to feed)
character_event = {
	id = HF.15111
	title = africa_drought_status_title
	desc = EVTDESC_HF_15110
	picture = GFX_evt_market_hf
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		job_treasurer = { save_event_target_as = my_steward } # For loc...

		# Select a province to randomly help out...
		random_realm_province = {
			limit = {
				held_under_PREV = yes

				OR = {
					has_province_modifier = africa_drought_risk
					has_province_modifier = africa_drought
				}

				is_capital = no
				NOT = { has_province_modifier = local_relief_efforts_food }
			}

			# Prefers to select something you are yourself the liege of...
			preferred_limit = {
				has_province_modifier = africa_drought
				owned_by = PREV
			}

			preferred_limit = {
				owned_by = PREV
			}

			save_event_target_as = province_to_save
		}
	}

	option = { # Feed our capital province
		name = EVTOPTA_HF_15111

		trigger = {
			capital_scope = {
				OR = {
					has_province_modifier = africa_drought_risk
					has_province_modifier = africa_drought
				}
			}
		}

		capital_scope = {
			show_scope_change = no

			custom_tooltip = { text = EVTOPTA_HF_15111_TT }
		}

		if = {
			limit = { is_tribal = yes }

			# Pay some Prestige instead, based around how many of these modifiers you're getting...
			trigger_switch = {
				on_trigger = num_of_count_titles_in_realm

				15 = { prestige = -150 }
				12 = { prestige = -120 }
				 9 = { prestige =  -90 }
				 7 = { prestige =  -70 }
				 5 = { prestige =  -50 }
				 3 = { prestige =  -30 }

				# Means you have a small realm
				fallback = { prestige = -15 }
			}
		}
		else = {
			scaled_wealth = {
				value = -1
				min = -25
				max = -500
			}
		}

		capital_scope = {
			show_scope_change = no

			add_province_modifier = {
				name = local_relief_efforts_food
				years = 4
			}
		}
	}

	option = { # Help random province
		name = EVTOPTB_HF_15111

		trigger = {
			event_target:province_to_save = { always = yes } # Only exists if you have more than one province
		}

		event_target:province_to_save = {
			show_scope_change = no

			custom_tooltip = { text = EVTOPTA_HF_15111_TT }
		}

		if = {
			limit = { is_tribal = yes }

			# Pay some Prestige instead, based around how many of these modifiers you're getting...
			trigger_switch = {
				on_trigger = num_of_count_titles_in_realm

				15 = { prestige = -150 }
				12 = { prestige = -120 }
				 9 = { prestige =  -90 }
				 7 = { prestige =  -70 }
				 5 = { prestige =  -50 }
				 3 = { prestige =  -30 }

				# Means you have a small realm
				fallback = { prestige = -15 }
			}
		}
		else = {
			scaled_wealth = {
				value = -1
				min = -25
				max = -500
			}
		}

		remove_trait_silently_greedy_effect = yes

		event_target:province_to_save = {
			show_scope_change = no

			add_province_modifier = {
				name = local_relief_efforts_food
				years = 4
			}
		}
	}

	option = { # Character modifier (pious)
		name = EVTOPTC_HF_15111

		add_trait_partially_silently_zealous_effect = yes

		add_character_modifier = {
			name = superstitious_ruler
			years = 5
		}
	}

	option = { # Do nothing
		name = SO_IT_IS
	}
}


# Landslide (negative heavy rain)
character_event = {
	id = HF.15121
	title = EVTTITLE_HF_15121
	desc = EVTDESC_HF_15121
	picture = GFX_evt_dead_body_hf
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		random_demesne_province = {
			limit = {
				has_province_modifier = africa_heavy_rain
				owned_by = PREV
			}

			preferred_limit = { terrain = mountain }

			save_event_target_as = flooded_province

			add_province_modifier = {
				name = africa_heavy_rain_cooldown_1
				years = 3
				hidden = yes
			}

			random_province_holding = {
				limit = { num_of_buildings >= 1 }

				save_event_target_as = flooded_holding

				holder_scope = {
					if = { # if the holder of this holding has a few courtiers around...
						limit = {
							any_courtier = {
								count = 3
								ai = yes
							}
						}

						save_event_target_as = flooded_court_liege
					}
					else = { # Otherwise, find someone in the province that *does* have courtiers...
						event_target:flooded_province = {
							random_province_holding = {
								limit = {
									holder_scope = {
										any_courtier = {
											count = 3
											ai = yes
										}
									}
								}

								holder_scope = {
									save_event_target_as = flooded_court_liege
								}
							}
						}
					}
				}

				# Now, use that character's court to find flood_victims...
				event_target:flooded_court_liege = {
					while = {
						count = 3

						random_courtier = {
							limit = { ai = yes }

							preferred_limit = {
								at_location = event_target:flooded_province
								is_rival = ROOT
								prisoner = no
								is_ruler = no
							}
							preferred_limit = {
								is_rival = ROOT
								prisoner = no
								is_ruler = no
							}
							preferred_limit = {
								at_location = event_target:flooded_province
								prisoner = no
								is_ruler = no
							}
							preferred_limit = {
								at_location = event_target:flooded_province
							}

							set_character_flag = flood_victim
						}
					}
				}
			}
		}
	}

	option = { # Save the people (destroy building)
		name = EVTOPTA_HF_15121

		scaled_wealth = {
			value = -1
			min = -35
			max = -350
		}

		piety = 10

		event_target:flooded_holding = {
			show_scope_change = no

			custom_tooltip = {
				text = random_building_is_destroyed_tt
				destroy_random_building = THIS
			}
		}
	}

	option = { # Save ... some people (building destroyed and rival dies)
		name = EVTOPTB_HF_15121_rival
		tooltip_info_custom = available_because_rivals_tt

		trigger = {
			event_target:flooded_court_liege = {
				any_courtier = {
					has_character_flag = flood_victim
					is_rival = ROOT
				}
			}
		}

		custom_tooltip = { text = EVTOPTB_HF_15121_TT }

		scaled_wealth = {
			value = -1
			min = -15
			max = -250
		}

		piety = -10
		add_trait_partially_silently_deceitful_effect = yes

		event_target:flooded_holding = {
			show_scope_change = no

			custom_tooltip = {
				text = random_building_is_destroyed_tt
				destroy_random_building = THIS
			}
		}

		event_target:flooded_court_liege = {
			show_scope_change = no

			any_courtier = {
				show_scope_change = no

				limit = {
					has_character_flag = flood_victim
					is_rival = ROOT
				}

				death = {
					death_reason = death_accident_drowning
					killer = ROOT
				}
			}
		}

		ai_chance = { factor = 100 }
	}

	option = { # Save the buildings (people die)
		name = EVTOPTB_HF_15121

		scaled_wealth = {
			value = -1
			min = -25
			max = -350
		}

		prestige = 20

		event_target:flooded_court_liege = {
			show_scope_change = no

			any_courtier = {
				show_scope_change = no

				limit = { has_character_flag = flood_victim }

				death = {
					death_reason = death_accident_drowning
					killer = ROOT
				}
			}
		}
	}

	option = {
		name = EVTOPTC_HF_15121 # Tragic!

		piety = -5
		prestige = -10

		event_target:flooded_holding = {
			show_scope_change = no

			custom_tooltip = {
				text = random_building_is_destroyed_tt
				destroy_random_building = THIS
			}
		}

		event_target:flooded_court_liege = {
			show_scope_change = no

			any_courtier = {
				show_scope_change = no

				limit = { has_character_flag = flood_victim }

				death = {
					death_reason = death_accident_drowning
					killer = ROOT
				}
			}
		}

		add_trait_fully_silently_cruel_effect = yes
	}
}

# Drought kills people (negative drought)
character_event = {
	id = HF.15122
	title = EVTTITLE_HF_15122
	desc = EVTDESC_HF_15122
	picture = GFX_evt_desert
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			random_demesne_province = {
				limit = {
					has_province_modifier = africa_drought
					NOT = { disease = slow_fever }
					owned_by = PREV
				}

				preferred_limit = {
					terrain = desert
					has_province_modifier = africa_drought_cooldown_2
				}
				preferred_limit = {
					terrain = desert
				}
				preferred_limit = {
					has_province_modifier = africa_drought_cooldown_2
				}

				save_event_target_as = starved_province

				random_province_holding = {
					holder_scope = {
						while = {
							count = 3

							random_courtier = {
								limit = {
									ai = yes

									NOR = {
										has_character_flag = starvation_victim
										has_character_flag = immune_slow_fever
									}
								}

								set_character_flag = starvation_victim
								add_trait = slow_fever
								set_character_flag = manifest_slow_fever
								add_disease_level_effect = yes
								scrying_omen_fulfilled_by_gaining_disease_effect = yes
								clr_character_flag = developing_illness
								clr_character_flag = got_slow_fever
							}
						}
					}
				}
			}
		}
	}

	option = { # Kill whoever is currently sick...
		name = EVTOPTB_HF_15122
		tooltip_info = intrigue

		trigger = { intrigue >= 10 }

		custom_tooltip = { text = EVTOPTB_HF_15122_TT }

		scaled_wealth = {
			value = -1
			min = -15
			max = -250
		}

		piety = -10

		if = {
			limit = { NOT = { trait = paranoid } }

			remove_trait_silently_trusting_effect = yes
			add_trait = paranoid
		}
		else_if = {
			limit = { trait = honest }
			remove_trait = honest
		}
		else_if = {
			limit = { NOT = { trait = deceitful } }
			add_trait = deceitful
		}
		else_if = {
			limit = { trait = kind }
			remove_trait = kind
		}
		else_if = {
			limit = { NOT = { trait = cruel } }
			add_trait = cruel
		}

		any_realm_character = {
			show_scope_change = no

			limit = { has_character_flag = starvation_victim }

			random_accident_death_effect = yes
		}

		ai_chance = { factor = 100 }
	}

	option = { # Spend money to recruit builders...
		name = EVTOPTC_HF_15122

		trigger = {
			NOT = { has_character_modifier = relief_efforts_builders }
		}

		prestige = 15

		scaled_wealth = {
			value = -3
			min = -65
			max = -850
		}

		add_character_modifier = {
			name = relief_efforts_builders
			years = 5
		}

		custom_tooltip = {
			text = spawn_slow_fever_tt

			event_target:starved_province = {
				spawn_disease = slow_fever

				add_province_modifier = {
					name = africa_drought_cooldown_1
					years = 3
					hidden = yes
				}
			}
		}
	}

	option = { # Start disease...
		name = EVTOPTA_HF_15122

		custom_tooltip = {
			text = spawn_slow_fever_tt

			event_target:starved_province = {
				spawn_disease = slow_fever

				add_province_modifier = {
					name = africa_drought_cooldown_1
					years = 3
					hidden = yes
				}
			}
		}
	}
}

# Rotting Library (negative heavy rain)
character_event = {
	id = HF.15123
	title = EVTTITLE_HF_15123
	desc = EVTDESC_HF_15123
	picture = GFX_evt_monk
	border = GFX_event_normal_frame_religion
	portrait = event_target:my_spiritual

	is_triggered_only = yes

	immediate = {
		random_demesne_province = {
			limit = {
				has_province_modifier = africa_heavy_rain
				NOT = { has_province_modifier = africa_heavy_rain_cooldown_2 }
				owned_by = PREV
			}

			save_event_target_as = flooded_province

			add_province_modifier = {
				name = africa_heavy_rain_cooldown_2
				years = 3
				hidden = yes
			}
		}

		random_artifact = {
			limit = {
				has_artifact_flag = book
				is_indestructible = no
			}
			preferred_limit = { is_artifact_equipped = yes } # Means it reads as in your "Library" in the Treasury UI

			save_event_target_as = target_artifact
		}

		job_spiritual = { save_event_target_as = my_spiritual } # For loc...
	}

	option = { # Spend money to save the book...
		name = EVTOPTA_HF_15123

		scaled_wealth = {
			value = -2
			min = -55
			max = -750
		}

		reverse_opinion = {
			name = opinion_agreed_with_opinion
			who = event_target:my_spiritual
			years = 5
		}

		set_character_flag = had_book_event
	}

	option = { # Let the book be destroyed
		name = EVTOPTB_HF_15123

		event_target:target_artifact = {
			show_scope_change = no

			destroy_artifact = yes
		}
	}
}

# Flooded Armory (negative heavy rain)
character_event = {
	id = HF.15124
	title = EVTTITLE_HF_15124
	desc = EVTDESC_HF_15124
	picture = GFX_evt_armory
	border = GFX_event_normal_frame_religion
	portrait = event_target:my_marshal

	is_triggered_only = yes

	immediate = {
		random_demesne_province = {
			limit = {
				has_province_modifier = africa_heavy_rain
				NOT = { has_province_modifier = africa_heavy_rain_cooldown_3 }
				owned_by = PREV
			}

			save_event_target_as = flooded_province

			add_province_modifier = {
				name = africa_heavy_rain_cooldown_3
				years = 3
				hidden = yes
			}
		}

		random_artifact = {
			limit = {
				OR = {
					has_artifact_flag = armor
					has_artifact_flag = combat_weapon
				}
				is_indestructible = no
			}

			preferred_limit = {
				is_artifact_equipped = no # In case you are out and about
			}

			save_event_target_as = target_artifact
		}

		job_marshal = { save_event_target_as = my_marshal } # For loc...
	}

	option = { # Spend money to save the weapon/armor...
		name = EVTOPTA_HF_15124

		scaled_wealth = {
			value = -2
			min = -55
			max = -750
		}

		reverse_opinion = {
			name = opinion_was_praised
			who = event_target:my_marshal
			years = 5
		}

		set_character_flag = had_weapon_event
	}

	option = { # Let the book be destroyed
		name = EVTOPTB_HF_15124

		event_target:target_artifact = {
			show_scope_change = no

			destroy_artifact = yes
		}
	}
}

# People are suffering from the drought. (negative drought)
character_event = {
	id = HF.15125
	picture = GFX_evt_desert

	desc = {
		text = EVTDESC_HF_15125_A # People are starving...
		trigger = {
			NOT = { event_target:starving_province = { has_province_modifier = local_relief_efforts_food } }
		}
	}
	desc = {
		text = EVTDESC_HF_15125_B # In spite of our efforts, people are starving..
		trigger = {
			event_target:starving_province = { has_province_modifier = local_relief_efforts_food }
		}
	}
	desc = {
		text = EVTDESC_HF_15125_C # In spite of storages, people are starving..
		trigger = {
			event_target:starving_province = { has_province_modifier = africa_surplus_grain }
		}
	}

	is_triggered_only = yes
	notification = yes

	immediate = {
		random_demesne_province = {
			limit = {
				has_province_modifier = africa_drought
				NOT = { has_province_modifier = africa_drought_cooldown_2 }
				owned_by = PREV
			}

			preferred_limit = {
				NOR = {
					has_province_modifier = africa_surplus_grain
					has_province_modifier = local_relief_efforts_food
				}
			}
			preferred_limit = {
				NOT = { has_province_modifier = local_relief_efforts_food }
			}
			preferred_limit = {
				NOT = { has_province_modifier = africa_surplus_grain }
			}

			save_event_target_as = starving_province

			add_province_modifier = {
				name = africa_drought_cooldown_2
				years = 1
				hidden = yes
			}

			holder_scope = {
				any_courtier = {
					lose_weight_medium_effect = yes
					weight_trait_check_effect = yes
				}
			}
		}
	}

	option = {
		name = OK
	}
}