-- Разное от АМК
local nrg,med,cnt
local in_hide = false
local sound_obj_right, sound_obj_left, snd_volume, snd_obj_eq
local sync_done = false
local dynlasthour

local weather_types = {
	l01_escape = 1,
	l02_garbage = 1,
	l03_agroprom = 1,
	l03u_agr_underground = 1,
	l04_darkvalley = 1,
	l04u_labx18 = 1,
	l05_bar = 1,
	l06_rostok = 1,
	l07_military = 1,
	l08_yantar = 1,
	l08u_brainlab = 1,
	l10_radar = 1,
	l10u_bunker = 1,
	l11_pripyat = 1,
	l12_stancia = 1,
	l12_stancia_2 = 1,
	l12u_control_monolith = 1,
	l12u_sarcofag = 1
}

-- Квест Ночная Звезда
function spawn_star(actor,npc,p1,p2)
	local points = {
		{position={x=-24.2727108001709,y=-12.1660995483398,z=-100.200202941895},gv=0,lv=73868},
		{position={x=159.56,y=4.72,z=88.60},gv=155,lv=463808},
		{position={x=-4.11,y=2.90,z=108.09},gv=85,lv=272619}
	}
    local a = table.random(points)
    local obj = create("amk_af_night_star", xyz(a.position.x,a.position.y,a.position.z), a.lv, a.gv)

	local m_where = news_main.get_point_description("l01_escape", vector():set(a.position.x,a.position.y,a.position.z))
	db.actor:give_talk_message(m_where.." "..translate("spawn_star_0"), "ui\\ui_iconstotal", Frect():set(0,0,10,10), "simple_answer_item")
end

-- Эта функция вызывается первой. Онлайновые объекты недоступны. db.actor недоступен.
function on_game_start()
	math.randomseed(screen:time_global())
end

function first_run()
	if not has_info("x_first_run") then
		amk.spawn_item("amk_zapiska",xyz(-126.96,-28.41,-379.12),27,125181)
		amk.spawn_item("amk_zapiska",xyz(21.6,-3.94,-18.28),1140,5991)
		create("amk_zapiska",xyz(124.86881256104,31.754182815552,-13.352614402771),7186,1543)
		sak.add_new_lcitem()

		spawn_military_btr()
		spawn_fuel()
		meceniy_work.main()

		-- Удаляем недоступные с НИ level_changer-ы
		release(story_object(417))
		release(story_object(6002))
		release(story_object(9100))
		release(story_object(9101))
		release(story_object(9102))
		release(story_object(9103))
		release(story_object(9104))
		release(story_object(9105))
		release(story_object(9106))
		release(story_object(9107))
		release(story_object(9108))
		release(story_object(9109))
		release(story_object(9110))
		release(story_object(9111))
		release(story_object(1008))
		release(story_object(592))
		release(story_object(97101))
		release(story_object(11504))
		release(story_object(11505))
		release(story_object(11502))
		release(story_object(11503))
		release(story_object(97071))
		release(story_object(97081))
		release(story_object(97021))
		release(story_object(11512))
		release(story_object(11515))
		release(story_object(11511))
		release(story_object(97091))
		release(story_object(97092))
		release(story_object(97093))
		release(story_object(97100))
		release(story_object(11514))
		release(story_object(11513))
		release(story_object(12506))
		release(story_object(11510))
		release(story_object(97094))
		release(story_object(97095))
		release(story_object(97097))
		release(story_object(97098))
		release(story_object(14002))
		release(story_object(11529))
		release(story_object(11531))
		release(story_object(97103))
		release(story_object(97104))
		release(story_object(97105))
		release(story_object(97001))
		release(story_object(97106))
		release(story_object(97102))
		release(story_object(11521))
		release(story_object(97096))
		release(story_object(97107))
		release(story_object(97108))
		release(story_object(97109))
		release(story_object(97110))
		release(story_object(97111))
		release(story_object(97112))
		release(story_object(97113))
		release(story_object(97114))
		release(story_object(608))
		release(story_object(594))
		release(story_object(30184))
		release(story_object(453))
		release(story_object(900076))
		release(story_object(900077))
		release(story_object(900082))
		release(story_object(900083))
		release(story_object(900085))
		release(story_object(900086))
		release(story_object(900087))
		release(story_object(900089))
		release(story_object(900090))
		release(story_object(900091))
		release(story_object(900092))
		release(story_object(91))
		release(story_object(194))
		release(story_object(97117))
		release(story_object(97118))
		release(story_object(196))
		release(story_object(11506))
		release(story_object(22048))

		_G.ID_Cleaner:on_new_game()

		give_info("x_first_run")
	end

	-- фикс пропадания таймеров
	if not Timer:has("show_news") then
		Timer:start_game("show_news",0,0,10,"amk_mod.show_news()")
	end
end

function blowout_hours() 
	local hours = level.get_time_hours()
	if hours > 5 and hours < 21 then return "d"
	elseif hours > 22 or hours < 4 then return "n"
	end
	return "m"
end

function check_spawn()
	amk_anoms.init()
	news_main.init()
	amk_offline_alife.init()

	--level_changers section
	local lname = level.name()
	local sname = get_value("level_on_save","")

	if lname ~= sname and sname ~= "" then
		u3_utils.copy_autosave(sname, lname)
	end

	local blowphase=get_value("blowout",0)

	if blowphase>0 and blowphase<=6 then
		local blow_type=blowout_type()
		local t_w=blowout_hours().."_blow"
		level.set_weather(t_w,true)
		if Timer:has("blowout") then
			Timer:remove("blowout")
			if blow_type==2 then 
				Timer:start_game("blowout",0,0,0,3)
			else 
				Timer:start_game("blowout",0,0,0,blowphase-1)
			end	
		end
	end

	if db.actor and not has_info("game_over") then
		local flame = db.actor:object("wpn_flame")
		if flame then
			db.actor:iterate_inventory(
				function(dummy,item)
					if item:section()=="wpn_flame" then
						release(server_object(item:id()))
					end
				end
				,db.actor)
		end
	end
	restore_sun()
end

function restore_sun()
	set_value("level_on_save", level.name())
    if not Timer:has("blow_shift") then
		start_blow_timer()
	end
end

-- Количества новостей в каждом разделе. При добавлении новостей увеличивать здесь значения.
local sms_name = 177
local sms_surname = 1322
local sms_pogon = 294
local sms_dolg = 31
local sms_freedom = 22
local sms_modders = 345
local sms_modders2 = 97
local sms_uniq = 278
local sms_uniq2 = 136

-- Динамические новости
function show_news()
	news_main.on_news()

	if not _G.Dream:is_sleep_active() then
		-- Вероятности поставлены по примерному количеству СМС в каждом разделе
		if math.random() > 0.91 then
			if math.random() > 0.40 then
				local dolg_news = translate("sms_dolg_"..math.random(sms_dolg))
				db.actor:give_game_news(dolg_news, "ui\\ui_iconsTotal", Frect():set(498,141,83,47), 0, news_len(dolg_news)*1000)
				say([[device\pda\pda_tip]])
			else
				local freedom_news = translate("sms_freedom_"..math.random(sms_freedom))
				db.actor:give_game_news(freedom_news, "ui\\ui_iconsTotal", Frect():set(498,94,83,47), 0, news_len(freedom_news)*1000)
				say([[device\pda\pda_tip]])
			end
		else
			if math.random() > 0.52 then
				local uniq
				if ui_mm_opt_creator.get_bool_user_param("new_sms",true) and math.random() < 0.38 then
					uniq = translate("sms_uniq2_"..math.random(sms_uniq2))
				else
					uniq = translate("sms_uniq_"..math.random(sms_uniq))
				end
				local name, sname = amk_mod.get_news_sender()
				amk.send_tip(uniq,name.." "..sname,nil,news_len(uniq),"uniq")
			else
				local mod_news
				if ui_mm_opt_creator.get_bool_user_param("new_sms",true) and math.random() < 1 then
					local rnd=math.random(sms_modders2)
					mod_news = translate("sms_modders2_"..rnd)
					local need_format={[3]=true,[11]=true,[35]=true,[85]=true,[87]=true,[91]=true}
					if need_format[rnd] then
						mod_news=string.extformat(mod_news,user_name())
					elseif rnd==93 then
						mod_news=string.extformat(mod_news,translate(level.name()))
					end
				else
					mod_news = translate("sms_modders_"..math.random(sms_modders))
				end
				--mod_news=string.extformat(mod_news,user_name())
				-- попробуем подобрать иконку
				local x,y, pos
				pos = string.find(mod_news,"[default]",1,true)
				if pos then
					x,y = news_manager.get_sender_icon(string.sub(mod_news,1,pos-5)..":")
				else
					x,y = 498,47
				end

				db.actor:give_game_news(mod_news, "ui\\ui_iconsTotal", Frect():set(x,y,83,47), 0, news_len(mod_news)*1000)
				say([[device\pda\pda_tip]])
			end
		end
	end
	Timer:start_game("show_news",0,0,math.random(50,70),"amk_mod.show_news()")
end

function news_len(news)
	local length = string.len(news)/12
	if length > 45 then
		length = 45
	end
	return length
end

function get_news_sender()
	local name, sname
	if math.random() > 0.20 then
		name = translate("sms_name_"..math.random(sms_name))
		sname = translate("sms_surname_"..math.random(sms_surname))
	else
		name = translate("sms_pogon_"..math.random(sms_pogon))
		sname = ""
	end

	return name, sname
end

-- Фикс Радара
function check_radar_off()
	if (level.name() == "l10_radar") then
		if not has_info("bar_deactivate_radar_done") then
			local pos = db.actor:position()
			if pos.z > 65 and pos.x > 350 and pos.x < 410 then
				if get_value("radar_fix",0) == 0 then
					level.add_pp_effector("fire_hit.ppe", 1523, true)
					level.set_pp_effector_factor(1523, 0.5)
					set_value("radar_fix",1)
					timer("radar_fix",5,"amk_mod.radar_fix()")
				end
			end
		end
	end
end

function radar_fix()
	level.remove_pp_effector(1523)
	local pos = db.actor:position()
	if pos.z > 65 and pos.x > 350 and pos.x < 410 then
		db.actor:kill(db.actor)
	end
	del_value("radar_fix")
end

