################################
### UKRAINE SCRIPTED EFFECTS ###
################################

# Here you'll find all of Ukraine's scripted effects. They are separated into multiple categories. Please keep them in their categories. Please. And when you add new categories, make sure they're cohesive and not all over the place. If you do fuck things up I'll kill you.
# Also please comment your code so it's readable and understandable by others :)
# Also make sure you type the number in full so you dont get sent to a random breadbasket effect!!!
# -Corn

#########
# INDEX #
#########
# 0 - Intro Scripted Effects
# 1.0.0 - Ukrainian Civil War Scripted Effects
 # 1.1 - Bitter Harvest Scripted Effects
 # 1.2 - Red Army Scripted Effects
 # 1.3 - The War Within Scripted Effects
 # 1.4 - Panacea Scripted Effects
 # 1.5 - All Alone Scripted Effects
 # 1.6 - Dispirited, Deranged Domevoy Scripted Effects
 # 1.7 - Ukrainian Civil War Breadbasket Variable Transfer Scripted Effects
# 2.0.0 - An Empty Throne Scripted Effects
# 3.0.0 - Breadbasket Scripted Effects
 # 3.1 - Breadbasket Setup Scripted Effects
 # 3.2 - Breadbasket Backend Scripted Effects
 # 3.3 - Breadbasket Consumption Scripted Effects
 # 3.4 - Breadbasket Dynamic Modifier Scripted Effects
 # 3.5 - Breadbasket Actions Scripted Effects
 # 3.6 - Breadbasket Randomizer Scripted Effects, idk i ain't actually reorganizing the order of these scripted effects lmao
 # 3.7 - Breadbasket Development Scripted Effects
 # 3.8 - Breadbasket Resistance Scripted Effects
 # 3.9 - Breadbasket Alerts
# 4.0 - UNRA (FUK) Mechanics
 # 4.1 - Election Mech
 # 4.2 - Culturalist Mechanic Scripted Effects
# 5.0.0 - UPA (BOV) Mechanics
 # 5.1 - Three Heads of the Dragon Scripted Effects
 # 5.2 - Galicia War
# 6.0 - Republic of Ukraine UCW Mechanic Scripted Effects
# 7.0 - Ukrainian SSR Revolutionary Will Mechanic Scripted Effects
# 8.0 - Assorted Laws Scripted Effects

##############################
# 0 - INTRO SCRIPTED EFFECTS #
##############################

UKR_fire_intro_events = { # Used for firing intro events
	country_event = { # Leib
		id = UKR_intro_chain.3
		days = 30
	}
	country_event = { # Brautigam
		id = UKR_intro_chain.2
		days = 50
	}
	country_event = { # Ohlendorf
		id = UKR_intro_chain.5
		days = 70
	}
	country_event = { # UNRA/Republic
		id = UKR_intro_chain.6
		days = 90
	}
	country_event = { # UA-SSR
		id = UKR_intro_chain.9
		days = 110
	}
	country_event = { # UPA/OUN-B
		id = UKR_intro_chain.12
		days = 130
	}
	country_event = { # Kyi Chain
		id = UKR_intro_chain.19
		days = 200
	}
	country_event = { # Van Norden Chain
		id = UKR_VanNordenIntro.1
		days = 10
	}
	country_event = { # Nosenko Chain
		id = UKR_NosenkoIntro.1
		days = 25
	}
	country_event = { # Bohdan Chain
		id = UKR_BohdanIntro.1
		days = 40
	}
}

UKR_Destiny_start = {
	custom_effect_tooltip = UKR_SE_destiny_start_tt
	set_variable = { destiny_controller_UKR = 0 }
	activate_mission = UKR_MIS_destiny_timer
}

############################################
# 1.0.0 - UKRAINIAN CIVIL WAR SCRIPTED EFFECTS #
############################################

UKR_UCW_check_victor = {
	if = {
		limit = {
			NOT = { FROM = { has_war_with = GER } }
			check_variable = { global.UKR_contenders^num = 1 }
		}
		#Cleanup space; clear some flags, unset some variables- whatever.
		clear_array = global.UKR_contenders
		clr_global_flag = UKR_UCW_ongoing
		clr_global_flag = UKR_ucw_supply_active
		clr_global_flag = UKR_UCW_ai_stuff

		#just to make sure that the supply ideas are removed for good
		remove_ideas = {
			UKR_supply_inefficient
			UKR_supply_conserve
			UKR_supply_feed_soldiers
			UKR_supply_feed_people
			UKR_a_bitter_harvest_negligible
			UKR_a_bitter_harvest_mild
			UKR_a_bitter_harvest_moderate
			UKR_a_bitter_harvest_severe
			UKR_a_bitter_harvest_famine
		}

		FROM = {
			set_capital = { state = 1428 }
			remove_ideas = {
				UKR_the_ukrainian_civil_war
				UKR_the_ukrainian_civil_war_2
			}
			TNS = {
				country_event = {
					id = TNS_skeleton.4
					days = 120
				}
			}
			every_owned_state = {
				force_disable_resistance = {
					clear = yes
					occupier = UKR
					occupied = FUK
				}
				force_disable_resistance = {
					clear = yes
					occupier = UKR
					occupied = UKS
				}
				force_disable_resistance = {
					clear = yes
					occupier = UKR
					occupied = BOV
				}
				force_disable_resistance = {
					clear = yes
					occupier = UKR
					occupied = UKR
				}
				add_core_of = FROM #Failsafe
			}
			#RKU
			if = {
				limit = { original_tag = UKR }
				news_event = { id = UKR_UCW_NEWS.0 days = 1 }
				country_event = {
					id = UKR_post_UCW_characters.1
					days = 3
				}
				set_country_flag = UKR_wars_over
				if = {
					limit = { has_idea = UKR_UCW_panacea }
					country_event = {
						id = UKR_pwr_struggle.40
						days = 7
					}
				}
				load_focus_tree = TNO_UKR_Post_War_Power_Struggle
				set_global_flag = UKR_UCW_RK_Victory
				#set_country_flag = UKR_bb_enabled
				if = {
					limit = { has_idea = UKR_UCW_intel_based_partisan_warfare }
					remove_ideas = UKR_UCW_intel_based_partisan_warfare
				}
				remove_ideas = {
					UKR_UCW_war_within
					UKR_UCW_all_alone
				}
				remove_dynamic_modifier = { modifier = UKR_UCW_war_within_mod }
				remove_dynamic_modifier = { modifier = UKR_UCW_all_alone_mod }
				every_owned_state = {
					cancel_resistance = yes
				}
				set_temp_variable = { gdp_growth_temp = 0.8 }
				econ_gdp_growth_change = yes
				set_temp_variable = { inflation_temp = -0.5 }
				econ_inflation_change = yes
			}
			#RoU
			else_if = {
				limit = { original_tag = FUK }
				news_event = { id = UKR_UCW_NEWS.1 days = 1 }
				country_event = {
					id = UKR_post_UCW_characters.4
					days = 3
				}
				FUK_Yuriy_Horlis = {
					set_portraits = {
						civilian = {
							large = "gfx/leaders/FUK/Portrait_FUK_Yuriy_Horlis.png"
						}
					}
				}

				UKR = { #so they don't still have this when Germany kills you
					remove_ideas = { 
						UKR_indecisive_council
						UKR_to_the_strongest_idea
						UKR_in_this_together
					}
				}

				every_owned_state = {
					remove_core_of = UKS
					remove_core_of = BOV
				}

				load_focus_tree = TNO_UKR_FUK_Post_War
				set_global_flag = UKR_UCW_PG_Victory
				activate_mission = UKR_Countdown_To_Invasion
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_idea_scraps_of_the_pipeline
					}
					remove_ideas = FUK_idea_scraps_of_the_pipeline
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_ukrainian_war_machine
					}
					remove_ideas = FUK_ukrainian_war_machine
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_collaborator_industrial_connections
					}
					remove_ideas = FUK_collaborator_industrial_connections
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_everything_for_victory
					}
					remove_ideas = FUK_everything_for_victory
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_legacy_of_the_one_hundred
					}
					remove_ideas = FUK_legacy_of_the_one_hundred
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_reinvigorated_UNRA
					}
					remove_ideas = FUK_reinvigorated_UNRA
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_formalized_officer_corps
					}
					remove_ideas = FUK_formalized_officer_corps
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_dropping_the_hammer
					}
					remove_ideas = FUK_dropping_the_hammer
				}
				if = { #remove the wartime national spirits
					limit = {
						has_idea = FUK_freedom_to_ukraine_or_death_idea
					}
					remove_ideas = FUK_freedom_to_ukraine_or_death_idea
				}
				add_stability = 0.4 # big stability buff
				add_war_support = 0.6 # big stability buff
				set_temp_variable = { gdp_growth_temp = 1.2 }
				econ_gdp_growth_change = yes
				set_temp_variable = { inflation_temp = -0.8 }
				econ_inflation_change = yes
			}
			#UA-SSR
			else_if = {
				limit = { original_tag = UKS }
				news_event = { id = UKR_UCW_NEWS.2 days = 1 }
				country_event = {
					id = UKR_post_UCW_characters.7
					days = 3
				}

				UKR = { #so they don't still have this when Germany kills you
					remove_ideas = { 
						UKR_indecisive_council
						UKR_to_the_strongest_idea
						UKR_in_this_together
					}
				}

				set_country_flag = UKS_wars_over

				every_owned_state = {
					remove_core_of = FUK
					remove_core_of = BOV
				}

				set_global_flag = UKR_UCW_COM_Victory
				load_focus_tree = TNO_UKS_POST_UCW

				#UKR_bb_startup_UKS_communists = yes
				activate_mission = UKR_Countdown_To_Invasion
				add_stability = 0.4 # big stability buff
				add_war_support = 0.6 # big stability buff
				set_temp_variable = { gdp_growth_temp = 1.2 }
				econ_gdp_growth_change = yes
				set_temp_variable = { inflation_temp = -0.8 }
				econ_inflation_change = yes
			}
			#UPA
			else_if = {
				limit = { original_tag = BOV }
				news_event = { id = UKR_UCW_NEWS.3 days = 1 }
				country_event = {
					id = UKR_post_UCW_characters.10
					days = 3
				}
				BOV_Dmytro_Klyachkivsky = {
					set_portraits = {
						civilian = { large = "gfx/leaders/BOV/Portrait_BOV_Dmytro_Klyachkivsky.png" }
					}
					promote_leader = yes
				}

				UKR = { #so they don't still have this when Germany kills you
					remove_ideas = { 
						UKR_indecisive_council
						UKR_to_the_strongest_idea
						UKR_in_this_together
					}
				}

				every_owned_state = {
					remove_core_of = FUK
					remove_core_of = UKS
				}

				remove_ideas = {
					BOV_atrophied_azhdaya_2
				}
				set_global_flag = UKR_UCW_UPA_Victory
				#UKR_bb_startup_BOV_Klyachivsky = yes
				add_stability = 0.25 # big stability buff
				add_war_support = 0.4 # big stability buff
				set_temp_variable = { gdp_growth_temp = 0.6 }
				econ_gdp_growth_change = yes
				set_temp_variable = { inflation_temp = -0.4 }
				econ_inflation_change = yes
			}
			else = {
				log = "[ERROR]: [GetDateText]: [Root.GetName]: UKR_UCW_check_victor; Somebody's ([From]: [From.GetName]) in UKR_contenders that shouldn't be."
			}
		}
	}
}

UKR_UCW_someone_dead = {
	remove_from_array = { global.UKR_contenders = ROOT }
}

UKR_UCW_fire_capitulation_event = {
	if = {
		limit = {
			FROM = { original_tag = UKR }
			ROOT = { original_tag = FUK }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.1
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = UKR }
			ROOT = { original_tag = BOV }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.2
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = UKR }
			ROOT = { original_tag = UKS }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.3
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = FUK }
			ROOT = { original_tag = UKR }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.4
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = FUK }
			ROOT = { original_tag = BOV }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.5
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = FUK }
			ROOT = { original_tag = UKS }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.6
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = BOV }
			ROOT = { original_tag = UKR }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.7
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = BOV }
			ROOT = { original_tag = UKS }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.9
				days = 2
			}
		}
	}
	if = {
		limit = {
			FROM = { original_tag = UKS }
			ROOT = { original_tag = UKR }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.10
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = UKS }
			ROOT = { original_tag = FUK }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.11
				days = 2
			}
		}
	}
	else_if = {
		limit = {
			FROM = { original_tag = UKS }
			ROOT = { original_tag = BOV }
		}
		FROM = {
			country_event = {
				id = UKR_UCW_capitulation.12
				days = 2
			}
		}
	}
}

UKR_UCW_econ_setup = {
	set_variable = { GDP_growth = -2.3 }
	set_variable = { base_inflation_rate = 1.7 }
	set_variable = { base_interest_rates = 5.4 }
	if = {
		limit = {
			tag = BOV
		}
		set_temp_variable = { temp_credit_rating = 2 }
		set_temp_variable = { temp_credit_rating_min = 1 }
		set_temp_variable = { temp_credit_rating_max = 2 }
		econ_initialize_credit_rating_system = yes
		set_variable = { income_tax_rate = 0.41 }
		set_variable = { business_tax_rate = 0.34 }
		set_variable = { poverty_monthly_change = -0.06 }
		set_variable = { economic_centralization = 65 }
	}
	else_if = {
		limit = {
			tag = UKS
		}
		set_temp_variable = { temp_credit_rating = 2 }
		set_temp_variable = { temp_credit_rating_min = 1 }
		set_temp_variable = { temp_credit_rating_max = 4 }
		econ_initialize_credit_rating_system = yes
		set_variable = { income_tax_rate = 0.32 }
		set_variable = { business_tax_rate = 0.55 }
		set_variable = { poverty_monthly_change = -0.03 }
		set_variable = { economic_centralization = 70 }
	}
	else_if = {
		limit = {
			tag = FUK
		}
		set_temp_variable = { temp_credit_rating = 2 }
		set_temp_variable = { temp_credit_rating_min = 1 }
		set_temp_variable = { temp_credit_rating_max = 4 }
		econ_initialize_credit_rating_system = yes
		set_variable = { income_tax_rate = 0.26 }
		set_variable = { business_tax_rate = 0.31 }
		set_variable = { poverty_monthly_change = -0.04 }
		set_variable = { economic_centralization = 45 }
	}
	else = {
		TNO_worsen_poverty_high = yes
	}
}

### 1.1 - Bitter Harvest Scripted Effects ###

UCW_supply_startup = {
	set_global_flag = UKR_ucw_supply_active
	set_variable = { UCW_supply_consumption_base = 25 } # This variable is the one that can be altered
	set_variable = { UCW_supply_consumption_true = UCW_supply_consumption_base } # UCW_supply_consumption_true must NOT be altered
	add_to_variable = { UCW_supply_consumption_true = modifier@weekly_supply_consumption }
	set_variable = { UCW_supply_consumption = UCW_supply_consumption_true }

	clamp_variable = { var = UCW_supply_consumption min = 0 }

	# Increase of weekly supply consumption every (undetermined) days
	set_variable = { UCW_weekly_supply_increase = 0 }
	set_variable = { UCW_consumption_increase_amount = 5 }

	### Regional supply pieces, probably change to arrays in the future
	set_variable = { global.UCW_supply_region_west_frame = 8 }
	set_variable = { global.UCW_supply_region_south_frame = 8 }
	set_variable = { global.UCW_supply_region_north_frame = 8 }
	set_variable = { global.UCW_supply_region_east_frame = 8 }

	# Tag specific setup
	if = {
		limit = { tag = UKR }
		set_variable = { UCW_remaining_supply = 1000 }
	}
	if = {
		limit = { tag = BOV }
		set_variable = { UCW_remaining_supply = 1000 }
	}
	if = {
		limit = { tag = FUK }
		set_variable = { UCW_remaining_supply = 1000 }
	}
	if = {
		limit = { tag = UKS }
		set_variable = { UCW_remaining_supply = 1000 }
	}

	if = { #so the ai doesn't get stuck with inefficient supply
		limit = {
			is_ai = yes
		}
		random_list = {
			2 = {
				clr_country_flag = UCW_feed_people
				clr_country_flag = UCW_conserve_supply
				set_country_flag = UCW_feed_soldiers
				add_ideas = UKR_supply_feed_soldiers
			}
			2 = {
				clr_country_flag = UCW_feed_soldiers
				clr_country_flag = UCW_conserve_supply
				set_country_flag = UCW_feed_people
				add_ideas = UKR_supply_feed_people
			}
			1 = {
				clr_country_flag = UCW_feed_soldiers
				clr_country_flag = UCW_feed_people
				set_country_flag = UCW_conserve_supply
				add_ideas = UKR_supply_conserve
			}
		}
	}
	if = {
		limit = {
			is_ai = no
		}
		add_ideas = UKR_supply_inefficient
	}
	add_ideas = UKR_the_ukrainian_civil_war
	add_ideas = UKR_a_bitter_harvest_negligible
}

UCW_supply_mechanic_check = {
	if = {
		limit = { has_global_flag = UKR_ucw_supply_active }

		set_variable = { UCW_supply_consumption_true = UCW_supply_consumption_base } # UCW_supply_consumption_true must NOT be altered
		add_to_variable = { UCW_supply_consumption_true = modifier@weekly_supply_consumption }
		set_variable = { UCW_supply_consumption = UCW_supply_consumption_true } # UCW_supply_consumption also mustn't be altered

		clamp_variable = { var = UCW_supply_consumption min = 0 }
		clamp_variable = { var = UCW_remaining_supply min = 0 max = 1000 }

		UKR_UCWMech_calculate_effects = yes
		UKR_UCWMech_ai_effects = yes

		# This thing is just for visuals
		if = {
			limit = {
				NOT = { has_country_flag = UCW_supply_fucked }
				check_variable = {
					var = UCW_remaining_supply
					value = 100
					compare = less_than_or_equals
				}
			}
			set_country_flag = UCW_supply_fucked
		}
		if = {
			limit = {
				has_country_flag = UCW_supply_fucked
				check_variable = {
					var = UCW_remaining_supply
					value = 250
					compare = greater_than_or_equals
				}
			}
			clr_country_flag = UCW_supply_fucked
		}
	}
}

UKR_UCWMech_calculate_effects = {
	if = {
		limit = {
			has_global_flag = UKR_UCW_ongoing
		}
		if = {
			limit = {
				check_variable = { UCW_remaining_supply > 799 }
			}
			if = {
				limit = {
					NOT = { has_idea = UKR_a_bitter_harvest_negligible }
				}
				country_event = UKR_UCW_bitter_harvest.5
			}
			remove_ideas = UKR_a_bitter_harvest_mild
			remove_ideas = UKR_a_bitter_harvest_moderate
			remove_ideas = UKR_a_bitter_harvest_severe
			remove_ideas = UKR_a_bitter_harvest_famine
			add_ideas = UKR_a_bitter_harvest_negligible
			add_ideas = UKR_the_ukrainian_civil_war
			remove_ideas = UKR_the_ukrainian_civil_war_2
		}
		else_if = {
			limit = {
				AND = {
					check_variable = { UCW_remaining_supply > 599 }
					check_variable = { UCW_remaining_supply < 800 }
				}
			}
			if = {
				limit = {
					has_idea = UKR_a_bitter_harvest_negligible
				}
				country_event = UKR_UCW_bitter_harvest.1
			}
			else_if = {
				limit = {
					OR = {
						has_idea = UKR_a_bitter_harvest_moderate
						has_idea = UKR_a_bitter_harvest_severe
						has_idea = UKR_a_bitter_harvest_famine
					}
				}
				country_event = UKR_UCW_bitter_harvest.5
			}
			remove_ideas = UKR_a_bitter_harvest_negligible
			remove_ideas = UKR_a_bitter_harvest_moderate
			remove_ideas = UKR_a_bitter_harvest_severe
			remove_ideas = UKR_a_bitter_harvest_famine
			add_ideas = UKR_a_bitter_harvest_mild
			add_ideas = UKR_the_ukrainian_civil_war
			remove_ideas = UKR_the_ukrainian_civil_war_2
		}
		else_if = {
			limit = {
				AND = {
					check_variable = { UCW_remaining_supply > 399 }
					check_variable = { UCW_remaining_supply < 600 }
				}
			}
			if = {
				limit = {
					OR = {
						has_idea = UKR_a_bitter_harvest_negligible
						has_idea = UKR_a_bitter_harvest_mild
					}
				}
				country_event = UKR_UCW_bitter_harvest.2
			}
			else_if = {
				limit = {
					OR = {
						has_idea = UKR_a_bitter_harvest_severe
						has_idea = UKR_a_bitter_harvest_famine
					}
				}
				country_event = UKR_UCW_bitter_harvest.5
			}
			remove_ideas = UKR_a_bitter_harvest_negligible
			remove_ideas = UKR_a_bitter_harvest_mild
			remove_ideas = UKR_a_bitter_harvest_severe
			remove_ideas = UKR_a_bitter_harvest_famine
			add_ideas = UKR_a_bitter_harvest_moderate
			add_ideas = UKR_the_ukrainian_civil_war
			remove_ideas = UKR_the_ukrainian_civil_war_2
		}
		else_if = {
			limit = {
				AND = {
					check_variable = { UCW_remaining_supply > 199 }
					check_variable = { UCW_remaining_supply < 400 }
				}
			}
			if = {
				limit = {
					OR = {
						has_idea = UKR_a_bitter_harvest_negligible
						has_idea = UKR_a_bitter_harvest_mild
						has_idea = UKR_a_bitter_harvest_moderate
					}
				}
				country_event = UKR_UCW_bitter_harvest.3
			}
			else_if = {
				limit = {
					has_idea = UKR_a_bitter_harvest_famine
				}
				country_event = UKR_UCW_bitter_harvest.5
			}
			remove_ideas = UKR_a_bitter_harvest_negligible
			remove_ideas = UKR_a_bitter_harvest_mild
			remove_ideas = UKR_a_bitter_harvest_moderate
			remove_ideas = UKR_a_bitter_harvest_famine
			add_ideas = UKR_a_bitter_harvest_severe
			add_ideas = UKR_the_ukrainian_civil_war
			remove_ideas = UKR_the_ukrainian_civil_war_2
		}
		else_if = {
			limit = {
				check_variable = { UCW_remaining_supply < 200 }
			}
			if = {
				limit = {
					NOT = { has_idea = UKR_a_bitter_harvest_famine }
				}
				country_event = UKR_UCW_bitter_harvest.4
			}
			remove_ideas = UKR_a_bitter_harvest_negligible
			remove_ideas = UKR_a_bitter_harvest_mild
			remove_ideas = UKR_a_bitter_harvest_moderate
			remove_ideas = UKR_a_bitter_harvest_severe
			add_ideas = UKR_a_bitter_harvest_famine
			remove_ideas = UKR_the_ukrainian_civil_war
			add_ideas = UKR_the_ukrainian_civil_war_2
		}
	}
}

UKR_UCWMech_ai_effects = { #so the ai does stuff!
	if = { #so the ai doesn't get stuck with inefficient supply
		limit = {
			is_ai = yes
		}
		add_to_variable = { UKR_UCW_ai_supply_check = 1 }
		if = {
			limit = {
				check_variable = { UKR_UCW_ai_supply_check = 3 }
			}
			set_variable = { UKR_UCW_ai_supply_check = 0 } #resets, this exists so it doesn't change every week
			if = {
				limit = {
					check_variable = { UCW_remaining_supply < 350 } #AI needs to conserve supply if it gets this low
				}
				clr_country_flag = UCW_feed_soldiers
				clr_country_flag = UCW_feed_people
				set_country_flag = UCW_conserve_supply

				remove_ideas = {
					UKR_supply_inefficient
					UKR_supply_feed_soldiers
					UKR_supply_feed_people
				}

				add_ideas = UKR_supply_conserve
			}
			else_if = {
				limit = {
					surrender_progress > 0.6 #AI needs to focus on soldiers if they're losing
				}
				clr_country_flag = UCW_feed_people
				clr_country_flag = UCW_conserve_supply
				set_country_flag = UCW_feed_soldiers
				
				remove_ideas = {
					UKR_supply_inefficient
					UKR_supply_feed_people
					UKR_supply_conserve
				}

				add_ideas = UKR_supply_feed_soldiers
			}
			else_if = {
				limit = {
					AND = {
						has_stability < -0.7 #AI needs to focus on people if stability is this low
						NOT = {
							original_tag = UKR #RK always has dogshit stability so with this it'd always focus on the people which doesn't make much sense. it can still decide through RNG
						}
					}
				}
				clr_country_flag = UCW_feed_soldiers
				clr_country_flag = UCW_conserve_supply
				set_country_flag = UCW_feed_people
				
				remove_ideas = {
					UKR_supply_inefficient
					UKR_supply_feed_soldiers
					UKR_supply_conserve
				}

				add_ideas = UKR_supply_feed_people
			}
			else = { #if the AI does not meet any of the above states, it'll choose randomly, weighted heavily towards soldiers and people
				random_list = {
					3 = {
						clr_country_flag = UCW_feed_people
						clr_country_flag = UCW_conserve_supply
						set_country_flag = UCW_feed_soldiers

						remove_ideas = {
							UKR_supply_inefficient
							UKR_supply_feed_people
							UKR_supply_conserve
						}

						add_ideas = UKR_supply_feed_soldiers
					}
					3 = {
						clr_country_flag = UCW_feed_soldiers
						clr_country_flag = UCW_conserve_supply
						set_country_flag = UCW_feed_people

						remove_ideas = {
							UKR_supply_inefficient
							UKR_supply_feed_soldiers
							UKR_supply_conserve
						}

						add_ideas = UKR_supply_feed_people
					}
					1 = {
						clr_country_flag = UCW_feed_soldiers
						clr_country_flag = UCW_feed_people
						set_country_flag = UCW_conserve_supply

						remove_ideas = {
							UKR_supply_inefficient
							UKR_supply_feed_soldiers
							UKR_supply_feed_people
						}

						add_ideas = UKR_supply_conserve
					}
				}
			}
		}
	}
}

UCW_weekly_consumption = {
	if = {
		limit = { has_global_flag = UKR_ucw_supply_active }
		subtract_from_variable = { UCW_remaining_supply = UCW_supply_consumption }
	}
}

# Increases weekly consumption of supply by a certain amount every 30 days
UCW_weekly_increase_mechanic = {
	if = {
		limit = { has_global_flag = UKR_ucw_supply_active }
		add_to_variable = { UCW_weekly_supply_increase = 1 }
		if = {
			limit = {
				check_variable = {
					UCW_weekly_supply_increase > 29
				}
			}
			add_to_variable = { UCW_supply_consumption_base = UCW_consumption_increase_amount }
			set_variable = { UCW_weekly_supply_increase = 0 }
		}
	}
}

# Changes in supply decay, use temp vars to avoid tooltip spam
UCW_weekly_consumption_change = {
	add_to_variable = { UCW_supply_consumption_base = UCW_weekly_temp }
	if = {
		limit = {
			check_variable = {
				UCW_weekly_temp < 0
			}
		}
		multiply_temp_variable = { UCW_weekly_temp = -1 }
		custom_effect_tooltip = UCW_weekly_consumption_decrease_tt
	}
	else = {
		custom_effect_tooltip = UCW_weekly_consumption_increase_tt
	}
}

# Change in supply amount
UCW_supply_left_change = {
	add_to_variable = { UCW_remaining_supply = UCW_supply_temp }
	if = {
		limit = {
			check_variable = {
				UCW_supply_temp < 0
			}
		}
		multiply_temp_variable = { UCW_supply_temp = -1 }
		custom_effect_tooltip = UCW_supply_amount_decrease_tt
	}
	else = {
		custom_effect_tooltip = UCW_supply_amount_increase_tt
	}
}

### 1.2 - Red Army Scripted Effects ###

