@LOCAL_OPERATION_EFFECT = 0.25

@STEAL_TECH_BONUS = 0.25
@STEAL_TECH_AOT = 0.25
@STEAL_TECH_USES = 2

@COORDINATED_STRIKE_USES = 12

@SABOTAGE_RADAR_DAMAGE = 1.5
@SABOTAGE_RADAR_REPAIR = -0.33

operation_infiltrate_armed_forces_airforce = { ### 6 1/55
	icon = GFX_operations_infiltrate_air_forces
	map_icon = GFX_operations_infiltrate_air_forces_map
	name = operation_infiltrate_armed_forces_airforce
	desc = operation_infiltrate_armed_forces_airforce_desc
	priority = 12

	days = 90
	network_strength = 35
	operatives = 2

	allowed = {
		has_done_agency_upgrade = upgrade_form_operations
	}

	visible = {
		NOT = { has_country_flag = ui_hide_air_operations@FROM }
		network_national_coverage = {
			target = FROM
			value > 0
		}
		has_done_agency_upgrade = upgrade_form_operations
		
	}

	available = {
		set_temp_variable = { t = modifier@operation_air_max_asset }
		add_to_temp_variable = { t = 1 }
		custom_trigger_tooltip = {
			tooltip = operation_max_asset_trigger
			NOT = {
				check_variable = { intel_air_asset_level@FROM = t }
			}
		}
	}

	equipment = {
		support_equipment = 75
	}
	
	ai_will_do = {
		base = 0
		modifier = {
			add = 1250
			
			#OR = {
				is_in_array = { ai_operations = token:operation_sabotage_radar }
			#}
		}
		modifier = {
			add = num_asset
			
			set_temp_variable = { num_asset = intel_air_asset_level@FROM }
			multiply_temp_variable = { num_asset = -250 }
		}
		modifier = {
			add = asset_chance
			
			set_temp_variable = { num_asset = modifier@operation_air_keep_asset_chance }
			multiply_temp_variable = { num_asset = -1000 }
		}
	}

	awarded_tokens = {
		token_airforce
	}
	risk_chance = 0.1
	outcome_extra_chance = 0
	risk_modifiers = { operation_infiltrate_risk operation_risk }
	outcome_modifiers = { operation_infiltrate_outcome operation_outcome }
	cost_modifiers = { operation_infiltrate_cost operation_cost }
	
	on_start = {
		every_operative = {
			add_to_temp_variable = { operative_outcome = leader_modifier@operation_infiltrate_outcome }
		}
		ROOT = {
			set_temp_variable = { CRITICAL_SUCCESS = 25 }
			set_temp_variable = { factor = modifier@operation_infiltrate_outcome }
			add_to_temp_variable = { factor = modifier@operation_outcome }
			add_to_temp_variable = { factor = operative_outcome }
			subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
			add_to_temp_variable = { factor = 1 }
			multiply_temp_variable = { CRITICAL_SUCCESS = factor }
			
			random = {
				chance = CRITICAL_SUCCESS
				
				set_country_flag = operation_infiltrate_air_critical@FROM
			}
		}
	}
	outcome_execute = {
		ROOT = {
			
			custom_effect_tooltip = {
				localization_key = ADD_INTEL_TOKEN
				TOKEN = token_airforce
				MODIFIER = MODIFIER_AIRFORCE_INTEL_FACTOR
				AMOUNT = 5
			}
			
			operation_add_air_asset = yes
			
			if = {
				limit = {
					has_country_flag = operation_infiltrate_air_critical@FROM
				}
				custom_effect_tooltip = CRITICAL_SUCCESS
				air_experience = 10
				add_intel = {
					target = FROM
					airforce_intel = 10
				}
				clr_country_flag = operation_infiltrate_air_critical@FROM
			}
			
			if = {
				limit = {
					has_global_flag = ai_track_operations
				}
				add_to_array = { ROOT.operation_completed = token:operation_infiltrate_armed_forces_airforce }
				add_to_array = { ROOT.operation_completed_state = FROM.FROM }
				add_to_array = { ROOT.operation_completed_target = FROM }
				add_to_array = { ROOT.operation_completed_date = global.date }
			}
		}
	}

	### THIS IS ONLY! TOOLTIP
	outcome_potential = { 
		ROOT = {
			
			set_temp_variable = { CRITICAL_SUCCESS = 25 }
			set_temp_variable = { factor = modifier@operation_infiltrate_outcome }
			add_to_temp_variable = { factor = modifier@operation_outcome }
			subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
			add_to_temp_variable = { factor = 1 }
			multiply_temp_variable = { CRITICAL_SUCCESS = factor }
			
			custom_effect_tooltip = {
				localization_key = ADD_INTEL_TOKEN
				TOKEN = token_airforce
				MODIFIER = MODIFIER_AIRFORCE_INTEL_FACTOR
				AMOUNT = 5
			}
			
			custom_effect_tooltip = OPERATION_OUTCOME_CRITICAL_SUCCESS
			air_experience = 10
			add_intel = {
				target = FROM
				airforce_intel = 10
			}
		}
	}

	phases = { #infiltration
		infiltration_border = { base = 25 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		infiltration_submarine = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
		infiltration_paradrop = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		infiltration_diplomatic = {	base = 50 modifier = { factor = 0 FROM = { has_war_with = ROOT } } }
	}
	phases = { #infiltrate military
		infiltrate_military_bribe = { base = 25 }
		infiltrate_military_seduction = { base = 25 }
		infiltrate_military_ideological_supporter = {
			base = 25
			modifier = {
				FROM = { has_government = ROOT }
				factor = 0
			}
		}
	}
	phases = { #exfiltration
		exfiltration_air_pickup = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		exfiltration_border = { base = 30 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		exfiltration_go_to_ground = { base = 30 }
		exfiltration_submarine_pickup = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
	}
}


operation_steal_tech_airforce = { ### 16 3/55
	icon = GFX_operations_steal_blueprints
	map_icon = GFX_operations_steal_blueprints_map
	name = operation_steal_tech_airforce
	desc = operation_steal_tech_airforce_desc
	priority = 13

	days = 70
	network_strength = 40
	operatives = 2

	allowed = {
		has_done_agency_upgrade = upgrade_form_operations
	}

	visible = {
		NOT = { has_country_flag = ui_hide_air_operations@FROM }
		network_strength = {
			target = FROM
			value > 25
		}

		has_operation_token = {
			tag = FROM
			token = token_airforce
		}
	}
	
	available = {
		custom_trigger_tooltip = {
			tooltip = REQUIRE_AIR_ASSET
			
			check_variable = { intel_air_asset_level@FROM > 0 }
		}
	}

	equipment = {
		support_equipment = 125
	}

	required_tokens = { token_airforce }
	
	risk_chance = 0.2
	outcome_extra_chance = 0
	risk_modifiers = { operation_steal_tech_risk operation_risk }
	outcome_modifiers = { operation_steal_tech_outcome operation_outcome }
	cost_modifiers = { operation_steal_tech_cost operation_cost }

	outcome_potential = {
		custom_effect_tooltip = OPERATION_CHANCE_AIR_TOKEN
		
		set_temp_variable = { bonus = @STEAL_TECH_BONUS }
		set_temp_variable = { factor = modifier@operation_steal_tech_bonus_factor }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { bonus = factor }
	
		set_temp_variable = { aot_bonus = @STEAL_TECH_AOT }
		set_temp_variable = { factor = modifier@operation_steal_tech_aot_factor }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { aot_bonus = factor }
		
		set_temp_variable = { uses = @STEAL_TECH_USES }
		add_to_temp_variable = { uses = modifier@operation_steal_tech_uses }
		
		set_temp_variable = { CRITICAL_SUCCESS = 25 }
		set_temp_variable = { factor = modifier@operation_outcome }
		add_to_temp_variable = { factor = modifier@operation_steal_tech_outcome }
		subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { CRITICAL_SUCCESS = factor }
		
		custom_effect_tooltip = STEAL_TECH_AIR_OUTCOME_POTENTIAL_TOOLTIP
		FROM = {
			add_timed_idea = {
				idea = air_steal_tech_critical
				days = 70
			}
		}
	}
	on_start = {
		every_operative = {
			add_to_temp_variable = { operative_outcome = leader_modifier@operation_steal_tech_outcome }
			add_to_temp_variable = { operative_bonus = leader_modifier@operation_steal_tech_bonus_factor }
			add_to_temp_variable = { operative_uses = leader_modifier@operation_steal_tech_uses }
			add_to_temp_variable = { operative_asset = leader_modifier@operation_air_keep_asset_chance }
		}
		ROOT = {
			set_temp_variable = { CRITICAL_SUCCESS = 25 }
			set_temp_variable = { factor = modifier@operation_outcome }
			add_to_temp_variable = { factor = modifier@operation_steal_tech_outcome }
			add_to_temp_variable = { factor = operative_outcome }
			subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
			add_to_temp_variable = { factor = 1 }
			multiply_temp_variable = { CRITICAL_SUCCESS = factor }
			
			random = {
				chance = CRITICAL_SUCCESS
				
				set_country_flag = operation_steal_tech_air_critical@FROM
			}
			
			
			set_temp_variable = { USE_ASSET_CHANCE = 1 }
			subtract_from_temp_variable = { USE_ASSET_CHANCE = operative_asset }
			subtract_from_temp_variable = { USE_ASSET_CHANCE = modifier@operation_air_keep_asset_chance }
			multiply_temp_variable = { USE_ASSET_CHANCE = 100 }
			random = {
				chance = USE_ASSET_CHANCE
				
				set_country_flag = operation_steal_tech_air_use_asset@FROM
				operation_remove_air_asset = yes
			}
			
			
			set_variable = { operation_steal_tech_air_bonus@FROM = @STEAL_TECH_BONUS }
			set_temp_variable = { factor = modifier@operation_steal_tech_bonus_factor }
			add_to_temp_variable = { factor = mtth:decryption_operation_effect }
			add_to_temp_variable = { factor = operative_bonus }
			subtract_from_temp_variable = { factor = FROM.modifier@operation_air_enemy_effect }
			add_to_temp_variable = { factor = 1 }
			multiply_variable = { operation_steal_tech_air_bonus@FROM = factor }
			
			set_variable = { operation_steal_tech_air_ahead_of_time@FROM = @STEAL_TECH_AOT }
			set_temp_variable = { factor = modifier@operation_steal_tech_aot_factor }
			add_to_temp_variable = { factor = mtth:decryption_operation_effect }
			subtract_from_temp_variable = { factor = FROM.modifier@operation_air_enemy_effect }
			add_to_temp_variable = { factor = 1 }
			multiply_variable = { operation_steal_tech_air_ahead_of_time@FROM = factor }
			
			set_variable = { operation_steal_tech_air_uses@FROM = @STEAL_TECH_USES }
			add_to_variable = { operation_steal_tech_air_uses@FROM = operative_bonus }
			add_to_variable = { operation_steal_tech_air_uses@FROM = modifier@operation_steal_tech_uses }
		}
	}
	outcome_execute = {
		ROOT = {
			
			if = {
				limit = {
					has_country_flag = operation_steal_tech_air_use_asset@FROM
				}
				custom_effect_tooltip = SUBTRACT_AIR_ASSET
				clr_country_flag = operation_steal_tech_air_use_asset@FROM
			}
			else = {
				custom_effect_tooltip = OPERATION_KEEP_ASSET
			}
			
			custom_effect_tooltip = STEAL_TECH_AIR_TOOLTIP
			if = {
				limit = {
					NOT = { is_in_array = { FROM.research_steal = ROOT } }
				}
				add_to_array = { FROM.research_steal_air = ROOT }
			}
			add_to_variable = { FROM.research_steal_uses_air@ROOT = operation_steal_tech_air_uses@FROM }
			set_variable = { FROM.research_steal_bonus_air@ROOT = operation_steal_tech_air_bonus@FROM }
			set_variable = { FROM.research_steal_ahead_of_time_air@ROOT = operation_steal_tech_air_ahead_of_time@FROM }
			
			clear_variable = operation_steal_tech_air_bonus@FROM
			clear_variable = operation_steal_tech_air_ahead_of_time@FROM
			clear_variable = operation_steal_tech_air_uses@FROM
			
			if = {
				limit = {
					has_country_flag = operation_steal_tech_air_critical@FROM
				}
				custom_effect_tooltip = CRITICAL_SUCCESS
				FROM = {
					add_timed_idea = {
						idea = air_steal_tech_critical
						days = 70
					}
				}
				clr_country_flag = operation_steal_tech_air_critical@FROM
			}
		}
	}

	phases = { #infiltration
		infiltration_border = { base = 25 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		infiltration_submarine = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
		infiltration_paradrop = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		infiltration_diplomatic = {	base = 50 modifier = { factor = 0 FROM = { has_war_with = ROOT } } }
	}
	phases = { #blueprint theft
		steal_blueprints_bribe = { base = 33 }
		steal_blueprints_seduction = { base = 33 }
		steal_blueprints_middle_manager = { base = 33 }
	}
	phases = { #exfiltration
		exfiltration_air_pickup = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		exfiltration_border = { base = 30 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		exfiltration_go_to_ground = { base = 30 }
		exfiltration_submarine_pickup = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
	}
}

operation_coordinated_strike = { ### 11 2/70
	icon = GFX_operations_coordinated_strike
	map_icon = GFX_operations_coordinated_strike_map
	name = operation_coordinated_strike
	desc = operation_coordinated_strike_desc
	priority = 14

	days = 50
	network_strength = 50
	operatives = 2

	allowed = {
		has_done_agency_upgrade = upgrade_form_operations
	}

	visible = {
		NOT = { has_country_flag = ui_hide_air_operations@FROM }
		network_strength = {
			target = FROM
			value > 25
		}
		
		has_operation_token = {
			tag = FROM
			token = token_airforce
		}
	}

	available = {
		custom_trigger_tooltip = {
			tooltip = REQUIRE_AIR_ASSET
			
			check_variable = { intel_air_asset_level@FROM > 0 }
		}
		has_war_with = FROM
	}

	equipment = {	
		infantry_equipment = 150
		support_equipment = 225
	}

	required_tokens = { token_airforce }

	target_type = strategic_region

	selection_target = {
		targets = { FROM }
	}

	risk_chance = 0.15
	outcome_extra_chance = 0
	outcome_modifiers = { operation_coordinated_strike_outcome operation_outcome }
	risk_modifiers = { operation_coordinated_strike_risk operation_risk }
	cost_modifiers = { operation_coordinated_strike_cost operation_cost }
	
	on_start = {
		every_operative = {
			add_to_temp_variable = { operative_outcome = leader_modifier@operation_coordinated_strike_outcome }
			add_to_temp_variable = { operative_bonus = leader_modifier@operation_coordinated_strike_damage }
			add_to_temp_variable = { operative_asset = leader_modifier@operation_air_keep_asset_chance }
		}
		ROOT = {
			set_temp_variable = { CRITICAL_SUCCESS = 25 }
			set_temp_variable = { factor = modifier@operation_outcome }
			add_to_temp_variable = { factor = operative_outcome }
			add_to_temp_variable = { factor = modifier@operation_coordinated_strike_outcome }
			subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
			add_to_temp_variable = { factor = 1 }
			multiply_temp_variable = { CRITICAL_SUCCESS = factor }
			
			random = {
				chance = CRITICAL_SUCCESS
				
				set_country_flag = operation_coordinated_strike_critical@FROM
			}
			
			
			set_temp_variable = { USE_ASSET_CHANCE = 1 }
			subtract_from_temp_variable = { USE_ASSET_CHANCE = operative_asset }
			subtract_from_temp_variable = { USE_ASSET_CHANCE = modifier@operation_air_keep_asset_chance }
			multiply_temp_variable = { USE_ASSET_CHANCE = 100 }
			random = {
				chance = USE_ASSET_CHANCE
				
				set_country_flag = operation_coordinated_strike_use_asset@FROM
				operation_remove_air_asset = yes
			}
			
			
			set_variable = { operation_coordinated_strike_damage@FROM = @COORDINATED_STRIKE_USES }
			set_temp_variable = { factor = modifier@operation_coordinated_strike_damage }
			add_to_temp_variable = { factor = mtth:decryption_operation_effect }
			add_to_temp_variable = { factor = operative_bonus }
			subtract_from_temp_variable = { factor = FROM.modifier@operation_air_enemy_effect }
			add_to_temp_variable = { factor = 1 }
			multiply_variable = { operation_coordinated_strike_damage@FROM = factor }
		}
	}
	outcome_execute = { # SCOPE_OPERATION
		hidden_effect = {
			FROM.FROM = {
				ROOT = {
					set_temp_variable = { local = mtth:network_strength_state }
					divide_temp_variable = { local = 100 }
					set_temp_variable = { network_strength_state = local }
					multiply_temp_variable = { local = @LOCAL_OPERATION_EFFECT }
					add_to_temp_variable = { local = PREV.modifier@local_operation_effect }
					set_temp_variable = { local_effect = local }
					
					add_to_temp_variable = { local = 1 }
					
					multiply_variable = { operation_coordinated_strike_damage@FROM = local }
					
					## use these variables for tooltips & effects
					set_temp_variable = { effect = operation_coordinated_strike_damage@FROM }
					multiply_temp_variable = { effect = local }
					
				}
			}
		}
		custom_effect_tooltip = LOCAL_OPERATION_EFFECT_TOOLTIP
		
		ROOT = {
			if = {
				limit = {
					has_country_flag = operation_coordinated_strike_use_asset@FROM
				}
				custom_effect_tooltip = SUBTRACT_AIR_ASSET
				clr_country_flag = operation_coordinated_strike_use_asset@FROM
			}
			else = {
				custom_effect_tooltip = OPERATION_KEEP_ASSET
			}
		}
			
		custom_effect_tooltip = COORDINATED_STRIKE_TOOLTIP
		meta_effect = {
			text = {
				execute_operation_coordinated_strike = {
					amount = [X]
				}
			}
			X = "[?ROOT.operation_coordinated_strike_damage@FROM]"
		}
		
		ROOT = {
			clear_variable = operation_coordinated_strike_damage@FROM
				
			if = {
				limit = {
					has_country_flag = operation_coordinated_strike_critical@FROM
				}
				custom_effect_tooltip = CRITICAL_SUCCESS
				
				custom_override_tooltip = {
					tooltip = COORDINATED_STRIKE_CRITICAL_TOOLTIP
					
					FROM.FROM = {
						for_each_scope_loop = {
							array = global.region_states@var:region
							
							add_dynamic_modifier = {
								modifier = operation_coordinated_strike_critical
								days = 30
							}
						}
					}
				}
				clr_country_flag = operation_coordinated_strike_critical@FROM
			}
		}
	
	}

	outcome_potential = {
		custom_effect_tooltip = OPERATION_CHANCE_AIR_TOKEN
		
		set_temp_variable = { damage = @COORDINATED_STRIKE_USES }
		set_temp_variable = { factor = modifier@operation_coordinated_strike_damage }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { damage = factor }
		
		
		set_temp_variable = { CRITICAL_SUCCESS = 25 }
		set_temp_variable = { factor = modifier@operation_outcome }
		add_to_temp_variable = { factor = modifier@operation_coordinated_strike_outcome }
		subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { CRITICAL_SUCCESS = factor }
		
		custom_effect_tooltip = COORDINATED_STRIKE_OUTCOME_POTENTIAL_TOOLTIP
		
	}

	phases = { #infiltration
		infiltration_border = { base = 25 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		infiltration_submarine = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
		infiltration_paradrop = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		infiltration_diplomatic = {	base = 50 modifier = { factor = 0 FROM = { has_war_with = ROOT } } }
	}
	phases = { #preparing
		coordinated_strike_scout_target = { base = 50 }
		coordinate_strike_mark_targets = { base = 50 }
	}

	phases = { #execution
		coordinated_strike_sabotage_communications = { base = 34 }
		coordinated_strike_direct_units = { base = 34 }
		coordinated_strike_occupy_bridges = { 
			base = 34 
			modifier = {
				NOT = {
					FROM = {
						any_neighbor_country = {
							tag = ROOT #no land connection between FROM and ROOT
						}
					}
				}
				factor = 0
			}
		}
	}
}

operation_sabotage_radar = { ### 18 2/35

	icon = GFX_operations_targeted_sabotage
	map_icon = GFX_operations_targeted_sabotage_map
	name = operation_sabotage_radar
	desc = operation_sabotage_radar_desc

	priority = 15

	days = 50
	operatives = 2
	network_strength = 50

	allowed = {
		has_done_agency_upgrade = upgrade_form_operations
	}

	visible = {
		NOT = { has_country_flag = ui_hide_air_operations@FROM }
		network_strength = {
			target = FROM
			value > 25
		}

		has_operation_token = {
			tag = FROM
			token = token_airforce
		}
	}	

	available = {
		FROM = { radar_station > 0 }
		custom_trigger_tooltip = {
			tooltip = REQUIRE_AIR_ASSET
			
			check_variable = { intel_air_asset_level@FROM > 0 }
		}
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 1000
			
			is_in_array = { ai_operations = token:operation_sabotage_radar }
		}
		modifier = {
			add = 150
			
			check_variable = { ai_operations^0 = token:operation_sabotage_radar }
		}
		modifier = {
			add = 100
			
			check_variable = { ai_operations^1 = token:operation_sabotage_radar }
		}
		modifier = {
			add = 50
			
			check_variable = { ai_operations^2 = token:operation_sabotage_radar }
		}
	}
	selection_target_state = {
		check_variable = { non_damaged_building_level@radar_station > 0 }
	}
	selection_target = {
		targets = { FROM }
	}
	
	target_weight = {
		base = 100
		
		modifier = {
			add = t
			
			set_temp_variable = { t = non_damaged_building_level@radar_station }
			multiply_temp_variable = { t = 10 }
		}
		modifier = {
			add = 50
			
			is_in_array = { global.front_states = THIS }
		}
	}
	
	required_tokens = { token_airforce }
	
	
	equipment = {
		infantry_equipment = 100
		support_equipment = 100
	}
	
	risk_chance = 0.2
	outcome_extra_chance = 0
	outcome_modifiers = { operation_sabotage_outcome operation_outcome }
	risk_modifiers = { operation_sabotage_risk operation_risk }
	cost_modifiers = { operation_sabotage_cost operation_cost }
	
	outcome_potential = {
		custom_effect_tooltip = OPERATION_CHANCE_AIR_TOKEN
		
		set_temp_variable = { damage = @SABOTAGE_RADAR_DAMAGE }
		set_temp_variable = { factor = modifier@operation_sabotage_damage }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { damage = factor }
		
		set_temp_variable = { repair = @SABOTAGE_RADAR_REPAIR }
		set_temp_variable = { factor = modifier@operation_sabotage_repair }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { repair = factor }
		multiply_temp_variable = { repair = 100 }
		
		set_temp_variable = { CRITICAL_SUCCESS = 25 }
		set_temp_variable = { factor = modifier@operation_outcome }
		add_to_temp_variable = { factor = modifier@operation_sabotage_outcome }
		subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
		add_to_temp_variable = { factor = 1 }
		multiply_temp_variable = { CRITICAL_SUCCESS = factor }
		
		custom_effect_tooltip = {
			localization_key = SABOTAGE_RADAR_OUTCOME_POTENTIAL_TOOLTIP
			DAMAGE = [?damage]
			REPAIR = [?repair]
		}
	
	}
	on_start = {
		every_operative = {
			add_to_temp_variable = { operative_outcome = leader_modifier@operation_sabotage_outcome }
			add_to_temp_variable = { operative_bonus = leader_modifier@operation_sabotage_damage }
			add_to_temp_variable = { operative_spread = leader_modifier@operation_sabotage_spread }
			add_to_temp_variable = { operative_asset = leader_modifier@operation_air_keep_asset_chance }
		}
		ROOT = {
			set_temp_variable = { CRITICAL_SUCCESS = 25 }
			set_temp_variable = { factor = modifier@operation_outcome }
			add_to_temp_variable = { factor = modifier@operation_sabotage_outcome }
			add_to_temp_variable = { factor = operative_outcome }
			subtract_from_temp_variable = { factor = FROM.modifier@enemy_operation_critical_success_chance }
			add_to_temp_variable = { factor = 1 }
			multiply_temp_variable = { CRITICAL_SUCCESS = factor }
			
			random = {
				chance = CRITICAL_SUCCESS
				
				set_country_flag = operation_sabotage_radar_critical@FROM
			}
			
			
			set_temp_variable = { USE_ASSET_CHANCE = 1 }
			subtract_from_temp_variable = { USE_ASSET_CHANCE = operative_asset }
			subtract_from_temp_variable = { USE_ASSET_CHANCE = modifier@operation_air_keep_asset_chance }
			multiply_temp_variable = { USE_ASSET_CHANCE = 100 }
			random = {
				chance = USE_ASSET_CHANCE
				
				set_country_flag = operation_sabotage_radar_use_asset@FROM
				operation_remove_air_asset = yes
			}
			
			
			set_variable = { operation_sabotage_radar_damage@FROM = @SABOTAGE_RADAR_DAMAGE }
			set_temp_variable = { factor = modifier@operation_sabotage_damage }
			add_to_temp_variable = { factor = mtth:decryption_operation_effect }
			add_to_temp_variable = { factor = operative_bonus }
			subtract_from_temp_variable = { factor = FROM.modifier@operation_air_enemy_effect }
			add_to_temp_variable = { factor = 1 }
			multiply_variable = { operation_sabotage_radar_damage@FROM = factor }
			
			set_variable = { operation_sabotage_radar_repair@FROM = @SABOTAGE_RADAR_REPAIR }
			add_to_variable = { operation_sabotage_radar_repair@FROM = modifier@operation_sabotage_repair }
			
			set_temp_variable = { factor = modifier@operation_sabotage_spread }
			add_to_temp_variable = { factor = operative_spread }
			
			set_variable = { operation_sabotage_radar_damage_spread@FROM = operation_sabotage_radar_damage@FROM }
			multiply_variable = { operation_sabotage_radar_damage_spread@FROM = factor }
			set_variable = { operation_sabotage_radar_repair_spread@FROM = operation_sabotage_radar_repair@FROM }
			multiply_variable = { operation_sabotage_radar_repair_spread@FROM = factor }
			
			
		}
	}
	outcome_execute = {
		hidden_effect = {
			FROM.FROM = {
				ROOT = {
					set_temp_variable = { local = mtth:network_strength_state }
					divide_temp_variable = { local = 100 }
					set_temp_variable = { network_strength_state = local }
					multiply_temp_variable = { local = @LOCAL_OPERATION_EFFECT }
					add_to_temp_variable = { local = PREV.modifier@local_operation_effect }
					set_temp_variable = { local_effect = local }
					
					add_to_temp_variable = { local = 1 }
					
					multiply_variable = { operation_sabotage_radar_damage@FROM = local }
					multiply_variable = { operation_sabotage_radar_repair@FROM = local }
					
					
					## use these variables for tooltips & effects
					set_temp_variable = { effect = operation_sabotage_radar_damage@FROM }
					multiply_temp_variable = { effect = local }
					set_temp_variable = { repair = operation_sabotage_radar_repair@FROM }
					multiply_temp_variable = { repair = local }
					
				}
			}
		}
		custom_effect_tooltip = LOCAL_OPERATION_EFFECT_TOOLTIP
		
		ROOT = {
			if = {
				limit = {
					has_country_flag = operation_sabotage_radar_use_asset@FROM
				}
				custom_effect_tooltip = SUBTRACT_AIR_ASSET
				clr_country_flag = operation_sabotage_radar_use_asset@FROM
			}
			else = {
				custom_effect_tooltip = OPERATION_KEEP_ASSET
			}
		
			custom_effect_tooltip = SABOTAGE_RADAR_TOOLTIP
			hidden_effect = {
				meta_effect = {
					text = {
						FROM.FROM = {
							damage_building = {
								type = radar_station
								damage = [D]
								repair_speed_modifier = [R]
							}
						}
					}
					D = "[?ROOT.operation_sabotage_radar_damage@FROM]"
					R = "[?ROOT.operation_sabotage_radar_repair@FROM]"
				}
				if = {
					limit = {
						ROOT = { has_country_flag = operation_sabotage_radar_critical@FROM }
					}
					FROM.FROM = {
						remove_building = {
							type = radar_station
							level = 1
						}
					}
				}
			
			}
			
			if = {
				limit = {
					check_variable = { modifier@operation_sabotage_spread > 0 }
				}
				hidden_effect = {
					FROM = {
						every_controlled_state = {
							limit = {
								#check_variable = { building_level@radar_station > 0 }
								check_variable = { non_damaged_building_level@radar_station > 0 }
							}
							add_to_temp_array = { radar_states = THIS }
						}
					}
					FROM.FROM = { set_temp_variable = { target_radar = THIS } }
					random_scope_in_array = {
						array = radar_states
						limit = {
							check_variable = { distance_to@var:target_radar > 0 }
							radar_station > 0
							#is_controlled_by = FROM
							NOT = {
								any_of_scopes = {
									array = radar_states
									check_variable = { distance_to@var:target_radar < PREV.distance_to@var:target_radar }
								}
							}
						}
						ROOT = {
							meta_effect = {
								text = {
									PREV = {
										damage_building = {
											type = radar_station
											damage = [D]
											repair_speed_modifier = [R]
										}
									}
								}
								D = "[?ROOT.operation_sabotage_radar_damage_spread@FROM]"
								R = "[?ROOT.operation_sabotage_radar_repair_spread@FROM]"
							}
						}
						set_temp_variable = { spread_target = THIS }
					}
				}
				custom_effect_tooltip = SABOTAGE_RADAR_SPREAD_TOOLTIP
			}
			
			if = {
				limit = {
					has_country_flag = operation_sabotage_radar_critical@FROM
				}
				custom_effect_tooltip = CRITICAL_SUCCESS
				custom_effect_tooltip = SABOTAGE_RADAR_CRITICAL_TOOLTIP
				
				#clr_country_flag = operation_sabotage_radar_critical@FROM
			}
			
			hidden_effect = {
				FROM = {
					set_variable = { operation_target_state = FROM.FROM }
					set_variable = { operation_spread_target_state = spread_target }
					country_event = { id = lar_operative_event.103 days = 3 }
				}
			}
			#clear_variable = operation_sabotage_radar_damage@FROM
			#clear_variable = operation_sabotage_radar_repair@FROM
			#clear_variable = operation_sabotage_radar_damage_spread@FROM
			#clear_variable = operation_sabotage_radar_repair_spread@FROM
			
			if = {
				limit = {
					has_global_flag = ai_track_operations
				}
				add_to_array = { ROOT.operation_completed = token:operation_sabotage_radar }
				add_to_array = { ROOT.operation_completed_state = FROM.FROM }
				add_to_array = { ROOT.operation_completed_target = FROM }
				add_to_array = { ROOT.operation_completed_date = global.date }
			}
		}
	}
	phases = { #infiltration
		infiltration_border = { base = 25 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		infiltration_submarine = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
		infiltration_paradrop = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		infiltration_diplomatic = {	base = 50 modifier = { factor = 0 FROM = { has_war_with = ROOT } } }
	}
	phases = { #exfiltration
		sabotage_radar_explosives = { base = 50 }
		sabotage_burn_radar = { base = 50 }
	}
	phases = { #exfiltration
		exfiltration_air_pickup = { base = 25 modifier = { factor = 0.1 ROOT = { has_equipment = { transport_plane_equipment < 1 } } } }
		exfiltration_border = { base = 30 modifier = { factor = 0.1 ROOT = { is_neighbor_of = FROM } } }
		exfiltration_go_to_ground = { base = 30 }
		exfiltration_submarine_pickup = { base = 25 modifier = { factor = 0.1 ROOT = { has_navy_size = { size < 1 type = submarine } } } }
	}
}
