
#Important to put HIGHEST first
GER_mefo_bills_level_up = {
	if = {
		limit = { has_idea = GER_mefo_bills_17 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_17
			add_idea = GER_mefo_bills_18
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_16 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_16
			add_idea = GER_mefo_bills_17
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_15 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_15
			add_idea = GER_mefo_bills_16
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_14 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_14
			add_idea = GER_mefo_bills_15
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_13 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_13
			add_idea = GER_mefo_bills_14
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_12 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_12
			add_idea = GER_mefo_bills_13
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_11 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_11
			add_idea = GER_mefo_bills_12
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_10 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_10
			add_idea = GER_mefo_bills_11
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_9 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_9
			add_idea = GER_mefo_bills_10
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_8 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_8
			add_idea = GER_mefo_bills_9
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_7 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_7
			add_idea = GER_mefo_bills_8
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_6 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_6
			add_idea = GER_mefo_bills_7
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_5 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_5
			add_idea = GER_mefo_bills_6
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_4 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_4
			add_idea = GER_mefo_bills_5
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_3 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_3
			add_idea = GER_mefo_bills_4
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_2 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_2
			add_idea = GER_mefo_bills_3
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_1 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_1
			add_idea = GER_mefo_bills_2
		}
	}
}

#Important to put HIGHEST first
GER_remove_mefo_bills = {
	if = {
		limit = { has_idea = GER_mefo_bills_1 }
		remove_ideas = GER_mefo_bills_1
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_2 }
		remove_ideas = GER_mefo_bills_2
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_3 }
		remove_ideas = GER_mefo_bills_3
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_4 }
		remove_ideas = GER_mefo_bills_4
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_5 }
		remove_ideas = GER_mefo_bills_5
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_6 }
		remove_ideas = GER_mefo_bills_6
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_7 }
		remove_ideas = GER_mefo_bills_7
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_8 }
		remove_ideas = GER_mefo_bills_8
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_9 }
		remove_ideas = GER_mefo_bills_9
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_10 }
		remove_ideas = GER_mefo_bills_10
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_11 }
		remove_ideas = GER_mefo_bills_11
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_12 }
		remove_ideas = GER_mefo_bills_12
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_13 }
		remove_ideas = GER_mefo_bills_13
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_14 }
		remove_ideas = GER_mefo_bills_14
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_15 }
		remove_ideas = GER_mefo_bills_15
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_16 }
		remove_ideas = GER_mefo_bills_16
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_17 }
		remove_ideas = GER_mefo_bills_17
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_18 }
		remove_ideas = GER_mefo_bills_18
	}
}

# Like the level up effect except it runs in reverse
# For use when annexing the gold reserves of Austria, Czechoslovakia and Yugoslavia

GER_mefo_bills_level_down = {
	if = {
		limit = { has_idea = GER_mefo_bills_2 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_2
			add_idea = GER_mefo_bills_1
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_3 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_3
			add_idea = GER_mefo_bills_2
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_4 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_4
			add_idea = GER_mefo_bills_3
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_5 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_5
			add_idea = GER_mefo_bills_4
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_6 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_6
			add_idea = GER_mefo_bills_5
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_7 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_7
			add_idea = GER_mefo_bills_6
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_8 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_8
			add_idea = GER_mefo_bills_7
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_9 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_9
			add_idea = GER_mefo_bills_8
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_10 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_10
			add_idea = GER_mefo_bills_9
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_11 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_11
			add_idea = GER_mefo_bills_10
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_12 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_12
			add_idea = GER_mefo_bills_11
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_13 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_13
			add_idea = GER_mefo_bills_12
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_14 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_14
			add_idea = GER_mefo_bills_13
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_15 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_15
			add_idea = GER_mefo_bills_14
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_16 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_16
			add_idea = GER_mefo_bills_15
		}
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_17 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_17
			add_idea = GER_mefo_bills_16
		}		
	}
	else_if = {
		limit = { has_idea = GER_mefo_bills_18 }
		swap_ideas = {
			remove_idea = GER_mefo_bills_18
			add_idea = GER_mefo_bills_17
		}
	}
}

