GGR_set_up_RK_ROOT = {

	hidden_effect = { #should've done that long ago tbh

		if = {
			limit = { NOT = { has_country_flag = GGR_set_up_RK_ROOT_done } }
			econ_join_sphere_GER = yes

			set_country_flag = GGR_set_up_RK_ROOT_done

			remove_all_ideas = yes
			TNO_startup_nation = yes # there's already a stack preventor and this might fix some shit on the way
			remove_faction_status = yes
			GGR_lock_division_making = yes

			inherit_technology = GER
			set_technology = {
				nuclear_reactors = 0
				nuclear_weapons = 0
			}
			if = {
				limit = { is_ai = yes }
				add_ideas = GGR_gorings_rk
			}

			set_temp_variable = { business_tax_temp = 0.2 }
			econ_business_tax_rate_change = yes
			set_temp_variable = { income_tax_temp = 0.2 }
			econ_income_tax_rate_change = yes
			set_temp_variable = { sales_tax_temp = 0.02 }
			econ_sales_tax_rate_change = yes

			every_country = {
				limit = {
					NOT = {
						is_in_faction_with = GER
						is_subject_of = GER
						has_idea = Pakt_Observer
					}
				}
				PREV = {
					set_embargo_PREV = yes
				}
				set_embargo_PREV = yes
			}
			every_country = {
				limit = {
					is_in_faction_with = GER
				}
				PREV = {
					clear_embargo_PREV = yes
				}
				clear_embargo_PREV = yes
			}
			if = {
				limit = {
					OR = {
						tag = ENG
						tag = HUN
						tag = BOR
					}
				}
				add_ideas = Pakt_Marionettenstaat
				GER = {
					set_autonomy = {
						target = PREV
						autonomous_state = autonomy_collaborator_puppet_state
						end_wars = no
						end_civil_wars = no
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						tag = SCN
						tag = GSL
						tag = MCW
						tag = UKR
						tag = BEL
						AND = {
							tag = CAU
							has_country_leader = {
								character = CAU_paul_pleiger
								ruling_only = yes
							}
						}
					}
				}
				add_ideas = Pakt_Autonomous_Reichskommissariat
				GER = {
					set_autonomy = {
						target = PREV
						autonomous_state = autonomy_autonomous_reichskommissariat
						end_wars = no
						end_civil_wars = no
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						tag = RCA
						tag = ROA
						tag = GWA
						tag = RSA
						tag = GEA
						tag = RKM
						tag = WAF
						tag = NAF
						tag = GWA
						tag = MAD
						tag = MDG
						tag = TSM
						tag = RMK
						tag = CAU
						tag = GAR
						tag = GBR
						tag = GCO
					}
				}
				add_ideas = Pakt_Reichskolonie
				GER = {
					set_autonomy = {
						target = PREV
						autonomous_state = autonomy_reichskolonie
						end_wars = no
						end_civil_wars = no
					}
				}
			}
			else_if = {
				limit = {
					OR = {
						tag = HOL
						tag = OST
						tag = GGN
						tag = DST
						tag = BEL
					}
				}
				add_ideas = Pakt_Integrated_Reichskommissariat
				GER = {
					set_autonomy = {
						target = PREV
						autonomous_state = autonomy_integrated_reichskommissariat
						end_wars = no
						end_civil_wars = no
					}
				}
			}
			else = {
				add_ideas = Pakt_Military_Authority
				GER = {
					set_autonomy = {	
						target = PREV
						autonomy_state = autonomy_military_government
						end_wars = no
						end_civil_wars = no
					}
				}
			}
			if = {
				limit = {
					NOT = { has_idea = GGR_garrisons_from_germany_dummy }
					OR = {
						has_idea = Pakt_Autonomous_Reichskommissariat
						has_idea = Pakt_Integrated_Reichskommissariat
						has_idea = Pakt_Military_Authority
						has_idea = Pakt_Reichskolonie
					}
				}
				add_ideas = GGR_garrisons_from_germany_dummy
				set_variable = { garrison_draining_factor = 1 }
			}
			GGR_update_garrison_draining = yes

			if = {
				limit = {
					NOT = {
						has_country_flag = GGR_install_RK_with_no_changes
					}
				}

				set_research_slots = 0
							
				set_stability = 0.25
				set_war_support = -0.1

				set_popularities = {
					national_socialism = 60
					national_socialism_2 = 40
				}
				if = {
					limit = {
						exists = yes
					}
					GGR_transfer_general_RK_guy = yes
				}


				set_politics = {
					ruling_party = national_socialism_2
				}
				set_country_leader_ideology = national_socialism_2_schorner_subtype
				set_politics = {
					ruling_party = national_socialism
				}

				add_ideas = {
					# Political
					tno_political_parties_one_party_state
					tno_religious_rights_suppression_of_churches
					tno_trade_unions_illegal
					tno_immigration_closed_borders
					tno_slavery_chattel
					tno_public_meetings_outlawed
					tno_press_rights_state_press_only
					tno_vote_franchise_no_voting
					# Military
					tno_conscription_volunteer_only
					tno_military_supervision_kill_em_all
					tno_training_basic_training
					tno_draft_exemptions_none
					# Social
					tno_health_care_service_for_care
					tno_education_restricted_education
					tno_penal_system_politicized_penal_system
					tno_gender_rights_traditional_roles
					tno_security_resource_extraction
					tno_regulations_token_regulations
					# Economic
					tno_trade_laws_limited_exports
					tno_income_taxation_high_income_weighted
					tno_minimum_wage_trinket_minimum_wage
					tno_max_workhours_unlimited_work_day
					tno_pensions_no_pensions
					tno_unemployment_no_subsidies
					# Misc
					tno_refugees_skilled
					tno_women_banned
					tno_racial_integration_integrated_military
					tno_safety_minimal_regulations
					tno_pollution_no_controls
					tno_lgbt_rights_lgbt_outlawed
					tno_minorities_oppression
					tno_child_labor_legal
				}

				#econtype
				set_variable = { TNO_economy_type = token:Econ_Type_Planned }
				if = {
					limit = {
						OR = {
							tag = NAF
							tag = WAF
							tag = GWA
							tag = RCA
							tag = RSA
							tag = ROA
							tag = GEA
							tag = RSA
							tag = MAD
							tag = RKM
						}
					}
					set_variable = { TNO_economy_subtype = token:Econ_Subtype_Colonial_Economy_Corporatism }
				}
				else = {
					set_variable = { TNO_economy_subtype = token:Econ_Subtype_Gelenkte_Wirtschaft }
				}
			}
			else = {
				clr_country_flag = GGR_install_RK_with_no_changes
			}

			if = {
				limit = {
					NOT = { tag = SCN }
				}
				add_timed_idea = {
					idea = GGR_stabilising_regime
					days = 730
				}
			}
			
			set_variable = { national_debt = 0 }

			GER = {
				country_event = {
					id = goering_expanded.99
					days = 1
				}
			}
			country_event = { id = goering_expanded.102 days = 3 }
		}
		add_core_effect = yes
	}
}