UKS_red_army_setup = {
	set_variable = { UKS_red_army_org = -0.15 }
	set_variable = { UKS_red_army_morale = 0.15 }
	set_variable = { UKS_red_army_attack = -0.2 }
	set_variable = { UKS_red_army_defence = -0.1 }
	set_variable = { UKS_red_army_max_planning = -0.3 }
	set_variable = { UKS_red_army_training = 0.15 }
	set_variable = { UKS_red_army_supply_grace = 72 }
	set_variable = { UKS_red_army_supply_consumption = -0.15 }
	set_variable = { UKS_red_army_out_supply = -0.25 }
	set_variable = { UKS_red_army_pocket = -0.15 }
	add_dynamic_modifier = {
		modifier = UKS_red_army_mod
	}
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_org_L = {
	custom_effect_tooltip = UKS_red_army_change_org_L_tt
	add_to_variable = { UKS_red_army_org = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_morale_L = {
	custom_effect_tooltip = UKS_red_army_change_morale_L_tt
	add_to_variable = { UKS_red_army_morale = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_attack_L = {
	custom_effect_tooltip = UKS_red_army_change_attack_L_tt
	add_to_variable = { UKS_red_army_attack = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_defence_L = {
	custom_effect_tooltip = UKS_red_army_change_defence_L_tt
	add_to_variable = { UKS_red_army_defence = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_max_planning_L = {
	custom_effect_tooltip = UKS_red_army_change_max_planning_L_tt
	add_to_variable = { UKS_red_army_max_planning = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_training_L = {
	custom_effect_tooltip = UKS_red_army_change_training_L_tt
	add_to_variable = { UKS_red_army_training = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_supply_grace_L = {
	custom_effect_tooltip = UKS_red_army_change_supply_grace_L_tt
	add_to_variable = { UKS_red_army_supply_grace = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_supply_consumption_L = {
	custom_effect_tooltip = UKS_red_army_change_supply_consumption_L_tt
	add_to_variable = { UKS_red_army_supply_consumption = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_out_supply_L = {
	custom_effect_tooltip = UKS_red_army_change_out_supply_L_tt
	add_to_variable = { UKS_red_army_out_supply = L }
	force_update_dynamic_modifier = yes
}

UKS_red_army_change_pocket_L = {
	custom_effect_tooltip = UKS_red_army_change_pocket_L_tt
	add_to_variable = { UKS_red_army_pocket = L }
	force_update_dynamic_modifier = yes
}

### 1.3 - The War Within Scripted Effects ###

UKR_RK_war_within_setup = {
	set_variable = { UKR_war_within_monthly_pop = -0.15 }
	set_variable = { UKR_war_within_stability_weekly = -0.075 }
	set_variable = { UKR_war_within_compliance_gain_disabled = 1 }
	set_variable = { UKR_war_within_resistance_activity = 0.75 }
	set_variable = { UKR_war_within_resistance_growth = 0.33 }
	set_variable = { UKR_war_within_resistance_decay = -0.33 }
	set_variable = { UKR_war_within_garrison_factor = 0.5 }
	add_dynamic_modifier = {
		modifier = UKR_UCW_war_within_mod
	}
	force_update_dynamic_modifier = yes
}

# Scripted effects to modify the War Within dynmod.
# Remember to set U to a different value each time
# unless you want to change multiple modifiers by the same variable (in which case remember that changing monthly population and weekly stability by, say, +0.05 will have vastly different effects for both.

# UKR_RK_war_within_change_pop_U = change Monthly Population
# UKR_RK_war_within_change_stab_U = change Weekly Stability
# UKR_RK_war_within_change_resistance_activity_U = change Resistance Activity Change
# UKR_RK_war_within_change_resistance_growth_U = change Resistance Growth Speed
# UKR_RK_war_within_change_resistance_decay_U = change Resistance Decay Speed
# UKR_RK_war_within_change_garrison_factor_U = change Required Garrisons
# all by U obviously
# UKR_RK_war_within_enable_compliance = enable compliance growth. Doesn't use U, you don't need to set a variable.

# I tried to figure out how to make a single scripted effect that would change multiple modifiers with just one call, but the scripted loc for that would be a giant pain in the ass.
# - Numa out

UKR_RK_war_within_change_pop_U = {
	custom_effect_tooltip = UKR_RK_war_within_change_pop_U_tt
	add_to_variable = { UKR_war_within_monthly_pop = U }
	force_update_dynamic_modifier = yes
}

UKR_RK_war_within_change_stab_U = {
	custom_effect_tooltip = UKR_RK_war_within_change_stab_U_tt
	add_to_variable = { UKR_war_within_stability_weekly = U }
	force_update_dynamic_modifier = yes
}

UKR_RK_war_within_change_resistance_activity_U = {
	custom_effect_tooltip = UKR_RK_war_within_change_resistance_activity_U_tt
	add_to_variable = { UKR_war_within_resistance_activity = U }
	force_update_dynamic_modifier = yes
}

UKR_RK_war_within_change_resistance_growth_U = {
	custom_effect_tooltip = UKR_RK_war_within_change_resistance_growth_U_tt
	add_to_variable = { UKR_war_within_resistance_growth = U }
	force_update_dynamic_modifier = yes
}

UKR_RK_war_within_change_resistance_decay_U = {
	custom_effect_tooltip = UKR_RK_war_within_change_resistance_decay_U_tt
	add_to_variable = { UKR_war_within_resistance_decay = U }
	force_update_dynamic_modifier = yes
}

UKR_RK_war_within_change_garrison_factor_U = {
	custom_effect_tooltip = UKR_RK_war_within_change_garrison_factor_U_tt
	add_to_variable = { UKR_war_within_garrison_factor = U }
	force_update_dynamic_modifier = yes
}

UKR_RK_war_within_enable_compliance = {
	custom_effect_tooltip = UKR_RK_war_within_enable_compliance_tt
	set_variable = { UKR_war_within_compliance_gain_disabled = 0 }
	force_update_dynamic_modifier = yes
}

### 1.4 - Panacea Scripted Effects ###

#Panacea Scripted effects

UKR_RK_panacea_setup = {
	set_variable = { UKR_panacea_monthly_pop = -0.75 }
	set_variable = { UKR_panacea_stability_weekly = -0.05 }
	set_variable = { UKR_panacea_supply_consumption = -10 }
	add_dynamic_modifier = {
		modifier = UKR_UCW_panacea_mod
	}
	force_update_dynamic_modifier = yes
	add_ideas = UKR_UCW_panacea
}

UKR_RK_panacea_change_monthly_pop_C = {
	custom_effect_tooltip = UKR_RK_panacea_change_monthly_pop_C_tt
	add_to_variable = { UKR_panacea_monthly_pop = C }
	force_update_dynamic_modifier = yes
}

UKR_RK_panacea_stability_weekly_C = {
	custom_effect_tooltip = UKR_RK_panacea_change_stability_weekly_C_tt
	add_to_variable = { UKR_panacea_stability_weekly = C }
	force_update_dynamic_modifier = yes
}

UKR_RK_panacea_change_supply_consumption_C = {
	custom_effect_tooltip = UKR_RK_panacea_change_supply_consumption_C_tt
	add_to_variable = { UKR_panacea_supply_consumption = C }
	force_update_dynamic_modifier = yes
}

### 1.5 - All Alone Scripted Effects ###

#All Alone scripted effects, works same as war within mod

UKR_RK_all_alone_setup = {
	set_variable = { UKR_all_alone_recruitable_pop = -0.9 }
	set_variable = { UKR_all_alone_stability_weekly = -0.05 }
	add_dynamic_modifier = {
		modifier = UKR_UCW_all_alone_mod
	}
	force_update_dynamic_modifier = yes
}

UKR_RK_all_alone_change_stab_P = {
	custom_effect_tooltip = UKR_RK_all_alone_change_stab_P_tt
	add_to_variable = { UKR_all_alone_stability_weekly = P }
	force_update_dynamic_modifier = yes
}

UKR_RK_all_alone_change_recruitable_pop_P = {
	custom_effect_tooltip = UKR_RK_all_alone_change_recruitable_pop_P_tt
	add_to_variable = { UKR_all_alone_recruitable_pop = P }
	force_update_dynamic_modifier = yes
}

UKR_RK_all_alone_change_natsoc_drift_P = {
	custom_effect_tooltip = UKR_RK_all_alone_change_natsoc_drift_P_tt
	add_to_variable = { UKR_all_alone_natsoc_drift = P }
	force_update_dynamic_modifier = yes
}

### 1.6 - Dispirited, Deranged Domevoy Scripted Effects ###

#Dispirited, Deranged Domevoy effects

BOV_domevoy_setup = {
	custom_effect_tooltip = BOV_domevoy_add_tt
	set_variable = { BOV_domevoy_war_support = -0.25 }
	set_variable = { BOV_domevoy_surrender_limit = -0.25 }
	set_variable = { BOV_domevoy_manpower_modifier = -0.5 }
	set_variable = { BOV_domevoy_supply_consumption = 0 }
	hidden_effect = {
		add_dynamic_modifier = {
			modifier = BOV_dispirited_domevoy
		}
		swap_ideas = {
			remove_idea = BOV_dispirited_domevoy_0
			add_idea = BOV_dispirited_domevoy_1
		}
	}
	force_update_dynamic_modifier = yes
}

BOV_domevoy_disable = {
	clear_variable = BOV_domevoy_war_support
	clear_variable = BOV_domevoy_surrender_limit
	clear_variable = BOV_domevoy_manpower_modifier
	clear_variable = BOV_domevoy_supply_consumption
	remove_dynamic_modifier = {
		modifier = BOV_dispirited_domevoy
	}
}

BOV_domevoy_war_support_D = {
	custom_effect_tooltip = BOV_domevoy_change_war_support_D_tt
	add_to_variable = { BOV_domevoy_war_support = D }
	force_update_dynamic_modifier = yes
}

BOV_domevoy_surrender_limit_D = {
	custom_effect_tooltip = BOV_domevoy_change_surrender_limit_D_tt
	add_to_variable = { BOV_domevoy_surrender_limit = D }
	force_update_dynamic_modifier = yes
}

BOV_domevoy_manpower_modifier_D = {
	custom_effect_tooltip = BOV_domevoy_change_manpower_modifier_D_tt
	add_to_variable = { BOV_domevoy_manpower_modifier = D }
	force_update_dynamic_modifier = yes
}

BOV_domevoy_supply_consumption_D = {
	custom_effect_tooltip = BOV_domevoy_change_supply_consumption_D_tt
	add_to_variable = { BOV_domevoy_supply_consumption = D }
	force_update_dynamic_modifier = yes
}

### 1.7 - Ukrainian Civil War Breadbasket Variable Transfer Scripted Effects ###

##### UCW BB VARIABLE TRANSFER EFFECTS #####
UKR_bb_UCW_variable_transfer = { #making it all mean something
	### POINT CALCULATION ###
	var:Kiev_region = {
		add_to_temp_variable = { UKR_RK_UCW_points_temp = resistance_control^0 }
		add_to_temp_variable = { UKR_UA_SSR_UCW_points_temp = resistance_control^1 }
		add_to_temp_variable = { UKR_PG_UCW_points_temp = resistance_control^2 }
		add_to_temp_variable = { UKR_UPA_UCW_points_temp = resistance_control^3 }

		# desolation calc
		subtract_from_temp_variable = { UKR_RK_UCW_points_temp = desolation }
	}
	var:Mykolaiv_region = {
		add_to_temp_variable = { UKR_RK_UCW_points_temp = resistance_control^0 }
		add_to_temp_variable = { UKR_UA_SSR_UCW_points_temp = resistance_control^1 }
		add_to_temp_variable = { UKR_PG_UCW_points_temp = resistance_control^2 }
		add_to_temp_variable = { UKR_UPA_UCW_points_temp = resistance_control^3 }

		# desolation calc
		subtract_from_temp_variable = { UKR_RK_UCW_points_temp = desolation }
	}
	var:Chernihiv_region = {
		add_to_temp_variable = { UKR_RK_UCW_points_temp = resistance_control^0 }
		add_to_temp_variable = { UKR_UA_SSR_UCW_points_temp = resistance_control^1 }
		add_to_temp_variable = { UKR_PG_UCW_points_temp = resistance_control^2 }
		add_to_temp_variable = { UKR_UPA_UCW_points_temp = resistance_control^3 }

		# desolation calc
		subtract_from_temp_variable = { UKR_RK_UCW_points_temp = desolation }
	}
	var:Kharkiv_region = {
		add_to_temp_variable = { UKR_RK_UCW_points_temp = resistance_control^0 }
		add_to_temp_variable = { UKR_UA_SSR_UCW_points_temp = resistance_control^1 }
		add_to_temp_variable = { UKR_PG_UCW_points_temp = resistance_control^2 }
		add_to_temp_variable = { UKR_UPA_UCW_points_temp = resistance_control^3 }

		# desolation calc
		subtract_from_temp_variable = { UKR_RK_UCW_points_temp = desolation }
		subtract_from_temp_variable = { UKR_PG_UCW_points_temp = desolation }
		subtract_from_temp_variable = { UKR_UPA_UCW_points_temp = desolation }
	}
	var:Volyn_region = {
		add_to_temp_variable = { UKR_RK_UCW_points_temp = resistance_control^0 }
		add_to_temp_variable = { UKR_UA_SSR_UCW_points_temp = resistance_control^1 }
		add_to_temp_variable = { UKR_PG_UCW_points_temp = resistance_control^2 }
		add_to_temp_variable = { UKR_UPA_UCW_points_temp = resistance_control^3 }

		# desolation calc
		subtract_from_temp_variable = { UKR_PG_UCW_points_temp = desolation }
		subtract_from_temp_variable = { UKR_UPA_UCW_points_temp = desolation }
	}
	var:Luhansk_region = {
		add_to_temp_variable = { UKR_RK_UCW_points_temp = resistance_control^0 }
		add_to_temp_variable = { UKR_UA_SSR_UCW_points_temp = resistance_control^1 }
		add_to_temp_variable = { UKR_PG_UCW_points_temp = resistance_control^2 }
		add_to_temp_variable = { UKR_UPA_UCW_points_temp = resistance_control^3 }

		# desolation calc
		subtract_from_temp_variable = { UKR_UA_SSR_UCW_points_temp = desolation }
	}

	set_variable = { UKR_RK_UCW_points = UKR_RK_UCW_points_temp }
	set_variable = { UKS.UKR_UA_SSR_UCW_points = UKR_UA_SSR_UCW_points_temp }
	set_variable = { FUK.UKR_PG_UCW_points = UKR_PG_UCW_points_temp }
	set_variable = { BOV.UKR_UPA_UCW_points = UKR_UPA_UCW_points_temp }
}

UKR_UCW_RKU_point_buffs = {
	UKR = {
		custom_effect_tooltip = UKR_breadbasket_points_effects_tt
		set_temp_variable = { UKR_RK_UCW_political_power = UKR_RK_UCW_points }
		divide_temp_variable = { UKR_RK_UCW_political_power = 10 }
		multiply_temp_variable = { UKR_RK_UCW_political_power = 3 } 
		add_political_power = var:UKR_RK_UCW_political_power

		set_temp_variable = { UKR_RK_UCW_stability_war_support = UKR_RK_UCW_points }
		divide_temp_variable = { UKR_RK_UCW_stability_war_support = 2000 } 
		add_stability = var:UKR_RK_UCW_stability_war_support
		add_war_support = var:UKR_RK_UCW_stability_war_support

		set_temp_variable = { UKR_RK_UCW_manpower = UKR_RK_UCW_points }
		multiply_temp_variable = { UKR_RK_UCW_manpower = 50 }
		add_manpower = var:UKR_RK_UCW_manpower

		set_temp_variable = { UKR_RK_UCW_guns = UKR_RK_UCW_points }
		multiply_temp_variable = { UKR_RK_UCW_guns = 10 }
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = var:UKR_RK_UCW_guns
			producer = UKR
		}

		set_temp_variable = { UKR_RK_UCW_divs = UKR_RK_UCW_points }
		divide_temp_variable = { UKR_RK_UCW_divs = 50 }
		round_temp_variable = UKR_RK_UCW_divs
		if = {
			limit = { check_variable = { UKR_RK_UCW_divs > 0 } }
			capital_scope = {
				create_unit = {
					division = "division_template = \"Infanterie-Division\" start_experience_factor = 0.2 start_equipment_factor = 1"
					owner = UKR
					count = UKR_RK_UCW_divs
				}
			}
		}
	}
}

UKR_UCW_UKS_point_buffs = {
	UKS = {
		custom_effect_tooltip = UKR_breadbasket_points_effects_tt
		set_temp_variable = { UKR_UA_SSR_UCW_political_power = UKR_UA_SSR_UCW_points }
		divide_temp_variable = { UKR_UA_SSR_UCW_political_power = 10 }
		multiply_temp_variable = { UKR_UA_SSR_UCW_political_power = 3 } 
		add_political_power = var:UKR_UA_SSR_UCW_political_power

		set_temp_variable = { UKR_UA_SSR_UCW_stability_war_support = UKR_UA_SSR_UCW_points }
		divide_temp_variable = { UKR_UA_SSR_UCW_stability_war_support = 1000 }
		add_stability = var:UKR_UA_SSR_UCW_stability_war_support
		add_war_support = var:UKR_UA_SSR_UCW_stability_war_support

		set_temp_variable = { UKR_UA_SSR_UCW_manpower = UKR_UA_SSR_UCW_points }
		multiply_temp_variable = { UKR_UA_SSR_UCW_manpower = 200 }
		if = {
			limit = { has_country_flag = UKR_play_UKS }
			set_temp_variable = { UKR_UA_SSR_UCW_stockpile_manpower = UKR_bb_partisan_stockpile_manpower }
			add_to_temp_variable = { UKR_UA_SSR_UCW_manpower = UKR_UA_SSR_UCW_stockpile_manpower }
		}
		add_manpower = var:UKR_UA_SSR_UCW_manpower

		set_temp_variable = { UKR_UA_SSR_UCW_guns = UKR_UA_SSR_UCW_points }
		multiply_temp_variable = { UKR_UA_SSR_UCW_guns = 20 }
		if = {
			limit = { has_country_flag = UKR_play_UKS }
			set_temp_variable = { UKR_UA_SSR_UCW_stockpile_guns = UKR_bb_partisan_stockpile_guns }
			add_to_temp_variable = { UKR_UA_SSR_UCW_guns = UKR_UA_SSR_UCW_stockpile_guns }
		}
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = var:UKR_UA_SSR_UCW_guns
			producer = UKR
		}

		set_temp_variable = { UKR_UA_SSR_UCW_divs = UKR_UA_SSR_UCW_points }
		divide_temp_variable = { UKR_UA_SSR_UCW_divs = 25 }
		round_temp_variable = UKR_UA_SSR_UCW_divs
		if = {
			limit = { check_variable = { UKR_UA_SSR_UCW_divs > 0 } }
			capital_scope = {
				meta_effect = {
					text = {
						create_unit = {
							division = "division_template = \"Partyzans'ka Dyviziya\" start_experience_factor = [UKR_EXP] start_equipment_factor = 1"
							owner = UKS
							count = var:UKR_UA_SSR_UCW_divs #I have a suspicion that this doesn't actually work and may need to be put in the meta effect as well. Need to check later - Auskom
						}
					}
					UKR_EXP = "[?UKS_uprising_division_exp]"
				}
			}
		}
	}
}

UKR_UCW_FUK_point_buffs = {
	FUK = {
		custom_effect_tooltip = UKR_breadbasket_points_effects_tt
		set_temp_variable = { UKR_PG_UCW_political_power = UKR_PG_UCW_points }
		divide_temp_variable = { UKR_PG_UCW_political_power = 10 }
		multiply_temp_variable = { UKR_PG_UCW_political_power = 3 } 
		add_political_power = var:UKR_PG_UCW_political_power

		set_temp_variable = { UKR_PG_UCW_stability_war_support = UKR_PG_UCW_points }
		divide_temp_variable = { UKR_PG_UCW_stability_war_support = 1000 }
		add_stability = var:UKR_PG_UCW_stability_war_support
		add_war_support = var:UKR_PG_UCW_stability_war_support

		set_temp_variable = { UKR_PG_UCW_manpower = UKR_PG_UCW_points }
		multiply_temp_variable = { UKR_PG_UCW_manpower = 200 }
		if = {
			limit = { has_country_flag = UKR_play_FUK }
			set_temp_variable = { UKR_UNRA_UCW_stockpile_manpower = UKR_bb_partisan_stockpile_manpower }
			add_to_temp_variable = { UKR_PG_UCW_manpower = UKR_UNRA_UCW_stockpile_manpower }
		}
		add_manpower = var:UKR_PG_UCW_manpower

		set_temp_variable = { UKR_PG_UCW_guns = UKR_PG_UCW_points }
		multiply_temp_variable = { UKR_PG_UCW_guns = 20 }
		if = {
			limit = { has_country_flag = UKR_play_FUK }
			set_temp_variable = { UKR_UNRA_UCW_stockpile_guns = UKR_bb_partisan_stockpile_guns }
			add_to_temp_variable = { UKR_PG_UCW_guns = UKR_UNRA_UCW_stockpile_guns }
		}
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = var:UKR_PG_UCW_guns
			producer = UKR
		}

		set_temp_variable = { UKR_PG_UCW_divs = UKR_PG_UCW_points }
		divide_temp_variable = { UKR_PG_UCW_divs = 25 }
		round_temp_variable = UKR_PG_UCW_divs
		if = {
			limit = { check_variable = { UKR_PG_UCW_divs > 0 } }
			capital_scope = {
				create_unit = {
					division = "division_template = \"Partyzans'ka Dyviziya\" start_experience_factor = 0.2 start_equipment_factor = 1"
					owner = FUK
					count = UKR_PG_UCW_divs
				}
			}
		}
	}
}

UKR_UCW_BOV_point_buffs = {
	BOV = {
		custom_effect_tooltip = UKR_breadbasket_points_effects_tt
		set_temp_variable = { UKR_UPA_UCW_political_power = UKR_UPA_UCW_points }
		divide_temp_variable = { UKR_UPA_UCW_political_power = 10 }
		multiply_temp_variable = { UKR_UPA_UCW_political_power = 3 } 
		add_political_power = var:UKR_UPA_UCW_political_power

		set_temp_variable = { UKR_UPA_UCW_stability_war_support = UKR_UPA_UCW_points }
		divide_temp_variable = { UKR_UPA_UCW_stability_war_support = 1000 }
		add_stability = var:UKR_UPA_UCW_stability_war_support
		add_war_support = var:UKR_UPA_UCW_stability_war_support

		set_temp_variable = { UKR_UPA_UCW_manpower = UKR_UPA_UCW_points }
		multiply_temp_variable = { UKR_UPA_UCW_manpower = 200 }
		if = {
			limit = { has_country_flag = UKR_play_BOV }
			set_temp_variable = { UKR_UPA_UCW_stockpile_manpower = UKR_bb_partisan_stockpile_manpower }
			add_to_temp_variable = { UKR_UPA_UCW_manpower = UKR_UPA_UCW_stockpile_manpower }
		}
		add_manpower = var:UKR_UPA_UCW_manpower

		set_temp_variable = { UKR_UPA_UCW_guns = UKR_UPA_UCW_points }
		multiply_temp_variable = { UKR_UPA_UCW_guns = 20 }
		if = {
			limit = { has_country_flag = UKR_play_BOV }
			set_temp_variable = { UKR_UPA_UCW_stockpile_guns = UKR_bb_partisan_stockpile_guns }
			add_to_temp_variable = { UKR_UPA_UCW_guns = UKR_UPA_UCW_stockpile_guns }
		}
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = var:UKR_UPA_UCW_guns
			producer = UKR
		}

		set_temp_variable = { UKR_UPA_UCW_divs = UKR_UPA_UCW_points }
		divide_temp_variable = { UKR_UPA_UCW_divs = 25 }
		round_temp_variable = UKR_UPA_UCW_divs
		if = {
			limit = { check_variable = { UKR_UPA_UCW_divs > 0 } }
			capital_scope = {
				create_unit = {
					division = "division_template = \"Partyzans'ka Dyviziya\" start_experience_factor = 0.2 start_equipment_factor = 1"
					owner = BOV
					count = UKR_UPA_UCW_divs
				}
			}
		}
	}
}

##########################################
# 2.0.0 - An Empty Throne Scripted Effects #
##########################################

##################################################
### Ukraine power struggle script version 2 by Scars ###
##################################################

## Arrays of the 'sections'
# Industrialists - UKR_PS_Industrialist
# Bureaucrats - UKR_PS_Bureaucrat
# Collaborators - UKR_PS_Collaborator
# Militarists - UKR_PS_Militarist

## You do not have to read this entire script, these are the scripted effects you need to worry about:

# UKR_PS_Industrialist_update (temp var being `PS_IND_temp`)
# UKR_PS_Bureaucrat_update (temp var being `PS_BUR_temp`)
# UKR_PS_Collaborator_update (temp var being `PS_COL_temp`)
# UKR_PS_Militarist_update (temp var being `PS_MIL_temp`)

## How to Use:
# set_temp_variable = { UKR_PS_contender_id = 3 }
# set_temp_variable = { PS_BUR_temp = 10 }
# UKR_PS_Bureaucrat_update = yes

## Array indexes (UKR_PS_contender_id)
# 0 - Ohlendorf
# 1 - Leibbrandt
# 2 - Brautigam

UKR_PS_Startup_script = {
	clear_array = UKR_PS_Industrialist
	clear_array = UKR_PS_Bureaucrat
	clear_array = UKR_PS_Collaborator
	clear_array = UKR_PS_Militarist
	add_to_array = { UKR_PS_Industrialist = 30 }
	add_to_array = { UKR_PS_Industrialist = 40 }
	add_to_array = { UKR_PS_Industrialist = 30 }
	add_to_array = { UKR_PS_Bureaucrat = 35 }
	add_to_array = { UKR_PS_Bureaucrat = 50 }
	add_to_array = { UKR_PS_Bureaucrat = 15 }
	add_to_array = { UKR_PS_Collaborator = 25 }
	add_to_array = { UKR_PS_Collaborator = 45 }
	add_to_array = { UKR_PS_Collaborator = 30 }
	add_to_array = { UKR_PS_Militarist = 45 }
	add_to_array = { UKR_PS_Militarist = 40 }
	add_to_array = { UKR_PS_Militarist = 15 }
	UKR_PS_update_GUI_data = yes
	set_country_flag = UKR_power_struggle_active

	UKR_PS_ideology_setup = yes

	### UKR POWER STRUGGLE DECISION COST VARIABLES
	set_variable = { UKR_brautigam_ai_shutup = 10 }
	set_variable = { UKR_leib_ai_shutup = 10 }
	set_variable = { UKR_ohlendorf_ai_shutup = 10 }
	set_variable = { UKR_reduce_factionalism_cost = 10 }

	hidden_effect = {
		random_list = {
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_agitates_against_brutality
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_mobilizes_dissidents_in_bureaucracy
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_appeals_to_unc
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_imports_foreign_office_dissidents
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_makes_deals_with_businesses
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_spreads_pro_collab_propaganda
			}
		}
		random_list = {
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_strengthens_acting_rk_position
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_tightens_control_over_unc
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_appoints_rosenbergite_bureaucrats
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_sways_corporate_interests
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_expands_una
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_forces_through_reforms
			}
		}
		random_list = {
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_calls_for_stronger_action
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_enacts_reprisals
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_defends_german_settler_interests
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_grows_the_kampfgruppe
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_funds_ss_enterprises
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_recruits_more_ukrainian_police
			}
		}
		activate_mission = UKR_power_struggle_factionalism_intensifies
	}
	custom_effect_tooltip = UKR_RK_power_struggle_begin_tt
}

UKR_PS_ideology_setup = {
	hidden_effect = {
		if = {
			limit = {
				NOT = {
					has_country_leader = {
						character = UKR_Eduard_Wagner
						ruling_only = yes
					}
				}
			}
		if = { # again, the winmerge
			limit = {
				has_country_flag = UKR_bb_enabled
			}
			202 = {
				add_to_temp_variable = { UKR_temp_rku_pop = resistance_control^0 }
				add_to_temp_variable = { UKR_temp_com_pop = resistance_control^1 }
				add_to_temp_variable = { UKR_temp_pat_pop = resistance_control^2 }
				add_to_temp_variable = { UKR_temp_ult_pop = resistance_control^3 }
			}
			226 = {
				add_to_temp_variable = { UKR_temp_rku_pop = resistance_control^0 }
				add_to_temp_variable = { UKR_temp_com_pop = resistance_control^1 }
				add_to_temp_variable = { UKR_temp_pat_pop = resistance_control^2 }
				add_to_temp_variable = { UKR_temp_ult_pop = resistance_control^3 }
			}
			1427 = {
				add_to_temp_variable = { UKR_temp_rku_pop = resistance_control^0 }
				add_to_temp_variable = { UKR_temp_com_pop = resistance_control^1 }
				add_to_temp_variable = { UKR_temp_pat_pop = resistance_control^2 }
				add_to_temp_variable = { UKR_temp_ult_pop = resistance_control^3 }
			}
			1430 = {
				add_to_temp_variable = { UKR_temp_rku_pop = resistance_control^0 }
				add_to_temp_variable = { UKR_temp_com_pop = resistance_control^1 }
				add_to_temp_variable = { UKR_temp_pat_pop = resistance_control^2 }
				add_to_temp_variable = { UKR_temp_ult_pop = resistance_control^3 }
			}
			93 = {
				add_to_temp_variable = { UKR_temp_rku_pop = resistance_control^0 }
				add_to_temp_variable = { UKR_temp_com_pop = resistance_control^1 }
				add_to_temp_variable = { UKR_temp_pat_pop = resistance_control^2 }
				add_to_temp_variable = { UKR_temp_ult_pop = resistance_control^3 }
			}
			227 = {
				add_to_temp_variable = { UKR_temp_rku_pop = resistance_control^0 }
				add_to_temp_variable = { UKR_temp_com_pop = resistance_control^1 }
				add_to_temp_variable = { UKR_temp_pat_pop = resistance_control^2 }
				add_to_temp_variable = { UKR_temp_ult_pop = resistance_control^3 }
			}

			divide_temp_variable = { UKR_temp_rku_pop = 6 } #we want an average here
			divide_temp_variable = { UKR_temp_com_pop = 6 } #we want an average here
			divide_temp_variable = { UKR_temp_pat_pop = 6 } #we want an average here
			divide_temp_variable = { UKR_temp_ult_pop = 6 } #we want an average here

			round_temp_variable = UKR_temp_rku_pop #prevents fucky shit with decimals - useful!
			round_temp_variable = UKR_temp_com_pop #prevents fucky shit with decimals - useful!
			round_temp_variable = UKR_temp_pat_pop #prevents fucky shit with decimals - useful!
			round_temp_variable = UKR_temp_ult_pop #prevents fucky shit with decimals - useful!
		}

		else = {
			set_temp_variable = { UKR_temp_rku_pop = 70 }
			set_temp_variable = { UKR_temp_com_pop = 15 }
			set_temp_variable = { UKR_temp_pat_pop = 10 }
			set_temp_variable = { UKR_temp_ult_pop = 5 }
		}


		set_temp_variable = { UKR_temp_ps_rk_pop = UKR_temp_rku_pop }
		divide_temp_variable = { UKR_temp_ps_rk_pop = 100 }

		set_temp_variable = { UKR_temp_ps_collab_pop = UKR_temp_ps_rk_pop }
		multiply_temp_variable = { UKR_temp_ps_collab_pop = 0.3 }
		multiply_temp_variable = { UKR_temp_ps_rk_pop = 0.7 }

		set_temp_variable = { UKR_temp_total_leib_popularity = UKR_PS_Bureaucrat^1 }
		add_to_temp_variable = { UKR_temp_total_leib_popularity = UKR_PS_Militarist^1 }
		add_to_temp_variable = { UKR_temp_total_leib_popularity = UKR_PS_Industrialist^1 }

		divide_temp_variable = { UKR_temp_total_leib_popularity = 3 }
		multiply_temp_variable = { UKR_temp_total_leib_popularity = UKR_temp_ps_rk_pop }
		round_temp_variable = UKR_temp_total_leib_popularity

		set_temp_variable = { UKR_temp_total_ohlendorf_popularity = UKR_PS_Bureaucrat^0 }
		add_to_temp_variable = { UKR_temp_total_ohlendorf_popularity = UKR_PS_Militarist^0 }
		add_to_temp_variable = { UKR_temp_total_ohlendorf_popularity = UKR_PS_Industrialist^0 }

		divide_temp_variable = { UKR_temp_total_ohlendorf_popularity = 3 }
		multiply_temp_variable = { UKR_temp_total_ohlendorf_popularity = UKR_temp_ps_rk_pop }
		round_temp_variable = UKR_temp_total_ohlendorf_popularity

		set_temp_variable = { UKR_temp_total_brautigam_popularity = UKR_PS_Bureaucrat^2 }
		add_to_temp_variable = { UKR_temp_total_brautigam_popularity = UKR_PS_Militarist^2 }
		add_to_temp_variable = { UKR_temp_total_brautigam_popularity = UKR_PS_Industrialist^2 }

		divide_temp_variable = { UKR_temp_total_brautigam_popularity = 3 }
		multiply_temp_variable = { UKR_temp_total_brautigam_popularity = UKR_temp_ps_rk_pop }
		round_temp_variable = UKR_temp_total_brautigam_popularity

		set_temp_variable = { UKR_temp_total_fash_popularity = UKR_PS_Collaborator^1 }
		add_to_temp_variable = { UKR_temp_total_fash_popularity = UKR_PS_Collaborator^0 }
		set_temp_variable = { UKR_temp_total_despot_popularity = UKR_PS_Collaborator^2 }

		multiply_temp_variable = { UKR_temp_total_fash_popularity = UKR_temp_ps_collab_pop }
		multiply_temp_variable = { UKR_temp_total_despot_popularity = UKR_temp_ps_collab_pop }
		round_temp_variable = UKR_temp_total_fash_popularity
		round_temp_variable = UKR_temp_total_despot_popularity

		#make sure the popularities add to 100 - bandaid fix - shukla 
		set_temp_variable = { UKR_temp_tot_ideog_pop = 0 }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_com_pop }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_pat_pop }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_total_despot_popularity }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_ult_pop }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_total_fash_popularity }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_total_leib_popularity }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_total_brautigam_popularity }
		add_to_temp_variable = { UKR_temp_tot_ideog_pop = UKR_temp_total_ohlendorf_popularity }

		if = { 
			limit = {
				check_variable = { UKR_temp_tot_ideog_pop < 100 }
			}
			set_temp_variable = { UKR_temp_tot_pop_diff = 100 }
			subtract_from_temp_variable = { UKR_temp_tot_pop_diff = UKR_temp_tot_ideog_pop }

			#we just give all the remaining popularity to despotism, idk what it looks like and dont wanna go in game to check
			add_to_temp_variable = { UKR_temp_total_despot_popularity = UKR_temp_tot_pop_diff }
		}

		set_popularities = {
			communist = var:UKR_temp_com_pop
			socialist = 0
			progressivism = 0
			liberalism = 0
			liberal_conservatism = 0
			conservatism = 0
			anocracy = var:UKR_temp_pat_pop
			despotism = var:UKR_temp_total_despot_popularity
			ultranationalism = var:UKR_temp_ult_pop
			fascism = var:UKR_temp_total_fash_popularity
			national_socialism = var:UKR_temp_total_leib_popularity
			national_socialism_3 = var:UKR_temp_total_brautigam_popularity
			national_socialism_2 = var:UKR_temp_total_ohlendorf_popularity
		}
	}
	}
}

UKR_PS_Startup_script_ai = { #when the UKR tag doesn't go down RKU in destiny, balances things out a bit and makes it actually fire for the AI
	clear_array = UKR_PS_Industrialist
	clear_array = UKR_PS_Bureaucrat
	clear_array = UKR_PS_Collaborator
	clear_array = UKR_PS_Militarist
	add_to_array = { UKR_PS_Industrialist = 30 }
	add_to_array = { UKR_PS_Industrialist = 35 }
	add_to_array = { UKR_PS_Industrialist = 35 }
	add_to_array = { UKR_PS_Bureaucrat = 35 }
	add_to_array = { UKR_PS_Bureaucrat = 40 }
	add_to_array = { UKR_PS_Bureaucrat = 25 }
	add_to_array = { UKR_PS_Collaborator = 25 }
	add_to_array = { UKR_PS_Collaborator = 40 }
	add_to_array = { UKR_PS_Collaborator = 35 }
	add_to_array = { UKR_PS_Militarist = 45 }
	add_to_array = { UKR_PS_Militarist = 30 }
	add_to_array = { UKR_PS_Militarist = 25 }
	UKR_PS_update_GUI_data = yes
	set_country_flag = UKR_power_struggle_active

	UKR_PS_ideology_setup = yes

	hidden_effect = {
		random_list = {
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_agitates_against_brutality
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_mobilizes_dissidents_in_bureaucracy
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_appeals_to_unc
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_imports_foreign_office_dissidents
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_makes_deals_with_businesses
			}
			1 = {
				activate_mission = UKR_power_struggle_brautigam_ai_spreads_pro_collab_propaganda
			}
		}
		random_list = {
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_strengthens_acting_rk_position
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_tightens_control_over_unc
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_appoints_rosenbergite_bureaucrats
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_sways_corporate_interests
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_expands_una
			}
			1 = {
				activate_mission = UKR_power_struggle_leibbrandt_ai_forces_through_reforms
			}
		}
		random_list = {
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_calls_for_stronger_action
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_enacts_reprisals
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_defends_german_settler_interests
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_grows_the_kampfgruppe
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_funds_ss_enterprises
			}
			1 = {
				activate_mission = UKR_power_struggle_ohlendorf_ai_recruits_more_ukrainian_police
			}
		}
		random_list = {
			1 = {
				set_country_flag = UKR_play_leibbrandt
				hidden_effect = {
					remove_mission = UKR_power_struggle_leibbrandt_ai_strengthens_acting_rk_position
					remove_mission = UKR_power_struggle_leibbrandt_ai_tightens_control_over_unc
					remove_mission = UKR_power_struggle_leibbrandt_ai_appoints_rosenbergite_bureaucrats
					remove_mission = UKR_power_struggle_leibbrandt_ai_sways_corporate_interests
					remove_mission = UKR_power_struggle_leibbrandt_ai_expands_una
					remove_mission = UKR_power_struggle_leibbrandt_ai_forces_through_reforms
				}
			}
			1 = {
				set_country_flag = UKR_play_ohlendorf
				# so he wins a bit more often when chosen by AI
				set_temp_variable = { UKR_PS_contender_id = 0 }
				set_temp_variable = { PS_BUR_temp = 10 }
				UKR_PS_Bureaucrat_update = yes
				set_temp_variable = { UKR_PS_contender_id = 0 }
				set_temp_variable = { PS_MIL_temp = 10 }
				UKR_PS_Militarist_update = yes
				set_temp_variable = { UKR_PS_contender_id = 0 }
				set_temp_variable = { PS_IND_temp = 10 }
				UKR_PS_Industrialist_update = yes
				set_temp_variable = { UKR_PS_contender_id = 0 }
				set_temp_variable = { PS_COL_temp = 10 }
				UKR_PS_Collaborator_update = yes
				hidden_effect = {
					remove_mission = UKR_power_struggle_ohlendorf_ai_calls_for_stronger_action
					remove_mission = UKR_power_struggle_ohlendorf_ai_enacts_reprisals
					remove_mission = UKR_power_struggle_ohlendorf_ai_defends_german_settler_interests
					remove_mission = UKR_power_struggle_ohlendorf_ai_grows_the_kampfgruppe
					remove_mission = UKR_power_struggle_ohlendorf_ai_funds_ss_enterprises
					remove_mission = UKR_power_struggle_ohlendorf_ai_recruits_more_ukrainian_police
				}
			}
			1 = {
				set_country_flag = UKR_play_brautigam
				# so he wins a bit more often when chosen by AI
				set_temp_variable = { UKR_PS_contender_id = 2 }
				set_temp_variable = { PS_BUR_temp = 10 }
				UKR_PS_Bureaucrat_update = yes
				set_temp_variable = { UKR_PS_contender_id = 2 }
				set_temp_variable = { PS_MIL_temp = 10 }
				UKR_PS_Militarist_update = yes
				set_temp_variable = { UKR_PS_contender_id = 2 }
				set_temp_variable = { PS_IND_temp = 10 }
				UKR_PS_Industrialist_update = yes
				set_temp_variable = { UKR_PS_contender_id = 2 }
				set_temp_variable = { PS_COL_temp = 10 }
				UKR_PS_Collaborator_update = yes
				hidden_effect = {
					remove_mission = UKR_power_struggle_brautigam_ai_agitates_against_brutality
					remove_mission = UKR_power_struggle_brautigam_ai_mobilizes_dissidents_in_bureaucracy
					remove_mission = UKR_power_struggle_brautigam_ai_appeals_to_unc
					remove_mission = UKR_power_struggle_brautigam_ai_imports_foreign_office_dissidents
					remove_mission = UKR_power_struggle_brautigam_ai_makes_deals_with_businesses
					remove_mission = UKR_power_struggle_brautigam_ai_spreads_pro_collab_propaganda
				}
			}
		}
		activate_mission = UKR_power_struggle_factionalism_intensifies
	}
	custom_effect_tooltip = UKR_RK_power_struggle_begin_tt
}

