﻿namespace = asp_game_start

# 4.4.6 migration-safe initialization of the ASP-owned cleanup policy.
country_event = {
	id = asp_game_start.2
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_ai = no
		is_country_type = default
		OR = {
			NOT = { has_country_flag = aspmod_cleanup_policy_initialized }
			NOT = { has_global_flag = aspmod_rc3d_repair_migration_scanned }
		}
	}

	immediate = {
		# Preserve the previous shared-policy preference where possible.
		if = {
			limit = { NOT = { has_country_flag = aspmod_cleanup_policy_initialized } }
			if = {
				limit = {
					OR = {
						has_policy_flag = scfe_archaeology_cleanup_active
						has_policy_flag = aspmod_archaeology_cleanup_active
					}
				}
				set_policy = { policy = aspmod_archaeology_cleanup option = aspmod_archaeology_cleanup_active }
			}
			else = {
				set_policy = { policy = aspmod_archaeology_cleanup option = aspmod_archaeology_cleanup_inactive }
			}
			set_country_flag = aspmod_cleanup_policy_initialized
		}

		# One-time old-save discovery. The expensive global scan is paid once,
		# then yearly repair is gated by durable global state set here or by new rewards.
		if = {
			limit = { NOT = { has_global_flag = aspmod_rc3d_repair_migration_scanned } }
			if = {
				limit = {
					any_system = {
						any_system_planet = { has_modifier = aspmod_infinite_observatory_planet }
					}
				}
				set_global_flag = aspmod_observatory_repair_active
			}
			if = {
				limit = {
					any_system = {
						any_system_planet = { has_modifier = aspmod_ftl_lane_switcher }
					}
				}
				set_global_flag = aspmod_ftl_switcher_repair_active
			}
			set_global_flag = aspmod_rc3d_repair_migration_scanned
		}
	}
}
