#site
stellar_manipulator_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	entity_offset = {
		x = -7
		y = -7
	}
	build_time = 1260
	resources = {
		category = megastructures
		cost = {
			alloys = 5000
			unity = @giga_kilo_unity_cost
		}
		upkeep = {
			energy = 5
		}
	}
	construction_blocks_and_blocked_by = none
	prerequisites = {
		"tech_gigas_stellar_manip_2"
	}
	possible = {
		from = {
			is_ai = no
		}
		custom_tooltip = {
			fail_text = "requires_inside_border"
			is_inside_border = from
		}
	}
	placement_rules = {
		planet_possible = {
			custom_tooltip = {
				fail_text = "requires_no_anomaly"
				has_anomaly = no
			}
			custom_tooltip = {
				fail_text = "requires_no_existing_megastructure"
				planet_has_no_megastructure = yes
			}
			custom_tooltip = {
				fail_text = "requires_survey_not_habitable"
				is_surveyed = {
					who = prev.from
					status = yes
				}
				is_planet_habitable = no
			}
			custom_tooltip = {
				fail_text = "requires_standard_planet_class"
				stmp_is_valid_star = yes
			}
			custom_tooltip = {
				fail_text = "requires_no_habitable_planets"
				NOT = {
					solar_system = {
						any_system_planet = {
							is_planet_habitable = yes
						}
					}
				}
			}
		}
	}
	ai_weight = {
		factor = 10
		#maybe i should actually make weights for once, maybe not
	}
	on_build_complete = {
		fromfrom.planet = {
			set_planet_flag = has_megastructure
			set_planet_flag = megastructure
		}
		save_event_target_as = star_manip_system
		owner = {
			country_event = {
				id = stellar_manip.101
			}
		}
	}
}

#full
stellar_manipulator_1 = {
	entity = "stellar_manip_full_nobeam_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	build_time = 1260
	resources = {
		category = megastructures
		cost = {
			unity = @giga_kilo_unity_cost
		}
		cost = {
			trigger = {
				this.planet = {
					giga_is_o_star_for_megas = yes
				}
			}
			alloys = @manip_alloy_cost_o_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_b_star
				}
			}
			alloys = @manip_alloy_cost_b_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_m_giant_star
				}
			}
			alloys = @manip_alloy_cost_m_giant_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_a_star
				}
			}
			alloys = @manip_alloy_cost_a_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_f_star
				}
			}
			alloys = @manip_alloy_cost_f_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_g_star
				}
			}
			alloys = @manip_alloy_cost_g_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_k_star
				}
			}
			alloys = @manip_alloy_cost_k_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_m_star
				}
			}
			alloys = @manip_alloy_cost_m_star
		}
		cost = {
			trigger = {
				this.planet = {
					is_planet_class = pc_gigaignited_star
				}
			}
			alloys = @manip_alloy_cost_ignited_star
		}
		upkeep = {
			energy = 50
		}
	}
	upgrade_from = {
		stellar_manipulator_0
	}
	prerequisites = {
		"tech_gigas_stellar_manip_2"
	}
	ai_weight = {
		factor = 10
		#maybe i should actually make weights for once, maybe not
	}
	on_build_complete = {
		save_event_target_as = star_manip_system
		owner = {
			country_event = {
				id = stellar_manip.102
			}
		}
		if = {
			limit = {
				fromfrom.planet = {
					giga_is_o_star_for_megas = yes
				}
			}
			fromfrom.planet = {
				save_event_target_as = star_manip_planet
			}
			spawn_megastructure = {
				type = stellar_manipulator_o_1
				planet = event_target:star_manip_planet
				owner = fromfrom.owner
			}
			remove_megastructure = fromfrom
		}
	}
}