UKR_PS_update_GUI_data = {
	# Industrialists
	set_variable = { UKR_PS_Ohl_IND_disp = UKR_PS_Industrialist^0 }

	set_variable = { UKR_PS_Leib_IND_disp = UKR_PS_Industrialist^0 }
	add_to_variable = { UKR_PS_Leib_IND_disp = UKR_PS_Industrialist^1 }

	set_variable = { UKR_PS_Brau_IND_disp = UKR_PS_Industrialist^0 }
	add_to_variable = { UKR_PS_Brau_IND_disp = UKR_PS_Industrialist^1 }
	add_to_variable = { UKR_PS_Brau_IND_disp = UKR_PS_Industrialist^2 }

	# Bureaucrats
	set_variable = { UKR_PS_Ohl_BUR_disp = UKR_PS_Bureaucrat^0 }

	set_variable = { UKR_PS_Leib_BUR_disp = UKR_PS_Bureaucrat^0 }
	add_to_variable = { UKR_PS_Leib_BUR_disp = UKR_PS_Bureaucrat^1 }

	set_variable = { UKR_PS_Brau_BUR_disp = UKR_PS_Bureaucrat^0 }
	add_to_variable = { UKR_PS_Brau_BUR_disp = UKR_PS_Bureaucrat^1 }
	add_to_variable = { UKR_PS_Brau_BUR_disp = UKR_PS_Bureaucrat^2 }

	# Collaborators
	set_variable = { UKR_PS_Ohl_COL_disp = UKR_PS_Collaborator^0 }

	set_variable = { UKR_PS_Leib_COL_disp = UKR_PS_Collaborator^0 }
	add_to_variable = { UKR_PS_Leib_COL_disp = UKR_PS_Collaborator^1 }

	set_variable = { UKR_PS_Brau_COL_disp = UKR_PS_Collaborator^0 }
	add_to_variable = { UKR_PS_Brau_COL_disp = UKR_PS_Collaborator^1 }
	add_to_variable = { UKR_PS_Brau_COL_disp = UKR_PS_Collaborator^2 }

	# Bureaucrats
	set_variable = { UKR_PS_Ohl_MIL_disp = UKR_PS_Militarist^0 }

	set_variable = { UKR_PS_Leib_MIL_disp = UKR_PS_Militarist^0 }
	add_to_variable = { UKR_PS_Leib_MIL_disp = UKR_PS_Militarist^1 }

	set_variable = { UKR_PS_Brau_MIL_disp = UKR_PS_Militarist^0 }
	add_to_variable = { UKR_PS_Brau_MIL_disp = UKR_PS_Militarist^1 }
	add_to_variable = { UKR_PS_Brau_MIL_disp = UKR_PS_Militarist^2 }

	# Find who owns which section
	clear_array = PS_section_owner

	find_highest_in_array = {
		array = UKR_PS_Industrialist	# PS_section_owner^0 Industralist
		index = indx1
	}
	add_to_array = { PS_section_owner = indx1 }

	find_highest_in_array = {
		array = UKR_PS_Bureaucrat		# PS_section_owner^1 bureaucrat
		index = indx2
	}
	add_to_array = { PS_section_owner = indx2 }

	find_highest_in_array = {
		array = UKR_PS_Collaborator		# PS_section_owner^2 collabs
		index = indx3
	}
	add_to_array = { PS_section_owner = indx3 }

	find_highest_in_array = {
		array = UKR_PS_Militarist		# PS_section_owner^3 military
		index = indx4
	}
	add_to_array = { PS_section_owner = indx4 }

	# Find who has the most sections
	clear_variable = PS_Ohl_section_num
	clear_variable = PS_Leib_section_num
	clear_variable = PS_Brau_section_num
	for_each_loop = {
		array = PS_section_owner
		index = idx
		value = val
		if = {
			limit = {
				OR = {
					AND = {
						NOT = {
							has_game_rule = {
								rule = UKR_POST_KOCH_PATH
								option = UKR_POST_KOCH_PATH_LEIB
							}
							has_game_rule = {
								rule = UKR_POST_KOCH_PATH
								option = UKR_POST_KOCH_PATH_BRAUT
							}
						}
						check_variable = { val = 0 }
					}
					has_game_rule = {
						rule = UKR_POST_KOCH_PATH
						option = UKR_POST_KOCH_PATH_OHLEN
					}
				}
			}
			add_to_variable = { PS_Ohl_section_num = 1 }
		}
		else_if = {
			limit = {
				OR = {
					AND = {
						NOT = {
							has_game_rule = {
								rule = UKR_POST_KOCH_PATH
								option = UKR_POST_KOCH_PATH_OHLEN
							}
							has_game_rule = {
								rule = UKR_POST_KOCH_PATH
								option = UKR_POST_KOCH_PATH_BRAUT
							}
						}
						check_variable = { val = 1 }
					}
					has_game_rule = {
						rule = UKR_POST_KOCH_PATH
						option = UKR_POST_KOCH_PATH_LEIB
					}
				}
			}
			add_to_variable = { PS_Leib_section_num = 1 }
		}
		else_if = {
			limit = {
				OR = {
					AND = {
						NOT = {
							has_game_rule = {
								rule = UKR_POST_KOCH_PATH
								option = UKR_POST_KOCH_PATH_OHLEN
							}
							has_game_rule = {
								rule = UKR_POST_KOCH_PATH
								option = UKR_POST_KOCH_PATH_LEIB
							}
						}
						check_variable = { val = 2 }
					}
					has_game_rule = {
						rule = UKR_POST_KOCH_PATH
						option = UKR_POST_KOCH_PATH_BRAUT
					}
				}
			}
			add_to_variable = { PS_Brau_section_num = 1 }
		}
	}

	add_to_variable = { UKR_Powerstruggle_dirty_var = 0.01 }

	UKR_PS_ideology_setup = yes
}

UKR_PS_Industrialist_update = {
	if = {
		limit = {
			set_temp_variable = { PS_future_IND = UKR_PS_Industrialist^UKR_PS_contender_id }
			add_to_temp_variable = { PS_future_IND = PS_IND_temp }
			check_variable = { var = PS_future_IND value = 0 compare = greater_than_or_equals }
		}
		add_to_variable = { UKR_PS_Industrialist^UKR_PS_contender_id = PS_IND_temp }
		if = {
			limit = {
				check_variable = { PS_IND_temp < 0 }
			}
			multiply_temp_variable = { PS_IND_temp = -1 }
			custom_effect_tooltip = UKR_ind_influence_decrease_tt
			multiply_temp_variable = { PS_IND_temp = -1 }
		}
		else = { custom_effect_tooltip = UKR_ind_influence_increase_tt }

		set_temp_variable = { IND_div = UKR_PS_Industrialist^num }
		subtract_from_temp_variable = { IND_div = 1 }
		divide_temp_variable = { PS_IND_temp = IND_div }

		set_temp_variable = { PS_excess = 0 }
		for_each_loop = {
			array = UKR_PS_Industrialist
			index = idx
			if = {
				limit = {
					NOT = {
						check_variable = { idx = UKR_PS_contender_id }
					}
				}
				subtract_from_variable = { UKR_PS_Industrialist^idx = PS_IND_temp }
			}
			if = {
				limit = { check_variable = { UKR_PS_Industrialist^idx < 0 } }
				add_to_temp_variable = { PS_excess = UKR_PS_Industrialist^idx }
				set_variable = { UKR_PS_Industrialist^idx = 0 }
			}
		}
		add_to_variable = { UKR_PS_Industrialist^UKR_PS_contender_id = PS_excess }
		UKR_PS_update_GUI_data = yes
	}
	else = { custom_effect_tooltip = UKR_PS_IND_lowpoint }
}

UKR_PS_Bureaucrat_update = {
	if = {
		limit = {
			set_temp_variable = { PS_future_BUR = UKR_PS_Bureaucrat^UKR_PS_contender_id }
			add_to_temp_variable = { PS_future_BUR = PS_BUR_temp }
			check_variable = { var = PS_future_BUR value = 0 compare = greater_than_or_equals }
		}
		add_to_variable = { UKR_PS_Bureaucrat^UKR_PS_contender_id = PS_BUR_temp }
		if = {
			limit = {
				check_variable = { PS_BUR_temp < 0 }
			}
			multiply_temp_variable = { PS_BUR_temp = -1 }
			custom_effect_tooltip = UKR_bur_influence_decrease_tt
			multiply_temp_variable = { PS_BUR_temp = -1 }
		}
		else = { custom_effect_tooltip = UKR_bur_influence_increase_tt }

		set_temp_variable = { BUR_div = UKR_PS_Bureaucrat^num }
		subtract_from_temp_variable = { BUR_div = 1 }
		divide_temp_variable = { PS_BUR_temp = BUR_div }

		set_temp_variable = { PS_excess = 0 }
		for_each_loop = {
			array = UKR_PS_Bureaucrat
			index = idx
			if = {
				limit = {
					NOT = {
						check_variable = { idx = UKR_PS_contender_id }
					}
				}
				subtract_from_variable = { UKR_PS_Bureaucrat^idx = PS_BUR_temp }
			}
			if = {
				limit = { check_variable = { UKR_PS_Bureaucrat^idx < 0 } }
				add_to_temp_variable = { PS_excess = UKR_PS_Bureaucrat^idx }
				set_variable = { UKR_PS_Bureaucrat^idx = 0 }
			}
		}
		add_to_variable = { UKR_PS_Bureaucrat^UKR_PS_contender_id = PS_excess }
		UKR_PS_update_GUI_data = yes
	}
	else = { custom_effect_tooltip = UKR_PS_BUR_lowpoint }
}

UKR_PS_Collaborator_update = {
	if = {
		limit = {
			set_temp_variable = { PS_future_COL = UKR_PS_Collaborator^UKR_PS_contender_id }
			add_to_temp_variable = { PS_future_COL = PS_COL_temp }
			check_variable = { var = PS_future_COL value = 0 compare = greater_than_or_equals }
		}
		add_to_variable = { UKR_PS_Collaborator^UKR_PS_contender_id = PS_COL_temp }
		if = {
			limit = {
				check_variable = { PS_COL_temp < 0 }
			}
			multiply_temp_variable = { PS_COL_temp = -1 }
			custom_effect_tooltip = UKR_col_influence_decrease_tt
			multiply_temp_variable = { PS_COL_temp = -1 }
		}
		else = { custom_effect_tooltip = UKR_col_influence_increase_tt }

		set_temp_variable = { COL_div = UKR_PS_Collaborator^num }
		subtract_from_temp_variable = { COL_div = 1 }
		divide_temp_variable = { PS_COL_temp = COL_div }

		set_temp_variable = { PS_excess = 0 }
		for_each_loop = {
			array = UKR_PS_Collaborator
			index = idx
			if = {
				limit = {
					NOT = {
						check_variable = { idx = UKR_PS_contender_id }
					}
				}
				subtract_from_variable = { UKR_PS_Collaborator^idx = PS_COL_temp }
			}
			if = {
				limit = { check_variable = { UKR_PS_Collaborator^idx < 0 } }
				add_to_temp_variable = { PS_excess = UKR_PS_Collaborator^idx }
				set_variable = { UKR_PS_Collaborator^idx = 0 }
			}
		}
		add_to_variable = { UKR_PS_Collaborator^UKR_PS_contender_id = PS_excess }
		UKR_PS_update_GUI_data = yes
	}
	else = { custom_effect_tooltip = UKR_PS_COL_lowpoint }
}

UKR_PS_Militarist_update = {
	if = {
		limit = {
			set_temp_variable = { PS_future_MIL = UKR_PS_Militarist^UKR_PS_contender_id }
			add_to_temp_variable = { PS_future_MIL = PS_MIL_temp }
			check_variable = { var = PS_future_MIL value = 0 compare = greater_than_or_equals }
		}
		add_to_variable = { UKR_PS_Militarist^UKR_PS_contender_id = PS_MIL_temp }
		if = {
			limit = {
				check_variable = { PS_MIL_temp < 0 }
			}
			multiply_temp_variable = { PS_MIL_temp = -1 }
			custom_effect_tooltip = UKR_mil_influence_decrease_tt
			multiply_temp_variable = { PS_MIL_temp = -1 }
		}
		else = { custom_effect_tooltip = UKR_mil_influence_increase_tt }

		set_temp_variable = { MIL_div = UKR_PS_Militarist^num }
		subtract_from_temp_variable = { MIL_div = 1 }
		divide_temp_variable = { PS_MIL_temp = MIL_div }

		set_temp_variable = { PS_excess = 0 }
		for_each_loop = {
			array = UKR_PS_Militarist
			index = idx
			if = {
				limit = {
					NOT = {
						check_variable = { idx = UKR_PS_contender_id }
					}
				}
				subtract_from_variable = { UKR_PS_Militarist^idx = PS_MIL_temp }
			}
			if = {
				limit = { check_variable = { UKR_PS_Militarist^idx < 0 } }
				add_to_temp_variable = { PS_excess = UKR_PS_Militarist^idx }
				set_variable = { UKR_PS_Militarist^idx = 0 }
			}
		}
		add_to_variable = { UKR_PS_Militarist^UKR_PS_contender_id = PS_excess }
		UKR_PS_update_GUI_data = yes
	}
	else = { custom_effect_tooltip = UKR_PS_MIL_lowpoint }
}

# Debugging corner

c_PS_update_industrialist = {
	set_temp_variable = { UKR_PS_contender_id = args^0 }
	set_temp_variable = { PS_IND_temp = args^1 }
	UKR_PS_Industrialist_update = yes
}

c_PS_update_bureaucrat = {
	set_temp_variable = { UKR_PS_contender_id = args^0 }
	set_temp_variable = { PS_BUR_temp = args^1 }
	UKR_PS_Bureaucrat_update = yes
}

c_PS_update_collaborator = {
	set_temp_variable = { UKR_PS_contender_id = args^0 }
	set_temp_variable = { PS_COL_temp = args^1 }
	UKR_PS_Collaborator_update = yes
}

c_PS_update_militarist = {
	set_temp_variable = { UKR_PS_contender_id = args^0 }
	set_temp_variable = { PS_MIL_temp = args^1 }
	UKR_PS_Militarist_update = yes
}

UKR_clamp_UKR_POL_tension = {
	clamp_variable = {
		var = global.UKR_POL_tension
		min = 0
		max = 100
	}
}

####################################
# 3.0.0 - Breadbasket Scripted Effects #
####################################

###################################
### **NEW** New Breadbasket GUI ###
###################################

## ID	Region name		Variable constant
# 202 	- Kiew			-> Kiev_region
# 226	- Mikolajiw		-> Mykolaiv_region
# 1427	- Tschernigow	-> Chernihiv_region
# 1430	- Charkiw		-> Kharkiv_region ### note: this is shitomir/zhytomyr now, not kharkiv ###
# 93	- Wolhynien		-> Volyn_region
# 228	- Lugansk		-> Luhansk_region

### 3.1 - Breadbasket Setup Scripted Effects ###

UKR_bb_startup = {
	set_country_flag = UKR_bb_enabled

	UKR_bb_startup_essential = yes

	### Variables startup ###

	##### Development
	var:Kiev_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 55 }
		set_variable = { exploitation = 80 }
		set_variable = { grain_output = 8 }
	}
	var:Mykolaiv_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 65 }
		set_variable = { exploitation = 75 }
		set_variable = { grain_output = 7 }
	}
	var:Chernihiv_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 50 }
		set_variable = { exploitation = 85 }
		set_variable = { grain_output = 5 }
	}
	var:Kharkiv_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 75 }
		set_variable = { exploitation = 80 }
		set_variable = { grain_output = 6 }
	}
	var:Volyn_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 20 }
		set_variable = { exploitation = 75 }
		set_variable = { grain_output = 5 }
	}
	var:Luhansk_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 60 }
		set_variable = { exploitation = 90 }
		set_variable = { grain_output = 4 }
	}

	# Actions

	add_to_array = { UKR_BB_actions_development_array = token:UKR_BB_D_Action_RK_PreUCW_1 }
	add_to_array = { UKR_BB_actions_development_array = token:UKR_BB_D_Action_RK_PreUCW_2 }
	add_to_array = { UKR_BB_actions_development_array = token:UKR_BB_D_Action_RK_PreUCW_3 }

	add_to_array = { UKR_BB_actions_resistance_array = token:UKR_BB_R_Action_RK_PreUCW_1 }
	add_to_array = { UKR_BB_actions_resistance_array = token:UKR_BB_R_Action_RK_PreUCW_2 }
	add_to_array = { UKR_BB_actions_resistance_array = token:UKR_BB_R_Action_RK_PreUCW_3 }

	resize_array = { array = UKR_BB_actions_development_cooldown size = 20 value = 0 }
	resize_array = { array = UKR_BB_actions_resistance_cooldown size = 20 value = 0 }

	##### Resistance
	set_country_flag = SLOT_0_NAZIS
	set_country_flag = SLOT_1_U_SSR
	set_country_flag = SLOT_2_PG
	set_country_flag = SLOT_3_UPA

	for_each_loop = {
		array = UKR_bb_map_array
		var:v = {
			clear_array = resistance_control
		}
	}
	var:Kiev_region = {
		add_to_array = { resistance_control = 100 }
		add_to_array = { resistance_control = 0 }
		add_to_array = { resistance_control = 0 }
		add_to_array = { resistance_control = 0 }
		set_variable = { desolation = 5 }
	}
	var:Mykolaiv_region = {
		add_to_array = { resistance_control = 95 }
		add_to_array = { resistance_control = 5 }
		add_to_array = { resistance_control = 0 }
		add_to_array = { resistance_control = 0 }
		set_variable = { desolation = 10 }
	}
	var:Chernihiv_region = {
		add_to_array = { resistance_control = 95 }
		add_to_array = { resistance_control = 5 }
		add_to_array = { resistance_control = 0 }
		add_to_array = { resistance_control = 0 }
		set_variable = { desolation = 10 }
	}
	var:Kharkiv_region = {
		add_to_array = { resistance_control = 80 }
		add_to_array = { resistance_control = 5 }
		add_to_array = { resistance_control = 10 }
		add_to_array = { resistance_control = 5 }
		set_variable = { desolation = 15 }
	}
	var:Volyn_region = {
		add_to_array = { resistance_control = 75 }
		add_to_array = { resistance_control = 0 }
		add_to_array = { resistance_control = 10 }
		add_to_array = { resistance_control = 15 }
		set_variable = { desolation = 25 }
	}
	var:Luhansk_region = {
		add_to_array = { resistance_control = 70 }
		add_to_array = { resistance_control = 30 }
		add_to_array = { resistance_control = 0 }
		add_to_array = { resistance_control = 0 }
		set_variable = { desolation = 20 }
	}

	### Dynmod ###
	UKR_bb_national_dynmod_setup_and_vars = yes
	set_variable = { UKR_bb_trade_op_mod = 0.5 }
	set_variable = { UKR_bb_civ_spend_mod = -0.15 }
	set_variable = { UKR_bb_cp_mod = 0.25 }
	add_dynamic_modifier = { modifier = UKR_breadbasket_dynmod }

	### ADD STATE DYNMODS ###
	every_owned_state = {
		add_dynamic_modifier = {
			modifier = UKR_BB_state_dynmod
		}
	}
	UKR_bb_regional_modifiers = yes

	# GERMANIA'S DEMANDS #
	set_country_flag = UKR_bb_consumption_enabled

	set_variable = { UKR_bb_cycle_start_date = global.date }
	set_variable = { UKR_bb_consumption_countdown = 365 }

	UKR_bb_consumption_total_grain_calc = yes
	UKR_bb_consumption_total_dev_calc = yes
	UKR_bb_consumption_local_grain_needs_calc = yes

	## Germania's grain demand

	set_variable = { UKR_BB_Germania_Demand_grain = UKR_total_grain_output }
	multiply_variable = { UKR_BB_Germania_Demand_grain = 0.7 }
	round_variable = UKR_BB_Germania_Demand_grain
	add_to_variable = { UKR_BB_Germania_Demand_grain = 10 }

	## Development level demand
	set_variable = { UKR_BB_Germania_Demand_total_development_level = 9 }

	UKR_bb_consumption_update_gui = yes

	# Consumption Actions #
	add_to_array = { UKR_bb_consumption_actions_array = token:UKR_BB_consumption_request_aid_against_insurgents }
	add_to_array = { UKR_bb_consumption_actions_array = token:UKR_BB_consumption_request_political_aid }
	add_to_array = { UKR_bb_consumption_actions_array = token:UKR_BB_consumption_enforce_food_austerity }
	resize_array = { UKR_bb_consumption_actions_cooldown = 3 }

	## Partisan Stockpile (mainly for debugging purposes)
	set_variable = { UKR_bb_partisan_stockpile_guns = 10000 }
	set_variable = { UKR_bb_partisan_stockpile_manpower = 1000 }
	set_variable = { UKR_bb_partisan_stockpile_money = 100 }

	set_variable = { UKS_uprising_division_exp = 0.2 } #for the action that varys UKS's division exp

	# RESISTANCE ACTIVITIES #
	set_variable = { UKR_partisan_activity_multiplier = modifier@partisan_power }
	add_to_variable = { UKR_partisan_activity_multiplier = 1 }

	set_variable = { UKR_bb_resistance_countdown = 21 }

	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UA_SSR_Active }
	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_PG_Active }
	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPA_Active }

	add_to_array = { UKR_bb_resistance_activities_array_parallel = 1 } # UA SSR
	add_to_array = { UKR_bb_resistance_activities_array_parallel = 2 } # PG
	add_to_array = { UKR_bb_resistance_activities_array_parallel = 3 } # UPA

	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Luhansk_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Volyn_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Volyn_region }

	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }
	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }
	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }

	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }
	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }
	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }

	UKR_BB_resistance_activity_daily_update = yes
	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

UKR_bb_startup_BOV_Klyachivsky = {
	set_country_flag = UKR_bb_enabled

	UKR_bb_startup_essential = yes

	### Variables startup ###

	##### Development
	var:Kiev_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 55 }
		set_variable = { exploitation = 80 }
		set_variable = { grain_output = 8 }
	}
	var:Mykolaiv_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 65 }
		set_variable = { exploitation = 75 }
		set_variable = { grain_output = 7 }
	}
	var:Chernihiv_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 50 }
		set_variable = { exploitation = 85 }
		set_variable = { grain_output = 5 }
	}
	var:Kharkiv_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 75 }
		set_variable = { exploitation = 80 }
		set_variable = { grain_output = 6 }
	}
	var:Volyn_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 20 }
		set_variable = { exploitation = 75 }
		set_variable = { grain_output = 5 }
	}
	var:Luhansk_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 60 }
		set_variable = { exploitation = 90 }
		set_variable = { grain_output = 4 }
	}

	# Actions

	resize_array = { array = UKR_BB_actions_development_cooldown size = 20 value = 0 }
	resize_array = { array = UKR_BB_actions_resistance_cooldown size = 20 value = 0 }

	##### Resistance
	set_country_flag = SLOT_0_UPA_STATE
	set_country_flag = SLOT_1_UPRA_WEST
	set_country_flag = SLOT_2_UPRA_SOUTH
	set_country_flag = SLOT_3_UPRA_EAST

	for_each_loop = {
		array = UKR_bb_map_array
		var:v = {
			clear_array = resistance_control
		}
	}
	var:Kiev_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 10 }
	}
	var:Mykolaiv_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 10 }
	}
	var:Chernihiv_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 10 }
	}
	var:Kharkiv_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 10 }
	}
	var:Volyn_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 10 }
	}
	var:Luhansk_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 10 }
	}

	### Dynmod ###
	UKR_bb_national_dynmod_setup_and_vars = yes
	set_variable = { UKR_bb_trade_op_mod = 0.5 }
	set_variable = { UKR_bb_civ_spend_mod = -0.15 }
	set_variable = { UKR_bb_cp_mod = 0.25 }
	add_dynamic_modifier = { modifier = UKR_breadbasket_dynmod }

	### ADD STATE DYNMODS ###
	every_owned_state = {
		add_dynamic_modifier = {
			modifier = UKR_BB_state_dynmod
		}
	}
	UKR_bb_regional_modifiers = yes

	# RESISTANCE ACTIVITIES #
	set_variable = { UKR_partisan_activity_multiplier = modifier@partisan_power }
	add_to_variable = { UKR_partisan_activity_multiplier = 1 }

	set_variable = { UKR_bb_resistance_countdown = 21 }

	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPRA_West_Active }
	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPRA_South_Active }
	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPRA_East_Active }

	add_to_array = { UKR_bb_resistance_activities_array_parallel = 1 } # UPRA West
	add_to_array = { UKR_bb_resistance_activities_array_parallel = 2 } # UPRA South
	add_to_array = { UKR_bb_resistance_activities_array_parallel = 3 } # UPRA East

	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Volyn_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Volyn_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Luhansk_region }

	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }
	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }
	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }

	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }
	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }
	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }

	UKR_BB_resistance_activity_daily_update = yes
	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

### Communist Breadbasket Setup
UKR_bb_startup_UKS_communists = {
	set_country_flag = UKR_bb_enabled

	UKR_bb_startup_essential = yes

	### Variables startup ###

	##### Development
	var:Kiev_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 25 }
		set_variable = { exploitation = 80 }
		set_variable = { grain_output = 8 }
	}
	var:Mykolaiv_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 15 }
		set_variable = { exploitation = 75 }
		set_variable = { grain_output = 7 }
	}
	var:Chernihiv_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 35 }
		set_variable = { exploitation = 85 }
		set_variable = { grain_output = 5 }
	}
	var:Kharkiv_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 45 }
		set_variable = { exploitation = 80 }
		set_variable = { grain_output = 6 }
	}
	var:Volyn_region = {
		set_variable = { development_level = 1 }
		set_variable = { development = 5 }
		set_variable = { exploitation = 75 }
		set_variable = { grain_output = 5 }
	}
	var:Luhansk_region = {
		set_variable = { development_level = 2 }
		set_variable = { development = 60 }
		set_variable = { exploitation = 90 }
		set_variable = { grain_output = 4 }
	}

	# Actions

	resize_array = { array = UKR_BB_actions_development_cooldown size = 20 value = 0 }
	resize_array = { array = UKR_BB_actions_resistance_cooldown size = 20 value = 0 }

	##### Resistance
	set_country_flag = SLOT_0_UKS_STATE
	set_country_flag = SLOT_1_UKS_WEST
	set_country_flag = SLOT_2_UKS_SOUTH
	set_country_flag = SLOT_3_UKS_EAST

	for_each_loop = {
		array = UKR_bb_map_array
		var:v = {
			clear_array = resistance_control
		}
	}
	var:Kiev_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 55 }
	}
	var:Mykolaiv_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 40 }
	}
	var:Chernihiv_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 60 }
	}
	var:Kharkiv_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 30 }
	}
	var:Volyn_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 75 }
	}
	var:Luhansk_region = {
		add_to_array = { resistance_control = 64 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		add_to_array = { resistance_control = 12 }
		set_variable = { desolation = 20 }
	}

	### Dynmod ###
	UKR_bb_national_dynmod_setup_and_vars = yes
	set_variable = { UKR_bb_trade_op_mod = 0.5 }
	set_variable = { UKR_bb_civ_spend_mod = -0.15 }
	set_variable = { UKR_bb_cp_mod = 0.25 }
	add_dynamic_modifier = { modifier = UKR_breadbasket_dynmod }

	### ADD STATE DYNMODS ###
	every_owned_state = {
		add_dynamic_modifier = {
			modifier = UKR_BB_state_dynmod
		}
	}
	UKR_bb_regional_modifiers = yes

	# RESISTANCE ACTIVITIES #
	set_variable = { UKR_partisan_activity_multiplier = modifier@partisan_power }
	add_to_variable = { UKR_partisan_activity_multiplier = 1 }

	set_variable = { UKR_bb_resistance_countdown = 21 }

	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPRA_West_Active }
	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPRA_South_Active }
	add_to_array = { UKR_bb_resistance_activities_array = token:UKR_BB_Resistance_Activities_UPRA_East_Active }

	add_to_array = { UKR_bb_resistance_activities_array_parallel = 1 } # UPRA West
	add_to_array = { UKR_bb_resistance_activities_array_parallel = 2 } # UPRA South
	add_to_array = { UKR_bb_resistance_activities_array_parallel = 3 } # UPRA East

	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Volyn_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Volyn_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array = var:Luhansk_region }

	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }
	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }
	add_to_array = { UKR_bb_resistance_activities_decisive_threshold_array = 45 }

	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }
	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }
	add_to_array = { UKR_bb_resistance_activities_decisive_max_array = 100 }

	UKR_BB_resistance_activity_daily_update = yes
	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

# Effects that are the same across all tags that use the breadbasket
UKR_bb_startup_essential = {

	add_to_array = { UKR_bb_map_array = 202 }
	add_to_array = { UKR_bb_map_array = 226 }
	add_to_array = { UKR_bb_map_array = 1427 }
	add_to_array = { UKR_bb_map_array = 1430 }
	add_to_array = { UKR_bb_map_array = 93 }
	add_to_array = { UKR_bb_map_array = 227 }

	add_to_array = { UKR_bb_map_x = 183 } # 202
	add_to_array = { UKR_bb_map_y = 55 }

	add_to_array = { UKR_bb_map_x = 203 } # 226
	add_to_array = { UKR_bb_map_y = 150 }

	add_to_array = { UKR_bb_map_x = 225 } # 1427
	add_to_array = { UKR_bb_map_y = 17 }

	add_to_array = { UKR_bb_map_x = 119 } # 1430
	add_to_array = { UKR_bb_map_y = 9 }

	add_to_array = { UKR_bb_map_x = 0 } # 93
	add_to_array = { UKR_bb_map_y = 0 }

	add_to_array = { UKR_bb_map_x = 359 } # 227
	add_to_array = { UKR_bb_map_y = 67 }

	# Region constants
	for_each_loop = {
		array = UKR_bb_map_array
		var:v = {
			clear_array = UKR_bb_states_within_region
		}
	}

	set_variable = { Kiev_region = 202 }
	add_to_array = { Kiev_region:UKR_bb_states_within_region = 202.id }
	add_to_array = { Kiev_region:UKR_bb_states_within_region = 259.id }
	add_to_array = { Kiev_region:UKR_bb_states_within_region = 1428.id }

	202 = { set_variable = { region_var = 202 } }
	259 = { set_variable = { region_var = 202 } }
	1428 = { set_variable = { region_var = 202 } }

	set_variable = { Mykolaiv_region = 226 }
	add_to_array = { Mykolaiv_region:UKR_bb_states_within_region = 226.id }
	add_to_array = { Mykolaiv_region:UKR_bb_states_within_region = 197.id }
	add_to_array = { Mykolaiv_region:UKR_bb_states_within_region = 1426.id }
	add_to_array = { Mykolaiv_region:UKR_bb_states_within_region = 200.id }

	226 = { set_variable = { region_var = 226 } }
	197 = { set_variable = { region_var = 226 } }
	1426 = { set_variable = { region_var = 226 } }
	200 = { set_variable = { region_var = 226 } }

	set_variable = { Chernihiv_region = 1427 }
	add_to_array = { Chernihiv_region:UKR_bb_states_within_region = 1427.id }
	add_to_array = { Chernihiv_region:UKR_bb_states_within_region = 225.id }

	1427 = { set_variable = { region_var = 1427 } }
	225 = { set_variable = { region_var = 1427 } }

	set_variable = { Kharkiv_region = 1430 }
	add_to_array = { Kharkiv_region:UKR_bb_states_within_region = 1430.id }
	add_to_array = { Kharkiv_region:UKR_bb_states_within_region = 201.id }
	add_to_array = { Kharkiv_region:UKR_bb_states_within_region = 773.id }
	add_to_array = { Kharkiv_region:UKR_bb_states_within_region = 1429.id }

	1430 = { set_variable = { region_var = 1430 } }
	201 = { set_variable = { region_var = 1430 } }
	773 = { set_variable = { region_var = 1430 } }
	1429 = { set_variable = { region_var = 1430 } }

	set_variable = { Volyn_region = 93 }
	add_to_array = { Volyn_region:UKR_bb_states_within_region = 93.id }
	add_to_array = { Volyn_region:UKR_bb_states_within_region = 1431.id }
	add_to_array = { Volyn_region:UKR_bb_states_within_region = 199.id }

	93 = { set_variable = { region_var = 93 } }
	1431 = { set_variable = { region_var = 93 } }
	199 = { set_variable = { region_var = 93 } }

	set_variable = { Luhansk_region = 227 }
	add_to_array = { Luhansk_region:UKR_bb_states_within_region = 227.id }
	add_to_array = { Luhansk_region:UKR_bb_states_within_region = 228.id }
	add_to_array = { Luhansk_region:UKR_bb_states_within_region = 218.id }
	add_to_array = { Luhansk_region:UKR_bb_states_within_region = 221.id }

	227 = { set_variable = { region_var = 227 } }
	228 = { set_variable = { region_var = 227 } }
	218 = { set_variable = { region_var = 227 } }
	221 = { set_variable = { region_var = 227 } }

	add_to_array = { dummy = 0 }
	set_variable = { opened_tab = 1 }
	set_variable = { BB_selected_region = 202 }
}

UKR_bb_add_crimea = {
	set_variable = { Crimea_region = 137 }
	add_to_array = { Crimea_region:UKR_bb_states_within_region = 196.id }
	add_to_array = { Crimea_region:UKR_bb_states_within_region = 137.id }
	add_to_array = { Crimea_region:UKR_bb_states_within_region = 1532.id }

	137 = { set_variable = { region_var = 137 } }
	196 = { set_variable = { region_var = 137 } }
	1532 = { set_variable = { region_var = 137 } }

	add_to_array = { UKR_bb_map_array = 137 }
	add_to_array = { UKR_bb_map_x = 263 }
	add_to_array = { UKR_bb_map_y = 229 }

	for_each_loop = {
		array = Crimea_region:UKR_bb_states_within_region
		var:v = {
			add_dynamic_modifier = {
				modifier = UKR_BB_state_dynmod
			}
		}
	}

	add_to_variable = { UKR_BB_DIRTY = 0.01 }

	# Set up resistance and development variables after this scripted effect is executed.
}

UKR_bb_add_galicia = {
	set_variable = { Galicia_region = 91 }

	if = {
		limit = { owns_state = 91 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 91.id }
		91 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 89 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 89.id }
		89 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1394 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1394.id }
		1394 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1388 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1388.id }
		1388 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1387 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1387.id }
		1387 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1391 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1391.id }
		1391 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1392 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1392.id }
		1392 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1393 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1393.id }
		1393 = { set_variable = { region_var = 91 } }
	}
	if = {
		limit = { owns_state = 1390 }
		add_to_array = { Galicia_region:UKR_bb_states_within_region = 1390.id }
		1390 = { set_variable = { region_var = 91 } }
	}

	for_each_loop = {
		array = Galicia_region:UKR_bb_states_within_region
		var:v = {
			add_dynamic_modifier = {
				modifier = UKR_BB_state_dynmod
			}
		}
	}

	add_to_array = { UKR_bb_map_array = 91 }
	add_to_array = { UKR_bb_map_x = -9 }
	add_to_array = { UKR_bb_map_y = 81 }
	add_to_variable = { UKR_BB_DIRTY = 0.01 }

	# Set up resistance and development variables after this scripted effect is executed.
}

