default_naval_role_ratios = {
	allowed = {
		OR = {
			#Random land-locked nations should never have functionoing naval AI unless they get contnet. Can reowrk at a later date
			any_owned_state = {
				is_coastal = yes
			}
			# Custom Content Nations - These can become coastal through generic means - Add if they can change their situation
			original_tag = BOL
			original_tag = ETH
			original_tag = AFG
			original_tag = TAL
			original_tag = ISI
			original_tag = SER
			original_tag = PAR
		}

		#Menial Nations and Custom AI Nations - Add to Custom AI if you are buildng custom AI- Default should not apply
		NOT = {
            original_tag = ANT #Antigua and Barbuda
			original_tag = MNC #Monaco
			original_tag = ADO #Andorra
			original_tag = LIC #Lic
			original_tag = BHU #Bhutan
			original_tag = BRU #Brunei
			original_tag = MIC #Micronesia
			original_tag = SAM #Samoa
			original_tag = STK #Saint Kitts and Nevis
			original_tag = DMI #Dominica
			original_tag = STL #Saint Lucia
			original_tag = STV #Saint Vincent and the Grenadines
			original_tag = BAR #Barbados
			original_tag = BAH #Bahamas
			original_tag = GRA #Grenada
			original_tag = JAM #Jamacia
			original_tag = SEY #Seychelles
			original_tag = GUY #Guyana
			original_tag = SUR #Suriname
			original_tag = COS #Costa Rica
			original_tag = VER #Cape Verde
			original_tag = GAM #Gambia
			original_tag = GUB #Guinea - Bissau
			original_tag = EGU #Equatorial Guinea
			original_tag = SAO #Sao Tome
			original_tag = DJI #Djibouti
			original_tag = MLD #Maldives
			original_tag = COM #Comoros
			original_tag = MRT #Mauritius
			original_tag = SOL #Solomon Islands
			original_tag = SHA #Sahrawi
			original_tag = LUX #Luxembourg
			original_tag = ICE #Iceland
			original_tag = PAU #Palau
			original_tag = MAR #Marshall Islands
			original_tag = KIR #Kiribati
			original_tag = TUL #Tuvalu
			original_tag = VAN #Vanuatu
			original_tag = TON #Tonga
			original_tag = NAU #Nauru

			#Custom AI
			original_tag = USA #United States
			original_tag = CHI #China
			original_tag = AST #Australia
			original_tag = BRA #Brazil
			original_tag = CAN #Canada
			original_tag = DEN #Denmark
			original_tag = ENG #England
			original_tag = FRA #France
			original_tag = GER #Germany
			original_tag = GRE #Greece
			original_tag = HOL #Holland
			original_tag = ITA #Italy
			original_tag = JAP #Japan
			original_tag = KOR #South Korea
			original_tag = NKO #North Korea
			original_tag = POR #Portugal
			original_tag = RAJ #India
			original_tag = SOV #Russia
			original_tag = SPR #Spain
			original_tag = TUR #Turkey
			original_tag = SWE #Sweden
			original_tag = IND #Indonesia
			original_tag = SIA #Thailand
			original_tag = TAI #Taiwan
			original_tag = EGY #Egypt
		}
	}
	enable = { always = yes }
	abort_when_not_enabled = yes

	ai_strategy = { type = role_ratio id = naval_corvettes value = 30 }
	ai_strategy = { type = role_ratio id = naval_frigate value = 20 }
	ai_strategy = { type = role_ratio id = naval_destroyer value = 15 }
	ai_strategy = { type = role_ratio id = naval_stealth_destroyer value = 1 }
	ai_strategy = { type = role_ratio id = naval_attack_submarine value = 25 }
	ai_strategy = { type = role_ratio id = naval_missile_submarine value = 1 }
	ai_strategy = { type = role_ratio id = naval_helicopter_operator value = 1 }
	ai_strategy = { type = role_ratio id = naval_carrier value = 5 }
	ai_strategy = { type = role_ratio id = naval_cruiser value = 3 }
	ai_strategy = { type = role_ratio id = naval_mine_sweeper value = 5 }
	#ai_strategy = { type = role_ratio id = naval_mine_layer value = 5 }
}

