
###################################################################################################
###################################################################################################
###################################################################################################

########  ########  ######## ########      ######  ##    ##  ######  ######## ######## ##     ## 
##     ## ##     ## ##       ##     ##    ##    ##  ##  ##  ##    ##    ##    ##       ###   ### 
##     ## ##     ## ##       ##     ##    ##         ####   ##          ##    ##       #### #### 
########  ########  ######   ########      ######     ##     ######     ##    ######   ## ### ## 
##        ##   ##   ##       ##                 ##    ##          ##    ##    ##       ##     ## 
##        ##    ##  ##       ##           ##    ##    ##    ##    ##    ##    ##       ##     ## 
##        ##     ## ######## ##            ######     ##     ######     ##    ######## ##     ## 

###################################################################################################
###################################################################################################
###################################################################################################

NOR_set_prepare_variables_historical = {
	set_variable = { NOR_prep_his_remove_days = 50 }
	set_variable = { NOR_prep_his_cost_convoys = 35 }
	set_variable = { NOR_prep_his_cost_pp = 50 }
	set_variable = { NOR_prep_his_cost_pp_remove = 0 } 
	set_variable = { NOR_prep_his_cost_convoys_remove = 0 }
	set_variable = { NOR_prep_his_cost_pp_trigger = -1 } 
	set_variable = { NOR_prep_his_cost_convoys_trigger = -1 }
	subtract_from_variable = { NOR_prep_his_cost_pp_remove = NOR_prep_his_cost_pp }
	subtract_from_variable = { NOR_prep_his_cost_convys_remove = NOR_prep_his_cost_convoys }
	add_to_variable = { NOR_prep_his_cost_pp_trigger = NOR_prep_his_cost_pp }
	add_to_variable = { NOR_prep_his_cost_convoys_trigger = NOR_prep_his_cost_convoys }
	set_variable = { NOR_prep_his_program_min_convoy = 99 }		
}

NOR_set_variables_alt_dem = {
	set_variable = { NOR_prep_his_remove_days = 50 }
	set_variable = { NOR_prep_alt_dem_remove_days = 35 }
	set_variable = { NOR_prep_alt_dem_convoy_cost = 50 }
	set_variable = { NOR_prep_alt_dem_convoy_cost_remove = 0 }
	set_variable = { NOR_prep_alt_dem_pp_cost = 70 }
	set_variable = { NOR_prep_alt_dem_pp_cost_remove = 0 }
	set_variable = { NOR_prep_alt_dem_convoy_cost_trigger = -1 }
	set_variable = { NOR_prep_alt_dem_pp_cost_trigger = -1 }	
	subtract_from_variable = { NOR_prep_alt_dem_convoy_cost_remove = NOR_prep_alt_dem_convoy_cost }
	subtract_from_variable = { NOR_prep_alt_dem_pp_cost_remove = NOR_prep_alt_dem_pp_cost }
	add_to_variable = { NOR_prep_alt_dem_convoy_cost_trigger = NOR_prep_alt_dem_convoy_cost }
	add_to_variable = { NOR_prep_alt_dem_pp_cost_trigger = NOR_prep_alt_dem_pp_cost }
}

NOR_set_prepare_variables_fascist = {
	# Prep vars 
	set_variable = { NOR_prep_fasc_remove_days = 45 }
	set_variable = { NOR_prep_fasc_cost_pp = 50 }
	set_variable = { NOR_prep_fasc_cost_pp_remove = 0 }
	set_variable = { NOR_prep_fasc_cost_pp_trigger = -1 }
	set_variable = { NOR_prep_fasc_cost_convoy = 25 }
	set_variable = { NOR_prep_fasc_cost_convoy_remove  = 0 }
	set_variable = { NOR_prep_fasc_cost_convoy_trigger  = -1 }
	subtract_from_variable = { NOR_prep_fasc_cost_convoy_remove = NOR_prep_fasc_cost_convoy }
	subtract_from_variable = { NOR_prep_fasc_cost_pp_remove = NOR_prep_fasc_cost_pp }
	add_to_variable = { NOR_prep_fasc_cost_convoy_trigger = NOR_prep_fasc_cost_convoy }
	add_to_variable = { NOR_prep_fasc_cost_pp_trigger = NOR_prep_fasc_cost_pp }
	# Deploy Vars
	set_variable = { NOR_deploy_fasc_cost_convoy = 40 }
	set_variable = { NOR_deploy_fasc_cost_cp = 30 }
	set_variable = { NOR_deploy_fasc_cost_cp_remove = 0 }	
	set_variable = { NOR_deploy_fasc_cost_convoy_remove = 0 }	
	set_variable = { NOR_deploy_fasc_cost_cp_trigger = -1 }	
	set_variable = { NOR_deploy_fasc_cost_convoy_trigger = -1 }	
	subtract_from_variable = { NOR_deploy_fasc_cost_cp_remove = NOR_deploy_fasc_cost_cp }
	subtract_from_variable = { NOR_deploy_fasc_cost_convoy_remove = NOR_deploy_fasc_cost_convoy }
	add_to_variable = { NOR_deploy_fasc_cost_cp_trigger = NOR_deploy_fasc_cost_cp }
	add_to_variable = { NOR_deploy_fasc_cost_convoy_trigger = NOR_deploy_fasc_cost_convoy }
}

NOR_start_state_preparation = { 
	if = {
		limit = { 
			ROOT = {
				has_country_flag = NOR_going_dem_historical
			}
		}
		NOR_historical_dem_prep_start = yes 
	}
	else_if = {
		limit = {
			ROOT = {
				has_country_flag = NOR_going_dem_allied
			}
		}
		NOR_alt_dem_prep_start = yes 
	}
	else_if = {
		limit = {
			ROOT = {
				has_country_flag = NOR_going_fascist
			}
		}
		NOR_fasc_prep_start = yes 
	}
	else_if = {
		limit = {
			ROOT = {
				OR = {
					has_country_flag = NOR_going_stalinist
					has_country_flag = NOR_going_against_stalin
				}
			}
		}
		NOR_comm_prep_start = yes
	}
	else_if = {
		limit = {
			ROOT = {
				has_country_flag = NOR_going_monarchist
			}
		}
		NOR_mon_prep_start = yes 
	}
}

