@stage_1_research_bonus	= 75
@stage_2_research_bonus	= 150
@stage_3_research_bonus	= 225
@stage_4_research_bonus	= 250
@entity_x				= 0
@entity_y 				= -20


think_tank_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no

	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }

	build_time = 360
	build_cost = {
		minerals = 10000
		influence = 300
	}

	maintenance = {
		energy = 25
	}
	
	potential = {
		has_ascension_perk = ap_galactic_wonders
	}
	
	possible = {
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
	}
	
	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				#has_any_megastructure = no
				has_no_non_gate_megastructure = yes
				NOR = {
					has_planet_flag = megastructure
					has_planet_flag = has_megastructure
					#solar_system = {
						#has_any_megastructure = yes
						#has_no_non_gate_megastructure = no
					#}
				}
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_think_tank"
				from = { NOT = { has_country_flag = built_think_tank } }
			}			
			custom_tooltip = {
				fail_text = "requires_survey_not_habitable"
				is_surveyed = {			# prevent leaking habitability information
					who = prev.from
					status = yes
				}
				colonizeable_planet = no
			}
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				NOT = { has_anomaly = yes }
			}

 			# balance for think tanks
			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_ring_world"
				is_ringworld = no
			}
		} # use these for all non-star megastructures
	}
	
	# root = system
	# from = country	
	ai_weight = {
		factor = 10
		modifier = {
			factor = 0.1
			starbase = { NOT = { has_starbase_size >= starbase_starfortress } }
		}	

		modifier = {
			factor = 0.1
			any_neighbor_system = { 
				NOT = { 
					owner = { is_same_value = from } 
				}
			}
		}		
		
		modifier = {
			factor = 2.0
			from = {
				OR = {
					has_ethic = ethic_materialist
					has_ethic = ethic_fanatic_materialist
				}			
			}
		}
	}
	
	on_build_start = {}
	on_build_cancel = {}
	on_build_complete = {
		set_star_flag = think_tank_built
		fromfrom.planet = {
			set_planet_flag = has_megastructure
		}
		from = { set_country_flag = built_think_tank }
	}
}

think_tank_1 = {
	entity = "thinktank_phase_01_entity"
	construction_entity = "thinktank_phase_01_entity"
	portrait = "GFX_megastructure_construction_background"
	
	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }
	
	upgrade_from = {
		think_tank_0
	}

	build_time = 480
	build_cost = {
		minerals = 30000
	}
	
	possible = {
		from = { has_ascension_perk = ap_galactic_wonders }
	}

	monthly_production = {
		society_research = @stage_1_research_bonus
		engineering_research = @stage_1_research_bonus
		physics_research = @stage_1_research_bonus
	}

	maintenance = {
		energy = 50
	}
}

think_tank_2 = {
	entity = "thinktank_phase_02_entity"
	construction_entity = "thinktank_phase_02_entity"
	portrait = "GFX_megastructure_construction_background"

	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }
	
	upgrade_from = {
		think_tank_1
	}

	build_time = 480
	build_cost = {
		minerals = 30000
	}
	
	possible = {
		from = { has_ascension_perk = ap_galactic_wonders }
	}
	
	monthly_production = {
		society_research = @stage_2_research_bonus
		engineering_research = @stage_2_research_bonus
		physics_research = @stage_2_research_bonus
	}

	maintenance = {
		energy = 75
	}
}

think_tank_3 = {
	entity = "thinktank_phase_03_entity"
	construction_entity = "thinktank_phase_03_entity"
	portrait = "GFX_megastructure_think_tank_background"

	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }
	
	upgrade_from = {
		think_tank_2
	}

	build_time = 480
	build_cost = {
		minerals = 30000
	}
	
	possible = {
		from = { has_ascension_perk = ap_galactic_wonders }
	}
	
	monthly_production = {
		society_research = @stage_3_research_bonus
		engineering_research = @stage_3_research_bonus
		physics_research = @stage_3_research_bonus
	}

	maintenance = {
		energy = 75
	}
}

think_tank_4 = {
	entity = "thinktank_phase_03_entity"
	construction_entity = "thinktank_phase_03_entity"
	portrait = "GFX_megastructure_think_tank_background"

	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }

	# used from script only
	upgrade_desc = hide
	potential = { always = no }
	
	upgrade_from = {
		think_tank_3
	}

	build_time = 4
	
	monthly_production = {
		society_research = @stage_4_research_bonus
		engineering_research = @stage_4_research_bonus
		physics_research = @stage_4_research_bonus
	}

	maintenance = {
		energy = 100
	}
}

# Ruined Science Nexus
think_tank_ruined = {
	entity = "think_tank_destroyed_01_entity"
	portrait = "GFX_megastructure_construction_background"

	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }

	potential = {
		always = no
	}
}

# Restored Science Nexus
think_tank_restored = {
	entity = "thinktank_phase_03_entity"
	construction_entity = "thinktank_phase_03_entity"
	portrait = "GFX_megastructure_think_tank_background"

	place_entity_on_planet_plane = no
	entity_offset = { x = @entity_x y = @entity_y }

	upgrade_from = {
		think_tank_ruined
	}
	build_time = 960
	build_cost = {
		minerals = 30000
	}

	monthly_production = {
		society_research = @stage_3_research_bonus
		engineering_research = @stage_3_research_bonus
		physics_research = @stage_3_research_bonus
	}
	
	maintenance = {
		energy = 100
	}

	possible = {
		from = { has_technology = tech_mega_engineering }	
	}

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

	on_build_complete = {
		every_system_ambient_object = { destroy_ambient_object = this }
		from = {
			country_event = { id = utopia.2013 }
		}
	}
}
