systemcraft_assembler_0 = {
	entity = "construction_platform_entity"
	construction_entity = "construction_platform_entity"
	portrait = "GFX_megastructure_construction_background"
	place_entity_on_planet_plane = no
	prerequisites = {
		tech_stellar_assembler
	}
	build_time = 2800
	resources = {
		category = megastructures
		cost = {
			alloys = 5000
			influence = 300
			unity = @giga_tera_unity_cost
		}
		upkeep = {
			energy = 5
		}
	}
	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"
				giga_is_standard_star = yes
				NOT = {
					giga_is_bitrinary = yes
				}
			}
		}
	}
	#once again stealing the weights from Gigas (this ones are form the planetcraft assembly)
	ai_weight = {
		weight = 100		# Default = 100
		# Can we afford the upkeep
		modifier = {
			factor = 1
			chk_afford_energy_10 = yes
		}
		modifier = {
			factor = 0.9
			chk_afford_energy_09 = yes
		}
		modifier = {
			factor = 0.8
			chk_afford_energy_08 = yes
		}
		modifier = {
			factor = 0.7
			chk_afford_energy_07 = yes
		}
		modifier = {
			factor = 0.6
			chk_afford_energy_06 = yes
		}
		modifier = {
			factor = 0.5
			chk_afford_energy_05 = yes
		}
		modifier = {
			factor = 0.4
			chk_afford_energy_04 = yes
		}
		modifier = {
			factor = 0.3
			chk_afford_energy_03 = yes
		}
		modifier = {
			factor = 0.2
			chk_afford_energy_25 = yes
		}
		modifier = {
			factor = 0.1
			chk_afford_energy_02 = yes
		}
		modifier = {
			factor = 0
			chk_afford_energy_15 = yes
		}
		modifier = {
			factor = 1
			chk_afford_alloys_10 = yes
		}
		modifier = {
			factor = 0.9
			chk_afford_alloys_09 = yes
		}
		modifier = {
			factor = 0.8
			chk_afford_alloys_08 = yes
		}
		modifier = {
			factor = 0.7
			chk_afford_alloys_07 = yes
		}
		modifier = {
			factor = 0.6
			chk_afford_alloys_06 = yes
		}
		modifier = {
			factor = 0.5
			chk_afford_alloys_05 = yes
		}
		modifier = {
			factor = 0.4
			chk_afford_alloys_04 = yes
		}
		modifier = {
			factor = 0.3
			chk_afford_alloys_03 = yes
		}
		modifier = {
			factor = 0.2
			chk_afford_alloys_25 = yes
		}
		modifier = {
			factor = 0.1
			chk_afford_alloys_02 = yes
		}
		modifier = {
			factor = 0
			chk_afford_alloys_15 = yes
		}
		# Do we want the production
		# Is this system a good location?
		modifier = {
			factor = 0.75
			any_neighbor_system = {
				exists = owner
				NOT = {
					owner = {
						is_same_value = from
					}
				}
			}
		}
		# Do we lean towards this from federation/ethic/civic?
		modifier = {
			factor = 10
			from = {
				has_country_flag = pangalactic_defense_league
			}
		}
		modifier = {
			factor = 2
			from = {
				has_federation = yes
				federation = {
					has_federation_type = military_federation
				}
			}
		}
		modifier = {
			factor = 3
			from = {
				has_ethic = ethic_fanatic_militarist
			}
		}
		modifier = {
			factor = 1.5
			from = {
				has_ethic = ethic_militarist
			}
		}
		modifier = {
			factor = 1.5
			from = {
				has_civic = civic_machine_terminator
			}
		}
		modifier = {
			factor = 1.5
			from = {
				has_civic = civic_fanatic_purifiers
			}
		}
		modifier = {
			factor = 1.5
			from = {
				has_civic = civic_hive_devouring_swarm
			}
		}
		modifier = {
			factor = 2
			from = {
				is_at_war = yes
			}
		}
		# How many of this megastructure can the AI build?
		modifier = {
			factor = 0
			from = {
				has_country_flag = has_recently_built_war_moon
			}
		}
	}
	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		from = {
			country_event = {
				id = star_printer.101
			}			# Notification
		}
		fromfrom.planet = {
			if = {
				limit = {
					exists = orbital_station
				}
				orbital_station = {
					dismantle = yes
				}
			}
			set_planet_flag = megastructure			# Vanilla uses to check if a megastrucure can be built here
			set_planet_flag = has_megastructure			# Vanilla uses to check if an orbital station can be built here
		}
	}
}

