namespace = painted_galaxy_homeworld

# correct homeworld planet class
# from = founder primary species
colony_event = {
	id = painted_galaxy_homeworld.1
	is_triggered_only = yes
	hide_window = yes
	trigger = {
		is_maybe_painted_galaxy = yes
		carrier_is_type = planet
		# don't fix homeworlds for extra spawns
		solar_system = { has_star_flag = empire_home_system }
	}
	immediate = {
		planet = {
			inline_script = {
				script = pgcompat/homeworld/origin_acot_grimdark/switch
				ACOT = @has_ancient_caches
			}
			if = { # resource consolidation, ie machine world start
				limit = { owner = { has_origin = origin_machine } }
				painted_galaxy_change_pc = { PC = pc_machine }
			}
			if = { # remnants, ie relic world start
				limit = { owner = { has_origin = origin_remnants } }
				painted_galaxy_change_pc = { PC = pc_relic }
			}
			if = { # post-apocalyptic, ie tomb world start
				limit = { owner = { OR = { has_origin = origin_post_apocalyptic has_origin = origin_post_apocalyptic_machines } } }
				painted_galaxy_change_pc = { PC = pc_nuked }
			}
			if = { # generic
				limit = {
					NOT = { has_planet_flag = painted_galaxy_changed_pc } # already handled
					# don't convert artificial worlds, that's probably an origin
					is_artificial = no
					# don't convert already ideal worlds, that might be special initializer
					# on the other hand, this is perhaps exposing some people to random modifiers/deposits on their planet, more research needed
					is_ideal_planet_class = { who = from status = no }
				}
				painted_galaxy_change_pc = { PC = from }
			}
		}
	}
}