NOR_historical_dem_prep_start = {
# Upgrading the existing modifier to the next level
	if = {
		limit = {   
			has_variable = NOR_state_preparation
			check_variable = { NOR_state_preparation < 3 }
		}
		if = {
			limit = {
				check_variable = { NOR_state_preparation = 1 }
				has_dynamic_modifier = { modifier = NOR_prep_his_dmod_1 }
			}
			remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_1 }
			add_dynamic_modifier = { modifier = NOR_prep_his_dmod_2 }
			custom_effect_tooltip = NOR_unlocks_emergency_productionin_state_TT
			add_to_variable = { NOR_state_preparation = 1 }	 		
		}
		else_if = {
			limit = {
				check_variable = { NOR_state_preparation = 2 }
				has_dynamic_modifier = { modifier = NOR_prep_his_dmod_2 }
			}
			remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_2 }
			add_dynamic_modifier = { modifier = NOR_prep_his_dmod_3 }
			custom_effect_tooltip = NOR_unlocks_deploy_emergency_militias_TT
			add_to_variable = { NOR_state_preparation = 1 }				
		}
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_TT
			}		
			set_country_flag = NOR_active_preparation 
		} 
	}
	else_if = { # Adding the modifier if it doesn't have it 
		limit = {
			NOT = {	has_variable = NOR_state_preparation }
		}
		set_variable = { NOR_state_preparation = 1 }
		add_dynamic_modifier = { modifier = NOR_prep_his_dmod_1 } 
		custom_effect_tooltip = NOR_unlocks_defend_state_TT
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_TT
			}
			set_country_flag = NOR_active_preparation 
		}
	}
	else = {
		#log = "Max Level"
	}	
}
NOR_alt_dem_prep_start = {
	if = {
		limit = {   
			has_variable = NOR_state_preparation
			check_variable = { NOR_state_preparation < 3 }
		}
		ROOT = {
			add_equipment_to_stockpile = { 
				type = convoy_1
				amount = NOR_prep_alt_dem_convoy_cost_remove
				producer = NOR
			}
			add_political_power = NOR_prep_alt_dem_pp_cost_remove
		}
		if = {
			limit = {
				check_variable = { NOR_state_preparation = 1 }
			}
			add_to_variable = { NOR_state_preparation = 1 }
			add_manpower = 250
			add_resource = {
				type = aluminium
				amount = 5 
			}
		}
		else_if = {
			limit = {
				check_variable = { NOR_state_preparation = 2 }
			}
			add_to_variable = { NOR_state_preparation = 1 }	
			if = {
				limit = {
					free_building_slots = {
						building = arms_factory
						size > 0 
						include_locked = yes
					}
				}		
				add_extra_state_shared_building_slots = 1
				add_building_construction = {
					type = arms_factory
					level = 1
					instant_build = yes
				}
			}			
		}
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_alt_dem_TT
			}		
			set_country_flag = NOR_active_preparation 
		} 
	}
	else_if = {
		limit = {
			NOT = {	has_variable = NOR_state_preparation }
		}
		ROOT = {
			add_equipment_to_stockpile = { 
				type = convoy_1
				amount = NOR_prep_alt_dem_convoy_cost_remove
				producer = NOR
			}
			add_political_power = NOR_prep_alt_dem_pp_cost_remove
		}
		set_variable = { NOR_state_preparation = 1 }
		set_state_flag = NOR_preparing_state
		FROM = {
			if = {
				limit = {
					free_building_slots = {
						building = arms_factory
						size > 0 
						include_locked = yes
					}
				}		
				add_extra_state_shared_building_slots = 1
				add_building_construction = {
					type = industrial_complex
					level = 1
					instant_build = yes
				}	
			}
		}
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_alt_dem_TT
			}
			set_country_flag = NOR_active_preparation 
		}
	}
	else = {
		#log = "Max Level" 
	}
}

NOR_fasc_prep_start = {
	if = {
		limit = {   
			has_variable = NOR_state_preparation
			check_variable = { NOR_state_preparation < 3 }
		}
		if = {
			limit = {
				check_variable = { NOR_state_preparation = 1 }
			}
			hidden_effect = {
				remove_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_1 }
				add_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_2 }
			}
			custom_effect_tooltip = NOR_modify_fascism_support_mod_TT
			add_to_variable = { 
				var = NOR_prep_fasc_dmod_factories
				value = -0.2
				tooltip = local_factories_tt
		 	}
			add_to_variable = { NOR_state_preparation = 1 }
			ROOT = {
				add_popularity = {
					ideology = fascism
					popularity = 0.02
				}
			}
		}
		else_if = {
			limit = {
				check_variable = { NOR_state_preparation = 2 }
			}
			hidden_effect = {
				remove_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_2 }
				add_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_3 }
			}
			add_to_variable = { 
				var = NOR_prep_fasc_dmod_local_supplies
				value = -0.15
				tooltip = local_supplies_tt
		 	}	
		 	ROOT = {
				add_popularity = {
					ideology = fascism
					popularity = 0.05
				}
		 	}
			add_to_variable = { NOR_state_preparation = 1 }				
		}
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_fasc_TT
			}		
			set_country_flag = NOR_active_preparation 
		} 
	}
	else_if = { # Adding the modifier if it doesn't have it 
		limit = {
			NOT = {	has_variable = NOR_state_preparation }
		}
		add_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_1 } 
		set_variable = { NOR_state_preparation = 1 } 
		set_variable = { NOR_prep_fasc_dmod_factories = 0 }
		set_variable = { NOR_prep_fasc_dmod_local_supplies = 0 }
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_fasc_TT
			}
			set_country_flag = NOR_active_preparation 
			add_popularity = {
				ideology = fascism
				popularity = 0.05
			}
		}
	}
	else = {
		#log = "Max Level" 
	}	
}

NOR_comm_prep_start = {
	if = {
		limit = {   
			has_variable = NOR_state_preparation
			check_variable = { NOR_state_preparation < 3 }
		}
		if = {
			limit = {
				check_variable = { NOR_state_preparation = 1 }
			}
			add_to_variable = { NOR_state_preparation = 1 }
			custom_effect_tooltip = NOR_communist_prep_level_2_TT
		}
		else_if = {
			limit = {
				check_variable = { NOR_state_preparation = 2 }
			}
			add_to_variable = { NOR_state_preparation = 1 }			
			custom_effect_tooltip = NOR_communist_prep_level_3_TT
		}
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_comm_TT
			}
			add_war_support = 0.02		
			set_country_flag = NOR_active_preparation 
		} 
	}
	else_if = { # Adding the modifier if it doesn't have it 
		limit = {
			NOT = {	has_variable = NOR_state_preparation }
		} 
		set_variable = { NOR_state_preparation = 1 } 
		set_state_flag = NOR_preparing_state
		ROOT = { 
			add_to_variable = { 
				var = NOR_country_preparedness 
				value = 1
				tooltip = NOR_adding_prep_comm_TT
			}
			add_war_support = 0.02
			set_country_flag = NOR_active_preparation 
			custom_effect_tooltip = NOR_communist_prep_level_1_TT
		}
	}
	else = {
		#log = "Max Level"	
	}	
} 