##Generic Naval
peace_time_naval_missions = {
	enable = { has_war = no }
	abort_when_not_enabled = yes

	ai_strategy = { type = naval_mission_threshold id = "MISSION_PATROL" value = 50000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_STRIKE_FORCE" value = 40000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_ESCORT" value = 50000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_RAIDING" value = 40000 }
}

halt_sub_missions = {
	enable = {
		OR = {
			any_enemy_country = {
				strength_ratio = { tag = ROOT ratio = 0.25 }
			}
			alliance_naval_strength_ratio < 0.25
			fuel_ratio < 0.20
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_RAIDING" value = 50000 }
}

conserve_fuel = {
	enable = { fuel_ratio < 0.25 }
	abort = { fuel_ratio > 0.5 }

	ai_strategy = { type = naval_mission_threshold id = "MISSION_STRIKE_FORCE" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_RAIDING" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_MINES_PLANTING" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_MINES_SWEEPING" value = 200000 }
}

conserve_fuel_if_fighting_landlocked_nations = {
	enable = {
		all_enemy_country = {
			any_owned_state = {
				is_coastal = no
			}
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = naval_mission_threshold id = "MISSION_PATROL" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_STRIKE_FORCE" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_ESCORT" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_RAIDING" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_MINES_PLANTING" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_MINES_SWEEPING" value = 200000 }
}

conserve_fuel_peace_time = {
	enable = {
		has_war = no
		has_navy_size = { size > 0 }
		fuel_ratio < 1.0
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = naval_mission_threshold id = "MISSION_PATROL" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_STRIKE_FORCE" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_ESCORT" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_CONVOY_RAIDING" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_MINES_PLANTING" value = 200000 }
	ai_strategy = { type = naval_mission_threshold id = "MISSION_MINES_SWEEPING" value = 200000 }
}

# avoid_mediterranean = {
# 	#This is to avoid the Naval death trap that is Med without owning one of the islands or states around the coast
# 	allowed = {
# 		NOT = {
# 			mediterranean_tags = yes
# 		}
# 	}
# 	enable = {
# 		NOT = {
# 			controls_state = 19 #Gibraltar
# 			controls_state = 94 #Mallorca
# 			controls_state = 84 #Sardinia
# 			controls_state = 65 #Corsica
# 			controls_state = 84 #Malta
# 			controls_state = 144 #Crete
# 			controls_state = 143 #Aegean Islands
# 			#Cyprus - 3 State
# 			controls_state = 145
# 			controls_state = 146
# 			controls_state = 812
# 		}
# 		any_country = {
# 			limit = {
# 				mediterranean_tags = yes
# 			}
# 			is_leading_volunteer_group_with_original_country = PREV
# 		}
# 		alliance_naval_strength_ratio < 4
# 	}
# 	abort_when_not_enabled = yes

# 	ai_strategy = { type = naval_avoid_region id = 25 value = 10000 }
# 	ai_strategy = { type = naval_avoid_region id = 29 value = 10000 }
# 	ai_strategy = { type = naval_avoid_region id = 68 value = 10000 }
# 	ai_strategy = { type = naval_avoid_region id = 69 value = 10000 }
# 	ai_strategy = { type = naval_avoid_region id = 168 value = 10000 }
# 	ai_strategy = { type = naval_avoid_region id = 169 value = 10000 }
# }

ship_limiter = {
	allowed = {
		has_global_flag = GAME_RULE_division_limiter_enabled
		NOT = {
            original_tag = ANT #Antigua and Barbuda
			original_tag = MNC #Monaco
			original_tag = ADO #Andorra
			original_tag = LIC #Lic
			original_tag = BHU #Bhutan
			original_tag = BRU #Brunei
			original_tag = MIC #Micronesia
			original_tag = SAM #Samoa
			original_tag = STK #Saint Kitts and Nevis
			original_tag = DMI #Dominica
			original_tag = STL #Saint Lucia
			original_tag = STV #Saint Vincent and the Grenadines
			original_tag = BAR #Barbados
			original_tag = BAH #Bahamas
			original_tag = GRA #Grenada
			original_tag = JAM #Jamacia
			original_tag = SEY #Seychelles
			original_tag = GUY #Guyana
			original_tag = SUR #Suriname
			original_tag = COS #Costa Rica
			original_tag = VER #Cape Verde
			original_tag = GAM #Gambia
			original_tag = GUB #Guinea - Bissau
			original_tag = EGU #Equatorial Guinea
			original_tag = SAO #Sao Tome
			original_tag = DJI #Djibouti
			original_tag = MLD #Maldives
			original_tag = COM #Comoros
			original_tag = MRT #Mauritius
			original_tag = SOL #Solomon Islands
			original_tag = SHA #Sahrawi
			original_tag = LUX #Luxembourg
			original_tag = ICE #Iceland
			original_tag = PAU #Palau
			original_tag = MAR #Marshall Islands
			original_tag = KIR #Kiribati
			original_tag = TUL #Tuvalu
			original_tag = VAN #Vanuatu
			original_tag = TON #Tonga
			original_tag = NAU #Nauru
		}
	}
	enable = {
		set_temp_variable = { ship_limit = num_of_naval_factories } # 5
		multiply_temp_variable = { ship_limit = 7 } #50

		if = { limit = { has_war = yes }
			multiply_temp_variable = { ship_limit = 1.15 } # 57.50
		}
		else = {
			multiply_temp_variable = { ship_limit = 0.65 } # 32.50
		}

		if = {
			limit = {
				OR = {
					has_country_flag = ai_yes_unit_build
					has_country_flag = AI_is_threatened
				}
			}
			multiply_temp_variable = { ship_limit = 1.25 } #If the AI didn't have divisions it is now 75
		}
		if = { limit = { is_major = yes }
			multiply_temp_variable = { ship_limit = 1.15 } #If the major is 86.25
		}
		if = { limit = { has_idea = NATO_member }
			multiply_temp_variable = { ship_limit = 0.70 } #if the nation is in the EU 51.75
		}
		if = { limit = { has_idea = EU_member }
			multiply_temp_variable = { ship_limit = 0.70 } #If the nation is also in NATO 31.05
		}
		if = { limit = { threat > 0.50 }
			multiply_temp_variable = { ship_limit = 1.25 } #38 if true
		}
		else = {
			multiply_temp_variable = { ship_limit = 0.85 } #26.39
		}

		if = { limit = { is_in_faction = yes }
			multiply_temp_variable = { ship_limit = 0.90 } #73.9
		}
		if = { limit = { original_tag = USA }
			multiply_temp_variable = { ship_limit = 1.25 }
		}
		round_temp_variable = ship_limit #27
		check_variable = { num_ships > ship_limit }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = unit_ratio id = convoy value = 500 }
	ai_strategy = { type = role_ratio id = naval_corvettes value = -50 }
	ai_strategy = { type = role_ratio id = naval_frigate value = -50 }
	ai_strategy = { type = role_ratio id = naval_destroyer value = -50 }
	ai_strategy = { type = role_ratio id = naval_stealth_destroyer value = -50 }
	ai_strategy = { type = role_ratio id = naval_attack_submarine value = -50 }
	ai_strategy = { type = role_ratio id = naval_missile_submarine value = -50 }
	ai_strategy = { type = role_ratio id = naval_helicopter_operator value = -50 }
	ai_strategy = { type = role_ratio id = naval_carrier value = -50 }
	ai_strategy = { type = role_ratio id = naval_cruiser value = -50 }
	ai_strategy = { type = role_ratio id = naval_mine_sweeper value = -50 }
}

ship_limiter_potato_edition = {
	allowed = {
		has_global_flag = GAME_RULE_division_limiter_potato_edition_enabled
		NOT = {
			original_tag = ANT #Antigua and Barbuda
			original_tag = MNC #Monaco
			original_tag = ADO #Andorra
			original_tag = LIC #Lic
			original_tag = BHU #Bhutan
			original_tag = BRU #Brunei
			original_tag = MIC #Micronesia
			original_tag = SAM #Samoa
			original_tag = STK #Saint Kitts and Nevis
			original_tag = DMI #Dominica
			original_tag = STL #Saint Lucia
			original_tag = STV #Saint Vincent and the Grenadines
			original_tag = BAR #Barbados
			original_tag = BAH #Bahamas
			original_tag = GRA #Grenada
			original_tag = JAM #Jamacia
			original_tag = SEY #Seychelles
			original_tag = GUY #Guyana
			original_tag = SUR #Suriname
			original_tag = COS #Costa Rica
			original_tag = VER #Cape Verde
			original_tag = GAM #Gambia
			original_tag = GUB #Guinea - Bissau
			original_tag = EGU #Equatorial Guinea
			original_tag = SAO #Sao Tome
			original_tag = DJI #Djibouti
			original_tag = MLD #Maldives
			original_tag = COM #Comoros
			original_tag = MRT #Mauritius
			original_tag = SOL #Solomon Islands
			original_tag = SHA #Sahrawi
			original_tag = LUX #Luxembourg
			original_tag = ICE #Iceland
			original_tag = PAU #Palau
			original_tag = MAR #Marshall Islands
			original_tag = KIR #Kiribati
			original_tag = TUL #Tuvalu
			original_tag = VAN #Vanuatu
			original_tag = TON #Tonga
			original_tag = NAU #Nauru
		}
	}
	enable = {
		set_temp_variable = { ship_limit = num_of_naval_factories } # 5
		multiply_temp_variable = { ship_limit = 3 } #50

		if = { limit = { has_war = yes }
			multiply_temp_variable = { ship_limit = 1.15 } # 57.50
		}
		else = {
			multiply_temp_variable = { ship_limit = 0.65 } # 32.50
		}

		if = {
			limit = {
				OR = {
					has_country_flag = ai_yes_unit_build
					has_country_flag = AI_is_threatened
				}
			}
			multiply_temp_variable = { ship_limit = 1.25 } #If the AI didn't have divisions it is now 75
		}
		if = { limit = { is_major = yes }
			multiply_temp_variable = { ship_limit = 1.15 } #If the major is 86.25
		}
		if = { limit = { has_idea = NATO_member }
			multiply_temp_variable = { ship_limit = 0.50 } #if the nation is in the EU 51.75
		}
		if = { limit = { has_idea = EU_member }
			multiply_temp_variable = { ship_limit = 0.50 } #If the nation is also in NATO 31.05
		}
		if = { limit = { threat > 0.50 }
			multiply_temp_variable = { ship_limit = 1.25 } #38 if true
		}
		else = {
			multiply_temp_variable = { ship_limit = 0.85 } #26.39
		}

		if = { limit = { is_in_faction = yes }
			multiply_temp_variable = { ship_limit = 0.90 } #73.9
		}
		if = { limit = { original_tag = USA }
			multiply_temp_variable = { ship_limit = 1.25 }
		}
		round_temp_variable = ship_limit #27
		check_variable = { num_ships > ship_limit }
	}
	abort_when_not_enabled = yes

	ai_strategy = { type = equipment_variant_production_factor id = convoy value = 500 }
	ai_strategy = { type = unit_ratio id = convoy value = 500 }
	ai_strategy = { type = role_ratio id = naval_corvettes value = -50 }
	ai_strategy = { type = role_ratio id = naval_frigate value = -50 }
	ai_strategy = { type = role_ratio id = naval_destroyer value = -50 }
	ai_strategy = { type = role_ratio id = naval_stealth_destroyer value = -50 }
	ai_strategy = { type = role_ratio id = naval_attack_submarine value = -50 }
	ai_strategy = { type = role_ratio id = naval_missile_submarine value = -50 }
	ai_strategy = { type = role_ratio id = naval_helicopter_operator value = -50 }
	ai_strategy = { type = role_ratio id = naval_carrier value = -50 }
	ai_strategy = { type = role_ratio id = naval_cruiser value = -50 }
	ai_strategy = { type = role_ratio id = naval_mine_sweeper value = -50 }
}