# Mega Art Installation
mega_art_installation_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = yes
	entity_offset = { x = -27 y = -27 }
	build_time = 1800
	resources = {
		category = megastructures
		cost = {
			unity = 2500
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 5000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 5000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 5000
			mult = @halved_alloy_to_food_cost_ratio
		}

		upkeep = {
			energy = 5
		}
	}

	custom_tooltip_requirements = "MEGASTRUCTURE_TOOLTIP_REQUIREMENTS_ONE_PER_COUNTRY"

	prerequisites = { "tech_mega_art" }

	possible = {
		hidden_trigger = {
			exists = starbase
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_megastructure"
			has_no_non_gate_megastructure = yes
			NOT = {
				any_system_planet = {
					is_planet_class = pc_cosmogenesis_world
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_surveyed_system"
			NOT = {
				any_system_planet = {
					is_surveyed = {
						who = prev.from
						status = no
					}
				}
			}
		}

		custom_tooltip = {
			fail_text = "requires_no_existing_mega_art_installation"
			from = {
				OR = {
					has_relic = r_contingency_core
					NOT = { has_country_flag = built_mega_art_installation }
				}
			}
		}
		custom_tooltip = {
			fail_text = "requires_no_existing_mega_art_installation_two"
			from = { NOT = { has_country_flag = built_mega_art_installation_contingency } }
		}
	}

	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_survey_not_habitable"
				is_surveyed = {			# prevent leaking habitability information
					who = prev.from
					status = yes
				}
				colonizable_planet = no
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}
			custom_tooltip = {
				fail_text = "requires_not_minor_planetary_body"
				NOR = {
					is_asteroid = yes
					is_moon = yes
				}
			}
			custom_tooltip = {
				fail_text = "requires_not_star"
				is_star = no
			}
			custom_tooltip = {
				fail_text = "requires_not_astral_scar"
				is_astral_scar = no
			}
			custom_tooltip = {
				fail_text = "requires_not_ring_world"
				is_ringworld = no
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				NOT = { has_planet_flag = megastructure }
			}
		}
	}

	# root = system
	# from = country
	ai_weight = {
		factor = 15

		modifier = {
			factor = 0.1
			starbase = { NOT = { has_starbase_size >= starbase_starfortress } }
		}

		modifier = {
			factor = 0.1
			any_neighbor_system = {
				exists = owner
				NOT = {
					owner = { is_same_value = from }
				}
			}
		}
	}

	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		from = {
			if = {
				limit = {
					has_relic = r_contingency_core
					has_country_flag = built_mega_art_installation
				}
				set_country_flag = built_mega_art_installation_contingency
			}
			set_country_flag = built_mega_art_installation
		}
	}
}

# Mega Art Installation 1
mega_art_installation_1 = {
	entity = "mega_art_institution_stage_1_entity"
	construction_entity = "mega_art_institution_stage_1_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			unity = 2500
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 15000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 15000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 15000
			mult = @halved_alloy_to_food_cost_ratio
		}

		produces = {
			unity = 100
		}

		upkeep = {
			energy = 10
		}
	}

	upgrade_from = {
		mega_art_installation_0
	}

	prerequisites = { tech_mega_art }

	country_modifier = {
		planet_amenities_mult = 0.05
		planetary_ascension_cost_mult = -0.05
	}

	on_build_complete = {
		from = { country_event = { id = mega.9000 } }
	}
}

# Mega Art Installation 2
mega_art_installation_2 = {
	entity = "mega_art_institution_stage_2_entity"
	construction_entity = "mega_art_institution_stage_2_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			unity = 2500
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 15000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 15000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 15000
			mult = @halved_alloy_to_food_cost_ratio
		}

		produces = {
			unity = 200
		}

		upkeep = {
			energy = 20
		}
	}

	upgrade_from = {
		mega_art_installation_1
	}

	prerequisites = { "tech_mega_art" }

	country_modifier = {
		planet_amenities_mult = 0.10
		planetary_ascension_cost_mult = -0.1
	}

	on_build_complete = {
		from = { country_event = { id = mega.9001 } }
	}
}

# Mega Art Installation
mega_art_installation_3 = {
	entity = "mega_art_institution_stage_3_entity"
	construction_entity = "mega_art_institution_stage_3_entity"
	portrait = "GFX_mega_art_installation_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			unity = 2500
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 15000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 15000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 15000
			mult = @halved_alloy_to_food_cost_ratio
		}

		produces = {
			unity = 300
		}

		upkeep = {
			energy = 30
		}
	}

	upgrade_from = {
		mega_art_installation_2
	}

	prerequisites = { "tech_mega_art" }
	show_prereqs = yes

	country_modifier = {
		planet_amenities_mult = 0.15
		planetary_ascension_cost_mult = -0.15
	}

	on_build_complete = {
		set_star_flag = mega_art_installation_built
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = mega.9002 }
		}
	}
}