-- Преобразование предметов
local tramsform_items = {
	["item1"] = {info = "info_portion_1", result = {"item_out_1", "item_out_2", "item_out_3", "item_out_4"}},
	["item2"] = {info = "info_portion_2", result = {"item_out_2"}},
	["kaktus_izomorf"] = {info = "kaktus_izo_resept", result = {"bloodsucker_effector", "af_spirit_4", "af_arhara_globus", "mutant_krovosos_cocoon"}},
	["izom_globus"] = {info = "kaktus_izo_resept", result = {"bomba_mina_n", "af_babka_3", "af_spirit_4", "device_teleport"}},
	["psevdokristall"] = {info = "kaktus_izo_resept", result = {"af_spirit_3", "af_babka_2", "wpn_m4", "device_teleport"}},
	["izomorf_plastilin"] = {info = "molniya_plastilin_ok_start", result = {"korobka_sigars", "ammo_5.45x39_izomorf", "ammo_7.62x54_izomorf", "ammo_zhekan_izomorf"}},
	["korobka_sigars"] = {info = "kluch_poluchen", result = {"9x39_izomorf", "ammo_9x39_izomorf", "ammo_9x39_izomorf", "ammo_9x39_izomorf"}}
}

-- проверка на упавший предмет/артефакт
function check_for_item_drop(obj)
	local obj_sect = obj:section()

	if tramsform_items[obj_sect] and has_info(tramsform_items[obj_sect].info) then
		local lv = obj:level_vertex_id()
		local gv = obj:game_vertex_id()
		if gv == 65535 then gv = db.actor:game_vertex_id() end
		if gv == 65535 then return end -- похоже, что рядом нету вертекса

		-- предмет подходит - отправляем его на экспертизу
		-- узнаем не съели ли его или вvложили в нvчку
		local tbl	= {}
		tbl.obj_id	= obj:id()
		tbl.lv		= lv
		tbl.gv		= gv
		timer("timer_drop_obj_transform", 0.2, tbl)
	end
end

function item_transform(obj_id, lv, gv)
    local obj = level_object(obj_id)
    if obj then
        level.add_pp_effector("teleport.ppe", 1524, false)
        local result = tramsform_items[obj:section()].result
        local position = obj:position()
        for i = 1, #result do
            amk.spawn_item(result[i], position, gv, lv)
        end
        amk.remove_item(obj)
    end
end

-- Преобразование артефактов
local cur_level=nil
local havegoodart=false

-- Список компонентов, желательно добавлять в алфавитном порядке
local afs={
["af_ameba_mica"] = true,
["af_ameba_slime"] = true,
["af_ameba_slug"] = true,
["af_armor_1"] = true,
["af_armor_2"] = true,
["af_armor_3"] = true,
["af_armor_4"] = true,  --chessplayer
["af_babka_1"] = true,
["af_babka_2"] = true,
["af_babka_3"] = true,
["af_blood"] = true,
["af_buliz"] = true,
["af_caterpillar"] = true,  --chessplayer
["af_cristall"] = true,
["af_cristall_flower"] = true,
["af_cry_1"] = true,
["af_cry_2"] = true,
["af_dik_1"] = true,
["af_dik_2"] = true,
["af_dik_3"] = true,
["af_drops"] = true,
["af_dummy_battery"] = true,
["af_dummy_battery_red"] = true,
["af_dummy_dummy"] = true,
["af_dummy_glassbeads"] = true,
["af_dummy_pellicle"] = true,
["af_dummy_pellicle_red"] = true,
["af_dummy_spring"] = true,
["af_dummy_spring_red"] = true,
["af_electra_flash"] = true,
["af_electra_moonlight"] = true,
["af_electra_sparkler"] = true,
["af_fireball"] = true,
["af_fuzz_kolobok"] = true,
["af_gold_fish"] = true,
["af_gravi"] = true,
["af_kamen_udachy"] = true,
["af_kol_1"] = true,
["af_kol_2"] = true,
["af_kol_3"] = true,
["af_life_heart"] = true,
["af_medusa"] = true,
["af_mincer_meat"] = true,
["af_night_star"] = true,
["af_part_monolit2"] = true,
["af_power"] = true,
["af_power_1"] = true,
["af_power_2"] = true,
["af_pudd_1"] = true,
["af_pudd_2"] = true,
["af_pudd_3"] = true,
["af_rusty_kristall"] = true,
["af_rusty_sea-urchin"] = true,
["af_rusty_thorn"] = true,
["af_simbion"] = true,
["af_soul"] = true,
["af_spirit_1"] = true,
["af_spirit_2"] = true,
["af_spirit_3"] = true,
["af_vyvert"] = true,
["af_black_angel"]=true,
["af_arhara_globus"]=true,
["bandage"] = true,
["bezoar"] = true,
["bread"] = true,
["conserva"] = true,
["drug_booster"] = true,
["energy_drink"] = true,
["izomorf_kompas"] = true,
["kolba_pustay"] = true,
["kolba_siniy_poln"] = true,
["kolba_orand_poln"] = true,
["kolba_krasn_poln"]=true,
["kolbasa"] = true,
["mutant_crow"] = true,
["part_boar_leg"] = true,
["part_burer_red_hand"] = true,
["part_chimera_kogot"] = true,
["part_deathclaw_antler"] = true,
["part_digitis_biblio"] = true,
["part_dog_tail"] = true,
["part_face_tushkano"] = true,
["part_flesh_eye"] = true,
["part_fracture_hand"] = true,
["part_krovosos_jaw"] = true,
["part_krovosos_red_jaw"] = true,
["part_psevdodog_tail"] = true,
["part_psevdogigant_hand"] = true,
["part_rudiment_big"] = true,
["part_snork_leg"] = true,
["part_spleen_rat"] = true,
["spleen_rat_plague"] = true,
["part_tail_cat"] = true,
["part_tarakan"] = true,
["part_tarakan_strong"] = true,
["part_zombie_hand"] = true,
["part_plague_hand"] = true,
["part_zombie_teeth"] = true,
["red_mozg"] = true,
["snp_prime_maz"] = true,
["sweetness"] = true,
["vodka"] = true,
-- все эмбрионы нужные для варки
["mutant_boar_cocoon"] = true,
["mutant_burer_cocoon"] = true,
["mutant_cat_cocoon"] = true,
["mutant_chimera_cocoon"] = true,
["mutant_flesh_cocoon"] = true,
["mutant_gigant_cocoon"] = true,
["mutant_krovosos_cocoon"] = true,
["mutant_poltergeist_cocoon"] = true,
["mutant_psevdodog_cocoon"] = true,
["mutant_psydog_cocoon"] = true,
["mutant_snork_cocoon"] = true,
["mutant_zombie_cocoon"] = true,
-- emb
["mutant_rat_cocoon"] = true,
["mutant_tarakan_cocoon"] = true,
["mutant_tarakan2_cocoon"] = true,
["mutant_bloodsucker_cocoon"] = true,
["mutant_bloodsucker2_cocoon"] = true,
["mutant_deathclaw_cocoon"] = true,
["mutant_fracture_cocoon"] = true,
["mutant_bibliotekar_cocoon"] = true,
["mutant_mono_cocoon"] = true,
["mutant_babka_cocoon"] = true,
["mutant_ghost_cocoon"] = true,
["mutant_kachok_cocoon"] = true,
["mutant_big_cocoon"] = true,
["mutant_jumper_cocoon"] = true,
["mutant_electro_cocoon"] = true,
["mutant_x_ray_cocoon"] = true
}

-- проверка на упавший предмет/артефакт
function check_for_af_drop(obj)
	local obj_sect = obj:section()

	-- проверка не один ли это из компонентов
	if afs[obj_sect] == true then
		local anom_id,anom_pos,anom_radius,dist = amk_anoms.get_nearest_anomaly(obj)

		if anom_id and anom_radius - dist > -2 then
			local lv = level_object(anom_id):level_vertex_id()
			local gv = level_object(anom_id):game_vertex_id()
			if gv == 65535 then gv = obj:game_vertex_id() end
			if gv == 65535 then gv = db.actor:game_vertex_id() end
			if gv == 65535 then return end -- похоже, что рядом нету вертекса

			-- предмет подходит - отправляем его на экспертизу
			-- узнаем не съели ли его или выложили в нычку
			local tbl		= {}
			tbl.obj_id		= obj:id()
			tbl.anom_id		= anom_id
			tbl.anom_radius	= anom_radius
			tbl.lv			= lv
			tbl.gv			= gv
			timer("timer_drop_obj_varka", 0.2, tbl)
		end
	end
end

-- проверка: является ли компонентом для варки
-- параметр - название секции
function is_komponent(sec)
     return (afs[sec] ~= nil)
end

