# Game will first pick an initializer using usage_odds, but only use it if it passes the spawn_chance check
# Even if it fails the spawn_chance check it will still count towards the initializer's max_instances

@jumps = 3
@homeworld_min_size = 18
@homeworld_max_size = 21

##########
# ORIGINS
##########

# MSI Home System
msi_home_system = {
	class = "rl_starting_stars"
	asteroid_belt = {
		type = rocky_asteroid_belt
		radius = 50
	}

	flags = { empire_home_system MSI_home_system }

	usage = misc_system_init

	usage_odds = {
		base = 0
		modifier = {
			NOT = { exists = event_target:MSI_country }
			any_country = {
				has_slave_origin = yes
				NOR = {
					has_country_flag = slavers_assigned
					# don't spawn if AI-generated and adv start disabled
					# see game_start.1
					AND = {
						is_ai = yes
						check_galaxy_setup_value = { setting = num_advanced_empires value < 1 }
					}
				}
			}
			NOT = { has_star_flag = empire_cluster }
			add = @spawn_system_max
		}
		modifier = {
			NOT = { exists = event_target:MSI_country }
			any_system = {
				exists = owner
				owner = {
					has_slave_origin = yes
				}
				distance = {
					max_jumps = 5
				}
			}
			factor = 0
		}
	}

	init_effect = {
		generate_home_system_resources = yes
	}

	planet = {
		count = 1
		class = star
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 20 max = 30 }
		has_ring = no
	}

	change_orbit = 50

	planet = {
		count = { min = 1 max = 3 }
		class = pc_asteroid
		orbit_distance = 0
		orbit_angle = { min = 40 max = 100 }
	}

	planet = {
		count = { min = 0 max = 2 }
		orbit_distance = 20
		class = random_non_colonizable
		orbit_angle = { min = 90 max = 270 }

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			class = random_non_colonizable
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		count = 1
		orbit_distance = 20
		home_planet = yes
		class = pc_relic
		orbit_angle = { min = 90 max = 270 }
		size = 25
		deposit_blockers = none
		modifiers = none
		flags = { MSI_homeworld }

		init_effect = {
			prevent_anomaly = yes
			create_MSI_effect = yes
		}

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			class = random_non_colonizable
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		count = { min = 2 max = 4 }
		orbit_distance = 20
		class = random_non_colonizable
		orbit_angle = { min = 90 max = 270 }

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			class = random_non_colonizable
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		count = { min = 1 max = 2 }
		orbit_distance = 20
		class = pc_gas_giant
		orbit_angle = { min = 90 max = 270 }

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 3 }
			class = random_non_colonizable
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	init_effect = {
		solar_system = {
			create_starbase = {
				size = starbase_starport
				module = shipyard
				building = crew_quarters
				owner = event_target:MSI_country
				effect = {
					set_starbase_module = {
						slot = 2
						module = trading_hub
					}
				}
			}
		}
	}

	neighbor_system = {
		hyperlane_jumps = { min = 1 max = @jumps }
		initializer = "slavers_neighbor_t1"
	}
	neighbor_system = {
		hyperlane_jumps = { min = 1 max = @jumps }
		initializer = "slavers_neighbor_t1_first_colony"
	}
}

# Neighbor Tier 1
slavers_neighbor_t1 = {
	class = "rl_standard_stars"
	flags = { neighbor_t1 }

	init_effect = {
		every_neighbor_system = { set_star_flag = empire_cluster }
	}

	planet = {
		count = 1
		class = star
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 20 max = 30 }
		has_ring = no
	}

	change_orbit = 45

	planet = {
		count = { min = 0 max = 2 }
		orbit_distance = 20
		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			orbit_distance = 5
		}
	}

	planet = {
		count = { min = 2 max = 5 }
		orbit_distance = 20
	}

	init_effect = {
		create_starbase = {
			size = starbase_outpost
			owner = event_target:MSI_country
		}
	}

	neighbor_system = {
		hyperlane_jumps = { min = 1 max = @jumps }
		initializer = "slavers_neighbor_t2_second_colony"
	}
}

