#Defensive armies can't transport of the planet
#maintenance is directly scripted here. 0.25 translates to 0.25 monthly cost (excluding other upkeep modifiers)
#morale_damage = 1		# average morale damage of the army, default: auto (calculated from morale * MORALE_DAMAGE_MULT)
#building spawned armies can't be built normally, but only created from pops working buildings

#spawn_chance: only works on defensive armies; pop scope check that lets you give weights for what sort of army should be spawned
#		Calculation is health * spawn_chance (default: 1), and it always picks the best one

# Defense Armies
defense_army = {
	defensive = yes
	is_pop_spawned = yes
	health = 1.25
	damage = 1.50
	morale = 1.25
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_army_type_defensive

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}

	potential = {
		from = {
			NOR = {
				has_trait = "trait_mechanical"
				has_trait = "trait_machine_unit"
				is_sapient = no
			}
		}
		owner = {
			is_primitive = no
			OR = {
				is_machine_empire = no
				has_valid_civic = civic_machine_assimilator
			}
			is_wilderness_empire = no
		}
	}
}

# Undead Armies
undead_defense_army = {
	defensive = yes
	is_pop_spawned = yes
	health = 1.75
	damage = 1.50
	collateral_damage = 0.0
	has_morale = no
	morale_damage = 1.75
	war_exhaustion = 0.0
	icon = GFX_army_type_undead
	use_armynames_from = undead_army

	potential = {
		from = {
			NOR = {
				has_trait = "trait_mechanical"
				has_trait = "trait_machine_unit"
				is_sapient = no
			}
		}
		planet = {
			OR = {
				has_active_building = building_dread_encampment
				has_carrier_flag = active_dread_outpost
			}
		}
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}

	spawn_chance = {
		factor = 100
	}
}

# Robotic Armies
robotic_defense_army = {
	defensive = yes
	is_pop_spawned = yes
	damage = 1.00
	health = 1.25
	morale_damage = 1.00
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	has_morale = no
	icon = GFX_army_type_robot
	has_species = yes

	potential = {
		from = {
			has_trait = "trait_mechanical"
		}
		owner = {
			is_machine_empire = no
		}
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}

	allow = {
		owner = { NOT = { has_policy_flag = robots_outlawed } }
	}
}

shroud_forged_defense_army = {
	defensive = yes
	is_pop_spawned = yes
	damage = 1.25
	health = 1.25
	morale = 1.50
	morale_damage = 1.00
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_army_type_robot
	has_species = yes
	use_armynames_from = robotic_defense_army

	potential = {
		from = {
			has_trait = trait_shroud_forged
		}
		owner = {
			has_origin = origin_shroud_forged
		}
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}

	spawn_chance = {
		factor = 2
	}
}

### Machine Empire Armies
machine_defense = {
	defensive = yes
	is_pop_spawned = yes
	health = 1.10
	damage = 1.10
	has_morale = no
	morale_damage = 1.00
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_army_type_machine_defensive
	has_species = yes

	potential = {
		owner = {
			is_machine_empire = yes
		}
		from = {
			has_trait = "trait_machine_unit"
		}
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}
}

offspring_defense = {
	defensive = yes
	is_pop_spawned = yes
	health = 2
	damage = 1.75
	has_morale = no
	morale_damage = 1.30
	collateral_damage = 0.0
	war_exhaustion = 0.0
	icon = GFX_army_type_xenomorph
	has_species = yes

	potential = {
		OR = {
			AND = {
				exists = planet.owner.overlord
				has_holding = {
					holding = holding_offspring_nest
					owner = planet.owner.overlord
				}
			}
			AND = {
				planet.owner = { has_origin = origin_progenitor_hive }
				OR = {
					AND = {
						has_offspring_nest = yes
						num_assigned_jobs = {
							job = spawning_drone
							value >= 100
						}
					}
					has_deposit = d_progenitor
				}
			}
		}
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}
}

# Wilderness Defense
wilderness_pre_sapient_defence_army = {
	defensive = yes
	is_pop_spawned = yes
	health = 1.25
	damage = 1.50
	morale = 1.25
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_wilderness_army_type_defensive

	potential = {
		exists = owner
		owner = {
			is_wilderness_empire = yes
		}
	}
}

################################
# Sovereign Guardianship Civic #
################################

fanatic_guardian = {
	defensive = yes
	is_pop_spawned = yes
	health = 2.5
	damage = 3
	morale = 2.5
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_army_type_defensive

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}

	potential = {
		owner = {
			is_gestalt = no
			is_sovereign_guardianship_empire = yes
		}
	}

	army_modifier = {
		army_damage_empire_sprawl_penalty_mult = 1
	}
}

machine_fanatic_guardian = {	# Actually gestalt
	defensive = yes
	is_pop_spawned = yes
	health = 2.20
	damage = 2.20
	has_morale = no
	morale_damage = 2.00
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_army_type_machine_defensive
	has_species = yes

	potential = {
		owner = {
			is_gestalt = yes
			is_sovereign_guardianship_empire = yes
		}
	}

	army_modifier = {
		army_damage_empire_sprawl_penalty_mult = 1
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}
}

### Individual Machine Empire Armies
individual_machine_defense = {
	defensive = yes
	is_pop_spawned = yes
	health = 1.10
	damage = 1.10
	morale = 1.25
	morale_damage = 1.00
	collateral_damage = 0.0
	war_exhaustion = 0.0 # No WE from defense armies
	icon = GFX_army_type_machine_defensive
	has_species = yes

	potential = {
		owner = {
			is_individual_machine = yes
		}
		from = {
			has_trait = "trait_machine_unit"
		}
	}

	resources = {
		category = armies
		produces = {
			trigger = {
				exists = owner
				owner = { has_active_tradition = tr_unyielding_resistance_is_frugal }
			}
			unity = 0.5
		}
	}
}