give_SOV_armor_research_bonuses = { #this effect is run for the Soviets!
	if = {
		limit = {
			NOT = {
				has_dlc = "No Step Back"
			}
		}
		add_tech_bonus = {
			name = med_armor_bonus
			ahead_reduction = 2
			category = cat_medium_armor
		}
		add_tech_bonus = {
			name = armor_bonus
			bonus = 1.0
			uses = 1
			category = armor
		}
	}
	if = { #double if because history files don't like else and this effect is run in the Soviet history file
		limit = {
			has_dlc = "No Step Back"
		}
		create_equipment_variant = {
			name = "A-20"
			type = medium_tank_chassis_1
			parent_version = 0
			modules = {
				main_armament_slot = tank_small_cannon_2
				turret_type_slot = tank_medium_two_man_tank_turret
				suspension_type_slot = tank_christie_suspension
				armor_type_slot = tank_welded_armor
				engine_type_slot = tank_diesel_engine
				special_type_slot_1 = sloped_armor
			}
			upgrades = {
				tank_nsb_engine_upgrade = 8
				tank_nsb_armor_upgrade = 2
			}
			icon = "GFX_SOV_basic_medium_tank_medium"
		}
		create_equipment_variant = {
			name = "KV-1"
			type = heavy_tank_chassis_1
			parent_version = 0
			modules = {
				main_armament_slot = tank_medium_cannon
				turret_type_slot = tank_heavy_three_man_tank_turret
				suspension_type_slot = tank_torsion_bar_suspension
				armor_type_slot = tank_welded_armor
				engine_type_slot = tank_diesel_engine		
			}
			upgrades = {
				tank_nsb_engine_upgrade = 10
				tank_nsb_armor_upgrade = 9
			}
			icon = "GFX_SOV_improved_heavy_tank_medium"
		}
		add_tech_bonus = {
			name = armor_bonus
			bonus = 1.0
			uses = 2
			category = armor
		}
	}
}