# Neighbor Tier 1 First Colony
slavers_neighbor_t1_first_colony = {
	class = "rl_standard_stars"
	flags = { neighbor_t1_first_colony }

	init_effect = {
		every_neighbor_system = { set_star_flag = empire_cluster }
	}

	planet = {
		count = 1
		class = star
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 20 max = 30 }
		has_ring = no
	}

	change_orbit = 45

	planet = {
		count = { min = 0 max = 2 }
		orbit_distance = 20

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			orbit_distance = 5
		}
	}

	planet = {
		count = 1
		orbit_distance = 25
		class = pc_continental
		modifiers = none
		anomaly = none
		orbit_angle = { min = 90 max = 270 }
		size = { min = 12 max = 18 }

		init_effect = {
			create_colony = {
				owner = event_target:MSI_country
			}
			add_modifier = { modifier = colonial_remains }
		}
	}

	planet = {
		count = { min = 2 max = 5 }
		orbit_distance = 25

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			orbit_distance = 5
		}
	}

	init_effect = {
		create_starbase = {
			size = starbase_outpost
			owner = event_target:MSI_country
		}
	}

	neighbor_system = {
		hyperlane_jumps = { min = 1 max = @jumps }
		initializer = "neighbor_t2"
	}
}

# Neighbor Tier 2 Second Colony
slavers_neighbor_t2_second_colony = {
	class = "rl_standard_stars"
	flags = { neighbor_t2_second_colony }

	init_effect = {
		every_neighbor_system = { set_star_flag = empire_cluster }
	}

	planet = {
		count = 1
		class = star
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 20 max = 30 }
		has_ring = no
	}

	change_orbit = 25

	planet = {
		count = 2
		orbit_angle = { min = 90 max = 270 }
		orbit_distance = 20
	}

	planet = {
		count = 1
		orbit_distance = 25
		class = pc_continental
		modifiers = none
		anomaly = none
		orbit_angle = { min = 90 max = 270 }
		size = { min = 14 max = 24 }

		init_effect = {
			create_colony = {
				owner = event_target:MSI_country
			}
			add_modifier = { modifier = colonial_remains }
		}

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			class = random_non_colonizable
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		count = 2
		orbit_angle = { min = 90 max = 270 }
		orbit_distance = 20

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			class = random_non_colonizable
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		count = { min = 0 max = 2 }
		orbit_angle = { min = 90 max = 270 }
		orbit_distance = 20
	}

	init_effect = {
		create_starbase = {
			size = starbase_outpost
			owner = event_target:MSI_country
		}
	}
}

# Fear of the Dark
fear_of_the_dark_system = {
	class = "sc_a"
	asteroid_belt = {
		type = rocky_asteroid_belt
		radius = 90
	}

	init_effect = {
		every_neighbor_system = {
			set_star_flag = empire_cluster
			every_neighbor_system = {
				set_star_flag = empire_cluster
			}
		}
		generate_home_system_resources = yes
	}

	flags = { empire_home_system fotd_system }

	usage = origin

	planet = {
		class = "pc_a_star"
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 28 max = 37 }
		has_ring = no
	}

	planet = {
		class = "pc_molten"
		orbit_distance = 60
		orbit_angle = 45
		size = 10
		has_ring = no
	}

	planet = {
		class = "pc_asteroid"
		orbit_distance = 30
		orbit_angle = 111
		size = 7
		has_ring = no
	}

	planet = {
		class = "pc_asteroid"
		orbit_distance = 0
		orbit_angle = 222
		size = 6
		has_ring = no
	}

	planet = {
		class = "pc_asteroid"
		orbit_distance = 0
		orbit_angle = 260
		size = 4
		has_ring = no
	}

	planet = {
		class = "pc_gas_giant"
		orbit_distance = 30
		orbit_angle = 200
		size = 0
		has_ring = no
		entity = "gas_giant_02_entity"
		flags = { delete_me_planet ignore_startup_effect }
		has_independent_orbital_line = yes
		init_effect = {
			remove_planet = yes
		}

		moon = {
			class = "pc_desert"
			size = 16
			orbit_distance = 12
			orbit_angle = 120
			flags = { haven_flag }
			has_ring = no
		}
		moon = {
			class = ideal_planet_class
			orbit_distance = 0
			orbit_angle = 180
			size = 16
			starting_planet = yes
			has_ring = no
			deposit_blockers = none
			modifiers = none

			init_effect = {
				prevent_anomaly = yes
			}

			init_effect = {
				generate_empire_home_planet = yes
			}
		}

		orbital_line = {
			orbit_distance_from_parent = 12
		}
	}


	planet = {
		name = "NAME_Divider"
		class = "pc_broken"
		orbit_distance = 30
		orbit_angle = 33
		size = 20
		flags = { divider_flag }
		has_ring = yes
		init_effect = {
			prevent_anomaly = yes
			set_deposit = d_alloys_5
		}
	}

	neighbor_system = {
		trigger = { num_guaranteed_colonies >= 2 }
		hyperlane_jumps = { min = 1 max = @jumps }
		initializer = "neighbor_t1"
	}
	neighbor_system = {
		trigger = { num_guaranteed_colonies >= 1 }
		hyperlane_jumps = { min = 1 max = @jumps }
		initializer = "neighbor_t1_first_colony"
	}
}

