###HoI4 AI Unit Production Limiter###
### https://gitlab.com/coop-mods/Shared-Resources/tree/master/Scripts%20and%20Code/AI%20Unit%20Limiter
###------------------------------
###Originally made by GunnarVonPontius
###Adapted to variables by Yard1
###------------------------------
###Limits the amount of divisions an AI country has to the number of factories (civ, mil, nav) it has
###If your mod adds new unit types, make sure to add them in as well

#Kudos to the above using their code as a guide to make AI recruit divs

division_enforcer = {
	enable = {
		set_temp_variable = {
			lower_limit = num_of_factories
		}
		if = {
			limit = {
				num_of_factories < 2
			}
			add_to_temp_variable = {
				lower_limit = 5
			}
		}
		if = {
			limit = {
				has_war = yes
			}
			if = {
				limit = {
					is_insignificant_power = yes
					has_war = yes
				}
				multiply_temp_variable = {
					lower_limit = 5.0
				}
			}
			else_if = {
				limit = {
					is_minor_power = yes
					has_war = yes
				}
				multiply_temp_variable = {
					lower_limit = 2.75
				}
			}
			else_if = {
				limit = {
					is_secondary_power = yes
					has_war = yes
				}
				multiply_temp_variable = {
					lower_limit = 2.0
				}
			}
			if = {
				limit = {
					manpower_per_military_factory < 1000
				}
				multiply_temp_variable = {
					lower_limit = 0.5
				}
			}
			else_if = {
				limit = {
					has_manpower < 2500
				}
				multiply_temp_variable = {
					lower_limit = 0.0
				}
			}
			if = {
				limit = {
					alliance_strength_ratio > 5.0
				}
				multiply_temp_variable = {
					lower_limit = 0.1
				}
			}
			else_if = {
				limit = {
					alliance_strength_ratio > 2.0
				}
				multiply_temp_variable = {
					lower_limit = 0.33
				}
			}
			else_if = {
				limit = {
					enemies_strength_ratio > 5.0
				}
				multiply_temp_variable = {
					lower_limit = 5.0
				}
			}
			else_if = {
				limit = {
					enemies_strength_ratio > 2.0
				}
				multiply_temp_variable = {
					lower_limit = 3.0
				}
			}
			if = {
				limit = {
					ai_wants_divisions > lower_limit
				}
				multiply_temp_variable = {
					lower_limit = 2.0
				}
			}
		}
		else = {

		}
		
		
		
		check_variable = {
			num_divisions < lower_limit
		}
	}
	abort_when_not_enabled = yes

	ai_strategy = {
		type = build_army
		id = cavalry
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = camelry
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = motorized
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = armored_car
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = mechanized
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = garrison
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = suppression
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = paratroopers
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = mountaineers
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = marines
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = armor
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = light_armor
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = heavy_armor
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = medium_armor
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = modern_armor
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = infantry
		value = 300
	}

	ai_strategy = {
		type = build_army
		id = artillery
		value = 300
	}
	ai_strategy = {
		type = build_army
		id = cannon_artillery
		value = 300
	}
	ai_strategy = {
		type = build_army
		id = howitzer_artillery
		value = 300
	}

}