scripted_gui = {

	Spy_Menu_Window = {
		context_type = selected_country_context
		parent_window_token = selected_country_view_diplomacy
	
		
		window_name = "Spy_Menu_Window_container"
		visible={
		check_variable = { ROOT.show_Spy_Menu@PREV = 1 }
		}
		
		effects = {
		
		
		
		Counter_Espionage_Button_click = {
		ROOT = {
		if = {limit = { check_variable = {ROOT.Counter_Intelligence@PREV = 0}}
		
		
		set_variable = {ROOT.Counter_Intelligence@PREV = -15}
		}}}
		
		Counter_Espionage_Button2_click = {
		ROOT = {
		if = {limit = { check_variable = {ROOT.Counter_Intelligence@PREV = -15}}
		
		
		set_variable = {ROOT.Counter_Intelligence@PREV = 0}
		}}}
		
		
		
   

		 
		
		
			Disrupt_Civilian_click  = { 
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 1}  
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			
			 
			}
			
			

		



			Disrupt_Military_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 2} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			}
			
			Sabotage_Production_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 3} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			}
		
			
			Sabotage_Extraction_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 4} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			}
			
			
			Sabotage_Recruitment_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 5} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			}
			
			Sabotage_Planning_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 6} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			}
		
		
		    Disrupt_Supply_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 7} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}

			}

			Jam_Radar_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV}
            add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}			
            set_variable = {ROOT.operation_type@PREV = 8} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			
			}
			
			Support_Resistance_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV}
            add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}			
            set_variable = {ROOT.operation_type@PREV = 10} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			
			}
			
			
			
			Poison_Food_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV}
            add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}			
            set_variable = {ROOT.operation_type@PREV = 9} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			
			}
						
			Support_Pacifists_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV}
            add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}			
            set_variable = {ROOT.operation_type@PREV = 11} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
			
			}
			
			
			Sabotage_Research_click  = {
			
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV}
            add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}			
            set_variable = {ROOT.operation_type@PREV = 12} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}}
			
			
			
			
			Infiltrate_click  = {
	       
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 40}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV} 
			add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}
            set_variable = {ROOT.operation_type@PREV = 14} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}
				

			
			}
				
				
				 
	            
	
            Sow_Discontent_click  = {
                
			ROOT = { 
            set_variable = {ROOT.Square@PREV = ROOT.Spy_Efficiency}
            divide_variable = { ROOT.Square@PREV = PREV.Spy_Efficiency}
			divide_variable = { ROOT.Square@PREV = 1.5}
            set_variable = {ROOT.base_of_this@PREV = 50}
            set_variable = {ROOT.Success_Chance@PREV = ROOT.Square@PREV}
            multiply_variable = {ROOT.Success_Chance@PREV = ROOT.base_of_this@PREV}
            add_to_variable = {ROOT.Success_Chance@PREV = PREV.Counter_Intelligence@ROOT}			
            set_variable = {ROOT.operation_type@PREV = 13} 
}
			
            set_variable = {ROOT.show_Mission_Confirmation = THIS.id}

				

			}
				
				
				
				
				
				
            Increase_Network_click = {
			
			
			ROOT = {


			
			if = { limit = {check_variable = {network_spies@PREV > 0}}
			subtract_from_variable = {spies_available = 100}
			add_to_variable = {network_spies@PREV = 100}}
			 
			 
			 
			
			else_if = {limit = {AND = {
			OR = {check_variable = {network1_target = PREV.id}
			      check_variable = {network2_target = PREV.id}
				  check_variable = {network3_target = PREV.id}
				  check_variable = {network4_target = PREV.id}
				  check_variable = {network5_target = PREV.id}
			
			}
			check_variable = {network_spies@PREV = 0}}}
			add_to_variable = {network_spies@PREV = 100}
			add_to_variable = {spies_available = -100}}
			
			else_if = {
			
			limit = {check_variable = { network1_target = 0}}
			set_variable = { network1_target = PREV.id}
			subtract_from_variable = {spies_available = 100}
			add_to_variable = {network_spies@PREV = 100}
			add_to_variable = {networks_used = 1}}
			
			else_if = {limit = {check_variable = { network2_target = 0}}
			set_variable = { network2_target = PREV.id}
			subtract_from_variable = {spies_available = 100}
			add_to_variable = {network_spies@PREV = 100}
			add_to_variable = {networks_used = 1}}
			
			else_if = {limit = {check_variable = { network3_target = 0}}
			set_variable = { network3_target = PREV.id}
			subtract_from_variable = {spies_available = 100}
			add_to_variable = {network_spies@PREV = 100}
			add_to_variable = {networks_used = 1}}
			
			else_if = {limit = {check_variable = { network4_target = 0}}
			set_variable = { network4_target = PREV.id}
			subtract_from_variable = {spies_available = 100}
			add_to_variable = {network_spies@PREV = 100}
			add_to_variable = {networks_used = 1}}
			
			else_if = {limit = {check_variable = { network5_target = 0}}
			set_variable = { network5_target = PREV.id}
			subtract_from_variable = {spies_available = 100}
			add_to_variable = {network_spies@PREV = 100}
			add_to_variable = {networks_used = 1}}
			

			 
			}
			
}   
				
				
		    Decrease_Network_click = {
			
			
			ROOT = {
			if = {
			limit = {check_variable = {network_spies@PREV > 100 }}
			add_to_variable = {spies_available = 100}
			subtract_from_variable = {network_spies@PREV = 100}
			}
			
			else_if = {
			limit = {check_variable = {network1_target = PREV.id }}
			set_variable = {network1_target = 0}
			subtract_from_variable = {network_spies@PREV = 100}
			add_to_variable = {spies_available = 100}
			add_to_variable = {networks_used = -1}
			clear_variable = network_strength@PREV
			clear_variable = network_spies@PREV
			}
				
			else_if = {
			limit = {check_variable = {network2_target = PREV.id }}
			set_variable = {network2_target = 0}
			subtract_from_variable = {network_spies@PREV = 100}
			add_to_variable = {spies_available = 100}
			add_to_variable = {networks_used = -1}
			clear_variable = network_strength@PREV
			clear_variable = network_spies@PREV
			}	
			
			else_if = {
			limit = {check_variable = {network3_target = PREV.id }}
			set_variable = {network3_target = 0}
			subtract_from_variable = {network_spies@PREV = 100}
			add_to_variable = {spies_available = 100}
			add_to_variable = {networks_used = -1}
			clear_variable = network_strength@PREV
			clear_variable = network_spies@PREV
			}	
				
			else_if = {
			limit = {check_variable = {network4_target = PREV.id }}
			set_variable = {network4_target = 0}
			subtract_from_variable = {network_spies@PREV = 100}
			add_to_variable = {spies_available = 100}
			add_to_variable = {networks_used = -1}
			clear_variable = network_strength@PREV
			clear_variable = network_spies@PREV
			}		     
			 
			else_if = {
			limit = {check_variable = {network5_target = PREV.id }}
			set_variable = {network5_target = 0}
			subtract_from_variable = {network_spies@PREV = 100}
			add_to_variable = {spies_available = 100}
			add_to_variable = {networks_used = -1}
			clear_variable = network_strength@PREV
			clear_variable = network_spies@PREV
			}		
			}}			
				 
			
            Negotiate_Release_Button_click = {
		    set_variable = { ROOT.show_Negotiate_Release = THIS.id}
			set_variable = {ROOT.Opinion_Factor = THIS.opinion@ROOT}
			add_to_variable = {ROOT.Deal_Favorability@THIS = ROOT.Opinion_Factor}
			 
}
				
			Operation_Eiche_Button_click = {
			ROOT = { set_variable = { show_Operation_Eiche = PREV.id} 
			clear_variable = ROOT.transport_needed@PREV
			set_variable = { ROOT.transport_needed@PREV = PREV.Spies_Captured@ROOT}
			divide_variable = {ROOT.transport_needed@PREV = 20}
			set_variable = { ROOT.eiche_success_chance@PREV = PREV.Spies_Captured@ROOT}
			divide_variable = { ROOT.eiche_success_chance@PREV = -4} 
			set_temp_variable = {Square = ROOT.Spy_Efficiency}
            divide_temp_variable = { Square = PREV.Spy_Efficiency}
            set_variable = {ratio@PREV = Square}
			divide_variable = { ROOT.eiche_success_chance@PREV = ratio@PREV}
			round_variable = ROOT.eiche_success_chance@PREV
			
			clear_variable = ROOT.marines_bonus@PREV
			clear_variable = ROOT.paratroopers_bonus@PREV 
			clear_variable = ROOT.eiche_transport@PREV
			clear_variable = ROOT.eiche_convoy@PREV         
			clear_variable = ROOT.paratroopers_eiche@PREV 		
			clear_variable = ROOT.marines_eiche@PREV 
			clear_variable = ROOT.convoy_penalty@PREV
			clear_variable = ROOT.convoy_needed@PREV
			clear_variable = ROOT.support_equipment_eiche@PREV
			clear_variable = ROOT.equipment_eiche@PREV
			clear_variable = ROOT.manpower_eiche@PREV

            set_variable = {ROOT.transport_penalty@PREV = -40}
		    add_to_variable = {ROOT.eiche_success_chance@PREV = ROOT.transport_penalty@PREV}			
			
			}
			
           } 	
				
				

					
				
				
				
				
				
				
	
			exitbutton_click = {
				set_variable = { ROOT.show_Spy_Menu@PREV = 0 }
			}
		}
		

		triggers = { 
		
		Counter_Espionage_Button_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                           }
												   
		Counter_Espionage_Button_ongoing_visible = { NOT = { check_variable = {ROOT.Counter_Intelligence@PREV = 0}}}
		Counter_Espionage_Button2_visible = { NOT = { check_variable = {ROOT.Counter_Intelligence@PREV = 0}}}												   
		
		Disrupt_Civilian_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}
										  }
		Disrupt_Military_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Sabotage_Production_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Sabotage_Extraction_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Sabotage_Recruitment_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Sabotage_Planning_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}      
		                                   check_variable = {ROOT.network_strength@PREV > 99.99} 
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Disrupt_Supply_click_enabled = {    check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Jam_Radar_click_enabled = {        check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Support_Resistance_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Poison_Food_click_enabled = {      check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Support_Pacifists_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Sabotage_Research_click_enabled = { check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Sow_Discontent_click_enabled = {   check_variable = {ROOT.network_spies@PREV > 99}
		                                   check_variable = {ROOT.network_strength@PREV > 99.99}
										   check_variable = {ROOT.Counter_Intelligence@PREV = 0}
										   NOT = {has_country_flag = Spy_Action_Attempted}}
		Infiltrate_click_enabled = { NOT = { has_country_flag = Spy_Action_Attempted }
		                                   check_variable = {ROOT.spies_available > 149 }
										   check_variable = {ROOT.Spy_Director_Level > 2}}		

        Increase_Network_click_enabled = { check_variable = {ROOT.Spies_Available > 99.99}
                                   check_variable = {ROOT.network_spies@PREV < 500}}

		Decrease_Network_click_enabled = { OR = {check_variable = {ROOT.network_spies@PREV > 100}
                                           AND = {check_variable = {ROOT.network_spies@PREV = 100}
										   NOT = {has_country_flag = Being_Disrupted_By@ROOT}}}}						   
		
		
		}
		
		  
		
		
		ai_enabled = {
            always = yes
        } 

        ai_check = {
        }
        
        ai_test_interval = 1500
        ai_test_variance = 0.3
        ai_test_scopes = test_neighbouring_countries
        ai_test_scopes = test_enemy_countries
		
		ai_check_scope = {
        check_variable = {ROOT.opinion@PREV < 0}
        check_variable = {num_of_factories > 30} 
		}                      
        ai_max_weight_taken_per_test = 10
        ai_max_weight_taken_per_test = 10
		
		# IMPROVED AI WEIGHTS - Strategic sabotage based on war/peace state
        ai_weights = {

        # Network Building - Scale based on enemy size and threat
        Increase_Network_click = {
               weight = 5
                 ai_will_do = {
                         factor = 0
						 # Small countries - 200 spies
						 modifier = {
						     ROOT = { check_variable = { ROOT.network_spies@PREV < 200 } }
							 PREV = { num_of_factories < 50 }
							 add = 5
						 }
						 # Medium countries - 300 spies
						 modifier = {
						     ROOT = { check_variable = { ROOT.network_spies@PREV < 300 } }
							 PREV = { num_of_factories > 49 }
							 add = 8
						 }
						 # Major powers at war - 400 spies
						 modifier = {
						     ROOT = { check_variable = { ROOT.network_spies@PREV < 400 } }
							 PREV = { is_major = yes }
							 has_war_with = PREV
							 add = 10
						 }
                 }
        }   
		

        # === WARTIME SABOTAGE (High Priority During War) ===
		
		# Supply Disruption - CRITICAL during active war
        Disrupt_Supply_click = {
               weight = 20
                 ai_will_do = {
                         factor = 0
						 # Only during war with target
						 modifier = { 
						     has_war_with = PREV
							 add = 15
						 }
						 # Extra priority vs industrialized enemies
						 modifier = {
						     has_war_with = PREV
							 PREV = { num_of_military_factories > 30 }
							 add = 10
						 }
                 }
        } 	
		
		# Sabotage Planning - CRITICAL during active war
        Sabotage_Planning_click = {
               weight = 18
                 ai_will_do = {
                         factor = 0
						 # Only during war with target
						 modifier = { 
						     has_war_with = PREV
							 add = 12
						 }
						 # Extra priority vs enemies with doctrine advantage
						 modifier = {
						     has_war_with = PREV
							 PREV = { has_army_maneuver_level > 1 }
							 add = 8
						 }
                 }
        }
		
		# Jam Radar - Useful during war (especially air superiority)
        Jam_Radar_click = {
               weight = 15
                 ai_will_do = {
                         factor = 0
						 # Only during war with target
						 modifier = { 
						     has_war_with = PREV
							 add = 10
						 }
						 # Extra priority vs air powers
						 modifier = {
						     has_war_with = PREV
							 PREV = { has_deployed_air_force_size = { size > 500 } }
							 add = 8
						 }
                 }
        } 	
		
		# Support Resistance - Only if enemy is occupying your states
        Support_Resistance_click = {
               weight = 12
                 ai_will_do = {
                         factor = 0
						 # Only if target occupies ROOT's core states
						 modifier = { 
						     PREV = {
							     any_owned_state = {
								     is_core_of = ROOT
									 NOT = { is_core_of = PREV }
								 }
							 }
							 add = 15
						 }
                 }
        }	
		
		# Sabotage Recruitment - Moderate priority during war
        Sabotage_Recruitment_click = {
               weight = 12
                 ai_will_do = {
                         factor = 0
						 modifier = { 
						     has_war_with = PREV
							 add = 8
						 }
                 }
        }  
		
		# Poison Food - Rare, extreme measure
        Poison_Food_click = {
               weight = 5
                 ai_will_do = {
                         factor = 0
						 # Only when enemy is nearly defeated
						 modifier = { 
						     has_war_with = PREV
							 PREV = { surrender_progress > 0.3 }
							 add = 6
						 }
                 }
        }	

        # === PEACETIME/PREPARATION SABOTAGE ===
		
		# Disrupt Civilian Industry - Preparation for war
        Disrupt_Civilian_click = {
               weight = 10
                 ai_will_do = {
                         factor = 0
						 # High priority during peace with hostile nations
						 modifier = {
						     has_war = no
							 check_variable = { ROOT.opinion@PREV < -25 }
							 add = 8
						 }
						 # Low priority during war
						 modifier = { 
						     has_war_with = PREV
							 add = 5
						 }
                 }
        }        
		
		# Disrupt Military Industry - Preparation for war
        Disrupt_Military_click = {
               weight = 10
                 ai_will_do = {
                         factor = 0
						 # High priority during peace vs military powers
						 modifier = {
						     has_war = no
							 check_variable = { ROOT.opinion@PREV < -25 }
							 PREV = { num_of_military_factories > 20 }
							 add = 9
						 }
						 # Lower priority during war
						 modifier = { 
						     has_war_with = PREV
							 add = 6
						 }
                 }
        } 
		
		# Sabotage Production - General disruption
        Sabotage_Production_click = {
               weight = 10
                 ai_will_do = {
                         factor = 0
						 # Peacetime preparation
						 modifier = {
						     has_war = no
							 check_variable = { ROOT.opinion@PREV < -25 }
							 add = 7
						 }
						 # Lower priority during war
						 modifier = { 
						     has_war_with = PREV
							 add = 5
						 }
                 }
        } 
		
		# Sabotage Extraction - Target resource-rich enemies
        Sabotage_Extraction_click = {
               weight = 10
                 ai_will_do = {
                         factor = 0
						 # Peacetime preparation vs resource-rich targets
						 modifier = {
						     has_war = no
							 check_variable = { ROOT.opinion@PREV < -25 }
							 PREV = { steel > 50 }
							 add = 8
						 }
						 # Lower priority during war
						 modifier = { 
						     has_war_with = PREV
							 add = 5
						 }
                 }
        }  						  
		
		# Support Pacifists - ONLY during peace (preparation)
        Support_Pacifists_click = {
               weight = 8
                 ai_will_do = {
                         factor = 0
						 # Only during peacetime vs hostile nations
						 modifier = {
						     has_war = no
							 check_variable = { ROOT.opinion@PREV < -50 }
							 ROOT = { has_war = no }
							 PREV = { has_war = no }
							 add = 10
						 }
                 }
        }		

        # Sabotage Research - Long-term disadvantage
        Sabotage_Research_click = {
               weight = 8
                 ai_will_do = {
                         factor = 0
						 # Target major powers and tech leaders
						 modifier = {
						     check_variable = { ROOT.opinion@PREV < -25 }
							 PREV = { is_major = yes }
							 add = 7
						 }
                 }
        }	
		
		# Sow Discontent - Peacetime preparation
        Sow_Discontent_click = {
               weight = 8
                 ai_will_do = {
                         factor = 0
						 # Only during peacetime vs hostile nations
						 modifier = {
						     has_war = no
							 check_variable = { ROOT.opinion@PREV < -50 }
							 add = 8
						 }
                 }
        }		

					  
		
			}
			 
			 
		
		
		}

	
}