hunter_of_the_dark_system = {
	class = "sc_b"
	asteroid_belt = {
		type = empty_asteroid_belt
		radius = 147
	}

	flags = { empire_home_system }

	usage = misc_system_init

	planet = {
		class = "pc_b_star"
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 33 max = 40 }
		has_ring = no
		init_effect = {
			while = {
				count = 10
				create_ambient_object = {
					type = "small_dead_tiyanki_object"
					use_3d_location = yes
					entity_offset = { min = 220 max = 240 }
					entity_offset_angle = { min = 0 max = 360 }
					location = this
				}
				create_ambient_object = {
					type = "small_dead_tiyanki_object"
					use_3d_location = yes
					entity_offset = { min = 2 max = 4 }
					entity_offset_angle = { min = 0 max = 360 }
					location = last_created_ambient_object
				}
				create_ambient_object = {
					type = "small_dead_tiyanki_object"
					use_3d_location = yes
					entity_offset = { min = 2 max = 4 }
					entity_offset_angle = { min = 0 max = 360 }
					location = last_created_ambient_object
				}
			}
			while = {
				count = 6
				create_ambient_object = {
					type = "abandoned_starbase_01_object"
					use_3d_location = yes
					entity_offset = { min = 140 max = 155 }
					entity_offset_angle = { min = 0 max = 360 }
					entity_offset_height = 10
					location = this
				}
			}
		}
	}

	planet = {
		name = "NAME_Fevor"
		class = "pc_desert"
		size = 22
		orbit_distance = 120
		orbit_angle = 9
		has_ring = no
		flags = { fotd_hunter }
		init_effect = {
			prevent_anomaly = yes
			while = {
				count = 5
				add_blocker = {
					type = d_empty_quarry
				}
			}
		}
		moon = {
			class = "pc_barren"
			size = 7
			orbit_distance = 12
			orbit_angle = 120
			has_ring = no
		}
	}

	planet = {
		class = "pc_gas_giant"
		orbit_distance = 60
		orbit_angle = 33
		size = 34
		has_ring = no
	}
	planet = {
		class = "pc_gas_giant"
		orbit_distance = 20
		orbit_angle = 133
		size = 21
		has_ring = no
	}
}

