operation_warsaw_uprising = { ### 8 2/40
	icon = GFX_operations_boost_resistance
	map_icon = GFX_operations_boost_resistance_map
	name = operation_warsaw_uprising
	desc = operation_warsaw_uprising_desc
	priority = 8
	
	cost_multiplier = 0.25
	
	days = 75
	network_strength = 50
	operatives = 2

	visible = {
		network_national_coverage = {
			target = FROM
			value > 0
		}
		
		OR = {
			has_completed_focus = POL_niech_zyje_opor
			has_completed_focus = POL_niech_zyje_opor_no_mtg #No MTG version (required duplicate focus)
		}

		has_operation_token = {
			tag = FROM
			token = token_resistance_contacts
		}
		
		FROM = {
			core_resistance = {
				occupied_country_tag = POL
				value > 50
			}
		}
		
		NOT = { has_global_flag = warsaw_liberated_self_flag }
	}

	selection_target = {
		targets = { FROM }
	}

	selection_target_state = {
		has_resistance = yes
		is_core_of = POL
	}

	equipment = {

	}

	required_tokens = {
		token_resistance_contacts
	}
	risk_chance = 0.5
	experience = 1.5
	outcome_extra_chance = 0.25
	outcome_modifiers = { boost_resistance_factor }
	outcome_execute = {
		custom_effect_tooltip = warsaw_uprising_will_happen_tt
		FROM = {
			set_temp_variable = { occupier_country = THIS }
			set_temp_variable = { occupied_country = POL }
			set_temp_variable = { new_occupied_country = POL }
			
			#warsaw achievement
			set_global_flag = warsaw_liberated_self_flag
			
			
			set_temp_variable = { civil_war_country_picked = 0 }
			
			
			
			# create resistance template for armies to spawn
			var:new_occupied_country = {
				if = {
					limit = { NOT = { has_country_flag = created_civil_war_template } }
					set_country_flag = created_civil_war_template
						
					division_template = {
						name = "Resistance"
						is_locked = yes
						regiments = {
							infantry = { x = 0 y = 0 }
							infantry = { x = 0 y = 1 }
				
							infantry = { x = 1 y = 0 }
							infantry = { x = 1 y = 1 }
							
							infantry = { x = 2 y = 0 }
							infantry = { x = 2 y = 1 }
						}
					}
				}
			}
			
			
			clear_temp_array = checked_neighbours
			every_controlled_state = {
				limit = { 
					OR = {
						state = 10
						state = 72
						state = 162
						state = 784
						state = 807
						state = 85
						state = 86
						state = 87
						state = 88
						state = 89
						state = 90
						state = 91
						state = 1400
						state = 92
						state = 93
						state = 94
						state = 95
						state = 96
						state = 97
						state = 98
					}
					impassable = no
				}
				
				# move our armies to back home
				teleport_armies = {
					limit = { 
						OR = {
							is_ally_with = occupier_country
							has_military_access_to = occupier_country
						}
					}
					to_state_array = owned_controlled_states
				}
				
				# transfer state
				if = {
					limit = { has_resistance = yes }
					set_resistance = 0
				}
				var:new_occupied_country = {
					transfer_state = PREV
				}
				
				if = {
					limit = { 
						var:occupier_country = {
							check_variable = { resistance_already_inited@var:occupied_country = 0 } 
						}
					}
					
					# create resistance units, number is relative to size of industry
					set_temp_variable = { num_units_to_create = building_level@arms_factory }
					add_to_temp_variable = { num_units_to_create = building_level@industrial_complex } 
					divide_temp_variable = { num_units_to_create = 3 }
					add_to_temp_variable = { num_units_to_create = 2 }
					round_temp_variable = num_units_to_create
					clamp_temp_variable = { var = num_units_to_create min = 2 max = 6 }
					for_loop_effect = {
						end = num_units_to_create
						
						create_unit = {
							division = "division_template = \"Resistance\" start_experience_factor = 1 start_equipment_factor = 1"
							owner = new_occupied_country
						}
					}
				}
				
				# also check neighbouring core states of the occupier that are not captured yet
				# move our armies so they are not surrounded/create pockets
				every_neighbor_state = {
					limit = {
						is_owned_and_controlled_by = occupied_country
						is_core_of = occupied_country
						not = { is_in_array = { checked_neighbours = this } }
					}
					add_to_temp_array = { checked_neighbours = this }
					
					teleport_armies = {
						limit = { 
							OR = {
								is_ally_with = occupier_country
								has_military_access_to = occupier_country
							}
						}
						to_state_array = owned_controlled_states
					}
					
					set_state_province_controller = {
						controller = occupied_country
						limit = {
							is_ally_with = occupier_country
						}
					}
				}
			}
		
			# create war if necesarry
			if = {
				limit = { NOT = { has_war_with = new_occupied_country } }
				declare_war_on = { target = new_occupied_country type = annex_everything }
			}
			
			var:occupier_country = {
				set_variable = { resistance_already_inited@var:occupied_country = 1 } 
			}
		}
	}
	outcome_extra_execute = { # SCOPE_OPERATION
	}

	outcome_potential = {
		custom_effect_tooltip = warsaw_uprising_operation_tt
	}

	
	target_weight = {
		base = 100
		
		modifier = {
			add = boost_resistance_chance
		}
		
		modifier = {
			set_temp_variable = { t = distance_to@ROOT.capital }
			divide_temp_variable = { t = 600 }
			clamp_temp_variable = { var = t min = 0 max = 1 }
			multiply_temp_variable = { t = -40 }
			
			add = t
		}
	}
	
	phases = { #infiltration
		infiltration_border = { base = 50 }
		infiltration_submarine = { base = 25 }
		infiltration_paradrop = { 
			base = 25 
		}
	}
	phases = { #resistance support
		resistance_support_arms_depots = { base = 25 }
		resistance_support_distribute_weapons = { base = 25 }
		resistance_support_organize_training = { base = 25 }
		resistance_support_coordinate_groups = { base = 25 }
	}
	phases = { #exfiltration
		exfiltration_air_pickup = { 
			base = 15 
		}
		exfiltration_border = { base = 30 }
		exfiltration_go_to_ground = { base = 30 }
		exfiltration_submarine_pickup = { base = 25 }
	}
}