auto_construct_checks = {
	$FLEET$ = {
		# NOR = {
		# 	has_fleet_order = build_orbital_station_order
		# 	has_fleet_order = evade_hostiles_order
		# 	has_fleet_order = build_megastructure_fleet_order
		# 	has_fleet_order = collect_data_fleet_order
		# 	has_fleet_order = orbit_planet_order
		# 	has_fleet_order = return_fleet_order
		# 	has_fleet_order = auto_patrol_order
		# 	has_fleet_order = repair_fleet_order
		# 	has_fleet_order = use_bypass_order
		# 	has_fleet_order = jumpdrive_order
		# 	has_fleet_order = jumpdrive_windup
		# 	has_fleet_order = follow_order
		# 	has_fleet_order = move_to_system_point_order	
		# }
		NOT = {
			has_fleet_flag = auto_construct_blocked_fleet_flag
		}
	}
	[[BLOCK_SYSTEM]
		$BLOCK_SYSTEM$ = {
			NOR = {
				has_star_flag = auto_construct_blocked_system_flag
				any_fleet_in_system = {
					exists = owner
					has_fleet_flag = auto_construct_blocked_fleet_flag
				}
			}
		}
	]
	[[BLOCK_PLANET]
		$BLOCK_PLANET$ = {
			NOT = {
				any_fleet_in_orbit = {
					has_fleet_flag = auto_construct_blocked_fleet_flag
				}
			}
		}
	]
}

# scope must be fleet (construction ship)
auto_construct_outposts_check = {
	$CHECK_SYSTEM$ = {
		is_surveyed = {
			who = prev.owner
			status = yes
		}	
		# NOR = {
		# 	exists = owner
		# 	system_star = {
		# 		has_carrier_flag = auto_construct_carrier_flag
		# 	}
		# 	has_star_flag = auto_construct_system_flag
		# }
		any_neighbor_system = {
			exists = space_owner
			is_owned_by = prevprev.owner
		}
		NOR = {
			exists = owner
			any_neighbor_system = {
				exists = space_owner
				space_owner = {
					is_country_type = fallen_empire
					OR = {
						has_ethic = ethic_xenophobe
						has_ethic = ethic_fanatic_xenophobe
					}
				}
			}
			any_ship_in_system = {
				exists = owner
				OR = {
					is_constructing = starbase_outpost
					owner = {
						is_hostile = prevprevprev.owner
					}
				}
			}
		}
	}
	[[CHECK_PLANET]
		$CHECK_PLANET$ = {
			is_primary_star = yes
			has_orbital_station = no
		}
	]
}

species_coloniseable_planet = {
	is_colony = no
	has_anomaly = no
	colonizable_planet = yes
	if = {
		limit = {
			root.owner = {
				has_country_flag = habitability_threshold_1
			}
		}
		habitability = {
			who = root.owner.owner_species
			value >= 0.1
		}
	}
	else_if = {
		limit = {
			root.owner = {
				has_country_flag = habitability_threshold_2
			}
		}
		habitability = {
			who = root.owner.owner_species
			value >= 0.2
		}
	}
	else_if = {
		limit = {
			root.owner = {
				has_country_flag = habitability_threshold_3
			}
		}
		habitability = {
			who = root.owner.owner_species
			value >= 0.3
		}
	}
	else_if = {
		limit = {
			root.owner = {
				has_country_flag = habitability_threshold_4
			}
		}
		habitability = {
			who = root.owner.owner_species
			value >= 0.4
		}
	}
	else_if = {
		limit = {
			root.owner = {
				has_country_flag = habitability_threshold_5
			}
		}
		habitability = {
			who = root.owner.owner_species
			value >= 0.5
		}
	}
	else_if = {
		limit = {
			root.owner = {
				has_country_flag = habitability_threshold_6
			}
		}
		habitability = {
			who = root.owner.owner_species
			value >= 0.6
		}
	}
	else = {
		habitability = {
			who = root.owner.owner_species
			value >= 0.7
		}
	}
}

check_leader_cost = {
	switch = {
		trigger = has_total_skill

		1 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 99
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		2 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 169
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		3 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 349
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		4 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 624
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		5 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 999
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		6 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 1474
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		7 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 2049
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		8 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 2724
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		9 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 3499
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
		10 = {
			root = {
				resource_stockpile_compare = {
					resource = unity
					value > 4499
					mult = value:positive_modifier_mult|MODIFIER|leaders_cost_mult|
				}
			}
		}
	}
}

# auto_construct_planet_check = {
# 	is_surveyed = {
# 		who = root.owner
# 		status = yes
# 	}
# 	OR = {
# 		has_deposit_for = shipclass_mining_station
# 		#has_deposit_for = shipclass_observation_station
# 		has_deposit_for = shipclass_research_station
# 	}
# 	has_orbital_station = no
# 	has_any_megastructure = no
# 	NOR = {
# 		exists = owner
# 		has_deposit = d_trade_value_1
# 		has_deposit = d_trade_value_2
# 		has_deposit = d_trade_value_3
# 		has_deposit = d_trade_value_4
# 		has_deposit = d_trade_value_5
# 		has_deposit = d_trade_value_6
# 		has_deposit = d_trade_value_7
# 		has_deposit = d_trade_value_8
# 		has_deposit = d_trade_value_9
# 		has_deposit = d_trade_value_10
# 		AND = {
# 			has_resource = {
# 				type = sr_dark_matter amount > 0
# 			}
# 			root.owner = {
# 				NOT = {
# 					has_technology = tech_mine_dark_matter
# 				}
# 			}
# 		}
# 		AND = {
# 			has_resource = {
# 				type = volatile_motes amount > 0
# 			}
# 			root.owner = {
# 				NOT = {
# 					has_technology = tech_mine_volatile_motes
# 				}
# 			}
# 		}
# 		AND = {
# 			has_resource = {
# 				type = sr_living_metal amount > 0
# 			}
# 			root.owner = {
# 				NOT = {
# 					has_technology = tech_mine_living_metal
# 				}
# 			}
# 		}
# 		AND = {
# 			has_resource = {
# 				type = rare_crystals amount > 0
# 			}
# 			root.owner = {
# 				NOT = {
# 					has_technology = tech_mine_rare_crystals
# 				}
# 			}
# 		}
# 		AND = {
# 			has_resource = { 
# 				type = exotic_gases amount > 0
# 			}
# 			root.owner = {
# 				NOT = {
# 					has_technology = tech_mine_exotic_gases
# 				}
# 			}
# 		}
# 		AND = {
# 			has_resource = { 
# 				type = sr_zro amount > 0
# 			}
# 			root.owner = {
# 				NOT = {
# 					has_technology = tech_mine_zro
# 				}
# 			}
# 		}
# 		has_carrier_flag = auto_construct_planet_flag
# 	}
# }