﻿ig_petty_bourgeoisie = {
	color = hsv{ 0.65 0.54 0.52 }
	texture = "gfx/interface/icons/ig_icons/petty_bourgeoisie.dds"
	layer = "revolution_dynamic_petty_bourgeoisie"
	index = 5

	ideologies = {
		ideology_reactionary
		ideology_meritocratic
		ideology_patriotic
	}

	character_ideologies = {
		ideology_moderate
		ideology_traditionalist
		ideology_jingoist_leader
		ideology_protectionist
		ideology_sovereignist_leader
		ideology_despotic_utopian
	}

	enable = {
		always = yes
	}

	# Deprecated; use on_enable effect to assign traits instead
	traits = {
		ig_trait_treasury_bonds
		ig_trait_middle_managers
		ig_trait_xenophobia
	}

	on_enable = {
		ig:ig_petty_bourgeoisie ?= {
			if = {
				limit = {
					owner = { c:SWE ?= this}
				}
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_bergsbrukens_valdistrikten
				set_ig_trait = ig_trait:ig_trait_treasury_bonds
			}
			else_if = {
				limit = {
					owner = { c:TUR ?= this }
				}
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_effendi
				set_ig_trait = ig_trait:ig_trait_reorganization
			}
			else_if = {
				limit = {
					owner = { c:EGY ?= this }
				}
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_effendi
				set_ig_trait = ig_trait:ig_trait_treasury_bonds
			}
			else_if = {
				limit = {
					has_dlc_feature = voice_of_the_people_content
					owner = { c:FRA ?= this }
				}
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_haute_finance
				set_ig_trait = ig_trait:ig_trait_master_of_the_house
			}
			else_if = {
				limit = {
					owner = { c:GBR ?= this }
				}
				set_ig_trait = ig_trait:ig_trait_bah_humbug
				set_ig_trait = ig_trait:ig_trait_civil_service
				set_ig_trait = ig_trait:ig_trait_old_lady_of_threadneedle_street
			}
			else_if = {
				limit = {
					c:POR ?= owner
				}
				remove_ideology = ideology_meritocratic
				add_ideology = ideology_cartist

				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_middle_managers
				set_ig_trait = ig_trait:ig_trait_treasury_bonds
			}
			else_if = {
				limit = {
					owner = {
						country_has_primary_culture = cu:japanese
					}
				}
				set_interest_group_name = ig_chonin
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_middle_managers
				set_ig_trait = ig_trait:ig_trait_treasury_bonds
			}
			else_if = {
				limit = {
					owner = {
						c:BIC ?= this
					}
				}
				set_interest_group_name = ig_bhadralok

				# Ideologies
				remove_ideology = ideology_patriotic
				add_ideology = ideology_sovereignist
				remove_ideology = ideology_reactionary
				add_ideology = ideology_modernizer

				# Traits
				set_ig_trait = ig_trait:ig_trait_swadesh
				set_ig_trait = ig_trait:ig_trait_lines_of_credit
				set_ig_trait = ig_trait:ig_trait_cooperative_agencies
			}
			# Kleinbürger
			else_if = {
				limit = {
					has_dlc_feature = ip3_content
					owner = {
						any_primary_culture = {
							has_discrimination_trait = language_germanophone
						}
					}
				}
				set_interest_group_name = ig_kleinburger
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_middle_managers
				set_ig_trait = ig_trait:ig_trait_biedermanner
			}
			else = {
				set_ig_trait = ig_trait:ig_trait_xenophobia
				set_ig_trait = ig_trait:ig_trait_middle_managers
				set_ig_trait = ig_trait:ig_trait_treasury_bonds
			}

			if = { # For newly-released countries. For game-start, initialisation is handled in global history
				limit = {
					owner = {
						OR = {
							has_law_or_variant = law_type:law_traditionalism
							has_law_or_variant = law_type:law_isolationism
						}
					}
				}
				add_ideology = ideology_mercantile
			}
		}
	}

	on_disable = {}
	priority_cultures = { #Country scope
		rule = {
			trigger = {
				c:BIC ?= this
				any_primary_culture = {
					cu:british = this
				}
			}
			cultures = {
				assamese avadhi baluchi bengali bihari gujarati kannada malayalam marathi oriya panjabi pathan rajput sindi tamil telegu hindustani bundeli pahari gondi bageli chhattisgarhi deccani
			}
		}
		rule = {
			trigger = {
				c:ZAN ?= this
				any_primary_culture = {
					cu:bedouin = this
				}
			}
			cultures = {
				swahili gujarati
			}
		}
		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 = {
		if = {
			limit = {
				culture = cu:gujarati
				owner = {
					c:ZAN ?= this
					any_primary_culture = {
						cu:bedouin = this
					}
				}
			}
			change_character_religion = rel:shiite
		}
	}

	pop_potential = {
		custom_tooltip = {
			text = would_be_accepted_under_national_supremacy_tt
			this.culture = {
				OR = {
					AND = {
						shares_heritage_trait_group_with_any_primary_culture = prev.owner
						shares_language_trait_group_with_any_primary_culture = prev.owner
					}
					AND = {
						c:BIC ?= prev.owner
						has_discrimination_trait_group = heritage_group_south_asian
					}
					AND = {
						c:ZAN ?= prev.owner
						c:ZAN ?= {
							any_primary_culture = { cu:bedouin = this }
						}
						OR = {
							cu:swahili = this
							cu:gujarati = this
						}
					}
				}
			}
		}
		NOT = {
			is_pop_type = aristocrats
		}
		OR = {
			NOT = {
				is_pop_type = capitalists
			}
			custom_tooltip = {
				text = capitalist_in_british_india_tt
				AND = {
					is_pop_type = capitalists
					c:BIC ?= owner
				}
			}
		}
		OR = {
			pop_employment_building_group = bg_manufacturing
			pop_employment_building_group = bg_service
			pop_employment_building_group = bg_urban_facilities
			pop_employment_building_group = bg_private_infrastructure
			pop_employment_building_group = bg_financial_districts
			pop_employment_building_group = bg_government
			pop_employment_building_group = bg_military
			pop_employment_building_group = bg_logging
			pop_employment_building_group = bg_mining
			pop_employment_building_group = bg_fishing
			pop_employment_building_group = bg_whaling
			pop_employment_building_group = bg_oil_extraction
			is_pop_type = peasants
			AND = {
				custom_tooltip = {
					text = owner_has_homesteading_tt
					owner = {
						OR = {
							has_law_or_variant = law_type:law_peasant_proprietorship
							has_law_or_variant = law_type:law_commercialized_agriculture
						}
					}
				}
				OR = {
					pop_employment_building_group = bg_agriculture
					pop_employment_building_group = bg_ranching
					pop_employment_building_group = bg_plantations
				}
				strata = middle
			}
		}
	}

	pop_weight = {
		if = {
			limit = {
				strata = lower
				standard_of_living > 10
			}
			add = {
				desc = "POP_BASE_ATTRACTION"
				value = standard_of_living
				multiply = 2
			}
		}
		else_if = {
			limit = {
				pop_typically_counts_as_middle_strata = yes
			}
			add = {
				desc = "POP_BASE_ATTRACTION"
				value = standard_of_living
				multiply = 3
			}
		}

		add = {
			desc = "POP_SHOPKEEPERS"
			if = {
				limit = {
					is_pop_type = shopkeepers
				}
				value = 250
			}
		}

		add = {
			desc = "POP_CLERKS"
			if = {
				limit = {
					is_pop_type = clerks
				}
				value = 75
				add = standard_of_living
			}
		}

		add = {
			desc = "POP_BUREAUCRATS"
			if = {
				limit = { 
					is_pop_type = bureaucrats
				}
				value = 75
				add = standard_of_living
			}
		}

		add = {
			desc = "POP_SOLDIERS"
			if = {
				limit = { 
					is_pop_type = soldiers
				}
				value = 50
			}
		}

		add = {
			desc = "POP_ENGINEERS"
			if = {
				limit = {
					is_pop_type = engineers
				}
				value = 75
			}
		}
		
		add = {
			desc = "POP_MACHINISTS"
			if = {
				limit = { 
					is_pop_type = machinists
				}
				value = 25
			}
		}

		add = {
			desc = "POP_FARMERS"
			if = {
				limit = { 
					is_pop_type = farmers
				}
				value = 25
			}
		}

		add = { #Some upper class support PB
			desc = "POP_CAPITALISTS"
			if = {
				limit = { 
					is_pop_type = capitalists
				}
				value = 25
			}
		}

		#add = { #Some upper class support PB #PB is powerful after 1.7, no need for this anymore, also doesn't make a ton of sense
		#	desc = "POP_ARISTOCRATS"
		#	if = {
		#		limit = { 
		#			is_pop_type = aristocrats
		#		}
		#		value = 10
		#	}
		#}

		add = {
			desc = "POP_PEASANTS" #represent artisans etc
			if = {
				limit = {
					is_pop_type = peasants
				}
				value = 25
			}
		}

		multiply = {
			desc = "RURAL_POP"
			value = 1.0
			if = {
				limit = { 
					rural_employment = yes
					owner = {
						ig:ig_petty_bourgeoisie = {
							leader = {
								NOT = { has_ideology = ideology:ideology_bonapartist }
							}
						}
					}
				}
				value = 0.75
			}
		}
		
		multiply = { # Boost to Facism to make it relevant
			desc = "ideology_fascist"
			value = 1.0
			if = {
				limit = {
					owner = {					
						ig:ig_petty_bourgeoisie = {
							leader = {
								has_ideology = ideology:ideology_fascist
							}
						}					
					}
				}
				value = 1.25
			}
		}

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

		multiply = {
			desc = "TRADE_CENTER"
			value = 1.0
			if = {
				limit = {
					OR = {
						is_pop_type = clerks
						is_pop_type = bureaucrats
					}
					pop_employment_building = building_trade_center
				}
				value = 1.5
			}
		}

		multiply = {
			desc = "URBAN_CENTER"
			value = 1.0
			if = {
				limit = {
					OR = {
						is_pop_type = clerks
						is_pop_type = bureaucrats
					}
					pop_employment_building = building_urban_center
				}
				value = 1.25
			}
		}

		multiply = {
			desc = "NOT_GOV"
			value = 1.0
			if = {
				limit = {
					OR = {
						is_pop_type = clerks
						is_pop_type = bureaucrats
					}
					NOR = { 
						pop_employment_building_group = bg_government
						pop_employment_building = building_trade_center
						pop_employment_building = building_urban_center
					}
				}
				value = 1.25
			}
		}
		
		multiply = { 
			desc = "COUNTERREVOLUTION"
			value = 1.0
			if = {
				limit = {
					owner = {
						ig:ig_petty_bourgeoisie = {
							has_ideology = ideology:ideology_reactionary
						}
						ig:ig_trade_unions = {
							is_powerful = yes
						}
					}
				}
				value = 1.5
			}
		}
		
		add = {
			desc = "INFAMY" 
			if = {
				limit = {
					owner = { 
						NOT = { has_law = law_type:law_council_republic }
						infamy >= 25
						infamy < 50
					}
				}
				value = 10
			}
		}

		add = {
			desc = "INFAMY" 
			if = {
				limit = {
					owner = { 
						NOT = { has_law = law_type:law_council_republic }
						infamy >= 50
						infamy < 100
					}
				}
				value = 25
			}
		}

		add = {
			desc = "INFAMY"
			if = {
				limit = {
					owner = { 
						NOT = { has_law = law_type:law_council_republic }
						infamy >= 100
					}
				}
				value = 50
			}
		}

		multiply = {
			desc = "law_cultural_exclusion" #they took our jobs!
			value = 1.0
			if = {
				limit = {
					owner = {
						has_law = law_type:law_cultural_exclusion
					}
					literacy_rate < 0.80
				}
				value = 1.1
			}
			else_if = {
				limit = {
					owner = {
						has_law = law_type:law_cultural_exclusion
					}
				}
				value = 1.05
			}
		}	

		multiply = {
			desc = "law_multicultural" #they took our jobs!
			value = 1.0
			if = {
				limit = {
					owner = {
						has_law = law_type:law_multicultural
					}
					literacy_rate < 0.90
				}
				value = 1.25
			}
			else_if = {
				limit = {
					owner = {
						has_law = law_type:law_multicultural
					}
				}
				value = 1.1
			}
		}

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

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

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

		add = {
			desc = "law_graduated_taxation" 
			if = {
				limit = {
					owner = {
						has_law = law_type:law_graduated_taxation
					}
					OR = {
						strata = middle
						is_pop_type = clerks
						is_pop_type = machinists
					}
				}
				value = 10
			}
		}

		multiply = {
			desc = "IG_COUNCIL_REPUBLIC"
			value = 1.0

			if = {
				limit = {
					owner = {
						has_law = law_type:law_council_republic
					}
				}
				value = 0.1
			}
		}

		multiply = {
			desc = "AFROAMERICAN"
			value = 1.0

			if = {
				limit = {
					owner = {
						c:USA = THIS
					}
					culture = cu:afro_american
				}
				value = 0.1
			}
		}

		multiply = {
			desc = "ideology_caudillismo"
			value = 1.0

			if = {
				limit = {
					owner = {
						ig:ig_armed_forces = {
							has_ideology = ideology:ideology_caudillismo
						}
					}
				}
				value = 0.75
			}
		}

		add = { #rural pops love bonnapartists
			desc = "ideology_bonapartist"
			if = {
				limit = { 
					rural_employment = yes
					owner = {
						ig:ig_petty_bourgeoisie = {
							leader = {
								has_ideology = ideology:ideology_bonapartist
							}
						}
					}
				}
				value = 25
			}
		}

		add = {
			desc = "ideology_bonapartist"
			if = { #military loves Napoleon
				limit = {
					owner = {
						ig:ig_petty_bourgeoisie = {
							leader = {
								has_ideology = ideology:ideology_bonapartist
							}
						}
					}
					OR = {
						is_pop_type = officers
						is_pop_type = soldiers
					}
				}
				value = 100
			}
		}

		add = {
			desc = "ideology_bonapartist"
			if = { #high and middle urban strata support Napoleon
				limit = {
					rural_employment = no
					owner = {
						ig:ig_petty_bourgeoisie = {
							leader = {
								has_ideology = ideology:ideology_bonapartist
							}
						}
					}
					OR = {
						strata = rich
						strata = middle
					}
				}
				value = 50
			}
		}

		multiply = {
			desc = "ideology_bonapartist"
			value = 1.0

			if = {
				limit = {
					owner = {
						NOT = { has_law = law_type:law_monarchy }
						ig:ig_petty_bourgeoisie = {
							leader = {
								has_ideology = ideology:ideology_bonapartist
							}
						}
					}
				}
				value = 1.25
			}
		}

		multiply = {
			desc = "IG_IS_MARGINALIZED"
			value = 1.0
			
			scope:interest_group = {
				if = {
					limit = {
						ig_counts_as_marginal = yes
					}
					value = 0.75
				}
			}
		}
		
		if = {
			limit = {
				owner = {
					has_law_or_variant = law_type:law_elected_bureaucrats
				}
			}
			add = {
				desc = "POP_BUREAUCRATS_ELECTED"
				if = {
					limit = {
						is_pop_type = bureaucrats
					}
					value = 50
				}
			}
		}

		add = {
			desc = "HOMESTEADING_LAW"
			if = {
				limit = {
					is_pop_type = farmers
					owner = {
						has_law_or_variant = law_type:law_peasant_proprietorship
					}
				}
				value = 25

				if = {
					limit = {
						state = {
							is_slave_state = yes
						}
					}
					subtract = 25
				}
			}
		}

		if = {
			limit = {
				standard_of_living >= 10
				NOR = {
					pop_employment_building_group = bg_agriculture
					pop_employment_building_group = bg_ranching
					pop_employment_building_group = bg_plantations
				}
			}
			add = {
				desc = "URBAN_POP"
				value = standard_of_living
				multiply = 2
			}
		}

		if = {
			limit = {
				c:BIC ?= owner
				culture = {
					has_discrimination_trait_group = heritage_group_european
				}
			}
			multiply = {
				desc = "POP_INDIA_COLONIAL_RULE"
				value = 0.1
			}
		}

		if = {
			limit = {
				c:BIC ?= owner
				culture = {
					has_discrimination_trait_group = heritage_group_south_asian
				}
				OR = {
					is_pop_type = capitalists
					is_pop_type = shopkeepers
				}
			}
			add = {
				desc = "POP_INDIA_MONEYED_ELITES"
				value = 75
			}
		}

		add= {
			desc = "ig_trade_unions"
			if = {
				limit = {
					strata = poor
					owner = {
						ig:ig_trade_unions = {
							is_powerful = yes
						}
						ig:ig_petty_bourgeoisie = {
							has_ideology = ideology:ideology_patriotic
						}
					}
				}
				value = wealth
				subtract = 15
				multiply = 5
				min = 0
				max = 50
			}
		}

		add= {
			desc = "ig_trade_unions"
			if = {
				limit = {
					strata = middle
					owner = {
						ig:ig_trade_unions = {
							is_powerful = yes
						}
						ig:ig_petty_bourgeoisie = {
							has_ideology = ideology:ideology_patriotic
						}
					}
				}
				value = wealth
				subtract = 20
				multiply = 5
				min = 0
				max = 50
			}
		}

		multiply = {
			desc = "LEADER_POPULARITY"
			scope:interest_group ?= {
				leader ?= {
					value = popularity
					multiply = 0.0025
					add = 1
					max = 1.25
					min = 0.75
				}
			}
		}

		multiply = {
			desc = "decentralized_power"
			value = 1.0

			if = {
				limit = {
					owner = {
						is_country_type = decentralized
					}
				}
				value = 0.0
			}
		}
		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 = {
				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
			}
		}
		# More likely with Elected Bureaucrats
		if = {
			limit = {
				owner = {
					has_law_or_variant = law_type:law_elected_bureaucrats
				}
			}
			multiply = {
				value = 1.5
			}
		}
		# More likely with ethnostate
		if = {
			limit = {
				owner = {
					has_law_or_variant = law_type:law_ethnostate
				}
			}
			multiply = {
				value = 2
			}
		}
	}

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

	commander_weight = {
		value = 1.0
	}
	
	magnate_weight = {
		value = 0.25
	}	

	executive_weight = {
		value = 1.5
		
		# 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.1
	}

	female_commander_chance = {
		value = 0.0
	}

	female_executive_chance = {
		value = 0.0
	}

	female_monarch_chance = {
		value = 0.10
	}

	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.025

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

			}
			add = {
				value = 0.025
			}
		}

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

			}
			add = {
				value = 0.025
			}
		}

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

			}
			add = {
				value = 0.025
			}
		}
	}

	# 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 = 1.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 = 1.0
	}
}
