

ai_decryption_target_scorer = {
	targets = {
		target_array = potential_and_current_enemies
		target_array = enemies_of_allies
		target_array = neighbors
		target_array = global.majors

		score = {
			base = 100

			modifier = {
				has_capitulated = yes
				factor = 0
			}
			# strat is directly added
			modifier = {
				add = FROM.ai_strategy_decrypt_target@THIS
			}

			# continue existing decryptions
			modifier = {
				FROM = {
					is_decrypting = PREV
					set_temp_variable = { temp_score = decryption_progress@PREV }
					multiply_temp_variable = { temp_score = 100 }
					add_to_temp_variable = { temp_score = 20 }
				}
				add = temp_score
			}

			modifier = {
				has_war_with = FROM
				factor = 2.0
			}

			modifier = {
				OR = {
					is_in_array = { FROM.potential_and_current_enemies = this }
					is_in_array = { FROM.enemies_of_allies = this }
				}
				factor = 1.5
			}

			# quite possibly we will attack this target due to strats
			modifier = {
				NOT = { has_war_with = FROM }
				OR = {
					check_variable = { FROM.ai_strategy_conquer@THIS > 0 }
					check_variable = { FROM.ai_strategy_antagonize@THIS > 0 }
					check_variable = { FROM.ai_strategy_declare_war@THIS > 0 }
					check_variable = { FROM.ai_strategy_prepare_for_war@THIS > 0 }
					check_variable = { FROM.ai_strategy_contain@THIS > 0 }
				}
				factor = 1.3
			}

			modifier = {
				is_in_array = { FROM.neighbors = this }
				factor = 1.2
			}


			modifier = {
				is_major = yes
				factor = 1.1
			}

			modifier = {
				has_government = FROM
				NOT = { has_war_with = FROM }
				factor = 0.6
			}

			# larger countries are a bit more prio
			modifier = {
				set_temp_variable = { temp_score = owned_states^num }
				divide_temp_variable = { temp_score = 20 }
				add_to_temp_variable = { temp_score = 1.0 }
				clamp_temp_variable = { var = temp_score max = 1.2 }
				factor = temp_score
			}

			# todo this should move to strat
			# modifier = {
			# 	FROM = {
			# 		tag = GER
			# 	}
			# 	OR = {
			# 		tag = SOV
			# 		tag = ENG
			# 	}
			# 	FRA = { has_capitulated = yes }
			# 	POL = { has_capitulated = yes }
			# 	factor = 1.8
			# }
			# todo this should move to strat
			# modifier = {
			# 	FROM = {
			# 		tag = GER
			# 	}
			# 	tag = POL
			# 	factor = 1.4
			# }
		}
	}
}