GGR_install_RK_with_no_changes = {
	get_current_government_type = yes
	save_party_popularities = yes
	set_country_flag = GGR_install_RK_with_no_changes
	GGR_set_up_RK_ROOT = yes
	restore_previous_government_type = yes
	apply_party_popularities = yes
}

GGR_set_up_RK_ROOT_forcibly = {
	clr_country_flag = GGR_set_up_RK_ROOT_done
	GGR_set_up_RK_ROOT = yes
}

ggr_test = {
	MDG = {
		save_global_event_target_as = losing_country
		set_cosmetic_tag = MDG_GERMAN
	}
	MAD = {
		save_global_event_target_as = winning_country
		set_cosmetic_tag = MAD_insurgent
	}
	add_to_variable = { global.peace_popup_dirty = 1 }
}
ggr_test1 = {
	every_country = {
		limit = {
			has_dynamic_modifier = { modifier = RUS_war_weariness }
		}
		remove_dynamic_modifier = { modifier = RUS_war_weariness }
	}
}

add_to_faction_effect = {
	ROOT = {
		leave_faction = yes
	}
	FROM = {
		white_peace = ROOT
		add_to_faction = ROOT
	}
}

calculate_resistance_for_russian_mws = {
	custom_effect_tooltip = GGR_russian_resistance_tooltip
	hidden_effect = {
		clamp_variable = {
			var = GER.GGR_russian_population_anger
			min = 0
			max = 1
		}
		set_variable = { GER.GGR_russian_population_anger_negative = GER.GGR_russian_population_anger }
		multiply_variable = { GER.GGR_russian_population_anger_negative = -1 }
		set_variable = { GER.min_resistance = GER.GGR_russian_population_anger }
		multiply_variable = { GER.min_resistance = 100 }
		every_state = {
			limit = {
				is_russian_state = yes
				controller = {
					is_in_faction_with = GER
				}
			}
			if = {
				limit = {
					NOT = { has_state_flag = GGR_russian_state_resistance_flag }
				}
				set_state_flag = GGR_russian_state_resistance_flag
				add_province_modifier = {
					static_modifiers = { GGR_russian_state_resistance }
					province = {
						all_provinces = yes
					}
				}
			}
			if = {
				limit = {
					NOT = {
						is_core_of = PREV
					}
					check_variable = {
						GER.min_resistance > resistance
					}
				}
				set_resistance = GER.min_resistance
			}
		}
	}
}

