﻿on_game_start = {
	on_actions = {
		on_legion_counties
	}
}

on_legion_counties = {
	effect = {
		every_ruler = {
			limit = {
				OR = {
					has_government = imperial_government
					has_government = autocratic_government
				}
				primary_title.tier > tier_county
			}
			every_held_county = {
				limit = {
					NOT = {
						THIS = PREV.capital_county
					}
				}
				save_temporary_scope_as = legion_tmp
				PREV = {
					add_to_variable_list = {
						name = legion_county_available
						target = scope:legion_tmp
					}
				}
			}
			if = {
				limit = {
					has_variable_list = legion_county_available
				}
			}
		}
	}
	on_actions = {
		delay = { months = 6 }
		on_legion_counties
	}
}


on_legion_raise = {
	effect = {
		random_character_war = {
			save_temporary_scope_as = temp_war
		}
		if = {
			limit = {
				scope:county = {
					has_variable = prae_guard
				}
			}
			spawn_army = {
				name = prae_guard
				men_at_arms = {
					type = legions
					stacks = 15
				}
				inheritable = no
				war = scope:temp_war
				location = scope:county.holder.capital_province
			}
		}
		if = {
			limit = {
				scope:county = {
					NOT = {
						has_variable = prae_guard
					}
				}
					
			}
			spawn_army = {
				name = legion_army_name
				men_at_arms = {
					type = legions
					stacks = 10
				}
				war = scope:temp_war
				inheritable = no
				location = scope:county.holder.capital_province
			}
		}
		
	}
}