﻿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
	}

	character_ideologies = {
		ideology_moderate
		ideology_authoritarian
	}

	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 = language_hispanophone
							has_discrimination_trait_group = heritage_group_european
							NOT = { has_discrimination_trait = heritage_iberian }
						}
					}
				}
				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 = {
						has_dlc_feature = ip2_content
						c:BIC ?= this
					}
				}
				set_ig_trait = ig_trait:ig_trait_divided_ranks
				set_ig_trait = ig_trait:ig_trait_imperial_service
				set_ig_trait = ig_trait:ig_trait_veerta
			}
			else_if = {
				limit = {
					owner = {
						c:PAN ?= this
					}
				}
				set_ig_trait = ig_trait:ig_trait_materiel_waste
				set_ig_trait = ig_trait:ig_trait_khalsa
				set_ig_trait = ig_trait:ig_trait_patriotic_fervor
			}
			else_if = {
				limit = {
					owner = {
						c:ZAN ?= this
						any_primary_culture = { cu:bedouin = this }
					}
				}
				set_ig_trait = ig_trait:ig_trait_divided_ranks
				set_ig_trait = ig_trait:ig_trait_veteran_consultation
				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 = {
				is_in_geographic_region = geographic_region_latin_america
				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
				}
			}
			add_modifier = age_of_caudillos_modifier
			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
			}
		}
		# India
		else_if = {
			limit = {
				c:BIC ?= this
			}
			ig:ig_armed_forces ?= {
				set_interest_group_name = ig_presidency_armies
			}
		}
		# Sikh Empire
		else_if = {
			limit = {
				c:PAN ?= this
			}
			ig:ig_armed_forces ?= {
				set_interest_group_name = ig_khalsaji
				remove_ideology = ideology_jingoist
				add_ideology = ideology_sikh_militancy
			}
		}
	}
	on_disable = {}

	priority_cultures = { #Country scope
		rule = {
			trigger = {
				c:BIC ?= this
				any_primary_culture = {
					cu:british = this
				}
			}
			cultures = {
				british scottish irish
			}
		}
		rule = {
			trigger = {
				c:ZAN ?= this
				any_primary_culture = {
					cu:bedouin = this
				}
			}
			cultures = {
				bedouin swahili baluchi
			}
		}
		rule = {
			trigger = {
				c:PHI ?= this
				NOT = { has_variable = je_philippines_main_reliance_happened }
				NOT = { any_primary_culture = { cu:filipino = this } }
				NOT = { any_primary_culture = { cu:filipino_hispanophone = this } }
				any_primary_culture = { cu:spanish = this }
			}
			cultures = {
				spanish filipino_mestizo
			}
		}
		rule = {
			trigger = {
				c:PHI ?= this
				any_primary_culture = {
					AND = {
						cu:spanish = this
						cu:filipino_hispanophone = this
					}
				}
			}
			cultures = {
				spanish filipino_hispanophone
			}
		}
	}

	on_character_ig_membership = {}

	pop_potential = {
		OR = {
			is_pop_type = soldiers
			is_pop_type = officers
			is_pop_type = aristocrats
			pop_acceptance >= acceptance_status_4
		}
	}

	pop_weight = {
		value = 0

		add = {
			desc = "POP_NOT_DISCRIMINATED"
			if = {
				limit = {
					NOT = {
						owner = {
							has_social_hierarchy = edo_system
						}
					}
					pop_acceptance >= acceptance_status_4
				}
				value = 25
				if = { # Militarisation of colonial settlers
					limit = {
						owner = {
							OR = {
								has_law_or_variant = law_type:law_colonial_resettlement
								has_law_or_variant = law_type:law_frontier_colonization
							}
						}
						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_or_variant = law_type:law_professional_army
						}
					}
					divide = 2
				}
			}
		}

		add = {
			desc = "nationalism"
			if = {
				limit = {
					pop_acceptance >= acceptance_status_4
					owner = {
						has_technology_researched = nationalism
						NOT = {
							has_technology_researched = pan-nationalism
						}
					}
				}
				value = 20
			}
		}

		add = {
			desc = "nationalism"
			if = {
				limit = {
					pop_acceptance >= acceptance_status_4
					owner = {
						has_technology_researched = pan-nationalism
					}
				}
				value = 30
			}
		}

		add = {
			desc = "POP_SOLDIERS"
			if = {
				limit = {
					is_pop_type = soldiers
				}
				value = 100
				if = { # Institutional loyalty
					limit = {
						owner = {
							has_law_or_variant = law_type:law_professional_army
						}
					}
					add = 50
				}
				else_if = {
					limit = {
						owner = {
							has_law = law_type:law_warrior_caste
						}
					}
					add = 100
				}
				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 = 5
				if = {
					limit = {
						owner = {
							has_modifier = age_of_caudillos_modifier
						}
					}
					add = 25
				}
				if = {
					limit = {
						owner = {
							has_law = law_type:law_peasant_levies
						}
					}
					add = 50
				}
			}
		}

		add = {
			desc = "SAMURAI_TRADITIONS" # Warrior caste
			if = {
				limit = {
					is_pop_type = aristocrats
					culture = cu:japanese
				}
				add = 100
			}
		}

		add = {
			desc = "SIKH_MILITANCY"
			if = {
				limit = {
					is_pop_type = aristocrats
					religion = rel:sikh
				}
				add = 100
			}
		}

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

		add = { # There's one firearm for every twelve people on the planet. The question is, how do we arm the other eleven?
			desc = "MILITARY_INDUSTRIES"
			if = {
				limit = {
					pop_employment_building_group = bg_military_industry
				}
				if = {
					limit = {
						strata = poor
					}
					value = 50
				}
				if = {
					limit = {
						strata = middle
					}
					value = 100
				}
				if = {
					limit = {
						strata = upper
					}
					value = 200
				}
			}
		}

		add = {
			desc = "POP_MILITARY_BUREAUCRACY"
			if = {
				limit = {
					is_pop_type = bureaucrats
					owner = {
						c:ALK ?= this
						has_government_type = gov_chartered_company
					}
				}
				value = 100
			}
		}
		
		add = {
			desc = "IG_HAS_RIVAL"
			if = {
				limit = {
					owner = {
						any_rival_country = {
							count = 0
						}
					}
				}
				value = 0
			}
			else_if = {
				limit = {
					owner = {
						any_rival_country = {
							count = 1
						}
					}
				}
				value = 5
			}
			else_if ={
				limit = {
					owner = {
						any_rival_country = {
							count = 2
						}
					}
				}
				value = 10
			}
			else_if ={
				limit = {
					owner = {
						any_rival_country = {
							count = 3
						}
					}
				}
				value = 15
			}
			else_if ={
				limit = {
					owner = {
						any_rival_country = {
							count >= 4
						}
					}
				}
				value = 20
			}
		}

		multiply = {
            desc = "concept_war"    
            value = 1.0

            if = {
                limit = {
                    pop_acceptance >= acceptance_status_4
                    owner = {
                        is_at_war = yes
                    }
                }
                value = 1.5
            }        
        }

		add = { #Policemens
			desc = "POP_CLERKS"
			if = {
				limit = { 
					is_pop_type = clerks
				}
				value = 25
			}
		}

		add = { #Policemens
			desc = "POP_BUREAUCRATS"
			if = {
				limit = { 
					is_pop_type = bureaucrats
				}
				value = 10
			}
		}

		add = {
			desc = "ideology_junker_paternalistic"
			if = {
				limit = { 
					is_pop_type = aristocrats
					has_state_religion = yes
					culture = cu:north_german
					owner = {
						ig:ig_landowners = {
							has_ideology = ideology:ideology_junker_paternalistic
						}
					}
				}
				value = 75
			}
		}

		multiply = {
			desc = "ideology_bonapartist"
			value = 1.0

			if = {
				limit = {
					owner = {
						ig:ig_armed_forces = {
							leader = {
								has_ideology = ideology:ideology_bonapartist
							}
						}
					}
				}
				value = 1.25
			}
		}

		add = {
			desc = "ideology_caudillismo"
			if = {
				limit = { 
					OR = {
						is_pop_type = officers
						is_pop_type = soldiers
						is_pop_type = aristocrats
					}
					owner = {
						ig:ig_armed_forces = {
							has_ideology = ideology:ideology_caudillismo
						}
					}
				}
				value = 250
			}
		}

		multiply = { # Boost to Facism to make it relevant
			desc = "ideology_fascist"
			value = 1.0
			if = {
				limit = {
					owner = {					
						ig:ig_armed_forces = {
							leader = {
								has_ideology = ideology:ideology_fascist
							}
						}					
					}
				}
				value = 1.5
			}
		}

		multiply = { # extra boost to fascism for wealthy classes if powerful
			desc = "ideology_fascist"
			value = 1.0
			if = {
				limit = {
					owner = {					
						ig:ig_armed_forces = {
							leader = {
								has_ideology = ideology:ideology_fascist
							}
							is_powerful = yes
						}					
					}
					OR = {
						is_pop_type = capitalists
						is_pop_type = aristocrats
					}
				}
				value = 2.0
			}
		}

		multiply = {
			desc = "law_national_guard"
			value = 1.0
			if = {
				limit = {
					owner = {
						has_law = law_type:law_national_guard
					}
				}
				value = 1.1
			}
		}

		multiply = {
			desc = "LEFTISTARMY"
			value = 1.0

			if = {
				limit = {
					owner = {
						any_interest_group = { 
							is_interest_group_type = ig_armed_forces 
							leader = {
								OR = {
									has_ideology = ideology:ideology_communist
									has_ideology = ideology:ideology_vanguardist
									has_ideology = ideology:ideology_anarchist
									has_ideology = ideology:ideology_republican_leader
								}
							}
						}
					}
					is_pop_type = aristocrats
				}
				value = 0.1
			}
		}	

		multiply = {
			desc = "WOMENVOTE"
			value = 1.0

			if = {
				limit = {
					owner = {
						has_law = law_type:law_womens_suffrage
					}
				}
				value = 0.75
			}
		}
					
		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
			}
		}

		multiply = {
			desc = "IG_IS_MARGINALIZED"
			value = 1.0
			
			scope:interest_group ?= {
				if = {
					limit = {
						is_marginal = yes
					}
					value = 0.75
				}
			}
		}
	}

	monarch_weight = {
		value = 1
		# Monarch is not likely to adopt a marginal IG
		if = {
			limit = {
				ig_counts_as_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_or_variant = law_type:law_oligarchy
						has_law_or_variant = law_type:law_autocracy
						has_law_or_variant = 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_or_variant = law_type:law_universal_suffrage
						has_law_or_variant = law_type:law_census_voting
					}
				}
			}
			multiply = {
				value = 0.5
			}
		}
		# Less likely without Professional Army or Mass Conscription
		if = {
			limit = {
				owner = {
					NOR = {
						has_law_or_variant = law_type:law_professional_army
						has_law_or_variant = 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 ?= {
					ig_counts_as_marginal = yes
				}
			}
			multiply = {
				value = 0
			}
		}
	}

	commander_weight = {
		value = 5.0
	}
	
	magnate_weight = {
		value = 1.0
	}	

	executive_weight = {
		value = 0.2

		# The company owning BIC should not get non-industrialist executives
		if = {
			limit = {
				exists = scope:company
				exists = c:BIC
				c:BIC ?= {
					exists = owning_company
					owning_company = scope:company
				}
			}
			multiply = {
				value = 0
			}
		}
	}

	noble_chance = {
		value = 0.5
	}

	female_commander_chance = {
		value = 0.0
	}

	female_executive_chance = {
		value = 0.0
	}

	female_monarch_chance = {
		value = 0
	}

	female_politician_chance = {
		value = 0.0

		if = {
			limit = {
				owner = {
					has_law_or_variant = law_type:law_womens_suffrage
				}
				law_stance = {
					law = law_type:law_womens_suffrage
					value >= approve
				}
			}
			add = {
				value = 0.025
			}
		}
	}

	female_agitator_chance = {
		value = 0.01

		if = {
			limit = {
				owner = {
					has_law_or_variant = law_type:law_women_own_property
				}

			}
			add = {
				value = 0.01
			}
		}

		if = {
			limit = {
				owner = {
					has_law_or_variant = law_type:law_women_in_the_workplace
				}

			}
			add = {
				value = 0.01
			}
		}

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

			}
			add = {
				value = 0.01
			}
		}
	}

	# Multiplier applied to the weight for an appropriate commander will be selected from the character pool to lead the IG
	# root = interest group
	commander_leader_weight = {
		value = 3.0
	}
	
	# Multiplier applied to the weight for an appropriate magnate will be selected from the character pool to lead the IG
	# root = interest group
	magnate_leader_weight = {
		value = 1.0
		if = {
			limit = {
				c:JAP ?= owner
				NOT = {
					has_variable = japan_restoration_complete
				}
			}
			add = 5
		}
	}

	# Multiplier applied to the weight for an appropriate executive will be selected from the character pool to lead the IG
	# root = interest group
	executive_leader_weight = {
		value = 0.1
	}
}
