
on_actions = {

	#### MIO on actions
	# ROOT is MIO
	on_mio_size_increased = {}
	# NB : all the following also exist at MIO level
	# use on-action here if the purpose is to execute for any MIO
	# use on-action at MIO level to execute just for one precise MIO
	# i.e. don't use this here : if = { limit = { is_military_industrial_organisation = ... } } }
	on_mio_design_team_assigned_to_tech = {}
	on_mio_design_team_assigned_to_variant = {}
	on_mio_industrial_manufacturer_assigned = {}
	on_mio_tech_research_cancelled = {}
	on_mio_tech_research_completed = {}
	on_mio_industrial_manufacturer_unassigned = {}


	#Not run on a specific country.
	on_startup = {
		effect= {
			if = {
				limit = { 
					is_historical_focus_on = yes
				}

				every_possible_country = {

					SWE = {
						add_ai_strategy = {
							type = protect
							id = PREV
							value = -1000
						}

						add_ai_strategy = {
							type = alliance
							id = PREV
							value = -50
						}	
					}
				}
			}
		}
		#SET UP MIO SIZE IN 1939 BOOKMARK
		effect = {
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					date > 1939.01.01 #1939 Bookmark
				}
				every_country = {
					limit = {
						is_major = yes
					}
					every_military_industrial_organization = {
						add_mio_size = 4
					}
				}
				every_country = {
					limit = {
						is_major = no
					}
					every_military_industrial_organization = {
						add_mio_size = 3
					}
				}
			}
		}

		effect = { # Setting up Nordic Cooperation system 
			NOR = {
				NORDIC_cooperation_initial_setup = yes 
			}
		}

		effect = {
			SWE = {
				SWE_calc_refugee_from_war = yes
			}
		}

		effect = {
			GER = {
				find_global_platonic_countries = yes # This is so platonic country variables are updated in game start and doesn't show as "Norway"
			}
		}
	}

	on_new_term_election = {
		random_events = {
			100 = denmark_political_events.3 #danish election events
		}
	}

	on_weekly_SWE = {
		effect = {
			set_variable = { SWE_civs_built = 0 }
			every_core_state = {
				add_to_variable = { ROOT.SWE_civs_built = industrial_complex_level }
			}
			if = {
				limit = {
					check_variable = { SWE_civs_built > 14 }
				}
				if = {
					limit = {
						SWE = { has_idea = SWE_hungershield }
					}
					remove_ideas = SWE_hungershield
				}
				if = {
					limit = {
						SWE = { has_idea = SWE_minor_hungershield_strike }
					}
					remove_ideas = SWE_minor_hungershield_strike
				}
				if = {
					limit = {
						SWE = { has_idea = SWE_major_hungershield_strike }
					}
					remove_ideas = SWE_major_hungershield_strike
				}

			}

			clear_variable = SWE_civs_built
		}
	}

	#ROOT is capitulated country, FROM is winner.
	on_capitulation_immediate = {
		effect = {
			SWE_is_norway_mostly_occupied = yes
			SWE_is_finland_mostly_occupied = yes
			SWE_is_denmark_mostly_occupied = yes
			SWE_is_ice_mostly_occupied = yes
		}

		#FINLAND - BROKEN CONTINUATION WAR PACT
		effect = {
			if = { #Finland or GER capitulating
				limit = {
					has_country_flag = FIN_pact_for_continuation_war_flag
				}
				#Send Event to Finland and to GER, regardless of who is ROOT
				country_event = AAT_finland_continuation_war.04
				random_other_country = {
					limit = {
						has_country_flag = FIN_pact_for_continuation_war_flag
					}
					country_event = AAT_finland_continuation_war.04
				}
			}
		}
	}
	
	# ROOT is capitulated country, FROM is winner
	on_capitulation = {
		effect = { #Achievement Two Arms Against Tyranny
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					FROM = {
						OR = {
							original_tag = FIN
							is_in_faction_with = FIN
						}
						num_faction_members < 3
						num_faction_members > 1
						any_allied_country = {
							NORDIC_is_nordic = yes
						}
					}

					ROOT = {
						original_tag = SOV
					}
				}

				set_global_flag = capitulated_soviet_with_only_finland_and_another_nordic
			}
			if = { #Flag locking Achievement "Everything is Awesome"
				limit = {
					has_dlc = "Arms Against Tyranny"
					ROOT = {
						original_tag = DEN
					}
				}
				set_global_flag = achievement_den_has_never_been_capitulated
			}
		}
	}

	##ROOT is affected country
	on_uncapitulation = {
		effect = { # Setting Oslo as capital of Oslo again 
			if = {
				limit = {
					ROOT = { 
						original_tag = NOR
						has_government = democratic
						has_variable = NOR_mobile_government_hq
						NOT = {
							check_variable = {
								NOR_mobile_government_hq = 110 # Checking that the state is not Oslo 
							}  
						}
					}
				}
				ROOT = {
					set_capital = { state = 110}
					set_variable = { NOR_mobile_government_hq = 110 }
				}
			}
		}
	}

	# FROM is the country that is hosting the government in exile.
	# ROOT is the government in exile
	on_government_exiled = {   
		#FINLAND - Remove BoP (agendas should not take effect while in exile)
		effect = {
			if = {
				limit = {
					original_tag = FIN
					has_power_balance = {
						id = FIN_power_balance
					}
				}
				remove_power_balance = {
					id = FIN_power_balance
				}
			}
		}
		effect = { # Telling the player they have the good exiled decisions 
			if = {
				limit = {
					ROOT = {
						tag = NOR
						has_country_flag = NOR_capitulation_prepared
						is_in_faction = yes 
					}
				}
				ROOT = {
					country_event = {
						id = AAT_norway.16
						hours = 4 
					}
				}
			}
		}
	}

	#Root is exile
	#From is old host 
	on_exile_government_reinstated = {
		#FINLAND - Bring back BoP
		effect = {
			if = {
				limit = {
					original_tag = FIN
					NOT = {
						has_power_balance = {
							id = FIN_power_balance
						}
					}
				}
				#Value based on present Sisu NS
				if = {
					limit = {
						has_idea = FIN_sisu_1
					}
					set_power_balance = {
						id = FIN_power_balance
						left_side = FIN_bad_side
						right_side = FIN_good_side
						set_value = -0.8
					}
				}
				else_if = {
					limit = {
						has_idea = FIN_sisu_2
					}
					set_power_balance = {
						id = FIN_power_balance
						left_side = FIN_bad_side
						right_side = FIN_good_side
						set_value = -0.3
					}
				}
				else_if = {
					limit = {
						has_idea = FIN_sisu_3
					}
					set_power_balance = {
						id = FIN_power_balance
						left_side = FIN_bad_side
						right_side = FIN_good_side
						set_value = 0
					}
				}
				else_if = {
					limit = {
						has_idea = FIN_sisu_4
					}
					set_power_balance = {
						id = FIN_power_balance
						left_side = FIN_bad_side
						right_side = FIN_good_side
						set_value = 0.3
					}
				}
				else_if = {
					limit = {
						has_idea = FIN_sisu_5
					}
					set_power_balance = {
						id = FIN_power_balance
						left_side = FIN_bad_side
						right_side = FIN_good_side
						set_value = 0.8
					}
				}
				else = { #Something weird happened and FIN doesn't have the Sisu NS -> Mid BoP and add Sisu NS
					set_power_balance = {
						id = FIN_power_balance
						left_side = FIN_bad_side
						right_side = FIN_good_side
						set_value = 0
					}
					add_ideas = FIN_sisu_3
				}
			}
		}
	}

	on_create_faction = {
		effect = {
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					ROOT = { original_tag = FIN }
				}
				set_global_flag = achievement_FIN_has_joined_a_faction
			}
		}	
	}

	on_liberate = {
		effect = {
			SWE_on_freed_cross_we_bear = yes
		}
		effect = {
			IF = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					ROOT = { original_tag = DEN }
				}
				DEN_puppet_on_action_effects = yes
				#This checks various Danish Occupation set ups and removing them if they are true, such as the Occupation tag, making Denmark able to join wars and facitons again, and restoring the Welfare/Warfare BoP
			}
		}
	}
 	#ROOT is the nation being released, FROM is the overlord
	on_release_as_free = { 
		effect = {
			SWE_on_freed_cross_we_bear = yes
		}

		effect = {
			if = {
				limit = {
					ROOT = {
						tag = SMI
						owns_state = 148
					}
				}
				148 = {
					add_victory_points = {
						province = 6142
						value = 2
					}
				}	
			}
		}

		effect = { # Jan Mayen's Rebirth 
			if = {
				limit = {
					ROOT = { tag = JAN }
					NOT = {	has_global_flag = JAN_mayen_has_risen } 
				}
				914 = { # YES! You, Jan Mayen, let's see what you got.  
					add_extra_state_shared_building_slots = 25
					add_manpower = 7000
					remove_core_of = NOR 
					force_disable_resistance = yes 
				}
				set_global_flag = JAN_mayen_has_risen
				news_event = AAT_norway_news.99
			}
		}
		effect = {
			IF = {
				limit = {
					original_tag = DEN
					has_dlc = "Arms Against Tyranny"
				}
				if = {
					limit = {
						ROOT = {
							has_cosmetic_tag = DEN_occupied_denmark
						}
					}
					ROOT = {
						drop_cosmetic_tag = yes
					}
				}
				if = {
					limit = {
						ROOT = {
							has_country_flag = DEN_is_protectorate_flag
						}
					}
					ROOT = {
						clr_country_flag = DEN_is_protectorate_flag
					}
				}
				if = {
					limit = {	
						has_country_flag = DEN_cannot_join_factions_flag
					}
					set_rule = { can_join_factions = yes }
					set_rule = { can_decline_call_to_war = no }
					clr_country_flag = DEN_cannot_join_factions_flag
				}
			}
		}
		effect = {
			IF = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					ROOT = { original_tag = DEN }
				}
				DEN_puppet_on_action_effects = yes
				#This checks various Danish Occupation set ups and removing them if they are true, such as the Occupation tag, making Denmark able to join wars and facitons again, and restoring the Welfare/Warfare BoP
			}
		}
	}

	#ROOT is winner #FROM gets annexed - This fires just before FROM gets annexed, meaning the country and everything it owns still exists. It will also fire on_annex and on_civil_war_end
	on_civil_war_end_before_annexation = {
		effect = {
			if = {
				limit = {
					original_tag = FIN
					has_dlc = "Arms Against Tyranny"
					has_focus_tree = generic_focus
					FROM = {
						has_focus_tree = finnish_focus
					}
					OR = {
						AND = { # Civil wars from Finnish Focus Tree
							ROOT = {
								has_government = neutrality
							}
							OR = {
								FROM = { has_government = communism }
								FROM = { has_government = fascism }
							}
						}
						ROOT = { # Civil war from Estonia Focus Tree
							has_government = fascism
						}
					}
				}
				load_focus_tree = finnish_focus
				if = {
					limit = {
						FROM = { has_government = communism }
						ROOT = { has_government = neutrality }
					}
					uncomplete_national_focus = {
						focus = FIN_suomalainen_sosialismi
						uncomplete_children = yes
						refund_political_power = no
					}
					unlock_national_focus = FIN_finnish_neutrality
					unlock_national_focus = FIN_political_unity
					unlock_national_focus = FIN_national_unity
				}
				else_if = {
					limit = {
						FROM = { has_government = fascism }
						ROOT = { has_government = neutrality }
					}
					uncomplete_national_focus = {
						focus = FIN_right_wing_policies
						uncomplete_children = yes
						refund_political_power = no
					}
					unlock_national_focus = FIN_finnish_neutrality
					unlock_national_focus = FIN_political_unity
					unlock_national_focus = FIN_national_unity
				}
				else_if = {
					limit = {
						ROOT = { has_government = fascism }
					}
					if = {
						limit = {
							has_completed_focus = FIN_finnish_neutrality
						}
						uncomplete_national_focus = {
							focus = FIN_right_wing_policies
							uncomplete_children = yes
							refund_political_power = no
						}
					}
					else_if = {
						limit = {
							has_completed_focus = FIN_suomalainen_sosialismi
						}
						uncomplete_national_focus = {
							focus = FIN_suomalainen_sosialismi
							uncomplete_children = yes
							refund_political_power = no
						}
					}

					if = {
						limit = {
							NOT = { has_completed_focus = FIN_right_wing_policies }
						}
						unlock_national_focus = FIN_right_wing_policies
					}
					if = {
						limit = {
							NOT = { has_completed_focus = FIN_prepare_a_military_coup }
						}
						unlock_national_focus = FIN_prepare_a_military_coup
					}
					if = {
						limit = {
							NOT = { has_completed_focus = FIN_a_fascist_regime }
						}
						unlock_national_focus = FIN_a_fascist_regime
					}
				}
				
				FIN_initiate_balance_of_power_effect = yes
			}
		}
		effect = {
			IF = {
				limit = {
					ROOT = {
						original_tag = NOR
						has_government = communism
					}
				}
			}
			IF = {
				limit = {
					ROOT = {
						has_template = "Våpenfolket"
					}
				}
				ROOT = {
					delete_unit_template_and_units = {
					    division_template = "Våpenfolket"
					    disband = yes #will refund equipment and manpower
					}
				}
			}
			IF = {
				limit = {
					ROOT = {
						has_template = "Folkets Hær"
					}
				}
				ROOT = {
					delete_unit_template_and_units = {
					    division_template = "Folkets Hær"
					    disband = yes #will refund equipment and manpower
					}
				}
			}
		}
	}

	on_weekly_SWE = {
		effect = {
			if = {
				limit = {
					has_dynamic_modifier = {
					 	modifier = SWE_folkhemmet_communism
					 } 
				}
				SWE_calc_communist_folkhemmet = yes
			}
		}
		effect = {
			if = {
				limit = {
					NOT = { has_country_flag = SWE_has_unlocked_vattenfall_upgrade }
				}

				set_temp_variable = { SWE_northern_infra = 0 }
				if = {
					limit = { 666 = { controller = { original_tag = SWE } } }
					666 = { PREV = { add_to_temp_variable = { SWE_northern_infra = PREV.infrastructure_level } } }
				}

				if = {
					limit = { 918 = { controller = { original_tag = SWE } } }
					918 = { PREV = { add_to_temp_variable = { SWE_northern_infra = PREV.infrastructure_level } } }
				}

				if = {
					limit = { 38 = { controller = { original_tag = SWE } } }
					38 = { PREV = { add_to_temp_variable = { SWE_northern_infra = PREV.infrastructure_level } } }
				}

				if = {
					limit = { check_variable = { SWE_northern_infra > 11 } }
					set_country_flag = SWE_has_unlocked_vattenfall_upgrade
					if = {
						limit = {
							has_idea = SWE_vattenfall
						}

						swap_ideas = {
							remove_idea = SWE_vattenfall
							add_idea = SWE_vattenfall_upgrade
						}
					}
				}
			}

			###
			if = {
				limit = { 
					has_completed_focus = SWE_strike_the_capitalist_beast_down 
					NOT = { has_completed_focus = SWE_police_reforms }
				}
				set_temp_variable = { SWE_opposing_support = 0 }
				set_temp_variable = { SWE_opposing_support = party_popularity@fascism }
				add_to_temp_variable = { SWE_opposing_support = party_popularity@neutrality }

				if = {
					limit = {
						check_variable = { SWE_opposing_support > 0.45 }
						has_idea = SWE_fascist_counter_revolution_1
						NOT = { has_idea = SWE_fascist_counter_revolution_2 }
					}

					country_event = { id = AAT_Sweden_communism.3 hours = 2 }
				}
				else = {
					add_to_temp_variable = { SWE_opposing_support = party_popularity@democratic }
					if = {
						limit = {
							has_idea = SWE_fascist_counter_revolution_2
							check_variable = { SWE_opposing_support > 0.69 }
						}
						country_event = { id = AAT_Sweden_communism.4 hours = 2 }
					}
				}
			}
			SWE_is_norway_mostly_occupied = yes
			SWE_is_finland_mostly_occupied = yes
			SWE_is_denmark_mostly_occupied = yes
			SWE_is_ice_mostly_occupied = yes

			#Train the Sheltered
			if = {
				limit = {
					NOT = { has_country_flag = SWE_has_activated_train_the_sheltered }
					has_completed_focus = SWE_train_the_sheltered
					is_eligible_for_train_the_sheltered = yes
				}

				if = {
					limit = { check_variable = { SWE_train_the_sheltered_manpower_current_manpower < SWE_train_the_sheltered_manpower_current_cap } }
				
					add_to_variable = { var:SWE_train_the_sheltered_manpower_current_manpower = var:SWE_train_the_sheltered_manpower_gain_per_level_growth_base }
					set_temp_variable_to_random = { 
						var = SWE_randomSpread 
						min = SWE_train_the_sheltered_manpower_gain_per_level_growth_spread_min
						max = SWE_train_the_sheltered_manpower_gain_per_level_growth_spread_max
						integer = yes 
					}

					#prevents going over the manpower limit for 1 month in case it overflows
					if = {
						limit = {
							set_temp_variable = { SWE_current_manpower = SWE_train_the_sheltered_manpower_current_manpower }
							add_to_temp_variable = { SWE_current_manpower = SWE_randomSpread }
							check_variable = { SWE_current_manpower > SWE_train_the_sheltered_manpower_current_cap }
						}
						set_variable = { SWE_train_the_sheltered_manpower_current_manpower = SWE_train_the_sheltered_manpower_current_cap }
					}
					else = {
						add_to_variable = { SWE_train_the_sheltered_manpower_current_manpower = SWE_randomSpread }
					}

				}
				else = {
					set_variable = { SWE_train_the_sheltered_manpower_current_manpower = SWE_train_the_sheltered_manpower_current_cap }
				}
			}
		}
	}

	on_monthly_NOR = {
		effect = {
			if = {
				limit = {
					NOT = { 
						has_global_flag = NOR_the_norwegian_queen_is_dead 
						has_global_flag = NOR_the_norwegian_king_is_dead 
						has_government = communism
						has_government = fascism  
					}
				}
				if = {
					limit = {
						exists = yes 
						date > 1938.10.29 # 20 days before Queen Maud death. 
					}
					if = { # The King Dies
						limit = {
							has_country_flag = NOR_has_a_rikstanken
							has_completed_focus = NOR_the_chamberlains_overture
						}
						if = { # The King Dies
							limit = {
								has_completed_focus = NOR_shield_of_the_north
								has_war = yes
								surrender_progress > 0.2
							}
							country_event = { 
								id = AAT_norway_monarchist.2
								days = 20 
							}	
							every_country = {
								limit = {
									OR = {
										NORDIC_is_nordic = yes 
										is_major = yes 
									}
									NOT = { original_tag = NOR }
								}
								news_event = {
									id = AAT_norway_news.3
									days = 20 
								}
							}
						}
					}
					else = { # The Queen Dies
						country_event = { 
							id = AAT_norway.20
							days = 20 
						}	
						every_country = {
							limit = {
								OR = {
									NORDIC_is_nordic = yes 
									is_major = yes 
								}
								NOT = { original_tag = NOR }
							}
							news_event = {
								id = AAT_norway_news.2
								days = 20 
							}
						}
					}
				}
			}
		}
	}

	on_monthly_SWE = {

		#	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
		effect = {

			SWE_is_norway_mostly_occupied = yes
			SWE_is_finland_mostly_occupied = yes
			SWE_is_denmark_mostly_occupied = yes
			SWE_is_ice_mostly_occupied = yes
			if = {
				limit = {
					FIN = {
						has_country_flag = SWE_already_capped_once
						148 = { SWE_cross_we_bear_state_condition_trigger = yes } #Lappi
						722 = { SWE_cross_we_bear_state_condition_trigger = yes } #Petsamo
						929 = { SWE_cross_we_bear_state_condition_trigger = yes } #Wololo Oulolo
						150 = { SWE_cross_we_bear_state_condition_trigger = yes } #Kuopio
						149 = { SWE_cross_we_bear_state_condition_trigger = yes } #Vaasa, t
						926 = { SWE_cross_we_bear_state_condition_trigger = yes } #Turku
						927 = { SWE_cross_we_bear_state_condition_trigger = yes } #Häme
						930 = { SWE_cross_we_bear_state_condition_trigger = yes } #Mikelli
						928 = { SWE_cross_we_bear_state_condition_trigger = yes } #Kymi
						111 = { SWE_cross_we_bear_state_condition_trigger = yes }  #UUsima
						#Exclude Åland, Salla and Karaja due to uncertain future status depending on focus tree
					}
				}

				FIN = { SWE_on_freed_cross_we_bear = yes }
			}

			if = {
				limit = {
					DEN = {
						has_country_flag = SWE_already_capped_once
						37 = { SWE_cross_we_bear_state_condition_trigger = yes } #SJÖLAND
						911 = { SWE_cross_we_bear_state_condition_trigger = yes } #Faan
						99 = { SWE_cross_we_bear_state_condition_trigger = yes } #Jylland
						912 = { SWE_cross_we_bear_state_condition_trigger = yes } #Jylland som är sönder
						#Exclude Greenland, Faroe because honestly despite being very pretty no one wants to go there in hoi
					}
				}

				DEN = { SWE_on_freed_cross_we_bear = yes }
			}

			if = {
				limit = {
					ICE = {
						has_country_flag = SWE_already_capped_once
						100 = { SWE_cross_we_bear_state_condition_trigger = yes } #Vanilla Iceland
					}
				}

				ICE = { SWE_on_freed_cross_we_bear = yes }
			}

			if = {
				limit = {
					NOR = {
						has_country_flag = SWE_already_capped_once
						110 = { SWE_cross_we_bear_state_condition_trigger = yes } #Oslofjord
						921 = { SWE_cross_we_bear_state_condition_trigger = yes } #Telemarkor
						922 = { SWE_cross_we_bear_state_condition_trigger = yes } #Agder
						142 = { SWE_cross_we_bear_state_condition_trigger = yes } #Vestlandet
						920 = { SWE_cross_we_bear_state_condition_trigger = yes } #Opplande
						143 = { SWE_cross_we_bear_state_condition_trigger = yes } #Trondelag
						923 = { SWE_cross_we_bear_state_condition_trigger = yes } #Helgeland
						144 = { SWE_cross_we_bear_state_condition_trigger = yes } #Nordland
						924 = { SWE_cross_we_bear_state_condition_trigger = yes } #Troms	
						925 = { SWE_cross_we_bear_state_condition_trigger = yes } #Finnmark					
						#Not you Jan mayen
					}
				}

				NOR = { SWE_on_freed_cross_we_bear = yes }
			}

		}

		effect = {
			if = {
				limit = {
					has_completed_focus = SWE_hygenic_housing
					any_core_state = {
						NOT = { 
							OR = {
								has_dynamic_modifier = { modifier = SWE_hygenic_housing_output_bonus }
								has_dynamic_modifier = { modifier = SWE_hygenic_housing_resource_bonus } 
							}
						}
					}
				}

				if = {
					limit = {
						check_variable = { SWE_hygenic_housing_cooldown > 0 }
					}
					set_variable = { SWE_hygenic_housing_cooldown = 0 }

					if = {
						limit = {
							any_core_state = {
								OR = {
									is_island_state = yes
									has_state_category = small_island
									has_state_category = tiny_island
								}
							}
						}

						random_core_state = {
							limit = {
								OR = {
									is_island_state = yes
									has_state_category = small_island
									has_state_category = tiny_island
								}
								NOT = {
									has_dynamic_modifier = { modifier = SWE_hygenic_housing_output_bonus }
								}
							}
							add_dynamic_modifier = { modifier = SWE_hygenic_housing_output_bonus }

						}
					}

					random_core_state = {
						limit = {
							OR = {
								has_dynamic_modifier = { modifier = SWE_hygenic_housing_output_bonus }
								has_dynamic_modifier = { modifier = SWE_hygenic_housing_resource_bonus } 
							}

							NOT = {
								OR = {
									is_island_state = yes
									has_state_category = small_island
									has_state_category = tiny_island
								}
							}
						}
						random_neighbor_state = {
							limit = {
								NOT = {
									has_dynamic_modifier = { modifier = SWE_hygenic_housing_output_bonus }
									has_dynamic_modifier = { modifier = SWE_hygenic_housing_resource_bonus } 
								}
								is_core_of = ROOT
							}
							if = { 
								limit = {
									OR = {
										check_variable = { resource@steel > 16 }
										check_variable = { resource@aluminium > 16 }
										check_variable = { resource@oil > 16 }
										#check_variable = {resource@rubber > 7 } Not u
										check_variable = { resource@chromium > 16 }
										check_variable = { resource@tungsten > 16 }
									}
								}
								add_dynamic_modifier = { modifier = SWE_hygenic_housing_resource_bonus }
							}
							else = {
								add_dynamic_modifier = { modifier = SWE_hygenic_housing_output_bonus }
							}
						}
					}

				}
				else = {
					add_to_variable = { SWE_hygenic_housing_cooldown = 1 }
				}	
			}
		}

		effect = {
			if = {
				limit = {
					OR = {
						NOT = {  
							has_completed_focus = SWE_coalition_war_cabinet
						}

						NOT = {
							has_completed_focus = SWE_the_old_enemy_stirs
						}

						NOT = {
							has_completed_focus = SWE_refuge_from_war
						}
					}
				}
				SWE_calc_refugee_from_war = yes

			}
		}

		effect = {
			if = { #bus ded
				limit = {
					has_completed_focus = SWE_per_albin_bus
				}

				set_temp_variable = { bus_counter = 0 }
				every_country_division = {
					limit = {
						division_has_majority_template = bus
					}
					add_to_temp_variable = { bus_counter = 1 }
				}

				if = {
					limit = {
						check_variable = { bus_counter = 0 }
					}
					set_country_flag = SWE_bus_died
					country_event = { id = AAT_Sweden.12 }
				}
			}
		}
	}
	#ROOT = attacking side
	#FROM = defending side
	#fired when two countries end up at war with each other (on_war is fired when a country goes to war against anyone and is not fired again when it enters war against another country unless it went to peace first)
	on_war_relation_added = { # ---> Fires in 2nd place (1st is on_declare_war) -> This one is triggered ALWAYS 
		
		effect = { # This is the effect for setting up variable for Nordic cooperation members at war.  
			log = "[ROOT.GetName] is declaring war on [FROM.GetName]"
			if = {
				limit = {
					FROM = { NORDIC_is_nordic = yes }
					ROOT = { NORDIC_is_nordic = no }  
				}
				FROM = {
					NORDIC_add_to_war_array = yes 
					if = {
						limit = {
							NOT = {
								has_variable = NORDIC_attacker
							}
						}
						set_variable = { NORDIC_attacker = PREV }
					}
				}
			}
		}

		effect = {
			IF = {
				limit = {
					NOT = { has_global_flag = SOV_winter_war_flag }
					FROM = { tag = FIN }
					
				}
				set_variable = { FIN_white_death_target_country = ROOT }
			}
		}
		effect = {
			if = {
				limit = {
					GER = {
						has_resources_rights = {
							state = 918 #Västerbotten
						}
					}
					OR = {
						FROM = { original_tag = SWE }
						ROOT = { original_tag = SWE }
					}
					SWE = {
						has_war_with = GER
					}
				}

				GER = {
					remove_resource_rights = 918
				}

			}
		}

		effect = {
			if = {
				limit = {
					OR = {
						ROOT = { original_tag = SWE }
						FROM = { original_tag = SWE }
					}

					OR = {
						ROOT = { original_tag = GER }
						FROM = { original_tag = GER }
					}
					has_dlc = "Arms Against Tyranny"
					SWE = { 
						has_completed_focus = SWE_allow_landsverk_to_operate 
						NOT = { has_country_flag = SWE_landsberg_sabotage }
					}
				}
				SWE = {
					set_country_flag = SWE_landsberg_sabotage
					every_core_state = {
						limit = {
							is_fully_controlled_by = SWE
						}
						random_select_amount = 2

						damage_building = {
							type = arms_factory 
							damage = 4 # levels of damage 
						}
					}
				}
			}
		}

		effect = { #Militraize the narvik area if demilitarized
			if = { 
				limit = {
					OR = {
						FROM = { original_tag = SWE }
						ROOT = { original_tag = SWE }
						SWE = { has_completed_focus = SWE_the_narvik_solution }
					}
				}
				if = {
					limit = {
						144 = { 
							is_demilitarized_zone = yes 
							controller = { tag = SWE }
						}
					}
					144 = {
						#set_demilitarized_zone = no
					}
				}

				if = {
					limit = {
						924 = { 
							is_demilitarized_zone = yes 
							controller = { tag = SWE }
						}
					}

					924 = {
						#set_demilitarized_zone = no
					}
				}

				if = {
					limit = {
						925 = { 
							is_demilitarized_zone = yes 
							controller = { tag = SWE }
						}
					}

					925 = {
						#set_demilitarized_zone = no
					}
				}
			}
		}
		effect = { # Iceland declaring independence
			if = {
				limit = { 
					FROM = { original_tag = DEN }
					ICE = {
						NOT = { has_country_flag = declared_independence_flag }
						is_subject_of = FROM
						has_completed_focus = ICE_declare_absolute_neutrality
					}
				}
				set_variable = { ICE.overlord_attacker = ROOT}
				ICE = {
					set_country_flag = declared_independence_flag
					country_event = {
						id = iceland_events.1
						hours = 1
						#random_hours = 4 
					}
				}
			}
		}

		effect = { #manpower gain from train the sheltered focus
			if = { 
				limit = {
					SWE = { 
						has_completed_focus =  SWE_train_the_sheltered
						NOT = { has_country_flag = SWE_has_activated_train_the_sheltered }
						is_eligible_for_train_the_sheltered = yes
					}
					OR = { 
						FROM = {
							tag = SWE
						}
						ROOT = {
							tag = SWE
						}
					}
				}
				SWE = {
					set_country_flag = SWE_has_activated_train_the_sheltered
					add_manpower = var:SWE_train_the_sheltered_manpower_current_manpower
				}
			}
		}

		effect = { # Something about Swedish Ball Bearings? 
			if = {
				limit = {
					OR = {
						FROM = {
							original_tag = SWE
						}
						ROOT = {
							original_tag = SWE
						}
					}

					OR = {
						FROM  = {
							NOT = { original_tag = SWE }
							OR = {
								has_idea = SWE_ball_bearing_idea
								has_idea = SWE_ball_bearing_idea_food_partner
								has_idea = SWE_ball_bearing_idea_research_partner
							}
						}

						ROOT  = {
							NOT = { original_tag = SWE }
							OR = {
								has_idea = SWE_ball_bearing_idea
								has_idea = SWE_ball_bearing_idea_food_partner
								has_idea = SWE_ball_bearing_idea_research_partner
							}
						}
					}
				}

				if = { #reduce dynamic modifier if its a food trade partner, the rest is removed automatically in the spirits cancel trigger
					limit = {
						OR = {
							FROM = {
								has_idea = SWE_ball_bearing_idea_food_partner
							}
							ROOT = {
								has_idea = SWE_ball_bearing_idea_food_partner
							}
						}
					}

					SWE_reduce_or_remove_ball_bearing_food_trade_modifier = yes
				}
				FROM = { country_event = { id = AAT_Sweden_ball_bearing.8 } }
				ROOT = { country_event = { id = AAT_Sweden_ball_bearing.8 } }
			}
		}

		effect = {  #DEN is being attacked
			if = { 
				limit = {
					FROM = {
						original_tag = DEN
						OR = {
							has_idea = DEN_declaration_of_neutrality
							has_idea = DEN_declaration_of_neutrality_no_BBA
						}
					}
					ROOT = { 
						NOT = { #Don't trigger event in Civil War
							original_tag = DEN
						}
						strength_ratio = { #Gotta be strong enough to intimidate Denmark
						    tag = DEN
						    ratio > 0.5
						}
						OR = {
							is_neighbor_of = DEN
							any_subject_country = {
								is_subject_of = ROOT
								is_neighbor_of = DEN
							}
							AND = {
								naval_strength_ratio = { #Gotta be strong enough to intimidate Denmark
								    tag = DEN
								    ratio > 0.5
								}
								any_controlled_state = { #Gotta be close enough for Denmark to take you seriously
									is_coastal = yes
									state_is_in_the_mediterranean_sea = no
									BUL_state_is_in_the_black_sea = no
									distance_to = {
										target = 37
										value < 2451
									}
								}
							}
							any_subject_country = {
								is_subject_of = ROOT
								naval_strength_ratio = { #Gotta be strong enough to intimidate Denmark
								    tag = DEN
								    ratio > 0.5
								}
								any_controlled_state = { #Gotta be close enough for Denmark to take you seriously
									is_coastal = yes
									state_is_in_the_mediterranean_sea = no
									BUL_state_is_in_the_black_sea = no
									distance_to = {
										target = 37
										value < 2451
									}
								}
							}
						}
					}
				}
				
				ROOT = {
					DEN = { 
						country_event = { id = denmark_occupation_event.1 hours = 6 } 
						set_country_flag = DEN_attacked #Used to check if DEN was attacked by GER in Tests
					}
				}
					
			}
			#This is done so that Denmark's Election Events will NOT be triggered normally when at war
			if = {
				limit = {
					OR = {
						ROOT = {
							original_tag = DEN
							NOT = { has_country_flag = DEN_at_war_flag }
						}
						FROM = {
							original_tag = DEN
							NOT = { has_country_flag = DEN_at_war_flag }
						}
					}
				}
				if = {
					limit = {
						ROOT = {
							original_tag = DEN
						}
					}
					ROOT = {
						set_country_flag = DEN_at_war_flag
					}
				}
				else_if = {
					limit = {
						FROM = {
							original_tag = DEN
						}
					}
					FROM = {
						set_country_flag = DEN_at_war_flag
					}
				}
			}
		}

		effect = { # Fascist Attacks Norway, prep for Civil War
			if = {
				limit = {
					NOT = { has_global_flag = NOR_norwegian_fascist_cw_started }
					ROOT = {
						original_tag = GER 
						has_government = fascism
						is_faction_leader = yes
						NOT = { has_country_flag = NOR_attacked_norway }  
					}
					FROM = {
						original_tag = NOR
						NOT = { has_government = fascism }
						has_civil_war = no 
						is_ai = yes
					}
				}
				ROOT = {
					set_country_flag = NOR_attacked_norway
				}
				NOR = {
					set_variable = { NOR_cw_fascist_attacker = ROOT }
					if = { # Norway has chosen Fascist branch
						limit = {
							has_completed_focus = NOR_lurk_in_the_shadows
							NOT = { has_completed_focus = NOR_nasjonal_samling }

						}
						country_event = { 
							id = AAT_norway.199
							hours = 1
						}
					}
					else_if = {  # Democratic but Quisling is still around
						limit = {
							NOR = {	 
								has_completed_focus = NOR_continue_nygaardsvold_government 
								NOT = { has_completed_focus = NOR_get_rid_of_quisling }
								is_subject = no
							}
						}
						complete_national_focus = NOR_fascist_invasion_of_norway
						unlock_national_focus = NOR_quislings_coup
						var:NOR.NOR_cw_fascist_attacker = {
							country_event = {
								id = AAT_norway.14
								hours = 1 
							}
						}
					}
					else_if = { # Democratic but Quisling is arrrested
					 
						limit = {
							NOR = {
								has_completed_focus = NOR_continue_nygaardsvold_government 
								is_subject = no
							}
						}
						complete_national_focus = NOR_fascist_invasion_of_norway
					}
				}
			}
		}

		#FIN - Secret Pact for Continuation War (with GER)
		effect = { #ROOT = attacking side // FROM = defending side
			if = { #BARBAROSSA STARTS -> CONTINUATION WAR STARTS
				limit = {
					ROOT = { original_tag = GER }
					FROM = { original_tag = SOV }
					FIN = {
						exists = yes
						has_country_flag = FIN_pact_for_continuation_war_flag
						is_subject = no
						NOT = {
							is_in_faction_with = FROM
							has_subject = FROM
							has_non_aggression_pact_with = FROM
							has_guaranteed = FROM
						}
					}
				}
				FIN = {
					country_event = AAT_finland_continuation_war.05
				}
				ROOT = {
					country_event = AAT_finland_continuation_war.06
				}
				FROM = {
					country_event = AAT_finland_continuation_war.07
				}
				news_event = { id = aat_news.100 hours = 8 random_hours = 4 }
			}
			else_if = { #BARBAROSSA INVERTED STARTS (SOV declares on GER) -> CONTINUATION WAR STARTS
				limit = {
					ROOT = { original_tag = SOV }
					FROM = { original_tag = GER }
					FIN = {
						exists = yes
						has_country_flag = FIN_pact_for_continuation_war_flag
						is_subject = no
						NOT = {
							is_in_faction_with = ROOT
							has_subject = ROOT
							has_non_aggression_pact_with = ROOT
							has_guaranteed = ROOT
						}
					}
				}
				FIN = {
					country_event = AAT_finland_continuation_war.05
				}
				ROOT = {
					country_event = AAT_finland_continuation_war.07
				}
				FROM = {
					country_event = AAT_finland_continuation_war.06
				}
				news_event = { id = aat_news.100 hours = 8 random_hours = 4 }
			}
			else_if = { #FIN-GER at war, pact is broken
				limit = {
					OR = {
						AND = {
							ROOT = { original_tag = GER }
							FROM = { original_tag = FIN }
						}
						AND = {
							ROOT = { original_tag = FIN }
							FROM = { original_tag = GER }
						}
					}
					OR = {
						ROOT = { has_country_flag = FIN_pact_for_continuation_war_flag }
						FROM = { has_country_flag = FIN_pact_for_continuation_war_flag }
					}
				}
				# Send event
				if = {
					limit = {
						ROOT = { has_country_flag = FIN_pact_for_continuation_war_flag }
					}
					ROOT = { country_event = AAT_finland_continuation_war.04 }
				}
				if = {
					limit = {
						FROM = { has_country_flag = FIN_pact_for_continuation_war_flag }
					}
					FROM = { country_event = AAT_finland_continuation_war.04 }
				}
			}
		}
		effect = {
			if = {
				limit = {
					OR = {
						ROOT = {
							OR = {
								has_completed_focus = GER_oppose_hitler
								has_completed_focus = GER_oppose_hitler_ww
							}
						}
						FROM = {
							OR = {
								has_completed_focus = GER_oppose_hitler
								has_completed_focus = GER_oppose_hitler_ww
							}
						}
					}
				}
				NOR = {
					find_global_platonic_countries = yes 
					mark_focus_tree_layout_dirty = yes
				}
			}
		}
	}

	on_peaceconference_ended = {
		effect = {
			if = {
				limit = {

					OR = {
						144 = {
							controller = { tag = SWE }
						}

						924 = {
							controller = { tag = SWE }
						}

						925 = {
							controller = { tag = SWE }
						}
					}

					SWE = { 
						has_completed_focus = SWE_the_narvik_solution 
						NOT = { has_country_flag = SWE_has_sent_return_narvik_event }
					}
					NOR = {  
						is_subject = no
						has_war = no
					}
				}

				SWE = { 
					country_event = { id = AAT_Sweden.18 hours = 2 } 
					set_country_flag = SWE_has_sent_return_narvik_event
				}
			}
		}
		effect = {
			if = {
				limit = {
					ROOT  = {
						original_tag = SWE
						has_completed_focus = SWE_the_nordic_defense_council		
					}
					FROM = {
						is_subject_of = ROOT
						OR = {
							original_tag = NOR 
							original_tag = ICE 
							original_tag = DEN 
							original_tag = FIN 
						}
						NOT = {
							has_autonomy_state = autonomy_aat_defense_council_member
						}
					}
				}

				set_autonomy = {
					target=FROM
					autonomy_state = autonomy_aat_defense_council_member
					freedom_level = 0 # 0-1 
					end_wars  = no # default yes. will not cancel non civil wars if set to no
					end_civil_wars = no # default yes. will not cancel civil wars if set to no
				}
				if = {
					limit = {
						NOT = {
							is_in_array = {
								array = SWE.SWE_nordic_defense_council_members
								value = FROM
							}
						}
					}

					add_to_array = {
						array = SWE.SWE_nordic_defense_council_members
						value = FROM 
					}
				}
			}
		}
		effect = {
			IF = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					DEN = {
						has_country_flag = DEN_has_occupation_flag
						is_subject = no
					}
					OR = {
						FROM = { original_tag = DEN }
						FROM = { original_tag = DEN.DEN_overlord_nation }
					}
				}
				DEN_puppet_on_action_effects = yes
				#This checks various Danish Occupation set ups and removing them if they are true, such as the Occupation tag, making Denmark able to join wars and facitons again, and restoring the Welfare/Warfare BoP
			}
		}
		effect = { #Effect so Norway can update countries in its focus tree. 
			if = {
				limit = {
					has_aat = yes 
				}
				NOR = {
					find_global_platonic_countries = yes 
					mark_focus_tree_layout_dirty = yes
				}
			}
		}
	}

	on_peace = {
		effect = { # Clearing attacker variable 
			if = {
				limit = {
					NORDIC_is_nordic = yes 
					has_variable = NORDIC_attacker
				}
				clear_variable = NORDIC_attacker
			}
		}

		effect = { # Effect to reset the variables and flags associated with the prep system so they can do it all again afterwards 
			if = {
				limit = {
					original_tag = NOR
					OR = {
						has_country_flag = NOR_going_dem_historical 
						has_country_flag = NOR_going_dem_allied
					}
				}
				NOR_reset_prep_system = yes 
			}
		}

		# FIN - Remove winter war flag if over
		effect = {
			if = {
				limit = {
					original_tag = FIN
					has_country_flag = FIN_winter_war_ongoing_flag
					NOT = { has_war_with = SOV }
				}
				clr_country_flag = FIN_winter_war_ongoing_flag
			}
		}
		#This is done so that Denmark's Election Events will be triggered normally
		effect = {
			if = {
				limit = {
					original_tag = DEN
					has_country_flag = DEN_at_war_flag
				}
				clr_country_flag = DEN_at_war_flag
			}
		}
	}

	#	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
	on_state_control_changed = {
		effect = {
			if = {
				limit = {
					is_in_array = {
						array = FIN.core_states_at_game_start
						value = FROM.FROM
					}
				}

				set_global_flag = achievement_fin_has_lost_one_starting_core
			}
		}
		# FINNISH MOTTI - Remove Motti Tactics state modifier if Finland loses a state
		effect = {
			if = {
				limit = {
					FROM.FROM = {
						has_dynamic_modifier = { modifier = FIN_motti_tactics_modifier }
					}
					FROM = { tag = FIN }
				}
				FROM.FROM = {
					remove_dynamic_modifier = { modifier = FIN_motti_tactics_modifier }
				}
				#Cost decrease for Motti decisions in Finland
				hidden_effect = {
					FROM = {
						divide_variable = { FIN_motti_decision_cost = FIN_motti_decision_cost_increase }
						set_variable = { FIN_motti_decision_cost_for_trigger = FIN_motti_decision_cost } #For trigger purposes
						subtract_from_variable = { FIN_motti_decision_cost_for_trigger = 1 } 
					}
				}
			}
		}

		##RENAME STATES/VPs
		#effect = {
		#	IF = {
		#		limit = {
		#			FIN_state_or_vp_name_should_change = yes
		#		}
		#		FIN_change_name_of_state_or_vp = yes
		#	}
		#}

		##RENAME STATES/VPs
		#effect = {
		#	IF = {
		#		limit = {
		#			SWE_state_or_vp_name_should_change = yes
		#		}
		#		SWE_change_name_of_state_or_vp = yes
		#	}
		#}

		# FINNISH WEAPON CACHES - Communicate new controller about Finnish Weapon Caches if first time controlling state with this modifier
		effect = { #	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
			if = {
				limit = {
					FROM.FROM = {
						has_dynamic_modifier = { modifier = FIN_weapon_caches_modifier }
					}
					FROM = { tag = FIN }
				}
				#Communicate the new controller about the weapon caches only once
				if = {
					limit = {
						NOT = { has_country_flag = FIN_aware_about_weapon_caches_flag }
					}
					set_country_flag = FIN_aware_about_weapon_caches_flag
					set_variable = { FIN_state_with_weapon_caches = FROM.FROM }
					country_event = { id = AAT_finland_national_defense.01 hours = 1 }
				}
			}
		}

		# WINTER WAR - MISSION TO DEMAND PEACE (if pushing back) - FIN can no longer demand peace since they lost Leningrad
		effect = { #	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
			if = {
				limit = {
					FROM.FROM = { state = 195 } #LENINGRAD
					FROM = { has_country_flag = FIN_winter_war_ongoing_flag }
					FROM = { has_country_flag = FIN_can_demand_peace_negotiations_flag }
				}
				FROM = { clr_country_flag = FIN_can_demand_peace_negotiations_flag }
			}
		}

		# FINNISH PRESERVE SAPMI - If new SMI core controlled and focus is completed, add core of FIN.
		effect = { #	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					ROOT = {
						original_tag = FIN
						has_completed_focus = FIN_preserve_sapmi
						OR = {
							has_government = democratic
							has_government = communism
						}
					}
					FROM.FROM = {
						is_core_of = SMI
						NOT = { is_core_of = FIN }
					}
				}
				FROM.FROM = { add_core_of = ROOT }
			}
		}

		# FINNISH CONFEDERATED FINNO-RUSSIAN REPUBLICS
		effect = { #	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
				}	
				if = {
					limit = {
						FROM.FROM = {
							has_dynamic_modifier = { modifier = FIN_confederation_of_finno_russian_republics_dm }
						}
						ROOT = {
							NOT = {
								original_Tag = FIN
								has_completed_focus = FIN_confederated_finno_russian_republics
							}
						}
					}
					FROM.FROM = {
						remove_dynamic_modifier = { modifier = FIN_confederation_of_finno_russian_republics_dm }
					}
				}
				else_if = {
					limit = {
						ROOT = {
							original_tag = FIN
							has_completed_focus = FIN_confederated_finno_russian_republics
						}
						FROM.FROM = {
							is_core_of = SOV
							NOT = { has_dynamic_modifier = { modifier = FIN_confederation_of_finno_russian_republics_dm } }
						}
					}
					FROM.FROM = {
						add_dynamic_modifier = { modifier = FIN_confederation_of_finno_russian_republics_dm }
					}
				}
			}
		}

		effect = {
			if = {
				limit = {
					ROOT = { 
						original_tag = SWE 
						has_completed_focus = SWE_join_allies_for_colonies
					}
				}

				if = {
					limit = {
						FROM.FROM = {
							state = 359 
						}
					}

					FROM.FROM = { set_state_name = "New Sweden" }
				}

				if = {
					limit = {
						FROM.FROM = {
							state = 358 
						}
					}

					FROM.FROM = { set_state_name = "New Stockholm" }
				}

				if = {
					limit = {
						FROM.FROM = {
							state = 358 
						}
					}

					FROM.FROM = { set_state_name = "New Gothenburg" }
				}


				if = {
					limit = {
						FROM.FROM = {
							state = 378 
						}
					}

					set_province_name = { id = 9814 name = "Los Malmö" }
					set_province_name = { id = 9671 name = "San Lund" }
				}

				if = {
					limit = {
						FROM.FROM = {
							state = 274
						}
					}

					FROM.FROM = { set_state_name = "Swedish Gold Coast" }
				}
			}
		}

		#Danish States#
		effect = { #	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
			if = {
				limit = {
					FROM.FROM = {
						has_state_flag = DEN_home_guard_deployed_flag
					}
					FROM = { tag = DEN }
				}
				FROM.FROM = {
					#remove_dynamic_modifier = { modifier = DEN_home_guard_state_modifier }
					clr_state_flag = DEN_home_guard_deployed_flag
				}
			}
			#if = {
			#	limit = {
			#		has_dlc = "Arms Against Tyranny"
			#	}
			#	if = { 
			#		limit = {
			#			FROM.FROM = {
			#				state = 110
			#			}
			#		}
			#		if = { #Oslo to Christiania
			#			limit = {
			#				ROOT = {
			#					original_tag = DEN
			#				}
			#			}	
			#			set_province_name = { id = 6115 name = VICTORY_POINTS_6115_DEN }
			#		}
			#		else_if = { #Christiania back to Oslo
			#			limit = {
			#				FROM = {
			#					original_tag = DEN
			#				}
			#			}
			#			reset_province_name = 6115
			#		}
			#	}
			#	#if = {
			#	#	limit = {
			#	#		FROM.FROM = {
			#	#			state = 138
			#	#		}
			#	#	}
			#	#	if = { #Skåne to Skaanelandene
			#	#		limit = {
			#	#			ROOT = {
			#	#				original_tag = DEN
			#	#			}
			#	#		}	
			#	#		FROM.FROM = { set_state_name = STATE_138_DEN }
			#	#		set_province_name = { id = 9279 name = VICTORY_POINTS_9279_DEN }
			#	#	}
			#	#	if = { #Skaanelandene back to Skåne
			#	#		limit = {
			#	#			FROM = {
			#	#				original_tag = DEN
			#	#			}
			#	#		}
			#	#		FROM.FROM = { reset_state_name = yes }
			#	#		reset_province_name = 9279
			#	#	}
			#	#}
			#	#if = {
			#	#	limit = {
			#	#		FROM.FROM = {
			#	#			state = 909
			#	#		}
			#	#	}
			#	#	if = { #Schleswig to Sydslesvig
			#	#		limit = {
			#	#			ROOT = {
			#	#				original_tag = DEN
			#	#			}
			#	#		}	
			#	#		FROM.FROM = { set_state_name = STATE_909_DEN }
			#	#	}
			#	#	if = { #Sydslesvig back to Schleswig
			#	#		limit = {
			#	#			FROM = {
			#	#				original_tag = DEN
			#	#			}
			#	#		}
			#	#		FROM.FROM = { reset_state_name = yes }
			#	#	}
			#	#}
			#	#if = {
			#	#	limit = {
			#	#		FROM.FROM = {
			#	#			state = 58
			#	#		}
			#	#	}
			#	#	if = { #Holstein to Holsten
			#	#		limit = {
			#	#			ROOT = {
			#	#				original_tag = DEN
			#	#			}
			#	#		}	
			#	#		FROM.FROM = { set_state_name = STATE_58_DEN }
			#	#	}
			#	#	if = { #Holsten back to Holstein
			#	#		limit = {
			#	#			FROM = {
			#	#				original_tag = DEN
			#	#			}
			#	#		}
			#	#		FROM.FROM = { reset_state_name = yes }
			#	#	}
			#	#}
			#	#if = {
			#	#	limit = {
			#	#		FROM.FROM = {
			#	#			state = 113
			#	#		}
			#	#	}
			#	#	if = { #From Dublin to Dyflin
			#	#		limit = {
			#	#			OR = {
			#	#				ROOT = { original_tag = ICE }
			#	#				ROOT = { original_tag = NOR	}
			#	#				ROOT = { original_tag = DEN }
			#	#			}
			#	#		}	
			#	#		set_province_name = { id = 11293 name = VICTORY_POINTS_11293_DEN }
			#	#	}
			#	#	if = { #From Dyflin back to Dublin
			#	#		limit = {
			#	#			OR = {
			#	#				FROM = { original_tag = ICE }
			#	#				FROM = { original_tag = NOR }
			#	#				FROM = { original_tag = DEN }
			#	#			}
			#	#		}	
			#	#		reset_province_name = 11293
			#	#	}
			#	#}
			#	#if = {
			#	#	limit = {
			#	#		FROM.FROM = {
			#	#			state = 130
			#	#		}
			#	#	}
			#	#	if = { #From Yorkshire to Jorvik
			#	#		limit = {
			#	#			OR = {
			#	#				ROOT = { original_tag = ICE }
			#	#				ROOT = { original_tag = NOR	}
			#	#				ROOT = { original_tag = DEN }
			#	#			}
			#	#		}	
			#	#		FROM.FROM = { set_state_name = STATE_130_DEN }
			#	#	}
			#	#	if = { #From Jorvik back to Yorkshire
			#	#		limit = {
			#	#			OR = {
			#	#				FROM = { original_tag = ICE }
			#	#				FROM = { original_tag = NOR }
			#	#				FROM = { original_tag = DEN }
			#	#			}
			#	#		}	
			#	#		FROM.FROM = { reset_state_name = yes }
			#	#	}
			#	#}
			#}
		}
		effect = { #Greenland's new Controller gets all of Greenland
			if = {
				limit = {
					FROM.FROM = {
						state = 101
					}
					
				}
				ROOT = {  #Province 13058 is impassable and cannot be conquered. Give it to the new state controller.
    				set_province_controller = 13058
  				}
			}
		}

		effect = {
			#if = {
			#	limit = {
			#		FROM = { tag = SWE }
			#		FROM.FROM = {
			#			has_dynamic_modifier = { modifier = SWE_bus }
			#		}
			#		ROOT = { 
			#			has_war_with = FROM 
			#		}
			#	}
			#
			#	FROM.FROM = { remove_dynamic_modifier = { modifier = SWE_bus }}
			#	FROM = { 
			#		set_variable = { bus_capture_tag = ROOT } #used in loc
			#		clear_variable =  SWE_bus_location 
			#		country_event = { id = AAT_Sweden.12 }
			#	}
			#

			if = {
				limit = {
					SWE = {
						has_completed_focus = SWE_finlands_cause_is_ours
						has_idea = SWE_gateway_to_peace
					}
					FROM.FROM = {
						state = 195 #Leningrad
					}

					FROM = { 
						original_tag = SOV 
						OR = {
							has_war_with = FIN
							has_war_with = SWE
						}
					}

					ROOT = {
						OR = {
							original_tag = FIN
							original_tag = SWE
							is_subject_of = SWE
							FIN = {
								any_allied_country = {
									has_war_with = SOV
								}
							}

							SWE = {
								any_allied_country = {
									has_war_with = SOV
								}
							}
						}
					}
				}

				FROM = {  
					country_event = { id = AAT_Sweden.26 hours = 2 random_hours = 2 }	
				}
			}

			#	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
			if = {
				limit = {
					SWE = { has_idea = SWE_crusade_against_the_eastern_threat }
					ROOT = {
						OR = {
							original_tag = SWE
							is_in_faction_with = SWE
						}
					}

					FROM = {
						original_tag = SOV
					}

					FROM.FROM = {
						OR = {
							state = 195 #Leningrad
							state = 206 #Minsk
							state = 202 #Kiev
							state = 242 #Smolensk
							state = 219 #Moscow
							state = 137 #Crimea
							state = 218 #Rostov
							state = 217 #Stalingrad
							state = 252 #Gorky
							state = 249 #Kazan
							state = 229 #Azerbaijan (Baku)
							state = 247 #Kalinin
							state = 408 #Vladivostok
							state = 214 #Arch-Ankle
						}
					}
				}

				remove_ideas = SWE_crusade_against_the_eastern_threat
				add_timed_idea = {
					idea = SWE_crusade_against_the_eastern_threat
					days = 365
				}
			}
		}
		effect = { # Waiting for Norway to be over 50% conquered. 
			if = {
				limit = {
					FROM = {
						original_tag = NOR 
						NOT = { has_government = fascism }
						surrender_progress > 0.45
						has_completed_focus = NOR_continue_nygaardsvold_government 
						has_country_flag = NOR_delayed_quislings_coup
						has_civil_war = no 
					}
				}
				FROM = {
					country_event = {
						id = AAT_norway.15
						hours = 2 
					}
				}
				clr_country_flag = NOR_delayed_quislings_coup
			}
		}
		#	ROOT is new controller, FROM is old controller, FROM.FROM is state ID.
		effect = {
			if = {
				limit = {
					ROOT = {
						original_tag = SWE
						has_completed_focus = SWE_universal_basic_income
					}
					FROM.FROM = {
						NOT = { has_state_flag = SWE_been_taken_by_communist_sweden_once }
					}
				}
				FROM.FROM = {
					add_compliance = 25
					set_resistance = 0
					set_state_flag = SWE_been_taken_by_communist_sweden_once
				}
			}
		}
		# JAN MAYEN'S REVENGE
		effect = { 
			if = {
				limit = {
					FROM.FROM = { state = 914 }	
				}
				if = {
					limit = {
						FROM.FROM = {
							NOT = { is_core_of = JAN }
						}
						ROOT = {
							original_tag = POL
							has_country_leader = {
								character = POL_wojtek 
								ruling_only = yes
							}
						}
					}
					FROM.FROM = { 
						add_core_of = JAN 
						remove_core_of = NOR
					}  
				}
				else_if = {
					limit = {
						FROM.FROM = { is_core_of = JAN } 
						FROM = { 
							OR = {
								original_tag = JAN
								original_tag = POL 
							}
						}
					}
					FROM.FROM = { 
						remove_core_of = JAN # Only Wojtek and Johan could bear this responsibility 
						add_core_of = NOR 
					} 
				}
			}
		}	
	}

	on_puppet = { #ROOT = nation being puppeted, FROM = overlord
		effect = {
			if = {
				limit = {
					is_ironman = yes
					original_tag = DEN
				}

				set_global_flag = achievement_den_has_never_been_puppeted
			}
			IF = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					original_tag = SWE
					FROM = {
						AND = {
							original_tag = SOV
							has_government = communism
							has_country_leader = {
								character = SOV_iosif_stalin
								ruling_only = yes
							}
						}
					}
				}
				ROOT = {
					retire_country_leader = yes
					SWE_sven_linderot = {
						add_country_leader_role = {
							country_leader = {
								ideology = stalinism
								expire="1965.1.1.1"
							}
							promote_leader = yes
						}
					}
					set_politics = {
						ruling_party = communism
						elections_allowed = no
					}
				}
			}
		}

		#FINLAND LONE WOLF STUFF - Add to tech group
		effect = { #ROOT = nation being puppeted, FROM = overlord
			if = {
				limit = {
					FROM = {
						original_tag = FIN
						has_idea = FIN_the_lone_wolf
					}
				}
				add_to_tech_sharing_group = FIN_joint_research_and_development_program
			}
		}

		#FINLAND - BROKEN CONTINUATION WAR PACT
		effect = { #ROOT = nation being puppeted, FROM = overlord
			if = { #Finland or GER puppeted by someone else
				limit = {
					has_country_flag = FIN_pact_for_continuation_war_flag
					FROM = {
						NOT = { has_country_flag = FIN_pact_for_continuation_war_flag }
					}
				}
				#Send Event to Finland and to GER, regardless of who us ROOT here
				country_event = AAT_finland_continuation_war.04
				random_other_country = {
					limit = {
						has_country_flag = FIN_pact_for_continuation_war_flag
					}
					country_event = AAT_finland_continuation_war.04
				}
			}
			else_if = { #Finland puppeted by GER or viceversa - Silently clear the flags
				limit = {
					ROOT = { has_country_flag = FIN_pact_for_continuation_war_flag }
					FROM = { has_country_flag = FIN_pact_for_continuation_war_flag }
				}
				ROOT = { clr_country_flag = FIN_pact_for_continuation_war_flag }
				FROM = { clr_country_flag = FIN_pact_for_continuation_war_flag }
			}
		}

		#FINLAND FINNISH DEMOCRATIC REPUBLIC
		effect = { #ROOT = nation being puppeted, FROM = overlord
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					original_tag = FIN
					FROM = {
						original_tag = SOV
						has_country_leader = {
							ruling_only = yes
							character = SOV_iosif_stalin
						}
					}
				}
				FIN_form_finnish_democratic_republic = yes
			}
		}
		effect = { #ROOT = nation being puppeted, FROM = overlord
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					original_tag = DEN
				}
				ROOT = {
					add_dynamic_modifier = { modifier = DEN_occupation_laws_dynamic_modifier }
					add_to_variable = {
						DEN_occupation_laws_cic_to_overlord = 0.05
						tooltip = cic_to_overlord_factor_tt
					}
					add_to_variable = {
						DEN_occupation_laws_mic_to_overlord = 0.05
						tooltip = mic_to_overlord_factor_tt
					}

					set_cosmetic_tag = DEN_occupied_denmark

					mark_focus_tree_layout_dirty = yes

					set_power_balance = { #New BoP for DEN
						id = DEN_occupation_balance
						left_side = DEN_annexation_side
						right_side = DEN_autonomy_side	
						set_value = -0.3
					}

					set_country_flag = DEN_has_occupation_flag #this is needed in a lot of Danish Occupation stuff
				}
				set_variable = { DEN.DEN_overlord_nation = FROM }
			}
		}
	}

	#ROOT is winner, FROM gets annexed. For civil wars on_civil_war_end is also fired.
	on_annex = {
		effect = {
			if = {
				limit = {
					FROM = { original_tag = DEN }
				}
				DEN_puppet_on_action_effects = yes
				#This checks various Danish Occupation set ups and removing them if they are true, such as the Occupation tag, making Denmark able to join wars and facitons again, and restoring the Welfare/Warfare BoP
			}
		}
	}

	#ROOT is subject FROM is previous overlord
	on_subject_free = {
		effect = {
			IF = {
				limit = {
					original_tag = ICE
					has_dlc = "Arms Against Tyranny"
					has_country_flag = ICE_republicanism_flag
				}
				ROOT = {
					country_event = {
						id = iceland_events.45
						hours = 16
						random_hours = 32 
					}
				}
			}
			IF = {
				limit = {
					original_tag = SWE
					has_dlc = "Arms Against Tyranny"
					has_country_flag = SWE_is_reichsprotectorate_flag
				}
				# Fascist Sweden
				ROOT = {
					drop_cosmetic_tag = yes
					clr_country_flag = SWE_is_reichsprotectorate_flag
				}
			}
			IF = {
				limit = {
					original_tag = DEN
					has_dlc = "Arms Against Tyranny"
				}
				if = {
					limit = {
						ROOT = {
							has_cosmetic_tag = DEN_occupied_denmark
						}
					}
					ROOT = {
						drop_cosmetic_tag = yes
					}
				}
				if = {
					limit = {
						ROOT = {
							has_country_flag = DEN_is_protectorate_flag
						}
					}
					ROOT = {
						clr_country_flag = DEN_is_protectorate_flag
					}
				}
				if = {
					limit = {	
						has_country_flag = DEN_cannot_join_factions_flag
					}
					set_rule = { can_join_factions = yes }
					set_rule = { can_decline_call_to_war = no }
					clr_country_flag = DEN_cannot_join_factions_flag
				}
			}
		}
		
		effect = { # Effect to re-add 'An Independent Norway' National Spirit  
			ROOT = {
				if = {
					limit = {
						NOR_aat = yes 
						has_completed_focus = NOR_building_an_independent_norway
						NOT = { 
							has_dynamic_modifier = { modifier = NOR_independent_norway_dmod }
						}
					}
					add_dynamic_modifier = { modifier = NOR_independent_norway_dmod	}
				}
			}
		}

		#FINLAND LONE WOLF STUFF - Remove from tech group
		effect = {
			if = {
				limit = {
					is_in_tech_sharing_group = FIN_joint_research_and_development_program
					FROM = {
						original_tag = FIN
						has_idea = FIN_the_lone_wolf
					}
				}
				remove_from_tech_sharing_group = FIN_joint_research_and_development_program
			}
		}
		#DENMARK becomes free without completing DEN_declare_independence
		effect = {
			if = {
				limit = {
					ROOT = {
						original_tag = DEN
						has_country_flag = DEN_has_occupation_flag
						NOT = { has_completed_focus = DEN_declare_independence }
					}
				}
				DEN_puppet_on_action_effects = yes
				#This checks various Danish Occupation set ups and removing them if they are true, such as the Occupation tag, making Denmark able to join wars and facitons again, and restoring the Welfare/Warfare BoP
			}
		}
	}

	on_ruling_party_change = {
	# temp var old_ideology_token is available for effects
		effect = {
			IF = {
				limit = {
					original_tag = SWE
					has_government = fascism
					has_completed_focus = SWE_revoke_anti_militia_laws
				}
				every_core_state = {
					limit = {
						is_fully_controlled_by = SWE
					}
					random_select_amount = 6
					create_unit = {
						division = "division_template = \"Stormtrupper\" start_experience_factor = 0.15 start_equipment_factor = 1"
						owner = ROOT
						count = 1
					}
				}
				SWE = {
					set_division_force_allow_recruiting = { division_template = "Stormtrupper" force_allow_recruiting = yes }
					set_division_template_lock = { division_template = "Stormtrupper" is_locked = no }
				}
			}
		}

		effect = { # FIN - Make sure country leaders have their appropriate party name
			if = {
				limit = {
					original_tag = FIN
				}
				if = {
					limit = {
						has_country_leader = {
							ruling_only = no
							character = FIN_kyosti_kallio
						}
					}
					set_party_name = { #Maalaisliitto (Agrarian League)
						ideology = neutrality
						name = FIN_neutrality_party
						long_name = FIN_neutrality_party_long
					}
				}
				else_if = {
					limit = {
						has_country_leader = {
							ruling_only = no
							character = FIN_risto_ryti
						}
					}
					set_party_name = { #National Progressive Party
						ideology = neutrality
						name = FIN_neutrality_party_progressive
						long_name = FIN_neutrality_party_progressive_long
					}
				}
				else_if = {
					limit = {
						has_country_leader = {
							ruling_only = no
							character = FIN_carl_mannerheim
						}
					}
					set_party_name = { #Non-Partisan Military Government
						ideology = neutrality
						name = FIN_neutrality_party_military
						long_name = FIN_neutrality_party_military_long
					}
				}
				else_if = {
					limit = {
						OR = {
							has_country_leader = {
								ruling_only = no
								character = FIN_pehr_evind_svinhufvud
							}
							has_country_leader = {
								ruling_only = no
								character = FIN_juho_kusti_paasikivi
							}
						}
					}
					set_party_name = { #Kokoomus (National Coalition Party)
						ideology = neutrality
						name = FIN_neutrality_party_kokoomus
						long_name = FIN_neutrality_party_kokoomus_long
					}
				}
				else_if = {
					limit = {
						has_country_leader = {
							ruling_only = no
							character = FIN_prince_wolfgang_von_hesse
						}
					}
					set_party_name = {
						ideology = neutrality
						long_name = FIN_neutrality_party_monarchist_long
						name = FIN_neutrality_party_monarchist
					}
				}
				else = { #Fallback is Agrarian League (Maalaisliitto)
					set_party_name = {
						ideology = neutrality
						name = FIN_neutrality_party
						long_name = FIN_neutrality_party_long
					}
				}
			}
		}

		effect = { # FIN - Deactivate BoP and bringing back old Sisu NS if changing ideology without AAT
			if = {
				limit = {
					NOT = { has_dlc = "Arms Against Tyranny" }
					original_tag = FIN
					NOT = {
						has_country_leader = {
							ruling_only = yes
							character = FIN_pehr_evind_svinhufvud
						}
						has_country_leader = {
							ruling_only = yes
							character = FIN_kyosti_kallio
						}
						has_country_leader = {
							ruling_only = yes
							character = FIN_risto_ryti
						}
						has_country_leader = {
							ruling_only = yes
							character = FIN_carl_mannerheim
						}
						has_country_leader = {
							ruling_only = yes
							character = FIN_juho_kusti_paasikivi
						}
						has_country_leader = {
							ruling_only = yes
							character = FIN_prince_wolfgang_von_hesse
						}
					}
				}
				if = { #Remove BoP and related Sisu NS
					limit = {
						has_power_balance = {
							id = FIN_power_balance
						}
					}
					remove_power_balance = { id = FIN_power_balance }
					if = {
						limit = {
							has_idea = FIN_sisu_1
						}
						remove_ideas = FIN_sisu_1
					}
					else_if = {
						limit = {
							has_idea = FIN_sisu_2
						}
						remove_ideas = FIN_sisu_2
					}
					else_if = {
						limit = {
							has_idea = FIN_sisu_3
						}
						remove_ideas = FIN_sisu_3
					}
					else_if = {
						limit = {
							has_idea = FIN_sisu_4
						}
						remove_ideas = FIN_sisu_4
					}
					else_if = {
						limit = {
							has_idea = FIN_sisu_5
						}
						remove_ideas = FIN_sisu_5
					}
				}

				if = { #Add old Sisu NS
					limit = {
						NOT = { has_idea = sisu }
					}
					add_ideas = sisu
				}
			}
		}

		effect = { #FIN - Drop cosmetic tags if appropriate
			if = { #RED FINLAND cosmetic
				limit = {
					has_cosmetic_tag = FIN_red_finland
					NOT = { has_government = communism }
				}
				drop_cosmetic_tag = yes
			}
			if = { #GRAND FINNISH FEDERATION cosmetic
				limit = {
					has_cosmetic_tag = FIN_grand_finnish_federation
					NOT = { has_government = democratic }
				}
				drop_cosmetic_tag = yes
			}
			if = { #GREATER FINLAND cosmetic
				limit = {
					has_cosmetic_tag = FIN_greater_finland
					OR = {
						has_government = democratic
						has_government = communism
					}
				}
				drop_cosmetic_tag = yes
			}
			if = { #CONFEDERATED FINNO-RUSSIAN REPUBLICS cosmetic
				limit = {
					has_cosmetic_tag = FIN_confederated_finno_russian_republics
					OR = {
						has_government = fascism
						has_government = neutrality
					}
				}
				drop_cosmetic_tag = yes
			}
			if = { #KINGDOM OF FINLAND cosmetic
				limit = {
					has_cosmetic_tag = FIN_kingdom_of_finland
					NOT = { has_government = neutrality }
				}
				drop_cosmetic_tag = yes
			}
		}

		effect = { # Changing Norway Cosmetic Tags depending on situation 
			if = {
				limit = {
					original_tag = NOR 
				}
				if = {
					limit = {
						has_government = democratic
						OR = {
							has_cosmetic_tag = NOR_SOV_communism
							has_cosmetic_tag = NOR_trotsky_communism
							has_cosmetic_tag = NOR_cw_communism
							has_cosmetic_tag = NOR_neutrality_purple_flag 
							has_cosmetic_tag = NOR_GER_fascism
							has_cosmetic_tag = NOR_fascism
							has_cosmetic_tag = NOR_norgesveldet_fascism
						}
					}
					if = {
						limit = {
							has_completed_focus = NOR_vote_of_no_confidence
						}
						set_cosmetic_tag = NOR_alt_democratic
					}
					else = {
						drop_cosmetic_tag = yes
					}
				}
				else_if = {
					limit = {
						has_government = communism 
						OR = {
							has_cosmetic_tag = NOR_neutrality_purple_flag 
							has_cosmetic_tag = NOR_GER_fascism
							has_cosmetic_tag = NOR_fascism
							has_cosmetic_tag = NOR_norgesveldet_fascism
							has_cosmetic_tag = NOR_alt_democratic
						}
					}
					if = {
						limit = {
							has_completed_focus = NOR_compromise_with_the_nkp 
						}
						set_cosmetic_tag = NOR_SOV_communism
					}
					else_if = {
						limit = {
							has_completed_focus = NOR_prosecute_the_nkp
						}
						set_cosmetic_tag = NOR_trotsky_communism
					}
					else = {
						set_cosmetic_tag = NOR_cw_communism 
					}
				}
				else_if = {
					limit = {
						has_government = fascism 
						OR = {
							has_cosmetic_tag = NOR_SOV_communism
							has_cosmetic_tag = NOR_trotsky_communism
							has_cosmetic_tag = NOR_cw_communism
							has_cosmetic_tag = NOR_neutrality_purple_flag 					
						}
					}
					if = {
						limit = {
							has_completed_focus = NOR_reviving_the_norgesveldet
						}
						set_cosmetic_tag = NOR_norgesveldet_fascism
					}
					else_if = {
						limit = {
							is_subject_of = GER 
						}
						set_cosmetic_tag = NOR_GER_fascism
					}
					else = {
						set_cosmetic_tag = NOR_fascism
					}
				}
				else_if = {
					limit = {
						has_government = neutrality 
						OR = {
							has_cosmetic_tag = NOR_SOV_communism
							has_cosmetic_tag = NOR_trotsky_communism
							has_cosmetic_tag = NOR_cw_communism
							has_cosmetic_tag = NOR_GER_fascism
							has_cosmetic_tag = NOR_fascism
							has_cosmetic_tag = NOR_norgesveldet_fascism
							has_cosmetic_tag = NOR_alt_democratic
						}
					}
					set_cosmetic_tag = NOR_neutrality_purple_flag 
				}
			}
		}
	}

	on_weekly_FIN = {
		#FINLAND BOP
		effect = {
			##################
			### SVINHUFVUD ###
			##################
			if = { #SVINHUFVUD - GOOD = No Democ & No Commie |||| BAD = Some Democ OR Commie // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_pehr_evind_svinhufvud
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#CONCERNING SUPPORT FOR SOCIALISTS
				if = {
					limit = {
						OR = {
							communism > 0.09
							democratic > 0.09
						}
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_concerning_support_for_socialists
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
					#Remove opposite modifier if necessary
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_eradicate_socialism
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_eradicate_socialism
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_concerning_support_for_socialists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
				}
				#### GOOD ####
				#ERADICATE SOCIALISM
				if = {
					limit = {
						democratic < 0.01
						communism < 0.01
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_eradicate_socialism
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_eradicate_socialism
						}
					}
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_concerning_support_for_socialists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_eradicate_socialism
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_eradicate_socialism
						}
					}
				}
			}
			##################
			##### KALLIO #####
			##################
			else_if = { #KALLIO - GOOD = No Fascist & No Commie |||| BAD = Some Fascist OR Commie // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_kyosti_kallio
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#CONCERNING SUPPORT FOR EXTREMISTS
				if = {
					limit = {
						OR = {
							communism > 0.09
							fascism > 0.09
						}
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_concerning_support_for_extremists
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_extremists
						}
					}
					#Remove opposite modifier if necessary
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_eradicate_extremists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_eradicate_extremists
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_concerning_support_for_extremists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_extremists
						}
					}
				}
				#### GOOD ####
				#ERADICATE EXTREMISTS
				if = {
					limit = {
						fascism < 0.01
						communism < 0.01
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_eradicate_extremists
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_eradicate_extremists
						}
					}
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_concerning_support_for_extremists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_extremists
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_eradicate_extremists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_eradicate_extremists
						}
					}
				}
			}
			###########################################################
			###### RYTI ############################## VON HESSE ######
			###########################################################
			else_if = { #RYTI - GOOD = Control Cores owned by enemies |||| BAD = Some Democ OR Commie // Losing Cores  ######## Also used for King von Hesse
				limit = {
					OR = {
						has_country_leader = {
							ruling_only = yes
							character = FIN_risto_ryti
						}
						has_country_leader = {
							ruling_only = yes
							character = FIN_prince_wolfgang_von_hesse
						}
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#CONCERNING SUPPORT FOR SOCIALISTS
				if = {
					limit = {
						OR = {
							communism > 0.09
							democratic > 0.09
						}
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_concerning_support_for_socialists
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
				}
				else_if = {
					limit = {
						has_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
					remove_power_balance_modifier = {
						id = FIN_power_balance
						modifier = FIN_bop_modifier_concerning_support_for_socialists
					}
				}
				#### GOOD ####
				#DREAM OF GREATER FINLAND
				if = {
					limit = {
						any_core_state = {
							NOT = { is_owned_by = ROOT }
							is_controlled_by = ROOT
						}
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_dream_of_greater_finland
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_dream_of_greater_finland
						}
					}
				}
				else_if = {
					limit = {
						has_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_dream_of_greater_finland
						}
					}
					remove_power_balance_modifier = {
						id = FIN_power_balance
						modifier = FIN_bop_modifier_dream_of_greater_finland
					}
				}
			}
			##################
			### MANNERHEIM ###
			##################
			else_if = { #MANNERHEIM - GOOD = War |||| BAD = Peace
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_carl_mannerheim
					}
				}
				#### BAD ####
				#PEACE
				if = {
					limit = {
						has_war = no
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_appointed_regent
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_appointed_regent
						}
					}
					#Remove opposite modifier if necessary
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_reliable_leader
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_reliable_leader
						}
					}
				}
				#### GOOD ####
				#WAR
				else = {
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_reliable_leader
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_reliable_leader
						}
					}
					#Remove opposite modifier if necessary
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_appointed_regent
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_appointed_regent
						}
					}
				}
			}
			##################
			#### PAASIKIVI ###
			##################
			else_if = { #PAASIKIVI - GOOD = Very High Stab |||| BAD = Low Stab // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_juho_kusti_paasikivi
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#CARETAKER
				if = {
					limit = {
						has_stability < 0.6
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_caretaker
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_caretaker
						}
					}
					#Remove opposite modifier if necessary
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_realist_conservative
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_realist_conservative
						}
					}
				}
				#### GOOD ####
				#WAR
				else_if = {
					limit = {
						has_stability > 0.95 
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_realist_conservative
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_realist_conservative
						}
					}
					#Remove opposite modifier if necessary
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_caretaker
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_caretaker
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_realist_conservative
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_realist_conservative
						}
					}
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_caretaker
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_caretaker
						}
					}
				}
			}
			##################
			##### ANNALA #####
			##################
			else_if = { #ANNALA - GOOD = Deployed MP and winning war |||| BAD = Some Democratic OR Commie // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_vilho_annala
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#CONCERNING SUPPORT FOR SOCIALISTS
				if = {
					limit = {
						OR = {
							communism > 0.09
							democratic > 0.09
						}
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_concerning_support_for_socialists
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
				}
				else_if = {
					limit = {
						has_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_socialists
						}
					}
					remove_power_balance_modifier = {
						id = FIN_power_balance
						modifier = FIN_bop_modifier_concerning_support_for_socialists
					}
				}

				#### GOOD ####
				#STRONG NATION
				if = {
					limit = {
						has_war = yes
						surrender_progress < 0.05
						has_army_manpower = { size > 299999 }
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_strong_nation
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_strong_nation
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_strong_nation
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_strong_nation
						}
					}
				}
			}
			##################
			##### TANNER #####
			##################
			else_if = { #TANNER - GOOD = High Democ Support |||| BAD = Some Fascist OR Commie // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_vaino_tanner
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#CONCERNING SUPPORT FOR EXTREMISTS
				if = {
					limit = {
						OR = {
							communism > 0.09
							fascism > 0.09
						}
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_concerning_support_for_extremists
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_extremists
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_concerning_support_for_extremists
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_concerning_support_for_extremists
						}
					}
				}

				#### GOOD ####
				#UNITED NATION
				if = {
					limit = {
						democratic > 0.95
						all_owned_state = {
							is_controlled_by = ROOT
						}
						controls_state = 146 #KARJALA
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_united_nation
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_united_nation
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_united_nation
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_united_nation
						}
					}
				}
			}
			####################
			##### AALTONEN #####
			####################
			else_if = { #AALTONEN - GOOD = Winning war against Fascists |||| BAD = Not high Commie // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_aimo_aaltonen
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#DIVIDED PROLETARIAT
				if = {
					limit = {
						communism < 0.8
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_divided_proletariat
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_divided_proletariat
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_divided_proletariat
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_divided_proletariat
						}
					}
				}

				#### GOOD ####
				#ANTI-FASCIST CRUSADE
				if = {
					limit = {
						has_war = yes
						any_enemy_country = {
							has_government = fascism
						}
						surrender_progress < 0.05
						NOT = {
							any_war_score < 10
						}
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_anti_fascist_crusade
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_anti_fascist_crusade
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_anti_fascist_crusade
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_anti_fascist_crusade
						}
					}
				}
			}
			#################
			##### LEINO #####
			#################
			else_if = { #LEINO - GOOD = No Fascism in Europe |||| BAD = Not high Commie // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_yrjo_leino
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#DIVIDED PROLETARIAT
				if = {
					limit = {
						communism < 0.8
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_divided_proletariat
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_divided_proletariat
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_divided_proletariat
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_divided_proletariat
						}
					}
				}

				#### GOOD ####
				#OBLITERATED EUROPEAN FASCISM
				if = {
					limit = {
						fascism < 0.01
						all_country = { #No Fascist country in Europe
							OR = {
								NOT = { has_government = fascism }
								capital_scope = {
									NOT = { is_on_continent = europe }
								}
							}
						}
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_obliterated_european_fascism
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_obliterated_european_fascism
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_obliterated_european_fascism
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_obliterated_european_fascism
						}
					}
				}
			}
			####################
			##### KUUSINEN #####
			####################
			else_if = { #KUUSINEN - GOOD = Scandinavian and Baltic allies |||| BAD = No Kola & Karelia // Losing Cores
				limit = {
					has_country_leader = {
						ruling_only = yes
						character = FIN_otto_wille_kuusinen
					}
				}
				#### BAD ####
				#LOSING CORES
				FIN_check_and_manage_losing_cores_for_bop_effect = yes

				#FORGOTTEN FINNO-KARELIANS
				if = {
					limit = {
						OR = {
							NOT = { controls_state = 146 } #KARJALA
							NOT = { controls_state = 213 } #KOLA
							NOT = { controls_state = 215 } #ONEGA
							NOT = { controls_state = 216 } #OLONETS
						}
					}
					#Add modifier (only once)
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_forgotten_finno_karelians
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_forgotten_finno_karelians
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_forgotten_finno_karelians
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_forgotten_finno_karelians
						}
					}
				}

				#### GOOD ####
				#SOLAR SYSTEM OF ORGANIZATIONS
				if = {
					limit = {
						SWE = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
						NOR = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
						DEN = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
						ICE = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
						EST = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
						LAT = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
						LIT = {
							all_core_state = {
								OR = {
									is_controlled_by = ROOT
									controller = {
										is_in_faction_with = ROOT
									}
								}
							}
						}
					}
					if = {
						limit = {
							NOT = {
								has_power_balance_modifier = {
									id = FIN_power_balance
									modifier = FIN_bop_modifier_a_solar_system_of_organizations
								}
							}
						}
						add_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_a_solar_system_of_organizations
						}
					}
				}
				else = {
					if = {
						limit = {
							has_power_balance_modifier = {
								id = FIN_power_balance
								modifier = FIN_bop_modifier_a_solar_system_of_organizations
							}
						}
						remove_power_balance_modifier = {
							id = FIN_power_balance
							modifier = FIN_bop_modifier_a_solar_system_of_organizations
						}
					}
				}
			}
			# UNKNOWN LEADER -> KILL BOP
			else = {
				remove_power_balance = {
					id = FIN_power_balance
				}
			}

			#### CLEAN ANY OBSOLETE BOP MODIFIERS (based on country leader)
			FIN_clean_all_obsolete_bop_modifiers_effect = yes
		}
	}

  	#FROM is faction leader on join faction requests. THIS DOES NOT FIRE ON ADD_TO_FACTION EFFECT! USE ON_OFFER_JOIN_FACTION!
	on_join_faction = { 
		effect = { # Adding the correct flags for the Joint Focus Alliance
			if = {
				limit = {
					FROM = { 
						OR = {
							has_country_flag = NORDIC_council_leader 
							has_country_flag = NORDIC_league_leader
							has_country_flag = NORDIC_union_leader
						}
					}
					NORDIC_is_nordic = yes
				}
				set_country_flag = NORDIC_alliance_member
				NORDIC_add_to_nordic_alliance = yes 
			}
		}

		#FROM is faction leader on join faction requests. THIS DOES NOT FIRE ON ADD_TO_FACTION EFFECT! USE ON_OFFER_JOIN_FACTION!
		effect = { # FINNISH - Kuusinen becomes country leader and Finland becomes the Finnish Democratic Republic if Commie Finland joins Comintern
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					original_tag = FIN
					has_government = communism
					FROM = {
						original_tag = SOV
						has_country_leader = {
							ruling_only = yes
							character = SOV_iosif_stalin
						}
					}
				}
				FIN_form_finnish_democratic_republic = yes
			}
		}

		effect = { #Lone Wolf Achievement
			if = {
				limit = {
					ROOT = {
						original_tag = FIN
					}
				}
				set_global_flag = achievement_FIN_has_joined_a_faction
			}
		}
	}

	#FROM is country getting invited. THIS GETS TRIGGERED WHEN THE COUNTRY BEING OFFERED ACTUALLY JOINS THE FACTION (AND ALSO TRIGGERED ON ADD_TO_ACTION EFFECT TACK SÅ MYCKET)
	on_offer_join_faction = {
		effect = { # Adding the correct flags for the Joint Focus Alliance
			if = {
				limit = {
					OR = {
						has_country_flag = NORDIC_council_leader 
						has_country_flag = NORDIC_league_leader
						has_country_flag = NORDIC_union_leader
					}
					FROM = { 
						NORDIC_is_nordic = yes
					}
				}
				FROM = {
					set_country_flag = NORDIC_alliance_member
					NORDIC_add_to_nordic_alliance = yes 
				}
			}
		}

		effect = {
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					FROM = {
						original_tag = FIN
					}
				}
				set_global_flag = achievement_FIN_has_joined_a_faction
			}
		}

		#FROM is country getting invited.
		effect = { # FINNISH - Kuusinen becomes country leader and Finland becomes the Finnish Democratic Republic if Commie Finland joins Comintern
			if = {
				limit = {
					has_dlc = "Arms Against Tyranny"
					FROM = {
						original_tag = FIN
						has_government = communism
					}
					original_tag = SOV
					has_country_leader = {
						ruling_only = yes
						character = SOV_iosif_stalin
					}
				}
				FROM = {
					FIN_form_finnish_democratic_republic = yes
				}
			}
		}
	}
	# FROM is the faction Leader, ROOT is the country leaving the faction 
	on_leave_faction = {
		effect = { # Removing Joint Focus Tree flags 
			if = {
				limit = {
					NORDIC_is_nordic = yes
					OR = {
						has_country_flag = NORDIC_council_leader 
						has_country_flag = NORDIC_league_leader
						has_country_flag = NORDIC_union_leader
						has_country_flag = NORDIC_alliance_member
					} 
				}
				clr_country_flag = NORDIC_council_leader
				clr_country_flag = NORDIC_league_leader
				clr_country_flag = NORDIC_union_leader
				clr_country_flag = NORDIC_alliance_member
			}
		}
	}
}