stop_russian_warlords_wars = {
	every_country = {
		limit = {
			is_russian_nation = yes
			NOT = {
				is_in_faction_with = GER
			}
		}
		every_country = {
			limit = {
				is_russian_nation = yes
				NOT = {
					is_in_faction_with = GER
				}
			}
			white_peace = PREV
		}
	}
}

#Tree Reloader
GGR_Reload_main = {
	custom_effect_tooltip = USA_more_focus_tree_options
	hidden_effect = {
		mark_focus_tree_layout_dirty = yes
	}
}

GER_GOR_epilogue_trigger = {
	hidden_effect = {
		if = {
			limit = {
				has_completed_focus = GER_GOR_the_black_sun_eclipsed
				has_completed_focus = GGR_break_the_unbroken_line
				has_completed_focus = GER_GOR_their_last_best_hoped_dimmed	
			}
			set_country_flag = GER_GOR_epilogue_content
			mark_focus_tree_layout_dirty = yes
		}
	}
}

declare_war_with_rks = {
	if = {
		limit = {
			exists = yes
		}
		custom_effect_tooltip = GGR_declare_war_on
		hidden_effect = {
			if = {
				limit = {
					NOT = {
						has_war_with = GER
					}
				}
				GER = {
					declare_war_on = {
						target = PREV
						type = annex_everything
					}
				}
			}
			every_neighbor_country = {
				limit = { is_in_faction_with = GER }
				if = {
					limit = {
						NOT = {
							has_war_with = PREV
						}
					}
					add_to_war = {
						targeted_alliance = GER
						enemy = PREV
						hostility_reason = asked_to_join
					}
				}
			}
			every_country = {
				limit = {
					is_in_faction_with = GER
					is_subject = no
				}
				add_to_war = {
					targeted_alliance = GER
					enemy = PREV
					hostility_reason = asked_to_join
				}
			}
		}
	}
}

GGR_repair_germany = {
	if = {
		limit = { has_idea = GGR_rebuilding_germany5 }
		remove_ideas = GGR_rebuilding_germany5
	}
	else_if = {
		limit = { has_idea = GGR_rebuilding_germany4 }
		swap_ideas = {
			remove_idea = GGR_rebuilding_germany4
			add_idea = GGR_rebuilding_germany5
		}
	}
	else_if = {
		limit = { has_idea = GGR_rebuilding_germany3 }
		swap_ideas = {
			remove_idea = GGR_rebuilding_germany3
			add_idea = GGR_rebuilding_germany4
		}
	}
	else_if = {
		limit = { has_idea = GGR_rebuilding_germany2 }
		swap_ideas = {
			remove_idea = GGR_rebuilding_germany2
			add_idea = GGR_rebuilding_germany3
		}
	}
	else_if = {
		limit = { has_idea = GGR_rebuilding_germany }
		swap_ideas = {
			remove_idea = GGR_rebuilding_germany
			add_idea = GGR_rebuilding_germany2
		}
	}
}

GGR_plan_A_max_planning = {
	add_timed_idea = {
		idea = GGR_back_to_the_drawing_room
		days = 90
	}
}

GGR_clear_temporary_variables = {
	clear_variable = GGR_temporary_soft_attack
	clear_variable = GGR_temporary_speed
	clear_variable = GGR_temporary_bombing
	clear_variable = GGR_temporary_repair_speed
	clear_variable = GGR_temporary_organisation_factor
	clear_variable = GGR_temporary_air_cas_present_factor
	clear_variable = GGR_temporary_entrenchment_speed
	clear_variable = GGR_temporary_reinforce_rate
	clear_variable = GGR_temporary_planning_speed
	clear_variable = GGR_temporary_attrition
	clear_variable = GGR_temporary_infantry_attack
	clear_variable = GGR_temporary_paradrop_attack
	clear_variable = GGR_temporary_supply_grace
	clear_variable = GGR_temporary_invasion_speed
	clear_variable = GGR_temporary_harbour_construction_speed
	clear_variable = GGR_temporary_max_command_power
	clear_variable = GGR_temporary_experience_loss_factor
	clear_variable = GGR_temporary_army_organisation
	clear_variable = GGR_temporary_experience_gain_army_factor
	clear_variable = GGR_temporary_max_planning
	clear_variable = GGR_temporary_army_armor_attack_factor
	clear_variable = GGR_temporary_army_armor_speed_factor
	clear_variable = GGR_temporary_defence_factor
	clear_variable = GGR_temporary_special_forces_attack_factor
	clear_variable = GGR_temporary_special_forces_defence_factor
	clear_variable = GGR_temporary_army_bonus_air_superiority_factor
	clear_variable = GGR_temporary_army_artillery_attack_factor
	clear_variable = GGR_temporary_army_morale_factor
	clear_variable = GGR_temporary_winter_attrition_factor
	clear_variable = GGR_temporary_training_time_army_factor
	clear_variable = GGR_temporary_acclimatization_cold_climate_gain_factor
	clear_variable = GGR_temporary_mechanized_attack_factor
	clear_variable = GGR_temporary_mechanized_defence_factor
	clear_variable = GGR_temporary_convoy_escort_efficiency
	clear_variable = GGR_temporary_invasion_preparation
	clear_variable = GGR_temporary_convoy_raiding_efficiency
	clear_variable = GGR_temporary_enemy_partisan_effect
	clear_variable = GGR_temporary_war_support
	clear_variable = GGR_temporary_supply_consumption
	clear_variable = GGR_temporary_resistance_target
	clear_variable = GGR_temporary_decryption_factor
	clear_variable = GGR_temporary_heat_attrition_factor
}

