# Worldseeders

# Scope: country. Marks one random valid world inside our borders as a terraforming
# candidate (worlds of size 12 or more first, smaller ones only if there is no such
# world) and shows it in apb_seeders.2. Does nothing if no world qualifies.
# Called by the decade pulse (apb_seeders.1) and the edict apb_survey_candidates.
apb_seeders_find_candidate = {
	if = {
		limit = {
			any_planet_within_border = {
				apb_seeders_valid_world = yes
				planet_size >= 12
			}
		}
		random_planet_within_border = {
			limit = {
				apb_seeders_valid_world = yes
				planet_size >= 12
			}
			apb_seeders_mark_world = yes
		}
		country_event = { id = apb_seeders.2 }
	}
	else_if = {
		limit = { apb_seeders_has_valid_world = yes }
		random_planet_within_border = {
			limit = { apb_seeders_valid_world = yes }
			apb_seeders_mark_world = yes
		}
		country_event = { id = apb_seeders.2 }
	}
}

# Scope: planet. Adds the vanilla candidate modifier that matches the planet class
# and saves the planet as event_target:apb_seeders_world.
apb_seeders_mark_world = {
	if = {
		limit = { is_planet_class = pc_toxic }
		add_modifier = { modifier = toxic_terraforming_candidate days = -1 }
	}
	else_if = {
		limit = { is_planet_class = pc_frozen }
		add_modifier = { modifier = frozen_terraforming_candidate days = -1 }
	}
	else = {
		add_modifier = { modifier = terraforming_candidate days = -1 }
	}
	save_event_target_as = apb_seeders_world
}