# Broken Shackles Parent System
broken_shackles_parent_system = {
	class = "rl_starting_stars"
	asteroid_belt = {
		type = rocky_asteroid_belt
		radius = 50
	}

	flags = { primitive_system empire_home_system }

	usage = misc_system_init

	usage_odds = {
		base = 0
		modifier = {
			any_country = {
				has_origin = origin_broken_shackles
				NOT = {
					has_country_flag = parent_system_spawned
					species_portrait = human
				}
			}
			NOT = { has_star_flag = empire_cluster }
			add = @spawn_system_max
		}
	}

	planet = {
		count = 1
		class = star
		orbit_distance = 0
		orbit_angle = 1
		size = { min = 20 max = 30 }
		has_ring = no
	}

	change_orbit = 20

	planet = {
		orbit_distance = 20
		count = { min = 0 max = 3 }
	}

	change_orbit = 20

	planet = {
		count = 1
		orbit_distance = 0
		class = "rl_habitable_normal"
		orbit_angle = { min = 90 max = 270 }
		size = { min = 12 max = 25 }

		flags = { }

		init_effect = {
			prevent_anomaly = yes

			random_country = {
				limit = {
					has_origin = origin_broken_shackles
					NOT = {
						has_country_flag = parent_system_spawned
						species_portrait = human
					}
				}
				set_country_flag = parent_system_spawned
				save_event_target_as = broken_shackles_child
			}

			set_planet_flag = broken_shackles_homeworld_@event_target:broken_shackles_child

			solar_system = {
				set_star_flag = broken_shackles_system
				set_star_flag = broken_shackles_home_system_@event_target:broken_shackles_child
			}

			create_country = {
				species = event_target:broken_shackles_child
				name_list = event_target:broken_shackles_child
				type = primitive
				origin = "origin_default"
				government_restrictions = {
					authority = { NOT = { value = auth_machine_intelligence value = auth_hive_mind } }
				}
				civics = {
					civic = civic_increasing_urbanization
					civic = civic_atmospheric_pollution
				}
				flag = {
					icon = {
						category = "spherical"
						file = "flag_spherical_22.dds"
					}
					background= {
						category = "backgrounds"
						file = "new_dawn.dds"
					}
					colors={
						"turquoise"
						"green"
						"null"
						"null"
					}
				}
				effect = {
					save_event_target_as = broken_shackles_parent
				}
			}
			event_target:broken_shackles_parent = {
				set_graphical_culture = industrial_01
				random_list = {
					25 = {
						set_country_flag = industrial_age
						set_pre_ftl_age = industrial_age
						change_country_flag = {
							icon = {
								category = "pre_ftl"
								file = "preftl_industrial_age.dds"
							}
							background= {
								category = "backgrounds"
								file = "new_dawn.dds"
							}
							colors={
								"beige"
								"yellow"
								"null"
								"null"
							}
						}
					}
					25 = {
						set_country_flag = machine_age
						set_pre_ftl_age = machine_age
						change_country_flag = {
							icon = {
								category = "pre_ftl"
								file = "preftl_machine_age.dds"
							}
							background= {
								category = "backgrounds"
								file = "new_dawn.dds"
							}
							colors={
								"yellow"
								"orange"
								"null"
								"null"
							}
						}
					}
					25 = {
						set_country_flag = atomic_age
						set_pre_ftl_age = atomic_age
						change_country_flag = {
							icon = {
								category = "pre_ftl"
								file = "preftl_atomic_age.dds"
							}
							background= {
								category = "backgrounds"
								file = "new_dawn.dds"
							}
							colors={
								"beige"
								"brown"
								"null"
								"null"
							}
						}
					}
					25 = {
						set_country_flag = early_space_age
						set_pre_ftl_age = early_space_age
						change_country_flag = {
							icon = {
								category = "pre_ftl"
								file = "preftl_early_space_age.dds"
							}
							background= {
								category = "backgrounds"
								file = "new_dawn.dds"
							}
							colors={
								"grey"
								"dark_grey"
								"null"
								"null"
							}
						}
					}
				}

				set_country_flag = broken_shackles_parent_country
				set_country_flag = special_intro_for@event_target:broken_shackles_child
				set_country_flag = broken_shackles_parent_of@event_target:broken_shackles_child
				owner_species = { set_species_homeworld = prevprev }
				set_name = random # Fixes some naming issues
			}

			setup_pre_ftl_broken_shackles_planet = yes
		}

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		class = pc_gas_giant
		orbit_distance = 20
		count = { min = 1 max = 4 }

		change_orbit = @base_moon_distance

		moon = {
			count = { min = 0 max = 1 }
			orbit_angle = { min = 90 max = 270 }
			orbit_distance = 5
		}
	}

	planet = {
		class = pc_gas_giant
		orbit_distance = 20
		count = { min = 0 max = 2 }
	}
}

# Solarpunk Systems
solarpunk_01 = {
	name = "NAME_Helito"
	class = sc_binary_8
	asteroid_belt = {
		type = empty_asteroid_belt
		radius = 200
	}

	flags = { solarpunk_system_01 }

	usage = misc_system_init

	max_instances = 1

	usage_odds = {
		base = @spawn_system_common
		modifier = {
			factor = 0
			has_first_contact_dlc = no
		}
		inline_script = "solar_system_initializers/initializer_modifiers_habitable_world_systems"
	}

	primitive_system = yes # usage odds modified by primitives setup slider

	planet = {
		name = "NAME_Helito_A"
		count = 1
		class = pc_f_star
		orbit_distance = 30
		orbit_angle = 30
		size = 25
		has_ring = no
		init_effect = {
			prevent_anomaly = yes
		}
	}

	planet = {
		name = "NAME_Helito_B"
		count = 1
		class = pc_f_star
		orbit_distance = 0
		orbit_angle = 200
		size = 33
		has_ring = no
		init_effect = {
			prevent_anomaly = yes
		}
	}

	orbital_line = {
		orbit_distance_from_parent = 90
	}

	planet = {
		name = "NAME_Helito_II"
		orbit_distance = 85
		count = 1
		class = pc_molten
		size = 6
		has_ring = no
	}

	orbital_line = {
		orbit_distance_from_parent = 150
	}

	planet = {
		name = "NAME_Helito_IV"
		count = 1
		orbit_distance = 150
		orbit_angle = { min = 90 max = 270 }
		class = pc_gas_giant
		size = { min = 33 max = 45 }
		has_ring = no

		orbital_line = {
			orbit_distance_from_parent = 15
		}
	}

	planet = {
		name = "NAME_Helito_V"
		count = 1
		orbit_distance = 80
		orbit_angle = { min = 90 max = 270 }
		class = pc_gas_giant
		size = { min = 33 max = 45 }
		has_ring = no

		orbital_line = {
			orbit_distance_from_parent = 12
		}
		orbital_line = {
			orbit_distance_from_parent = 20
		}
		orbital_line = {
			orbit_distance_from_parent = 25
		}
	}

	planet = {
		name = "NAME_Helito_VI"
		count = 1
		orbit_distance = 80
		orbit_angle = { min = 90 max = 270 }
		class = pc_gas_giant
		size = { min = 33 max = 45 }
		has_ring = no

		orbital_line = {
			orbit_distance_from_parent = 15
		}
		orbital_line = {
			orbit_distance_from_parent = 23
		}
	}
}