mega_art_installation_4 = {
	entity = "mega_art_institution_stage_3_entity"
	construction_entity = "mega_art_institution_stage_3_entity"
	portrait = "GFX_mega_art_installation_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			minor_artifacts = 2000
			unity = 2500
		}

		produces = {
			unity = 400
		}

		upkeep = {
			energy = 30
		}
	}

	upgrade_from = {
		mega_art_installation_3
	}

	prerequisites = { "tech_mega_art" }
	show_prereqs = no

	possible = {
		from = {
			has_ancrel = yes
			if = { #otherwise, it will pause building any multitier megas
				limit = { is_ai = yes }
				resource_stockpile_compare = {
					resource = minor_artifacts
					value >= 2000
				}
			}
		}
	}

	country_modifier = {
		planet_amenities_mult = 0.2
		planetary_ascension_cost_mult = -0.2
	}

	on_build_complete = {
		set_star_flag = mega_art_installation_built
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = ancrel.10030 }
		}
	}
}

# Permanently Ruined Mega Art Installation
mega_art_installation_permanently_ruined = {
	entity = mega_art_institution_01_destroyed_entity
	construction_entity = "mega_art_institution_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	show_galactic_map_icon = no
	show_in_outliner = no

	potential = {
		always = no
	}
}

# Ruined Mega Art Installation
mega_art_installation_ruined = {
	entity = mega_art_institution_01_destroyed_entity
	construction_entity = "mega_art_institution_01_destroyed_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }

	potential = {
		always = no
	}
}

# Mega Art Installation
mega_art_installation_restored = {
	entity = "mega_art_institution_stage_3_entity"
	construction_entity = "mega_art_institution_stage_3_entity"
	portrait = "GFX_mega_art_installation_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 4800
	resources = {
		category = megastructures
		cost = {
			unity = 3200
		}
		cost = {
			trigger = {
				country_uses_bio_ships = no
			}
			alloys = 15000
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			alloys = 15000
			mult = 0.5
		}
		cost = {
			trigger = {
				country_uses_bio_ships = yes
			}
			food = 15000
			mult = @halved_alloy_to_food_cost_ratio
		}

		produces = {
			unity = 300
		}

		upkeep = {
			energy = 30
		}
	}

	upgrade_from = {
		mega_art_installation_ruined
	}

	possible = {
		from = { has_technology = tech_mega_engineering }
	}

	country_modifier = {
		planet_amenities_mult = 0.15
		planetary_ascension_cost_mult = -0.15
	}

	on_build_complete = {
		set_star_flag = mega_art_installation_built
		every_system_ambient_object = {
			limit = {
				OR = {
					is_ambient_object_type = large_debris_object
					is_ambient_object_type = medium_debris_01_object
					is_ambient_object_type = medium_debris_02_object
					is_ambient_object_type = small_debris_object
				}
			}
			destroy_ambient_object = this
		}
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = mega.9121 }
		}
	}

	on_build_start = {
		fromfrom = {
			set_graphical_culture = root.from
		}
	}

	potential = {
		has_ancrel = yes
	}
}

mega_art_installation_restored_2 = {
	entity = "mega_art_institution_stage_3_entity"
	construction_entity = "mega_art_institution_stage_3_entity"
	portrait = "GFX_mega_art_installation_background"
	place_entity_on_planet_plane = no
	entity_offset = { x = -27 y = -27 }
	build_time = 3600
	resources = {
		category = megastructures
		cost = {
			minor_artifacts = 2000
			unity = 3200
		}

		produces = {
			unity = 400
		}

		upkeep = {
			energy = 30
		}
	}

	upgrade_from = {
		mega_art_installation_restored
	}

	prerequisites = { "tech_mega_art" }
	show_prereqs = no

	country_modifier = {
		planet_amenities_mult = 0.2
		planetary_ascension_cost_mult = -0.2
	}

	possible = {
		from = {
			has_ancrel = yes
			if = { #otherwise, it will pause building any multitier megas
				limit = { is_ai = yes }
				resource_stockpile_compare = {
					resource = minor_artifacts
					value >= 2000
				}
			}
		}
	}

	on_build_complete = {
		set_star_flag = mega_art_installation_built
		from = {
			set_country_flag = has_built_or_repaired_megastructure
			country_event = { id = ancrel.10030 }
		}
	}
}