MR_pact_transfer_state_effect = {
	if = {
		limit = {
			96 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 96
						is_subject_of = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					any_other_country = {
						is_in_faction_with = SOU
						has_country_flag = BLT_soviets_said_yes_to_belarus_flag
					}
				}
			}
			SOU = { transfer_state = 96 }
		}
		else = {
			random_other_country = {
				limit = {
					is_in_faction_with = SOU
					OR = {
						has_cosmetic_tag = LIT_belarus
						has_cosmetic_tag = LAT_belarus
						has_cosmetic_tag = EST_belarus
						has_cosmetic_tag = BAL_UNIFIED
						tag = BLR
					}
				}
				transfer_state = 96
			}
		}
	}
	if = {
		limit = {
			95 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 95
						is_subject_of = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					any_other_country = {
						is_in_faction_with = SOU
						has_country_flag = BLT_soviets_said_yes_to_belarus_flag
					}
				}
			}
			BLR = { transfer_state = 95 }
		}
		else = {
			random_other_country = {
				limit = {
					is_in_faction_with = SOU
					OR = {
						has_cosmetic_tag = LIT_belarus
						has_cosmetic_tag = LAT_belarus
						has_cosmetic_tag = EST_belarus
						has_cosmetic_tag = BAL_UNIFIED
						tag = BLR
					}
				}
				transfer_state = 95
			}
		}
	}
	if = {
		limit = {
			977 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 95
						is_subject_of = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					any_other_country = {
						is_in_faction_with = SOU
						has_country_flag = BLT_soviets_said_yes_to_belarus_flag
					}
				}
			}
			BLR = { transfer_state = 977 }
		}
		else = {
			random_other_country = {
				limit = {
					is_in_faction_with = SOU
					OR = {
						has_cosmetic_tag = LIT_belarus
						has_cosmetic_tag = LAT_belarus
						has_cosmetic_tag = EST_belarus
						has_cosmetic_tag = BAL_UNIFIED
						tag = BLR
					}
				}
				transfer_state = 95
			}
		}
	}
	if = {
		limit = {
			94 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 94
						is_subject_of = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					any_other_country = {
						is_in_faction_with = SOU
						has_country_flag = BLT_soviets_said_yes_to_belarus_flag
					}
				}
			}
			BLR = { transfer_state = 94 }
		}
		else = {
			random_other_country = {
				limit = {
					is_in_faction_with = SOU
					OR = {
						has_cosmetic_tag = LIT_belarus
						has_cosmetic_tag = LAT_belarus
						has_cosmetic_tag = EST_belarus
						has_cosmetic_tag = BAL_UNIFIED
						tag = BLR
					}
				}
				transfer_state = 94
			}
		}
	}
	if = {
		limit = {
			97 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 97
						is_subject_of = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					any_other_country = {
						is_in_faction_with = SOU
						has_country_flag = BLT_soviets_said_yes_to_belarus_flag
					}
				}
			}
			BLR = { transfer_state = 97 }
		}
		else = {
			random_other_country = {
				limit = {
					is_in_faction_with = SOU
					OR = {
						has_cosmetic_tag = LIT_belarus
						has_cosmetic_tag = LAT_belarus
						has_cosmetic_tag = EST_belarus
						has_cosmetic_tag = BAL_UNIFIED
						tag = BLR
					}
				}
				transfer_state = 97
				97 = {
					add_core_of = PREV
				}
			}
		}
	}
	if = {
		limit = {
			784 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 784
						is_subject_of = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_global_flag = LIT_gets_vilnius
					LIT = { controls_state = 784 }
					LIT = { is_in_faction_with = SOU }
				}
				LIT = { exists = yes }
			}
			LIT = { transfer_state = 784 }
		}
		else_if = {
			limit = {
				NOT = {
					any_other_country = {
						is_in_faction_with = SOU
						has_country_flag = BLT_soviets_said_yes_to_belarus_flag
					}
				}
			}
			SOU = { transfer_state = 784 }
		}
		else = {
			random_other_country = {
				limit = {
					is_in_faction_with = SOU
					OR = {
						has_cosmetic_tag = LIT_belarus
						has_cosmetic_tag = LAT_belarus
						has_cosmetic_tag = EST_belarus
						has_cosmetic_tag = BAL_UNIFIED
						tag = BLR
					}
				}
				transfer_state = 784
			}
		}
	}
}

MR_pact_transfer_faction_state_effect = {
	if = {
		limit = {
			206 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 96
						is_in_faction_with = ROOT
					}
				}
			}
		}
		SOU = { transfer_state = 96 }
	}
	if = {
		limit = {
			95 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 95
						is_in_faction_with = ROOT
					}
				}
			}
		}
		SOU = { transfer_state = 95 }
	}
	if = {
		limit = {
			977 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 977
						is_in_faction_with = ROOT
					}
				}
			}
		}
		SOU = { transfer_state = 977 }
	}
	if = {
		limit = {
			94 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 94
						is_in_faction_with = ROOT
					}
				}
			}
		}
		SOU = { transfer_state = 94 }
	}
	if = {
		limit = {
			97 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = {
						controls_state = 97
						is_in_faction_with = ROOT
					}
				}
			}
		}
		SOU = { transfer_state = 97 }
	}
	if = {
		limit = {
			784 = {
				OR = {
					is_controlled_by = ROOT
					any_other_country = { 
						controls_state = 784
						is_in_faction_with = ROOT
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					has_global_flag = LIT_gets_vilnius
					LIT = { controls_state = 784 }
				}
				LIT = { exists = yes }
			}
			LIT = { transfer_state = 784 }
		}
		else = {
			SOU = { transfer_state = 784 }
		}
	}
}