############################
# INHERITANCE OF GIANTS (ap_inheritance_of_giants)
# apb_giants.1  perk taken: enable the Deep Archive Survey special project
# apb_giants.2  project done (or retry): hidden dispatcher
# apb_giants.3  choose one of three ruins
# apb_giants.4  no suitable system yet (retries every year)
# apb_giants.5  the ruin has been found
# apb_giants.6  nothing left to find (every type already owned)
# Scripted effects: common/scripted_effects/apb_inheritance_of_giants_effects.txt
############################

namespace = apb_giants

# Perk taken
country_event = {
	id = apb_giants.1
	title = apb_giants.1.name
	desc = apb_giants.1.desc
	picture = GFX_evt_ancient_records
	show_sound = event_default
	is_triggered_only = yes

	immediate = {
		enable_special_project = {
			name = "APB_DEEP_ARCHIVE_SURVEY_PROJECT"
			owner = root
			location = capital_scope
		}
	}

	option = {
		name = apb_giants.1.a
	}
}

# Survey complete (fired by the special project, or by the yearly retry)
country_event = {
	id = apb_giants.2
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		apb_giants_check_types = yes
		if = {
			limit = {
				NOR = {
					has_country_flag = apb_giants_ok_think_tank
					has_country_flag = apb_giants_ok_spy_orb
					has_country_flag = apb_giants_ok_mega_art_installation
					has_country_flag = apb_giants_ok_strategic_coordination_center
					has_country_flag = apb_giants_ok_interstellar_assembly
					has_country_flag = apb_giants_ok_mega_shipyard
				}
			}
			apb_giants_clear_flags = yes
			country_event = { id = apb_giants.6 }
		}
		else_if = {
			limit = {
				NOT = {
					any_system_within_border = {
						exists = starbase
						has_no_non_gate_megastructure = yes
						NOT = { any_system_planet = { is_planet_class = pc_cosmogenesis_world } }
						NOT = { has_star_flag = apb_giants_site }
					}
				}
			}
			apb_giants_clear_flags = yes
			country_event = { id = apb_giants.4 }
			country_event = { id = apb_giants.2 days = 360 }
		}
		else = {
			apb_giants_pick_one = yes
			apb_giants_pick_one = yes
			apb_giants_pick_one = yes
			country_event = { id = apb_giants.3 }
		}
	}
}

# The choice
country_event = {
	id = apb_giants.3
	title = apb_giants.3.name
	desc = apb_giants.3.desc
	picture = GFX_evt_ancient_databank
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_giants.3.think_tank
		trigger = { has_country_flag = apb_giants_offer_think_tank }
		custom_tooltip = apb_giants_ruin_tooltip
		hidden_effect = {
			apb_giants_spawn_ruin = { TYPE = think_tank_ruined }
		}
	}
	option = {
		name = apb_giants.3.spy_orb
		trigger = { has_country_flag = apb_giants_offer_spy_orb }
		custom_tooltip = apb_giants_ruin_tooltip
		hidden_effect = {
			apb_giants_spawn_ruin = { TYPE = spy_orb_ruined }
		}
	}
	option = {
		name = apb_giants.3.mega_art_installation
		trigger = { has_country_flag = apb_giants_offer_mega_art_installation }
		custom_tooltip = apb_giants_ruin_tooltip
		hidden_effect = {
			apb_giants_spawn_ruin = { TYPE = mega_art_installation_ruined }
		}
	}
	option = {
		name = apb_giants.3.strategic_coordination_center
		trigger = { has_country_flag = apb_giants_offer_strategic_coordination_center }
		custom_tooltip = apb_giants_ruin_tooltip
		hidden_effect = {
			apb_giants_spawn_ruin = { TYPE = strategic_coordination_center_ruined }
		}
	}
	option = {
		name = apb_giants.3.interstellar_assembly
		trigger = { has_country_flag = apb_giants_offer_interstellar_assembly }
		custom_tooltip = apb_giants_ruin_tooltip
		hidden_effect = {
			apb_giants_spawn_ruin = { TYPE = interstellar_assembly_ruined }
		}
	}
	option = {
		name = apb_giants.3.mega_shipyard
		trigger = { has_country_flag = apb_giants_offer_mega_shipyard }
		custom_tooltip = apb_giants_ruin_tooltip
		hidden_effect = {
			apb_giants_spawn_ruin = { TYPE = mega_shipyard_ruined }
		}
	}
}

# No suitable system inside our borders: try again in a year
country_event = {
	id = apb_giants.4
	title = apb_giants.4.name
	desc = apb_giants.4.desc
	picture = GFX_evt_space_debris
	show_sound = event_default
	is_triggered_only = yes

	trigger = {
		NOT = { has_country_flag = apb_giants_waiting_shown }
	}

	immediate = {
		set_country_flag = apb_giants_waiting_shown
	}

	option = {
		name = apb_giants.4.a
	}
}

# The ruin has been found
country_event = {
	id = apb_giants.5
	title = apb_giants.5.name
	desc = apb_giants.5.desc
	picture = GFX_evt_space_debris
	show_sound = event_default
	location = event_target:apb_giants_site
	is_triggered_only = yes

	immediate = {
		random_system_within_border = {
			limit = { has_star_flag = apb_giants_site }
			save_event_target_as = apb_giants_site
		}
	}

	option = {
		name = apb_giants.5.a
	}
}

# Every type is already ours: the archive yields knowledge instead
country_event = {
	id = apb_giants.6
	title = apb_giants.6.name
	desc = apb_giants.6.desc
	picture = GFX_evt_ancient_databank
	show_sound = event_default
	is_triggered_only = yes

	option = {
		name = apb_giants.6.a
		add_monthly_resource_mult = {
			resource = engineering_research
			value = @tier3researchreward
			min = @tier3researchmin
			max = @tier3researchmax
		}
	}
}