GGR_anti_goering_upgrade = {
	if = {
		limit = { has_idea = GGR_anti_goering_4 }
		swap_ideas = {
			remove_idea = GGR_anti_goering_4
			add_idea = GGR_anti_goering_5
		}
	}
	else_if = {
		limit = { has_idea = GGR_anti_goering_3 }
		swap_ideas = {
			remove_idea = GGR_anti_goering_3
			add_idea = GGR_anti_goering_4
		}
	}
	else_if = {
		limit = { has_idea = GGR_anti_goering_2 }
		swap_ideas = {
			remove_idea = GGR_anti_goering_2
			add_idea = GGR_anti_goering_3
		}
	}
	else_if = {
		limit = { has_idea = GGR_anti_goering_1 }
		swap_ideas = {
			remove_idea = GGR_anti_goering_1
			add_idea = GGR_anti_goering_2
		}
	}
	else_if = {
		limit = { has_idea = GGR_anti_goering_5 }
	}
	else = {
		add_ideas = GGR_anti_goering_1
	}
}

GGR_increase_japanese_awarenes = {
	custom_effect_tooltip = GGR_increase_japanese_awarenes_tooltip
	if = {
		limit = {
			check_variable = { GGR_tension_with_japan = 0 }
		}
		add_to_variable = {
			var = GGR_tension_with_japan
			value = 2
		}
	}
	if = {
		limit = {
			AND = {
				check_variable = { GGR_tension_with_japan > 0 }
				check_variable = { GGR_tension_with_japan < 10 }
			}
		}
		add_to_variable = {
			var = GGR_tension_with_japan
			value = 1
		}
	}
	if = {
		limit = {
			check_variable = { GGR_tension_with_japan = 15 }
		}
		add_to_variable = {
			var = GGR_tension_with_japan
			value = 1
		}
		every_country = {
			limit = { is_in_faction_with = JAP }
			declare_war_on = {
				target = GER
				type = annex_everything
			}
			every_neighbor_country = {
				limit = { is_in_faction_with = GER }
				JAP = {
					declare_war_on = {
						target = PREV
						type = annex_everything
					}
				}
			}
		}
	}
}

# Science variables

GGRCSI_increase_corruption = {
	custom_effect_tooltip = GGR_increase_GGRCSI_corruption_tooltip
	add_to_variable = { GGRCSI_corruption = 0.05 }
	clamp_variable = { var = GGRCSI_corruption min = 0 max = 1 }
}

GGRCSI_decrease_corruption = {
	custom_effect_tooltip = GGR_decrease_GGRCSI_corruption_tooltip
	subtract_from_variable = { GGRCSI_corruption = 0.05 }
	clamp_variable = { var = GGRCSI_corruption min = 0 max = 1 }
}

GGRCSI_increase_public_concern = {
	custom_effect_tooltip = GGR_increase_public_concern_tooltip
	add_to_variable = { GGRCSI_public_concern = 0.05 }
	clamp_variable = { var = GGRCSI_public_concern min = 0 max = 1 }
}

GGRCSI_decrease_public_concern = {
	custom_effect_tooltip = GGR_decrease_public_concern_tooltip
	subtract_from_variable = { GGRCSI_public_concern = 0.05 }
	clamp_variable = { var = GGRCSI_public_concern min = 0 max = 1 }
}

GGRCSI_increase_military_concern = {
	custom_effect_tooltip = GGR_increase_military_concern_tooltip
	add_to_variable = { GGRCSI_military_concern = 0.05 }
	clamp_variable = { var = GGRCSI_military_concern min = 0 max = 1 }
}