UKR_bb_national_dynmod_setup_and_vars = {
	202 = {
		add_to_temp_variable = { national_dynmod_temp_dev = development_level }
		add_to_temp_variable = { national_dynmod_temp_exploitation = exploitation }
		add_to_temp_variable = { national_dynmod_temp_desolation = desolation }
		add_to_temp_variable = { national_dynmod_temp_gov_control = resistance_control^0 }
	}
	226 = {
		add_to_temp_variable = { national_dynmod_temp_dev = development_level }
		add_to_temp_variable = { national_dynmod_temp_exploitation = exploitation }
		add_to_temp_variable = { national_dynmod_temp_desolation = desolation }
		add_to_temp_variable = { national_dynmod_temp_gov_control = resistance_control^0 }
	}
	1427 = {
		add_to_temp_variable = { national_dynmod_temp_dev = development_level }
		add_to_temp_variable = { national_dynmod_temp_exploitation = exploitation }
		add_to_temp_variable = { national_dynmod_temp_desolation = desolation }
		add_to_temp_variable = { national_dynmod_temp_gov_control = resistance_control^0 }
	}
	1430 = {
		add_to_temp_variable = { national_dynmod_temp_dev = development_level }
		add_to_temp_variable = { national_dynmod_temp_exploitation = exploitation }
		add_to_temp_variable = { national_dynmod_temp_desolation = desolation }
		add_to_temp_variable = { national_dynmod_temp_gov_control = resistance_control^0 }
	}
	93 = {
		add_to_temp_variable = { national_dynmod_temp_dev = development_level }
		add_to_temp_variable = { national_dynmod_temp_exploitation = exploitation }
		add_to_temp_variable = { national_dynmod_temp_desolation = desolation }
		add_to_temp_variable = { national_dynmod_temp_gov_control = resistance_control^0 }
	}
	227 = {
		add_to_temp_variable = { national_dynmod_temp_dev = development_level }
		add_to_temp_variable = { national_dynmod_temp_exploitation = exploitation }
		add_to_temp_variable = { national_dynmod_temp_desolation = desolation }
		add_to_temp_variable = { national_dynmod_temp_gov_control = resistance_control^0 }
	}
	divide_temp_variable = { national_dynmod_temp_exploitation = 6 } #get an average. not done for dev level since it's different
	divide_temp_variable = { national_dynmod_temp_desolation = 6 } #get an average. not done for dev level since it's different
	divide_temp_variable = { national_dynmod_temp_gov_control = 6 } #get an average. not done for dev level since it's different
	round_temp_variable = national_dynmod_temp_exploitation #rounding to prevent silly decimal shit
	round_temp_variable = national_dynmod_temp_desolation #rounding to prevent silly decimal shit
	round_temp_variable = national_dynmod_temp_gov_control #rounding to prevent silly decimal shit

	# DEVELOPMENT LEVEL #
	divide_temp_variable = { national_dynmod_temp_dev = 10 } #if you have 10 dev level total across all regions you'll have 1% extra GDP growth
	set_variable = { national_dynmod_dev_gdp = national_dynmod_temp_dev } #for display
	#divide_variable = { national_dynmod_dev_gdp = 100 }

	# EXPLOITATION #
	set_temp_variable = { national_dynmod_temp_exploitation_resources = national_dynmod_temp_exploitation } #exploitation modifies multiple things and it does so differently
	set_temp_variable = { national_dynmod_temp_exploitation_gdp = national_dynmod_temp_exploitation } #exploitation modifies multiple things and it does so differently
	set_temp_variable = { national_dynmod_temp_exploitation_pop = national_dynmod_temp_exploitation } #exploitation modifies multiple things and it does so differently
	divide_temp_variable = { national_dynmod_temp_exploitation_resources = 800 } #division
	divide_temp_variable = { national_dynmod_temp_exploitation_gdp = 150 } #division
	divide_temp_variable = { national_dynmod_temp_exploitation_pop = -1600 } #division

	set_variable = { national_dynmod_exploitation_resources = national_dynmod_temp_exploitation_resources } #for display
	set_variable = { national_dynmod_exploitation_gdp = national_dynmod_temp_exploitation_gdp } #for display
	#divide_variable = { national_dynmod_exploitation_gdp = 100 }
	set_variable = { national_dynmod_exploitation_pop = national_dynmod_temp_exploitation_pop } #for display

	# DESOLATION #
	set_temp_variable = { national_dynmod_temp_desolation_pop = national_dynmod_temp_desolation }
	set_temp_variable = { national_dynmod_temp_desolation_gdp = national_dynmod_temp_desolation }
	set_temp_variable = { national_dynmod_temp_desolation_resources = national_dynmod_temp_desolation }
	set_temp_variable = { national_dynmod_temp_desolation_stability = national_dynmod_temp_desolation }
	divide_temp_variable = { national_dynmod_temp_desolation_pop = -200 } #division
	divide_temp_variable = { national_dynmod_temp_desolation_gdp = -100 } #division
	divide_temp_variable = { national_dynmod_temp_desolation_resources = -200 } #division
	divide_temp_variable = { national_dynmod_temp_desolation_stability = -200 } #division

	set_variable = { national_dynmod_desolation_pop = national_dynmod_temp_desolation_pop } #for display
	set_variable = { national_dynmod_desolation_gdp = national_dynmod_temp_desolation_gdp } #for display
	#divide_variable = { national_dynmod_desolation_gdp = 100 }
	set_variable = { national_dynmod_desolation_resources = national_dynmod_temp_desolation_resources } #for display
	set_variable = { national_dynmod_desolation_stab = national_dynmod_temp_desolation_stability } #for display

	# GOVERNMENT CONTROL #
	subtract_from_temp_variable = { national_dynmod_temp_gov_control = 100 } #for math purposes, figure out what on average the government lacks control-wise
	divide_temp_variable = { national_dynmod_temp_gov_control = 200 } #division

	set_variable = { national_dynmod_gov_control_stab = national_dynmod_temp_gov_control }

	# CALCULATING THE MODIFIER VARS #
	#stability
	set_temp_variable = { UKR_bb_stab_mod_temp = national_dynmod_temp_gov_control }
	add_to_temp_variable = { UKR_bb_stab_mod_temp = national_dynmod_temp_desolation_stability }
	#resources
	set_temp_variable = { UKR_bb_resources_mod_temp = national_dynmod_temp_exploitation_resources }
	add_to_temp_variable = { UKR_bb_resources_mod_temp = national_dynmod_temp_desolation_resources }
	#gdp
	set_temp_variable = { UKR_bb_gdp_mod_temp = national_dynmod_temp_dev }
	add_to_temp_variable = { UKR_bb_gdp_mod_temp = national_dynmod_temp_exploitation_gdp }
	add_to_temp_variable = { UKR_bb_gdp_mod_temp = national_dynmod_temp_desolation_gdp }
	#pop
	set_temp_variable = { UKR_bb_pop_mod_temp = national_dynmod_temp_exploitation_pop }
	add_to_temp_variable = { UKR_bb_pop_mod_temp = national_dynmod_temp_desolation_pop }


	set_variable = { UKR_bb_stab_mod = UKR_bb_stab_mod_temp }
	set_variable = { UKR_bb_resources_mod = UKR_bb_resources_mod_temp }
	set_variable = { UKR_bb_gdp_mod = UKR_bb_gdp_mod_temp }
	#UKR_bb_create_dummy_gdp_value = yes
	set_variable = { UKR_bb_pop_mod = UKR_bb_pop_mod_temp }

	force_update_dynamic_modifier = yes
}

UKR_bb_disable = { #for UCW
	clr_country_flag = UKR_BB_Partisan_Stockpile_active
	clr_country_flag = UKR_bb_enabled # you can't see the mechanic anymore

	# remove state dynmods
	every_owned_state = {
		remove_dynamic_modifier = {
			modifier = UKR_BB_state_dynmod
		}
	}
}

UKR_bb_daily_effects = {
	## Consumption

	if = {
		limit = {
			has_country_flag = UKR_bb_consumption_enabled
		}
		if = {
			limit = {
				NOT = {
					check_variable = { UKR_bb_consumption_countdown = 0 }
					check_variable = { UKR_bb_consumption_countdown < 0 }
				}
			}
			subtract_from_variable = { UKR_bb_consumption_countdown = 1 }
		}
		else = {
			UKR_bb_consumption_complete_consumption_cycle = yes
			set_variable = { UKR_bb_consumption_countdown = 365 }
		}
		UKR_bb_consumption_update_gui = yes

		for_each_loop = {
			array = UKR_bb_consumption_actions_cooldown
			if = {
				limit = {
					check_variable = { v > 0 }
				}
				subtract_from_variable = { UKR_bb_consumption_actions_cooldown^i = 1 }
			}
		}
	}

	## Actions

	for_each_loop = {
		array = UKR_BB_actions_development_cooldown
		if = {
			limit = {
				check_variable = { v > 0 }
			}
			subtract_from_variable = { UKR_BB_actions_development_cooldown^i = 1 }
		}
	}
	for_each_loop = {
		array = UKR_BB_actions_resistance_cooldown
		if = {
			limit = {
				check_variable = { v > 0 }
			}
			subtract_from_variable = { UKR_BB_actions_resistance_cooldown^i = 1 }
		}
	}

	## Resistance activities
	set_variable = { UKR_partisan_activity_multiplier = modifier@partisan_power }
	add_to_variable = { UKR_partisan_activity_multiplier = 1 }

	if = {
		limit = {
			NOT = {
				check_variable = { UKR_bb_resistance_countdown = 0 }
				check_variable = { UKR_bb_resistance_countdown < 0 }
			}
		}
		subtract_from_variable = { UKR_bb_resistance_countdown = 1 }
	}
	else = {
		set_variable = { UKR_bb_resistance_countdown = 21 }
		for_each_loop = {
			array = UKR_bb_resistance_activities_array
			index = r_i
			UKR_BB_resistance_activity_effect_execute = yes
		}
	}
	UKR_BB_resistance_activity_daily_update = yes

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

### 3.2 - Breadbasket Backend Scripted Effects ###

####### RESISTANCE ACTIVITY SCRIPTS

## Hell.

## Array names and what they do:

# UKR_bb_resistance_activities_array
	# -> Main array, contains token of an active resistance group

# UKR_bb_resistance_activities_array_parallel
	# -> Index of the slot from the main gui, see pie chart slots

# UKR_bb_resistance_activities_decisive_region_array
	# -> Array containing the "decisive region" of the resistance group
	# -> Set to 999 to use `UKR_bb_resistance_activities_decisive_region_array_multiple` instead

# UKR_bb_resistance_activities_decisive_threshold_array
	# - >The threshold for the minimum control of the resistance group

# UKR_bb_resistance_activities_decisive_region_array_multiple
	# -> Unique array used for the resistance group that has more than one decisive regions
	# -> Limited to one resistance group at a time

UKR_BB_resistance_activity_daily_update = {
	clear_array = UKR_bb_resistance_activities_decisive_control_array
	for_each_loop = {
		array = UKR_bb_resistance_activities_array_parallel
		value = v
		index = i

		if = {
			limit = {
				check_variable = {
					UKR_bb_resistance_activities_decisive_region_array^i = 999
				}
			}
			set_temp_variable = { temp_control_amt = 0 }
			for_each_loop = {
				array = UKR_bb_resistance_activities_decisive_region_array_multiple
				value = j
				index = k

				add_to_temp_variable = { temp_control_amt = j:resistance_control^v }
			}
			add_to_array = { UKR_bb_resistance_activities_decisive_control_array = temp_control_amt }
		}
		else = {
			set_temp_variable = { decisive_region = UKR_bb_resistance_activities_decisive_region_array^i }
			add_to_array = { UKR_bb_resistance_activities_decisive_control_array = decisive_region:resistance_control^v }
		}
	}
}

UKR_BB_resistance_activity_multiple_region_display = {
	if = {
		limit = {
			check_variable = { region_index < UKR_bb_resistance_activities_decisive_region_array_multiple^num }
		}
		set_temp_variable = { region_to_display = UKR_bb_resistance_activities_decisive_region_array_multiple^region_index }
		custom_effect_tooltip = UKR_BB_Resistance_Activities_decisive_region_multiple_entry

		add_to_temp_variable = { region_index = 1 }
		UKR_BB_resistance_activity_multiple_region_display = yes
	}
}

test_add_RKU = {
	set_variable = { UKR_bb_resistance_activities_array^1 = token:UKR_BB_Resistance_Activities_RK_Active }
	set_variable = { UKR_bb_resistance_activities_array_parallel^1 = 0 }
	set_variable = { UKR_bb_resistance_activities_decisive_region_array^1 = 999 }
	set_variable = { UKR_bb_resistance_activities_decisive_threshold_array^1 = 125 }
	set_variable = { UKR_bb_resistance_activities_decisive_max_array^1 = 300 }
	clear_array = UKR_bb_resistance_activities_decisive_region_array_multiple
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array_multiple = Kiev_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array_multiple = Mykolaiv_region }
	add_to_array = { UKR_bb_resistance_activities_decisive_region_array_multiple = Chernihiv_region }
	UKR_BB_resistance_activity_daily_update = yes
}

UKR_BB_resistance_activity_effect_execute = {
	if = {
		limit = {
			check_variable = {
				UKR_bb_resistance_activities_array^r_i = token:UKR_BB_Resistance_Activities_RK_Active
			}
		}
		if = {
			limit = {
				check_variable = {
					UKR_bb_resistance_activities_decisive_control_array^r_i > UKR_bb_resistance_activities_decisive_threshold_array^r_i
				}
			}
			set_temp_variable = { threshold_exceeded = 1 }
		}
		UKR_BB_resistance_activity_effect_RKU = yes
		set_temp_variable = { threshold_exceeded = 0 }
	}
	else_if = {
		limit = {
			check_variable = {
				UKR_bb_resistance_activities_array^r_i = token:UKR_BB_Resistance_Activities_UA_SSR_Active
			}
		}
		if = {
			limit = {
				check_variable = {
					UKR_bb_resistance_activities_decisive_control_array^r_i > UKR_bb_resistance_activities_decisive_threshold_array^r_i
				}
			}
			set_temp_variable = { threshold_exceeded = 1 }
		}
		UKR_BB_resistance_activity_effect_UA_SSR = yes
		set_temp_variable = { threshold_exceeded = 0 }
	}
	else_if = {
		limit = {
			check_variable = {
				UKR_bb_resistance_activities_array^r_i = token:UKR_BB_Resistance_Activities_PG_Active
			}
		}
		if = {
			limit = {
				check_variable = {
					UKR_bb_resistance_activities_decisive_control_array^r_i > UKR_bb_resistance_activities_decisive_threshold_array^r_i
				}
			}
			set_temp_variable = { threshold_exceeded = 1 }
		}
		UKR_BB_resistance_activity_effect_PG = yes
		set_temp_variable = { threshold_exceeded = 0 }
	}
	else_if = {
		limit = {
			check_variable = {
				UKR_bb_resistance_activities_array^r_i = token:UKR_BB_Resistance_Activities_UPA_Active
			}
		}
		if = {
			limit = {
				check_variable = {
					UKR_bb_resistance_activities_decisive_control_array^r_i > UKR_bb_resistance_activities_decisive_threshold_array^r_i
				}
			}
			set_temp_variable = { threshold_exceeded = 1 }
		}
		UKR_BB_resistance_activity_effect_BOV = yes
		set_temp_variable = { threshold_exceeded = 0 }
	}
}

UKR_BB_resistance_activity_effect_RKU = {
	if = {
		limit = {
			check_variable = { threshold_exceeded = 1 }
		}
		set_temp_variable = { temp_state_pool_0 = Volyn_region }
		set_temp_variable = { temp_state_pool_1 = Kiev_region }
		set_temp_variable = { temp_state_pool_2 = Kharkiv_region }
		set_temp_variable = { temp_state_pool_3 = Chernihiv_region }
		set_temp_variable = { temp_state_pool_4 = Mykolaiv_region }
		set_temp_variable = { temp_state_pool_5 = Luhansk_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = 4.5 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_dev = 1 }
		set_temp_variable = { temp_exp = 0.5 }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
	else = {
		set_temp_variable = { temp_state_pool_0 = Mykolaiv_region }
		set_temp_variable = { temp_state_pool_1 = Chernihiv_region }
		set_temp_variable = { temp_state_pool_2 = Kiev_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_dev = 0.5 }
		set_temp_variable = { temp_exp = 0.5 }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
}

UKR_BB_resistance_activity_effect_PG = {
	if = {
		limit = {
			check_variable = { threshold_exceeded = 1 }
		}
		set_temp_variable = { temp_state_pool_0 = Volyn_region }
		set_temp_variable = { temp_state_pool_1 = Kiev_region }
		set_temp_variable = { temp_state_pool_2 = Kharkiv_region }
		set_temp_variable = { temp_state_pool_3 = Chernihiv_region }
		set_temp_variable = { temp_state_pool_4 = Mykolaiv_region }
		set_temp_variable = { temp_state_pool_5 = Luhansk_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 2 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_exp = -0.5 }

		add_to_temp_variable = { temp_value = modifier@partisan_power_addition }
		multiply_temp_variable = { temp_des = UKR_partisan_activity_multiplier }
		multiply_temp_variable = { temp_exp = UKR_partisan_activity_multiplier }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
	else = {
		set_temp_variable = { temp_state_pool_0 = Volyn_region }
		set_temp_variable = { temp_state_pool_1 = Kharkiv_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 2 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_exp = -0.5 }

		add_to_temp_variable = { temp_value = modifier@partisan_power_addition }
		multiply_temp_variable = { temp_des = UKR_partisan_activity_multiplier }
		multiply_temp_variable = { temp_exp = UKR_partisan_activity_multiplier }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
}

UKR_BB_resistance_activity_effect_UA_SSR = {
	if = {
		limit = {
			check_variable = { threshold_exceeded = 1 }
		}
		set_temp_variable = { temp_state_pool_0 = Volyn_region }
		set_temp_variable = { temp_state_pool_1 = Kiev_region }
		set_temp_variable = { temp_state_pool_2 = Kharkiv_region }
		set_temp_variable = { temp_state_pool_3 = Chernihiv_region }
		set_temp_variable = { temp_state_pool_4 = Mykolaiv_region }
		set_temp_variable = { temp_state_pool_5 = Luhansk_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 1 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_exp = -0.5 }

		add_to_temp_variable = { temp_value = modifier@partisan_power_addition }
		multiply_temp_variable = { temp_des = UKR_partisan_activity_multiplier }
		multiply_temp_variable = { temp_exp = UKR_partisan_activity_multiplier }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
	else = {
		set_temp_variable = { temp_state_pool_0 = Mykolaiv_region }
		set_temp_variable = { temp_state_pool_1 = Chernihiv_region }
		set_temp_variable = { temp_state_pool_2 = Luhansk_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 1 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_exp = -0.5 }

		add_to_temp_variable = { temp_value = modifier@partisan_power_addition }
		multiply_temp_variable = { temp_des = UKR_partisan_activity_multiplier }
		multiply_temp_variable = { temp_exp = UKR_partisan_activity_multiplier }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
}

UKR_BB_resistance_activity_effect_BOV = {
	if = {
		limit = {
			check_variable = { threshold_exceeded = 1 }
		}
		set_temp_variable = { temp_state_pool_0 = Volyn_region }
		set_temp_variable = { temp_state_pool_1 = Kiev_region }
		set_temp_variable = { temp_state_pool_2 = Kharkiv_region }
		set_temp_variable = { temp_state_pool_3 = Chernihiv_region }
		set_temp_variable = { temp_state_pool_4 = Mykolaiv_region }
		set_temp_variable = { temp_state_pool_5 = Luhansk_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 3 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_exp = -0.5 }

		add_to_temp_variable = { temp_value = modifier@partisan_power_addition }
		multiply_temp_variable = { temp_des = UKR_partisan_activity_multiplier }
		multiply_temp_variable = { temp_exp = UKR_partisan_activity_multiplier }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
	else = {
		set_temp_variable = { temp_state_pool_0 = Volyn_region }
		set_temp_variable = { temp_state_pool_1 = Kharkiv_region }
		UKR_bb_D_R_select_a_random_region = yes

		set_temp_variable = { temp_group = 3 }
		set_temp_variable = { temp_value = 3 }
		set_temp_variable = { temp_des = 1 }
		set_temp_variable = { temp_exp = -0.5 }

		add_to_temp_variable = { temp_value = modifier@partisan_power_addition }
		multiply_temp_variable = { temp_des = UKR_partisan_activity_multiplier }
		multiply_temp_variable = { temp_exp = UKR_partisan_activity_multiplier }

		UKR_bb_R_change_control = yes
		UKR_bb_R_change_desolation = yes
		UKR_bb_D_change_development_values = yes

		UKR_bb_D_R_clear_random_region = yes
	}
}

# development/exploitation/grain debuffs from high resistance control #
UKR_bb_resistance_debuffs = {
	set_temp_variable = { temp_dev = -10 }
	set_temp_variable = { temp_exp = -5 }
	set_temp_variable = { temp_grain_output = -1 }
	UKR_bb_D_change_development_values = yes
}

UKR_bb_resistance_demilitarized_zone_logic = {
	if = {
		limit = {
			has_country_flag = UKR_bb_enabled
		}
		hidden_effect = {
			every_owned_state = {
				set_demilitarized_zone = no
			}
			for_each_loop = {
				array = UKR_bb_map_array
				if = {
					limit = {
						check_variable = { v:resistance_control^0 < 50 }
					}

					set_temp_variable = { amount_of_states_demilitarized = 100 }
					subtract_from_temp_variable = { amount_of_states_demilitarized = v:resistance_control^0 }
					subtract_from_temp_variable = { amount_of_states_demilitarized = 50 }
					divide_temp_variable = { amount_of_states_demilitarized = 25 }

					log = "amount_of_states_demilitarized = [?amount_of_states_demilitarized]"
					clamp_temp_variable = { var = amount_of_states_demilitarized min = 0 max = 1 }
					multiply_temp_variable = { amount_of_states_demilitarized = v:UKR_bb_states_within_region^num }
					round_temp_variable = amount_of_states_demilitarized

					log = "amount_of_states_demilitarized = [?amount_of_states_demilitarized]"

					for_each_loop = {
						array = v:UKR_bb_states_within_region
						value = j
						index = k

						set_temp_variable = { current_index = k }
						add_to_temp_variable = { current_index = 1 }
						if = {
							limit = {
								check_variable = {
									var = current_index
									value = amount_of_states_demilitarized
									compare = less_than_or_equals
								}
							}
							var:j = {
								set_demilitarized_zone = yes
							}
						}
					}
				}
			}
		}
	}

}

### 3.3 - Breadbasket Consumption Scripted Effects ###

### GERMANIA'S DEMANDS ###

UKR_bb_consumption_total_grain_calc = {
	set_temp_variable = { output_temp = 0 }
	for_each_loop = {
		array = UKR_bb_map_array
		add_to_temp_variable = { output_temp = v:grain_output }
	}
	set_variable = { UKR_total_grain_output = output_temp }
	UKR_bb_consumption_update_gui = yes

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

UKR_bb_consumption_local_grain_needs_calc = {
	set_temp_variable = { pop_total = max_manpower_k }
	divide_temp_variable = { pop_total = 4000 }
	set_variable = { UKR_BB_local_grain_needs = pop_total }
	round_variable = UKR_BB_local_grain_needs
	UKR_bb_consumption_update_gui = yes

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

UKR_bb_consumption_total_dev_calc = {
	set_temp_variable = { dev_temp = 0 }
	for_each_loop = {
		array = UKR_bb_map_array
		add_to_temp_variable = { dev_temp = v:development_level }
	}
	set_variable = { UKR_total_development = dev_temp }
	UKR_bb_consumption_update_gui = yes

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

# raise/lower need/demand effects #
UKR_bb_consumption_Germania_Demands_dev_demand_alter = {
	add_to_variable = { UKR_BB_Germania_Demand_total_development_level = U }
	clamp_variable = { var = UKR_BB_Germania_Demand_total_development_level min = 0 }
	if = {
		limit = {
			check_variable = { U < 0 }
		}
		multiply_temp_variable = {
			var = U
			value = -1
		}
		custom_effect_tooltip = UKR_bb_Germania_Demands_dev_demand_lower_tt
	}
	else = {
		custom_effect_tooltip = UKR_bb_Germania_Demands_dev_demand_raise_tt
	}
}

UKR_bb_consumption_Germania_Demands_grain_demand_alter = {
	add_to_variable = { UKR_BB_Germania_Demand_grain = U }
	clamp_variable = { var = UKR_BB_Germania_Demand_grain min = 0 }
	if = {
		limit = {
			check_variable = { U < 0 }
		}
		multiply_temp_variable = {
			var = U
			value = -1
		}
		custom_effect_tooltip = UKR_bb_Germania_Demands_grain_demand_lower_tt
	}
	else = {
		custom_effect_tooltip = UKR_bb_Germania_Demands_grain_demand_raise_tt
	}
	UKR_bb_consumption_update_gui = yes
	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

UKR_bb_local_needs_grain_alter = {
	add_to_variable = { UKR_BB_local_grain_needs = U }
	clamp_variable = { var = UKR_BB_local_grain_needs min = 0 }
	if = {
		limit = {
			check_variable = { U < 0 }
		}
		multiply_temp_variable = {
			var = U
			value = -1
		}
		custom_effect_tooltip = UKR_bb_Germania_Demands_grain_need_lower_tt
	}
	else = {
		custom_effect_tooltip = UKR_bb_Germania_Demands_grain_need_raise_tt
	}
	UKR_bb_consumption_update_gui = yes
	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}
# end #

UKR_bb_consumption_update_gui = {
	set_variable = { stockpile_frame = UKR_BB_consumption_grain_STOCKPILE }
	set_variable = { gain_frame = UKR_total_grain_output }
	add_to_variable = { gain_frame = UKR_BB_consumption_grain_STOCKPILE }

	set_variable = { stockpile_total = UKR_BB_consumption_grain_STOCKPILE }
	add_to_variable = { stockpile_total = UKR_total_grain_output }


	set_variable = { grain_demand_frame = UKR_BB_Germania_Demand_grain }
	set_variable = { grain_local_frame = UKR_BB_local_grain_needs }
	add_to_variable = { grain_local_frame = UKR_BB_Germania_Demand_grain }

	set_variable = { demands_total = UKR_BB_Germania_Demand_grain }
	add_to_variable = { demands_total = UKR_BB_local_grain_needs }

	if = {
		limit = {
			OR = {
				check_variable = { stockpile_total > 100 }
				check_variable = { demands_total > 100 }
			}
		}
		set_temp_variable = { divide = 2 }
		divide_temp_variable = { divide = 3 }

		multiply_variable = { stockpile_frame = divide }
		multiply_variable = { gain_frame = divide }
		multiply_variable = { grain_demand_frame = divide }
		multiply_variable = { grain_local_frame = divide }
	}

	set_variable = { stock_total_num_x = gain_frame }
	set_variable = { demand_total_num_x = grain_local_frame }
	multiply_variable = { stock_total_num_x = 2.4 }
	multiply_variable = { demand_total_num_x = 2.4 }
	add_to_variable = { stock_total_num_x = 5 }
	add_to_variable = { demand_total_num_x = 5 }
}

UKR_bb_consumption_complete_consumption_cycle = {

	add_to_variable = { UKR_BB_consumption_grain_STOCKPILE = UKR_total_grain_output }

	set_temp_variable = { stockpile_temp = UKR_BB_consumption_grain_STOCKPILE }
	set_temp_variable = { stockpile_consumed_temp = 0 }

	# The code is seperated between here and UKR_bb_consumption_complete_consumption_cycle_effects for ease of tooltips
	### Germania's grains demand

	# Fulfilled nicely # ( UKR_BB_Germania_Demand_grain + 5 ) =< stockpile
	if = {
		limit = {
			set_temp_variable = { g_check = UKR_BB_Germania_Demand_grain }
			add_to_temp_variable = { g_check = 5 }
			check_variable = {
				var = g_check
				value = stockpile_temp
				compare = less_than_or_equals
			}
		}
		subtract_from_temp_variable = { stockpile_temp = UKR_BB_Germania_Demand_grain }
		add_to_temp_variable = { stockpile_consumed_temp = UKR_BB_Germania_Demand_grain }
		set_country_flag = BB_DEMAND_GRAIN_GREAT
	}
	# Just about fulfilled
	else_if = {
		limit = {
			check_variable = {
				var = stockpile_temp
				value = UKR_BB_Germania_Demand_grain
				compare = greater_than_or_equals
			}
		}
		subtract_from_temp_variable = { stockpile_temp = UKR_BB_Germania_Demand_grain }
		add_to_temp_variable = { stockpile_consumed_temp = UKR_BB_Germania_Demand_grain }
		set_country_flag = BB_DEMAND_GRAIN_OK
	}
	# Not fulfilled
	else = {
		add_to_temp_variable = { stockpile_consumed_temp = stockpile_temp }
		set_temp_variable = { stockpile_temp = 0 }
	}

	### Local grains need

	# Fulfilled nicely # ( UKR_BB_local_grain_needs + 5 ) =< stockpile
	if = {
		limit = {
			set_temp_variable = { l_check = UKR_BB_local_grain_needs }
			add_to_temp_variable = { l_check = 5 }
			check_variable = {
				var = l_check
				value = stockpile_temp
				compare = less_than_or_equals
			}
		}
		subtract_from_temp_variable = { stockpile_temp = UKR_BB_local_grain_needs }
		add_to_temp_variable = { stockpile_consumed_temp = UKR_BB_local_grain_needs }
		set_country_flag = BB_LOCAL_GRAIN_GREAT
	}
	# Just about fulfilled
	else_if = {
		limit = {
			check_variable = {
				var = stockpile_temp
				value = UKR_BB_local_grain_needs
				compare = greater_than_or_equals
			}
		}
		subtract_from_temp_variable = { stockpile_temp = UKR_BB_local_grain_needs }
		add_to_temp_variable = { stockpile_consumed_temp = UKR_BB_local_grain_needs }
		set_country_flag = BB_LOCAL_GRAIN_OK
	}
	# Not fulfilled
	else = {
		add_to_temp_variable = { stockpile_consumed_temp = stockpile_temp }
		set_temp_variable = { stockpile_temp = 0 }
	}
	set_variable = { UKR_BB_consumption_grain_STOCKPILE = stockpile_temp }
	set_variable = { stockpile_consumed = stockpile_consumed_temp }

	### Development expectations

	# Fulfilled nicely # ( UKR_BB_Germania_Demand_total_development_level + 3 ) =< UKR_total_development
	if = {
		limit = {
			set_temp_variable = { dev_check = UKR_BB_Germania_Demand_total_development_level }
			add_to_temp_variable = { dev_check = 3 }
			check_variable = {
				var = dev_check
				value = UKR_total_development
				compare = less_than_or_equals
			}
		}
		set_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_GREAT
	}
	# Just about fulfilled
	else_if = {
		limit = {
			check_variable = {
				var = UKR_total_development
				value = UKR_BB_Germania_Demand_total_development_level
				compare = greater_than_or_equals
			}
		}
		set_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_OK
	}

	set_variable = { UKR_bb_cycle_end_date = global.date }
	country_event = UKR.consumption_cycle
	set_variable = { UKR_bb_cycle_start_date = global.date }
}

UKR_bb_consumption_complete_consumption_cycle_effects = {
	# Ordered from bad to good - anticheat precautions

	if = {
		limit = {
			NOT = {
				has_country_flag = BB_DEMAND_GRAIN_GREAT
				has_country_flag = BB_DEMAND_GRAIN_OK
			}
		}
		custom_effect_tooltip = UKR_consumption_cycle_germania_grain_demand_bad

		add_political_power = -200
		add_stability = -0.15
		add_war_support = -0.15
	}
	else_if = {
		limit = {
			has_country_flag = BB_DEMAND_GRAIN_OK
		}
		custom_effect_tooltip = UKR_consumption_cycle_germania_grain_demand_ok

		add_political_power = 10
		add_stability = 0.005
		add_war_support = 0.005
	}
	else = {
		custom_effect_tooltip = UKR_consumption_cycle_germania_grain_demand_great

		add_political_power = 100
		add_stability = 0.05
		add_war_support = 0.05
	}

	if = {
		limit = {
			NOT = {
				has_country_flag = BB_LOCAL_GRAIN_GREAT
				has_country_flag = BB_LOCAL_GRAIN_OK
			}
		}
		custom_effect_tooltip = UKR_consumption_cycle_local_grain_need_bad

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { temp_all_group = 0 }
		set_temp_variable = { temp_all_value = -4.5 }
		UKR_bb_R_change_control_all = yes
		set_temp_variable = { temp_all_des = 10 }
		UKR_bb_R_change_desolation_all = yes
	}
	else_if = {
		limit = {
			has_country_flag = BB_LOCAL_GRAIN_OK
		}
		custom_effect_tooltip = UKR_consumption_cycle_local_grain_need_ok

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { temp_all_group = 0 }
		set_temp_variable = { temp_all_value = 0.9 }
		UKR_bb_R_change_control_all = yes
		set_temp_variable = { temp_all_des = -2 }
		UKR_bb_R_change_desolation_all = yes
	}
	else = {
		custom_effect_tooltip = UKR_consumption_cycle_local_grain_need_great

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { temp_all_group = 0 }
		set_temp_variable = { temp_all_value = 3 }
		UKR_bb_R_change_control_all = yes
		set_temp_variable = { temp_all_des = -5 }
		UKR_bb_R_change_desolation_all = yes
	}

	if = {
		limit = {
			NOT = {
				has_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_GREAT
				has_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_OK
			}
		}
		custom_effect_tooltip = UKR_consumption_cycle_development_demand_bad

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { gdp_growth_temp = -0.5 }
		econ_gdp_growth_change = yes
	}
	else_if = {
		limit = {
			has_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_OK
		}
		custom_effect_tooltip = UKR_consumption_cycle_development_demand_ok
		set_temp_variable = { U = 1 }
		UKR_bb_consumption_Germania_Demands_dev_demand_alter = yes

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { gdp_growth_temp = 0.1 }
		econ_gdp_growth_change = yes
	}
	else = {
		custom_effect_tooltip = UKR_consumption_cycle_development_demand_great
		set_temp_variable = { U = 2 }
		UKR_bb_consumption_Germania_Demands_dev_demand_alter = yes

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { gdp_growth_temp = 0.33 }
		econ_gdp_growth_change = yes
	}
}

UKR_bb_consumption_complete_consumption_cycle_effects_partisan = {
	# Ordered from bad to good - anticheat precautions

	if = {
		limit = {
			NOT = {
				has_country_flag = BB_DEMAND_GRAIN_GREAT
				has_country_flag = BB_DEMAND_GRAIN_OK
			}
		}
		custom_effect_tooltip = UKR_consumption_cycle_germania_grain_demand_bad

		add_political_power = 100
		add_stability = -0.15
		add_war_support = -0.15
	}
	else_if = {
		limit = {
			has_country_flag = BB_DEMAND_GRAIN_OK
		}
		custom_effect_tooltip = UKR_consumption_cycle_germania_grain_demand_ok

		add_political_power = 25
		add_stability = -0.005
		add_war_support = -0.005
	}
	else = {
		custom_effect_tooltip = UKR_consumption_cycle_germania_grain_demand_great

		add_political_power = -100
		add_stability = 0.05
		add_war_support = 0.05
	}

	if = {
		limit = {
			NOT = {
				has_country_flag = BB_LOCAL_GRAIN_GREAT
				has_country_flag = BB_LOCAL_GRAIN_OK
			}
		}
		custom_effect_tooltip = UKR_consumption_cycle_local_grain_need_bad

		if = {
			limit = {
				has_country_flag = UKR_play_BOV
			}
			BOV = {
				add_stability = 0.2
				add_war_support = 0.2
				add_manpower = 20000
			}
			set_temp_variable = { temp_all_group = 3 }
			set_temp_variable = { temp_all_value = 4.5 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = 10 }
			UKR_bb_R_change_desolation_all = yes
		}

		else_if = {
			limit = {
				has_country_flag = UKR_play_UKS
			}
			UKS = {
				add_stability = 0.2
				add_war_support = 0.2
				add_manpower = 20000
			}
			set_temp_variable = { temp_all_group = 1 }
			set_temp_variable = { temp_all_value = 4.5 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = 10 }
			UKR_bb_R_change_desolation_all = yes
		}

		if = {
			limit = {
				has_country_flag = UKR_play_FUK
			}
			FUK = {
				add_stability = 0.2
				add_war_support = 0.2
				add_manpower = 20000
			}
			set_temp_variable = { temp_all_group = 2 }
			set_temp_variable = { temp_all_value = 4.5 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = 10 }
			UKR_bb_R_change_desolation_all = yes
		}

	}
	else_if = {
		limit = {
			has_country_flag = BB_LOCAL_GRAIN_OK
		}
		custom_effect_tooltip = UKR_consumption_cycle_local_grain_need_ok

		if = {
			limit = {
				has_country_flag = UKR_play_BOV
			}
			BOV = {
				add_stability = 0.05
				add_war_support = 0.05
				add_manpower = 5000
			}
			set_temp_variable = { temp_all_group = 3 }
			set_temp_variable = { temp_all_value = 0.9 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = 2 }
			UKR_bb_R_change_desolation_all = yes
		}

		else_if = {
			limit = {
				has_country_flag = UKR_play_UKS
			}
			UKS = {
				add_stability = 0.05
				add_war_support = 0.05
				add_manpower = 5000
			}
			set_temp_variable = { temp_all_group = 1 }
			set_temp_variable = { temp_all_value = 0.9 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = 2 }
			UKR_bb_R_change_desolation_all = yes
		}

		else = {
			FUK = {
				add_stability = 0.05
				add_war_support = 0.05
				add_manpower = 5000
			}
			set_temp_variable = { temp_all_group = 2 }
			set_temp_variable = { temp_all_value = 0.9 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = 2 }
			UKR_bb_R_change_desolation_all = yes
		}
	}
	else = {
		custom_effect_tooltip = UKR_consumption_cycle_local_grain_need_great

		if = {
			limit = {
				has_country_flag = UKR_play_BOV
			}
			BOV = {
				add_stability = -0.05
				add_war_support = -0.05
				add_manpower = -5000
			}
			set_temp_variable = { temp_all_group = 3 }
			set_temp_variable = { temp_all_value = -3 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = -5 }
			UKR_bb_R_change_desolation_all = yes
		}

		else_if = {
			limit = {
				has_country_flag = UKR_play_UKS
			}
			UKS = {
				add_stability = -0.05
				add_war_support = -0.05
				add_manpower = -5000
			}
			set_temp_variable = { temp_all_group = 1 }
			set_temp_variable = { temp_all_value = -3 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = -5 }
			UKR_bb_R_change_desolation_all = yes
		}

		else = {
			FUK = {
				add_stability = -0.05
				add_war_support = -0.05
				add_manpower = -5000
			}
			set_temp_variable = { temp_all_group = 2 }
			set_temp_variable = { temp_all_value = -3 }
			UKR_bb_R_change_control_all = yes
			set_temp_variable = { temp_all_des = -5 }
			UKR_bb_R_change_desolation_all = yes
		}
	}

	if = {
		limit = {
			NOT = {
				has_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_GREAT
				has_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_OK
			}
		}
		custom_effect_tooltip = UKR_consumption_cycle_development_demand_bad

		UKR = {
			add_stability = -0.1
			add_war_support = -0.1
		}

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { gdp_growth_temp = -0.5 }
		econ_gdp_growth_change = yes
	}
	else_if = {
		limit = {
			has_country_flag = BB_DEVELOPMENT_LEVEL_EXPECTATIONS_OK
		}
		custom_effect_tooltip = UKR_consumption_cycle_development_demand_ok
		set_temp_variable = { U = 1 }
		UKR_bb_consumption_Germania_Demands_dev_demand_alter = yes

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { gdp_growth_temp = 0.1 }
		econ_gdp_growth_change = yes
	}
	else = {
		custom_effect_tooltip = UKR_consumption_cycle_development_demand_great
		set_temp_variable = { U = 2 }
		UKR_bb_consumption_Germania_Demands_dev_demand_alter = yes

		custom_effect_tooltip = UKR_bb_national_dynmod_change_tt
		set_temp_variable = { gdp_growth_temp = 0.33 }
		econ_gdp_growth_change = yes
	}
}

UKR_bb_consumption_cycle_dynmod_add = {
	set_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_extra_temp = UKR_total_grain_output }
	subtract_from_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_extra_temp = UKR_BB_Germania_Demand_grain }
	subtract_from_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_extra_temp = UKR_BB_local_grain_needs }
	if = {
		limit = {
			check_variable = { UKR_BB_consumption_cycle_profits_gdp_extra_temp < 0 }
		}
		set_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_extra_temp = 0 }
	}
	divide_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_extra_temp = 25 }

	set_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_temp = UKR_total_grain_output }
	divide_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_temp = 50 }

	set_variable = { UKR_BB_consumption_cycle_profits_gdp = UKR_BB_consumption_cycle_profits_gdp_temp }
	add_to_variable = { UKR_BB_consumption_cycle_profits_gdp = UKR_BB_consumption_cycle_profits_gdp_extra_temp }

	set_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_display = UKR_BB_consumption_cycle_profits_gdp_temp }
	add_to_temp_variable = { UKR_BB_consumption_cycle_profits_gdp_display = UKR_BB_consumption_cycle_profits_gdp_extra_temp }

	set_temp_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp = UKR_total_grain_output }
	subtract_from_temp_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp = UKR_BB_Germania_Demand_grain }
	subtract_from_temp_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp = UKR_BB_local_grain_needs }
	if = {
		limit = {
			check_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp < 0 }
		}
		set_temp_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp = 0 }
	}
	multiply_temp_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp = 10 }
	divide_temp_variable = { UKR_BB_consumption_cycle_profits_income_extra_temp = 1000 }

	set_temp_variable = { UKR_BB_consumption_cycle_profits_income_temp = UKR_total_grain_output }
	multiply_temp_variable = { UKR_BB_consumption_cycle_profits_income_temp = 5 }
	divide_temp_variable = { UKR_BB_consumption_cycle_profits_income_temp = 1000 }

	set_variable = { UKR_BB_consumption_cycle_profits_income = UKR_BB_consumption_cycle_profits_income_temp }
	add_to_variable = { UKR_BB_consumption_cycle_profits_income = UKR_BB_consumption_cycle_profits_income_extra_temp }

	set_temp_variable = { UKR_BB_consumption_cycle_profits_income_display = UKR_BB_consumption_cycle_profits_income_temp }
	add_to_temp_variable = { UKR_BB_consumption_cycle_profits_income_display = UKR_BB_consumption_cycle_profits_income_extra_temp }

	hidden_effect = {
		add_timed_idea = {
			idea = UKR_breadbasket_of_the_reich_consumption_cycle
			days = 120
		}
		add_dynamic_modifier = {
			modifier = UKR_BB_consumption_cycle_profits
		}
		country_event = {
			id = UKR_consumption_cycle.100
			days = 120
		}
	}
	custom_effect_tooltip = UKR_consumption_cycle_dynmod_add_tt
}