-- аномалия "узнаётся" по части названия!
-- komp - компоненты
-- удача v_udachi + вырождение в булыжник v_virogd <= 100 !!!
-- отторжение v_ottorg = 100 - (v_udachi + v_virogd) посему и не нужно прописывать в таблицу
-- cel - цель (может быть одновременно несколько целей)
-- info - инфопорция, которая будет выдана после L-L+=+Ј варки
-- virogd - во что вырождается (может быть одновременно несколько вырождений)
-- vremya = {дни, часы, минуты} - время варки/мутации
-- remove_anomaly - удалить ли аномалию (можно комбинировать вместе с варкой/мутацией)
-- not_for_mutator - рецепт никогда не попадёт в трансмутатор
local anom_recept_komp = {
	-- умолчание, если нет данных ближе к рецепту
	default = {
		cel = {},
		v_udachi = 80,
		v_virogd = 20,
		virogd = {["af_buliz"]=true},
		vremya = {0,0,1},
		remove_anomaly = false
	},

	anomalii = {
		["_zharka"] = {
			-- умолчание, если нет данных ближе к рецепту,
			-- которое может переопределяться в рецепте
			name = "\""..translate("task_foto_anomaly_1").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,1}
			},

			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалию без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["starik_zadanie_vzyt_done"] = {
					komp = {["mutant_boar_cocoon"]=true,["mutant_flesh_cocoon"]=true,["mutant_psevdodog_cocoon"]=true,["part_boar_leg"]=true},
					cel = {["mutant_kachok_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["voron_new_kvest_done"] = {
					komp = {["mutant_krovosos_cocoon"]=true,["mutant_burer_cocoon"]=true,["mutant_bloodsucker_cocoon"]=true,["part_deathclaw_antler"]=true},
					cel = {["mutant_bloodsucker2_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["info_artmod_electra_flash_zharka"] = {
					komp = {["af_medusa"]=true,["af_rusty_thorn"]=true,["af_vyvert"]=true,["vodka"]=true},
					cel = {["af_electra_flash"]=true}
				},
				["agr_krot_PDA_done"] = {
					komp = {["af_medusa"]=true,["af_blood"]=true,["kolbasa"]=true,["part_dog_tail"]=true},
					cel = {["af_ameba_slime"]=true}
				},
				["bar_dolg_petrenko_gaussgan_done"] = {
					komp = {["af_medusa"]=true,["af_blood"]=true,["bandage"]=true,["conserva"]=true},
					cel = {["af_gravi"]=true}
				},
				["mil_Svoboda_trader_plan_done"] = {
					komp = {["af_rusty_kristall"]=true,["af_vyvert"]=true,["af_electra_flash"]=true,["part_snork_leg"]=true},
					cel = {["af_night_star"]=true}
				},
				["bar_dolg_petrenko_electra_flash_done"] = {
					komp = {["af_gravi"]=true,["af_medusa"]=true,["af_electra_flash"]=true,["part_krovosos_jaw"]=true},
					cel = {["af_electra_moonlight"]=true}
				},
				["sak_reward_outfit_done"] = {
					komp = {["af_electra_flash"]=true,["af_ameba_mica"]=true,["vodka"]=true,["part_dog_tail"]=true},
					cel = {["af_dummy_battery"]=true}
				},
				["info_amk_recipt_soul_drops"] = {
					komp = {["af_soul"]=true},
					cel = {["af_spirit_1"]=true},
					vremya = {0,0,1}
				},
				["info_artmod_gusenica"] = {
					komp = {["bezoar"]=true,["spleen_rat_plague"]=true},
					cel = {["af_caterpillar"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["info_artmod_probabka_burera"] = {
					komp = {["af_babka_3"]=true},
					cel = {["af_babka_4"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["kostya_journal_done"] = {
					komp = {["af_spirit_1"]=true},
					cel = {["af_spirit_2"]=true},
					vremya = {0,0,1}
				},
				["ohota_tushkan_done"] = {
					komp = {["af_spirit_2"]=true},
					cel = {["af_spirit_3"]=true},
					vremya = {0,0,1}
				},
				["yan_kill_brain_done"] = {
					komp = {["af_cry_1"]=true},
					cel = {["af_cry_2"]=true},
					vremya = {0,0,1}
				},
				["info_amk_recipt_dikoobraz"] = {
					komp = {["af_rusty_sea-urchin"]=true},
					cel = {["af_dik_1"]=true},
					vremya = {0,0,1}
				},
				["info_amk_recipt_giant_small_brother"] = {
					komp = {["af_kol_3"]=true},
					cel = {["af_kol_4"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["detection_sensor_done"] = {
					komp = {["af_armor_3"]=true},
					cel = {["af_armor_4"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
                                },
				["info_recipt_shadow_face"] = {
					komp = {["af_kamen_udachy"]=true,["af_simbion"]=true,["af_armor_4"]=true,["af_caterpillar"]=true},
					cel = {["af_shadow_face"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				}
			}
		},

		["_galant"] = {
			-- умолчание, если нет данных ближе к рецепту
			name = "\""..translate("task_foto_anomaly_2").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},

			recepti = {
				["mil_trader_teleport_07_done"] = {
					komp = {["mutant_cat_cocoon"]=true,["part_chimera_kogot"]=true,["mutant_jumper_cocoon"]=true,["mutant_psydog_cocoon"]=true},
					cel = {["mutant_electro_cocoon"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["embt_vp1_done"] = {
					komp = {["mutant_deathclaw_cocoon"]=true,["mutant_bibliotekar_cocoon"]=true,["red_mozg"]=true,["af_life_heart"]=true},
					cel = {["mutant_mono_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["esc_fox_medkit_done"] = {
					komp = {["af_blood"]=true,["af_medusa"]=true,["vodka"]=true,["part_dog_tail"]=true},
					cel = {["af_fireball"]=true}
				},
				["val_prisoner_give_info"] = {
					komp = {["af_vyvert"]=true,["af_rusty_thorn"]=true,["conserva"]=true,["part_dog_tail"]=true},
					cel = {["af_cristall_flower"]=true}
				},
				["info_artmod_ameba_mica_galant"] = {
					komp = {["af_ameba_slime"]=true,["af_rusty_thorn"]=true,["af_medusa"]=true,["kolbasa"]=true},
					cel = {["af_ameba_mica"]=true}
				},
				["val_escort_PDA_done"] = {
					komp = {["af_gravi"]=true,["af_blood"]=true,["af_fireball"]=true,["part_psevdodog_tail"]=true},
					cel = {["af_soul"]=true}
				},
				["sak_gold_fish_done"] = {
					komp = {["af_medusa"]=true,["af_rusty_thorn"]=true,["af_cristall_flower"]=true,["part_flesh_eye"]=true},
					cel = {["af_gold_fish"]=true}
				},
				["bar_dolg_petrenko_exo_done"] = {
					komp = {["af_cristall_flower"]=true,["af_cristall"]=true,["part_psevdodog_tail"]=true,["conserva"]=true},
					cel = {["af_dummy_spring"]=true}
				},
				["krysyk_pomer_give_pda"] = {
					komp = {["part_face_tushkano"]=true,["bandage"]=true,["conserva"]=true,["part_dog_tail"]=true},
					cel = {["af_medusa"]=true}
				},
				["docent_art_start"] = {
					komp = {["af_spirit_3"]=true},
					cel = {["af_spirit_4"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["info_amk_recipt_tears_electra"] = {
					komp = {["af_drops"]=true},
					cel = {["af_cry_1"]=true},
					vremya = {0,0,1}
				},
				["info_amk_recipt_grandmother_glassbeards"] = {
					komp = {["af_dummy_glassbeads"]=true},
					cel = {["af_babka_1"]=true},
					vremya = {0,0,1}
				},
				["info_amk_recipt_dummy_fire"] = {
					komp = {["af_dummy_dummy"]=true},
					cel = {["af_pudd_1"]=true},
					vremya = {0,0,1}
				},
				["kalinin_voen1_done"] = {
					komp = {["af_pudd_1"]=true},
					cel = {["af_pudd_2"]=true},
					vremya = {0,0,2}
				},
				["taynik_gila_done"] = {
					komp = {["af_pudd_2"]=true},
					cel = {["af_pudd_3"]=true},
					vremya = {0,0,1}
				},
				["info_amk_recipt_electra_dikoobraz"] = {
					komp = {["af_dik_1"]=true},
					cel = {["af_dik_2"]=true},
					vremya = {0,0,1}
				}
			}
		},

		["_buzz"] = {
			-- умолчание, если нет данных ближе к рецепту
			name = "\""..translate("task_foto_anomaly_3").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},

			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалию без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["hand_otdan"] = {
					komp = {["mutant_zombie_cocoon"]=true,["bezoar"]=true,["part_rudiment_big"]=true,["part_zombie_hand"]=true},
					cel = {["mutant_babka_cocoon"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["test_quest_art_otdan"] = {
					komp = {["mutant_rat_cocoon"]=true,["part_tarakan_strong"]=true,["sweetness"]=true,["conserva"]=true},
					cel = {["mutant_tarakan_cocoon"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["esc_bridge_vodka_done"] = {
					komp = {["af_electra_sparkler"]=true,["af_medusa"]=true,["af_drops"]=true,["bread"]=true},
					cel = {["af_rusty_kristall"]=true}
				},
				["info_artmod_rusty_thorn_buzz"] = {
					komp = {["af_blood"]=true,["bandage"]=true,["bread"]=true,["part_dog_tail"]=true},
					cel = {["af_rusty_thorn"]=true}
				},
				["info_artmod_fireball_buzz"] = {
					komp = {["af_rusty_thorn"]=true,["af_vyvert"]=true,["part_snork_leg"]=true,["bread"]=true},
					cel = {["af_fireball"]=true}
				},
				["yan_kruglov_decoder_done"] = {
					komp = {["af_gravi"]=true,["af_blood"]=true,["af_electra_flash"]=true,["part_psevdodog_tail"]=true},
					cel = {["af_gold_fish"]=true}
				},
				["yan_kruglov_art_done"] = {
					komp = {["af_night_star"]=true,["af_soul"]=true,["af_electra_moonlight"]=true,["af_rusty_sea-urchin"]=true},
					cel = {["af_fuzz_kolobok"]=true}
				},
				["bandit_krisyk_done"] = {
					komp = {["part_face_tushkano"]=true,["bandage"]=true,["conserva"]=true,["part_dog_tail"]=true},
					cel = {["af_vyvert"]=true}
				},
				["info_amk_recipt_tears_chimaera"] = {
					komp = {["af_cry_2"]=true},
					cel = {["af_cry_3"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["info_amk_recipt_pra_grandmother_glassbeards"] = {
					komp = {["af_babka_1"]=true},
					cel = {["af_babka_2"]=true},
					vremya = {0,0,1}
				},
				["vasily_toolkit_done"] = {
					komp = {["af_pudd_3"]=true},
					cel = {["af_pudd_4"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["val_sos_give_info"] = {
					komp = {["af_dik_2"]=true},
					cel = {["af_dik_3"]=true},
					vremya = {0,0,1}
				},
				["bar_rescue_research_reward"] = {
					komp = {["af_kol_2"]=true},
					cel = {["af_kol_3"]=true},
					vremya = {0,0,1}
				},
				["escape_blockpost_case_done"] = {
					komp = {["af_armor_2"]=true},
					cel = {["af_armor_3"]=true},
					vremya = {0,0,1}
				},
				["shax_plennik_nayti_done"] = {
					komp = {["af_simbion"]=true},
					cel = {["af_arhara_globus"]=true},
					vremya = {0,0,1},
					v_udachi = 75,
					v_virogd = 25
				},
				["info_amk_recipt_simbion"] = {
					komp = {["af_medusa"]=true,["af_drops"]=true,["af_blood"]=true,["af_rusty_thorn"]=true},
					cel = {["af_simbion"]=true},
					vremya = {0,0,1}
				},
				["snp_kalmyk1_done"] = {
					komp = {["snp_prime_maz"]=true},
					cel = {["snp_prime_maz_green"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["we_ne_chmuri"] = {
					komp = {["af_kamen_udachy"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					not_for_mutator = true,
					info = "spawn_hospit_live"
				}

			}
		},

		["_fountain"] = {
			name = "\""..translate("task_foto_anomaly_4").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},

			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалию без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["emb0"] = {
					komp = {["mutant_x_ray_cocoon"]=true},
					cel = {["mutant_wolf_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["acv_forwarder"] = {
					komp = {["af_power_2"]=true,["af_buliz"]=true,["af_cry_1"]=true,["af_pudd_3"]=true,["af_dik_2"]=true},
					cel = {["af_power_3"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["snp_receipt_parts6_done"] = {
					komp = {["kolba_pustay"]=true,["kolba_siniy_poln"]=true,["kolba_orand_poln"]=true,["part_rudiment_big"]=true,["part_tarakan"]=true,["part_tarakan_strong"]=true},
					cel = {["kolba_krasn_poln"]=true},
					vremya = {0,0,10},
					v_udachi = 100,
					v_virogd = 0
				},
				["info_artmod_cristall_buzz"] = {
					komp = {["af_cristall_flower"]=true,["af_medusa"]=true,["af_fireball"]=true,["part_krovosos_jaw"]=true},
					cel = {["af_cristall"]=true}
				}
			}
		},

		["_mincer"] = {
			-- умолчание, если нет данных ближе к рецепту
			name = "\""..translate("task_foto_anomaly_5").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},

			recepti = {
				["emb_container_done"] = {
					komp = {["mutant_big_cocoon"]=true},
					cel = {["mutant_jumper_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["kalmyak_need_done"] = {
					komp = {["mutant_zombie_cocoon"]=true,["vodka"]=true,["part_fracture_hand"]=true,["part_digitis_biblio"]=true},
					cel = {["mutant_fracture_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["esc_shustryi_medusa_done"] = {
					komp = {["af_blood"]=true,["af_medusa"]=true,["bandage"]=true,["conserva"]=true},
					cel = {["af_cristall_flower"]=true}
				},
				["info_artmod_drops_mincer"] = {
					komp = {["af_vyvert"]=true,["bandage"]=true,["vodka"]=true,["part_dog_tail"]=true},
					cel = {["af_drops"]=true}
				},
				["info_artmod_rusty_kristall_mincer"] = {
					komp = {["af_electra_sparkler"]=true,["af_medusa"]=true,["conserva"]=true,["part_dog_tail"]=true},
					cel = {["af_rusty_kristall"]=true}
				},
				["mil_Svoboda_trader_ammo_done"] = {
					komp = {["af_fireball"]=true,["af_blood"]=true,["af_ameba_slug"]=true,["part_krovosos_jaw"]=true},
					cel = {["af_electra_moonlight"]=true}
				},
				["info_artmod_ameba_slug_mincer"] = {
					komp = {["af_electra_flash"]=true,["af_vyvert"]=true,["af_fireball"]=true,["part_psevdodog_tail"]=true},
					cel = {["af_ameba_mica"]=true}
				},
				["sak_find_seif_done"] = {
					komp = {["af_ameba_mica"]=true,["af_rusty_sea-urchin"]=true,["af_gold_fish"]=true,["af_night_star"]=true},
					cel = {["af_dummy_glassbeads"]=true}
				},
				["sidor_ugon_baggi"] = {
					komp = {["af_babka_2"]=true},
					cel = {["af_babka_3"]=true},
					vremya = {0,0,1}
				},
				["svoboda_lukash_done"] = {
					komp = {["af_kol_1"]=true},
					cel = {["af_kol_2"]=true},
					vremya = {0,0,1}
				},
				["hand_otdan"] = {
					komp = {["kolbasa"]=true,["energy_drink"]=true,["part_spleen_rat"]=true,["part_psevdodog_tail"]=true},
					cel = {["af_blood"]=true}
				},
				["bar_svoboda_rg6_done"] = {
					komp = {["af_armor_1"]=true},
					cel = {["af_armor_2"]=true},
					vremya = {0,0,1}
				}
			}
		},

		["_mosquito_bald"] = {
			-- умолчание, если нет данных ближе к рецепту
			name = "\""..translate("task_foto_anomaly_6").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,1}
			},

			recepti = {
				["emb14"] = {
					komp = {["mutant_gigant_cocoon"]=true,["mutant_snork_cocoon"]=true,["mutant_kachok_cocoon"]=true,["part_psevdogigant_hand"]=true},
					cel = {["mutant_big_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["dar_password_info2"] = {
					komp = {["mutant_tarakan_cocoon"]=true,["part_tarakan"]=true},
					cel = {["mutant_tarakan2_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["esc_tolik_five_teil_done"] = {
					komp = {["af_vyvert"]=true,["af_blood"]=true,["vodka"]=true,["part_dog_tail"]=true},
					cel = {["af_mincer_meat"]=true}
				},
				["gar_dram_novice_mp5_m1_done"] = {
					komp = {["af_drops"]=true,["bandage"]=true,["kolbasa"]=true,["part_dog_tail"]=true},
					cel = {["af_electra_sparkler"]=true}
				},
				["gar_dolg_flesh_eye_done"] = {
					komp = {["af_medusa"]=true,["af_drops"]=true,["bandage"]=true,["vodka"]=true},
					cel = {["af_ameba_slug"]=true}
				},
				["mil_Svoboda_trader_outfit_done"] = {
					komp = {["af_mincer_meat"]=true,["af_vyvert"]=true,["af_fireball"]=true,["part_flesh_eye"]=true},
					cel = {["af_cristall"]=true}
				},
				["bar_ivancov_rg6_done"] = {
					komp = {["af_ameba_slime"]=true,["af_blood"]=true,["af_rusty_kristall"]=true,["part_krovosos_jaw"]=true},
					cel = {["af_rusty_sea-urchin"]=true}
				},
				["info_artmod_dummy_dummy_mosquito_bald"] = {
					komp = {["af_ameba_mica"]=true,["af_cristall"]=true,["af_mincer_meat"]=true,["af_night_star"]=true},
					cel = {["af_dummy_dummy"]=true}
				},
				["info_amk_recipt_stone_dikoobraz"] = {
					komp = {["af_dik_3"]=true},
					cel = {["af_dik_4"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["bar_bar_hunter_quest_finish"] = {
					komp = {["af_fuzz_kolobok"]=true},
					cel = {["af_kol_1"]=true},
					vremya = {0,0,1}
				},
				["info_amk_recipt_shkura"] = {
					komp = {["af_dummy_pellicle"]=true},
					cel = {["af_armor_1"]=true},
					vremya = {0,0,1}
				}
			}
		},

		["_gravi_zone"] = {
			-- умолчание, если нет данных ближе к рецепту
			name = "\""..translate("task_foto_anomaly_7").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},

			recepti = {
				["snp_almaz0"] = {
					komp = {["mutant_bloodsucker2_cocoon"]=true},
					cel = {["mutant_deathclaw_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["arhara_shaxter_start"] = {
					komp = {["part_tarakan"]=true,["bread"]=true,["part_tail_cat"]=true,["part_spleen_rat"]=true},
					cel = {["mutant_rat_cocoon"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["kostya_biznes1_done"] = {
					komp = {["af_power_1"]=true,["af_buliz"]=true,["af_gravi"]=true,["af_pudd_2"]=true,["af_rusty_thorn"]=true},
					cel = {["af_power_2"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["esc_petruha_toz_done"] = {
					komp = {["af_vyvert"]=true,["af_medusa"]=true,["kolbasa"]=true,["part_dog_tail"]=true},
					cel = {["af_ameba_slug"]=true}
				},
				["gar_hellcar_outfit_done"] = {
					komp = {["af_medusa"]=true,["bandage"]=true,["conserva"]=true,["part_dog_tail"]=true},
					cel = {["af_ameba_slime"]=true}
				},
				["gar_dolg_krovosos_jaw_done"] = {
					komp = {["af_vyvert"]=true,["af_blood"]=true,["part_dog_tail"]=true,["vodka"]=true},
					cel = {["af_electra_flash"]=true}
				},
				["val_pula_ammo_done"] = {
					komp = {["af_rusty_thorn"]=true,["af_medusa"]=true,["af_rusty_kristall"]=true,["part_psevdodog_tail"]=true},
					cel = {["af_night_star"]=true}
				},
				["sak_repair_box_done"] = {
					komp = {["af_electra_flash"]=true,["af_cristall_flower"]=true,["af_ameba_slug"]=true,["part_snork_leg"]=true},
					cel = {["af_soul"]=true}
				},
				["yan_scientist_books_done"] = {
					komp = {["af_ameba_mica"]=true,["af_cristall"]=true,["af_gold_fish"]=true,["af_soul"]=true},
					cel = {["af_dummy_pellicle"]=true}
				}
			}
		},

		["_ice"] = {
			-- умолчание, если нет данных ближе к рецепту
			name = "\""..translate("task_foto_anomaly_8").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},

			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалию без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["emb_kill_tm_done"] = {
					komp = {["mutant_babka_cocoon"]=true},
					cel = {["mutant_ghost_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["acv_supplier"] = {
					komp = {["af_power"]=true,["af_buliz"]=true,["af_blood"]=true,["af_pudd_1"]=true,["af_ameba_slug"]=true},
					cel = {["af_power_1"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["acv_fzom"] = {
					komp = {["af_buliz"]=true,["af_electra_moonlight"]=true,["af_electra_flash"]=true,["af_electra_sparkler"]=true,["spleen_rat_plague"]=true},
					cel = {["af_power"]=true},
					vremya = {0,0,5},
					v_udachi = 90,
					v_virogd = 10
				},
				["life_heart_final"] = {
					komp = {["af_dummy_dummy"]=true,["af_rusty_sea-urchin"]=true,["af_gold_fish"]=true,["af_night_star"]=true},
					cel = {["af_life_heart"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["mil_volk_resiver_done"] = {
					komp = {["af_dummy_battery"]=true},
					cel = {["af_dummy_battery_red"]=true}
				},
				["plov_kulinar_done"] = {
					komp = {["af_dummy_spring"]=true},
					cel = {["af_dummy_spring_red"]=true}
				},
				["val_pula_boar_leg_done"] = {
					komp = {["af_dummy_pellicle"]=true},
					cel = {["af_dummy_pellicle_red"]=true}
				}
			}
		},

		["_sphere"] = {
		name = "\""..translate("task_foto_anomaly_9").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},
			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалиі без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["emb8"] = {
					komp = {["mutant_fracture_cocoon"]=true},
					cel = {["mutant_bibliotekar_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["emb4"] = {
					komp = {["mutant_poltergeist_cocoon"]=true,["mutant_tarakan2_cocoon"]=true,["part_krovosos_red_jaw"]=true,["part_burer_red_hand"]=true},
					cel = {["mutant_bloodsucker_cocoon"]=true},
					vremya = {0,0,5},
					v_udachi = 100,
					v_virogd = 0
				},
				["info_amk_recipt_teleport"] = {
					komp = {["part_plague_hand"]=true,["drug_booster"]=true,["mutant_crow"]=true,["af_fuzz_kolobok"]=true},
					cel = {["af_teleport"]=true},
					vremya = {0,0,1}
				},
				["mozno_varit"] = {
					komp = {["af_part_monolit2"]=true},
					cel = {["af_kamen_udachy"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
--					not_for_mutator = true,
					info = "spawn_kamen_udachy"
				}
			}
		},

		["_zavesa"] = {
		name = "\""..translate("task_foto_anomaly_10").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},
			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалиі без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
               },
				["emb17"] = {
					komp = {["mutant_chimera_cocoon"]=true,["mutant_electro_cocoon"]=true,["mutant_kachok_cocoon"]=true,["mutant_ghost_cocoon"]=true},
					cel = {["mutant_x_ray_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				},
				["fima_mulo_nayti_done"] = {
					komp = {["part_zombie_teeth"]=true,["kolbasa"]=true},
					cel = {["part_rudiment_big"]=true},
					v_udachi = 50,
					v_virogd = 50
				}
			}
		},

		["_smallrain"] = {
		name = "\""..translate("task_foto_anomaly_11").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,5}
			},
			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалиі без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["snp_almaz3"] = {
					komp = {["mutant_mono_cocoon"]=true},
					cel = {["mutant_tm_cocoon"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0
				}
			}
		},

		["_sakbuzz_average"] = {
			name = "\""..translate("task_foto_anomaly_12").."\"",
			default = {
				v_udachi = 80,
				v_virogd = 20,
				vremya = {0,0,1}
			},
			recepti = {
				["info_izomorf_kompas"] = { -- артефакт удалит аномалиі без результатов варки/мутации
					komp = {["izomorf_kompas"]=true},
					cel = {["izomorf_kompas"]=true},
					vremya = {0,0,1},
					v_udachi = 100,
					v_virogd = 0,
					remove_anomaly = true
				},
				["gena_sakharov2_done"] = {
					komp = {["kolba_pustay"]=true,["kolba_siniy_poln"]=true,["kolba_orand_poln"]=true,["kolba_krasn_poln"]=true,["af_black_angel"]=true,["af_arhara_globus"]=true},
					cel = {["kolba_fiol_poln"]=true},
					vremya = {0,0,10},
					v_udachi = 100,
					v_virogd = 0
				}
			}
		}
	}
}

-- возвращает значение, возможно из умолчаний
function get_af_transform_param(name, recept, recepti)
	local result
	--log(string.format(name.." имя"))
	if recept[name] ~= nil then
		result = recept[name]
	elseif recepti["default"] ~= nil and recepti["default"][name] ~= nil then
		result = recepti["default"][name]
	elseif anom_recept_komp["default"] ~= nil and anom_recept_komp["default"][name] ~= nil then
		result = anom_recept_komp["default"][name]
	else
		amk.send_tip(translate("get_af_transform_param_text_0")..name.."!",translate("get_af_transform_param_text_1"),0,15,"gen_info")
		result = nil
	end
	return result
end

-- получаем полный набор рецептов для аномалии anom_sect
function fill_recepti_est(anom_sect)
	local recepti_est = {} -- рецепты для заданной аномалии
	local anom_name = nil
	for anom, recepti in pairs(anom_recept_komp["anomalii"]) do
		if string.find(anom_sect, anom) ~= nil then --нашли в списке аномалий
			anom_name = anom_recept_komp["anomalii"][anom]["name"]
			if anom_recept_komp["anomalii"][anom]["recepti"] then
				for info, recept in pairs(recepti["recepti"]) do
					if not recept["not_for_mutator"] and not recept["remove_anomaly"] and has_info(info) then
						-- есть рецепт: заносим в таблицу
						recepti_est[info] = {}
						for k, v in pairs(recept) do
							if type(v) == "table" then
								recepti_est[info][k] = {}
								for i, j in pairs(v) do
									recepti_est[info][k][i] = j
								end
							else
								recepti_est[info][k] = v
							end
						end
					end
				end
			end
		end
	end
	return recepti_est,anom_name
end

-- проверяет рецепты и компонеты
-- если всї в порядке - запускает варку/мутации
function check_af_transform(af, af_sect, obj_pos, anom_id, anom_sect, anom_pos, anom_radius, lv, gv)
	--поиск по аномалиям
	local finish = false -- флаг для выхода из циклов
	for anom, recepti in pairs(anom_recept_komp["anomalii"]) do
		if string.find(anom_sect, anom) ~= nil then --нашли в списке аномалий, возле которой стоим
			local recepti_est = {} -- рецепты в наличии у ++, в которых участвует данный компонент
			local recept_podhodit = false

			-- собираем рецепты, в которых участвует данный компонент
			for info, recept in pairs(recepti["recepti"]) do
				if has_info(info) and recept["komp"][af_sect] == true then --есть рецепт и этот компонент в нём участвует
					recept_podhodit = true
					-- копируем рецепт
					recepti_est[info] = {}
					for k, v in pairs(recept) do
						if type(v) == "table" then
							recepti_est[info][k] = {}
							for i, j in pairs(v) do
								recepti_est[info][k][i] = j
							end
						else
							recepti_est[info][k] = v
						end
					end
					-- так как table.getn() как и оператор # не работает с таблицами, у которых не целочисельные индексы,
					-- то считаем количество в ручную
					local count = 0
					for k,v in pairs(recepti_est[info]["komp"]) do
						count = count + 1
					end
					recepti_est[info]["count"] = count
					--log(string.format("0 "..af_sect.." принят. Lном: "..anom.." рец. "..info.." "..recepti_est[info]["count"]))
				end
			end

			if recept_podhodit then -- если нашли хоть один имеющийся подходящий рецепт
				--ищем рядом другие компоненты
				--если находим их в выбранных рецептах, то удаляем их из рецептов
				--как только какой-то рецепт остаётся без компонентов - рецепт сработал
				local obj
				for i=1,65534 do
					obj = level_object(i)
					if obj and server_object(i) then
						local dist = obj:position():distance_to(anom_pos)
						if obj:parent() == nil and ((anom_radius - obj:position():distance_to(anom_pos)) > -2) then
							local obj_sect = obj:section()
							--log(string.format(" obj_sect: "..obj_sect.." dist: "..dist))
							--проверяем отобранные рецепты
							for info, recept in pairs(recepti_est) do
								-- если компонент есть в рецепте
								if recepti_est[info]["komp"][obj_sect] == true then
									-- добавляем L- компонента для будущего удаления из игры
									recepti_est[info]["komp"][obj_sect] = obj:id()
									-- уменьшаем количество компонентов в рецепте
									recepti_est[info]["count"] = recepti_est[info]["count"] - 1
									--log(string.format(obj_sect.." найден. Lном: "..anom.." рец. "..info.." "..recepti_est[info]["count"]))

									-- если рецепт пуст, то он сработал
									if recepti_est[info]["count"] == 0 then
										--log(string.format(info.." сработал. Lном: "..anom))

										-- устанавливаем все параметры для рецепта, возможно из умолчаний
										local cel		= get_af_transform_param("cel", recepti_est[info], recepti)
										local v_udachi		= get_af_transform_param("v_udachi", recepti_est[info], recepti)
										local v_virogd		= get_af_transform_param("v_virogd", recepti_est[info], recepti)
										local virogd		= get_af_transform_param("virogd", recepti_est[info], recepti)
										local vremya		= get_af_transform_param("vremya", recepti_est[info], recepti)
										local remove_anomaly	= get_af_transform_param("remove_anomaly", recepti_est[info], recepti)
										local remove_anomaly_id = anom_id
										local komp		= recepti_est[info]["komp"]
										local result, udacha 	= af_select_result(v_udachi, v_virogd, virogd, cel, komp)
										local info_portion	= recepti_est[info]["info"]

										if cel == nil or v_udachi == nil or v_virogd == nil
											or virogd == nil or vremya == nil or remove_anomaly == nil
											or cel == nil and remove_anomaly == false
											or v_udachi + v_virogd > 100 then

											-- кривой рецепт  - выходим
											finish = true
											break
										end

										-- неудача
										if udacha == false then
											remove_anomaly = false
											info_portion = nil
										end

										level.add_pp_effector("teleport.ppe", 1524, false)

										-- запускаем варку/мутации
						as_start_universal_transform_timer(komp, result, udacha, obj_pos, vremya, gv, lv, info_portion, remove_anomaly, remove_anomaly_id)

										-- удаляем из игры компоненты рецепта
										give_info("biznes_remove_special_item")
										for k,v in pairs(komp) do
											release(server_object(v))
										end
										disable_info("biznes_remove_special_item")

										-- выходим
										finish = true
										break
									end
								end
							end
						end
					end

					if finish then break end
				end
			end

			-- аномалия с рецептами найдена, все дела сделаны - выходим
			break
		end
	end

end

function af_flash(af)
	level.add_pp_effector("teleport.ppe", 1524, false)
	amk.remove_item(af)
end

-- случайно выбирает результат, возвращает таблицу с секциями результатов
function af_select_result(v_udachi, v_virogd, virogd, cel, komp)
	local rnd=math.random(0,100)
	if rnd > v_udachi then --неудача
		if rnd > v_virogd + v_udachi then -- отторжение
			return komp, false
		else -- вvрождение
			return virogd, false
		end
	else -- удача
		-- log(string.format("удача "..table.to_string(cel)))
		return cel, true
	end
end

-- запускаем трансформации
-- результаты могут быть многочисленны (несколько целей, полное отторжение компонентов, несколько вырождений)
function as_start_universal_transform_timer(komp, result, udacha, pos, vremya, gv, lv, info_portion, remove_anomaly, remove_anomaly_id)
	local t={} -- сохраняемые данные
	t.result = result -- можно сохранять сразу таблицы
	t.udacha = udacha
	t.pos = {}
		t.pos.x = pos.x
		t.pos.y = pos.y
		t.pos.z = pos.z
	t.gv = gv
	t.lv = lv
	t.info_portion = info_portion
	t.komp = komp -- можно сохранять сразу таблицы
	t.remove_anomaly = remove_anomaly
	t.remove_anomaly_id = remove_anomaly_id
	t.level_trans=object_level_name(server_object(remove_anomaly_id))
	--log(string.format(" Timer:start_game: "..vremya[1].." "..vremya[2].." "..vremya[3].." "..table.to_string(t)))
	Timer:start_game("af_transform_universal", vremya[1], vremya[2], vremya[3], t)
end

-- завершаем варку/мутации
-- может быть много результатов
function af_transform_universal_end(params)
	--log(string.format(" af_transform_universal_end "))
	-- если есть результаты
	local anom_trans=server_object(params.remove_anomaly_id)
	if not anom_trans then
		sms("%c[sender]"..translate("name_lokalnaya_set")..":\\n%c[sms_red]"..
			translate("trans_finished_failed").." "..translate("trans_territory").." "..
			translate(params.level_trans))
		return
	end
	local count = 0
	for k, v in pairs(params.result) do
		count = count + 1
	end
	if count > 0 then
		local anom_pos = vector():set(params.pos.x, params.pos.y, params.pos.z)
		if db.actor:position():distance_to(anom_pos) < 15 then
			level.add_pp_effector("teleport.ppe", 1524, false)
		end
		-- формируем строку с названиями компонентов
		local from_komp = ""
		for k,v in pairs(params.komp) do
			if k then
				if string.len(from_komp)>0 then
					from_komp=from_komp..", "
				end
				from_komp = from_komp..get_inv_name(k)
			end
		end

		-- спавним результат(v)
		local message_text=string.extformat(translate("trans_finished_title"),"%c[255,255,0,0]"..from_komp.."%c[default]")
		for k,v in pairs(params.result) do
			local obj
			-- спавн поднят на 10 метров, попытка победить проваливание под текстуры
			obj = amk.spawn_item(k, xyz(params.pos.x,params.pos.y+10,params.pos.z), params.gv, params.lv)
			map_spot(obj.id, "red_location", message_text)
			if params.udacha and string.find(k, "^af_") then
				archievements.acv_count_event("acv_art", 100, "acv_art")
			end
		end
		sms("%c[sender]"..translate("name_lokalnaya_set")..":\\n%c[default]"..
			message_text.."\\n"..translate("trans_territory").." "..translate(params.level_trans))
	end

	-- даём инфопорции, если есть
	if params.info_portion and not has_info(params.info_portion) then
		--log("params.info_portion: "..params.info_portion)
		give_info(params.info_portion)
	end

	-- удаляем аномалии, если нужно и она не в исключениях
	if params.remove_anomaly then
		if anom_trans then
			local map = object_level_name(anom_trans)
			local obj_name = anom_trans:name()
			if not amk_anoms.check_exclusion(anom_trans, map) then
				local status = amk_anoms.get_anomaly_status(anom_trans)
				if status == "" or status == "on" then
					amk_anoms.set_anomaly_status(anom_trans, "del")
					release(anom_trans, true)
				end
			end
		end
	end
--[[	log(string.format(" варка закончена "))
	console:execute("flush")]]
end

function check_metka(id)
	local obj = level_object(id)
	if obj and obj:parent() == nil then
		level.start_stop_menu(ui_dots.dots(id), true)
	end
end

-- Динамическая музыка
local last_update=0
local inert = 1000
local clicks_prev = 200
local music_section=""
local music_previous_section=""
local music_next_section_start_time=0
local music_stop_previous=0
local music=false
local music_init = 0
local music_themes = {}
local music_phases={}
local musicflag=1
local music_objs={[1] = nil,[2] = nil}
local music_stor={ enemy_see_actor=0, actor_see_enemy=0, enemy_hit_actor=0, actor_hit_enemy=0 }
music_lo_lvl=7
music_hi_lvl=17
local music_graph = {}

function build_music_graph()
	local skip = false
	local lname = level.name()

	local sect = "music_themes"
	local sini = ini_file("scripts\\amk\\music.ltx")
	if sini:section_exist(sect) then
		local value1, tmp, t, tt
		sini:iterate_lines(sect, function(result, id, value)
			value1 = string.explode(value, "|", true)
			value = {}

			for k,v in pairs(value1) do
				tmp = string.explode(v, "=", true)
				value[tmp[1]] = tmp[2]
			end

			if value.map then
				t = string.explode(value.map, ",", true)
				for kk,vv in pairs(t)do
					skip = skip or vv == lname
				end
				skip = not skip
			else
				skip = false
			end

			if not skip then
				table.insert(music_themes, id)
				t = sini:key_value(id.."_music_files")
				t.null = ""
				for k,v in pairs(t) do
					music_phases[id.."_"..k]=v
					if not music_graph[id.."_"..k] then
						music_graph[id.."_"..k] = {}
					end
					tt = sini:key_value(id.."_graph_"..k)
					for kk,vv in pairs(tt) do
						tmp = string.explode(vv, ",", true)
						--lvl = tmp[1]
						lvl = amk_mod["music_"..tmp[1].."_lvl"]
						music_graph[id.."_"..k][id.."_"..kk] = {lvl,tmp[2]}
					end
				end
			end
		end)

		if #music_themes > 0 then
			return true
		else
			return false
		end
	end

	return false
end

function music_start(sound)
	if not ui_mm_opt_creator.get_bool_user_param("amk_option_mus",false) then 
		return
	end
	if not music then
		if music_objs[1] == nil then
			music_objs[1] = amk_music.amk_music()
		end
		if music_objs[2] == nil then
			music_objs[2] = amk_music.amk_music()
		end
		music_objs[musicflag]:initialize(music_phases[sound])
		music_next_section_start_time = music_objs[musicflag]:play()-200
		music_previous_section = music_section
		musicflag = 3-musicflag
	end

	music = true
end

function music_change(sound)
	if music then
		music_objs[musicflag]:initialize(music_phases[sound])
		music_next_section_start_time = music_objs[musicflag]:play_at_time(music_next_section_start_time+200)-200
		musicflag=3-musicflag music_previous_section=music_section
	end
end

function interactive_music()
	amk.oau_reason="music begin"
	
	if not ui_mm_opt_creator.get_bool_user_param("amk_option_mus",false) then 
		if music then
			if music_objs[1] then music_objs[1]:stop() end
			if music_objs[2] then music_objs[2]:stop() end
		end
		return 
	end
	if music_init == -1 then return end
	if music_init == 0 then
		if build_music_graph() then
			music_init = 1
		else
			music_init = -1
			return
		end
	end
	if not music then
		if time_global() - last_update > inert then
			music_select_section(inert) last_update = time_global()
		end
	end
	if not music and music_previous_section == "" and music_section ~= "" then
		music_start(music_section)
	end
	if music and music_previous_section ~= "" and music_section == "" then
		music_previous_section = ""
	end
	if music then
		music_objs[1]:update()
		music_objs[2]:update()
		if time_global() > music_next_section_start_time then
			music_select_section(music_objs[musicflag]:length())
			if music_section ~= "" then
				music_change(music_section)
			else
				music = false
			end
		end
	end

	amk.oau_reason=""
end

function reset_music_cntrs(c)
	music_stor.actor_see_enemy = music_stor.actor_see_enemy-2*c
	music_stor.enemy_see_actor = music_stor.enemy_see_actor-2*c
	music_stor.actor_hit_enemy = music_stor.actor_hit_enemy-8*c
	music_stor.enemy_hit_actor = music_stor.enemy_hit_actor-4*c
	if music_stor.actor_see_enemy < 0 then
		music_stor.actor_see_enemy = 0
	elseif music_stor.actor_see_enemy > music_lo_lvl then
		music_stor.actor_see_enemy = music_lo_lvl
	end
	if music_stor.enemy_see_actor < 0 then
		music_stor.enemy_see_actor = 0
	elseif music_stor.enemy_see_actor > music_lo_lvl then
		music_stor.enemy_see_actor = music_lo_lvl
	end
	if music_stor.actor_hit_enemy < 0 then
		music_stor.actor_hit_enemy = 0
	elseif music_stor.actor_hit_enemy > music_hi_lvl then
		music_stor.actor_hit_enemy = music_hi_lvl
	end
	if music_stor.enemy_hit_actor < 0 then
		music_stor.enemy_hit_actor = 0
	elseif music_stor.enemy_hit_actor > music_hi_lvl then
		music_stor.enemy_hit_actor = music_hi_lvl
	end
end

local shoot_helper = 0

function calc_adrenaline(act,obj,typ)
	local dist = obj:position():distance_to(db.actor:position())

	if act == "actor_see_enemy" then
		music_stor.actor_see_enemy = music_stor.actor_see_enemy+50/dist
	elseif act == "enemy_see_actor" then
		music_stor.enemy_see_actor = music_stor.enemy_see_actor+50/dist
	elseif act == "actor_hit_enemy" then
		if time_global() > shoot_helper then
			music_stor.actor_hit_enemy = music_stor.actor_hit_enemy+13
			shoot_helper = time_global()+500
		end
	elseif act == "enemy_hit_actor" then
		music_stor.enemy_hit_actor = music_stor.enemy_hit_actor+8
	end
end

function music_select_section(time)
	reset_music_cntrs(time/inert)

	local cs = music_section
	local eseen = music_stor.enemy_see_actor
	if eseen >= music_lo_lvl then
		eseen = music_lo_lvl
	end
	local aseen = music_stor.actor_see_enemy
	if aseen >= music_lo_lvl then
		aseen = music_lo_lvl
	end
	local ehits = music_stor.enemy_hit_actor
	if ehits >= music_hi_lvl then
		ehits = music_hi_lvl
	end
	local ahits = music_stor.actor_hit_enemy
	if ahits >= music_hi_lvl then
		ahits = music_hi_lvl
	end

	local lvl = aseen+eseen
	if lvl > music_hi_lvl*0.75 then
		lvl = music_hi_lvl*0.75
	end
	lvl = ehits+lvl+ahits

	if music_section == "" then
		music_section = table.random(music_themes).."_null"
	end

	local last_sel_max = 0
	local last_sel_min = 1000
	for k,v in pairs(music_graph[music_section]) do
		if v[2] == "<" and v[1] < last_sel_min then
			if v[1] > lvl then
				music_section=k
				last_sel_min=v[1]
			end
		end
		if v[2] == ">" and v[1] >= last_sel_max then
			if v[1] <= lvl then
				music_section = k
				last_sel_max = v[1]
			end
		end
	end

	if string.find(music_section,"null") then
		music_section = ""
	end
	if music and music_previous_section ~= "" and music_section == "" then
		music_previous_section = ""
	end

	local l = 0
	if music and music_objs[musicflag] ~= nil then
		l = music_objs[musicflag]:length()
	end
end

-- Выброс
function blowout_phantoms()
	local blow = get_value("blowout",-1)
	if blow > 1 and blow < 4 and blowout_type() < 2 then
		local lname = level.name()
		local hides = amk_hideouts.hide[lname]
		if not hides then
			return
		end
		local need_phantom=true
		for _,hide in ipairs(hides) do --same as "hit" check... 
			if hide.zone then
				need_phantom=need_phantom and not check_npc_in_hideout(db.actor,hide)
			end
		end
		if not need_phantom then
			return
		end
		local phantoms=amk_hideouts.blowouts_phantoms[lname]
		if phantoms and phantoms.count > 0 then
			if math.random() < phantoms.probability then
				if phantom_manager:phantom_count() < phantoms.count then
					local yaw = math.pi*2.0*math.random()
					local radius = phantoms.radius*(math.random()/2.0+0.5)
					local height = phantoms.height*math.random()
					local a_pos = db.actor:position()
					local pos = vector():set(math.sin(yaw)*radius+a_pos.x,a_pos.y+height,math.cos(yaw)*radius+a_pos.z)
					phantom_manager.spawn_phantom(pos)
				end
			end
		end
	end
end

function blowout_scary_sounds()
	local blow = get_value("blowout",-1)
	if blow > 0 and blow < 4 then
		local snd_obj = voice(table.random(amk_hideouts.blowout_sounds))
		local a = vector()
		a.x = math.random(0,10)
		a.y = math.random(0,10)
		a.z = math.random(0,10)
		snd_obj:play_at_pos(db.actor, db.actor:position():add(a))
		timer("blowout_ss",math.random(10,30),"amk_mod.blowout_scary_sounds()")
	end
end

function blowout_psy_sound(action)
	if action == "start" then
		snd_obj_eq = sound_object([[ambient\earthquake]],sound_object.looped+sound_object.s2d)
		snd_obj_eq:play(db.actor, 4, sound_object.looped+sound_object.s2d)
	end
	if action == "stop" then
		if snd_obj_eq then
			snd_obj_eq:stop()
		end
	end

	local lname = level.name()
	if not amk_hideouts.blowouts_phantoms[lname] then return end
	local psy_sound = amk_hideouts.blowouts_phantoms[lname].psy_sounds or false
	if not psy_sound then return end

	if action == "start" then
		local level_vol = amk_hideouts.blowouts_phantoms[lname].level_vol or 1
		sound_obj_right, sound_obj_left = xr_sound.get_sound_object("psy_voices", "random")
		sound_obj_left:play_at_pos (db.actor, xyz(-1, 0, 1), 0, sound_object.s2d + sound_object.looped)
		sound_obj_right:play_at_pos(db.actor, xyz( 1, 0, 1), 0, sound_object.s2d + sound_object.looped)
		snd_volume	= level.get_snd_volume()
		level.set_snd_volume(level_vol)
	end
	if action == "stop" then
		if sound_obj_left then sound_obj_left:stop() end
		if sound_obj_right then sound_obj_right:stop() end
		if snd_volume then level.set_snd_volume(snd_volume) end
	end
end

function Run_Blowout_pp()
	if game_options.run_blowout_pp == 1 then
		local bt = blowout_type()
		if bt == 2 then
			start_blow_timer()
			return
		end

		_G.Dream:stopper(1)
		set_value("blowout",1)
		level.add_cam_effector("camera_effects\\shell_shock.anm", 2004, false, "")
		say([[ambient\organic_moan1]])
		if bt < 1 then
			level.add_pp_effector("monolith_off.ppe", 2003, false)
		end
		timer("blowout_ss",math.random(5,15),"amk_mod.blowout_scary_sounds()")
		timer("blowout",11,0)
		blowout_modif_arts()
		amk_hideouts.pda_show_hideouts(false)
	end
	start_blow_timer()
end

function start_blow_timer()
	local basis = game_options.blow_time_basis
	local shift = game_options.blow_time_shift
	local resuls = basis+math.random(-shift, shift)
	Timer:start_game("blow_shift", 0, 0, resuls, "amk_mod.Run_Blowout_pp()")
	crow_blow_voice.start_voice_step(resuls)
	news_main.next_blow(resuls)
end

function Blowout_pp(phase)
	phase=tonumber(phase)
	--' TimeFactor = 5
	--' GameMin = 12 RealSec
	--' TimeBlowout = 184 RealSec

	--' начало (Timer = 36 sec)
	--' первая фаза (Timer = 36 sec)
	--' вторая фаза (Timer = 36 sec)
	--' Tретья фаза (Timer = 36 sec)
	--' четвертая фаза (Timer = 60 sec)
	--' конечная фаза (Timer = 0 sec)

	local basis = game_options.blow_phase_basis
	local shift = game_options.blow_phase_shift
	local max = game_options.blow_phase_max
	local resuls = basis+(math.random()*shift)-(shift/2)
	if resuls < 1 then
		resuls = 1
	elseif resuls > max then
		resuls = max
	end

	local blow = get_value("blowout", 0)
	local blow_type = blowout_type()
	local hours_type=blowout_hours()
	--log("Blowout_pp phase "..phase)
	if phase == 0 then
		give_info("save_prohibited")
		db.actor.blowout_outside = true
		--winsor: начало граблей с костылями
		local lobj
		for b_id,_ in pairs(db.creatures) do
			lobj=level_object(b_id)
			if lobj and isMonster(lobj) then
				lobj:remove_all_restrictions() --сгорите в аду...
			end
		end
		--winsor: конец граблей с костылями
		
		amk_anoms.pre_blow_off()
		ai:iterate_alife_objects(function(sobj)
			if sobj and sobj:name():find("^caps_.*") and isAnomaly(sobj) then
				release(sobj)
			end
		end)
		if blow_type < 1 then
			level.set_weather_fx("surge_"..hours_type.."_0")
		else
			level.set_weather_fx("isurge_"..hours_type.."_0")
		end
		Timer:start_game("blowout", 0, 0, resuls, 1)
	elseif phase == 1 then
		give_info("save_prohibited")
		set_value("blowout",2)
		say([[ambient\earthquake]])
		level.add_cam_effector("camera_effects\\shell_shock.anm", 2002, true, "")
		blowout_psy_sound("start")

		if blow_type < 1 then
			level.set_weather_fx("surge_"..hours_type.."_1")
		else
			level.set_weather_fx("isurge_"..hours_type.."_1")
		end
		in_hide = false
		Timer:start_game("blowout", 0, 0, resuls, 2)
	elseif phase == 2 then
		give_info("save_prohibited")
		set_value("blowout",3)
		say([[anomaly\blowout]])
		if blow_type < 1 then
			level.set_weather_fx("surge_"..hours_type.."_2")
		else
			level.set_weather_fx("isurge_"..hours_type.."_2")
		end
		level.add_cam_effector("camera_effects\\earthquake.anm",2002,true,"")
		Timer:start_game("blowout",0,0,3,3)
	elseif phase == 3 then
		give_info("save_prohibited")
		amk_anoms.after_blow_on()
		set_value("blowout",4)
		if blow_type < 1 then
			level.set_weather_fx("surge_"..hours_type.."_3")
			local h = hit()
			h.type = hit.strike
			h.power = 1000
			h.impulse = 1000
			level.iterate_level_objects(function(obj) 
				if obj ~= nil and obj:section() == "m_crow" and math.random(0,100) < 30 then
					h.draftsman = obj
					h.direction = obj:direction()
					obj:hit(h)
				end
			end)
		else
			level.set_weather_fx("isurge_"..hours_type.."_3")
		end
		Timer:start_game("blowout", 0, 0, resuls, 4)
	elseif phase == 4 then
		give_info("save_prohibited")
		set_value("blowout",5)
		if blow_type < 1 then
			level.set_weather_fx("surge_"..hours_type.."_4")
		else
			level.set_weather_fx("isurge_"..hours_type.."_4")
		end
		level.remove_cam_effector(2002)
		blowout_psy_sound("stop")
		timer("blowout",5,5)
	elseif phase == 5 then
		give_info("save_prohibited")
		set_value("blowout",6)
		if blow_type < 1 then
			level.add_pp_effector("monolith_off.ppe",2003,false)
		end
		timer("blowout",11,6)
	elseif phase == 6 then
		disable_info("save_prohibited")
		level_weathers.get_weather_manager():weather_set()
		if blow_type < 1 then
			say([[anomaly\teleport_work_2]])
		end
		del_value("blowout")
		if db.actor.blowout_outside then
			archievements.acv_count_event("acv_blow", 5, "acv_blow")
			db.actor.blowout_outside = nil
		end
		amk_hideouts.pda_hide_hideouts(false)
		crow_blow_voice.blowout_final()
   		timer("autosave_blowout", 20, "") -- autosave
	end
end

function on_blowout_hit(npc, hide)
	if not blowout_scheme.blowout_started() then
		return false
	end
	local bt = blowout_type()
	local blowout_step=get_value("blowout",-1)
	if bt > 0 or (blowout_step ~= 3 and blowout_step ~= 4) then
		if npc:id() == db.actor:id() then
			in_hide = true
		end
		return false
	end

	local lname = level.name()
	local need_hit = true
	local khit = 1
	if hide and hide.zone then
		need_hit = not check_npc_in_hideout(npc, hide)
		if not need_hit then
			if hide.defence then
				khit = hide.defence
			else
				khit = 0
			end
		end
	else
		--log("before check need_hit "..(need_hit and "true" or "false"))
		local hides = amk_hideouts.hide[lname]
		local tmp
		if hides then
			for i,o in ipairs(hides) do
				if o.zone then
					for j,v in ipairs(o.zone) do
						if v.p3 then
							tmp=amk.check_npc_in_box(npc,vector():set(unpack(v.p1)),vector():set(unpack(v.p2)),vector():set(unpack(v.p3)))
						else
							tmp=amk.check_npc_in_box(npc,vector():set(unpack(v.p1)),vector():set(unpack(v.p2)))
						end
						need_hit = need_hit and not tmp
						if tmp then
							if o.defence then
								khit = o.defence
							else
								khit = 0
							end
						end
					end
				end
			end
		end
		--log("after check need_hit [%s][%d]",(need_hit and "true" or "false"),blowout_step)
	end

    if npc:id() == db.actor:id() then
		if not need_hit then
			db.actor.blowout_outside = nil
		end
		if outfit_hideout() then -- защита от выброса броником
			need_hit = false
			khit = 0
		else
			khit = khit+khit*level.get_game_difficulty()/6	-- усиление хита для актора, чтобы вне укрытия не пережил
		end
		in_hide = not need_hit
	end
    if (need_hit or khit > 0) and (blowout_step == 3 or blowout_step==4) and not (hide and hide.hidden) then
		local h = hit()
    	h.power = (amk_hideouts.blowout_damages[lname] or 0.01)*khit
    	h.impulse = 0
		h.draftsman = npc
		h.direction = vector():set(0,0,0)
		h:bone("bip01_spine") -- чтобv учитvвалась броня
    	h.type = hit.strike
		npc:hit(h)
    	h.type = hit.telepatic
		npc:hit(h)
    	h.type = hit.radiation
		npc:hit(h)
    end
    return need_hit or khit > 0
end

function outfit_hideout()
	local outfits = {
		["gagarin_outfit"] = true,
		["exo_knight_outfit"] = true
	}
	return db.actor:item_in_slot(6) and outfits[db.actor:item_in_slot(6):section()]
end

function check_npc_in_hideout(npc, hide)
	local not_in_zone = true
	if hide and hide.zone then
		for k,v in pairs(hide.zone) do
			if v.p3 then
				not_in_zone = not_in_zone and not amk.check_npc_in_box(npc,vector():set(unpack(v.p1)),vector():set(unpack(v.p2)),vector():set(unpack(v.p3)))
			else
				not_in_zone = not_in_zone and not amk.check_npc_in_box(npc,vector():set(unpack(v.p1)),vector():set(unpack(v.p2)))
			end
		end
	end
	return not not_in_zone
end

function blowout_modif_arts()
	local arts = {
		["af_cry_2"] = true,
		["af_cry_3"] = true,
		["af_babka_3"] = true,
		["af_babka_4"] = true,
		["af_dik_3"] = true,
		["af_dik_4"] = true,
		["af_spirit_3"] = true,
		["af_spirit_4"] = true,
		["af_armor_3"] = true,
		["af_armor_4"] = true,
		["af_pudd_3"] = true,
		["af_pudd_4"] = true,
		["af_kol_3"] = true,
		["af_kol_4"] = true,
		["af_caterpillar"] = true,
		["af_simbion"] = true,
		["af_dummy_battery_red"] = true,
		["af_dummy_spring_red"] = true,
		["af_dummy_pellicle_red"] = true,
	}

	local obj
	for i=1,65534 do
		obj = server_object(i)
		if obj and arts[obj:section_name()] and math.random() < 0.05 then
			if obj.parent_id == 65535 then
				create("af_buliz", obj.position, obj.m_level_vertex_id, obj.m_game_vertex_id)
			else
				create("af_buliz", obj.position, obj.m_level_vertex_id, obj.m_game_vertex_id, obj.parent_id)
				if obj.parent_id == 0 then
					sms(translate("blowout_modif_arts_0_0")..get_inv_name(obj:section_name())..".", nil, "nano", 20000)
				end
			end
			release(obj)
		end
	end
end

-- Спавн аномалий
local anomalies_state = {}

function remove_anoms()
	set_value("blowout_anoms",string.rep(string.char(128),math.ceil(amk_hideouts.anom_count/7)))
	update_anoms()
end

function create_anoms()
	anomalies_state = {}
	for i = amk_hideouts.anom_sid0,amk_hideouts.anom_sid0+amk_hideouts.anom_count-1,1 do
		anomalies_state[i] = math.random(0,1) == 1
	end
	local str = pack_anoms(anomalies_state)
	set_value("blowout_anoms",str)
	update_anoms()
end

function update_anoms()
	local anoms = get_value("blowout_anoms",string.rep(string.char(128),math.ceil(amk_hideouts.anom_count/7)))
	anomalies_state = unpack_anoms(anoms)
	for i = amk_hideouts.anom_sid0,amk_hideouts.anom_sid0+amk_hideouts.anom_count-1,1 do
		local sobj = story_object(i)
		if sobj then
			local obj = level_object(sobj.id)
			if obj then
				if anomalies_state[i] then
					obj:enable_anomaly()
				else
					obj:disable_anomaly()
				end
			end
		end
    end
end

-- anom_state[sid]==true для активнvх аномалий
function pack_anoms(anom_state)
	local str = ""
	for i = 0,amk_hideouts.anom_count-1,7 do
		local cval = 128
		local mul = 1
		for j = 0,6,1 do
			if anom_state[i+j+amk_hideouts.anom_sid0] then
				cval = cval+mul
			end
		mul = mul*2
		end
		str = str..string.char(cval)
	end
	return str
end

function unpack_anoms(str)
	local anom = {}
	for i = 1,string.len(str),1 do
		local cval = string.byte(string.sub(str,i,i))
		local mul = 1
		for j = 0,6,1 do
			anom[(i-1)*7+j+amk_hideouts.anom_sid0] = bit_and(mul,cval) ~= 0
			mul = mul*2
		end
	end
	return anom
end

function blowout_type()
	local lname = level.name()
	local blow_type = amk_hideouts.blowout_types[lname]
	return blow_type or 0
end

-- Получение рецептов
function check_take_item(obj)
	local info = nil
	if obj:section() == "amk_zapiska" then
		if level.name() == "l01_escape" then
			info = "info_amk_recipt_shkura"
		elseif level.name() == "l04u_labx18" then
			info = "info_amk_recipt_simbion"
		elseif level.name() == "l08u_brainlab" then
			info = "info_amk_recipt_dummy_fire"
		elseif level.name() == "l03_agroprom" then
			sak.add_new_escape_100()
		else
			local recipes = table.load("amk_body_recipe")
			info = recipes[obj:id()]
		end
		amk.remove_item(obj)
	end
	if info == nil or has_info(info) then
		return
	end
	give_info(info)
	amk_dialogs.info_received()
end

function generate_recipe(obj)
	local info = nil
	local prop = 100

	if not info then return end

	local recipes = table.load("amk_body_recipe")
	-- Проверим не генерился ли уже этот рецепт
	for k,v in pairs(recipes) do
		if v == info then return end
	end
	-- Сгенерим рецепт
	if math.random(100) <= prob then
		recipes[obj:id()] = info
		table.save("amk_body_recipe",recipes)
	end
end

-- Спавн с НИ
function spawn_fuel()
	local ballons = {
		{108.16, -6.30, -18.17, 412158, 115},
		{370.12, 15.06, -39.48, 594401, 0},
		{58.30, 19.36, 156.50, 345136, 97},
		{-92.21, -1.18, -212.66, 115177, 268},
		{-74.17, 1.80, 8.45, 127766, 329},
		{3.18, 1.24, 42.48, 243919, 490},
		{15.35, -1.90, 2.40, 255433, 479},
		{77.54, 0.30, -108.47, 312366, 427},
		{-145.54, -0.00, -199.61, 92520, 650},
		{-130.08, 10.00, -196.67, 109214, 629},
		{-140.13, 10.00, -197.94, 98647, 629},
		{37.28, 1.02, -49.90, 220638, 1084},
		{476.68, -46.94, -0.23, 155714, 1919},
		{76.80, -2.54, -23.93, 36304, 1970},
		{94.78, 0.03, -6.88, 88986, 1514},
		{-3.24, -11.75, -263.07, 33794, 1448}
	}
	local kanisters = {
		{-293.80, -14.18, -15.36, 15703, 67},
		{-16.57, 2.48, 58.82, 260308, 88},
		{-74.81, -1.30, 160.52, 196218, 163},
		{-69.94, 0.97, 6.51, 131411, 329},
		{64.01, 0.60, 148.46, 235341, 364},
		{63.29, -0.20, 5.10, 299326, 461},
		{-28.52, -1.04, -181.84, 211644, 676},
		{2.93, -1.88, -13.30, 176553, 1047},
		{41.71, 4.54, -86.36, 227110, 1100},
		{7.90, 1.41, -71.93, 183138, 1041},
		{158.71, -0.76, -259.73, 358950, 962},
		{-342.92, -13.60, 390.01, 11235, 1847},
		{305.22, -36.99, -24.40, 68330, 1930},
		{55.02, 1.17, 40.35, 68094, 1511},
		{-114.14, -0.00, 121.75, 43453, 1315},
		{31.33, 5.60, -13.51, 4683, 1538}
	}
	for k,v in pairs(ballons) do
		if #v == 5 then
			create("amk_ballon",xyz(v[1], v[2], v[3]), v[4], v[5])
		end
	end
	for k,v in pairs(kanisters) do
		if #v == 5 then
			create("amk_kanistra",xyz(v[1], v[2], v[3]), v[4], v[5])
		end
	end
end

-- БТР на блокпосту
function spawn_military_btr()
	create_car("vehicle_btr",xyz(-168.11, -29.71, -303.21),81808,38, "scripts\\esc\\esc_blockpost_btr.ltx")
	create_car("vehicle_btr",xyz(-237.85, -26.23, -378.81),17147,14, "scripts\\esc\\esc_blockpost_btr.ltx")
	create_helicopter("helicopter",xyz(-150.0,-40.0,-620.0),128298,11 , "scripts\\esc\\esc_blockpost_heli.ltx")
end

-- Респавнеры  АМК
function switch_monster_online(obj)
	se_monster.need_be_online[obj.id]=true
end

function switch_monster_offline(obj)
	se_monster.need_be_online[obj.id]=false
end

function respawned(obj,respawner)
	if obj and (iAmMonster[obj:clsid()] or iAmStalker[obj:clsid()]) then
		local sini = respawner:spawn_ini()
		if sini:line_exist("respawn", "amk_respawn") then
			--log(obj:name(), respawner:name())
			local diff_koef = 1+level.get_game_difficulty()/6

			local cfg_name = 
				"[smart_terrains]\n"..
				"none = true\n"

			if sini:line_exist("respawn", "creature_binded_logic") then
				cfg_name = cfg_name.."[logic]\ncfg = scripts\\amk\\"..sini:r_string("respawn", "creature_binded_logic")..".ltx"
			elseif sini:line_exist("respawn", "free_monster") then
				-- просто гуляем по территории, нет логики
			else
				cfg_name = cfg_name..
					"[logic]\n"..
					"active = mob_home\n"..

					"[mob_home]\n"..
					"path_home = "..sini:r_string("respawn", "amk_name").."\n"..
					"aggressive_home\n"..
					"on_signal = sig_attacked | mob_combat\n"..

					"[mob_combat]\n"..
					"on_timer = ".. 30000*diff_koef .." | mob_home\n"
			end
			--log(cfg_name)
			obj:set_ini_lua_string(cfg_name)
		end
	end
end

local respawners={}

function init_unspawned_respawners(obj)
	local oini = obj:spawn_ini()
	if oini:line_exist("respawn", "amk_name") then
		local amk_name = utils.cfg_get_string(oini, "respawn", "amk_name", false, false, false, false)
		if amk_name then
			respawners[amk_name] = true
		end
	end
end

function spawn_unspawned_respawners()
	local sini = ini_file("scripts\\amk\\amk_respawns.ltx")
	local dv = sini:key_value("default_values")
	local amk_respawns = sini:list("amk_respawns")
	local diff_koef = 1+level.get_game_difficulty()/6	-- Коэффициент количества от уровня сложности
	local flag, t, xyzlg, respawner, tbl
	for k,v in pairs(amk_respawns) do
		flag = sini:r_bool("amk_respawns", v)
		if not respawners[v] and flag == true then
			t = sini:key_value(v)
			if t.xyzlg then
				xyzlg = t.xyzlg:parse_nums()
				if table.size(xyzlg)==5 then
					respawner = create("respawn",xyz(xyzlg[1],xyzlg[2],xyzlg[3]),xyzlg[4],xyzlg[5])
					tbl = netpacket:get(respawner)
					--tbl = respawner:get_ini_lua_table() -- ?????/
					t.xyzlg = nil
					t.amk_name = v
					for kkk,vvv in pairs(dv) do
						if t[kkk] == nil then
							t[kkk] = vvv
						end
					end
					-- Увеличиваем количество по уровню сложности
					t.max_count = math.floor(t.max_count*diff_koef)
					t.max_spawn = math.floor(t.max_spawn*diff_koef)

					tbl.custom_data:setTable({respawn=t})
					netpacket:set(tbl, respawner)
					--respawner:set_ini_lua_table({respawn=t})	-- ?????/				
					se_respawn.reinit_spawner_params(respawner:name())
				else
					log("! amk_mod.spawn_unspawned_respawners: invalid coords for "..tostring(v)..". ignoring!")
				end
			else
				log("! amk_mod.spawn_unspawned_respawners: invalid data for respawner "..v..". ignoring!")
			end
		end
		if flag == false then
			release(se_respawn.get_respawner_by_name(v))
		end
	end
end

-- Прочее
local last_armor_id = 0
local last_condition = 0

function repair_armor(val)
	local armor = db.actor:item_in_slot(inventory_slots.OUTFIT)
	if armor then
		last_armor_id = armor:id()
		last_condition = val
		armor:set_condition(val)
	end
end

btrs_friends = {}

function build_btrs_table(obj)
	if obj and (iAmStalker[obj:clsid()] and obj:character_community()=="military" and obj:alive()) or obj:section()=="vehicle_btr" then
		btrs_friends[obj:id()] = obj:section()
	end
end