NOR_mon_prep_start = {
	if = {
		limit = {   
			has_variable = NOR_state_preparation
			check_variable = { NOR_state_preparation < 3 }
		}
		if = { # Going to Level 2 
			limit = {
				check_variable = { NOR_state_preparation = 1 }
			}
			add_to_variable = { NOR_state_preparation = 1 }
			add_extra_state_shared_building_slots = 1
			NOR_mon_basic_prep_effects = yes
		}
		else_if = { # Going to Level 3
			limit = {
				check_variable = { NOR_state_preparation = 2 }
			}
			add_to_variable = { NOR_state_preparation = 1 }
			ROOT = {
				if = {
					limit = {
						NOT = { has_template = "Kongens Menn" }
					}
					division_template = {    
						name = "Kongens Menn" 
						force_allow_recruiting = yes
						priority = 1
						is_locked = yes					
						template_counter = 76
						regiments = {
							militia = { x = 0 y = 0 }
							militia = { x = 0 y = 1 }
							militia = { x = 0 y = 2 }
							militia = { x = 1 y = 0 }
							militia = { x = 1 y = 1 }
							militia = { x = 1 y = 2 }
						}
						support = {
						}
					}			
				}
			}
			create_unit = {
				division = "name = \"Kongens Menn\" division_template = \"Kongens Menn\" start_experience_factor = 0.15 start_equipment_factor = 0.45"
				owner = NOR
				allow_spawning_on_enemy_provs = no 
				count = 2 
			}
			NOR_mon_basic_prep_effects = yes 
		}
		set_state_flag = NOR_preparing_state
	}
	else_if = { # Adding the modifier if it doesn't have it 
		limit = { # Going to Level 1 
			NOT = {	has_variable = NOR_state_preparation }
		} 
		set_variable = { NOR_state_preparation = 1 } 
		set_state_flag = NOR_preparing_state
		add_dynamic_modifier = {
			modifier = NOR_royal_defenses
			days = 365
			scope = NOR
		}
		NOR_mon_basic_prep_effects = yes 		
	}
	else = {
		#log = "Max Level" 	
	}
}

NOR_mon_basic_prep_effects = {
	ROOT = {
		add_stability = -0.03
		add_war_support = -0.03
		add_popularity = {
			ideology = neutrality
			popularity = 0.03
		}
		add_command_power = 5 
		add_to_variable = { 
			var = NOR_country_preparedness 
			value = 1
			tooltip = NOR_adding_prep_mon_TT
		}
		set_country_flag = NOR_active_preparation
	}
}

NOR_end_state_preparation = {
	clr_state_flag = NOR_preparing_state
	ROOT = { 
		if = {
			 limit = {
			 	NOT = {
				 	any_owned_state = {
				 		has_state_flag = NOR_preparing_state 
				 	}
			 	}
			 }
			clr_country_flag = NOR_active_preparation 
		}
	}

}

start_deploying_prep = {
	set_state_flag = NOR_deploying_prep_in_state 
	ROOT = { 
		set_country_flag = NOR_state_prep_deployment_in_progress 
		if = {
			limit = {
				has_country_flag = NOR_going_dem_historical
			}
			hidden_effect = {
				add_equipment_to_stockpile = { 
					type = convoy_1
					amount = NOR_prep_his_cost_convys_remove
				}
				add_political_power = NOR_prep_his_cost_pp_remove
			}
		}
		else_if = {
			limit = {
				ROOT = { 
					has_country_flag = NOR_going_fascist
				}
			}
			ROOT = { 
				hidden_effect = {
					add_command_power = NOR_deploy_fasc_cost_cp_remove 
					add_equipment_to_stockpile = { 
						type = convoy_1
						amount = NOR_prep_fasc_cost_convoy_remove
					}
				}
			}
		}
	}
}

NOR_deploy_prep_dem = {
	if = {
		limit = {
			has_dynamic_modifier = {
				modifier = NOR_prep_his_dmod_1
			}
		}
		NOR_deploy_prep_dem_1 = yes 
	}
	else_if = {
		limit = {
			has_dynamic_modifier = {
				modifier = NOR_prep_his_dmod_2
			}
		}
		NOR_deploy_prep_dem_2 = yes 
	}
	else_if = {
		limit = {
			has_dynamic_modifier = {
				modifier = NOR_prep_his_dmod_3
			}
		}
		NOR_deploy_prep_dem_3 = yes 
	}
	clr_state_flag = NOR_deploying_prep_in_state 
	ROOT = { clr_country_flag = NOR_state_prep_deployment_in_progress }	
}

NOR_deploy_prep_dem_1 = {
	remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_1 }
	clear_variable = NOR_state_preparation
	add_dynamic_modifier = {
		modifier = NOR_defend_state_dmod
		days = 365
		scope = ROOT 
	}	
}

NOR_deploy_prep_dem_2 = {
	remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_2 }
	add_dynamic_modifier = { modifier = NOR_prep_his_dmod_1 }
	set_variable = { NOR_state_preparation = 1 }
	NOR_add_mil_to_state = yes 
}

NOR_deploy_prep_dem_3 = {	
	remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_3 }
	add_dynamic_modifier = { modifier = NOR_prep_his_dmod_2}
	set_variable = { NOR_state_preparation = 2 }
	add_dynamic_modifier = { modifier = NOR_prep_resistance_dmod }
	NOR_spawn_militias_in_state = yes 
}

NOR_deploy_prep_fasc = {
	if = {
		limit = {
			NOT = {
				is_controlled_by = ROOT 
			}
		}
		ROOT = {
			set_state_controller = PREV
		}
	}
	NOR_deploy_prep_fasc_basic_effects = yes 
	clr_state_flag = NOR_deploying_prep_in_state 
	ROOT = { clr_country_flag = NOR_state_prep_deployment_in_progress }	
}

NOR_deploy_prep_fasc_basic_effects = {
	if = {
		limit = {
			check_variable = { NOR_state_preparation > 1 }
		}
		add_extra_state_shared_building_slots = 1 
		add_building_construction = {
			type = arms_factory
			level = 1
			instant_build = yes
		}
	}
	if = {
		limit = {
			check_variable = { NOR_state_preparation > 2 }
			ROOT = { has_completed_focus = NOR_the_secret_army } 
		}
		NOR_spawn_militias_in_state = yes 
	}
	if = {
		limit = {
			has_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_1 }
		}
		remove_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_1 }
	}
	else_if = {
		limit = { 
			has_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_2 }
		}
		remove_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_2 }
	}
	else_if = {
		limit = { 
			has_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_3 }
		}
		remove_dynamic_modifier = { modifier = NOR_prep_fasc_dmod_3 }
	}
	clear_variable = NOR_state_preparation
}

