siberian_nationalist_independence = {
	set_temp_variable = { siberian_nationalist_country = this }
	every_core_state = {
		limit = {
			is_core_of = SOV
		}
		var:siberian_nationalist_country = { 
			transfer_state = PREV
			every_other_country = {
				remove_state_core = PREV.PREV
			}
		}
	}
}

transfer_SOV_to_WRF = {
	every_core_state = {
		limit = {
			is_core_of = SOV
			NOT = { state = 875 }
		}
		remove_core_of = SOV
		add_core_of = WRF
	}

	875 = {
		remove_core_of = SOV
		add_core_of = FAR
	}
}

soviet_german_white_peace = {

	SOV = {
		# Character reassignment
		every_character = {
			limit = {
				TR_SOV_is_WRF_character = yes
				NOT = { has_character_flag = SOV_character_purged_flag }
			}
			set_nationality = WRF
		}


		# Promote new leader
		if = {
			limit = { SOV_aleksandr_yegorov = { can_be_country_leader = yes } }
			WRF = { promote_character = SOV_aleksandr_yegorov }
		}
		else = {
			WRF = { promote_character = SOV_georgy_zhukov }
		}

		# Germany takes states
		every_state = {
			limit = {
				is_owned_by = SOV
				NOT = {
					is_core_of = WRF
					is_core_of = GEN
					state = 875 # We don't give it away because otherwise when the player is transferred to the WRF, he will become an observer
				}
			}
			transfer_state_to = GER
		}

		if = { # Transfer states to Reichskommissariat Moskowien
			limit = { 219 = { has_state_flag = GER_RK_capital_state_trasferred_RKM_flag } }
			every_state = {
				limit = {
					TR_GER_is_RKM_state = yes
					NOT = { is_controlled_by = RKM }
				}
				transfer_state_to = RKM
			}
		}

		if = { # Transfer states to Reichskommissariat Ukraine
			limit = { 202 = { has_state_flag = GER_RK_capital_state_trasferred_RKU_flag } }
			every_state = {
				limit = {
					TR_GER_is_RKU_state = yes
					NOT = { is_controlled_by = RKU }
				}
				transfer_state_to = RKU
			}
		}

		if = { # Transfer states to Reichskommissariat Ostland
			limit = { 808 = { has_state_flag = GER_RK_capital_state_trasferred_RKO_flag } }
			every_state = {
				limit = {
					TR_GER_is_RKO_state = yes
					NOT = { is_controlled_by = RKO }
				}
				transfer_state_to = RKO
			}
		}

		if = { # Transfer states to Reichskommissariat Kaukasus
			limit = { 231 = { has_state_flag = GER_RK_capital_state_trasferred_RKK_flag } }
			every_state = {
				limit = {
					TR_GER_is_RKK_state = yes
					NOT = { is_controlled_by = RKK }
				}
				transfer_state_to = RKK
			}
		}

		# Soviet's allies in war with Germany also white peace
		every_country = {
			limit = {
				original_tag = SOV
				is_in_faction_with = SOV
				SOV = { is_faction_leader = yes }
			}
			every_enemy_country = {
				white_peace = PREV
			}
			add_ideas = TR_neutrality_idea
			leave_faction = yes
		}
	}

	FIN = {

		if = {
			limit = {
				NOT = {
					147 = { is_owned_by = PREV }
					146 = { is_owned_by = PREV }
				}
			}

			transfer_state = 147
			transfer_state = 146
		}
	}
}