### 3.4 - Breadbasket Dynamic Modifier Scripted Effects

UKR_bb_regional_modifiers = { #set up dynmod vars

	for_each_loop = {
		array = UKR_bb_map_array
		value = v

		var:v = {
			set_temp_variable = { UKR_BB_state_dynmod_growth_calc = development_level } # take the dev level of the region id state and apply it to all states in the region
			multiply_temp_variable = { UKR_BB_state_dynmod_growth_calc = 2.5 } # a little multiplication
			divide_temp_variable = { UKR_BB_state_dynmod_growth_calc = 50 } # a little division

			set_temp_variable = { UKR_BB_state_dynmod_building_slots_calc = development_level } # take the dev level of the region id state and apply it to all states in the region
			divide_temp_variable = { UKR_BB_state_dynmod_building_slots_calc = 20 } # a little division

			set_temp_variable = { UKR_BB_state_dynmod_resources_calc = exploitation } # take the exploitation of the region id state and apply it to all states in the region
			divide_temp_variable = { UKR_BB_state_dynmod_resources_calc = 500 } # a little division

			set_temp_variable = { UKR_BB_state_population_growth_calc = exploitation } # take the exploitation of the region id state and apply it to all states in the region
			divide_temp_variable = { UKR_BB_state_population_growth_calc = 500 } # a little division
			multiply_temp_variable = { UKR_BB_state_population_growth_calc = -1 }

			set_temp_variable = { UKR_state_dynmod_desolation_growth_reduction = desolation } # take the desolation of the region id state and apply it to all states in the region
			divide_temp_variable = { UKR_state_dynmod_desolation_growth_reduction = 500 } # a little division
			multiply_temp_variable = { UKR_state_dynmod_desolation_growth_reduction = -1 } # a little multiplication

			set_temp_variable = { UKR_state_dynmod_desolation_pop_growth_reduction = desolation } # take the desolation of the region id state and apply it to all states in the region
			divide_temp_variable = { UKR_state_dynmod_desolation_pop_growth_reduction = 500 } # a little division
			multiply_temp_variable = { UKR_state_dynmod_desolation_pop_growth_reduction = -0.1 } # a little multiplication

			set_temp_variable = { UKR_state_dynmod_desolation_resources_reduction = desolation } # take the desolation of the region id state and apply it to all states in the region
			divide_temp_variable = { UKR_state_dynmod_desolation_resources_reduction = 500 } # a little division
			multiply_temp_variable = { UKR_state_dynmod_desolation_resources_reduction = -1 } # a little multiplication

			add_to_temp_variable = { UKR_BB_state_dynmod_growth_calc = UKR_state_dynmod_desolation_growth_reduction } # subtract growth by desolation
			add_to_temp_variable = { UKR_BB_state_dynmod_resources_calc = UKR_state_dynmod_desolation_resources_reduction } # subtract resources by desolation
			add_to_temp_variable = { UKR_BB_state_population_growth_calc = UKR_state_dynmod_desolation_pop_growth_reduction } # add the pop growth malus of desolation with the pop growth malus of desolation

			for_each_loop = {
				array = UKR_bb_states_within_region
				value = b

				var:b = {
					set_variable = { UKR_BB_state_dynmod_resources = UKR_BB_state_dynmod_resources_calc }
					set_variable = { UKR_BB_state_dynmod_growth = UKR_BB_state_dynmod_growth_calc }
					set_variable = { UKR_BB_state_dynmod_building_slots = UKR_BB_state_dynmod_building_slots_calc }
					set_variable = { UKR_BB_state_population_growth = UKR_BB_state_population_growth_calc }
					force_update_dynamic_modifier = yes
				}
			}
		}
	}
}

UKR_bb_create_dummy_gdp_value = {
	set_variable = { UKR_bb_gdp_mod_dummy = UKR_bb_gdp_mod }
	divide_variable = { UKR_bb_gdp_mod_dummy = 100 }
}

####### NATIONAL DYNMOD SCRIPTS
### How to use:
# FIRST USE THE CUSTOM TOOLTIP
# custom_effect_tooltip = UKR_bb_national_dynmod_change_tt

UKR_bb_national_dynmod_civ_spend = {
	custom_effect_tooltip = UKR_bb_national_dynmod_civ_spend_tt
	add_to_variable = { UKR_bb_civ_spend_mod = U }
	force_update_dynamic_modifier = yes
}

UKR_bb_national_dynmod_cp = {
	custom_effect_tooltip = UKR_bb_national_dynmod_cp_tt
	add_to_variable = { UKR_bb_cp_mod = U }
	force_update_dynamic_modifier = yes
}

### 3.5 - Breadbasket Actions Scripted Effects ###

#######################
#### ACTIONS STUFF ####
#######################

UKR_bb_actions_dev_clean_slate = {
	clear_array = UKR_BB_actions_development_array
	clear_array = UKR_BB_actions_development_cooldown
	resize_array = { array = UKR_BB_actions_development_cooldown size = 20 value = 0 }
}

UKR_bb_actions_res_clean_slate = {
	clear_array = UKR_BB_actions_resistance_array
	clear_array = UKR_BB_actions_resistance_cooldown
	resize_array = { array = UKR_BB_actions_resistance_cooldown size = 20 value = 0 }
}

## Consumption actions

UKR_bb_consumption_actions_execute = {
	if = {
		limit = {
			check_variable = { v = token:UKR_BB_consumption_request_aid_against_insurgents }
		}
		add_political_power = -50
		add_command_power = 40
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = 2000
			producer = UKR
		}
	}
	else_if = {
		limit = {
			check_variable = { v = token:UKR_BB_consumption_request_political_aid }
		}
		add_political_power = 75
		set_temp_variable = { U = 2 }
		UKR_bb_consumption_Germania_Demands_grain_demand_alter = yes
	}
	else_if = {
		limit = {
			check_variable = { v = token:UKR_BB_consumption_enforce_food_austerity }
		}
		add_political_power = -100
		set_temp_variable = { U = -2 }
		UKR_bb_local_needs_grain_alter = yes
		add_stability = -0.1
		set_temp_variable = { temp_all_group = 0 }
		set_temp_variable = { temp_all_value = -2.1 }
		UKR_bb_R_change_control_all = yes
	}
	set_variable = { UKR_bb_consumption_actions_cooldown^i = 30 }
}

### Add/remove actions

UKR_bb_actions_add_dev_action = {
	custom_effect_tooltip = UKR_BB_Action_add_dev
	add_to_array = { UKR_BB_actions_development_array = temp_action }
	for_each_loop = {
		array = UKR_BB_actions_development_array
		break = break
		if = {
			limit = {
				check_variable = { v = temp_action }
			}
			add_to_array = { array = UKR_BB_actions_development_cooldown index = i value = 0 }
			set_temp_variable = { break = 1 }
		}
	}
}

d_UKR_bb_actions_add_dev_action = {
	set_temp_variable = { temp_action = args^0 }
	UKR_bb_actions_add_dev_action = yes
}

UKR_bb_actions_add_res_action = {
	custom_effect_tooltip = UKR_BB_Action_add_res
	add_to_array = { UKR_BB_actions_resistance_array = temp_action }
	for_each_loop = {
		array = UKR_BB_actions_resistance_array
		break = break
		if = {
			limit = {
				check_variable = { v = temp_action }
			}
			add_to_array = { array = UKR_BB_actions_resistance_cooldown index = i value = 0 }
			set_temp_variable = { break = 1 }
		}
	}
}

d_UKR_bb_actions_add_res_action = {
	set_temp_variable = { temp_action = args^0 }
	UKR_bb_actions_add_res_action = yes
}

UKR_bb_actions_remove_dev_action = {
	custom_effect_tooltip = UKR_BB_Action_rem_dev
	for_each_loop = {
		array = UKR_BB_actions_development_array
		break = break
		if = {
			limit = {
				check_variable = { v = temp_action }
			}
			remove_from_array = { array = UKR_BB_actions_development_cooldown index = i }
			set_temp_variable = { break = 1 }
		}
	}
	remove_from_array = { UKR_BB_actions_development_array = temp_action }
}

d_UKR_bb_actions_remove_dev_action = {
	set_temp_variable = { temp_action = args^0 }
	UKR_bb_actions_remove_dev_action = yes
}

UKR_bb_actions_remove_res_action = {
	custom_effect_tooltip = UKR_BB_Action_rem_res
	for_each_loop = {
		array = UKR_BB_actions_resistance_array
		break = break
		if = {
			limit = {
				check_variable = { v = temp_action }
			}
			remove_from_array = { array = UKR_BB_actions_resistance_cooldown index = i }
			set_temp_variable = { break = 1 }
		}
	}
	remove_from_array = { UKR_BB_actions_resistance_array = temp_action }
}

d_UKR_bb_actions_remove_res_action = {
	set_temp_variable = { temp_action = args^0 }
	UKR_bb_actions_remove_res_action = yes
}

UKR_bb_resistance_stockpile_increment = { #weekly gain
	add_to_variable = { UKR_bb_partisan_stockpile_manpower = UKR_bb_stockpile_manpower_gain }
	add_to_variable = { UKR_bb_partisan_stockpile_guns = UKR_bb_stockpile_guns_gain }
}

UKR_bb_d_actions_execute= {

	### RK PRE-UCW

	if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_RK_PreUCW_1 }
		}
		add_political_power = -15
		set_temp_variable = { temp_econ_spending_amount = 0.025 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = 5 }
		set_temp_variable = { temp_grain_output = 1 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 1.015 }
			econ_state_value_change_multiply = yes
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_RK_PreUCW_2 }
		}
		add_political_power = -25
		set_temp_variable = { temp_econ_spending_amount = 0.03 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = 10 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 1.025 }
			econ_state_value_change_multiply = yes
			add_state_modifier = {
				modifier = {
					state_GDP_growth_factor_modifier = 0.025
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_RK_PreUCW_3 }
		}
		add_political_power = -40

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = 5 }
		set_temp_variable = { temp_exp = 5 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_state_modifier = {
				modifier = {
					state_GDP_growth_factor_modifier = 0.01
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_RK_PreUCW_4 }
		}
		add_political_power = -15

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_exp = 5 }
		UKR_bb_D_change_development_values = yes
		hidden_effect = {
			set_temp_variable_to_random = {
				var = casualties
				min = 50
				max = 100
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_RK_PreUCW_5 }
		}
		add_political_power = -30
		set_temp_variable = { temp_econ_spending_amount = 0.05 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = 20 }
		set_temp_variable = { temp_exp = 5 }
		set_temp_variable = { temp_grain_output = 1 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_state_modifier = {
				modifier = {
					state_GDP_growth_factor_modifier = 0.02
				}
			}
		}
	}

	### UNRA PRE-UCW

	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_PG_PreUCW_1 }
		}
		add_political_power = -20

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region } #values meant to be on the low end for resistance dev actions
		set_temp_variable = { temp_exp = -3 }
		set_temp_variable = { temp_grain_output = -1 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.999 }
			econ_state_value_change_multiply = yes
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_PG_PreUCW_2 }
		}
		add_political_power = -40
		add_command_power = -10

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = -5 }
		set_temp_variable = { temp_exp = -8 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.998 }
			econ_state_value_change_multiply = yes
			add_state_modifier = {
				modifier = {
					state_GDP_growth_factor_modifier = -0.01
				}
			}
		}

		FUK = {
			add_manpower = 1000
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_PG_PreUCW_3 }
		}
		add_political_power = -20

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = -5 }
		set_temp_variable = { temp_exp = -8 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.998 }
			econ_state_value_change_multiply = yes
		}
	}

	### UA-SSR PRE-UCW

	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_UA_SSR_PreUCW_1 }
		}
		add_political_power = -5
		add_command_power = -5

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region } #values meant to be on the low end for resistance dev actions
		set_temp_variable = { temp_exp = -3 }
		set_temp_variable = { temp_grain_output = -1 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.999 }
			econ_state_value_change_multiply = yes
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_UA_SSR_PreUCW_2 }
		}
		add_political_power = -10
		add_command_power = -30

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = -5 }
		set_temp_variable = { temp_exp = -8 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.998 }
			econ_state_value_change_multiply = yes
			add_state_modifier = {
				modifier = {
					state_GDP_growth_factor_modifier = -0.01
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_UA_SSR_PreUCW_3 }
		}
		add_political_power = -5
		add_command_power = -5

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = -5 }
		set_temp_variable = { temp_exp = -8 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.998 }
			econ_state_value_change_multiply = yes
		}
	}

	### UPA PRE-UCW

	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_UPA_PreUCW_1 }
		}
		add_political_power = -5
		add_command_power = -5

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region } #values meant to be on the low end for resistance dev actions
		set_temp_variable = { temp_exp = -3 }
		set_temp_variable = { temp_grain_output = -1 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.999 }
			econ_state_value_change_multiply = yes
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_UPA_PreUCW_2 }
		}
		add_political_power = -10
		add_command_power = -30

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = -5 }
		set_temp_variable = { temp_exp = -8 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.998 }
			econ_state_value_change_multiply = yes
			add_state_modifier = {
				modifier = {
					state_GDP_growth_factor_modifier = -0.01
				}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { d_action_val = token:UKR_BB_D_Action_UPA_PreUCW_3 }
		}
		add_political_power = -5
		add_command_power = -5

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_dev = -5 }
		set_temp_variable = { temp_exp = -8 }
		UKR_bb_D_change_development_values = yes
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.998 }
			econ_state_value_change_multiply = yes
		}
	}
}

UKR_bb_r_actions_execute = {

	### RK PRE-UCW

	if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_1 }
		}
		add_political_power = -10
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = -300
			producer = UKR
		}
		set_temp_variable = { temp_econ_spending_amount = 0.010 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = 2 }
		UKR_bb_R_change_control = yes

		TNO_improve_security_policy_effectiveness_low = yes
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_2 }
		}
		add_command_power = -15
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = -100
			producer = UKR
		}
		add_manpower = -50

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = 3.5 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 1 }
		UKR_bb_R_change_desolation = yes

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { state_value_multiplier_temp = 0.999 }
			econ_state_value_change_multiply = yes
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_3 }
		}
		add_command_power = -20
		set_temp_variable = { temp_econ_spending_amount = 0.003 }
		econ_spend_money_once_effect_raw_money = yes
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = -250
			producer = UKR
		}
		add_manpower = -150

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		random_list = {
			80 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 0 }
				set_temp_variable = { temp_value = 5 }
				UKR_bb_R_change_control = yes
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_des = 5 }
				UKR_bb_R_change_desolation = yes
			}
			15 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_des = 4 }
				UKR_bb_R_change_desolation = yes
			}
			5 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 0 }
				set_temp_variable = { temp_value = -2.5 }
				UKR_bb_R_change_control = yes
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_des = 5 }
				UKR_bb_R_change_desolation = yes
			}
		}
		hidden_effect = { #casualties
			set_temp_variable_to_random = {
				var = casualties
				min = 140
				max = 350
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
			set_temp_variable = { state_value_multiplier_temp = 0.995 }
			econ_state_value_change_multiply = yes
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_4 }
		}
		add_political_power = -20
		add_command_power = -40
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = -400
			producer = UKR
		}
		set_temp_variable = { temp_econ_spending_amount = 0.01 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = 8.5 }
		UKR_bb_R_change_control = yes

		hidden_effect = { #raid casualties
			set_temp_variable_to_random = {
				var = casualties
				min = 20
				max = 150
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_5 }
		}
		add_political_power = -25
		add_command_power = -20
		set_temp_variable = { temp_econ_spending_amount = 0.002 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = -5.5 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = 202 }
		set_temp_variable = { temp_group = 0 }
		set_temp_variable = { temp_value = 10.0 }
		UKR_bb_R_change_control = yes
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_6 }
		}
		add_command_power = -10
		add_equipment_to_stockpile = {
			type = infantry_equipment
			amount = -500
			producer = UKR
		}

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 12.0 }
		UKR_bb_R_change_desolation = yes

		set_temp_variable = { UKR_PS_contender_id = 0 }
		set_temp_variable = { PS_MIL_temp = 4 }
		UKR_PS_Militarist_update = yes

		hidden_effect = { #casualties
			set_temp_variable_to_random = {
				var = casualties
				min = 100
				max = 450
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}
		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
			set_temp_variable = { state_value_multiplier_temp = 0.995 }
			econ_state_value_change_multiply = yes
		}

		random_list = {
			80 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 0 }
				set_temp_variable = { temp_value = 5.0 }
				UKR_bb_R_change_control = yes
			}
			20 = {}
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_RK_PreUCW_7 }
		}
		add_political_power = -25
		add_command_power = -10
		set_temp_variable = { temp_econ_spending_amount = 0.002 }
		econ_spend_money_once_effect_raw_money = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = -5.0 }
		UKR_bb_R_change_desolation = yes

		set_temp_variable = { UKR_PS_contender_id = 2 }
		set_temp_variable = { PS_MIL_temp = 2 }
		UKR_PS_Militarist_update = yes
		set_temp_variable = { UKR_PS_contender_id = 2 }
		set_temp_variable = { PS_BUR_temp = 2 }
		UKR_PS_Bureaucrat_update = yes

		random_list = { #todo: tooltip for this section
			80 = {}
			7 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 1 }
				set_temp_variable = { temp_value = 3.0 }
				UKR_bb_R_change_control = yes
			}
			7 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 2 }
				set_temp_variable = { temp_value = 3.0 }
				UKR_bb_R_change_control = yes
			}
			7 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 3 }
				set_temp_variable = { temp_value = 3.0 }
				UKR_bb_R_change_control = yes
			}
		}
	}

	### UNRA PRE-UCW

	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_PG_PreUCW_1 }
		}
		set_temp_variable = { temp_guns = -250 }
		UKR_bb_guns_stockpile_change = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 2 }
		set_temp_variable = { temp_value = 4 }
		UKR_bb_R_change_control = yes

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			set_temp_variable = { initial_value = state_value }
			set_temp_variable = { state_value_multiplier_temp = 0.995 }
			econ_state_value_change_multiply = yes
			set_temp_variable = { damage_done = state_value }
		}


	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_PG_PreUCW_2 }
		}
		add_command_power = -25

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		hidden_effect = { #germans firing back, does not appear in tooltip
			set_temp_variable_to_random = {
				var = casualties
				min = 20
				max = 100
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
			random_owned_state = {
				limit = {
					is_in_array = {
						array = temp_state:UKR_bb_states_within_region
						value = THIS.id
					}
				}
				add_manpower = var:casualties
			}
		}

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 2 }
		set_temp_variable = { temp_value = 3 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 1.5 }
		UKR_bb_R_change_desolation = yes
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_PG_PreUCW_3 }
		}
		add_command_power = -40

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		hidden_effect = {
			set_temp_variable_to_random = {
				var = casualties
				min = 1
				max = 25
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 2 }
		set_temp_variable = { temp_value = 6 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 5 }
		UKR_bb_R_change_desolation = yes

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			damage_building = {
				type = infrastructure
				damage = 1
			}
			add_manpower = var:casualties
		}
	}

	### UA-SSR PRE-UCW

	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_1 }
		}
		add_political_power = -15

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		random_list = {
			75 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 1 }
				set_temp_variable = { temp_value = 2 }
				UKR_bb_R_change_control = yes
			}
			25 = {}
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_2 }
		}
		add_command_power = -10
		set_temp_variable = { temp_guns = -50 }
		UKR_bb_guns_stockpile_change = yes
		set_temp_variable = { temp_mp = -20 }
		UKR_bb_manpower_stockpile_change = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		hidden_effect = {
			set_temp_variable_to_random = {
				var = casualties
				min = 3
				max = 59
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 1 }
		set_temp_variable = { temp_value = 3 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 2 }
		UKR_bb_R_change_desolation = yes

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			damage_building = {
				type = infrastructure
				damage = 1
			}
			add_manpower = var:casualties
			set_temp_variable = { initial_value = state_value }
			set_temp_variable = { state_value_multiplier_temp = 0.995 }
			econ_state_value_change_multiply = yes
			set_temp_variable = { damage_done = state_value }
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_3 }
		}
		add_command_power = -20
		set_temp_variable = { temp_guns = -100 }
		UKR_bb_guns_stockpile_change = yes
		set_temp_variable = { temp_mp = -70 }
		UKR_bb_manpower_stockpile_change = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		hidden_effect = {
			set_temp_variable_to_random = {
				var = casualties
				min = 11
				max = 110
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
			set_temp_variable = { initial_value = state_value }
			set_temp_variable = { state_value_multiplier_temp = 0.997 }
			econ_state_value_change_multiply = yes
			set_temp_variable = { damage_done = state_value }
		}

		random_list = {
			80 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 1 }
				set_temp_variable = { temp_value = 5 }
				UKR_bb_R_change_control = yes
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_des = 5 }
				UKR_bb_R_change_desolation = yes
			}
			15 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_des = 4 }
				UKR_bb_R_change_desolation = yes
			}
			5 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 1 }
				set_temp_variable = { temp_value = -2.5 }
				UKR_bb_R_change_control = yes
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_des = 5 }
				UKR_bb_R_change_desolation = yes
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_4 }
		}
		add_command_power = -5
		set_temp_variable = { temp_guns = -80 }
		UKR_bb_guns_stockpile_change = yes
		set_temp_variable = { temp_mp = -40 }
		UKR_bb_manpower_stockpile_change = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		hidden_effect = {
			set_temp_variable_to_random = {
				var = casualties
				min = 20
				max = 80
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 1 }
		UKR_bb_R_change_desolation = yes

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
		}

		random_list = {
			25 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 1 }
				set_temp_variable = { temp_value = 6 }
				UKR_bb_R_change_control = yes
			}
			45 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 1 }
				set_temp_variable = { temp_value = 2 }
				UKR_bb_R_change_control = yes
			}
			15 = {}
			13 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 2 }
				set_temp_variable = { temp_value = 2 }
				UKR_bb_R_change_control = yes
			}
			2 = {
				set_temp_variable = { temp_state = BB_selected_region }
				set_temp_variable = { temp_group = 3 }
				set_temp_variable = { temp_value = 2 }
				UKR_bb_R_change_control = yes
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_5 }
		}
		add_political_power = -25

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 1 }
		set_temp_variable = { temp_value = 4 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = -1 }
		UKR_bb_R_change_desolation = yes
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_6 }
		}
		add_command_power = -25
		set_temp_variable = { temp_guns = -200 }
		UKR_bb_guns_stockpile_change = yes
		set_temp_variable = { temp_mp = -70 }
		UKR_bb_manpower_stockpile_change = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		hidden_effect = {
			set_temp_variable_to_random = {
				var = casualties
				min = 30
				max = 140
				integer = yes
			}
			multiply_temp_variable = { casualties = -1 }
		}

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 1 }
		set_temp_variable = { temp_value = 8 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 5 }
		UKR_bb_R_change_desolation = yes

		random_owned_state = {
			limit = {
				is_in_array = {
					array = temp_state:UKR_bb_states_within_region
					value = THIS.id
				}
			}
			add_manpower = var:casualties
			set_temp_variable = { initial_value = state_value }
			set_temp_variable = { state_value_multiplier_temp = 0.994 }
			econ_state_value_change_multiply = yes

			random_list = {
				75 = {
					if = {
						limit = {
							non_damaged_building_level = {
								building = barracks
								level > 1
							}
						}
						damage_building = {
							type = barracks
							damage = 1
						}
					}
					else_if = {
						limit = {
							non_damaged_building_level = {
								building = prisons
								level > 1
							}
						}
						damage_building = {
							type = prisons
							damage = 1
						}
					}
					else_if = {
						limit = {
							non_damaged_building_level = {
								building = air_base
								level > 1
							}
						}
						damage_building = {
							type = air_base
							damage = 1
						}
					}
					else = {
						damage_building = {
							type = infrastructure
							damage = 1
						}
					}
				}
				25 = {}
			}
		}
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_7 }
		}
		add_political_power = -25
		add_command_power = -5

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_guns = 1000 }
		UKR_bb_guns_stockpile_change = yes
		custom_effect_tooltip = UKS_pre_uprising_guns_tt

	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UA_SSR_PreUCW_8 }
		}
		add_political_power = -25
		add_command_power = -5

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 1 }
		set_temp_variable = { temp_value = 1 }
		UKR_bb_R_change_control = yes

		add_to_variable = { UKS_uprising_division_exp = 0.15 }
		#clamp_variable = { var = UKS_uprising_division_exp max = 1 }
		custom_effect_tooltip = UKS_uprising_division_exp_tt
	}

	### UPA PRE-UCW

	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UPA_PreUCW_1 }
		}
		set_temp_variable = { temp_guns = -250 }
		UKR_bb_guns_stockpile_change = yes

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 3 }
		set_temp_variable = { temp_value = 3 }
		UKR_bb_R_change_control = yes
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UPA_PreUCW_2 }
		}
		add_command_power = -25

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 3 }
		set_temp_variable = { temp_value = 4.5 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 2.5 }
		UKR_bb_R_change_desolation = yes
	}
	else_if = {
		limit = {
			check_variable = { r_action_val = token:UKR_BB_R_Action_UPA_PreUCW_3 }
		}
		add_command_power = -40

		custom_effect_tooltip = UKR_BB_D_Action_Effects_divider

		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_group = 3 }
		set_temp_variable = { temp_value = 7.5 }
		UKR_bb_R_change_control = yes
		set_temp_variable = { temp_state = BB_selected_region }
		set_temp_variable = { temp_des = 7.5 }
		UKR_bb_R_change_desolation = yes
	}
}

### 3.6 - Breadbasket Randomizer Scripted Effect, idk i ain't actually reorganizing the order of these scripted effects lmao ###

####### Randomizer, selects a random region from a pool and applies it as a temp variable for every script here.