NOR_spawn_militias_in_state = {
	hidden_effect = {
		set_state_flag = NOR_has_spawned_militia_in_state
	}
	if = {
		limit = {
			ROOT = {
				has_country_flag = NOR_going_dem_historical
			}
		}
		if = {
			limit = {
				ROOT = {
					NOT = { has_template = "forsvarsmilitser" }
				} 
			}
			ROOT = {
				division_template = { 
					name = "forsvarsmilitser" 
					force_allow_recruiting = yes
					division_names_group = NOR_MIL_01
					priority = 1
					is_locked = yes					
					template_counter = 7  
					regiments = {
						militia = { x = 0 y = 0 }
						militia = { x = 0 y = 1 }
						militia = { x = 0 y = 2 }
					}
					support = {
					}
					override_model = NOR_irregular_entity										
				}
			}
		}	
		create_unit = {
			division = "division_template = \"forsvarsmilitser\" start_experience_factor = 0.1 start_equipment_factor = 0.1"
			owner = NOR
			allow_spawning_on_enemy_provs = no 
			count = 2 
		}
	}
	else_if = {
		limit = {
			ROOT = {
				has_country_flag = NOR_going_fascist
			}
		}
		if = {
			limit = {
				ROOT = {
					NOT = { has_template = "Hemmelige Hæren" }
				} 
			}
			ROOT = {
				division_template = {  
					name = "Hemmelige Hæren" 
					force_allow_recruiting = yes
					priority = 1
					is_locked = yes
					template_counter = 75
					regiments = {
						militia = { x = 0 y = 0 }
						militia = { x = 0 y = 1 }
						militia = { x = 0 y = 2 }
					}
					support = {
					}
					override_model = NOR_militia_alt_1_entity						
				}
			}
		}	
		create_unit = {
			division = "name = \"Hemmelige Hæren\" division_template = \"Hemmelige Hæren\" start_experience_factor = 0.1 start_equipment_factor = 0.3"
			owner = NOR
			allow_spawning_on_enemy_provs = no 
			count = 2 
		}		
	}
	else_if = {
		limit = {
			ROOT = { NOR_going_communist = yes } 
		}
		if = {
			limit = {
				check_variable = { NOR_state_preparation = 2 }
			}
			create_unit = {
				division = "name = \"Våpenfolket\" division_template = \"våpenfolket\" start_experience_factor = 0.3 start_equipment_factor = 0.5"
				owner = NOR
				allow_spawning_on_enemy_provs = no 
				count = 2 
			}
		}
		if = {
			limit = {
				check_variable = { NOR_state_preparation = 3 }
			}
			create_unit = {
				division = "name = \"Folkets Hær\" division_template = \"folkets hær\" start_experience_factor = 0.5 start_equipment_factor = 0.7"
				owner = NOR
				allow_spawning_on_enemy_provs = no 
				count = 2 
			}			
		}
	}
}


NOR_add_mil_to_state = {
	if = {
		limit = {
			free_building_slots = {
				building = arms_factory 
				size > 0
				include_locked = no 
			}
		}
		add_building_construction = {
			type = arms_factory 
			level = 1
			instant_build = yes
		}
	}
	else_if = {
		limit = {
			free_building_slots = {
				building = arms_factory 
				size > 1
				include_locked = yes 
			}
		}
		add_extra_state_shared_building_slots = 1
	}
	else = {
		#log = "You can't add anything to this state"
	}	
}

NOR_reset_prep_system = {
	clr_country_flag = NOR_active_preparation
	clr_country_flag = NOR_ongoing_countrywide_program
	every_controlled_state = {
		clear_variable = NOR_state_preparation
		clr_state_flag = NOR_preparing_state
		NOR_set_prepare_variables_historical = yes 
		if = {
			limit = {
				has_dynamic_modifier = { modifier = NOR_prep_his_dmod_1 }
			}
			remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_1}
		}
		if = {
			limit = {
				has_dynamic_modifier = { modifier = NOR_prep_his_dmod_2 }
			}
			remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_2}
		}
		if = {
			limit = {
				has_dynamic_modifier = { modifier = NOR_prep_his_dmod_3 }
			}
			remove_dynamic_modifier = { modifier = NOR_prep_his_dmod_3 }
		}
		if = {
			limit = {
				has_dynamic_modifier = { modifier = NOR_prep_resistance_dmod }
			}
			remove_dynamic_modifier = { modifier =  NOR_prep_resistance_dmod }
		}
	}
	NOR_set_prepare_variables_historical = yes
	set_country_flag = NOR_preps_system_has_been_reset 
}

###################################################################################################
###################################################################################################
###################################################################################################

			 ######  #### ##     ## #### ##          ##      ##    ###    ########  
			##    ##  ##  ##     ##  ##  ##          ##  ##  ##   ## ##   ##     ## 
			##        ##  ##     ##  ##  ##          ##  ##  ##  ##   ##  ##     ## 
			##        ##  ##     ##  ##  ##          ##  ##  ## ##     ## ########  
			##        ##   ##   ##   ##  ##          ##  ##  ## ######### ##   ##   
			##    ##  ##    ## ##    ##  ##          ##  ##  ## ##     ## ##    ##  
			 ######  ####    ###    #### ########     ###  ###  ##     ## ##     ## 
			
###################################################################################################
###################################################################################################
###################################################################################################


NOR_start_fascist_civil_war = {
	if = {
		limit = {
			NOT = { has_country_flag = NOR_sorted_characters date > 1940.1.1 }
		}
		NOR_character_flag_setup_for_cw = yes 
	}
	if = { 
		limit = { #### This is for the Player led Civil War, Alt-History Fascist Path. 
			has_completed_focus = NOR_lurk_in_the_shadows
			date > 1965.1.1
		}
		NOR_fcw_effect_fascist_player = yes 
		if = {
			limit = { #### This is for when a fascist country (Usually Germany) accepted to attack Nrway and support Quisling in his civil war 
				 has_country_flag = NOR_fascist_bully_accepted_invasion_invitation@NOR_cw_fascist_attacker 
				 date > 1965.1.1
			}
			NOR_fcw_big_fascist_support = yes 			
		}
	}
	else_if = {# Opportunistically Fascist (Started as Democratic but continued as Historical Fascist)
		limit = {
			has_completed_focus = NOR_continue_nygaardsvold_government
			has_country_flag = NOR_switched_to_fasc_hist
			date > 1965.1.1
		}
		NOR_fcw_effect_fascist_player = yes 
		NOR_fcw_big_fascist_support = yes
		complete_national_focus = NOR_fascist_invasion_of_norway
		NOR_apply_resistance_to_fascists = yes 
	}
	else_if = { # This is for the player who decided to stay on the democratic path
		limit = {
			has_completed_focus = NOR_continue_nygaardsvold_government
			date > 1965.1.1
			NOT = { has_country_flag = NOR_switched_to_fasc_hist } 	
		}
		NOR_fcw_effect_democratic_player = yes 
		NOR_fcw_big_fascist_support = yes
		complete_national_focus = NOR_fascist_invasion_of_norway
		NOR_apply_resistance_to_fascists = yes 	
	}
	if = {
		limit = {
			has_completed_focus = NOR_empower_hirden 
			date > 1965.1.1
		}
		NOR_spawn_hirden = yes 
	}
	if = {
		limit = {
			NOT = {
				has_global_flag = NOR_quislings_coup_happened
				date > 1940.1.1
			}
		}
		set_global_flag =  NOR_quislings_coup_happened
	}
}

