﻿ig_armed_forces = {
	color = hsv{ 0.09 0.29 0.39 }
	texture = "gfx/interface/icons/ig_icons/armed_forces.dds"
	layer = "revolution_dynamic_armed_forces"
	index = 0

	ideologies = {
		ideology_jingoist
		ideology_loyalist
		ideology_patriotic
	}

	enable = {
		always = yes
	}

	# Deprecated; use on_enable effect to assign traits instead
	traits = {
		ig_trait_patriotic_fervor
		ig_trait_veteran_consultation
		ig_trait_materiel_waste
	}

	on_enable = {
		ig:ig_armed_forces = {
			if = {
				limit = {
					owner = {
						c:CHI ?= this
					}
				}
				set_ig_trait = ig_trait:ig_trait_newly_created_army
				set_ig_trait = ig_trait:ig_trait_self_strengthening
				set_ig_trait = ig_trait:ig_trait_parochial_leadership
			}
			else_if = {
				limit = {
					owner = {
						OR = {
							c:FRA ?= this
							country_has_primary_culture = cu:french
						}
					}
				}
				set_ig_trait = ig_trait:ig_trait_materiel_waste
				set_ig_trait = ig_trait:ig_trait_veteran_consultation
				set_ig_trait = ig_trait:ig_trait_elan_vital
			}
			else_if = {
				limit = {
					owner = {
						any_primary_culture = {
							has_discrimination_trait = hispanophone
							has_discrimination_trait = european_heritage
							NOT = { has_discrimination_trait = iberian_culture_group }
						}
					}
				}
				set_ig_trait = ig_trait:ig_trait_materiel_waste
				set_ig_trait = ig_trait:ig_trait_veteran_consultation
				set_ig_trait = ig_trait:ig_trait_el_buen_jefe
			}
			else_if = {
				limit = {
					owner = {
						has_dlc_feature = rp1_content
						c:BRZ ?= this
					}
				}
				set_ig_trait = ig_trait:ig_trait_coronelismo
				set_ig_trait = ig_trait:ig_trait_clube_militar
				set_ig_trait = ig_trait:ig_trait_patriotic_fervor
			}
			else_if = {
				limit = {
					owner = {
					country_has_state_religion = rel:hindu
					}
				}
				set_ig_trait = ig_trait:ig_trait_materiel_waste
				set_ig_trait = ig_trait:ig_trait_armed_forces_supporting_caste
				set_ig_trait = ig_trait:ig_trait_patriotic_fervor
			}
			else = {
				set_ig_trait = ig_trait:ig_trait_materiel_waste
				set_ig_trait = ig_trait:ig_trait_veteran_consultation
				set_ig_trait = ig_trait:ig_trait_patriotic_fervor
			}
		}
		# Caudillo Ideology
		if = {
			limit = {
				OR = {
					country_has_primary_culture = cu:platinean
					country_has_primary_culture = cu:south_andean
					country_has_primary_culture = cu:north_andean
					country_has_primary_culture = cu:central_american
					country_has_primary_culture = cu:mexican
				}
			}
			ig:ig_armed_forces = {
				add_ideology = ideology_caudillismo
			}
		}
		# Samurai
		else_if = {
			limit = {
				country_has_primary_culture = cu:japanese
				NOT = { has_global_variable = fall_of_the_samurai_global_var }
			}
			ig:ig_armed_forces = {
				add_ideology = ideology_bakufu
				set_interest_group_name = ig_samurai
			}
		}
		# Kshatriyas Warriors
		else_if = {
			limit = { country_has_state_religion = rel:hindu }
			ig:ig_armed_forces = {
				set_interest_group_name = ig_kshatriyas_warriors
				#remove_ideology = ideology_moralist
				#add_ideology = ideology_hindu_moralist
				
			}
		}
	}
	on_disable = {}
	on_character_ig_membership = {}

	pop_potential = {
		OR = {
			is_pop_type = soldiers
			is_pop_type = officers
			is_pop_type = aristocrats
			pop_is_discriminated = no
		}
	}

	pop_weight = {
		value = 0

		add = {
			desc = "POP_NOT_DISCRIMINATED"
			if = {
				limit = {
					pop_is_discriminated = no
				}
				value = 25
				if = { # Militarisation of colonial settlers
					limit = {
						owner = {
							has_law = law_type:law_colonial_resettlement
						}
						state = {
							is_incorporated = no
						}
					}
					add = 50
				}
				if = { # Separation of the military and people
					limit = {
						NOR = {
							is_pop_type = soldiers
							is_pop_type = officers
						}
						owner = {
							has_law = law_type:law_professional_army
						}
					}
					divide = 2
				}
			}
		}

		add = {
			desc = "POP_SOLDIERS"
			if = {
				limit = {
					is_pop_type = soldiers
				}
				value = 100
				if = { # Institutional loyalty
					limit = {
						owner = {
							has_law = law_type:law_professional_army
						}
					}
					add = 50
				}
				if = { # Pay makes soldiers more inclined to be loyal to Armed Forces
					limit = {
						owner = {
							military_wage_level = very_low
						}
					}
					multiply = 0.75
				}
				if = {
					limit = {
						owner = {
							military_wage_level = low
						}
					}
					multiply = 0.85
				}
				if = {
					limit = {
						owner = {
							military_wage_level = medium
						}
					}
					multiply = 1
				}
				if = {
					limit = {
						owner = {
							military_wage_level = high
						}
					}
					multiply = 1.15
				}
				if = {
					limit = {
						owner = {
							military_wage_level = very_high
						}
					}
					multiply = 1.25
				}
			}
		}

		add = {
			desc = "POP_ARISTOCRATS"
			if = {
				limit = {
					is_pop_type = aristocrats
				}
				value = 50
				if = {
					limit = {
						owner = {
							has_law = law_type:law_peasant_levies
						}
					}
					add = 50
				}
			}
		}

		add = {
			desc = "POP_OFFICERS"
			if = {
				limit = {
					is_pop_type = officers
				}
				value = 250
			}
		}

		multiply = {
			desc = "LEADER_POPULARITY"
			scope:interest_group = {
				leader ?= {
					value = popularity
					multiply = 0.0025
					add = 1
					max = 1.25
					min = 0.75
				}
			}
		}
		if = {
			limit = {
				scope:interest_group = {
					is_in_government = yes
				}
			}
			multiply = {
				desc = "IN_GOVERNMENT_ATTRACTION"
				value = 1
				add = scope:interest_group.modifier:interest_group_in_government_attraction_mult
				min = 0
			}
		}
		if = {
			limit = {
				scope:interest_group = {
					is_in_government = yes
				}
			}
			multiply = { # Multiplied by 1.25x max
				desc = "POP_LOYALISTS"
				value = pop_loyalist_fraction
				divide = 4
				add = 1
			}
		}
		if = {
			limit = {
				scope:interest_group = {
					is_in_government = no
				}
			}
			multiply = { # Multiplied by 1.25x max
				desc = "POP_RADICALS"
				value = pop_radical_fraction
				divide = 4
				add = 1
			}
		}
	}

	monarch_weight = {
		value = 1
		# Monarch is not likely to adopt a marginal IG
		if = {
			limit = {
				is_marginal = yes
			}
			multiply = {
				value = 0.1
			}
		}
		# Monarch is more likely to adopt a Powerful IG
		if = {
			limit = {
				is_powerful = yes
			}
			multiply = {
				value = 2
			}
		}
		# Monarch more likely to be Armed Forces under an autocratic or oligarchic regime
		if = {
			limit = {
				owner = {
					OR = {
						has_law = law_type:law_oligarchy
						has_law = law_type:law_autocracy
						has_law = law_type:law_single_party_state
					}
				}
			}
			multiply = {
				value = 2
			}
		}
		# Monarch is less likely to be Armed forces in a democratic monarchy
		if = {
			limit = {
				owner = {
					OR = {
						has_law = law_type:law_universal_suffrage
						has_law = law_type:law_census_voting
					}
				}
			}
			multiply = {
				value = 0.5
			}
		}
		# Less likely without Professional Army or Mass Conscription
		if = {
			limit = {
				owner = {
					NOR = {
						has_law = law_type:law_professional_army
						has_law = law_type:law_mass_conscription
					}
				}
			}
			multiply = {
				value = 0.5
			}
		}
	}

	agitator_weight = {
		# Agitators more likely to come from populist IG's rather than elitist
		value = 0.5
		# Agitators will never be part of a marginalized IG
		if = {
			limit = {
				owner.ig:ig_armed_forces = {
					is_marginal = yes
				}
			}
			multiply = {
				value = 0
			}
		}
	}

	commander_weight = {
		value = 5.0
	}

	noble_chance = {
		value = 0.5
	}

	female_commander_chance = {
		value = 0.0
	}

	female_politician_chance = {
		value = 0.0
	}

	female_agitator_chance = {
		value = 0.01
		
		if = {
			limit = {
				owner = {
					has_law = law_type:law_women_own_property
				}

			}
			add = {
				value = 0.01
			}
		}	
		
		if = {
			limit = {
				owner = {
					has_law = law_type:law_women_in_the_workplace
				}

			}
			add = {
				value = 0.01
			}
		}

		if = {
			limit = {
				owner = {
					has_law = law_type:law_womens_suffrage
				}

			}
			add = {
				value = 0.01
			}
		}		
	}

	# The chance that a commander belonging to this IG takes over leadership when it changes
	# scope:character is the most popular commander in the IG
	commander_leader_chance = {
		value = 0.75
		if = {
			limit = {
				exists = scope:character
			}
			multiply = {
				value = 1
				add = scope:character.popularity
				min = 0
			}
		}
	}
}