#harvester
stellar_manipulator_2 = {
	entity = "stellar_manip_full_entity"
	construction_entity = "stellar_manip_full_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	build_time = 1260
	resources = {
		category = megastructures
		cost = {
			energy = 5000
			unity = @giga_kilo_unity_cost
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_b_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_b_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_m_giant_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_m_giant_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_a_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_a_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_f_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_f_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_g_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_g_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_k_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_k_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_m_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_m_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		produces = {
			trigger = {
				this.planet = {
					is_planet_class = pc_gigaignited_star
				}
			}
			sr_stellar_plasma = @harvester_plasma_production_ignited_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		upkeep = {
			energy = 250
		}
	}
	upgrade_from = {
		stellar_manipulator_1
	}
	ai_weight = {
		factor = 10
		#maybe i should actually make weights for once, maybe not
	}
	on_build_complete = {
		save_event_target_as = star_manip_system
		if = {
			limit = {
				owner = {
					NOR = {
						has_country_flag = restarted_harvester
						has_country_flag = auto_harvester
					}
				}
			}
			owner = {
				country_event = {
					id = stellar_manip.103
				}
			}
		}
		owner = {
			remove_country_flag = auto_harvester
			remove_country_flag = restarted_harvester
		}
		fromfrom = {
			save_event_target_as = star_harvester
		}
		fromfrom.planet = {
			save_event_target_as = star_being_harvested
			# if = {
			# 	limit = {
			# 		is_planet_class = pc_giga_o_star
			# 	}
			# 	planet_event = {
			# 		id = stellar_manip.1000
			# 		days = 1460
			# 	}				#1460 - 4 years, for o classes it's doubled
			# }
			# else = {
			# 	planet_event = {
			# 		id = stellar_manip.1000
			# 		days = 730
			# 	}				#730 - 2 years
			# }
		}
		if = {
			limit = {
				exists = from
				from = {
					NOT = {
						any_situation = {
							is_situation_type = situation_stellar_extraction
							target = {
								is_same_value = root.fromfrom.planet
							}
						}
					}
				}
			}
			from = {
				start_situation = {
					type = situation_stellar_extraction
					target = root.fromfrom.planet
				}
			}
		}
	}
}

#injector
stellar_manipulator_3 = {
	entity = "stellar_manip_full_entity"
	construction_entity = "stellar_manip_full_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	build_time = 1260
	resources = {
		category = megastructures
		cost = {
			energy = 5000
			unity = @giga_kilo_unity_cost
		}
		upkeep = {
			energy = 150
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_b_star
				}
			}
			sr_stellar_plasma = @injector_plasma_b_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_m_giant_star
				}
			}
			sr_stellar_plasma = @injector_plasma_m_giant_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_a_star
				}
			}
			sr_stellar_plasma = @injector_plasma_a_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_f_star
				}
			}
			sr_stellar_plasma = @injector_plasma_f_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_g_star
				}
			}
			sr_stellar_plasma = @injector_plasma_g_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_k_star
				}
			}
			sr_stellar_plasma = @injector_plasma_k_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_m_star
				}
			}
			sr_stellar_plasma = @injector_plasma_m_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
		upkeep = {
			trigger = {
				this.planet = {
					is_planet_class = pc_gigaignited_star
				}
			}
			sr_stellar_plasma = @injector_plasma_ignited_star
			multiplier = this.planet.value:stellarm_infusion_multiplier
		}
	}
	upgrade_from = {
		stellar_manipulator_1
	}
	ai_weight = {
		factor = 1
		#maybe i should actually make weights for once, maybe not
	}
	on_build_complete = {
		if = {
			limit = {
				owner = {
					OR = {
						has_country_flag = restarted_injector
						has_country_flag = auto_injector
					}
				}
			}
			owner = {
				remove_country_flag = restarted_injector
				remove_country_flag = auto_injector
			}
		}
		else = {
			save_event_target_as = star_manip_system
			owner = {
				country_event = {
					id = stellar_manip.104
				}
			}
		}
		fromfrom = {
			save_event_target_as = star_injector
		}
		fromfrom.planet = {
			save_event_target_as = star_being_injected
			# if = {
			# 	limit = { is_planet_class = pc_b_star }
			# 	planet_event = { id = stellar_manip.1001 days = 1460 } #1460 - 4 years, for o classes it's doubled
			# } else = {
			# 	planet_event = { id = stellar_manip.1001 days = 730 } #730 - 2 years
			# }
		}
		if = {
			limit = {
				exists = from
				from = {
					NOT = {
						any_situation = {
							is_situation_type = situation_stellar_infusion
							target = {
								is_same_value = root.fromfrom.planet
							}
						}
					}
				}
			}
			from = {
				start_situation = {
					type = situation_stellar_infusion
					target = root.fromfrom.planet
				}
			}
		}
	}
}

#o class full
stellar_manipulator_o_1 = {
	entity = "stellar_manip_o_full_nobeam_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	resources = {
		category = megastructures
		upkeep = {
			energy = 50
		}
	}
	potential = {
		always = no
	}
}

