
#name is also used for loc
#modifier_id = {
#	#description to use in tooltip
#	tooltip = "bla_bla"
#	
#	#gfx entry & frame for law entry icon. both frame and gfx name can be ommited
#	#gfx entry can be omitted, in that case it will default to GFX_occupation_modifier_strip
#	icon = "GFX_bla_bla:1"
#	#small icon will be used for progress bars (GFX_occupation_modifier_small_strip is default gfx)
#	icon_small = "GFX_bla_bla_small:1"
#	
#	type = state_resistance_modifier
#	#type = core_resistance_modifier
#	#type = state_compliance_modifier
#	#type = core_compliancemodifier
#	
#	#for state modifiers, the scope will be the state, FROM/root will be the occuppier and from from will be the occuppied country
#	#for core modifiers, the scope/root will be the occuppier and from will be the occuppied country
#	
#	#percentage threshold to enable
#	threshold = 35
#	
#	#margin to disable the modifier back. it will be disabled if current value < threshold - margin.
#	margin = 2
#	
#	#if visible is false, the modifier will not show up anywhere
#	visible = {
#		
#	}
#	
#	#if enabled is false, the modifier won't be enabled even if it passes threshold (and will be disabled if it was enabled before)
#	enabled = {
#	
#	}
#	
#	#the effect will be called when modifier is enabled
#	on_enable = {
#	
#	}
#	
#	#the effect will be called when modifier is disabled
#	on_disable = {
#	
#	}
#	
#	#will be added to state if modifier is enabled
#	state_modifier = {
#	
#	}
#}


resistance_25 = {
	type = state_resistance_modifier
	icon = "GFX_occupation_resistance_modifier_strip:1"
	small_icon = "GFX_occupation_resistance_modifier_small_strip:1"
	threshold = 25
	margin = 2
	state_modifier = {
		resistance_garrison_penetration_chance = 0.5
	}
}
resistance_50 = {
	type = state_resistance_modifier
	icon = "GFX_occupation_resistance_modifier_strip:2"
	small_icon = "GFX_occupation_resistance_modifier_small_strip:2"
	threshold = 50
	margin = 2
	state_modifier = {
		resistance_damage_to_garrison = 1
	}
}

resistance_75 = {
	type = state_resistance_modifier
	icon = "GFX_occupation_resistance_modifier_strip:3"
	small_icon = "GFX_occupation_resistance_modifier_small_strip:3"
	threshold = 75
	margin = 2
	state_modifier = {
		army_speed_factor_for_controller = -0.5
		local_supplies_for_controller = -0.5
		attrition_for_controller = 0.3
		disable_strategic_redeployment_for_controller = 1
	}
}

resistance_90 = {
	type = core_resistance_modifier
	icon = "GFX_occupation_resistance_modifier_strip:4"
	small_icon = "GFX_occupation_resistance_modifier_small_strip:4"
	threshold = 90
	margin = 2
	
	alert_level = high
	alert_margin = 20
	
	state_modifier = {
		local_factories = -0.03
	}
	
	on_enable = {
		custom_effect_tooltip = resistance_90_effect_tooltip
		hidden_effect = {
			set_temp_variable = { occupier_country = THIS }
			set_temp_variable = { occupied_country = FROM }
			set_temp_variable = { new_occupied_country = FROM }
			
			if = { #warsaw achievement
				limit = {
					var:occupied_country = { original_tag = POL }
				}
				set_global_flag = warsaw_liberated_self_flag
			}
			
			
			set_temp_variable = { civil_war_country_picked = 0 }
			if = {
				## pick an existing civil war country
				limit = {
					FROM = {
						tag = PREV
					}
				}
				
				random_country_with_original_tag = {
					original_tag_to_check = var:occupier_country
					
					limit = {
						NOT = { tag = var:occupier_country }
						has_war_with = var:occupier_country
					}
					
					set_temp_variable = { civil_war_country_picked = 1 }
					set_temp_variable = { new_occupied_country = this }
				}
			}
			
			if = {
				## create a new country if necesarry
				limit = {
					check_variable = { civil_war_country_picked = 0 } 
					FROM = {
						#if resistance country exists and not at war with occupier (whitepaced/subjected etc) create a country instead
						exists = yes
						NOT = { has_war_with = occupier_country }
					}
				}
				create_dynamic_country = {
					original_tag = FROM
					copy_tag = FROM
					
					set_temp_variable = { new_occupied_country = THIS }
				}
			}
			
			# 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 = { occupied_country_tag = occupied_country }
				
				# 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 } 
			}
		}
	}
}