#5k
systemcraft_assembler_1 = {
	entity = "war_system_printer_1_entity"
	construction_entity = "war_system_printer_1_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_0
	}
	place_entity_on_planet_plane = no
	build_time = 4200
	resources = {
		category = megastructures
		cost = {
			alloys = 50000
			unity = @giga_tera_unity_cost
			rare_crystals = 2000
			volatile_motes = 2000
			exotic_gases = 2000
		}
		upkeep = {
			energy = 400
			alloys = 200
		}
	}
	#55k
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		from = {
			country_event = {
				id = star_printer.102
			}
		}		# Notification
	}
}

systemcraft_assembler_2 = {
	entity = "war_system_printer_2_entity"
	construction_entity = "war_system_printer_2_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_1
	}
	place_entity_on_planet_plane = no
	build_time = 4200
	resources = {
		category = megastructures
		cost = {
			alloys = 115000
			unity = @giga_tera_unity_cost
			rare_crystals = 2000
			volatile_motes = 2000
			exotic_gases = 2000
		}
		upkeep = {
			energy = 800
			alloys = 400
		}
	}
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		giga_remove_system_planets = yes
		giga_remove_system_debris = yes
		set_asteroid_belt = {
			radius = 0
		}
		#delete the star
		if = {
			limit = {
				NOT = {
					any_system_planet = {
						is_star = yes
						NOT = {
							is_planet_class = pc_giga_empty_space
						}
					}
				}
			}
			set_star_class = sc_empty_space
		}
		fromfrom.planet = {
			change_pc = pc_giga_empty_space
		}
		space_owner = {
			add_resource = {
				sr_stellar_plasma = 15000				#enough to print one plus a little extra
			}
		}
		save_event_target_as = star_manip_system
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		from = {
			country_event = {
				id = star_printer.103
			}
		}		# Notification
	}
}

#170k
systemcraft_assembler_3 = {
	entity = "war_system_printer_3_entity"
	construction_entity = "war_system_printer_3_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_2
	}
	place_entity_on_planet_plane = no
	build_time = 4200
	resources = {
		category = megastructures
		cost = {
			alloys = 115000
			unity = @giga_tera_unity_cost
			rare_crystals = 3000
			volatile_motes = 3000
			exotic_gases = 3000
		}
		upkeep = {
			energy = 1000
			alloys = 500
		}
	}
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		from = {
			country_event = {
				id = star_printer.104
			}
		}		# Notification
	}
}

#285k
systemcraft_assembler_4 = {
	entity = "war_system_printer_4_entity"
	construction_entity = "war_system_printer_4_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_3
	}
	place_entity_on_planet_plane = no
	build_time = 5500
	resources = {
		category = megastructures
		cost = {
			alloys = 115000
			unity = @giga_tera_unity_cost
			rare_crystals = 3000
			volatile_motes = 3000
			exotic_gases = 3000
		}
		upkeep = {
			energy = 1500
			alloys = 750
		}
	}
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		from = {
			country_event = {
				id = star_printer.105
			}
		}		# Notification
	}
}

#400k
systemcraft_assembler_5 = { #ready to print
	entity = "war_system_printer_5_entity"
	construction_entity = "war_system_printer_5_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_4
	}
	place_entity_on_planet_plane = no
	build_time = 5000
	resources = {
		category = megastructures
		cost = {
			alloys = 9000
			unity = @giga_tera_unity_cost
			rare_crystals = 3000
			volatile_motes = 3000
			exotic_gases = 3000
		}
		upkeep = {
			energy = 3000
			alloys = 1500
		}
	}
	country_modifier = {
		country_resource_max_alloys_add = 150000000
		country_resource_max_energy_add = 100000000
	}
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		save_event_target_as = star_manip_system
		fromfrom.planet = {
			save_event_target_as = star_manip_planet
		}
		from = {
			if = {  #This check and flag exists because after printing the structure is automatically upgraded back to this stage, the next stage sets the country flag and that stops the notification event from triggering every time
				limit = {
					NOT = {
						has_country_flag = just_assembled_systemcraft
					}
				}
				country_event = {
					id = star_printer.106
				}				# Notification
			}
			else_if = {
				limit = {
					has_country_flag = just_assembled_systemcraft
				}
				remove_country_flag = just_assembled_systemcraft
			}
		}
	}
}