UKR_bb_D_R_select_a_random_region = {
	set_temp_variable = { randomizer_on = 1 }
	set_temp_variable = { tooltip_index = 0 }
	custom_effect_tooltip = UKR_bb_D_R_random_region_tt
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_0 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_0 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 1 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_1 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_1 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 2 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_2 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_2 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 3 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_3 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_3 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 4 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_4 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_4 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 5 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_5 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_5 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 6 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_6 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_6 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 7 }
	}
	if = {
		limit = {
			NOT = {
				check_variable = { temp_state_pool_7 = 0 }
			}
		}
		set_temp_variable = { current_region = temp_state_pool_7 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 8 }
	}
	custom_effect_tooltip = UKR_bb_D_R_random_region_tt_end

	set_temp_variable = { max_region_num = temp_state_pool_num }
	add_to_temp_variable = { max_region_num = 1 }
	set_temp_variable_to_random = {
		var = temp_region_selected
		min = 0
		max = max_region_num
		integer = yes
	}
	meta_effect = {
		text = {
			set_temp_variable = { temp_state = temp_state_pool_[NUMBER] }
		}
		NUMBER = "[?temp_region_selected]"
	}
}

UKR_bb_D_R_clear_random_region = {
	set_temp_variable = { temp_state_pool_0 = 0 }
	set_temp_variable = { temp_state_pool_1 = 0 }
	set_temp_variable = { temp_state_pool_2 = 0 }
	set_temp_variable = { temp_state_pool_3 = 0 }
	set_temp_variable = { temp_state_pool_4 = 0 }
	set_temp_variable = { temp_state_pool_5 = 0 }
	set_temp_variable = { temp_state_pool_6 = 0 }
	set_temp_variable = { temp_state_pool_7 = 0 }
	set_temp_variable = { max_region_num = 0 }
	set_temp_variable = { temp_state = 0 }
	set_temp_variable = { randomizer_on = 0 }
}

### 3.7 - Breadbasket Development Scripted Effects ###

####### DEVELOPMENT SCRIPTS

### Accepted arguments:
# temp_state - The region affected, use constants from above

## The following two are optional, but use at least one.
# temp_dev - (OPTIONAL) the development value to be changed (can be negative or positive)
# temp_exp - (OPTIONAL) the exploitation value to be chagned (can be negative or positive)

## How to use:
# set_temp_variable = { temp_state = Kiev_region }
# set_temp_variable = { temp_dev = 10 }
# set_temp_variable = { temp_exp = 5 }
# UKR_bb_D_change_development_values = yes

# In the Kiev region, this will increase development by 10, and exploitation by 5
# note that usage of both temp variables at the same time is not necessary. If you'd like to only manipulate one, then only use one of the temp variables and not the other.

UKR_bb_D_change_development_values = {
	if = {
		limit = {
			check_variable = { temp_disable_scope_d_tt = 0 }
		}
		custom_effect_tooltip = UKR_bb_D_development_scope_tt
	}

	## DEVELOPMENT
	if = {
		limit = {
			NOT = { check_variable = { temp_dev = 0 } }
		}

		add_to_variable = { temp_state:development = temp_dev }
		clamp_variable = {
			var = temp_state:development
			min = 0
			max = 100
		}

		if = {
			limit = {
				check_variable = { temp_dev < 0 }
			}
			multiply_temp_variable = { temp_dev = -1 }
			custom_effect_tooltip = UKR_bb_D_change_development_bad_tt
			multiply_temp_variable = { temp_dev = -1 }
		}
		else = { custom_effect_tooltip = UKR_bb_D_change_development_good_tt }

		set_temp_variable = { advance_check = temp_state:development }
		add_to_temp_variable = { advance_check = temp_dev }
	
		if = {
			limit = {
				check_variable = {
					var = advance_check
					value = 100
					compare = greater_than_or_equals
				}
			}
			custom_effect_tooltip = UKR_bb_D_advance_development_tt
		}

		if = {
			limit = {
				check_variable = { temp_state:development = 100 }
			}
			add_to_variable = { temp_state:development_level = 1 }
			set_variable = { temp_state:development = 0 }
			clamp_variable = {
				var = temp_state:development_level
				min = 0
				max = 10
			}
			UKR_bb_consumption_total_dev_calc = yes
		}
	}

	## Exploitation
	if = {
		limit = {
			NOT = { check_variable = { temp_exp = 0 } }
		}

		add_to_variable = { temp_state:exploitation = temp_exp }
		clamp_variable = {
			var = temp_state:exploitation
			min = 0
			max = 100
		}

		if = {
			limit = {
				check_variable = { temp_exp < 0 }
			}
			multiply_temp_variable = { temp_exp = -1 }
			custom_effect_tooltip = UKR_bb_D_change_exploitation_bad_tt
			multiply_temp_variable = { temp_exp = -1 }
		}
		else = { custom_effect_tooltip = UKR_bb_D_change_exploitation_good_tt }
	}

	## Grain output
	if = {
		limit = {
			NOT = { check_variable = { temp_grain_output = 0 } }
		}

		add_to_variable = { temp_state:grain_output = temp_grain_output }
		if = {
			limit = {
				check_variable = { temp_grain_output < 0 }
			}
			multiply_temp_variable = { temp_grain_output = -1 }
			custom_effect_tooltip = UKR_bb_D_change_grain_output_bad_tt
			multiply_temp_variable = { temp_grain_output = -1 }
		}
		else = { custom_effect_tooltip = UKR_bb_D_change_grain_output_good_tt }
		UKR_bb_consumption_total_grain_calc = yes
	}

	add_to_variable = { UKR_BB_DIRTY = 0.01 }

	set_temp_variable = { temp_dev = 0 }
	set_temp_variable = { temp_exp = 0 }
	set_temp_variable = { temp_grain_output = 0 }
}

d_UKR_bb_D_change_development_values = {
	set_temp_variable = { temp_state = args^0 }
	set_temp_variable = { temp_dev = args^1 }
	set_temp_variable = { temp_exp = args^2 }
	UKR_bb_D_change_development_values = yes
}

UKR_bb_D_change_development_values_all = {
	set_temp_variable = { temp_disable_scope_d_tt = 1 }
	custom_effect_tooltip = UKR_bb_D_development_scope_all_tt
	effect_tooltip = {
		set_temp_variable = { temp_state = 202 } # Does nothing
		set_temp_variable = { temp_dev = temp_all_dev }
		set_temp_variable = { temp_exp = temp_all_exp }
		set_temp_variable = { temp_grain_output = temp_all_grain_output }
		UKR_bb_D_change_development_values = yes
	}
	hidden_effect = {
		for_each_loop = {
			array = UKR_bb_map_array
			set_temp_variable = { temp_state = v }
			set_temp_variable = { temp_dev = temp_all_dev }
			set_temp_variable = { temp_exp = temp_all_exp }
			set_temp_variable = { temp_grain_output = temp_all_grain_output }
			UKR_bb_D_change_development_values = yes
		}
	}
}

### 3.8 - Breadbasket Resistance Scripted Effects ###

####### RESISTANCE SCRIPTS

## Accepted Arguments:
# temp_state - state id that stores the region's data, use the provided region constants as the value at the top.
# temp_group - the slot that the affected group is placed in, accepted values are 0, 1, 2, and 3
# temp_value - the amount of control that changes, can be either negative or positive

## Example of usage:
# set_temp_variable = { temp_state = Volyn_region }
# set_temp_variable = { temp_group = 2 }
# set_temp_variable = { temp_value = 10 }
# UKR_bb_R_change_control = yes

## The above effect will change (Slot 2) resistance control in the Wolhynien region by +10

