#site
stellar_manipulator_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	place_entity_on_planet_plane = no
	portrait = "GFX_megastructure_construction_background"
	entity_offset = { x = -7 y = -7 }
	build_time = 1260
	resources = {
		category = megastructures
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}

		upkeep = {
			energy = 5
		}
	}
	construction_blocks_and_blocked_by = none

	prerequisites = {
		"tech_gigas_stellar_manip_2"
	}

	potential = {
		is_ai = no
	}

	possible = {
		custom_tooltip = { fail_text = "requires_inside_border"		 		is_inside_border = from  }
		custom_tooltip = { fail_text = "requires_surveyed_system"			giga_system_is_surveyed = yes }
		custom_tooltip = { fail_text = "requires_no_colonized_planets"		NOT = { any_system_planet = { is_colony = yes } } }
	}

	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_standard_planet_class"	stellar_manip_is_valid_star = yes }
			custom_tooltip = { fail_text = "requires_no_binary_trinary" 			giga_is_bitrinary = no }
		}
	}
	ai_weight = {
		factor = 10
		#maybe i should actually make weights for once, maybe not
	}
	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom = { save_event_target_as = star_manip_mega }

		create_message = {
			type = MESSAGE_STELLAR_MANIPULATOR_SITE_BUILT
			localization = MESSAGE_STELLAR_MANIPULATOR_SITE_BUILT
			days = @toast_important_message_days
			target = event_target:star_manip_system
		}

		fromfrom.planet = {
			set_carrier_flag = has_megastructure
			save_event_target_as = star_manip_planet
		}
	}
}

#full
stellar_manipulator_1 = {
	entity = "stellar_manip_full_nobeam_entity"
	construction_entity = "stellar_manip_full_nobeam_entity"
	portrait = "GFX_star_manip_01_background"
	build_time = 1260

	resources = {
		category = megastructures
		cost = {
			unity = @giga_mega_unity_cost
		}
		inline_script = {
			script = megastructures/generic_parts/giga_mega_alloy_cost
			alloys = 5000
		}

		upkeep = {
			energy = 25
		}
	}
	upgrade_from = {
		stellar_manipulator_0
	}
	prerequisites = {
		"tech_gigas_stellar_manip_2"
	}

	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom = { save_event_target_as = star_manip_mega }

		owner = {
			country_event = {
				id = stellar_manip_dialogue.2
				scopes = {
					from = this
					fromfrom = root.fromfrom # mega scope
					fromfromfrom = fromfrom.planet
				}
			}
		}
	}
}

#harvester
stellar_manipulator_2 = {
	entity = "stellar_manip_full_entity"
	construction_entity = "stellar_manip_full_entity"
	portrait = "GFX_star_manip_01_background"
	build_time = 0
	upgrade_from = { stellar_manipulator_1 }
	potential = { always = no }

	resources = {
		category = megastructures
		cost = {
			energy = 5000
			unity = 500
		}

		upkeep = {
			trigger = {
				exists = owner
				owner = {
					any_situation = {
						is_situation_type = situation_stellar_extraction
						this = {
							current_situation_approach = approach_stellarm_standard
						}
					}
				}
			}
			energy = 150
		}

		upkeep = {
			trigger = {
				exists = owner
				owner = {
					any_situation = {
						is_situation_type = situation_stellar_extraction
						this = {
							NOT = {
								current_situation_approach = approach_stellarm_standard
							}
						}
					}
				}
			}
		}
	}


	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom = { save_event_target_as = star_manip_mega }

		create_message = {
			type = MESSAGE_STELLAR_HARVESTER_BUILT
			localization = MESSAGE_STELLAR_HARVESTER_BUILT
			days = @toast_important_message_days
			target = event_target:star_manip_system

		}
		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 = {
				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"
	build_time = 0
	upgrade_from = { stellar_manipulator_1}
	potential = { always = no }

	resources = {
		category = megastructures
		cost = {
			energy = 5000
			unity = 500
		}

		# Not injecting? No upkeep! (like when you have no plasma)
		upkeep = {
			trigger = {
				exists = owner
				owner = {
					any_situation = {
						is_situation_type = situation_stellar_infusion
						this = {
							current_situation_approach = approach_stellarm_standard_infusion
						}
					}
				}
			}
			energy = 150
		}

		upkeep = {
			trigger = {
				exists = owner
				owner = {
					any_situation = {
						is_situation_type = situation_stellar_infusion
						this = {
							NOT = {
								current_situation_approach = approach_stellarm_standard_infusion
							}
						}
					}
				}
			}
		}
	}

	ai_weight = {
		factor = 1
		#maybe i should actually make weights for once, maybe not
	}

	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom = { save_event_target_as = star_injector }

		create_message = {
			type = MESSAGE_STELLAR_INJECTOR_BUILT
			localization = MESSAGE_STELLAR_INJECTOR_BUILT
			days = @toast_important_message_days
			target = event_target:star_manip_system

		}

		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
			}
		}

		# REPLACED BY MESSAGE/TOAST
		# else = {
		# 	save_event_target_as = star_manip_system
		# 	owner = {
		# 		country_event = {
		# 			id = stellar_manip_dialogue.4
		# 		}
		# 	}
		# }

		fromfrom.planet = {
			save_event_target_as = star_being_injected
		}

		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"
	build_time = 0
	upgrade_from = { stellar_manipulator_1 }
	potential = { always = no }

	resources = {
		category = megastructures
		cost = {
			energy = 10000
			unity = @giga_kilo_unity_cost
		}

		upkeep = {
			trigger = {
				exists = owner
				owner = {
					any_situation = {
						is_situation_type = situation_stellar_extraction
						this = {
							current_situation_approach = approach_stellarm_standard
						}
					}
				}
			}
			energy = 150
		}

		upkeep = {
			trigger = {
				exists = owner
				owner = {
					any_situation = {
						is_situation_type = situation_stellar_extraction
						this = {
							NOT = {
								current_situation_approach = approach_stellarm_standard
							}
						}
					}
				}
			}
		}
	}

	ai_weight = {
		factor = 10
	}

	on_build_complete = {
		save_event_target_as = star_manip_system

		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
				}
			}
		}
	}
}
