###########################
# Prophetic Dreams (ap_prophetic_dreams)
###########################
namespace = apb_dreams

# Draw three visions (no repeats), each with a 1-in-10 chance to be a true dream,
# plus a patron vision for empires with a covenant.
# Fired by the perk's on_enabled; each offer schedules the next one five years later,
# so a new vision is ready as the previous one (5 years) runs out.
country_event = {
	id = apb_dreams.1
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_ascension_perk = ap_prophetic_dreams
	}

	immediate = {
		apb_dreams_clear_offer = yes
		while = {
			count = 3
			apb_dreams_pick_one = yes
		}
		if = {
			limit = { has_any_covenant = yes }
			set_country_flag = apb_dream_patron_offer
		}
		country_event = { id = apb_dreams.2 }
		country_event = { id = apb_dreams.1 days = 1800 }
	}
}

# The visions
country_event = {
	id = apb_dreams.2
	title = apb_dreams.2.name
	desc = apb_dreams.2.desc
	picture = GFX_evt_surreal_visions
	show_sound = event_mystic_reveal
	is_triggered_only = yes

	option = {
		name = apb_dreams.option.war
		trigger = { has_country_flag = apb_dream_offer_war }
		apb_dreams_take = { V = war }
	}
	option = {
		name = apb_dreams.option.growth
		trigger = { has_country_flag = apb_dream_offer_growth }
		apb_dreams_take = { V = growth }
	}
	option = {
		name = apb_dreams.option.discovery
		trigger = { has_country_flag = apb_dream_offer_discovery }
		apb_dreams_take = { V = discovery }
	}
	option = {
		name = apb_dreams.option.wealth
		trigger = { has_country_flag = apb_dream_offer_wealth }
		apb_dreams_take = { V = wealth }
	}
	option = {
		name = apb_dreams.option.industry
		trigger = { has_country_flag = apb_dream_offer_industry }
		apb_dreams_take = { V = industry }
	}
	option = {
		name = apb_dreams.option.unity
		trigger = { has_country_flag = apb_dream_offer_unity }
		apb_dreams_take = { V = unity }
	}
	option = {
		name = apb_dreams.option.harmony
		trigger = { has_country_flag = apb_dream_offer_harmony }
		apb_dreams_take = { V = harmony }
	}
	option = {
		name = apb_dreams.option.building
		trigger = { has_country_flag = apb_dream_offer_building }
		apb_dreams_take = { V = building }
	}
	option = {
		name = apb_dreams.option.voyage
		trigger = { has_country_flag = apb_dream_offer_voyage }
		apb_dreams_take = { V = voyage }
	}
	option = {
		name = apb_dreams.option.war_true
		trigger = { has_country_flag = apb_dream_true_war }
		apb_dreams_take_true = { V = war }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.growth_true
		trigger = { has_country_flag = apb_dream_true_growth }
		apb_dreams_take_true = { V = growth }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.discovery_true
		trigger = { has_country_flag = apb_dream_true_discovery }
		apb_dreams_take_true = { V = discovery }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.wealth_true
		trigger = { has_country_flag = apb_dream_true_wealth }
		apb_dreams_take_true = { V = wealth }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.industry_true
		trigger = { has_country_flag = apb_dream_true_industry }
		apb_dreams_take_true = { V = industry }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.unity_true
		trigger = { has_country_flag = apb_dream_true_unity }
		apb_dreams_take_true = { V = unity }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.harmony_true
		trigger = { has_country_flag = apb_dream_true_harmony }
		apb_dreams_take_true = { V = harmony }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.building_true
		trigger = { has_country_flag = apb_dream_true_building }
		apb_dreams_take_true = { V = building }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.voyage_true
		trigger = { has_country_flag = apb_dream_true_voyage }
		apb_dreams_take_true = { V = voyage }
		ai_chance = { factor = 0.5 }
	}
	option = {
		name = apb_dreams.option.patron_eater
		trigger = {
			has_country_flag = apb_dream_patron_offer
			has_covenant_with_the_eater_of_worlds = yes
		}
		add_modifier = {
			modifier = apb_dream_patron_eater
			years = 5
		}
	}
	option = {
		name = apb_dreams.option.patron_desire
		trigger = {
			has_country_flag = apb_dream_patron_offer
			has_covenant_with_the_instrument_of_desire = yes
		}
		add_modifier = {
			modifier = apb_dream_patron_desire
			years = 5
		}
	}
	option = {
		name = apb_dreams.option.patron_composer
		trigger = {
			has_country_flag = apb_dream_patron_offer
			has_covenant_with_the_composer_of_strands = yes
		}
		add_modifier = {
			modifier = apb_dream_patron_composer
			years = 5
		}
	}
	option = {
		name = apb_dreams.option.patron_cradle
		trigger = {
			has_country_flag = apb_dream_patron_offer
			has_covenant_with_the_cradle_of_souls = yes
		}
		add_modifier = {
			modifier = apb_dream_patron_cradle
			years = 5
		}
	}
	option = {
		name = apb_dreams.option.patron_whisperers
		trigger = {
			has_country_flag = apb_dream_patron_offer
			has_covenant_with_whisperers_in_the_void = yes
		}
		add_modifier = {
			modifier = apb_dream_patron_whisperers
			years = 5
		}
	}
	option = {
		name = apb_dreams.option.patron_cycle
		trigger = {
			has_country_flag = apb_dream_patron_offer
			has_covenant_with_end_of_the_cycle = yes
		}
		add_modifier = {
			modifier = apb_dream_patron_cycle
			years = 5
		}
	}

	after = {
		hidden_effect = {
			apb_dreams_clear_offer = yes
		}
	}
}