#490k total
systemcraft_assembler_make_system = { #print normal
	entity = "war_system_printer_printing_entity"
	construction_entity = "war_system_printer_printing_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_5
	}
	place_entity_on_planet_plane = no
	build_time = 25000	#a full systemcraft takes 19800 not counting the planets and moons, but you can technically make them in paralle so i didn't add it
	resources = {
		category = megastructures
		cost = {
			alloys = 1750000				#250k alloys per planet for 1M on planetcrafts + 30k per moon for 150k + 600k for the systemcraft (it costs 550k, so i added a bit more) for a total of 1.750.000
			sr_solar_energy = 140			#planetary matter || 26 per planetcraft * 4 = 104 on planetcrafts + 7 per moon * 5 = 35 on moons for a total of 139
			energy = 2000000				#just made it 2M, i'm not doing more math
			sr_stellar_plasma = 10000		#idk, maybe balance this eventually
		}
		upkeep = {
			energy = 3000
			alloys = 1500
		}
	}
	potential = {
		NOT = {
			has_global_flag = systemcraft_disabled
		}
		OR = {
			check_variable = {
				which = giga_systemcraft_cap
				value = 0
			}			# No Cap
			check_variable = {
				which = giga_current_systemcraft
				value < giga_systemcraft_cap
			}
		}
	}
	possible = {
		from = {
			has_technology = tech_stellar_assembler
		}
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					check_variable = {
						which = giga_systemcraft_cap
						value = 0
					}					# No Cap
					check_variable = {
						which = giga_current_systemcraft
						value < giga_systemcraft_cap
					}
				}
			}
		}
	}
	country_modifier = {
		country_resource_max_alloys_add = 150000
		country_resource_max_energy_add = 100000
	}
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		save_event_target_as = giga_systemcraft_print
		from = {
			set_country_flag = just_assembled_systemcraft
			country_event = {
				id = star_printer.1000
			}
			if = {
				limit = {
					NOR = {
						has_global_flag = giga_achievements_disabled
						has_country_flag = giga_achievement_91
					}
				}
				set_country_flag = giga_achievement_91
				set_timed_country_flag = {
					flag = giga_achievement_91_notification
					days = 30
				}
				giga_achievement_sound = yes
			}
		}
	}
}
systemcraft_assembler_make_o_system = { #print o class
	entity = "war_system_printer_printing_entity"
	construction_entity = "war_system_printer_printing_entity"
	portrait = "GFX_evt_binary_stars"
	upgrade_from = {
		systemcraft_assembler_5
	}
	place_entity_on_planet_plane = no
	build_time = 75000	#a full systemcraft takes 19800 not counting the planets and moons, but you can technically make them in paralle so i didn't add it
	resources = {
		category = megastructures
		cost = {
			alloys = 5000000			
			sr_solar_energy = 140		
			energy = 2000000		
			sr_stellar_plasma = 40000
		}
		upkeep = {
			energy = 3000
			alloys = 1500
		}
	}
	potential = {
		NOT = {
			has_global_flag = systemcraft_disabled
		}
		OR = {
			check_variable = {
				which = giga_systemcraft_cap
				value = 0
			}			# No Cap
			check_variable = {
				which = giga_current_systemcraft
				value < giga_systemcraft_cap
			}
		}
	}
	possible = {
		from = {
			has_technology = tech_stellar_assembler
			has_technology = tech_o_class_war_system
		}
		custom_tooltip = {
			fail_text = "requires_not_capped"
			from = {
				OR = {
					check_variable = {
						which = giga_systemcraft_cap
						value = 0
					}					# No Cap
					check_variable = {
						which = giga_current_systemcraft
						value < giga_systemcraft_cap
					}
				}
			}
		}
	}
	country_modifier = {
		country_resource_max_alloys_add = 150000
		country_resource_max_energy_add = 100000
	}
	ai_weight = {
		factor = 10
	}	# If we can build it, we will build it
	on_build_complete = {
		save_event_target_as = giga_systemcraft_print
		from = {
			set_country_flag = just_assembled_systemcraft
			country_event = {
				id = star_printer.1001
			}
			if = {
				limit = {
					NOR = {
						has_global_flag = giga_achievements_disabled
						has_country_flag = giga_achievement_91
					}
				}
				set_country_flag = giga_achievement_91
				set_timed_country_flag = {
					flag = giga_achievement_91_notification
					days = 30
				}
				giga_achievement_sound = yes
			}
		}
	}
}