#o harvester
stellar_manipulator_o_2 = {
	entity = "stellar_manip_o_full_entity"
	construction_entity = "stellar_manip_full_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	build_time = 1260
	resources = {
		category = megastructures
		cost = {
			energy = 10000
			unity = @giga_kilo_unity_cost
		}
		produces = {
			sr_stellar_plasma = @harvester_plasma_production_o_star
			multiplier = this.planet.value:stellarm_harvest_multiplier
		}
		upkeep = {
			energy = 250
		}
	}
	upgrade_from = {
		stellar_manipulator_o_1
	}
	ai_weight = {
		factor = 10
		#maybe i should actually make weights for once, maybe not
	}
	on_build_complete = {
		save_event_target_as = star_manip_system
		owner = {
			country_event = {
				id = stellar_manip.103
			}
		}
		fromfrom = {
			save_event_target_as = star_harvester
		}
		fromfrom.planet = {
			save_event_target_as = star_being_harvested
			# planet_event = { id = stellar_manip.1002 days = 1460 } #4 years 1460
		}
		if = {
			limit = {
				exists = from
			}
			from = {
				start_situation = {
					type = situation_stellar_extraction
					target = root.fromfrom.planet
				}
			}
		}
	}
}

#disabled injector
stellar_manipulator_off = {
	entity = "stellar_manip_full_nobeam_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	potential = {
		always = no
	}
	resources = {
		category = megastructures
		upkeep = {
			energy = 15
		}
	}
	on_build_complete = {
		if = {
			limit = {
				not = {
					has_star_flag = stellarm_tempt_dont_abort
				}
				fromfrom = {
					exists = planet
				}
			}
			every_country = {
				limit = {
					any_situation = {
						exists = target
						OR = {
							is_situation_type = situation_stellar_extraction
							is_situation_type = situation_stellar_infusion
						}
						target = {
							is_same_value = root.fromfrom.planet
						}
					}
				}
				every_situation = {
					limit = {
						exists = target
						OR = {
							is_situation_type = situation_stellar_extraction
							is_situation_type = situation_stellar_infusion
						}
						target = {
							is_same_value = root.fromfrom.planet
						}
					}
					abort_situation = this
				}
			}
		}
	}
}

stellar_manipulator_on = {
	entity = "stellar_manip_full_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	resources = {
		category = megastructures
		upkeep = {
			energy = 150
		}
		cost = {
			sr_stellar_plasma = 100
			energy = 5000
		}
	}
	upgrade_from = {
		stellar_manipulator_off
	}
	build_time = 30
	on_build_complete = {
		owner = {
			set_country_flag = restarted_injector
		}
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		spawn_megastructure = {
			type = stellar_manipulator_3
			planet = event_target:star_manip_planet
			owner = fromfrom.owner
		}
		remove_megastructure = fromfrom
		if = {
			limit = {
				exists = from
			}
			from = {
				start_situation = {
					type = situation_stellar_infusion
					target = root.fromfrom.planet
				}
			}
		}
	}
}

#disabled harvester
stellar_harvester_off = {
	entity = "stellar_manip_full_nobeam_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	potential = {
		always = no
	}
	resources = {
		category = megastructures
		upkeep = {
			energy = 15
		}
	}
	on_build_complete = {
		if = {
			limit = {
				not = {
					has_star_flag = stellarm_tempt_dont_abort
				}
				fromfrom = {
					exists = planet
				}
			}
			every_country = {
				limit = {
					any_situation = {
						exists = target
						OR = {
							is_situation_type = situation_stellar_extraction
							is_situation_type = situation_stellar_infusion
						}
						target = {
							is_same_value = root.fromfrom.planet
						}
					}
				}
				every_situation = {
					limit = {
						exists = target
						OR = {
							is_situation_type = situation_stellar_extraction
							is_situation_type = situation_stellar_infusion
						}
						target = {
							is_same_value = root.fromfrom.planet
						}
					}
					abort_situation = this
				}
			}
		}
	}
}

stellar_harvester_on = {
	entity = "stellar_manip_full_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	place_entity_on_planet_plane = yes
	resources = {
		category = megastructures
		upkeep = {
			energy = 150
		}
		cost = {
			energy = 5000
		}
	}
	upgrade_from = {
		stellar_harvester_off
	}
	build_time = 30
	on_build_complete = {
		owner = {
			set_country_flag = restarted_harvester
		}
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		spawn_megastructure = {
			type = stellar_manipulator_2
			planet = event_target:star_manip_planet
			owner = fromfrom.owner
		}
		remove_megastructure = fromfrom
		if = {
			limit = {
				exists = from
			}
			from = {
				start_situation = {
					type = situation_stellar_extraction
					target = root.fromfrom.planet
				}
			}
		}
	}
}