UKR_bb_R_change_control = {
	set_temp_variable = { v_check = temp_state:resistance_control^temp_group }
	add_to_temp_variable = { v_check = temp_value }

	if = {
		limit = {
			check_variable = { v_check < 0 }
		}
		subtract_from_temp_variable = { temp_value = v_check }
	}

	if = {
		limit = {
			NOT = {
				check_variable = { temp_value = 0 }
			}
		}
		custom_effect_tooltip = UKR_bb_R_change_control_tt

		add_to_variable = { temp_state:resistance_control^temp_group = temp_value }

		for_each_loop = {
			array = temp_state:resistance_control
			if = {
				limit = {
					OR = {
						check_variable = { v = 0 }
						check_variable = { resistance_control_disabled^i = 1 }
					}
					NOT = { check_variable = { i = temp_group } }
				}
				add_to_temp_array = { disable_index = i }
			}
			if = {
				limit = {
					check_variable = { resistance_control_disabled^i = 1 }
					NOT = { check_variable = { i = temp_group } }
				}
				add_to_temp_array = { disable_index_force = i }
			}
		}

		set_temp_variable = { divide_factor = 3 }
		if = {
			limit = {
				NOT = { check_variable = { disable_index^num = 3 } }
			}
			subtract_from_temp_variable = { divide_factor = disable_index^num }
		}
		else = {
			subtract_from_temp_variable = { divide_factor = disable_index_force^num }
		}
		divide_temp_variable = { temp_value = divide_factor }

		set_temp_variable = { excess = 0 }
		for_each_loop = {
			array = temp_state:resistance_control
			if = {
				limit = {
					NOT = {
						check_variable = { i = temp_group }
					}
					if = {
						limit = {
							NOT = {
								check_variable = { disable_index^num = 3 }
							}
						}
						NOT = {
							is_in_array = { array = disable_index value = i }
						}
					}
					else = {
						NOT = {
							is_in_array = { array = disable_index_force value = i }
						}
					}
				}
				subtract_from_variable = { temp_state:resistance_control^i = temp_value }
			}
			if = {
				limit = { check_variable = { temp_state:resistance_control^i < 0 } }
				add_to_temp_variable = { excess = temp_state:resistance_control^i }
				set_variable = { temp_state:resistance_control^i = 0 }
				add_to_temp_array = { zero_value = i }
			}
		}
		for_each_loop = {
			array = temp_state:resistance_control
			if = {
				limit = {
					NOT = {
						is_in_array = { array = zero_value value = i }
					}
					if = {
						limit = {
							NOT = {
								check_variable = { zero_value^num = 3 }
							}
						}
						NOT = {
							check_variable = { i = temp_group }
						}
					}
				}
				add_to_variable = { temp_state:resistance_control^i = excess }
				set_temp_variable = { break = 1 }
			}
		}
	}

	clear_temp_array = disable_index
	clear_temp_array = disable_index_force
	clear_temp_array = zero_value
	set_temp_variable = { excess = 0 }

	UKR_bb_resistance_demilitarized_zone_logic = yes

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

d_UKR_bb_R_change_control_final_test = {
	resize_array = { array = resistance_control_disabled size = 4 value = 0 }
	set_variable = { resistance_control_disabled^1 = 1 }
}

d_UKR_bb_R_change_control = {
	set_temp_variable = { temp_state = args^0 }
	set_temp_variable = { temp_group = args^1 }
	set_temp_variable = { temp_value = args^2 }
	UKR_bb_R_change_control = yes
}

UKR_bb_R_change_control_all = {
	set_temp_variable = { temp_group = temp_all_group }
	custom_effect_tooltip = UKR_bb_R_change_control_all_tt
	hidden_effect = {
		for_each_loop = {
			array = UKR_bb_map_array
			set_temp_variable = { temp_state = UKR_bb_map_array^i }
			set_temp_variable = { temp_group = temp_all_group }
			set_temp_variable = { temp_value = temp_all_value }
			UKR_bb_R_change_control = yes
			clear_variable = temp_state
			clear_variable = temp_group
			clear_variable = temp_value
		}
	}
}

d_UKR_bb_R_change_control_all = {
	set_temp_variable = { temp_all_group = args^0 }
	set_temp_variable = { temp_all_value = args^1 }
	UKR_bb_R_change_control_all = yes
}

### Mega scuffed because temp arrays dont act like temp variables
# temp_state_pool_<int> - state id that stores the region's data into the pool to be selected. Goes up to 5
# temp_group - the slot that the affected group is placed in, accepted values are 0, 1, 2, and 3
# temp_value - the amount of control that changes, can be either negative or positive

## Example of usage:
# set_temp_variable = { temp_state_pool_0 = Kiev_region }
# set_temp_variable = { temp_state_pool_1 = Kharkiv_region }
# set_temp_variable = { temp_state_pool_2 = Volyn_region }
# set_temp_variable = { temp_group = 2 }
# set_temp_variable = { temp_value = 10 }
# UKR_bb_R_change_control_random_region = yes

UKR_bb_R_change_control_random_region = {
	set_temp_variable = { tooltip_index = 0 }
	custom_effect_tooltip = UKR_bb_R_change_control_random_tt
	if = {
		limit = {
			has_variable = temp_state_pool_0
		}
		set_temp_variable = { current_region = temp_state_pool_0 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 1 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_1
		}
		set_temp_variable = { current_region = temp_state_pool_1 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 2 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_2
		}
		set_temp_variable = { current_region = temp_state_pool_2 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 3 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_3
		}
		set_temp_variable = { current_region = temp_state_pool_3 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 4 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_4
		}
		set_temp_variable = { current_region = temp_state_pool_4 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 5 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_5
		}
		set_temp_variable = { current_region = temp_state_pool_5 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 6 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_6
		}
		set_temp_variable = { current_region = temp_state_pool_6 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 7 }
	}
	if = {
		limit = {
			has_variable = temp_state_pool_7
		}
		set_temp_variable = { current_region = temp_state_pool_7 }
		custom_effect_tooltip = UKR_bb_D_R_random_region_tt_entry
		set_temp_variable = { temp_state_pool_num = 8 }
	}
	custom_effect_tooltip = UKR_bb_R_change_control_random_tt_2

	set_temp_variable = { max_region_num = temp_state_pool_num }
	add_to_temp_variable = { max_region_num = 1 }
	set_temp_variable_to_random = {
		var = temp_region_selected
		min = 0
		max = max_region_num
		integer = yes
	}
	meta_effect = {
		text = {
			set_temp_variable = { temp_state = temp_state_pool_[NUMBER] }
		}
		NUMBER = "[?temp_region_selected]"
	}
	hidden_effect = {
		UKR_bb_R_change_control = yes
	}
}

## The following scripted effect is used if you'd like to transfer some control from only one resistance group to another.

## Accepted arguments:
# temp_state - Region, use constants
# temp_group - The main group that has its value given to
# temp_target - The other group that has the values taken from
# temp_value - The value of control, MUST BE POSITIVE, negative values will return an error message in the custom effect tooltip.

UKR_bb_R_change_control_specific_1 = {
	if = {
		limit = {
			NOT = {
				check_variable = { temp_value < 0 }
				check_variable = { temp_group = temp_target }
			}
		}
		add_to_variable = { temp_state:resistance_control^temp_group = temp_value }
		subtract_from_variable = { temp_state:resistance_control^temp_target = temp_value }

		set_temp_variable = { temp_value_n = temp_value }
		multiply_temp_variable = { temp_value_n = -1 }

		custom_effect_tooltip = UKR_bb_R_change_control_specific_1_tt

		if = {
			limit = {
				check_variable = { temp_state:resistance_control^temp_target < 0 }
			}
			set_temp_variable = { excess = temp_state:resistance_control^temp_target }
			set_variable = { temp_state:resistance_control^temp_target = 0 }

			add_to_variable = { temp_state:resistance_control^temp_group = excess }
		}
	}
	else = {
		if = {
			limit = {
				check_variable = { temp_value < 0 }
			}
			custom_effect_tooltip = UKR_bb_R_change_control_specific_1_error_1
		}
		if = {
			limit = {
				check_variable = { temp_group = temp_target }
			}
			custom_effect_tooltip = UKR_bb_R_change_control_specific_1_error_2
		}
	}

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

d_UKR_bb_R_change_control_specific_1 = {
	set_temp_variable = { temp_state = args^0 }
	set_temp_variable = { temp_group = args^1 }
	set_temp_variable = { temp_target = args^2 }
	set_temp_variable = { temp_value = args^3 }
	UKR_bb_R_change_control_specific_1 = yes
}

# Accepted arguments: temp_state, temp_des
UKR_bb_R_change_desolation = {
	hidden_effect = {
		add_to_variable = { temp_state:desolation = temp_des }
		clamp_variable = {
			var = temp_state:desolation
			min = 0
			max = 100
		}
	}
	if = {
		limit = {
			check_variable = { temp_des < 0 }
		}
		multiply_temp_variable = { temp_des = -1 }
		custom_effect_tooltip = UKR_bb_R_change_desolation_good_tt
		multiply_temp_variable = { temp_des = -1 }
	}
	else = { custom_effect_tooltip = UKR_bb_R_change_desolation_bad_tt }
	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

d_UKR_bb_R_change_desolation = {
	set_temp_variable = { temp_state = args^0 }
	set_temp_variable = { temp_des = args^1 }
	UKR_bb_R_change_desolation = yes
}

UKR_bb_R_change_desolation_all = {
	for_each_loop = {
		array = UKR_bb_map_array
		add_to_variable = { v:desolation = temp_all_des }
		clamp_variable = {
			var = v:desolation
			min = 0
			max = 100
		}
	}
	if = {
		limit = {
			check_variable = { temp_all_des < 0 }
		}
		multiply_temp_variable = { temp_all_des = -1 }
		custom_effect_tooltip = UKR_bb_R_change_desolation_good_all_tt
		multiply_temp_variable = { temp_all_des = -1 }
	}
	else = { custom_effect_tooltip = UKR_bb_R_change_desolation_bad_all_tt }

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

d_UKR_bb_R_change_desolation_all = {
	set_temp_variable = { temp_all_des = args^0 }
	UKR_bb_R_change_desolation_all = yes
}

## Partisan Stockpile Scripted Effects
# Respective arguments: temp_guns, temp_mp
UKR_bb_guns_stockpile_change = {
	add_to_variable = { UKR_bb_partisan_stockpile_guns = temp_guns }
	custom_effect_tooltip = UKR_bb_guns_stockpile_change_tt

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}
UKR_bb_manpower_stockpile_change = {
	add_to_variable = { UKR_bb_partisan_stockpile_manpower = temp_mp }
	custom_effect_tooltip = UKR_bb_manpower_stockpile_change_tt

	add_to_variable = { UKR_BB_DIRTY = 0.01 }
}

d_UKR_bb_guns_stockpile_change = {
	set_temp_variable = { temp_guns = args^0 }
	UKR_bb_guns_stockpile_change = yes
}
d_UKR_bb_manpower_stockpile_change = {
	set_temp_variable = { temp_mp = args^0 }
	UKR_bb_manpower_stockpile_change = yes
}

# d8888b.          .d888b.
#     `88          Y8' `88
#  aaad8'          `8bad88
#     `88              `88
#     .88    dP    d.  .88
# d88888P    88    `8888P
### 3.9 - Breadbasket Alerts
# - Calph was here :^)
# - The only important effect is UKR_bb_alerts_pulse, everything else is dependent.
# - I found it easier to write it that way, no other particular reason for that.

# Central effect, checks & calls for alerts.
# - Called every week in <on_action>
# - Called in some scripted effects, too
UKR_bb_alerts_pulse = {
	log = "[GetDate]: [GetTag]: Breadbasket Alerts Pulse"

	UKR_bb_alerts_check_GovControl = yes
	UKR_bb_alerts_check_ConsCycle = yes
	UKR_bb_alerts_check_ActionAvailable = yes
	UKR_bb_alerts_check_DecisiveRegionWarning = yes
}

UKR_bb_alerts_check_GovControl = {

	set_temp_variable = { alert_id = token:Alert_UKR_BreadBasket_GovControl }

	if = {
		limit = {
			any_of_scopes  = {
				array = UKR_bb_map_array
				check_variable = { resistance_control^0 < 50 }
			}
		}
		add_TNO_alert_unless_exists = yes
	}
	else = {
		remove_TNO_alert_data = yes
	}
}

UKR_bb_alerts_check_GovControl_entries = {
	if = {
		limit = {
			check_variable = { temp_govcontrol_idx < UKR_bb_map_array^num }
		}

		if = {
			limit = {
				set_temp_variable = { check_resistance_control = UKR_bb_map_array^temp_govcontrol_idx }
				var:check_resistance_control = {
					check_variable = { resistance_control^0 < 50 }
				}
			}
			custom_effect_tooltip = Alert_UKR_Breadbasket_GovControl_entry
		}
		add_to_temp_variable = { temp_govcontrol_idx = 1 }
		UKR_bb_alerts_check_GovControl_entries = yes
	}
}

UKR_bb_alerts_check_ConsCycle = {
	set_temp_variable = { alert_id = token:Alert_UKR_BreadBasket_ConsCycle }
	set_temp_variable = { alert_data = UKR_bb_consumption_countdown }
	divide_temp_variable = { alert_data = 7 }
	if = {
		limit = {
			check_variable = { alert_data < 4 }
			NOT = { has_global_flag = UKR_UCW_ongoing }
		}

		log = "[GetDate]: [GetTag]: Breadbasket Alerts Check; ConsCyle; [?alert_data]!"
		add_TNO_alert_unless_exists = yes
	}
	else = { remove_TNO_alert = yes }
}

UKR_bb_alerts_check_DecisiveRegionWarning = {
	set_temp_variable = { alert_id = token:Alert_UKR_BreadBasket_DecisiveRegionWarning }

	for_each_loop = {
		array = UKR_bb_resistance_activities_decisive_control_array

		if = {
			limit = {
				check_variable = { UKR_bb_resistance_activities_decisive_control_array^i > UKR_bb_resistance_activities_decisive_threshold_array^i }
			}
			set_temp_variable = { there_is_emboldened = 1 }
		}
	}

	if = {
		limit = {
			check_variable = { there_is_emboldened = 1 }
		}
		add_TNO_alert_unless_exists = yes
	}
	else = { remove_TNO_alert = yes }
}

# Alerts Check Action Available
# - For this set, we're gonna take advantage of the Scripted GUI system in place for actions
UKR_bb_alerts_check_ActionAvailable = {
	#UKR_bb_alerts_check_ActionAvailable_Consumption = yes	# UKR_bb_consumption_actions_array
	UKR_bb_alerts_check_ActionAvailable_Development = yes	# UKR_BB_actions_development_array
	UKR_bb_alerts_check_ActionAvailable_Resistance = yes	# UKR_BB_actions_resistance_array
}

# Action Available - Consumption
# - Disabled for now since one of the Consumption actions is *always* available.
UKR_bb_alerts_check_ActionAvailable_Consumption = {
	set_temp_variable = { alert_id = token:Alert_UKR_BreadBasket_ActionAvailable }
	for_each_loop = {
		array = UKR_bb_consumption_actions_array
		value = v
		index = i

		set_temp_variable = { alert_data = v }

		if = {
			limit = { UKR_BB_can_do_consumption_action = yes }
			add_TNO_alert_unless_exists = yes
		}
		else = {
			remove_TNO_alert_data = yes
		}
	}
}

UKR_bb_alerts_check_ActionAvailable_Development = {
	set_temp_variable = { alert_id = token:Alert_UKR_BreadBasket_ActionAvailable }
	for_each_loop = {
		array = UKR_BB_actions_development_array
		value = d_action_val
		index = d_action_idx

		set_temp_variable = { alert_data = d_action_val }

		if = {
			limit = { UKR_BB_can_do_dev_action = yes }
			log = "[GetDate]: [GetTag]: Breadbasket Alerts Check; ActionsAvailable - Development; [?alert_data.GetTokenLocalizedKey]!"
			add_TNO_alert_unless_exists = yes
		}
		else = {
			remove_TNO_alert_data = yes
		}
	}
}

UKR_bb_alerts_check_ActionAvailable_Resistance = {
	set_temp_variable = { alert_id = token:Alert_UKR_BreadBasket_ActionAvailable }
	for_each_loop = {
		array = UKR_BB_actions_resistance_array
		value = r_action_val
		index = r_action_idx

		set_temp_variable = { alert_data = r_action_val }

		if = {
			limit = { UKR_BB_can_do_res_action = yes }
			log = "[GetDate]: [GetTag]: Breadbasket Alerts Check; ActionsAvailable - Resistance; [?alert_data.GetTokenLocalizedKey]!"
			add_TNO_alert_unless_exists = yes
		}
		else = {
			remove_TNO_alert_data = yes
		}
	}
}

# .d8888P
# 88'
# 88baaa.
# 88` `88
# 8b. .d8
# `Y888P'
### 4.0 - UNRA (FUK) Mechanics###

UKR_FUK_clear_wartime_laws = {
	if = {
		limit = {
			has_country_flag = UKR_FUK_wartime_laws
		}
		tno_public_meetings_improve = yes
		tno_press_rights_improve = yes
		tno_penal_system_improve = yes
	}
}

#
	# Overall
	#	- Focus on Political Violence / Voter Suppression / Intimidation
	#		- Alongside actual campaigning
	#	- 3 main coalitions
	#		- Culturalist, United Struggle & Spivavtor
	#	- Dual Citizenship DNE in Ukraine
	#		- As such no German votes
	#	- Fascist infiltration is a major issue to Culturalists & United Struggle
	#	- Spivavtor is more concerned for (the far less real) Communist infiltration
	#	- 3 major events during the mechanic
	#		- Ohloblyn's negotiations w/ German remnants to collab
	#		- Dziuba's Condemnation of Fascism and Babi Yar
	#		- Stus/Borovets going through and executing large amounts of the RK Admin

	# Per-Region
	#	- Popularity (per party)
	#		- Doesn't change much
	#	- Infrastructure* (per party)
	#		- *Need better name
	#		- Will generally be what changes
	#	- Regions
	#		-

	# Conversion
	#	- Infra can be spent to grow Popularity
	#		- Popularity is more stable, Infra isn't

	# Action Economy
	#	- Kyiv
	#	- Chernihiv
	#	- Yekatarinoslav
	#	- Yuzivka
	#	- Volyn
	#	- Zhytomyr
	#	- Galicia
#

# 4.1 - Election Mech

# Election Init
# | Initializes:
#   | static, target_spivavtor
#   | static, target_culturalist
#   | static, target_populist
#   | Regional;
#     | static, seats
#     | var, coalition_pop
#     | var, coalition_infra
FUK_election_init = {
	set_country_flag = UKR_FUK_election_mech

	# Region Vars
	set_variable = { West_region = 93 }  	# Volyn
	set_variable = { Central_region = 202 } # Kiev
	set_variable = { East_region = 227 }	# Luhansk / Yuzivka

	# Coalition Vars
	set_variable = { target_spivavtor = 0 }
	set_variable = { target_culturalist = 1 }
	set_variable = { target_populist = 2 }

	# Prediction Vars
	set_variable = { spivavtor_expected_seats = 0 }
	set_variable = { culturalists_expected_seats = 0 }
	set_variable = { populists_expected_seats = 0 }

	# Political Capital ^_^
	set_variable = { FUK_political_capital = 100 }

	# Popularity (ONLY USED FOR SETTING COALITION POP)
	set_temp_variable = { spivavtor_popularity = party_popularity@fascism }
	multiply_temp_variable = { spivavtor_popularity = 0.5 } # penalizes you for getting extremist pop
	add_to_temp_variable = { spivavtor_popularity = party_popularity@anocracy_1 }
	multiply_temp_variable = { spivavtor_popularity = 1.3 } # spivavtor corruption and bias in the voting system, gives them a little buff

	set_temp_variable = { culturalists_popularity = party_popularity@communist }
	multiply_temp_variable = { culturalists_popularity = 0.5 } # penalizes you for getting extremist pop
	add_to_temp_variable = { culturalists_popularity = party_popularity@socialist }

	set_temp_variable = { populists_popularity = party_popularity@despotism }
	multiply_temp_variable = { populists_popularity = 0.5 } # penalizes you for getting extremist pop
	add_to_temp_variable = { populists_popularity = party_popularity@progressivism }

	## Regions
	set_variable = { active_region = Central_region }
	add_to_array = { FUK_election_regions = Central_region } # Kiev & Chernigov
	var:Central_region = {
		# Seat Num
		# - 1 seat per 100k people
		set_temp_variable = { population = 0 }
		add_to_temp_variable = { population = 202.state_population_k }	# Kyiv
		add_to_temp_variable = { population = 225.state_population_k }	# Sumy
		add_to_temp_variable = { population = 259.state_population_k }	# Poltava
		add_to_temp_variable = { population = 1427.state_population_k }	# Chernigov
		add_to_temp_variable = { population = 1428.state_population_k }	# Kyiv City
		divide_temp_variable = { population = 100 }
		round_temp_variable = population

		set_variable = { seats = population }

		# Popularities
		clear_array = coalition_pop
		# a little randomization of popularity

		set_temp_variable = { spivavtor_popularity_central = spivavtor_popularity }
		set_temp_variable = { culturalists_popularity_central = culturalists_popularity }
		set_temp_variable = { populists_popularity_central = populists_popularity }

		randomize_temp_variable = {
			var = spivavtor_popularity_central_multiplier
			distribution = uniform
			min = 0.9
			max = 1.1
		}
		randomize_temp_variable = {
			var = culturalists_popularity_central_multiplier
			distribution = uniform
			min = 0.9
			max = 1.1
		}
		randomize_temp_variable = {
			var = populists_popularity_central_multiplier
			distribution = uniform
			min = 0.9
			max = 1.1
		}

		multiply_temp_variable = { spivavtor_popularity_central = spivavtor_popularity_central_multiplier }
		multiply_temp_variable = { culturalists_popularity_central = culturalists_popularity_central_multiplier }
		multiply_temp_variable = { populists_popularity_central = populists_popularity_central_multiplier }

		set_temp_variable = { total_popularity_central = spivavtor_popularity_central } # adding it all together to do a little bit of math
		add_to_temp_variable = { total_popularity_central = culturalists_popularity_central } # adding it all together to do a little bit of math
		add_to_temp_variable = { total_popularity_central = populists_popularity_central } # adding it all together to do a little bit of math

		subtract_from_temp_variable = { total_popularity_central = 1 } # we need what is left over from the rest of the pie chart
		multiply_temp_variable = { total_popularity_central = -1 } # fixing negatives

		set_temp_variable = { remaining_popularity = total_popularity_central }
		multiply_temp_variable = { remaining_popularity = 0.25 } # spiv
		add_to_temp_variable = { spivavtor_popularity_central = remaining_popularity }

		set_temp_variable = { remaining_popularity = total_popularity_central }
		multiply_temp_variable = { remaining_popularity = 0.4 } # culturalists
		add_to_temp_variable = { culturalists_popularity_central = remaining_popularity }

		set_temp_variable = { remaining_popularity = total_popularity_central }
		multiply_temp_variable = { remaining_popularity = 0.35 } # us
		add_to_temp_variable = { populists_popularity_central = remaining_popularity }

		add_to_array = { coalition_pop = spivavtor_popularity_central } # Spivavtor
		add_to_array = { coalition_pop = culturalists_popularity_central } # Culturalists
		add_to_array = { coalition_pop = populists_popularity_central } # Populists
	}

	add_to_array = { FUK_election_regions = West_region } # Volhynia & Zhytomyr
	var:West_region = {
		# Seat Num
		# - 1 seat per 100k people
		set_temp_variable = { population = 0 }
		add_to_temp_variable = { population = 93.state_population_k }	# Volhynia
		add_to_temp_variable = { population = 199.state_population_k }	# Podillia
		add_to_temp_variable = { population = 201.state_population_k }	# Mozyr
		add_to_temp_variable = { population = 773.state_population_k }	# Korosten
		add_to_temp_variable = { population = 1429.state_population_k }	# Zhytmoyr
		add_to_temp_variable = { population = 1430.state_population_k }	# Vinnytsia
		add_to_temp_variable = { population = 1431.state_population_k }	# Brest-Litovsk
		divide_temp_variable = { population = 100 }
		round_temp_variable = population

		set_variable = { seats = population }

		# Popularities
		clear_array = coalition_pop
		# a little randomization of popularity
		set_temp_variable = { spivavtor_popularity_west = spivavtor_popularity }
		set_temp_variable = { culturalists_popularity_west = culturalists_popularity }
		set_temp_variable = { populists_popularity_west = populists_popularity }

		randomize_temp_variable = {
			var = spivavtor_popularity_west_multiplier
			distribution = uniform
			min = 0.9
			max = 1.1
		}
		randomize_temp_variable = {
			var = culturalists_popularity_west_multiplier
			distribution = uniform
			min = 0.9
			max = 1.1
		}
		randomize_temp_variable = {
			var = populists_popularity_west_multiplier
			distribution = uniform
			min = 0.9
			max = 1.1
		}

		multiply_temp_variable = { spivavtor_popularity_west = spivavtor_popularity_west_multiplier }
		multiply_temp_variable = { culturalists_popularity_west = culturalists_popularity_west_multiplier }
		multiply_temp_variable = { populists_popularity_west = populists_popularity_west_multiplier }

		set_temp_variable = { total_popularity_west = spivavtor_popularity_west } # adding it all together to do a little bit of math
		add_to_temp_variable = { total_popularity_west = culturalists_popularity_west } # adding it all together to do a little bit of math
		add_to_temp_variable = { total_popularity_west = populists_popularity_west } # adding it all together to do a little bit of math

		subtract_from_temp_variable = { total_popularity_west = 1 } # we need what is left over from the rest of the pie chart
		multiply_temp_variable = { total_popularity_west = -1 } # fixing negatives

		set_temp_variable = { remaining_popularity = total_popularity_west }
		multiply_temp_variable = { remaining_popularity = 0.25 } # spiv
		add_to_temp_variable = { spivavtor_popularity_west = remaining_popularity }

		set_temp_variable = { remaining_popularity = total_popularity_west }
		multiply_temp_variable = { remaining_popularity = 0.4 } # culturalists
		add_to_temp_variable = { culturalists_popularity_west = remaining_popularity }

		set_temp_variable = { remaining_popularity = total_popularity_west }
		multiply_temp_variable = { remaining_popularity = 0.35 } # us
		add_to_temp_variable = { populists_popularity_west = remaining_popularity }

		add_to_array = { coalition_pop = spivavtor_popularity_west } # Spivavtor
		add_to_array = { coalition_pop = culturalists_popularity_west } # Culturalists
		add_to_array = { coalition_pop = populists_popularity_west } # Populists
	}

	add_to_array = { FUK_election_regions = East_region } # Yekatarinoslav & Yuzivka
	var:East_region = {
		# Seat Num
		# - 1 seat per 100k people
		set_temp_variable = { population = 0 }
		add_to_temp_variable = { population = 197.state_population_k }	# Mykolaiv
		add_to_temp_variable = { population = 200.state_population_k }	# Zaporizhia
		add_to_temp_variable = { population = 218.state_population_k }	# Rostov
		add_to_temp_variable = { population = 221.state_population_k }	# Kharkiv
		add_to_temp_variable = { population = 226.state_population_k }	# Reichenaustadt / Yekatarinoslav
		add_to_temp_variable = { population = 227.state_population_k }	# Yuzivka / Hughesdorf
		add_to_temp_variable = { population = 228.state_population_k }	# Luhansk
		add_to_temp_variable = { population = 1426.state_population_k }	# Novomoskovsk

		divide_temp_variable = { population = 100 }
		round_temp_variable = population

		set_variable = { seats = population }

		# Popularities
		clear_array = coalition_pop
		# a little randomization of popularity
		set_temp_variable = { spivavtor_popularity_east = spivavtor_popularity }
		set_temp_variable = { culturalists_popularity_east = culturalists_popularity }
		set_temp_variable = { populists_popularity_east = populists_popularity }

		#randomize_temp_variable = {
		#	var = spivavtor_popularity_east_multiplier
		#	distribution = uniform
		#	min = 0.9
		#	max = 1.1
		#}
		#randomize_temp_variable = {
		#	var = culturalists_popularity_east_multiplier
		#	distribution = uniform
		#	min = 0.9
		#	max = 1.1
		#}
		#randomize_temp_variable = {
		#	var = populists_popularity_east_multiplier
		#	distribution = uniform
		#	min = 0.9
		#	max = 1.1
		#}

		#multiply_temp_variable = { spivavtor_popularity_east = spivavtor_popularity_east_multiplier }
		#multiply_temp_variable = { culturalists_popularity_east = culturalists_popularity_east_multiplier }
		#multiply_temp_variable = { populists_popularity_east = populists_popularity_east_multiplier }

		set_temp_variable = { total_popularity_east = spivavtor_popularity_east } # adding it all together to do a little bit of math
		add_to_temp_variable = { total_popularity_east = culturalists_popularity_east } # adding it all together to do a little bit of math
		add_to_temp_variable = { total_popularity_east = populists_popularity_east } # adding it all together to do a little bit of math

		subtract_from_temp_variable = { total_popularity_east = 1 } # we need what is left over from the rest of the pie chart
		multiply_temp_variable = { total_popularity_east = -1 } # fixing negatives

		set_temp_variable = { remaining_popularity = total_popularity_east }
		multiply_temp_variable = { remaining_popularity = 0.25 } # spiv
		add_to_temp_variable = { spivavtor_popularity_east = remaining_popularity }

		set_temp_variable = { remaining_popularity = total_popularity_east }
		multiply_temp_variable = { remaining_popularity = 0.4 } # culturalists
		add_to_temp_variable = { culturalists_popularity_east = remaining_popularity }

		set_temp_variable = { remaining_popularity = total_popularity_east }
		multiply_temp_variable = { remaining_popularity = 0.35 } # us
		add_to_temp_variable = { populists_popularity_east = remaining_popularity }

		add_to_array = { coalition_pop = spivavtor_popularity_east } # Spivavtor
		add_to_array = { coalition_pop = culturalists_popularity_east } # Culturalists
		add_to_array = { coalition_pop = populists_popularity_east } # Populists
	}

	# Lviv
	# - Perma disabled for now, would make balancing the mechanic more complicated.
	# - Set up here in case it needs to be enabled again.
	if = {
		limit = {
			NOT = { always = yes }
			#owns_state = 1391
		}
		set_variable = { Lviv_region = 1391 }
		add_to_array = { FUK_election_regions = Lviv_region }
		var:Lviv_region = {
			# Seat Num
			# - 1 seat per 100k people
			set_temp_variable = { population = 0 }
			add_to_temp_variable = { population = 89.state_population_k }	# Volhynia
			add_to_temp_variable = { population = 91.state_population_k }	# Podillia
			add_to_temp_variable = { population = 1387.state_population_k }	#
			add_to_temp_variable = { population = 1388.state_population_k }	#
			add_to_temp_variable = { population = 1390.state_population_k }	#
			add_to_temp_variable = { population = 1391.state_population_k }	#
			add_to_temp_variable = { population = 1392.state_population_k }	#
			add_to_temp_variable = { population = 1393.state_population_k }	#
			add_to_temp_variable = { population = 1394.state_population_k }	#
			divide_temp_variable = { population = 100 }
			round_temp_variable = population

			set_variable = { seats = population }

			# Popularities
			clear_array = coalition_pop
			# a little randomization of popularity
			set_temp_variable = { spivavtor_popularity_lyiv = spivavtor_popularity }
			set_temp_variable = { culturalists_popularity_lyiv = culturalists_popularity }
			set_temp_variable = { populists_popularity_lyiv = populists_popularity }

			randomize_temp_variable = {
				var = spivavtor_popularity_lyiv
				distribution = uniform
				min = 0.9
				max = 1.1
			}
			randomize_temp_variable = {
				var = culturalists_popularity_lyiv
				distribution = uniform
				min = 0.9
				max = 1.1
			}
			randomize_temp_variable = {
				var = populists_popularity_lyiv
				distribution = uniform
				min = 0.9
				max = 1.1
			}

			add_to_array = { coalition_pop = spivavtor_popularity } # Spivavtor
			add_to_array = { coalition_pop = culturalists_popularity } # Culturalists
			add_to_array = { coalition_pop = populists_popularity } # Populists
		}
	}

	# not sure how necessary this is but I'm going to add it since the dynamic starting popularities could be outside normal limits, this should correct them
	#set_temp_variable = { t_region = var:Central_region }
	#FUK_election_balance_pop = yes
	#set_temp_variable = { t_region = var:West_region }
	#FUK_election_balance_pop = yes
	#set_temp_variable = { t_region = var:East_region }
	#FUK_election_balance_pop = yes

	if = {
		limit = {
			NOT = { always = yes }
			#owns_state = 1391
		}
		set_temp_variable = { t_region = var:Lyiv_region }
		FUK_election_balance_pop = yes
	}

	# Initialize Campaign Decisions
	if = {
		limit = { NOT = { check_variable = { FUK_election_protagonist = target_spivavtor } } }
		activate_mission = FUK_election_spivavtor_campaign
	}
	if = {
		limit = { NOT = { check_variable = { FUK_election_protagonist = target_culturalist } } }
		activate_mission = FUK_election_culturalist_campaign
	}
	if = {
		limit = { NOT = { check_variable = { FUK_election_protagonist = target_populist } } }
		activate_mission = FUK_election_populist_campaign
	}

	activate_mission = FUK_election_timer

	FUK_election_update = yes
}

# Election Clear
# - Clears all used vars
FUK_election_clear = {
	clr_country_flag = UKR_FUK_election_mech

	clear_variable = target_spivavtor
	clear_variable = target_culturalist
	clear_variable = target_populist

	for_each_scope_loop = {
		array = FUK_election_regions

		clear_variable = seats
		clear_array = coalition_pop
		clear_array = coalition_infra
	}

	clear_variable = Lviv_region
	clear_array = FUK_election_regions

	# GUI bs vars
	clear_variable = pb_s_frame
	clear_variable = pb_p_frame
	clear_variable = m_w_spiv
	clear_variable = m_w_cult
	clear_variable = m_w_pop
	clear_variable = m_c_spiv
	clear_variable = m_c_cult
	clear_variable = m_c_pop
	clear_variable = m_e_spiv
	clear_variable = m_e_cult
	clear_variable = m_e_pop
}

# Election Update
FUK_election_update = {
	FUK_election_predict = yes
	FUK_election_shuffle_actions = yes
	FUK_election_gui_update = yes
}

# Election GUI Update
# - Excuse the terrible variables names
#   - These all would otherwise be temp vars defined in the scripted gui file, but because decisions suck they're raw vars.
#   - I did not bother to change the temp var names
FUK_election_gui_update = {
	## Progress Bar
	# ProgBar - Spivavtor
	set_variable = { pb_s_frame = spivavtor_expected_seats }
	divide_variable = { pb_s_frame = total_seats }
	multiply_variable = { pb_s_frame = 100 }
	round_variable = pb_s_frame

	# ProgBar - Populists
	set_variable = { pb_p_frame = populists_expected_seats }
	divide_variable = { pb_p_frame = total_seats }
	multiply_variable = { pb_p_frame = 100 }
	round_variable = pb_p_frame

	## Map - Notation
	# - The Map frame stuff works off of the shader specifications
	# - That is, the shader receives frames in the format SSSEEE
	# - Where, SSS is a 3-digit max start position (between 0 - 100) and EEE is the same for the end position.
	#   - These values are whole numbers, because the frame argument does not pass decimal values.
	# - We make this variables by having a few assumptions;
	#   - Spivavtor's pie chart always begins at 0 and ends at it's popularity
	#   - Culturalist's pie chart always begins at Spivavtor's popularity and ends and it *and* Spivavtor's Popularity
	#   - Populist's pie chart always begins at Spivavtor's *and* Culturalist's popularity and ends at 100.
	# - These imply that;
	#   - Spivavtor's frame will always be of the form 000XXX
	#   - Culturalist's frame will always be of the form XXXYYY (where YYY is a sum of XXX and another number)
	#   - Populist's frame will always be of the form YYY100
	# - Example of a popularity situation and the pie chart it'd produce:
	#   - Spiv @ 30% pop, Cult @ 40% pop, Pop @ 25% pop
	#   - Spiv would generate "frame = 30"
	#   - Cult would generate "frame = 3060"
	#   - Pop would generate "frame = 60100"
	# - Another example,
	#   - Spiv @ 100% pop, Cult & Pop @ 0% pop
	#   - Spiv would generate "frame = 100"
	#   - Cult & Pop would generate "frame = 1000" (functionally equivalent to 0)

	## Map - West
	# Spiv
	set_variable 		= { m_w_spiv = 0 }
	multiply_variable 	= { m_w_spiv = 1000 }
	add_to_variable 	= { m_w_spiv = var:93.coalition_pop^0 }
	multiply_variable 	= { m_w_spiv = 100 }

	# Cult
	set_variable		= { m_w_cult = var:93.coalition_pop^0 }
	multiply_variable	= { m_w_cult = 1000 }
	add_to_variable		= { m_w_cult = var:93.coalition_pop^0 }
	add_to_variable		= { m_w_cult = var:93.coalition_pop^1 }
	multiply_variable	= { m_w_cult = 100 }

	# Pop
	set_variable 		= { m_w_pop = var:93.coalition_pop^0 }
	add_to_variable		= { m_w_pop = var:93.coalition_pop^1 }
	multiply_variable	= { m_w_pop = 1000 }
	add_to_variable		= { m_w_pop = 1 }
	multiply_variable	= { m_w_pop = 100 }

	## Map - Central
	# Spiv
	set_variable 		= { m_c_spiv = 0 }
	multiply_variable 	= { m_c_spiv = 1000 }
	add_to_variable 	= { m_c_spiv = var:202.coalition_pop^0 }
	multiply_variable 	= { m_c_spiv = 100 }

	# Cult
	set_variable		= { m_c_cult = var:202.coalition_pop^0 }
	multiply_variable	= { m_c_cult = 1000 }
	add_to_variable		= { m_c_cult = var:202.coalition_pop^0 }
	add_to_variable		= { m_c_cult = var:202.coalition_pop^1 }
	multiply_variable	= { m_c_cult = 100 }

	# Pop
	set_variable 		= { m_c_pop = var:202.coalition_pop^0 }
	add_to_variable		= { m_c_pop = var:202.coalition_pop^1 }
	multiply_variable	= { m_c_pop = 1000 }
	add_to_variable		= { m_c_pop = 1 }
	multiply_variable	= { m_c_pop = 100 }

	## Map - East
	# Spiv
	set_variable 		= { m_e_spiv = 0 }
	multiply_variable 	= { m_e_spiv = 1000 }
	add_to_variable 	= { m_e_spiv = var:227.coalition_pop^0 }
	multiply_variable 	= { m_e_spiv = 100 }

	# Cult
	set_variable		= { m_e_cult = var:227.coalition_pop^0 }
	multiply_variable	= { m_e_cult = 1000 }
	add_to_variable		= { m_e_cult = var:227.coalition_pop^0 }
	add_to_variable		= { m_e_cult = var:227.coalition_pop^1 }
	multiply_variable	= { m_e_cult = 100 }

	# Pop
	set_variable 		= { m_e_pop = var:227.coalition_pop^0 }
	add_to_variable		= { m_e_pop = var:227.coalition_pop^1 }
	multiply_variable	= { m_e_pop = 1000 }
	add_to_variable		= { m_e_pop = 1 }
	multiply_variable	= { m_e_pop = 100 }

	# Dirty Var (the important part)
	add_to_variable = { TNO_FUK_election_gui_dirty = 1 }
}

# Election Predict
# - Mostly for the ProgBar
FUK_election_predict = {
	log = "[GetDate]: [GetTag]: FUK Election Predict; Executing."

	set_variable = { total_seats = 0 }
	set_variable = { spivavtor_expected_seats = 0 }
	set_variable = { culturalists_expected_seats = 0 }
	set_variable = { populists_expected_seats = 0 }

	for_each_scope_loop = {
		array = FUK_election_regions

		log = "[THIS.GetName]: Seats: [?seats]"
		add_to_variable = { PREV.total_seats = seats }

		# Spivavtor
		set_temp_variable = { t_seats = seats }
		multiply_temp_variable = { t_seats = coalition_pop^0 }
		log = "[THIS.GetName]: Spivavtor Seats: [?t_seats]"
		add_to_variable = { PREV.spivavtor_expected_seats = t_seats }

		# Culturalist
		set_temp_variable = { t_seats = seats }
		multiply_temp_variable = { t_seats = coalition_pop^1 }
		log = "[THIS.GetName]: Culturalist Seats: [?t_seats]"
		add_to_variable = { PREV.culturalists_expected_seats = t_seats }

		# Populist
		set_temp_variable = { t_seats = seats }
		multiply_temp_variable = { t_seats = coalition_pop^2 }
		log = "[THIS.GetName]: Populist Seats: [?t_seats]"
		add_to_variable = { PREV.populists_expected_seats = t_seats }
	}

	log = "[GetDate]: [GetTag]: FUK Election Predict; Total Seats:       [?total_seats]"
	log = "[GetDate]: [GetTag]: FUK Election Predict; Spivavtor Seats:   [?spivavtor_expected_seats]"
	log = "[GetDate]: [GetTag]: FUK Election Predict; Culturalist Seats: [?culturalists_expected_seats]"
	log = "[GetDate]: [GetTag]: FUK Election Predict; Populist Seats:    [?populists_expected_seats]"
	log = "[GetDate]: [GetTag]: FUK Election Predict; Completed."
}

# Election Shuffle Actions
# - Shuffles actions for each region.
FUK_election_shuffle_actions = {
	log = "[GetDate]: [GetTag]: FUK Election Shuffle Actions; Executing."

	# Constants
	@NUM_MAX_ACTIONS = 3
	@NUM_POSSIBLE_ACTIONS = 11 # Increase this when adding new decisions (to the overall # of decisions)

	# Actual effect, avoid changing
	for_each_scope_loop = {
		array = FUK_election_regions

		clear_array = possible_actions
		for_loop_effect = {
			end = @NUM_MAX_ACTIONS

			set_temp_variable = { r = random }
			multiply_temp_variable = { r = @NUM_POSSIBLE_ACTIONS }
			round_temp_variable = r
			add_to_array = { possible_actions = r }
		}
	}

	log = "[GetDate]: [GetTag]: FUK Election Shuffle Actions; Completed."
}

# Election Change Pop
# | Receives:
# | t_region, state id
# | t_target, enum
#   | 0 = Spivavtor
#   | 1 = Culturalists
#   | 2 = Populists
# | t_val, int
#
# Example Usage:
# | set_temp_variable = { t_region = var:West_region }
# | set_temp_variable = { t_target = target_culturalist }
# | set_temp_variable = { t_val = 5 }
# | FUK_election_change_pop = yes
FUK_election_change_pop = {
	log = "[GetDate]: [GetTag]: FUK Election Change Pop"

	# Verify Input
	if = {
		limit = {
			OR = {
				# t_region
				NOT = {
					has_variable = t_region
					is_in_array = { FUK_election_regions = t_region }
				}

				# t_target
				NOT = {
					has_variable = t_target
					OR = {
						check_variable = { t_target = 0 }
						check_variable = { t_target = 1 }
						check_variable = { t_target = 2 }
					}
				}

				# t_val
				NOT = {
					has_variable = t_val
				}
			}
		}

		custom_effect_tooltip = "§rFUK Election Change Pop | Error!§!"
	}

	# Actual effect
	else = {
		custom_effect_tooltip = FUK_election_change_pop_tt
		var:t_region = { add_to_variable = { coalition_pop^t_target = t_val } }
		FUK_election_balance_pop = yes
		FUK_election_update = yes
	}
}

# Election Balance Pop
# - This balances
# | Receives:
# | t_region, state id
# | t_target, enum, optional
#   | 0 = Spivavtor
#   | 1 = Culturalists
#   | 2 = Populists
FUK_election_balance_pop = {
	log = "[GetDate]: [GetTag]: FUK Election Balance Pop"

	# Verify Input
	# - may not be necessary so disabled 4 now
	if = {
		limit = {
			always = no
		}
		custom_effect_tooltip = "§rFUK Election Balance Pop | Error!§!"
	}

	# Balance
	# - Works like so;
	#   - Sum up every coalition's popularity
	#   - Subtract by 1
	#     - If that value is positive, sum was over 1 (we need to remove)
	#     - If its negative, sum was under 1 (we need to add)
	#   - Divide remainder by 2 & multiply by -1
	#   - Add remainder to coalition pop's *other* than target
	#     - This should inverse the disproportionality made by changes to t_target
	#     - e.g. if target is culturalists, then add remainder to spivavtor & populists
	else = {
		var:t_region = {
			log = "[GetDate]: [GetTag]: FUK Election Balance Pop; Spiv: [?coalition_pop^0]"
			log = "[GetDate]: [GetTag]: FUK Election Balance Pop; Cult: [?coalition_pop^1]"
			log = "[GetDate]: [GetTag]: FUK Election Balance Pop; Pop : [?coalition_pop^2]"
			set_temp_variable = { sum = coalition_pop^0 }
			add_to_temp_variable = { sum = coalition_pop^1 }
			add_to_temp_variable = { sum = coalition_pop^2 }
			log = "[GetDate]: [GetTag]: FUK Election Balance Pop; Sum : [?sum]"

			if = {
				limit = { NOT = { check_variable = { sum = 1 } } }

				subtract_from_temp_variable = { sum = 1 }
				divide_temp_variable = { sum = 2 }
				multiply_temp_variable = { sum = -1 }

				for_each_loop = {
					array = coalition_pop
					value = v
					index = i

					if = {
						limit = { NOT = { check_variable = { i = t_target } } }
						add_to_variable = { coalition_pop^i = sum }
						clamp_variable = { var = coalition_pop^i min = 0 max = 1 }
						#FUK_election_balance_pop = yes
					}
					else_if = {
						limit = { check_variable = { i = t_target } }
						clamp_variable = { var = coalition_pop^i min = 0 max = 1 }
					}
				}
			}
		}
	}
}

# Election Change Political Capital
# - Shell for a tooltip, not a whole lot more.
# Receives
# | t_val
FUK_election_change_political_capital = {
	custom_effect_tooltip = FUK_election_change_pc_tt
	add_to_variable = { FUK_political_capital = t_val }
	clamp_variable = { var = FUK_political_capital min = 0 }
}

## 4.2 - Culturalist Mechanics
UKR_culture_initialize = {
	set_variable = { UKR_culture_active = 1 }
	set_variable = { UKR_culture_trident_lvl = 1 }
	set_variable = { UKR_culture_poland_lvl = 1 }
	set_variable = { UKR_culture_tatar_lvl = 1 }
}

### 5.0.0 - UPA (BOV) Scripted Effects ###
## 5.1 - Three Heads of the Dragon Scripted Effects ##

## Three Heads of the Dragon ##

BOV_initialize_three_heads_of_the_dragon = {
	set_variable = { BOV_klyachkivsky_power = 60 }
	set_variable = { BOV_shukhevych_power = 25 }
	set_variable = { BOV_stetsko_power = 15 }

	set_variable = { BOV_sway_officers_cost = 10 }

	set_country_flag = UKR_BOV_three_heads_of_the_dragon

	BOV_three_heads_of_the_dragon_math = yes
}

BOV_three_heads_of_the_dragon_math = {
	hidden_effect = {
		set_variable = { BOV_klyachkivsky_power_display = BOV_klyachkivsky_power }

		set_variable = { BOV_shukhevych_power_display = BOV_klyachkivsky_power_display }
		add_to_variable = { BOV_shukhevych_power_display = BOV_shukhevych_power }

		set_variable = { BOV_stetsko_power_display = BOV_shukhevych_power_display }
		add_to_variable = { BOV_stetsko_power_display = BOV_stetsko_power }

		clamp_variable = { var = BOV_klyachkivsky_power min = 0 max = 100 }
		clamp_variable = { var = BOV_shukhevych_power min = 0 max = 100 }
		clamp_variable = { var = BOV_stetsko_power min = 0 max = 100 }

		clamp_variable = { var = BOV_klyachkivsky_power_display min = 0 max = 100 }
		clamp_variable = { var = BOV_shukhevych_power_display min = 0 max = 100 }
		clamp_variable = { var = BOV_stetsko_power_display min = 0 max = 100 }

		remove_ideas = {
			UKR_BOV_klyachkivsky_dominant
			UKR_BOV_shukhevych_dominant
			UKR_BOV_stetsko_dominant
		}

		if = {
			limit = {
				original_tag = BOV
			}
			if = {
				limit = {
					check_variable = { BOV_klyachkivsky_power > BOV_shukhevych_power }
					check_variable = { BOV_klyachkivsky_power > BOV_stetsko_power }
				}
				if = {
					limit = {
						has_idea = UKR_BOV_shukhevych_dominant
					}
					swap_ideas = {
						remove_idea = UKR_BOV_shukhevych_dominant
						add_idea = UKR_BOV_klyachkivsky_dominant
					}
				}
				else_if = {
					limit = {
						has_idea = UKR_BOV_stetsko_dominant
					}
					swap_ideas = {
						remove_idea = UKR_BOV_stetsko_dominant
						add_idea = UKR_BOV_klyachkivsky_dominant
					}
				}
				else = {
					add_ideas = UKR_BOV_klyachkivsky_dominant
				}
			}
			else_if = {
				limit = {
					check_variable = { BOV_shukhevych_power > BOV_klyachkivsky_power }
					check_variable = { BOV_shukhevych_power > BOV_stetsko_power }
				}
				if = {
					limit = {
						has_idea = UKR_BOV_klyachkivsky_dominant
					}
					swap_ideas = {
						remove_idea = UKR_BOV_klyachkivsky_dominant
						add_idea = UKR_BOV_shukhevych_dominant
					}
				}
				else_if = {
					limit = {
						has_idea = UKR_BOV_stetsko_dominant
					}
					swap_ideas = {
						remove_idea = UKR_BOV_stetsko_dominant
						add_idea = UKR_BOV_shukhevych_dominant
					}
				}
				else = {
					add_ideas = UKR_BOV_shukhevych_dominant
				}
			}
			else_if = {
				limit = {
					check_variable = { BOV_stetsko_power > BOV_shukhevych_power }
					check_variable = { BOV_stetsko_power > BOV_klyachkivsky_power }
				}
				if = {
					limit = {
						has_idea = UKR_BOV_shukhevych_dominant
					}
					swap_ideas = {
						remove_idea = UKR_BOV_shukhevych_dominant
						add_idea = UKR_BOV_stetsko_dominant
					}
				}
				else_if = {
					limit = {
						has_idea = UKR_BOV_klyachkivsky_dominant
					}
					swap_ideas = {
						remove_idea = UKR_BOV_klyachkivsky_dominant
						add_idea = UKR_BOV_stetsko_dominant
					}
				}
				else = {
					add_ideas = UKR_BOV_stetsko_dominant
				}
			}
		}
		
		set_variable = { BOV_klyachkivsky_dynmod = BOV_klyachkivsky_power }
		divide_variable = { BOV_klyachkivsky_dynmod = 500 }
		set_variable = { BOV_shukhevych_dynmod = BOV_shukhevych_power }
		divide_variable = { BOV_shukhevych_dynmod = -5 }
		set_variable = { BOV_stetsko_dynmod = BOV_stetsko_power }
		divide_variable = { BOV_stetsko_dynmod = 2500 }
	}
}

BOV_add_klyachkivsky_power = {
	add_to_variable = { BOV_klyachkivsky_power = BOV_klyachkivsky_power_temp }
	if = {
		limit = { check_variable = { BOV_shukhevych_power < BOV_stetsko_power } }
		subtract_from_variable = { BOV_stetsko_power = BOV_klyachkivsky_power_temp }

		if = {
			limit = { check_variable = { BOV_stetsko_power < 0 } }
			set_temp_variable = { BOV_negative_temp = BOV_stetsko_power }
			add_to_variable = { BOV_shukhevych_power = BOV_negative_temp }
		}
	}
	else = {
		subtract_from_variable = { BOV_shukhevych_power = BOV_klyachkivsky_power_temp }

		if = {
			limit = { check_variable = { BOV_shukhevych_power < 0 } }
			set_temp_variable = { BOV_negative_temp = BOV_shukhevych_power }
			add_to_variable = { BOV_stetsko_power = BOV_negative_temp }
		}
	}
	custom_effect_tooltip = BOV_add_klyachkivsky_power_tt

	BOV_three_heads_of_the_dragon_math = yes
}

BOV_add_shukhevych_power = {
	add_to_variable = { BOV_shukhevych_power = BOV_shukhevych_power_temp }
	if = {
		limit = { check_variable = { BOV_klyachkivsky_power < BOV_stetsko_power } }
		subtract_from_variable = { BOV_stetsko_power = BOV_shukhevych_power_temp }

		if = {
			limit = { check_variable = { BOV_stetsko_power < 0 } }
			set_temp_variable = { BOV_negative_temp = BOV_stetsko_power }
			add_to_variable = { BOV_klyachkivsky_power = BOV_negative_temp }
		}
	}
	else = {
		subtract_from_variable = { BOV_klyachkivsky_power = BOV_shukhevych_power_temp }

		if = {
			limit = { check_variable = { BOV_klyachkivsky_power < 0 } }
			set_temp_variable = { BOV_negative_temp = BOV_klyachkivsky_power }
			add_to_variable = { BOV_stetsko_power = BOV_negative_temp }
		}
	}
	custom_effect_tooltip = BOV_add_shukhevych_power_tt

	BOV_three_heads_of_the_dragon_math = yes
}

BOV_add_stetsko_power = {
	add_to_variable = { BOV_stetsko_power = BOV_stetsko_power_temp }
	if = {
		limit = { check_variable = { BOV_klyachkivsky_power < BOV_shukhevych_power } }
		subtract_from_variable = { BOV_shukhevych_power = BOV_stetsko_power_temp }

		if = {
			limit = { check_variable = { BOV_shukhevych_power < 0 } }
			set_temp_variable = { BOV_negative_temp = BOV_shukhevych_power }
			add_to_variable = { BOV_klyachkivsky_power = BOV_negative_temp }
		}
	}
	else = {
		subtract_from_variable = { BOV_klyachkivsky_power = BOV_stetsko_power_temp }

		if = {
			limit = { check_variable = { BOV_klyachkivsky_power < 0 } }
			set_temp_variable = { BOV_negative_temp = BOV_klyachkivsky_power }
			add_to_variable = { BOV_shukhevych_power = BOV_negative_temp }
		}
	}
	custom_effect_tooltip = BOV_add_stetsko_power_tt

	BOV_three_heads_of_the_dragon_math = yes
}

BOV_add_klyachkivsky_power_flat = {
	add_to_variable = { BOV_klyachkivsky_power = BOV_klyachkivsky_power_temp }
	custom_effect_tooltip = BOV_add_klyachkivsky_power_tt

	BOV_three_heads_of_the_dragon_math = yes
}

BOV_add_shukhevych_power_flat = {
	add_to_variable = { BOV_shukhevych_power = BOV_shukhevych_power_temp }
	custom_effect_tooltip = BOV_add_shukhevych_power_tt

	BOV_three_heads_of_the_dragon_math = yes
}

BOV_add_stetsko_power_flat = {
	add_to_variable = { BOV_stetsko_power = BOV_stetsko_power_temp }
	custom_effect_tooltip = BOV_add_stetsko_power_tt

	BOV_three_heads_of_the_dragon_math = yes
}

UKR_remove_BOV_gui = { #get rid of the GUI for UKR once the Stetsko Coup Ends
	clr_country_flag = UKR_BOV_three_heads_of_the_dragon
	set_variable = { BOV_klyachkivsky_power = 0 }
	set_variable = { BOV_shukhevych_power = 0 }
	set_variable = { BOV_stetsko_power = 0 }

	set_variable = { BOV_sway_officers_cost = 0 }

	remove_mission = BOV_three_heads_of_the_dragon_ai_influence
}

## 5.2 - Galicia War ##
UKR_Victory_GalicianWar = {
	clr_global_flag = UKS_POL_GalicianWar
	clr_global_flag = BOV_POL_GalicianWar_Klyachkivsky
	clr_global_flag = BOV_POL_GalicianWar_Stetsko
	clr_global_flag = BOV_POL_GalicianWar_Shukhevych
	ROOT = {
		white_peace = FROM
	}
	FROM = {
		every_owned_state = {
			limit = {
				OR = {
					check_variable = { nationality = 164 }
					check_variable = { nationality = 380 }
				}
			}
			ROOT = { transfer_state = PREV }
			if = {
				limit = { check_variable = { nationality = 164 } }
				add_core_of = BOV
			}
			else = {
				set_compliance = 50
			}
		}
	}

}

### 6.0 - Republic of Ukraine UCW Mechanic Scripted Effects ###

# Republic Power Struggle

UKR_initialize_FUK_power_struggle_gui = {
	set_country_flag = UKR_FUK_power_struggle
	set_variable = { var_partisan_support = 75 }
	set_variable = { var_populist_support = 55 }
	set_variable = { var_collaborator_support = 35 }
	add_dynamic_modifier = { modifier = FUK_power_struggle_unified_dynmod }
	hidden_effect = {
		add_dynamic_modifier = { modifier = FUK_power_struggle_RK_manpower_dynmod }
	}
	clamp_variable = { var = var_partisan_support min = 0 max = 100 }
	clamp_variable = { var = var_populist_support min = 0 max = 100 }
	clamp_variable = { var = var_collaborator_support min = 0 max = 100 }
	UKR_FUK_power_strugle_update = yes

	set_variable = { FUK_pillar_decay = -5 }

	activate_mission = FUK_pillars_decay
}

FUK_initialize_FUK_power_struggle_gui_player = { #give the mechanic to FUK if it IS player-controlled - uses UKR variables
	set_country_flag = UKR_FUK_power_struggle
	add_dynamic_modifier = { modifier = FUK_power_struggle_unified_dynmod }
	set_variable = { var_partisan_support = UKR.var_partisan_support }
	set_variable = { var_populist_support = UKR.var_populist_support }
	set_variable = { var_collaborator_support = UKR.var_collaborator_support }
	clamp_variable = { var = var_partisan_support min = 0 max = 100 }
	clamp_variable = { var = var_populist_support min = 0 max = 100 }
	clamp_variable = { var = var_collaborator_support min = 0 max = 100 }
	UKR_FUK_power_strugle_update = yes

	set_variable = { FUK_pillar_decay = UKR.FUK_pillar_decay }

	activate_mission = FUK_pillars_decay
}

FUK_initialize_FUK_power_struggle_gui_ai = { #give the mechanic to FUK if it is NOT player-controlled - uses set variables
	set_country_flag = UKR_FUK_power_struggle
	add_dynamic_modifier = { modifier = FUK_power_struggle_unified_dynmod }
	set_variable = { var_partisan_support = 75 }
	set_variable = { var_populist_support = 55 }
	set_variable = { var_collaborator_support = 35 }
	clamp_variable = { var = var_partisan_support min = 0 max = 100 }
	clamp_variable = { var = var_populist_support min = 0 max = 100 }
	clamp_variable = { var = var_collaborator_support min = 0 max = 100 }
	UKR_FUK_power_strugle_update = yes

	set_variable = { FUK_pillar_decay = -5 }

	activate_mission = FUK_pillars_decay
}

UKR_remove_FUK_gui = { #get rid of the GUI for UKR once the UCW begins
	clr_country_flag = UKR_FUK_power_struggle
	#add_dynamic_modifier = { modifier = FUK_power_struggle_partisan_dynamod }
	#add_dynamic_modifier = { modifier = FUK_power_struggle_populist_dynamod }
	#add_dynamic_modifier = { modifier = FUK_power_struggle_collaborator_dynamod }
	set_variable = { var_partisan_support = 0 }
	set_variable = { var_populist_support = 0 }
	set_variable = { var_collaborator_support = 0 }

	set_variable = { FUK_pillar_decay = 0 }

	remove_mission = FUK_pillars_decay
}

UKR_FUK_power_strugle_update = {
	FUK_power_struggle_partisan_dynamod_update = yes
	FUK_power_struggle_populist_dynamod_update = yes
	FUK_power_struggle_collaborator_dynamod_update = yes
}

FUK_partisan_support_change = {
	add_to_variable = { var_partisan_support = var_partisan_support_temp }
	clamp_variable = { var = var_partisan_support min = 0 max = 100 }
	custom_effect_tooltip = FUK_partisan_support_change_tt

	UKR_FUK_power_strugle_update = yes
}

FUK_populist_support_change = {
	add_to_variable = { var_populist_support = var_populist_support_temp }
	clamp_variable = { var = var_populist_support min = 0 max = 100 }
	custom_effect_tooltip = FUK_populist_support_change_tt

	UKR_FUK_power_strugle_update = yes
}

FUK_collaborator_support_change = {
	add_to_variable = { var_collaborator_support = var_collaborator_support_temp }
	clamp_variable = { var = var_collaborator_support min = 0 max = 100 }
	custom_effect_tooltip = FUK_collaborator_support_change_tt

	UKR_FUK_power_strugle_update = yes
}

FUK_power_struggle_collaborator_dynamod_update = {
	set_variable = { FUK_collaborator_pp_bonus = var_collaborator_support }
	set_variable = { FUK_collaborator_manpower_bonus = var_collaborator_support }
	set_variable = { FUK_collaborator_anocracy_bonus = var_collaborator_support }
	set_variable = { FUK_collaborator_fascism_bonus = var_collaborator_support }
	set_variable = { FUK_collaborator_manpower_RK_bonus = var_collaborator_support }

	if = {
		limit = { check_variable = { FUK_collaborator_pp_bonus > 50 } }
		multiply_variable = { FUK_collaborator_pp_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_collaborator_pp_bonus = 0.01 }
		add_to_variable = { FUK_collaborator_pp_bonus = -0.5 }
	}
	if = {
		limit = { check_variable = { FUK_collaborator_manpower_bonus > 50 } }
		multiply_variable = { FUK_collaborator_manpower_bonus = 15 }
	}
	else = {
		multiply_variable = { FUK_collaborator_manpower_bonus = 15 }
		add_to_variable = { FUK_collaborator_manpower_bonus = -1500 }
	}
	if = {
		limit = { check_variable = { FUK_collaborator_manpower_RK_bonus > 50 } }
		multiply_variable = { FUK_collaborator_manpower_RK_bonus = -15 }
	}
	else = {
		multiply_variable = { FUK_collaborator_manpower_RK_bonus = -15 }
		add_to_variable = { FUK_collaborator_manpower_RK_bonus = 1500 }
	}
	if = {
		limit = { check_variable = { FUK_collaborator_anocracy_bonus > 50 } }
		multiply_variable = { FUK_collaborator_anocracy_bonus = 0.05 }
		multiply_variable = { FUK_collaborator_anocracy_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_collaborator_anocracy_bonus = 0.05 }
		multiply_variable = { FUK_collaborator_anocracy_bonus = 0.01 }
		add_to_variable = { FUK_collaborator_anocracy_bonus = -0.05 }
	}
	if = {
		limit = { check_variable = { FUK_collaborator_fascism_bonus > 50 } }
		set_variable = { FUK_collaborator_fascism_bonus = 0 }
	}
	else = {
		multiply_variable = { FUK_collaborator_fascism_bonus = -0.05 }
		multiply_variable = { FUK_collaborator_fascism_bonus = 0.01 }
		add_to_variable = { FUK_collaborator_fascism_bonus = 0.05 }
	}

	force_update_dynamic_modifier = yes
}

FUK_power_struggle_populist_dynamod_update = {
	set_variable = { FUK_populist_stability_bonus = var_populist_support }
	set_variable = { FUK_populist_war_support_bonus = var_populist_support }
	set_variable = { FUK_populist_socialist_bonus = var_populist_support }
	set_variable = { FUK_populist_communist_bonus = var_populist_support }

	if = {
		limit = { check_variable = { FUK_populist_stability_bonus > 50 } }
		multiply_variable = { FUK_populist_stability_bonus = 0.25 }
		multiply_variable = { FUK_populist_stability_bonus = 0.1 }
		multiply_variable = { FUK_populist_stability_bonus = 0.1 }
	}
	else = {
		multiply_variable = { FUK_populist_stability_bonus = 0.25 }
		multiply_variable = { FUK_populist_stability_bonus = 0.1 }
		multiply_variable = { FUK_populist_stability_bonus = 0.1 }
		add_to_variable = { FUK_populist_stability_bonus = -0.25 }
	}
	if = {
		limit = { check_variable = { FUK_populist_war_support_bonus > 50 } }
		multiply_variable = { FUK_populist_war_support_bonus = 0.25 }
		multiply_variable = { FUK_populist_war_support_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_populist_war_support_bonus = 0.25 }
		multiply_variable = { FUK_populist_war_support_bonus = 0.01 }
		add_to_variable = { FUK_populist_war_support_bonus = -0.25 }
	}
	if = {
		limit = { check_variable = { FUK_populist_socialist_bonus > 50 } }
		multiply_variable = { FUK_populist_socialist_bonus = 0.05 }
		multiply_variable = { FUK_populist_socialist_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_populist_socialist_bonus = 0.05 }
		multiply_variable = { FUK_populist_socialist_bonus = 0.01 }
		add_to_variable = { FUK_populist_socialist_bonus = -0.05 }
	}
	if = {
		limit = { check_variable = { FUK_populist_communist_bonus > 50 } }
		set_variable = { FUK_populist_communist_bonus = 0 }
	}
	else = {
		multiply_variable = { FUK_populist_communist_bonus = -0.05 }
		multiply_variable = { FUK_populist_communist_bonus = 0.01 }
		add_to_variable = { FUK_populist_communist_bonus = 0.05 }
	}

	force_update_dynamic_modifier = yes

}

FUK_power_struggle_partisan_dynamod_update = {
	set_variable = { FUK_partisan_attack_bonus = var_partisan_support }
	set_variable = { FUK_partisan_defense_bonus = var_partisan_support }
	set_variable = { FUK_partisan_organisation_bonus = var_partisan_support }
	set_variable = { FUK_partisan_recovery_bonus = var_partisan_support }
	set_variable = { FUK_populist_progressivism_bonus = var_partisan_support }
	set_variable = { FUK_partisan_despotism_bonus = var_partisan_support }

	if = {
		limit = { check_variable = { FUK_partisan_attack_bonus > 50 } }
		multiply_variable = { FUK_partisan_attack_bonus = 0.25 }
		multiply_variable = { FUK_partisan_attack_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_partisan_attack_bonus = 0.25 }
		multiply_variable = { FUK_partisan_attack_bonus = 0.01 }
		add_to_variable = { FUK_partisan_attack_bonus = -0.25 }

	}
	if = {
		limit = { check_variable = { FUK_partisan_defense_bonus > 50 } }
		multiply_variable = { FUK_partisan_defense_bonus = 0.25 }
		multiply_variable = { FUK_partisan_defense_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_partisan_defense_bonus = 0.25 }
		multiply_variable = { FUK_partisan_defense_bonus = 0.01 }
		add_to_variable = { FUK_partisan_defense_bonus = -0.25 }
	}
	if = {
		limit = { check_variable = { FUK_partisan_organisation_bonus > 50 } }
		multiply_variable = { FUK_partisan_organisation_bonus = 0.25 }
		multiply_variable = { FUK_partisan_organisation_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_partisan_organisation_bonus = 0.25 }
		multiply_variable = { FUK_partisan_organisation_bonus = 0.01 }
		add_to_variable = { FUK_partisan_organisation_bonus = -0.25 }
	}
	if = {
		limit = { check_variable = { FUK_partisan_recovery_bonus > 50 } }
		multiply_variable = { FUK_partisan_recovery_bonus = 0.25 }
		multiply_variable = { FUK_partisan_recovery_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_partisan_recovery_bonus = 0.25 }
		multiply_variable = { FUK_partisan_recovery_bonus = 0.01 }
		add_to_variable = { FUK_partisan_recovery_bonus = -0.25 }
	}
	if = {
		limit = { check_variable = { FUK_populist_progressivism_bonus > 50 } }
		multiply_variable = { FUK_populist_progressivism_bonus = 0.05 }
		multiply_variable = { FUK_populist_progressivism_bonus = 0.01 }
	}
	else = {
		multiply_variable = { FUK_populist_progressivism_bonus = 0.05 }
		multiply_variable = { FUK_populist_progressivism_bonus = 0.01 }
		add_to_variable = { FUK_populist_progressivism_bonus = -0.05 }
	}
	if = {
		limit = { check_variable = { FUK_partisan_despotism_bonus > 50 } }
		set_variable = { FUK_partisan_despotism_bonus = 0 }
	}
	else = {
		multiply_variable = { FUK_partisan_despotism_bonus = -0.05 }
		multiply_variable = { FUK_partisan_despotism_bonus = 0.01 }
		add_to_variable = { FUK_partisan_despotism_bonus = 0.05 }
	}

	force_update_dynamic_modifier = yes
}

FUK_initialize_power_struggle = {
	set_country_flag = FUK_power_struggle
	set_variable = { FUK_partisan_power = 60 }
	set_variable = { FUK_populist_power = 45 }
	set_variable = { FUK_collab_power = 25 }

	# FUK_power_struggle_math = yes
}

FUK_power_struggle = {
	### Partisan dynmod

	set_variable = { FUK_partisan_power_dynmod = FUK_partisan_power }
	set_variable = { FUK_partisan_power_dynmod_opposition = FUK_partisan_power_dynmod }

	subtract_from_variable = { FUK_partisan_power_dynmod_opposition = 75 }
	if = {
		limit = { check_variable = { FUK_partisan_power_dynmod_opposition > 0 } }
		divide_variable = { FUK_partisan_power_dynmod_opposition = 100 }
	}
	else = {
		set_variable = { FUK_partisan_power_dynmod_opposition = 0 }
	}

	### Populist dynmod

	set_variable = { FUK_populist_power_dynmod = FUK_populist_power }
	set_variable = { FUK_populist_power_dynmod_opposition = FUK_populist_power_dynmod }

	subtract_from_variable = { FUK_populist_power_dynmod_opposition = 75 }
	if = {
		limit = { check_variable = { FUK_populist_power_dynmod_opposition > 0 } }
		divide_variable = { FUK_populist_power_dynmod_opposition = 100 }
	}
	else = {
		set_variable = { FUK_populist_power_dynmod_opposition = 0 }
	}

	### Collab dynmod

	set_variable = { FUK_collab_power_dynmod = FUK_collab_power }
	set_variable = { FUK_collab_power_dynmod_opposition = FUK_collab_power_dynmod }

	subtract_from_variable = { FUK_collab_power_dynmod_opposition = 75 }
	if = {
		limit = { check_variable = { FUK_collab_power_dynmod_opposition > 0 } }
		divide_variable = { FUK_collab_power_dynmod_opposition = 100 }
	}
	else = {
		set_variable = { FUK_collab_power_dynmod_opposition = 0 }
	}
}

#############################################################
# 7.0 - Ukrainian SSR The Revolutionary Will Scripted Effects #
#############################################################

# Base Values
@TrustWeeklyBase		= 0.1		# Base value for weekly Trust
@StabilityModifier		= 0.075		# Addition modifier based on Stability
@AdminSpendModifier		= 0.045		# Addition modifier based on Administrative spending
@SocialSpendModifier	= 0.045		# Addition modifier based on Social spending
@OfficeCovModifier		= 0.075		# Addition modifier based on Office building coverage (neg)
@SocialCovModifier		= 0.05		# Addition modifier based on School/Hospital building coverage (pos)

UKS_Revolutionary_Will_Activate = {
	log = "[GetDateText]: [Root.GetName]: UKS_Revolutionary_Will_Activate; Executing."

	## Dumb thing used for image frames due to how the game handles them
	# COPYING THIS FROM KARTENHAUS - Lam why did you use this for all of the GUIs it makes it harder to figure out how this shit works :sob:
	clear_array = UKS_FrameArray
	add_to_array = { UKS_FrameArray = 1 }
	add_to_array = { UKS_FrameArray = 2 }
	add_to_array = { UKS_FrameArray = 3 }
	add_to_array = { UKS_FrameArray = 4 }
	add_to_array = { UKS_FrameArray = 5 }
	add_to_array = { UKS_FrameArray = 6 }
	add_to_array = { UKS_FrameArray = 7 }
	add_to_array = { UKS_FrameArray = 8 }
	add_to_array = { UKS_FrameArray = 9 }
	add_to_array = { UKS_FrameArray = 10 }

	## Setup arrays & variables
	clear_variable = UKS_Trust
	clear_variable = UKS_Authority

	clear_array = UKS_TrustThreshold
	clear_array = UKS_TrustEffects
	clear_array = UKS_AuthorityThreshold
	clear_array = UKS_AuthorityEffects

	add_to_array = { UKS_TrustEffects = 0 }
	resize_array = { UKS_TrustEffects = 15 }
	add_to_array = { UKS_AuthorityEffects = 0 }
	resize_array = { UKS_AuthorityEffects = 15 }

	set_variable = { UKS_CurrentThreshold_Trust = -1 }
	set_variable = { UKS_CurrentThreshold_Authority = -1 }

	## Setup starting values
	set_variable = { UKS_Trust = 55 }
	set_temp_variable = { y = party_popularity@communist }
	multiply_temp_variable = { y = 100 }
	set_variable = { UKS_authority = y }

	## Threshold positioning
	# Set arrays for positioning
	add_to_array = { UKS_TrustThreshold = 5 }
	add_to_array = { UKS_TrustThreshold = 15 }
	add_to_array = { UKS_TrustThreshold = 35 }
	add_to_array = { UKS_TrustThreshold = 50 }
	add_to_array = { UKS_TrustThreshold = 65 }
	add_to_array = { UKS_TrustThreshold = 80 }

	add_to_array = { UKS_AuthorityThreshold = 20 }
	add_to_array = { UKS_AuthorityThreshold = 35 }
	add_to_array = { UKS_AuthorityThreshold = 45 }
	add_to_array = { UKS_AuthorityThreshold = 60 }
	add_to_array = { UKS_AuthorityThreshold = 75 }
	add_to_array = { UKS_AuthorityThreshold = 95 }

	# X positioning is calculated by multiplying the progressbar horizontal size by the milestone's percentage value
	clear_array = UKS_TrustThreshold_X
	clear_array = UKS_AuthorityThreshold_X
	for_loop_effect = {
		start = 0
		end = 6
		value = threshold_idx

		# Trust
		set_temp_variable = { x = UKS_TrustThreshold^threshold_idx }
		divide_temp_variable = { x = 100 }
		multiply_temp_variable = { x = 400 } # Size of the progress bar
		round_temp_variable = x
		add_to_array = { UKS_TrustThreshold_X = x }

		# Authority
		set_temp_variable = { x = UKS_AuthorityThreshold^threshold_idx }
		divide_temp_variable = { x = 100 }
		multiply_temp_variable = { x = 400 } # Size of the progress bar
		round_temp_variable = x
		add_to_array = { UKS_AuthorityThreshold_X = x }
	}

	## Calculate effects
	hidden_effect = { #not going to do effects for now
		add_dynamic_modifier = { modifier = UKS_trust_dynamic_modifier }
		add_dynamic_modifier = { modifier = UKS_authority_dynamic_modifier }
	}
	UKS_Trust_ThresholdCheck = yes
	UKS_Authority_ThresholdCheck = yes

	## Remove initial alert #ADD THIS BACK IN LATER!!!
	#set_temp_variable = { alert_id = token:Alert_GER_DiscontentThreshold }
	#remove_TNO_alert = yes

	log = "[GetDateText]: [Root.GetName]: UKS_Revolutionary_Will_Activate; Completed execution."
}

# Applies Trust threshold effects
UKS_Trust_ThresholdCheck = {
	log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdCheck; Executing."

	UKS_Trust_ThresholdEffect_Clear = yes
	for_each_loop = {
		array = UKS_TrustThreshold
		if = {
			limit = { check_variable = { var = UKS_Trust value = v compare = greater_than_or_equals } }
			set_temp_variable = { ThresholdID = i }
			UKS_Trust_ThresholdEffect = yes
		}
		else = { set_temp_variable = { break = 1 } }
	}
	force_update_dynamic_modifier = yes

	#if = { # Check for alert #SET UP ALERTS LATER
	#	limit = { check_variable = { ThresholdID?-1 > BOR_CurrentThreshold_Partification } }
	#	set_variable = { BOR_CurrentThreshold_Partification = ThresholdID }
	#	set_temp_variable = { alert_id = token:Alert_GER_PartificationThreshold }
	#	set_temp_variable = { alert_data = BOR_CurrentThreshold_Partification }
	#	add_TNO_alert = yes
	#}

	log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdCheck; Completed execution."
}

# Applies Authority threshold effects
UKS_Authority_ThresholdCheck = {
	log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdCheck; Executing."

	UKS_Authority_ThresholdEffect_Clear = yes
	for_each_loop = {
		array = UKS_AuthorityThreshold
		if = {
			limit = { check_variable = { var = UKS_Authority value = v compare = greater_than_or_equals } }
			set_temp_variable = { ThresholdID = i }
			UKS_Authority_ThresholdEffect = yes
		}
		else = { set_temp_variable = { break = 1 } }
	}
	force_update_dynamic_modifier = yes
	log = "[GetDateText]: [Root.GetName]: ThresholdID: [?ThresholdID]"

	#if = { # Check for alert #SET UP ALERTS LATER
	#	limit = { check_variable = { ThresholdID?-1 > BOR_CurrentThreshold_Discontent } }
	#	set_variable = { BOR_CurrentThreshold_Discontent = ThresholdID }
	#	set_temp_variable = { alert_id = token:Alert_GER_DiscontentThreshold }
	#	set_temp_variable = { alert_data = BOR_CurrentThreshold_Discontent }
	#	add_TNO_alert = yes
	#}

	log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdCheck; Completed execution."
}

## Modify the Trust variable by a direct value
# Arguments: TrustChange
UKS_Modify_Trust = {
	log = "[GetDateText]: [Root.GetName]: UKS_Modify_Trust; Executing."
	log = "[GetDateText]: [THIS.GetName]: UKS_Modify_Trust; Given TrustChange: [?TrustChange]"

	multiply_temp_variable = { TrustChange = trust_gain_multiplier?1 }
	add_to_variable = { UKS_Trust = TrustChange }
	clamp_variable = { var = UKS_Trust min = 0 max = 100 }
	if = {
		limit = {
			check_variable = { TrustChange < 0 }
		}
		multiply_temp_variable = { TrustChange = -1 }
		custom_effect_tooltip = UKS_Lower_Trust_tt
	}
	else = {
		custom_effect_tooltip = UKS_Increase_Trust_tt
	}

	UKS_Trust_ThresholdCheck = yes

	log = "[GetDateText]: [Root.GetName]: UKS_Modify_Trust; Completed execution."
}
## Modify the Authority variable by a direct value (also adjusts communist party popularity)
# Arguments: AuthorityChange
UKS_Modify_Authority = {
	log = "[GetDateText]: [Root.GetName]: UKS_Modify_Authority; Executing."
	log = "[GetDateText]: [THIS.GetName]: UKS_Modify_Authority; Given AuthorityChange: [?AuthorityChange]"

	add_to_variable = { UKS_Authority = AuthorityChange }
	clamp_variable = { var = UKS_Authority min = 0 max = 100 }
	set_temp_variable = { AuthorityChangeIdeology = AuthorityChange }

	if = {
		limit = {
			check_variable = { AuthorityChange < 0 }
		}
		multiply_temp_variable = { AuthorityChange = -1 }
		custom_effect_tooltip = UKS_Lower_Authority_tt
	}
	else = {
		custom_effect_tooltip = UKS_Increase_Authority_tt
	}

	## multiply_temp_variable = { AuthorityChangeIdeology = 0.01 }
	## multiply_temp_variable = { AuthorityChangeIdeology = 0.5 }
	## add_popularity = { ideology = communist popularity = AuthorityChangeIdeology }

	UKS_Authority_ThresholdCheck = yes

	log = "[GetDateText]: [Root.GetName]: UKS_Modify_Authority; Completed execution."
}

UKS_Trust_ThresholdEffect = {
	## Trust Threshold effects
	if = { # Localized Open Rebellions (you fucked up big time)
		limit = { check_variable = { ThresholdID = 0 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdEffect; Trust Threshold 1 reached."
		set_variable = { UKS_TrustEffects^0  = 0.80  tooltip = UKS_Threshold_pp_cost_tt } # Daily PP Gain
		set_variable = { UKS_TrustEffects^1  = -0.2  tooltip = UKS_Threshold_recovery_rate_modifier_tt } # Division Recovery Rate
		set_variable = { UKS_TrustEffects^2  = -0.02 tooltip = UKS_Threshold_weekly_stability_tt } # Weekly Stability
		set_variable = { UKS_TrustEffects^3 = 0 } # Communism Drift
		set_variable = { UKS_TrustEffects^4 = 0 } # Voter Franchise Effectiveness Drift
		set_variable = { UKS_TrustEffects^5 = 0 } # Trade Unions Effectiveness Drift
		set_variable = { UKS_TrustEffects^6 = 0 } # Factory Output
		set_variable = { UKS_TrustEffects^7  = 0 } # Political Parties Effectiveness Drift
		set_variable = { UKS_TrustEffects^8  = 0 } # Press Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^9 = 0 } # Consumer Goods Factor
		set_variable = { UKS_TrustEffects^10 = 0 } # Trust Gain Multiplier
		set_variable = { UKS_TrustEffects^11 = 0 } # Industrial Regulations Effectiveness Drift
		set_variable = { UKS_TrustEffects^12 = 0 } # Religous Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^13 = 0 } # Mobilization Speed
	}
	else_if = { # Widespread Rioting
		limit = { check_variable = { ThresholdID = 1 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdEffect; Trust Threshold 2 reached."
		set_variable = { UKS_TrustEffects^0  = 0 } # Daily PP Gain
		set_variable = { UKS_TrustEffects^1  = 0 } # Division Recovery Rate
		set_variable = { UKS_TrustEffects^2  = 0 } # Weekly Stability
		set_variable = { UKS_TrustEffects^3 = -0.5   tooltip = UKS_Threshold_communism_drift_tt } # Communism Drift
		set_variable = { UKS_TrustEffects^4 = -3.00  tooltip = UKS_Threshold_vote_franchise_drift_tt } # Voter Franchise Effectiveness Drift
		set_variable = { UKS_TrustEffects^5 = -2.50  tooltip = UKS_Threshold_trade_unions_drift_tt } # Trade Unions Effectiveness Drift
		set_variable = { UKS_TrustEffects^6 = -0.30  tooltip = UKS_Threshold_industrial_capacity_factory_tt } # Factory Output
		set_variable = { UKS_TrustEffects^7  = 0 } # Political Parties Effectiveness Drift
		set_variable = { UKS_TrustEffects^8  = 0 } # Press Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^9 = 0 } # Consumer Goods Factor
		set_variable = { UKS_TrustEffects^10 = 0 } # Trust Gain Multiplier
		set_variable = { UKS_TrustEffects^11 = 0 } # Industrial Regulations Effectiveness Drift
		set_variable = { UKS_TrustEffects^12 = 0 } # Religous Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^13 = 0 } # Mobilization Speed
	}
	else_if = { # Shattered Public Trust
		limit = { check_variable = { ThresholdID = 2 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdEffect; Trust Threshold 3 reached."
		set_variable = { UKS_TrustEffects^0  = 0 } # Daily PP Gain
		set_variable = { UKS_TrustEffects^1  = 0 } # Division Recovery Rate
		set_variable = { UKS_TrustEffects^2  = 0 } # Weekly Stability
		set_variable = { UKS_TrustEffects^3 = 0 } # Communism Drift
		set_variable = { UKS_TrustEffects^4 = 0 } # Voter Franchise Effectiveness Drift
		set_variable = { UKS_TrustEffects^5 = 0 } # Trade Unions Effectiveness Drift
		set_variable = { UKS_TrustEffects^6 = 0 } # Factory Output
		set_variable = { UKS_TrustEffects^7  = -1.5  tooltip = UKS_Threshold_political_parties_drift_tt } # Political Parties Effectiveness Drift
		set_variable = { UKS_TrustEffects^8  = -2    tooltip = UKS_Threshold_press_rights_drift_tt } # Press Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^9 = 0.10   tooltip = UKS_Threshold_consumer_goods_production_tt } # Consumer Goods Factor
		set_variable = { UKS_TrustEffects^10 = -0.25 tooltip = UKS_Threshold_trust_gain_multiplier_tt } # Trust Gain Multiplier
		set_variable = { UKS_TrustEffects^11 = 0 } # Industrial Regulations Effectiveness Drift
		set_variable = { UKS_TrustEffects^12 = 0 } # Religous Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^13 = 0 } # Mobilization Speed
	}
	else_if = { # Functioning Participatory Institutions
		limit = { check_variable = { ThresholdID = 3 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdEffect; Trust Threshold 4 reached."
		set_variable = { UKS_TrustEffects^0 = -0.15 tooltip = UKS_Threshold_pp_cost_tt } # Political Power Cost
		set_variable = { UKS_TrustEffects^1  = 0 } # Division Recovery Rate
		set_variable = { UKS_TrustEffects^2  = 0 } # Weekly Stability
		set_variable = { UKS_TrustEffects^3 = 0.05  tooltip = UKS_Threshold_communism_drift_tt } # Communism Drift
		set_variable = { UKS_TrustEffects^4 = 3     tooltip = UKS_Threshold_vote_franchise_drift_tt } # Voter Franchise Effectiveness Drift
		set_variable = { UKS_TrustEffects^5 = 2     tooltip = UKS_Threshold_trade_unions_drift_tt } # Trade Unions Effectiveness Drift
		set_variable = { UKS_TrustEffects^6 = 0 } # Factory Output
		set_variable = { UKS_TrustEffects^7  = 0 } # Political Parties Effectiveness Drift
		set_variable = { UKS_TrustEffects^8  = 0 } # Press Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^9 = 0 } # Consumer Goods Factor
		set_variable = { UKS_TrustEffects^10 = 0 } # Trust Gain Multiplier
		set_variable = { UKS_TrustEffects^11 = 0 } # Industrial Regulations Effectiveness Drift
		set_variable = { UKS_TrustEffects^12 = 0 } # Religous Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^13 = 0 } # Mobilization Speed
	}
	else_if = { # Mass Engagement
		limit = { check_variable = { ThresholdID = 4 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdEffect; Trust Threshold 5 reached."
		set_variable = { UKS_TrustEffects^0  = 0 } # Daily PP Gain
		set_variable = { UKS_TrustEffects^1  = 0 } # Division Recovery Rate
		set_variable = { UKS_TrustEffects^2  = 0 } # Weekly Stability
		set_variable = { UKS_TrustEffects^3 = 0 } # Communism Drift
		set_variable = { UKS_TrustEffects^4 = 0 } # Voter Franchise Effectiveness Drift
		set_variable = { UKS_TrustEffects^5 = 0 } # Trade Unions Effectiveness Drift
		set_variable = { UKS_TrustEffects^6 = 0 } # Factory Output
		set_variable = { UKS_TrustEffects^7  = 0 } # Political Parties Effectiveness Drift
		set_variable = { UKS_TrustEffects^8 = 2     tooltip = UKS_Threshold_press_rights_drift_tt } # Press Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^9 = 0 } # Consumer Goods Factor
		set_variable = { UKS_TrustEffects^10 = 0 } # Trust Gain Multiplier
		set_variable = { UKS_TrustEffects^11 = 3    tooltip = UKS_Threshold_regulations_drift_tt } # Industrial Regulations Effectiveness Drift
		set_variable = { UKS_TrustEffects^12 = 3    tooltip = UKS_Threshold_religious_drift_tt } # Religous Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^13 = 0.25 tooltip = UKS_Threshold_mobilization_speed_tt } # Mobilization Speed
	}
	else_if = { # Durable Enthusiasism
		limit = { check_variable = { ThresholdID = 5 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Trust_ThresholdEffect; Trust Threshold 6 reached."
		set_variable = { UKS_TrustEffects^0 = -0.25 tooltip = UKS_Threshold_pp_cost_tt } # Political Power Cost
		set_variable = { UKS_TrustEffects^1 = 0.15  tooltip = UKS_Threshold_recovery_rate_modifier_tt } # Division Recovery Rate
		set_variable = { UKS_TrustEffects^2  = 0 } # Weekly Stability
		set_variable = { UKS_TrustEffects^3 = 0 } # Communism Drift
		set_variable = { UKS_TrustEffects^4 = 0 } # Voter Franchise Effectiveness Drift
		set_variable = { UKS_TrustEffects^5 = 0 } # Trade Unions Effectiveness Drift
		set_variable = { UKS_TrustEffects^6 = 0 } # Factory Output
		set_variable = { UKS_TrustEffects^7  = 0 } # Political Parties Effectiveness Drift
		set_variable = { UKS_TrustEffects^8  = 0 } # Press Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^9 = -0.10 tooltip = UKS_Threshold_consumer_goods_production_tt } # Consumer Goods Factor
		set_variable = { UKS_TrustEffects^10 = 0 } # Trust Gain Multiplier
		set_variable = { UKS_TrustEffects^11 = 0 } # Industrial Regulations Effectiveness Drift
		set_variable = { UKS_TrustEffects^12 = 0 } # Religous Rights Effectiveness Drift
		set_variable = { UKS_TrustEffects^13 = 0 } # Mobilization Speed
	}
}
UKS_Authority_ThresholdEffect = {
	## Authority Threshold effects
	if = { # Floundering Party Institutions
		limit = { check_variable = { ThresholdID = 0 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdEffect; Authority Threshold 1 reached."
		UKS_Authority_ThresholdEffect_Clear = yes
		set_variable = { UKS_AuthorityEffects^3  = -4.5 tooltip = UKS_Threshold_political_parties_drift_tt } # Political Party Effectiveness Drift
		set_variable = { UKS_AuthorityEffects^12 = 0.15 tooltip = UKS_Threshold_consumer_goods_production_tt } # Consumer Goods Factor
		set_variable = { UKS_AuthorityEffects^8  = -3   tooltip = UKS_Threshold_trade_unions_drift_tt } # Trade Unions Effectivness Drift
		set_variable = { UKS_AuthorityEffects^4  = 0.30 tooltip = UKS_Threshold_admin_program_cost_modifier_tt } # Admin Efficency Program Cost
	}
	else_if = { # Significant Party Factionalism
		limit = { check_variable = { ThresholdID = 1 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdEffect; Authority Threshold 2 reached."
		UKS_Authority_ThresholdEffect_Clear = yes
		set_variable = { UKS_AuthorityEffects^5 = -4    tooltip = UKS_Threshold_admin_efficiency_tt } # Admin Effectiveness Drift
		set_variable = { UKS_AuthorityEffects^7 = -3    tooltip = UKS_Threshold_vote_franchise_drift_tt } # Voting Rights Drift
		set_variable = { UKS_AuthorityEffects^6 = -0.10 tooltip = UKS_Threshold_army_org_factor_tt } # Division Organization
		set_variable = { UKS_AuthorityEffects^4 = 0.20  tooltip = UKS_Threshold_admin_program_cost_modifier_tt } # Administrative Program Cost Factor
	}
	else_if = { # Broad Local Control
		limit = { check_variable = { ThresholdID = 2 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdEffect; Authority Threshold 3 reached."
		UKS_Authority_ThresholdEffect_Clear = yes
		#No effects on purpose!
	}
	else_if = { # Active Political Opposition
		limit = { check_variable = { ThresholdID = 3 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdEffect; Authority Threshold 4 reached."
		UKS_Authority_ThresholdEffect_Clear = yes
		set_variable = { UKS_AuthorityEffects^13 = 0.10   tooltip = UKS_Threshold_trust_gain_multiplier_tt } # Trust Gain Multiplier
		set_variable = { UKS_AuthorityEffects^1  = -0.015 tooltip = UKS_Threshold_drift_defence_factor_tt } # Drift Defense Factor
		set_variable = { UKS_AuthorityEffects^14 = -0.12  tooltip = UKS_Threshold_communism_drift_tt } # Communism Drift
	}
	else_if = { # Dominant Party Organizations
		limit = { check_variable = { ThresholdID = 4 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdEffect; Authority Threshold 5 reached."
		UKS_Authority_ThresholdEffect_Clear = yes
		set_variable = { UKS_AuthorityEffects^3  = 2     tooltip = UKS_Threshold_political_parties_drift_tt } # Political Parties Effectiveness Drift
		set_variable = { UKS_AuthorityEffects^11 = 3.5   tooltip = UKS_Threshold_religious_drift_tt } # Religous Rights Effectiveness Drift
		set_variable = { UKS_AuthorityEffects^0  = -0.20 tooltip = UKS_Threshold_pp_cost_tt } # Political Power Cost
	}
	else_if = { # Merger of Party and State
		limit = { check_variable = { ThresholdID = 5 } }
		log = "[GetDateText]: [Root.GetName]: UKS_Authority_ThresholdEffect; Authority Threshold 6 reached."
		UKS_Authority_ThresholdEffect_Clear = yes
		set_variable = { UKS_AuthorityEffects^4 = -0.40 tooltip = UKS_Threshold_admin_program_cost_modifier_tt } # Administrative Program Cost Factor
		set_variable = { UKS_AuthorityEffects^13 = 0.2  tooltip = UKS_Threshold_trust_gain_multiplier_tt } # Trust Gain Multiplier
		set_variable = { UKS_AuthorityEffects^10 = 5    tooltip = UKS_Threshold_academic_base_drift_tt } # Academic Effectiveness Drift
	}
}

UKS_Trust_ThresholdEffect_Clear = {
	for_each_loop = {
		array = UKS_TrustEffects
		set_variable = { UKS_TrustEffects^i = 0 }
	}
}

UKS_Authority_ThresholdEffect_Clear = {
	for_each_loop = {
		array = UKS_AuthorityEffects
		set_variable = { UKS_AuthorityEffects^i = 0 }
	}
}

#################################################
#              Calculation Effects              #
#################################################

# Weekly pulse calculation
UKS_Rev_Will_CalculateWeeklyPulse = {
	log = "[GetDateText]: [Root.GetName]: UKS_Rev_Will_CalculateWeeklyPulse; Executing."

	## Refresh base values first
	UKS_Rev_Will_CalculateBaseEffect = yes

	## Trust
	set_variable = { UKS_TrustWeekly = UKS_TrustWeeklyBase }
	add_to_variable = { UKS_TrustWeekly = UKS_TrustWeeklyExtra }
	add_to_variable = { UKS_TrustWeekly = modifier@weekly_trust_gain }

	set_temp_variable = { multiplier = 1 }
	add_to_temp_variable = { multiplier = modifier@trust_gain_multiplier }
	multiply_variable = { UKS_TrustWeekly = multiplier }

	log = "[GetDateText]: [Root.GetName]: UKS_Rev_Will_CalculateWeeklyPulse; Completed execution."
}

# Calculates base weekly modifiers
UKS_Rev_Will_CalculateBaseEffect = {
	## Define base values
	set_variable = { UKS_TrustWeeklyBase = @TrustWeeklyBase }

	## Apply base modifiers
	# Stability modifier
	set_temp_variable = { StabMult = @StabilityModifier }
	multiply_temp_variable = { StabMult = stability }
	add_to_variable = { UKS_PartificationWeeklyBase = StabMult }
	multiply_temp_variable = { StabMult = -1 }
	add_to_variable = { UKS_DiscontentWeeklyBase = StabMult }

	# Admin spending modifier
	set_temp_variable = { AdminSpendMult = UKS.econ_admin_bureaucracy_slider_pct }
	divide_temp_variable = { AdminSpendMult = 100 }
	multiply_temp_variable = { AdminSpendMult = @AdminSpendModifier }
	add_to_variable = { UKS_PartificationWeeklyBase = AdminSpendMult }

	# Social spending modifier
	set_temp_variable = { SocialSpendMult = UKS.econ_social_expenditures_slider_pct }
	divide_temp_variable = { SocialSpendMult = 100 }
	multiply_temp_variable = { SocialSpendMult = @SocialSpendModifier }
	subtract_from_variable = { UKS_DiscontentWeeklyBase = SocialSpendMult }

	# Office Coverage modifier
	set_temp_variable = { OfficeCovMult = 1 }
	subtract_from_temp_variable = { OfficeCovMult = UKS.TNO_office_coverage }
	multiply_temp_variable = { OfficeCovMult = @OfficeCovModifier }
	subtract_from_variable = { UKS_PartificationWeeklyBase = OfficeCovMult }

	# School/Hospital Coverage modifier
	set_temp_variable = { SocialCovMult = 2 }
	subtract_from_temp_variable = { SocialCovMult = UKS.TNO_school_coverage }
	subtract_from_temp_variable = { SocialCovMult = UKS.TNO_hospital_coverage }
	multiply_temp_variable = { SocialCovMult = @SocialCovModifier }
	add_to_variable = { UKS_DiscontentWeeklyBase = SocialCovMult }
}