scripted_gui = {
	
	
	open_weapon_trade_window = {	###### Кнопка на экране!!
			context_type = player_context		#player_context
#			parent_window_token = top_bar	#удалить чуть что
			parent_window_token = decision_tab
			window_name = "open_weapon_trade_window"		
			visible = {
#				is_ai = no			
			}
			effects = {
				open_weapon_ai_trade_button_click = {		## КНОПОЧКА ЧИСТО НА ИИ, чтобы без этих всяких ваших видимостей гуи и прочегго			
					if = {
						limit = {
							OR = {
								is_major = yes
								has_country_flag = ar_we_can_trade_focus_flag	# Даётся по фокусу
							}
							NOT = {
								has_country_flag = ar_weapon_seller_country_flag
								has_idea = closed_economy								
							}	
							check_variable = { ar_weap_deneg_var > 99 }	# это цена чтобы стать торгашем											
							is_subject = no							
							has_civil_war = no
						}
						random_list = {
							20 = {
								add_to_variable = { ar_weap_deneg_var = -100 }
								set_country_flag = ar_weapon_seller_country_flag
							}
							80 ={
								
							}
						}	
					}
					random_list = {
						10 = {
							modifier = {
								factor = 0
								has_political_power < 160	# 80
								check_variable = { ar_weap_deneg_var > 600 }
							}							
							ar_ai_buy_ibni_kostyl = yes
						}
						10 = {
							modifier = {
								factor = 0
								check_variable = { ar_weap_deneg_var < 300 }
								has_equipment = {
									infantry_equipment > 500
								}
							}
							if = {
								limit = {
									check_variable = { ar_weap_deneg_var > 299 }
								}
								log = "([Root.GetTag]): AI tries to buy weapon...( [?ar_weap_deneg_var] )"
								ar_ai_buy_weapon_kostyl = yes
							}							
						}						
						10 = {		# Буст для политки
							modifier = {
								factor = 0
								has_stability > 0.4
								check_variable = { ar_weap_deneg_var < 499 }	# это цена на идею буста стабки
								NOT = {
									has_idea = ar_weapon_market_idea_politpropoganda_boost
									has_idea = ar_weapon_market_idea_politpropoganda_boost_2
								}
							}
							log = "([Root.GetTag]): AI get politpropoganda_boost...( [?ar_weap_deneg_var] )"
							if = {
								limit = {
									check_variable = { ar_weap_deneg_var > 499 }
								}
								add_to_variable = { ar_weap_deneg_var = -500 }
								ar_add_boost_2_button = yes
							}							
						}
						70 = {
#							log = "([Root.GetTag]): nothing..."
							clr_country_flag = weapon_trade_open_country_flag
						}
					}					
				}				
				
				open_weapon_trade_window_button_click = {	# на массив есть еще ежедневная чекалка в он экшн!
					if = {
						limit = {
							NOT = {
								has_country_flag = weapon_trade_open_country_flag	
							}
						}
						set_country_flag = weapon_trade_open_country_flag
						clear_array = ROOT.ar_weapon_seller_array	# очистить массив чтобы избежать дублирования
						every_other_country = { # список стран-продавцов						
							limit = {
								has_country_flag = ar_weapon_seller_country_flag		
								exists = yes
								is_subject = no
								has_civil_war = no
								NOT = {
									has_war_with = ROOT
								}
							}
							add_to_array = { ROOT.ar_weapon_seller_array = THIS }
						}
					}
					else = {
						clr_country_flag = weapon_trade_open_country_flag
					}						
				}
				###
				open_kosmos_window_button_click = {
					if = {
						limit = {
							NOT = {
								has_country_flag = kosmos_window_open_country_flag	
							}
						}
						set_country_flag = kosmos_window_open_country_flag
						kosmo_obnovit_massiv = yes
					}
					else = {
						clr_country_flag = kosmos_window_open_country_flag
					}
				}
				ai_effect_kosmos_button_click = {	## КНОПОЧКА ЧИСТО НА ИИ, чтобы без этих всяких ваших видимостей гуи и прочегго
					ar_ai_scripted_effect_kosmos = yes
				}
			}
			triggers = {
				open_weapon_ai_trade_button_visible = {
					is_ai = yes
				}
				open_kosmos_window_button_click_enabled = {
					has_global_flag = pervy_sputnik_v_kosmose					
				}
				ai_effect_kosmos_button_visible = {
					is_ai = yes
				}
			}
			ai_enabled = {
				always = yes
			}
			ai_test_interval = 650	# инетрвал проверки в часах	# 320
			ai_test_variance = 0.3
			ai_check = {
				is_subject = no
			}
			ai_max_weight_taken_per_test = 1	# максимальное количество действий, которые ИИ будет выполнять.
			ai_weights = {
				open_weapon_ai_trade_button_click = {
					ai_will_do = {
						factor = 1
						# modifier = {
							# add = 5						
							# NOT = {
								# has_country_flag = weapon_trade_open_country_flag	
							# }
						# }					
					}	
				}
				ai_effect_kosmos_button_click = {
					ai_will_do = {
						factor = 0
						modifier = {
							add = 5
							has_country_flag = kosmos_roketa_uletela_flag
						}
					}	
				}
			}	
	}		



	weapon_trade_container = {
		context_type = player_context		
#		context_type = technology_tab
		window_name = "weapon_trade_container"		
		visible = {			
#			OR = {
				has_country_flag = 	weapon_trade_open_country_flag	
#				is_ai = yes
#			}			
		}			
		dynamic_lists = {
			spisok_prodavtsov_orujiya_grid = {	# список продавцов 
				array = ar_weapon_seller_array
				change_scope = yes
				entry_container = prodavtsy_spisok_tag_entry
			}
		}
			
		effects = {
			weapon_trade_button_close_click = {	#выход  _click в конце
				clr_country_flag = 	weapon_trade_open_country_flag
			}
			weapon_trade_weareseller_button_click = {	# кнопка "стать\перестать торгашем"
				if = {
					limit = {
						NOT = {
							has_country_flag = ar_weapon_seller_country_flag	
						}
					}
					add_to_variable = { ar_weap_deneg_var = -100 }	# Цена за становление продавцом
					set_country_flag = ar_weapon_seller_country_flag	
				}
				else = {
					clr_country_flag = ar_weapon_seller_country_flag
				}
				every_other_country = {	# проброс на обновление массива для всех стран, у которых открыто окно торговли (срабатывает всегда)
					limit = {
						has_country_flag = ar_weapon_seller_country_flag
					}
					clear_array = ROOT.ar_weapon_seller_array	# очистить массив чтобы избежать дублирования
					every_other_country = { # список стран-продавцов						
						limit = {
							has_country_flag = ar_weapon_seller_country_flag		
							exists = yes
							is_subject = no
							has_civil_war = no
							NOT = {
								has_war_with = ROOT
							}
						}
						add_to_array = { ROOT.ar_weapon_seller_array = THIS }
					}
				}
			}
			ar_weap_ubavit_denejki_button_click = {	# убавить соточку	
				add_to_variable = { ar_weap_deneg_var = -100 } 
#				set_temp_variable = { ibni_cost_2_temp = global.ibni_kurs_prodaja_var }
#				multiply_temp_variable = { ibni_cost_2_temp = 0.8 }
				add_political_power = global.ibni_kurs_prodaja_var
			}
			ar_weap_pribavit_denejki_button_click = {	# прибавить соточку
				add_to_variable = { ar_weap_deneg_var = 100 } 
				set_temp_variable = { ibni_cost_temp = global.ibni_kurs_var }
				multiply_temp_variable = { ibni_cost_temp = -1 }
				add_political_power = ibni_cost_temp
				if = {
					limit = { has_government = communism }
					ar_omni_weapontrader_fond_ibni = yes
				}
##				log = "[GetDateText]: ([Root.GetTag]): add +100 ibni ( [?ar_weap_deneg_var] )"
			}				
#			ar_buy_test_button_click = {	# тестовая отправка эвента
#				PREV = {
#					country_event = { id = ar_weapon_market.1 }		# еее
#				}
#			}
			ar_buy_inf_weapon_button_click = {	# запрос на пехотное вооружение
				ROOT = {				
					add_to_variable = { ar_weap_deneg_var = -300 }					
				}
				PREV = {
					country_event = { id = ar_weapon_market.3 }						
				}
			}
			ar_buy_support_button_click = {	# запрос на снарягу
				ROOT = {				
					add_to_variable = { ar_weap_deneg_var = -200 }
				}
				PREV = {
					country_event = { id = ar_weapon_market.16 }
				}
			}
			ar_buy_arta_button_click = {	# открыть меню на запрос арты что есть у страны
				ROOT = {
					add_to_variable = { ar_weap_deneg_var = -300 }
				}	
				PREV = {
					country_event = { id = ar_weapon_market.8 }
				}
			}
			ar_buy_moto_button_click = {	# открыть меню на запрос мототехники что есть у страны
				ROOT = {
					add_to_variable = { ar_weap_deneg_var = -300 }
				}	
				PREV = {
					country_event = { id = ar_weapon_market.18 }
				}
			}
			ar_buy_tanki_button_click = {	# открыть меню на запрос ТАНКОВ что есть у страны
				ROOT = {
					add_to_variable = { ar_weap_deneg_var = -1000 }
				}	
				PREV = {
					country_event = { id = ar_weapon_market.26 }
				}
			}
			ar_buy_samolety_button_click = {
				ROOT = {
					add_to_variable = { ar_weap_deneg_var = -500 }
				}
				PREV = {
					country_event = { id = ar_weapon_market.34 }
				}
			}
#			weapon_trade_ai_buy_button_click = {
#				ar_ai_buy_weapon_kostyl = yes
#				log = "[GetDateText]: ([Root.GetTag]): ai buy..."
#			}
#			weapon_trade_ai_ibni_button_click = {
#				ar_ai_buy_ibni_kostyl = yes
#				log = "[GetDateText]: ([Root.GetTag]): get ibni...."
#			}
			ar_buy_boost_1_button_click = {	 # Промка
				add_to_variable = { ar_weap_deneg_var = -400 }
				ar_add_boost_1_button = yes				
			}
			ar_buy_boost_2_button_click = {	 # стабка
				add_to_variable = { ar_weap_deneg_var = -500 }
				ar_add_boost_2_button = yes				
			}
			ar_buy_boost_3_button_click = {	 # продать завод
				ar_add_boost_3_button = yes					
			}
			ar_buy_boost_4_button_click = {	 # 
				add_to_variable = { ar_weap_deneg_var = -400 }						
			}
			ar_buy_boost_5_button_click = {	 # наука
				add_to_variable = { ar_weap_deneg_var = -400 }
				ar_add_boost_5_button = yes				
			}
			ar_buy_boost_6_button_click = {	 # варсапп
				add_to_variable = { ar_weap_deneg_var = -400 }	
				ar_add_boost_6_button = yes	
			}
			ar_buy_boost_7_button_click = {	 # продать пушки на чёрный рынок
				ar_add_boost_7_button = yes						
			}
			ar_buy_boost_8_button_click = {	 # 
				add_to_variable = { ar_weap_deneg_var = -300 }						
			}
		}
###################################################################			
		triggers = {
			weapon_trade_weareseller_button_click_enabled = {	# доступность кнопки "стать\перестать торгашем"
				OR = {
					has_country_flag = ar_weapon_seller_country_flag
					AND = {		# дать больше условий через AND
						check_variable = { ar_weap_deneg_var > 99 }	# это цена чтобы стать торгашем
						OR = {
							is_major = yes
							has_country_flag = ar_we_can_trade_focus_flag
						}	
						is_subject = no
						has_civil_war = no
						NOT = {
							has_idea = closed_economy
						}
					}	
				}
			}
			ar_weap_ubavit_denejki_button_click_enabled = {		# убавить соточку	  -100 	
				check_variable = { ar_weap_deneg_var > 0 }
			}
			ar_weap_pribavit_denejki_button_click_enabled = {	# прибавить соточку   +100
				check_variable = { ar_weap_deneg_var < 50000 }	# лимит 10000 ибни, нефиг много хранить))0
				check_variable = { global.ibni_kurs_var < ROOT.political_power }				
			}	
			ar_buy_inf_weapon_button_click_enabled = {	# доступность кнопки пехотки
				ROOT = {
					check_variable = { ar_weap_deneg_var > 299 }
					NOT = {
						has_idea = closed_economy
					}
				}	
				PREV = {
					has_equipment = {	# есть что продать
						infantry_equipment > 300
					}
				}
			}	
			ar_buy_support_button_click_enabled = {	# доступность кнопки снаряги
				ROOT = {
					check_variable = { ar_weap_deneg_var > 199 }
					NOT = {
						has_idea = closed_economy
					}
				}	
				PREV = {
					has_equipment = {	# есть что продать
						support_equipment > 200
					}
				}
			}
			ar_buy_arta_button_click_enabled = {	# доступность кнопки списка арты
				ROOT = {
					check_variable = { ar_weap_deneg_var > 299 }
					NOT = {
						has_idea = closed_economy
					}
				}
				PREV = {
					OR = {
						has_equipment = {					
							artillery_equipment > 100				
						}
						has_equipment = {				
							anti_air_equipment > 100				
						}
						has_equipment = {				
							anti_tank_equipment > 100				
						}
					}
				}				
			}
			ar_buy_moto_button_click_enabled = {	# доступность кнопки списка мототехники
				ROOT = {
					check_variable = { ar_weap_deneg_var > 299 }
					NOT = {
						has_idea = closed_economy
					}
				}	
				PREV = {
					OR = {
						has_equipment = {				
							motorized_equipment > 100					
						}
						has_equipment = {				
							mechanized_equipment > 50					
						}
						has_equipment = {				
							armored_car_equipment > 40				
						}	
						has_equipment = {				
							train_equipment > 10				
						}
					}	
				}
			}
			ar_buy_tanki_button_click_enabled = {	# доступность кнопки списка танков
				ROOT = {
					check_variable = { ar_weap_deneg_var > 999 }
					NOT = {
						has_idea = closed_economy
					}
				}
				PREV = {
					OR = {
						has_equipment = {				
							light_tank_chassis > 100					
						}
						has_equipment = {				
							medium_tank_chassis > 50					
						}
						has_equipment = {				
							heavy_tank_chassis > 40				
						}
					}
				}
			}
			ar_buy_samolety_button_click_enabled = {	# доступность кнопки списка САМОЛЕТОВ
				ROOT = {
					check_variable = { ar_weap_deneg_var > 499 }
					NOT = {
						has_idea = closed_economy
					}
				}
				PREV = {
					OR = {
						has_equipment = {			
							small_plane_airframe > 70					
						}	
						has_equipment = {				
							medium_plane_airframe > 55					
						}
						has_equipment = {				
							large_plane_airframe > 20					
						}	
					}
				}
			}
			##	
			ar_buy_boost_1_button_click_enabled = {	# промка
				ROOT = {
					check_variable = { ar_weap_deneg_var > 399 }	
					NOT = {
						has_idea = ar_weapon_market_idea_prom_boost
						has_idea = ar_weapon_market_idea_prom_boost_2
					}	
				}
			}
			ar_buy_boost_2_button_click_enabled = {	#	стабка	
				check_variable = { ar_weap_deneg_var > 499 }	
				NOT = {	
					has_idea = ar_weapon_market_idea_politpropoganda_boost	
					has_idea = ar_weapon_market_idea_politpropoganda_boost_2	
				}					
			}
			ar_buy_boost_3_button_click_enabled = {	#	продать завод	
				NOT = { has_government = communism }
				any_owned_state = {
					industrial_complex > 0
				}	
			}
			ar_buy_boost_4_button_visible = {	###
				is_ai = yes
			}
			ar_buy_boost_4_button_click_enabled = {	#		
				check_variable = { ar_weap_deneg_var > 399 }	
				NOT = {	
					has_idea = ar_weapon_market_idea_prom_boost
					has_idea = ar_weapon_market_idea_prom_boost
				}					
			}
			ar_buy_boost_5_button_click_enabled = {	# наука	
				check_variable = { ar_weap_deneg_var > 399 }	
				NOT = {	
					has_idea = ar_weapon_market_idea_nauka_boost
					has_idea = ar_weapon_market_idea_nauka_boost_2
				}				
			}
			ar_buy_boost_6_button_click_enabled = {	# варсапп
				check_variable = { ar_weap_deneg_var > 399 }	
				NOT = {	
					has_idea = ar_weapon_market_idea_wapsupp_boost
					has_idea = ar_weapon_market_idea_wapsupp_boost_2
				}				
			}
			ar_buy_boost_7_button_click_enabled = {	#продать пушки на черный рынок	
				has_government = fascism
				has_equipment = {
					infantry_equipment > 1000
				}
			}
			ar_buy_boost_8_button_visible = {	###
				is_ai = yes
			}
			ar_buy_boost_8_button_click_enabled = {	#		
				check_variable = { ar_weap_deneg_var > 299 }	
				NOT = {	
					has_idea = ar_weapon_market_idea_prom_boost
					has_idea = ar_weapon_market_idea_prom_boost
				}				
			}
			##
#			weapon_trade_ai_buy_button_visible = {
#				is_ai = yes
#			}
#			weapon_trade_ai_buy_button_click_enabled = {
#				check_variable = { ar_weap_deneg_var > 299 }
#				NOT = {
#					has_idea = closed_economy
#				}
#				has_equipment = {
#					infantry_equipment < 200
#				}
#			}
#			weapon_trade_ai_ibni_button_visible = {
#				is_ai = yes
#			}
#			weapon_trade_ai_ibni_button_click_enabled = {
#				check_variable = { ar_weap_deneg_var < 50000 }	# лимит 10000 ибни, нефиг много хранить))0
#				check_variable = { global.ibni_kurs_var < ROOT.political_power }	
#			}
			#####
			
		}
			
		properties = {				
			flag_2 = {
				image = "[This.GetFlag]"
			}
		}


		####
		ai_enabled = {
			always = yes
		}
		ai_test_interval = 1800	# инетрвал проверки в часах	# 320
		ai_test_variance = 0.8
		ai_check = {
			is_subject = no
		}		
#		ai_test_scopes = test_self_country	# Для player_context  ai_test_scopes  вроде не требуется,
		ai_max_weight_taken_per_test = 1	# максимальное количество действий, которые ИИ будет выполнять.
		ai_weights = {
#			weapon_trade_weareseller_button_click = {
#				ai_will_do = {
#					factor = 0
#					modifier = {
#						add = 50
#						check_variable = { ar_weap_deneg_var > 99 }	# это цена чтобы стать торгашем
#						is_major = yes						
#						is_subject = no
#						NOT = {
#							has_idea = closed_economy
#							has_country_flag = ar_weapon_seller_country_flag
#						}
#						has_civil_war = no						
#					}
#				}
#			}
#			weapon_trade_ai_ibni_button_click = {
#				ai_will_do = {
#					factor = 0
#					modifier = {
#						add = 5						
#						has_political_power > 100
#					}
#					modifier = {
#						add = 5
#						has_equipment = {
#							infantry_equipment < 250
#						}
#					}
#					modifier = {
#						factor = 0						
#						check_variable = { ar_weap_deneg_var > 600 }						
#					}
#				}	
#			}			
#			weapon_trade_ai_buy_button_click = {
#				ai_will_do = {
#					factor = 0
#					modifier = {
#						add = 1
#						any_country = {
#							has_country_flag = ar_weapon_seller_country_flag		
#							exists = yes
#							is_subject = no
#							has_civil_war = no
#							NOT = {
#								has_war_with = ROOT
#							}
#							has_equipment = {	# есть что продать
#								infantry_equipment > 300
#							}
#						}
#						has_equipment = {
#							infantry_equipment < 250
#						}
#					}	
#				}
#			}
			weapon_trade_button_close_click = {
				ai_will_do = {
					factor = 0
					modifier = {
						add = 1						
						has_country_flag = weapon_trade_open_country_flag
					}					
				}	
			}
		}			
	}
}