autonomy_being_changed_process = {
	icon = "gfx/interface/icons/event_icons/event_portrait.dds"
	
	is_shown_when_inactive = {
		is_subject = yes
	}
	
	possible = {
		OR = {
			has_variable = turning_into_annexed
			has_variable = turning_into_puppet
			has_variable = turning_into_colony
			has_variable = turning_into_dominion
			has_variable = turning_into_protectorate
			has_modifier = subject_autonomy_being_increased_modifier
			has_modifier = subject_autonomy_being_lowered_modifier
		}
	}
	
	current_value = {
		value = subject_autonomy_journal_value
	}

	goal_add_value = {
		add = 100 # was 100, temp testing value
	}
	
	on_weekly_pulse = {
		effect = {
			if = {
				limit = {
					OR = {
						has_variable = turning_into_annexed
						has_variable = turning_into_puppet
						has_variable = turning_into_colony
						has_variable = turning_into_dominion
						has_variable = turning_into_protectorate
					}
				}
				overlord = {
					if = {
						limit = {
							NOT = { has_variable = autonomy_progress_reduction_rate }
						}
						set_variable = {
							name = autonomy_progress_reduction_rate
							value = 3
						}
					}
					set_local_variable = {
						name = overlord_autonomy_progress_reduction_rate
						value = var:autonomy_progress_reduction_rate
					}
				}
				if = {
					limit = {
						NOT = { has_variable = autonomy_progress }
					}
					set_variable = {
						name = autonomy_progress
						value = 0
					}
				}
				set_local_variable = {
					name = autonomy_change_resistance_modifiers
					value = 0
				}
				if = {
					limit = {
						always = yes
						#NOT = { has_variable = autonomy_change_resistance }
					}
					set_variable = {
						name = autonomy_change_resistance
						value = 0
					}
				}
				if = {
					limit = {
						country_rank >= rank_value:major_power
					}
					change_local_variable = {
						name = autonomy_change_resistance_modifiers
						add = 1
					}
				}
				change_variable = {
					name = autonomy_change_resistance
					add = local_var:autonomy_change_resistance_modifiers
				}
				change_local_variable = {
					name = overlord_autonomy_progress_reduction_rate
					subtract = var:autonomy_change_resistance
				}
				set_variable = {
					name = autonomy_progress_reduction_rate
					value = local_var:overlord_autonomy_progress_reduction_rate
				}
			}
			if = {
				limit = {
					OR = {
						has_modifier = subject_autonomy_being_increased_modifier
						has_modifier = subject_autonomy_being_lowered_modifier
					}
					NOT = {
						has_variable = turning_into_annexed
						has_variable = turning_into_puppet
						has_variable = turning_into_colony
						has_variable = turning_into_dominion
						has_variable = turning_into_protectorate
					}
				}
				remove_modifier = subject_autonomy_being_increased_modifier
				remove_modifier = subject_autonomy_being_lowered_modifier
				overlord = {
					remove_modifier = subject_autonomy_being_lowered_overlord_modifier
					remove_modifier = subject_autonomy_being_increased_overlord_modifier
					every_subject_or_below = {
						limit = {
							has_modifier = subject_autonomy_being_increased_modifier
						}
						overlord = {
							add_modifier = {
								name = subject_autonomy_being_increased_overlord_modifier
								days = -1 # permanent until removed
							}
						}
					}
					every_subject_or_below = {
						limit = {
							has_modifier = subject_autonomy_being_lowered_modifier
						}
						overlord = {
							add_modifier = {
								name = subject_autonomy_being_lowered_overlord_modifier
								days = -1 # permanent until removed
							}
						}
					}
				}
			}
		}
	}
	
	on_monthly_pulse = {
		effect = {
			if = {
				limit = {
					OR = {
						has_variable = turning_into_annexed
						has_variable = turning_into_puppet
						has_variable = turning_into_colony
						has_variable = turning_into_dominion
						has_variable = turning_into_protectorate
					}
				}
				if = {
					limit = {
						var:autonomy_progress_reduction_rate < 1
					}
					set_variable = {
						name = autonomy_progress_reduction_rate
						value = 3
					}
				}
				change_variable = {
					name = autonomy_progress
					subtract = var:autonomy_progress_reduction_rate
				}
				if = {
					limit = {
						OR = {
							is_subject_type = subject_type_protectorate
							is_subject_type = subject_type_tributary
						}
						has_variable = turning_into_dominion
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_dominion
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						if = {
							limit = {
								is_country_type = recognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = dominion
							}
						}
						if = {
							limit = {
								is_country_type = unrecognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = dominion
							}
						}
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						OR = {
							is_subject_type = subject_type_protectorate
							is_subject_type = subject_type_tributary
						}
						OR = {
							has_variable = turning_into_annexed
							has_variable = turning_into_puppet
							has_variable = turning_into_colony
						}
						var:autonomy_progress < 1
					}
					set_variable = { name = autonomy_progress value = 20 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						if = {
							limit = {
								is_country_type = recognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = dominion
							}
						}
						if = {
							limit = {
								is_country_type = unrecognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = dominion
							}
						}
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				### protectorate losing autonomy ^^^
				if = {
					limit = {
						is_subject_type = subject_type_dominion
						has_variable = turning_into_colony
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_colony
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = colony
						}
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						is_subject_type = subject_type_dominion
						OR = {
							has_variable = turning_into_annexed
							has_variable = turning_into_puppet
						}
						var:autonomy_progress < 1
					}
					set_variable = { name = autonomy_progress value = 20 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = colony
						}
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						is_subject_type = subject_type_dominion
						has_variable = turning_into_protectorate
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_protectorate
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = protectorate
						}
						add_modifier = {
							name = subject_autonomy_being_increased_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				### dominion losing/gaining autonomy ^^^
				if = {
					limit = {
						is_subject_type = subject_type_colony
						has_variable = turning_into_puppet
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_puppet
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						if = {
							limit = {
								is_country_type = recognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = puppet
							}
						}
						if = {
							limit = {
								is_country_type = unrecognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = vassal
							}
						}
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						is_subject_type = subject_type_colony
						has_variable = turning_into_annexed
						var:autonomy_progress < 1
					}
					set_variable = { name = autonomy_progress value = 20 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						if = {
							limit = {
								is_country_type = recognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = puppet
							}
						}
						if = {
							limit = {
								is_country_type = unrecognized
							}
							create_diplomatic_pact = {
								country = scope:autonomy_being_changed_process_target
								type = vassal
							}
						}
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						is_subject_type = subject_type_colony
						has_variable = turning_into_dominion
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_dominion
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = dominion
						}
						add_modifier = {
							name = subject_autonomy_being_increased_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						is_subject_type = subject_type_colony
						has_variable = turning_into_protectorate
						var:autonomy_progress < 1
					}
					set_variable = { name = autonomy_progress value = 20 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = dominion
						}
						add_modifier = {
							name = subject_autonomy_being_increased_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				### colony gaining/losing autonomy ^^^
				if = {
					limit = {
						OR = {
							is_subject_type = subject_type_puppet
							is_subject_type = subject_type_vassal
							is_subject_type = subject_type_personal_union
						}
						has_variable = turning_into_annexed
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_annexed
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						annex = scope:autonomy_being_changed_process_target
						add_modifier = {
							name = subject_autonomy_being_lowered_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						OR = {
							is_subject_type = subject_type_puppet
							is_subject_type = subject_type_vassal
							is_subject_type = subject_type_personal_union
						}
						has_variable = turning_into_colony
						var:autonomy_progress < 1
					}
					remove_variable = turning_into_colony
					set_variable = { name = autonomy_progress value = 0 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = colony
						}
						add_modifier = {
							name = subject_autonomy_being_increased_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				if = {
					limit = {
						OR = {
							is_subject_type = subject_type_puppet
							is_subject_type = subject_type_vassal
							is_subject_type = subject_type_personal_union
						}
						OR = {
							has_variable = turning_into_dominion
							has_variable = turning_into_protectorate
						}
						var:autonomy_progress < 1
					}
					set_variable = { name = autonomy_progress value = 20 }
					save_scope_as = autonomy_being_changed_process_target
					overlord = {
						create_diplomatic_pact = {
							country = scope:autonomy_being_changed_process_target
							type = colony
						}
						add_modifier = {
							name = subject_autonomy_being_increased_overlord_timed_modifier
							months = normal_modifier_time
						}
					}
				}
				# puppet gaining/losing autonomy
			}
			else = {
				
			}
		}
	}
	
	complete = {
		and = {
			scope:journal_entry = {
				is_goal_complete = yes
			}
			always = no
		}
	}

	fail = {
		always = no
	}

	on_complete = {
		
	}

	on_fail = {
		
	}
	progressbar = yes
	can_deactivate = yes
	should_be_pinned_by_default = yes
	weight = 100
}