GGRCSI_decrease_military_concern = {
	custom_effect_tooltip = GGR_decrease_military_concern_tooltip
	subtract_from_variable = { GGRCSI_military_concern = 0.05 }
	clamp_variable = { var = GGRCSI_military_concern min = 0 max = 1 }
}

GGRCSI_decrease_military_power = {
	custom_effect_tooltip = GGRCSI_decrease_military_power_tooltip
	if = {
		limit = {
			check_variable = { GGRCSI_corruption > 0.66 }
		}
		GGR_decrease_militarist_power_large = yes
		random_list = {
			8 = {
				GGRCSI_increase_military_concern = yes
			}

			2 = {

			}

		}
	}
	else_if = {
		limit = {
			check_variable = { GGRCSI_corruption > 0.33 }
		}
		GGR_decrease_militarist_power = yes
		random_list = {
			5 = {
				GGRCSI_increase_military_concern = yes
			}

			5 = {

			}
		}
	}
	else = {
		GGR_decrease_militarist_power_small = yes
		random_list = {
			2 = {
				GGRCSI_increase_military_concern = yes
			}

			8 = {

			}
		}
	}
}

GGRCSI_calculate_total_nuclear_reactors = {
	GER = {
		subtract_from_variable = { GGRCSI_spending = nuclear_spending }
		set_variable = { nuclear_spending = 0 }
		set_variable = { GGRCSI_total_nuclear_reactors = 0 }
		for_each_scope_loop = {
			array = owned_controlled_states

			add_to_variable = { GER.GGRCSI_total_nuclear_reactors = building_level@nuclear_reactor }
			add_to_variable = { GER.nuclear_spending = building_level@nuclear_reactor }
		}
	}

	UKR = {
		for_each_scope_loop = {
			array = owned_controlled_states

			add_to_variable = { UKR.GGRCSI_total_nuclear_reactors = building_level@nuclear_reactor }
			add_to_variable = { UKR.nuclear_spending = building_level@nuclear_reactor }
		}
	}
	GER = {
		add_to_variable = { GGRCSI_total_nuclear_reactors = UKR.GGRCSI_total_nuclear_reactors }
		divide_variable = { UKR.nuclear_spending = 2 }
		add_to_variable = { nuclear_spending = UKR.nuclear_spending }

		multiply_variable = { nuclear_spending = nuclear_maintenance }
		add_to_variable = { GGRCSI_spending = nuclear_spending }
		add_to_variable = { misc_costs = nuclear_spending }
	}
}

GGRCSI_update_spending = {
	set_variable = { GGR_GGRCSI_misc_costs = GGRCSI_spending }
	divide_variable = { GGR_GGRCSI_misc_costs = 1000 }
	set_temp_variable = { calculated_corruption = GGRCSI_corruption }
	multiply_temp_variable = { calculated_corruption = 5 }
	multiply_variable = { GGR_GGRCSI_misc_costs = calculated_corruption }
}

anti_goering_send_equipment = {
	if = {
		limit = {
			GER = { is_ai = no }
			is_ai = yes
			has_equipment = {
				infantry_equipment < 4999
			}
		}
		FROM = {
			add_equipment_to_stockpile = {
				type = infantry_equipment
				amount = 5000
			}
		}
	}
	else = {
		send_equipment = {
			equipment = infantry_equipment
			amount = 5000
			target = FROM
		}
	}
}

anti_goering_send_volunteers = {
	set_temp_variable = { target = FROM }
	set_temp_variable = { divider = 2 }
	set_temp_variable = { to_add = FROM.num_owned_states }
	if = {
		limit = {
			GER = { has_country_flag = GER_war_plan_zero }
		}
		set_temp_variable = { divider = 4 }
	}
	if = {
		limit = {
			GER = { has_country_flag = GER_war_plan_A }
		}
		set_temp_variable = { divider = 3 }
	}
	divide_temp_variable = { to_add = divider }
	round_temp_variable = to_add
	TNO_add_num_volunteers = yes
	
}

TNO_increase_volunteer_cap_5 = {
	set_temp_variable = { to_add = 5 }
	TNO_add_num_volunteers = yes
}

GGR_update_anarchy = {
	for_each_scope_loop = {
		array = GER.GGR_anarchy_states
		if = {
			limit = {
				any_country = {
					owns_state = PREV
					OR = {
						is_in_faction_with = GER
						tag = ZZZ
					}
				}
			}
			set_demilitarized_zone = yes
		}
	}
}