collapse_the_soviet_union = {
	set_global_flag = collapse_of_ussr
			
	SOV = {

		retire_character = SOV_iosif_stalin

		if = { # Promote new leader
			limit = {
				SOV_aleksandr_yegorov = {
					NOT = { has_character_flag = SOV_character_purged_flag }
				}
			}
			SOV_aleksandr_yegorov = {
				add_country_leader_role = {
					character = SOV_aleksandr_yegorov
					country_leader = {
						expire = "1965.1.1"
						ideology = stalinism
					}
					promote_leader = yes
				}
				promote_leader = yes
			}
		}
		else_if = {
			limit = {
				SOV_georgy_zhukov = {
					NOT = { has_character_flag = SOV_character_purged_flag }
				}
			}
			SOV_georgy_zhukov = {
				add_country_leader_role = {
					character = SOV_georgy_zhukov
					country_leader = {
						expire = "1965.1.1"
						ideology = stalinism
					}
					promote_leader = yes
				}
				promote_leader = yes
			}
		}

		WRF = {
			add_ideas = TR_neutrality_idea

			every_state = { # States to West Russian Revolutionary Front
				limit = {
					TR_SOV_is_WRF_state = yes
				}
				add_core_of = PREV
			}
		}

		KZR = {
			add_ideas = TR_neutrality_idea

			every_state = { # States to Kazakhstan
				limit = {
					TR_SOV_is_KZR_state = yes
				}
				add_core_of = PREV
			}
		}

		TYM = {
			add_ideas = TR_neutrality_idea

			every_state = { # States to Tymen
				limit = {
					TR_SOV_is_TYM_state = yes
				}
				add_core_of = PREV
			}
		}

		TOM = {
			add_ideas = TR_neutrality_idea

			every_state = { # States to Tomsk
				limit = {
					TR_SOV_is_TOM_state = yes
				}
				add_core_of = PREV
			}
			if = { # Give Tannu-Tuva's state to Tomsk
				limit = {
					NOT = {
						TAN = { owns_state = 329 }
					}
				}
				add_state_core = 329
			}
		}

		FAR = {
			add_ideas = TR_neutrality_idea

			every_state = { # States to Far East
				limit = {
					TR_SOV_is_FAR_state = yes
				}
				add_core_of = PREV
			}
		}
	}
}

TR_SOV_TYM_Promotes_Leader = {
	SOV = {
		every_character = {
			limit = {
				TR_SOV_is_TYM_character = yes
				NOT = { has_character_flag = SOV_character_purged_flag }
			}
			set_nationality = TYM
		}
	}
	TYM = {
		if = { # Assign new leader
			limit = {
				has_character = SOV_lazar_kaganovich
			}
			SOV_lazar_kaganovich = {
				add_country_leader_role = {
					character = SOV_lazar_kaganovich
					promote_leader = yes
					country_leader = {
						expire = "1953.1.1.1"
						ideology = stalinism
					}
				}
			}
			set_country_leader_portrait = {
				ideology = communism
				portrait = GFX_portrait_TYM_lazar_kaganovich
			}
		}
	}
}

TR_SOV_TOM_Promotes_Leader = {
	SOV = {
		every_character = {
			limit = {
				TR_SOV_is_TOM_character = yes
				NOT = { has_character_flag = SOV_character_purged_flag }
			}
			set_nationality = TOM
		}
	}
	TOM = {
		if = { # Assign new leader
			limit = {
				has_character = TOM_boris_pasternak
			}
			TOM_boris_pasternak = {
				add_country_leader_role = {
					character = TOM_boris_pasternak
					promote_leader = yes
					country_leader = {
						expire = "1960.1.1.1"
						ideology = liberalism
					}
				}
			}
			set_country_leader_portrait = {
				ideology = democratic
				portrait = GFX_portrait_TOM_boris_pasternak
			}
		}
	}
}

TR_SOV_FAR_Promotes_Leader = {
	SOV = {
		every_character = {
			limit = {
				TR_SOV_is_FAR_character = yes
				NOT = { has_character_flag = SOV_character_purged_flag }
			}
			set_nationality = FAR
		}
	}
	FAR = {
		if = { # Assign new leader
			limit = {
				has_character = SOV_genrikh_yagoda
			}
			FAR = { set_cosmetic_tag = FAR_IRK }
			SOV_genrikh_yagoda = {
				add_country_leader_role = {
					character = SOV_genrikh_yagoda
					promote_leader = yes
					country_leader = {
						expire = "1965.1.1.1"
						ideology = leninism
					}
				}
			}
			set_country_leader_portrait = {
				ideology = communism
				portrait = GFX_portrait_SOV_genrikh_yagoda
			}
		}
	}
}

TR_SOV_KZR_Promotes_Leader = {
	SOV = {
		every_character = {
			limit = {
				TR_SOV_is_KZR_character = yes
				NOT = { has_character_flag = SOV_character_purged_flag }
			}
			set_nationality = KZR
		}
	}
	KZR = {
		if = { # Assign new leader
			limit = {
				has_character = KZR_bauyrzhan_momyshuly
			}
			KZR_bauyrzhan_momyshuly = {
				add_country_leader_role = {
					character = KZR_bauyrzhan_momyshuly
					promote_leader = yes
					country_leader = {
						expire = "1953.3.1.1"
						ideology = stalinism
					}
				}
				promote_leader = yes
			}
			set_country_leader_portrait = {
				ideology = communism
				portrait = GFX_portrait_KZR_bauyrzhan_momyshuly
			}
		}
	}
}