solarpunk_02 = {
	class = "rl_trinary_stars"
	name = "NAME_Dacha"

	flags = { solarpunk_system_02 ancient_wonders_system }

	usage = misc_system_init

	init_effect = {
		every_system_planet = {
			prevent_anomaly = yes
		}
	}

	planet = {
		name = "NAME_Dacha_A"
		count = 1
		class = star
		orbit_distance = 0
		orbit_angle = 0
		size = { min = 30 max = 35 }
		has_ring = no
	}

	planet = {
		name = "NAME_Dacha_B"
		count = 1
		class = star
		orbit_distance = 250
		orbit_angle = 220
		size = { min = 20 max = 30 }
		has_ring = no

		change_orbit = 30

		planet = {
			name = "NAME_Sol_X"
			class = pc_gaia
			size = 25
			orbit_distance = 60
			orbit_angle = 300
			flags = { solarpunk_colony solar_mining_world }
			moon = {
				count = 1
				class = "rl_unhabitable_planets"
				orbit_distance = 10
				init_effect = {
					set_deposit = d_physics_4
					add_deposit = d_society_4
					add_deposit = d_engineering_4
				}
			}
		}
	}

	planet = {
		name = "NAME_Dacha_C"
		count = 1
		class = star
		orbit_distance = 10
		orbit_angle = 190
		size = { min = 15 max = 30 }
		has_ring = no

		change_orbit = 30

		planet = {
			name = "NAME_Helito_I"
			class = pc_gaia
			size = 10
			orbit_distance = 30
			flags = { solarpunk_colony solar_small_world }

			moon = {
				count = { min = 2 max = 3 }
				class = "rl_unhabitable_planets"
				orbit_distance = 10
				init_effect = {
					set_deposit = d_minerals_5
				}
			}
		}

		planet = {
			name = "NAME_Helito_III"
			class = pc_gaia
			size = 17
			orbit_distance = 30
			flags = { solarpunk_colony solar_industrial_world }

			moon = {
				count = { min = 1 max = 2 }
				class = "rl_unhabitable_planets"
				orbit_distance = 10
				init_effect = {
					set_deposit = d_alloys_3
				}
			}
		}
	}

	change_orbit = -220

	planet = {
		name = "NAME_Dacha_I"
		orbit_distance = 5
		orbit_angle = 270
		count = 1
		class = pc_gaia
		flags = { solarpunk_colony solar_small_world }
		size = 9
		has_ring = no
	}

	planet = {
		name = "NAME_Dacha_II"
		orbit_distance = 20
		orbit_angle = 200
		count = 1
		class = pc_gaia
		size = 23
		flags = { solarpunk_capital }
		has_ring = no

		moon = {
			count = 1
			orbit_angle = { min = 90 max = 270 }
			class = pc_gaia
			flags = { solarpunk_colony solar_small_world }
			size = 7
		}
	}

	asteroid_belt = {
		type = rocky_asteroid_belt
		radius = 100
	}

	planet = {
		name = "NAME_Dacha_III"
		orbit_distance = 50
		orbit_angle = 20
		count = 1
		class = pc_gas_giant
		size = 30
		has_ring = no
	}

	planet = {
		name = "NAME_Dacha_IV"
		orbit_distance = 20
		orbit_angle = 100
		count = 1
		class = pc_gas_giant
		size = 22
		has_ring = yes
	}
}