GGR_update_garrison_mech = {
	set_variable = { GER.GGR_manpower_eating_overall = 0 }
	set_variable = { GER.GGR_money_eating_overall = 0 }
	every_country = {
		limit = {
			has_idea = GGR_garrisons_from_germany_dummy
		}
		GGR_update_garrison_draining = yes
		add_to_variable = { GER.GGR_manpower_eating_overall = GGR_manpower_eating }
		add_to_variable = { GER.GGR_money_eating_overall = GGR_money_eating }
	}
	add_to_variable = { GER.GGR_manpower_eating_overall = GER.GGR_garrisons_from_germany_bonus }
	clamp_variable = {
		var = GER.GGR_manpower_eating_overall
		max = 0
	}
	if = {
		limit = {
			GER = { is_ai = yes }
		}
		clamp_variable = {
			var = GER.GGR_manpower_eating_overall
			min = -1
		}
	}
}

GGR_update_garrison_draining = {
	set_variable = { GGR_manpower_eating = max_manpower_k }
	every_owned_state = {
		limit = {
			is_demilitarized_zone = yes
		}
		subtract_from_variable = { PREV.GGR_manpower_eating = state_population_k }
	}
	round_variable = GGR_manpower_eating
	if = {
		limit = {
			OR = {
				has_idea = Pakt_Military_Authority
			}
		}
		divide_variable = { GGR_manpower_eating = -500000 }
	}
	else_if = {
		limit = {
			OR = {
				has_idea = Pakt_Autonomous_Reichskommissariat
				has_idea = Pakt_Integrated_Reichskommissariat
				has_idea = Pakt_Reichskolonie
			}
		}
		divide_variable = { GGR_manpower_eating = -1000000 }
	}
	if = { # you eat too much
		limit = {
			OR = {
				tag = RIN
				tag = ROC
				tag = INS
			}
		}
		divide_variable = { GGR_manpower_eating = 4 }
	}
	multiply_variable = { GGR_manpower_eating = garrison_draining_factor }
	set_variable = { GGR_money_eating = GGR_manpower_eating }
	multiply_variable = { GGR_money_eating = -50 }
}

GGR_update_garrison_draining_old = {
	set_variable = { GGR_manpower_eating = num_owned_controlled_states }
	every_owned_state = {
		limit = {
			is_demilitarized_zone = yes
		}
		subtract_from_variable = { PREV.GGR_manpower_eating = 1 }
	}
	if = {
		limit = {
			GER = { is_ai = yes }
		}
		multiply_variable = { GGR_manpower_eating = 0.75 }
	}
	round_variable = GGR_manpower_eating
	if = {
		limit = {
			OR = {
				has_idea = Pakt_Military_Authority
			}
		}
		multiply_variable = { GGR_manpower_eating = -0.002 }
	}
	else_if = {
		limit = {
			OR = {
				has_idea = Pakt_Autonomous_Reichskommissariat
				has_idea = Pakt_Integrated_Reichskommissariat
				has_idea = Pakt_Reichskolonie
			}
		}
		multiply_variable = { GGR_manpower_eating = -0.001 }
	}
	multiply_variable = { GGR_manpower_eating = garrison_draining_factor }
}

GGR_add_on_our_own = {
	if = {
		limit = {
			OR = {
				if = {
					limit = {
						is_subject = yes
					}
					OR = {
						is_subject_of = USA
						is_subject_of = JAP
						is_subject_of = ITA
						is_subject_of = CAN
					}
				}
				else_if = {
					limit = {
						is_in_faction = yes
					}
					OR = {
						is_in_faction_with = USA
						is_in_faction_with = JAP
						is_in_faction_with = ITA
					}
				}
				else_if = {
					limit = {
						any_country = {
							has_guaranteed = PREV
						}
					}
					OR = {
						is_guaranteed_by = USA
						is_guaranteed_by = JAP
						is_guaranteed_by = ITA
					}
				}
				else = { always = no }
			}
		}
		custom_effect_tooltip = GGR_on_our_own_tooltip
		set_country_flag = GGR_target
		if = {
			limit = {
				NOT = { has_variable = on_our_own_timer }
			}
			set_variable = { THIS.on_our_own_timer = 30 }
		}
		custom_effect_tooltip = GGR_on_our_own_timer_tooltip
		hidden_effect = {
			GGR_teleport_foreign_armies_home = yes
			if = {
				limit = {
					is_subject = yes
				}
				overlord = {
					end_puppet = PREV
					save_global_event_target_as = puppet_master
				}
			}
			#else_if = {
			#	limit = {
			#		is_in_faction = yes
			#	}
			#	leave_faction = yes
			#	faction_leader = { save_global_event_target_as = faction_master }
			#}
			else_if = {
				limit = {
					any_country = {
						has_guaranteed = PREV
					}
				}
				every_country = {
					limit = {
						has_guaranteed = PREV
					}					
			        diplomatic_relation = {
			            country = PREV
			            relation = guarantee
			            active = no
					}
					save_global_event_target_as = puppet_master
				}
			}
			if = {
				limit = {
					GER = { is_ai = yes }
				}
				multiply_variable = { THIS.on_our_own_timer = 2 }
			}
			add_timed_idea = {
				idea = GGR_on_our_own
				days = THIS.on_our_own_timer
			}
			if = {
				limit = {
					is_ai = no
				}
				every_country = {
					limit = {
						is_in_faction_with = PREV
					}
					add_timed_idea = {
						idea = GGR_on_our_own_hidden_allies
						days = PREV.on_our_own_timer
					}
				}
			}
			every_subject_country = {
				add_timed_idea = {
					idea = GGR_on_our_own
					days = PREV.on_our_own_timer
				}
			}
		}
	}
}