NOR_fcw_effect_fascist_player = {
	start_civil_war = {
		ruling_party = fascism 
		ideology = democratic
		size = party_popularity@democratic 
		states = all 
		states_filter = {
			 is_controlled_by = ROOT 
			 NOT = {
			 	state = 110
			 } 
		}
		keep_all_characters = yes  

		ROOT = {
			hidden_effect = { add_stability = 0.30 } 
		}
	}
	random_other_country = {
		limit = {
			original_tag = NOR 
			NOT = { has_government = fascism }
		}
		set_variable = { NOR.NOR_cw_democratic_norway = THIS }
	}
	every_character = {
		limit = {
			has_character_flag = NOR_anti_fascist
		}
		set_nationality = var:NOR.NOR_cw_democratic_norway 
	}
	var:NOR.NOR_cw_democratic_norway = {
		NOR_johan_nygaardsvold = {
			promote_character = yes
		}
	}
	ROOT = {
		add_popularity = {
			ideology = fascism
			popularity = 0.60
		}
		add_manpower = 10000
		set_cosmetic_tag = NOR_fascism
	}

	110 = {
		if = {
			limit = {
				check_variable = { NOR_state_preparation > 0 }
			}
			NOR_deploy_prep_fasc_basic_effects = yes 
		}
		transfer_state_to = ROOT
	}
	set_global_flag = NOR_norwegian_fascist_cw_started	
} 

NOR_fcw_effect_democratic_player = {
	start_civil_war = {
		ruling_party = democratic 
		ideology = fascism
		size = party_popularity@fascism 
		states = { 110 }
		keep_all_characters = yes 
		PREV.PREV = {
			hidden_effect = { add_stability = 0.30 } 
		}
	}
	110 = {
		if = {
			limit = {
				check_variable = { NOR_state_preparation > 0 }
			}
			NOR_deploy_prep_fasc_basic_effects = yes 
		}
	}
	set_global_flag = NOR_norwegian_fascist_cw_started	
	random_other_country = {
		limit = {
			original_tag = NOR 
			has_government = fascism
		}
		set_variable = { NOR.NOR_cw_fascist_norway = THIS }
	}
	every_character = {
		limit = {
			has_character_flag = NOR_anti_democratic
		}
		set_nationality = NOR.NOR_cw_fascist_norway 
	}
	var:NOR.NOR_cw_fascist_norway = {
		NOR_vidkun_quisling = {
			promote_character = yes  
		}
	}
} 

NOR_fcw_big_fascist_support = {
	# Saving both Norways for later
	random_country = {
		limit = {
			original_tag = NOR 
			has_government = democratic
			has_civil_war = yes 
		}
		NOR = {
			set_variable = { NOR_cw_democratic_norway = PREV } 
		}
	}
	random_country = {
		limit = {
			original_tag = NOR 
			has_government = fascism
			has_civil_war = yes
		}
		NOR = {
			set_variable = { NOR_cw_fascist_norway = PREV }
		}
	}
	if = {
		limit = { # This is just in case there's some weird shenanigans 
			var:NOR.NOR_cw_fascist_attacker = {
				OR = {
					has_war_with = NOR.NOR_cw_fascist_norway
					has_war_with = NOR.NOR_cw_democratic_norway 
				}
			}
		}
		var:NOR.NOR_cw_fascist_norway = { 
			var:NOR.NOR_cw_fascist_attacker = {
				if = {
					limit = {
						has_wargoal_against = {	target = PREV }
					}
					remove_wargoal = { 
						type = all
						target = PREV
					}
				}
			}
			var:NOR.NOR_cw_democratic_norway = {
				var:NOR.NOR_cw_fascist_attacker = {
					add_to_war = {
						targeted_alliance = PREV.PREV 
						enemy = PREV 
					}
				}
				var:NOR.NOR_cw_fascist_norway = {
					create_wargoal = {
						target = PREV
						type = topple_government
					}
				} 
			}
			add_ideas = { NOR_contested_leadership_ns }
		}				
	}
	var:NOR.NOR_cw_fascist_norway = {
		set_cosmetic_tag = NOR_fascism
		NOR_spawn_hirden = yes 

	}	
	var:NOR.NOR_cw_fascist_attacker = {
		every_controlled_state = {
			limit = {
				is_core_of = NOR 
			}
			transfer_state_to = var:NOR.NOR_cw_fascist_norway
		}
	}
}

NOR_apply_resistance_to_fascists = {
	if = {
		limit = {
			NOR_fascist_norway_exists = yes 
		}
		every_state = {
			limit = {
				is_core_of = NOR
			}
			force_enable_resistance = FNO 
			start_resistance = FNO
		}	
	}
}

NOR_spawn_hirden = {
	if = {
		limit = {
			NOT = { has_template = "Hirden Milits" }
		}
		division_template = {
			name = "Hirden Milits"
			is_locked = yes
			template_counter = 75 
			regiments = {
				militia = { x = 0 y = 0 }
				militia = { x = 0 y = 1 }
				militia = { x = 1 y = 0 }
				militia = { x = 1 y = 1 }	
				militia = { x = 2 y = 0 }
				militia = { x = 2 y = 1 }
			}
			support = {
			}
			override_model = NOR_militia_alt_1_entity			
		} 
	}
	110 = {
		create_unit = { 
			division = "name = \"1. Hirden Milits\" division_template = \"Hirden Milits\" start_experience_factor = 0.6" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"2. Hirden Milits\" division_template = \"Hirden Milits\" start_experience_factor = 0.6" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"3. Hirden Milits\" division_template = \"Hirden Milits\" start_experience_factor = 0.6" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"4. Hirden Milits\" division_template = \"Hirden Milits\" start_experience_factor = 0.6" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"5. Hirden Milits\" division_template = \"Hirden Milits\" start_experience_factor = 0.6" 
			owner = ROOT
		}
	}
}


