REPLACE:wanted_army_size_script_value = {
	# How many levels of barracks should the AI have
	# Using this value in other strategies will function additively
	value = 0

	# To increase base army size for small countries, capped at 1 million population
	add = {
		value = cached_ai_incorporated_population
		divide = 250000 # 1 level of barracks per 250k incorporated population

		max = 4
	}

	add = {
		value = cached_ai_incorporated_population
		divide = 250000 # 1 level of barracks per 250k incorporated population
	}

	add = {
		value = cached_ai_unincorporated_population
		divide = 1000000 # 1 level of barracks per 1 million unincorporated population
	}

	# Extra army size from rank
	if = {
		limit = { country_rank = rank_value:great_power }
		add = 25
	}
	if = {
		limit = { country_rank = rank_value:major_power }
		add = 10
	}

	save_temporary_value_as = pre_overseas_empire_value

	# Countries with a huge overseas subject population should focus more on navy
	subtract = {
		value = cached_ai_overseas_subject_population
		divide = 50000000
		max = {
			value = scope:pre_overseas_empire_value
			divide = 2
		}
	}

	max = 200 # No more than 200 from population & rank

	if = {
		limit = {
			cached_ai_incorporated_population > 0
			cached_ai_incorporated_coastal_population > 0
		}

		add = {
			value = fixed_income
			multiply = {
				value = 1
				subtract = { # Coastal population reduces spending on army as that spending is needed for navy too
					value = cached_ai_incorporated_coastal_population
					divide = cached_ai_incorporated_population
					divide = 4
				}
			}
			divide = 2500 # 1 level of barracks per 2.5k income
		}
	}

	# More advanced standing armies are expensive and should be smaller relative to population
	if = {
		limit = { has_technology_researched = general_staff }
		multiply = 0.8
	}

	if = {
		limit = { has_technology_researched = trench_works }
		multiply = 0.8
	}

	if = {
		limit = { has_technology_researched = nco_training }
		multiply = 0.8
	}

	if = {
		limit = { has_technology_researched = mobile_armor }
		multiply = 0.8
	}

	#T&R

	if = {
		limit = { has_technology_researched = mechanized_infantry }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = main_battle_tank }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = composite_armor }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = radar }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = precision_ammunition }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = laser_guided_weapons }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = high_performance_apparel }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = cannon_launched_guided_projectiles }
		multiply = 0.9 #+25% in country_military_wages_mult
	}

	#T&R
	if = {
		limit = {
			OR = {
				has_strategy = ai_strategy_superpower_command_hegemony
				has_strategy = ai_strategy_superpower_liberal_hegemony
			}
		}
		multiply = 2
	}

	# General multiplier for easy adjustment
	multiply = 1.0

	# Factor in strategies
	if = {
		limit = {
			OR = {
				has_strategy = ai_strategy_territorial_expansion
				has_strategy = ai_strategy_unify_italy
				has_strategy = ai_strategy_unify_ethiopia
				has_strategy = ai_strategy_unify_china
			}
		}
		multiply = 1.25
	}
	else_if = {
		limit = {
			has_strategy = ai_strategy_unify_germany
		}
		multiply = 2.0
	}

	if = {
		limit = { has_law_or_variant = law_type:law_national_militia }
		multiply = 0.33
	}

	if = {
		limit = {
			OR = {
				has_journal_entry = je_prussia_of_the_balkans
				has_strategy = ai_strategy_prussia_of_the_balkans
			}
		}
		multiply = 2.5
	}


	if = {
		limit = {
			capital = {
				OR = {
					is_in_geographic_region = geographic_region_england_old
					is_in_geographic_region = geographic_region_north_sea_coast_old
				}
			}
		}

		multiply = 0.75
	}

	if = {
		limit = {
			has_journal_entry = je_lands_of_anarchy
		}
		multiply = 1.5 # More eager to enlarge army in general during the makhzen je
	}
	
	# Multiply final value by diplomatic pact expenses ratio - countries paying a lot to pacts have lower spending ambitions
	multiply = {
		value = 1
		subtract = diplomatic_pact_expense_ratio
	}

	min = {
		value = 1

		if = {
			limit = {
				has_journal_entry = je_sick_man_army
			}
			value = 125
		}
		if = { #if Mon is raiding, troops pay for themselves and are the countries main source of income
			limit = {
				has_journal_entry = je_montenegrin_raiding
			}
			value = 20
		}
		if = {
			limit = {
				has_journal_entry = je_prussia_of_the_balkans
			}
			value = 35
		}

		if = { #If accepted Negotiation quest, build barracks until JE ends
			limit = {
				has_journal_entry = je_negotiate_army_quest
			}
			add = {
				every_interest_group = { #first get the desired app from the IG
					limit = {
						has_variable = desired_army_size
					}
					add = var:desired_army_size
				}
				divide = average_barracks_power_projection #divide by the amount of barracks this will need based on average barracks power projection
				multiply = 1.10 #safety margin
			}
		}
	}
}