GGR_choose_closest_russian_unifier = {
	hidden_effect = {
		if = {
			limit = {
				any_country = {
					can_form_west_russia = yes
				}
			}
			random_country = {
				limit = {
					can_form_west_russia = yes
				}
				save_global_event_target_as = RUS_western_unifier
			}
		}
		if = {
			limit = {
				any_country = {
					can_form_west_siberia = yes
				}
			}
			random_country = {
				limit = {
					can_form_west_siberia = yes
				}
				save_global_event_target_as = RUS_west_siberia_unifier
			}
		}
		if = {
			limit = {
				any_country = {
					can_form_central_siberia = yes
				}
			}
			random_country = {
				limit = {
					can_form_central_siberia = yes
				}
				save_global_event_target_as = RUS_central_siberia_unifier
			}
		}
		if = {
			limit = {
				any_country = {
					can_form_far_east = yes
				}
			}
			random_country = {
				limit = {
					can_form_far_east = yes
				}
				save_global_event_target_as = RUS_far_east_unifier
			}
		}
		random_country = {
			limit = {
				is_central_russian_nation = yes
				exists = yes
				has_war_with = GER
			}
			save_global_event_target_as = RUS_closest_unifier
		}
		if = {
			limit = {
				NOT = { has_event_target = RUS_closest_unifier }
			}
			random_country = {
				limit = {
					is_west_siberian_nation = yes
					exists = yes
					has_war_with = GER
				}
				save_global_event_target_as = RUS_closest_unifier
			}
		}
		if = {
			limit = {
				NOT = { has_event_target = RUS_closest_unifier }
			}
			random_country = {
				limit = {
					is_central_siberian_nation = yes
					exists = yes
					has_war_with = GER
				}
				save_global_event_target_as = RUS_closest_unifier
			}
		}
		if = {
			limit = {
				NOT = { has_event_target = RUS_closest_unifier }
			}
			random_country = {
				limit = {
					is_far_eastern_nation = yes
					exists = yes
					has_war_with = GER
				}
				save_global_event_target_as = RUS_closest_unifier
			}
		}
	}
}

GGR_decide_salted_earth_limits = {
	if = {
		limit = {
			KOM = {
				exists = yes
				has_government = national_socialism
			}
		}
		if = {
			limit = {
				has_global_flag = RUS_West_Russian_unification
			}
			MCW = {
				set_country_flag = GGR_add_salted_earth
			}
			RKU = {
				set_country_flag = GGR_add_salted_earth
			}
		}
		if = {
			limit = {
				has_global_flag = RUS_Russia_unification
			}
			RKS = {
				set_country_flag = GGR_add_salted_earth
			}
			if = {
				limit = {
					NOT = {
						any_country = {
							is_kazakh_nation = yes
							exists = yes
						}
					}
				}
				RKT = {
					set_country_flag = GGR_add_salted_earth
				}
			}
		}
		if = {
			limit = {
				has_global_flag = RUS_national_unification
			}
			RKS = {
				set_country_flag = GGR_add_salted_earth
			}
		}
	}
}

GGR_choose_moskowien_unifier = {
	if = {
		limit = {
			country_exists = PAU
		}
		PAU = { save_global_event_target_as = moskowien_unifier }
	}
	else_if = {
		limit = {
			country_exists = NTI
		}
		NTI = { save_global_event_target_as = moskowien_unifier }
	}
	else_if = {
		limit = {
			country_exists = LUF
		}
		LUF = { save_global_event_target_as = moskowien_unifier }
	}
	else_if = {
		limit = {
			country_exists = NTA
		}
		NTA = { save_global_event_target_as = moskowien_unifier }
	}
	else_if = {
		limit = {
			country_exists = OZO
			OZO = { has_government = fascism }
		}
		OZO = { save_global_event_target_as = moskowien_unifier }
	}
	if = {
		limit = {
			has_event_target = moskowien_unifier
		}
		event_target:moskowien_unifier = {
			set_variable = { GER.moskowien_unifier = THIS }
			every_character = {
				limit = { is_country_leader = yes }
				set_character_flag = moskowien_leader
			}
			THIS = {
				apply_war_buff_with_2_divisions = yes
			}
			if = {
				limit = {
					tag = LUF
				}
				annex_country = {
					target = OZM
					transfer_troops = yes
				}
			}
		}
	}
}