NOR_start_communist_civil_war = {
	if = {
		limit = {
			NOT = {
				has_country_flag = NOR_sorted_characters
			}		
		}
		NOR_character_flag_setup_for_cw = yes 
	}
	start_civil_war = {
		ideology = democratic
		ruling_party = communism 
		size = party_popularity@democratic 
		states = all 
		states_filter = {
			 OR = {
				 NOT = { has_variable = NOR_state_preparation }
				 state = 110 
			 }
		}
		keep_all_characters = yes 
	}
	random_other_country = {
		limit = {
			original_tag = NOR
			NOT = {
				has_government = communism 
			}
		}
		set_variable = { NOR.NOR_bourgeois_norway = THIS }
	}
	NOR = {
		if = {
			limit = {
				has_completed_focus = NOR_prosecute_the_nkp
			}
			every_character = {
				limit = {
					OR = {
						has_character_flag = NOR_anti_trostky
						has_character_flag = NOR_anti_communist
					}
				}
				set_nationality = var:NOR.NOR_bourgeois_norway 		
			}
		}
		else = {
			every_character = {
				limit = {
					OR = {
						has_character_flag = NOR_anti_stalin
						has_character_flag = NOR_anti_communist
					}
				}
				set_nationality = var:NOR.NOR_bourgeois_norway 		
			}
		}
	}
	var:NOR.NOR_bourgeois_norway = {
		uncomplete_national_focus = {
			focus = NOR_a_resurgent_labor_movement
			uncomplete_children = yes 
		}
		complete_national_focus = NOR_vote_of_no_confidence
	}
	NOR_create_communist_templates = yes
	add_popularity = {
		ideology = communism 
		popularity = 0.25
	}
	set_cosmetic_tag = NOR_cw_communism
	every_controlled_state = {
		limit = {
			check_variable = { NOR_state_preparation > 1 }
		}
		NOR_spawn_militias_in_state = yes 
		NOR_deploy_prep_comm_damage = yes 
	}
}

NOR_create_communist_templates = {
	if = {
		limit = {
			any_controlled_state = {
				check_variable = { NOR_state_preparation = 2 }
			}
		}
		division_template = {    
			name = "våpenfolket"
			force_allow_recruiting = yes
			is_locked = yes
			priority = 1
			template_counter = 68 
			regiments = {
				irregular_infantry = { x = 0 y = 0 }
				irregular_infantry = { x = 0 y = 1 }
				irregular_infantry = { x = 0 y = 2 }
				irregular_infantry = { x = 1 y = 0 }
				irregular_infantry = { x = 1 y = 1 }
			}
			support = {
			}
			override_model = NOR_irregular_entity			
		}		
	}
	if = {
		limit = {
			any_controlled_state = {
				check_variable = { NOR_state_preparation = 3 }
			}
		}
		division_template = {    
			name = "folkets hær" 
			force_allow_recruiting = yes
			priority = 1
			is_locked = yes
			template_counter = 69  
			regiments = {
				militia = { x = 0 y = 0 }
				militia = { x = 0 y = 1 }
				militia = { x = 0 y = 2 }
				militia = { x = 1 y = 0 }
				militia = { x = 1 y = 1 }
			}
			support = {
			}
			override_model = NOR_irregular_entity
		}
	}
}

NOR_deploy_prep_comm_damage = {  
	if = {
		limit = {
			check_variable = { NOR_state_preparation = 1 }
		} 
		damage_building = {
			type = arms_factory 
			damage = 1.5 
		}
		damage_building = {
			type = industrial_complex 
			damage = 1.5 
		}
		damage_building = {
			type = infrastructure
			damage = 1.5
		}
	}
	else_if = {
		limit = {
			check_variable = { NOR_state_preparation = 2 }
		} 
		damage_building = {
			type = arms_factory 
			damage = 1 
		}
		damage_building = {
			type = industrial_complex 
			damage = 1 
		}
		damage_building = {
			type = infrastructure
			damage = 1
		}
	}
	else_if = {
		limit = {
			check_variable = { NOR_state_preparation = 3 }
		} 
		damage_building = {
			type = arms_factory 
			damage = 0.5 
		}
		damage_building = {
			type = industrial_complex 
			damage = 0.5 
		}
		damage_building = {
			type = infrastructure
			damage = 0.5
		}
	}
}