wanted_marines_size_script_value = {
	value = 0

	# 1 marine per 1 mil coastal incorporated population
	add = {
		value = cached_ai_incorporated_coastal_population
		divide = 1000000
	}
	# 1 marine per 5 million coastal unincorporated population
	add = {
		value = cached_ai_unincorporated_coastal_population
		divide = 5000000
	}
	# 1 marine per 20 million population in direct overseas subjects
	add = {
		value = cached_ai_overseas_subject_population
		divide = 20000000
	}
	max = 25 # No more than 25 from population
	# 1 marine per 15k income, multiplied by relative incorporated coastal population to total incorporated population
	if = {
		limit = {
			cached_ai_incorporated_population > 0
			cached_ai_incorporated_coastal_population > 0
		}
		add = {
			value = fixed_income
			divide = cached_ai_incorporated_population
			multiply = cached_ai_incorporated_coastal_population
			divide = 15000
		}
	}
	# Special logic for british isles - this should be reworked to be less specific later
	if = {
		limit = {
			capital = {
				OR = {
					is_in_geographic_region = geographic_region_england_old
					is_in_geographic_region = geographic_region_north_sea_coast_old
				}
			}
		}
		add = 10
	}
	else_if = { # GPs and MPs should want to maintain some marines
		limit = { country_rank = rank_value:great_power }
		add = 5
	}
	else_if = {
		limit = { country_rank = rank_value:major_power }
		add = 2
	}

	#T&R

	if = {
		limit = { has_technology_researched = mechanized_infantry }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = radar }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = precision_ammunition }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	if = {
		limit = { has_technology_researched = high_performance_apparel }
		multiply = 0.9 #+25% in country_military_wages_mult
	}
	
	# General multiplier for easy adjustment
	multiply = 0.5
	
	# Less marines before we have steel ships
	if = {
		limit = { NOT = { has_technology_researched = ironclad_tech } }
		multiply = 0.5
	}	

	# Factor in strategies
	if = {
		limit = {
			OR = {
				has_strategy = ai_strategy_colonial_expansion
				has_strategy = ai_strategy_economic_imperialism
			}
		}
		multiply = 1.25
	}
	if = {
		limit = { has_strategy = ai_strategy_armed_isolationism }
		multiply = 0.5
	}
	if = {
		limit = { 
			OR = {
				country_rank < rank_value:minor_power
				is_country_type = unrecognized
				has_strategy = ai_strategy_maintain_mandate_of_heaven
			}
		}
		multiply = 0
	}
	
	# Multiply final value by diplomatic pact expenses ratio - countries paying a lot to pacts have lower spending ambitions
	multiply = {
		value = 1
		subtract = diplomatic_pact_expense_ratio
	}
	
	max = total_marine_capacity
}

REPLACE:wanted_navy_size_script_value = {
	value = 0

	# 1 ship per 500k coastal incorporated population
	add = {
		value = cached_ai_incorporated_coastal_population
		divide = 500000
	}
	# 1 ship per 2 million coastal unincorporated population
	add = {
		value = cached_ai_unincorporated_coastal_population
		divide = 2000000
	}
	# 1 ship per 10 million population in direct overseas subjects
	add = {
		value = cached_ai_overseas_subject_population
		divide = 10000000
	}
	max = 100 # No more than 100 from population
	# 1 ship per 5k income, multiplied by relative incorporated coastal population to total incorporated population
	if = {
		limit = {
			cached_ai_incorporated_population > 0
			cached_ai_incorporated_coastal_population > 0
		}
		add = {
			value = fixed_income
			divide = cached_ai_incorporated_population
			multiply = cached_ai_incorporated_coastal_population
			divide = 5000
		}
	}
	# Special logic for british isles - this should be reworked to be less specific later
	if = {
		limit = {
			country_rank = rank_value:great_power
			capital = {
				OR = {
					is_in_geographic_region = geographic_region_england_old
					is_in_geographic_region = geographic_region_north_sea_coast_old
				}
			}
		}
		add = 100
	}
	else_if = { # GPs and MPs should want to maintain a bit of a navy
		limit = { country_rank = rank_value:great_power }
		add = 25
	}
	else_if = {
		limit = { country_rank = rank_value:major_power }
		add = 10
	}
	
	# General multiplier for easy adjustment
	multiply = 0.75
	
	# More advanced ships require more crew
	if = {
		limit = { has_technology_researched = ironclad_tech }
		multiply = 1.15
	}
	if = {
		limit = { has_technology_researched = dreadnought_tech }
		multiply = 1.25
	}
	if = {
		limit = { has_technology_researched = battleship_tech }
		multiply = 1.25
	}

	# Journal related AI behaviours, choose this if you DONT care about the exact number of ships
	if = {
		limit = {
			has_journal_entry = je_reconquista
		}
		multiply = 1.25
	}

	# Factor in strategies

	#T&R

	if = {
		limit = { has_technology_researched = modern_battleships }
		multiply = 1.25
	}

	if = {
		limit = {
			has_modifier = ztr_superpower
		}
		multiply = 3
	}

	if = {
		limit = {
			c:USA = this
			has_modifier = ztr_superpower
		}
		multiply = 1.5
	}
	
	if = {
		limit = {
			OR = {
				has_strategy = ai_strategy_colonial_expansion
				has_strategy = ai_strategy_economic_imperialism
			}
		}
		multiply = 1.15
	}
	if = {
		limit = { has_strategy = ai_strategy_armed_isolationism }
		multiply = 0.75
	}
	if = {
		limit = { country_rank < rank_value:major_power }
		multiply = 0.5
	}
	if = {
		limit = { is_country_type = unrecognized }
		multiply = 0.5
	}
	if = {
		limit = { has_strategy = ai_strategy_maintain_mandate_of_heaven }
		multiply = 0.25
	}
	
	# Multiply final value by diplomatic pact expenses ratio - countries paying a lot to pacts have lower spending ambitions
	multiply = {
		value = 1
		subtract = diplomatic_pact_expense_ratio
	}	

	# Journal related AI behaviours, choose this if you DO care about the exact number of ships
	if = {
		limit = {
			has_journal_entry = je_hawaii
		}
		min = 25
	}
}