GGR_peacefully_transfer_moskowien = {
	if = {
		limit = {
			NOT = { has_event_target = moskowien_unifier }
		}
		GGR_choose_moskowien_unifier = yes
	}
	MCW = {
		annex_country = {
			target = event_target:moskowien_unifier
			transfer_troops = no
		}
		GGR_set_up_RK_ROOT = yes
		hidden_effect = {
			event_target:moskowien_unifier = {
				every_character = {
					set_nationality = MCW
					MCW = {
						promote_character = {
							character = MCW_hans_krebs
							ideology = national_socialism_idiosyncratic_nazism_subtype
						}
						GER = { country_event = { id = goering.heinrich.1 days = 2 } }
					}
				}
			}
		}
	}
}


GGR_teleport_foreign_armies_home = {
	every_owned_state = {
		teleport_armies = {
			limit = {
				is_in_faction_with = PREV.PREV
				NOT = {
					tag = PREV.PREV
					has_war_with = GER
				}
			}
		}
	}
}

GGR_transfer_general_RK_guy = {
	GER = {
		if = {
			limit = {
				PREV = {
					tag = GSL
				}
			}
			GER_friedrich_foertsch = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = SCN
					NOT = {
						has_country_leader = {
							character = NOR_Henry_Rinnan
							ruling_only = yes
						}
					}
				}
			}
			GER_heinzgeorg_lemm = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = UKR
				}
			}
			GER_eduard_wagner = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = MCW
				}
			}
			GER_hans_krebs = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				tag = CAU
			}
			GER_alfred_becker = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKB
				}
			}
			GER_leo_hepp = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = CAU
				}
			}
			GER_alfred_becker = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GLC
				}
			}
			GER_heinz_gunther_guderian = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = OST
				}
			}
			GER_albert_bormann = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKU
				}
			}
			GER_werner_mummert = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKS
				}
			}
			GER_bern_von_baer = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKF
				}
			}
			GER_theodor_tolsdorff = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GCA
				}
			}
			GER_otto_hitzfeld = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GBQ
				}
			}
			GER_karl_theodor_molinari = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKG
				}
			}
			GER_axel_von_dem_bussche = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GKA
				}
			}
			GER_franz_poschl = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GPG
				}
			}
			GER_alfred_zerbel = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = NAF
				}
			}
			GER_friedrich_august_freiherr_von_der_heydte = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RCA
				}
			}
			COG_siegfried_muller = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = LOM
				}
			}
			GGR_ernst_barkmann = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GEA
				}
			}
			GER_fritz_bayerlein = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = ROA
				}
			}
			GER_adolf_heusinger = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GWA
				}
			}
			GER_robert_gysae = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RSA
				}
			}
			GER_ulrich_de_maiziere = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKA
				}
			}
			GER_gerhard_von_schwerin = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKP
				}
			}
			GER_wolf_graf_von_baudissin = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RIN
				}
			}
			GER_heinrich_theodor_goring = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = ROC
				}
			}
			GER_otto_von_bülow = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GVT
				}
			}
			GER_erich_barenfanger = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RKO
				}
			}
			GER_heinz_kühnle = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = ENA
				}
			}
			GER_karljesko_von_puttkamer = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = BKT
				}
			}
			GER_armin_zimmermann = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = TOH
				}
			}
			GER_erich_topp = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GAS
				}
			}
			GER_bernhard_rogge = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GCO
				}
			}
			GER_hans_teusen = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = WST
				}
			}
			GER_heinrich_trettner = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RMI
				}
			}
			GER_ferdinand_schorner = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RLA
				}
			}
			GER_heinrich_lehmannwillenbrock = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = AMK
				}
			}
			GER_hansjoachim_hajo_herrmann = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GCR
				}
			}
			GER_karlfriedrich_merten = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GQB
				}
			}
			GER_berthold_maria_schenk_graf_von_stauffenberg = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = ANA
				}
			}
			GER_karl_donitz = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RLA
				}
			}
			GER_heinrich_lehmannwillenbrock = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = RLA
				}
			}
			GER_heinrich_lehmannwillenbrock = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = GAR
				}
			}
			GER_johannes_steinhoff = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
		if = {
			limit = {
				PREV = {
					tag = ADS
				}
			}
			GER_harald_von_hirschfeld = {
				set_character_flag = GGR_sent_to_brazil
				set_nationality = TSM
			}
		}
	}
}