NOR_character_flag_setup_for_cw = {
	### Country Leaders ###

	NOR_johan_nygaardsvold = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_communist
	}

	NOR_martin_tranmael = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_communist
	}

	NOR_johan_h_andresen = {
		set_character_flag = NOR_anti_communist
	}

	NOR_adam_egede_nissen = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_trostky
	}

	NOR_olav_scheflo = {
		set_character_flag = NOR_anti_stalin
		set_character_flag = NOR_anti_fascist
	}
	
	NOR_peder_anker_wedel_jarlsberg = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_communist
	}
	
	NOR_queen_mathilde_i = {
		set_character_flag = NOR_anti_fascist
	}
	
	NOR_king_haakon_vii = {
		set_character_flag = NOR_anti_fascist
	}
	
	NOR_prince_olav = {
		set_character_flag = NOR_anti_fascist
	}
	
	NOR_vidkun_quisling = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_democratic
	}
	
	NOR_josef_terboven = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_democratic
	}

	NOR_jonas_lie = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_democratic	
	}

	### Political Advisors ###

	NOR_axel_aubert = {
		set_character_flag = NOR_anti_communist
	}

	NOR_johan_ludwig_mowinckel ={
		set_character_flag = NOR_anti_communist
	}

	NOR_peder_furubotn = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_trostky	
	}

	NOR_jeanette_olsen = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_stalin
	}

	NOR_lev_trotsky ={
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_stalin
	}

	NOR_sverre_riisnaes ={
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_democratic
	}

	NOR_birger_meidell ={
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_democratic
	}

	NOR_ragnar_skancke ={
		set_character_flag = NOR_anti_communist
	}

	NOR_joakim_lehmkuhl ={
		set_character_flag = NOR_anti_communist
	}

	NOR_hans_ystgaard ={
		set_character_flag = NOR_anti_fascist
	}
	NOR_johan_ludwig_mowinckel = {
		set_character_flag = NOR_anti_fascist
		set_character_flag = NOR_anti_communist
	}

	### Unit Leaders ###

	NOR_carl_gustav_fleischer = {
		set_character_flag = NOR_anti_fascist	
		set_character_flag = NOR_anti_stalin	
	}

	NOR_wilhelm_von_tangen_hansteen = {
		set_character_flag = NOR_anti_trostky
		set_character_flag = NOR_anti_fascist				
	}
	# There's no proof either Wilhelm or Carl Gustav would join a communist Norway, but they're sorely lacking on leaders and them not joining the same side is an interesting wrinkle
	NOR_jacob_ager_laurantzon = {
		set_character_flag = NOR_anti_communist
	}
	
	NOR_carsten_tank_nielsen = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist		
	}
	

	NOR_skule_storheil = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist		
	}
	
	NOR_birger_ljungberg = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist
	}

	### Military Advisors ###
	
	NOR_tryggve_gran = {
		set_character_flag = NOR_anti_communist
	}

	NOR_birger_eriksen = {
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_konrad_sundlo = {
		set_character_flag = NOR_anti_communist
	}
		
	NOR_otto_ruge = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_rasmus_hatledal = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_bjorn_christophersen = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_kristian_laake = {
		set_character_flag = NOR_anti_communist
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_hjalmar_riiser_larsen = {
		set_character_flag = NOR_anti_communist
	}
		
	NOR_adolf_indrebo = {
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_halvdan_koht = {
		set_character_flag = NOR_anti_fascist	
	}
		
	NOR_trygve_halvdan_lie = {
		set_character_flag = NOR_anti_fascist	
	}
	set_country_flag = NOR_sorted_characters
}



###################################################################################################
###################################################################################################
###################################################################################################

	  ########  #######   ######  ##     ##  ######     ######## ########  ######## ######## 
	  ##       ##     ## ##    ## ##     ## ##    ##       ##    ##     ## ##       ##       
	  ##       ##     ## ##       ##     ## ##             ##    ##     ## ##       ##       
	  ######   ##     ## ##       ##     ##  ######        ##    ########  ######   ######   
	  ##       ##     ## ##       ##     ##       ##       ##    ##   ##   ##       ##       
	  ##       ##     ## ##    ## ##     ## ##    ##       ##    ##    ##  ##       ##       
	  ##        #######   ######   #######   ######        ##    ##     ## ######## ######## 

###################################################################################################
###################################################################################################
###################################################################################################

NOR_remove_broken_gun = {
	if = {
		limit = {
			has_idea = NOR_broken_gun_ns
		}
		remove_ideas = { NOR_broken_gun_ns }
	}
	else_if = {
		limit = {
			has_idea = NOR_broken_gun_ns_2
		}
		remove_ideas = { NOR_broken_gun_ns_2 }
	}
	else_if = {
		limit = {
			has_idea = NOR_broken_gun_ns_3
		}
		remove_ideas = { NOR_broken_gun_ns_3 }
	}
}

NOR_set_quisling_1 = {
	NOR_vidkun_quisling = {
		if = {
			limit = {
				has_trait = NOR_fascist_dilettante
			}
			remove_country_leader_trait = NOR_fascist_dilettante 

		}
		if = {
			limit = {
				has_trait = NOR_fascist_landssviker
			}
			remove_country_leader_trait = NOR_fascist_landssviker
		}
		add_country_leader_trait = NOR_fascist_lackey 
		set_portraits = {
			army = { large ="GFX_portrait_NOR_vidkun_quisling_1"}
			civilian = { large ="GFX_portrait_NOR_vidkun_quisling_1" }
		}	
	}
}

NOR_set_quisling_2 = {
	NOR_vidkun_quisling = {
		if = {
			limit = {
				has_trait = NOR_fascist_lackey
			}
			remove_country_leader_trait = NOR_fascist_lackey 

		}
		if = {
			limit = {
				has_trait = NOR_fascist_landssviker
			}
			remove_country_leader_trait = NOR_fascist_landssviker
		}
		add_country_leader_trait = NOR_fascist_dilettante 
		set_portraits = {
			army = { large ="GFX_portrait_NOR_vidkun_quisling_2"}
			civilian = { large ="GFX_portrait_NOR_vidkun_quisling_2" }
		}	
	}
}

NOR_set_quisling_3 = {
	NOR_vidkun_quisling = {
		if = {
			limit = {
				has_trait = NOR_fascist_lackey
			}
			remove_country_leader_trait = NOR_fascist_lackey 
		}
		else_if = {
			limit = {
				has_trait = NOR_fascist_dilettante
			}
		}
			remove_country_leader_trait = NOR_fascist_dilettante
			add_country_leader_trait = NOR_fascist_landssviker 
			set_portraits = {
			army = { large ="GFX_portrait_NOR_vidkun_quisling_3"}
			civilian = { large ="GFX_portrait_NOR_vidkun_quisling_3" }
		}	
	}
}

NOR_set_kingdom_of_norway_variables = {
	set_variable = { NOR_kingdom_of_norway_dmod_consumer_goods_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_research_speed = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_special_forces_cap_flat = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_special_forces_training_time_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_recruitable_population_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_army_defence_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_army_morale_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_army_org_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_production_speed_coastal_bunker_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_production_speed_naval_base_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_production_speed_dockyard_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_justify_war_goal_time = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_naval_mines_damage_factor = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_spotting_chance = 0 }
	set_variable = { NOR_kingdom_of_norway_dmod_navy_max_range_factor = 0 }
}
NOR_rikstanken_creation_effect = { # Moving it here so it's cleaner
	hidden_effect = { 
		if = {
			limit = { has_dlc = "No Step Back" }
			if = {
				limit = {
					NOT = { has_tech = basic_light_tank_chassis }
				}
				set_technology = {
					gwtank_chassis = 1 
					popup = yes 
				}
				set_technology = {
					basic_light_tank_chassis = 1
					popup = no
				}
				set_country_flag = NOR_added_basic_tank_tech
			}
			set_technology = {
				NOR_rikstanken_tech = 1
				popup = no
			}
		}
		else = {
			if = {
				limit = {
					NOT = { has_tech = basic_light_tank }
				}
				set_technology = {
					gwtank = 1 
					popup = yes 
				}
				set_technology = {
					basic_light_tank = 1 
					popup = no
				}
				set_country_flag = NOR_added_basic_tank_tech
			}
		}
	}
	create_equipment_variant = { # Creating a NSB variant doesn't break if you don't have NSB so going with this. 
		name = "Landsverk 'Rikstanken' L-120"  
		type = light_tank_chassis_1
		parent_version = 0
		allow_without_tech = yes
		icon = GFX_NOR_basic_light_tank_medium
		modules = {
			main_armament_slot = tank_heavy_machine_gun
			turret_type_slot = NOR_rikstanken_turret
			suspension_type_slot = tank_bogie_suspension
			armor_type_slot = NOR_tank_rikstanken_armor
			engine_type_slot = tank_gasoline_engine
		}
		upgrades = {
		}
		obsolete = no 
	}
	hidden_effect = {
		if = {
			limit = {
				has_dlc = "No Step Back"
			}
			add_equipment_to_stockpile = { 
				type = light_tank_chassis_1
				amount = 1 
				producer = NOR 
				variant_name = "Landsverk 'Rikstanken' L-120"
			}		
		}
		else = {
			add_equipment_to_stockpile = {
				type = light_tank_equipment_1
				amount = 1 
				producer = NOR 
				#variant_name = "Landsverk 'Rikstanken' L-120" # To the future content designer that looks at this: Make it so you can get an actual Rikstanken if you don't have NSB 
			}
		}
	}
	effect_tooltip = {
		if = {
			limit = {
				has_dlc = "No Step Back"
			}
			add_equipment_to_stockpile = { 
				type = light_tank_chassis_1
				amount = 1 
				producer = var:NOR.NOR_nordic_tank_seller 
				variant_name = "Landsverk 'Rikstanken' L-120"
			}		
		}
		else = {
			add_equipment_to_stockpile = {
				type = light_tank_equipment_1
				amount = 1 
				producer = var:NOR.NOR_nordic_tank_seller 
			}
		}		
	}
	if = {
		limit = {
			has_country_flag = NOR_added_basic_tank_tech
		}
		hidden_effect = {
			if = {
				limit = {
					has_dlc = "No Step Back"
				}
				set_technology = {
					basic_light_tank_chassis = 0
					popup = no
				}
			}
			else = {
				set_technology = {
					basic_light_tank = 0 
					popup = no 
				}
			}
		} 
		clr_country_flag = NOR_added_basic_tank_tech
	}		
	add_tech_bonus = {
		name = AAT_rikstanken_program_tech_bonus
		bonus = 0.75 
		uses = 2
		category = armor 
	}
}

###################################################################################################
###################################################################################################
###################################################################################################

							 #######  ######## ##     ## ######## ########  
							##     ##    ##    ##     ## ##       ##     ## 
							##     ##    ##    ##     ## ##       ##     ## 
							##     ##    ##    ######### ######   ########  
							##     ##    ##    ##     ## ##       ##   ##   
							##     ##    ##    ##     ## ##       ##    ##  
							 #######     ##    ##     ## ######## ##     ## 

###################################################################################################
###################################################################################################
###################################################################################################

NOR_set_mobile_government_variables = {
	set_variable = { NOR_mobile_gov_days_remove = 7 } 
	110 = { NOR_set_as_government_hq = yes } 
}

NOR_set_as_government_hq = {
	set_state_flag = NOR_hq_state_flag
	ROOT = {
		set_variable = { NOR_mobile_government_hq = PREV }
	}
}

NOR_reduce_hard_thirties_ns = {
	if = {
		limit = {
			has_idea = NOR_the_hard_thirties_ns
		}
		swap_ideas = {
			remove_idea = NOR_the_hard_thirties_ns
			add_idea = NOR_the_hard_thirties_ns_2
		}
	}
	else_if = {
		limit = {
			has_idea = NOR_the_hard_thirties_ns_2
		}
		swap_ideas = {
			remove_idea = NOR_the_hard_thirties_ns_2
			add_idea = NOR_the_hard_thirties_ns_3
		}
	}
	else_if = {
		limit = {
			has_idea = NOR_the_hard_thirties_ns_3
		}
		remove_ideas = { NOR_the_hard_thirties_ns_3 }
	}
}

NOR_make_militias_into_regulars = {
	hidden_effect = {
		add_equipment_to_stockpile = { 
			type = convoy_1
			amount = -50
			producer = NOR
		}
		army_experience = -80 
		division_template = { 
			name = "Integrated militias" 
			force_allow_recruiting = yes
			division_names_group = NOR_INF_01
			priority = 1
			is_locked = no					
			template_counter = 6  
			regiments = {
				infantry = { x = 0 y = 0 }
				infantry = { x = 0 y = 1 }
				infantry = { x = 0 y = 2 }
			}
			support = {
			}
		}
	}
	custom_effect_tooltip = NOR_convert_militias_to_regulars_TT
	every_country_division = {
		limit = { division_has_majority_template = militia }
		change_division_template = {
			division_template = "Integrated militias" 
		}
	}
	delete_unit_template_and_units = {
		division_template = "forsvarsmilitser"
	}
}

NOR_spawn_resistance = {
	ROOT = {
		if = {
			limit = {
				NOT = {
					has_template = "motstandsbevegelsen"
				}
			}
			division_template = {  
				name = "motstandsbevegelsen" 
				force_allow_recruiting = yes
				priority = 1
				is_locked = no
				template_counter = 68
				regiments = {
					militia = { x = 0 y = 0 }
					militia = { x = 0 y = 1 }
					militia = { x = 0 y = 2 } 
					militia = { x = 0 y = 3 }
					militia = { x = 0 y = 4 }
					militia = { x = 1 y = 0 }
					militia = { x = 1 y = 1 }
				}
				support = {
					engineer = { x = 0 y = 0 }
				}
				override_model = NOR_irregular_entity				
			}
		}
	}
	effect_tooltip = {
		create_unit = {
			division = "name = \"1. Motstandsbevegelsen\" division_template = \"motstandsbevegelsen\" start_experience_factor = 0.75" 
			owner = NOR 
			count = 5
		}
	}
	hidden_effect = {
		create_unit = { 
			division = "name = \"1. Motstandsbevegelsen\" division_template = \"motstandsbevegelsen\" start_experience_factor = 0.75" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"2. Motstandsbevegelsen\" division_template = \"motstandsbevegelsen\" start_experience_factor = 0.75" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"3. Motstandsbevegelsen\" division_template = \"motstandsbevegelsen\" start_experience_factor = 0.75" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"4. Motstandsbevegelsen\" division_template = \"motstandsbevegelsen\" start_experience_factor = 0.75" 
			owner = ROOT
		}
		create_unit = { 
			division = "name = \"5. Motstandsbevegelsen\" division_template = \"motstandsbevegelsen\" start_experience_factor = 0.75" 
			owner = ROOT
		}	
	}
}

NOR_remove_100_convoys = {
	hidden_effect = {
		add_equipment_to_stockpile = { 
			type = convoy_1
			amount = -100 
			producer = NOR
		}
	}
}

NOR_remove_75_convoys = {
	hidden_effect = {
		add_equipment_to_stockpile = { 
			type = convoy_1
			amount = -75 
			producer = NOR
		}
	}
}

NOR_remove_50_convoys = {
	hidden_effect = {
		add_equipment_to_stockpile = { 
			type = convoy_1
			amount = -50 
			producer = NOR
		}
	}
}

NOR_remove_25_convoys = {
	hidden_effect = {
		add_equipment_to_stockpile = { 
			type = convoy_1
			amount = -25 
			producer = NOR
		}
	}
}

NOR_add_50_convoys = {
	add_equipment_to_stockpile = { 
		type = convoy_1
		amount = 50 
		producer = NOR
	}
}

NOR_add_25_convoys = {
	add_equipment_to_stockpile = { 
		type = convoy_1
		amount = 25 
		producer = NOR
	}
}

NOR_add_10_convoys = {
	add_equipment_to_stockpile = { 
		type = convoy_1
		amount = 10 
		producer = NOR
	}
}
