-- Биндер фотоаппарата

-- фото местности с указанных точек
local territory_from_places = {
	[1] = { -- Затон гаусс-установка
		--[[Точка, которую фотаем: 
			position	- позиция
			angle 		- угол захвата в градусах (точность фото)
			scope		- использовать ли зум (увеличение)
			time		- интервал времени, неважно если не задано
			rain		- фото в дождь если > 0, без дождя если = 0, неважно если не задано
			blowout		- диапазон фаз выброса, во время которых нужно фотать (1-5)
			loc			- территория (неважно если не задано)
			danger		- учитывать ли видимость гг врагами
			has_info	- поршень о наличии задания
			tip			- смс об успешном фото
		--]]
		position={x=-421.85653686523,y=26.832511901855,z=-382.17221069336}, angle=30, scope=false, loc="zaton", danger=false, has_info="volna_foto_start", tip=translate("bind_fot_pos_0"),
		places = {
			-- места, с которых нужно сфотать точку: позиция, радиус зоны для удачного фото, какой выдать поршень.
			{position={x=-427.55120849609,y=25.158079147339,z=-386.2109375}, radius=50.0, info="volna_foto_gauss1"},
			{position={x=-426.79205322266,y=25.159393310547,z=-378.66714477539}, radius=50.0, info="volna_foto_gauss2"},
			{position={x=-417.63455200195,y=24.198610305786,z=-386.77926635742}, radius=50.0, info="volna_foto_gauss3"},
			{position={x=-417.86773681641,y=24.281158447266,z=-377.49911499023}, radius=50.0, info="volna_foto_gauss4"}
		}
	},
	[2] = { -- Х-18 эмбрион
		position={x=25.546020889282,y=-9.0142399215698,z=-27.526565170288}, angle=30, scope=false, loc="l04u_labx18", danger=false, has_info="bar_dolg_petrenko_electra_flash_start", tip=translate("bind_fot_pos_1"),
		places = {
			{position={x=22.200523376465,y=-9.6393566131592,z=-26.628593444824}, radius=50.0, info="petrenko_foto_embrion1"},
			{position={x=13.896068572998,y=-8.6110229492188,z=-17.953956604004}, radius=50.0, info="petrenko_foto_embrion2"}
		}
	},
	[3] = { -- ЧАЭС2 Фото Стрелка
		position={x=106.22660064697,y=63.244293212891,z=126.69090270996}, angle=30, scope=false, loc="l12_stancia_2", danger=false, has_info="foto_strelok_start", tip=translate("bind_fot_pos_2"),
		places = {
			{position={x=-26.665603637695,y=0.29913738369942,z=201.48274230957}, radius=50.0, info="foto_strelok_done"}
		}
	},
	[4] = { -- Центральная Припять колесо обозрения
		position={x=111.86683654785,y=26.061452865601,z=206.71987915039}, angle=30, scope=false, rain=0, loc="l11_pripyat", danger=true, has_info="fotograf_detector_start", tip=translate("bind_fot_pos_3"),
		places = {
			{position={x=102.80764007568,y=8.4573526382446,z=424.2004699707}, radius=50.0, info="fotograf_foto_pripyat"}
		}
	},
	[5] = { -- Радар третья антенна Выжигателя
		position={x=-19.285640716553,y=32.639163970947,z=11.00645160675}, angle=30, scope=false, rain=0, loc="l10_radar", danger=true, has_info="fotograf_detector_start", tip=translate("bind_fot_pos_4"),
		places = {
			{position={x=62.16032409668,y=0.16300323605537,z=15.46067237854}, radius=50.0, info="fotograf_foto_radar"}
		}
	},
	[6] = { -- Армейские Склады место отдыха на базе Свободы
		position={x=-58.303810119629,y=-10.375316619873,z=25.44437789917}, angle=30, scope=false, rain=0, loc="l07_military", danger=true, has_info="fotograf_detector_start", tip=translate("bind_fot_pos_5"),
		places = {
			{position={x=-71.606269836426,y=8.0900650024414,z=-27.900075912476}, radius=50.0, info="fotograf_foto_sklady"}
		}
	},
	[7] = { -- Янтарь бункер учёных во время Выброса
		position={x=28.812911987305,y=-5.9429173469543,z=-270.12854003906}, angle=30, scope=false, loc="l08_yantar", danger=true, has_info="fotograf_detector_start", tip=translate("bind_fot_pos_6"),
		places = {
			{position={x=18.804416656494,y=-3.37455534935,z=-216.86245727539}, radius=50.0, info="fotograf_foto_yantar"}
		}
	},
	[8] = { -- Свалка ангар на закате
		position={x=-90.162956237793,y=15.896196365356,z=-2.5918385982513}, angle=30, scope=false, rain=0, loc="l02_garbage", danger=true, has_info="fotograf_detector_start", tip=translate("bind_fot_pos_7"),
		places = {
			{position={x=-68.128463745117,y=21.15146446228,z=-74.063751220703}, radius=50.0, info="fotograf_foto_svalka"}
		}
	},
	[9] = { -- Подземка Агропрома газета
		position={x=-118.44055938721,y=-3.9259724617004,z=-141.52922058105}, angle=30, scope=false, loc="l03u_agr_underground", danger=false, has_info="crazy_surgery_laperuz", tip=translate("bind_fot_pos_8"),
		places = {
			{position={x=-117.22961425781,y=-3.9744911193848,z=-142.36505126953}, radius=50.0, info="izdelie_foton_foto"}
		}
	}
	-- ,
	-- [10]={
		-- position={x=-421.85653686523,y=26.832511901855,z=-382.17221069336}, angle=1.5, scope=true, loc="zaton", danger=false, has_info="volna_foto_start", tip=translate("bind_fot_pos_0"),
		-- places = {
			-- {position={x=-117.22961425781,y=-3.9744911193848,z=-142.36505126953}, radius=0.5, info="izdelie_foton_foto"}
		-- }
	-- }
}

-- Таблица фото монстров. Секция = поршень при удачном фото. Поиск по точному совпадению.
local foto_ohota_monsters = {
	["dog_weak"]				= "foto_ohota_dog_red",
	["dog_normal"]				= "foto_ohota_dog_brown",
	["dog_strong"]				= "foto_ohota_dog_white",
	["dog_skeleton"]			= "foto_ohota_dog_orange",
	["dog_green"]				= "foto_ohota_dog_green",
	["dog_sil_hill"]				= "foto_ohota_dog_shill",
	["dog_zombie"]				= "foto_ohota_dog_doberman",
	["dog_habaruch"]			= "foto_ohota_dog_black",
	["dog_wolf"]				= "foto_ohota_dog_wolf",
	["dog_fox"]					= "foto_ohota_dog_fox",
	["pseudodog_weak"]		= "foto_ohota_psydog_brown",
	["pseudodog_normal"]		= "foto_ohota_psydog_brown",
	["pseudodog_big"]			= "foto_ohota_pseudodog_big",
	["pseudodog_strong"]		= "foto_ohota_psydog_grey",
	["psy_dog"]					= "foto_ohota_psydog_grey",
	["psy_dog_radar"]			= "foto_ohota_psydog_grey",
	["volkodav"]				= "foto_ohota_volkodav",
	["flesh_weak"]				= "foto_ohota_flesh",
	["flesh_normal"]				= "foto_ohota_flesh",
	["flesh_strong"]				= "foto_ohota_flesh",
	["flesh_swamp"]			= "foto_ohota_flesh_swamp",
	["zanoza"]					= "foto_ohota_zanoza",
	["boar_weak"]				= "foto_ohota_boar",
	["boar_normal"]				= "foto_ohota_boar",
	["boar_strong"]				= "foto_ohota_boar",
	["boar_kachok"]			= "foto_ohota_boar",
	["molerat"]					= "foto_ohota_molerat",
	["kikimora"]					= "foto_ohota_kikimora",
	["spider"]					= "foto_ohota_spider",
	["arahnid"]					= "foto_ohota_arahnid",
	["arahnid_strong"]			= "foto_ohota_arahnid_strong",
	["snork_stronger"]			= "foto_ohota_snork_stronger",
	["snork_outdoor"]			= "foto_ohota_snork",
	["snork_indoor"]			= "foto_ohota_snork",
	["aes_snork"]				= "foto_ohota_snork",
	["snork_strong"]				= "foto_ohota_snork",
	["snork_normal"]			= "foto_ohota_snork",
	["snork_weak"]				= "foto_ohota_snork",
	["snork_jumper"]			= "foto_ohota_snork_jumper",
	["vypolzen"]				= "foto_ohota_vypolzen",
	["vypolzen_red"]			= "foto_ohota_vypolzen_red",
	["snork_nosach"]			= "foto_ohota_snork_nosach",
	["nosales"]					= "foto_ohota_nosales",
	["tushkano_normal"]		= "foto_ohota_tushkan",
	["tushkano_strong"]			= "foto_ohota_tushkan_strong",
	["winger"]					= "foto_ohota_winger",
	["stinger"]					= "foto_ohota_stinger",
	["m_poltergeist_normal_tele"]	= "foto_ohota_polter_tele",
	["m_poltergeist_tele_outdoor"]	= "foto_ohota_polter_tele",
	["m_poltergeist_normal_flame"]	= "foto_ohota_polter_flame",
	["m_poltergeist_strong_flame"]	= "foto_ohota_polter_flame",
	["poltergeist_build"]			= "foto_ohota_polter",
	["m_poltergeist_dd"]		= "foto_ohota_poltergeist_dd",
	["electro_polter"]			= "foto_ohota_electro_polter",
	["polter_xray"]				= "foto_ohota_polter_xray",
	["bloodsucker_mil"]			= "foto_ohota_sucker_albinos",
	["bloodsucker_strong"]		= "foto_ohota_sucker",
	["bloodsucker_normal"]		= "foto_ohota_sucker_normal",
	["bloodsucker_weak"]		= "foto_ohota_sucker",
	["bloodsucker_effector"]	= "foto_ohota_sucker_boloto",
	["bloodsucker_child"]		= "foto_ohota_sucker_child",
	["bloodsucker_hell"]		= "foto_ohota_sucker_hell",
	["controller_tubeman"]		= "foto_ohota_controler",
	["m_controller_old_fat"]		= "foto_ohota_controler",
	["m_controller_old"]			= "foto_ohota_controler",
	["m_controller_normal_fat"]	= "foto_ohota_controler",
	["m_controller_normal"]		= "foto_ohota_controler",
	["controller_senator"]		= "foto_ohota_controler_senator",
	["controller_babka"]			= "foto_ohota_controler_babka",
	["m_controller_act"]			= "foto_ohota_kontroler_act",
	["controller_flame"]			= "foto_ohota_controler_flame",
	["controller_electro"]		= "foto_ohota_kontrik_electro",
	["psyonik"]					= "foto_ohota_psyonik",
	["gigant_virus_strong"]		= "foto_ohota_gigant_virus",
	["gigant_big_strong"]		= "foto_ohota_gigant",
	["gigant_strong"]			= "foto_ohota_gigant",
	["gigant_normal"]			= "foto_ohota_gigant",
	["gigant_red_strong"]		= "foto_ohota_gigant_red",
	["gigant_jumper"]			= "foto_ohota_gigant_jumper",
	["gigant_jumper_strong"]	= "foto_ohota_gigant_jumper",
	["burer_normal"]			= "foto_ohota_burer",
	["burer_weak"]				= "foto_ohota_burer",
	["burer_strong"]				= "foto_ohota_burer_strong",
	["burer_build"]				= "foto_ohota_burer_build",
	["burer_electro"]			= "foto_ohota_burer_electro",
	["m_burer_cop"]			= "foto_ohota_burer_cop",
	["karlito"]					= "foto_ohota_karlito",
	["carlic"]					= "foto_ohota_carlic",
	["carlic_weak"]				= "foto_ohota_carlic",
	["carlic_strong"]				= "foto_ohota_carlic",
	["chimera_weak"]			= "foto_ohota_chimera",
	["chimera_normal"]			= "foto_ohota_chimera_red",
	["electro_chimera"]			= "foto_ohota_chimera_electro",
	["chimera_x_ray"]			= "foto_ohota_chimera_prizrak",
	["new_electro_chimera"]	= "foto_ohota_new_electro",
	["chimera_strong"]			= "foto_ohota_chimera_white",
	["chimera_black"]			= "foto_ohota_chimera_black",
	["fire_chimera"]				= "foto_ohota_fire_chimera",
	["chimera_wolf"]			= "foto_ohota_chimera_wolf",
	["lican"]					= "foto_ohota_lican",
	["bear"]					= "foto_ohota_bear",
	["bear_big"]				= "foto_ohota_bear_big",
	["tarakan_strong"]			= "foto_ohota_tarakan_strong",
	["tarakan_normal"]			= "foto_ohota_tarakan",
	["rat_plague"]				= "foto_ohota_rat",
	["rat_strong"]				= "foto_ohota_rat",
	["rat_normal"]				= "foto_ohota_rat",
	["rat_weak"]				= "foto_ohota_rat",
	["cat_strong"]				= "foto_ohota_cat",
	["cat_normal"]				= "foto_ohota_cat",
	["cat_weak"]				= "foto_ohota_cat",
	["fracture_strong"]			= "foto_ohota_izlom",
	["fracture_normal"]			= "foto_ohota_izlom",
	["fracture_weak"]			= "foto_ohota_izlom",
	["fracture_master"]			= "foto_ohota_izlom_master",
	["fracture_karlik"]			= "foto_ohota_izlom_karlik",
	["bibliotekar"]				= "foto_ohota_biblik",
	["bibliotekar_black"]		= "foto_ohota_biblik_black",
	["deathclaw_strong"]		= "foto_ohota_kogot",
	["deathclaw_normal"]		= "foto_ohota_kogot_normal",
	["deathclaw_weak"]			= "foto_ohota_kogot_weak",
	["rotan"]					= "foto_ohota_rotan",
	["oboroten"]				= "foto_ohota_oboroten",
	["zombie_plague"]			= "foto_ohota_zombie_plague",
	["zombie_plague_komar"]	= "foto_ohota_zombie_plague_komar",
	["zombie_parazit"]			= "foto_ohota_zombie_parazit",
	["zombie_hell15"]			= "foto_ohota_zombie_hell15",
	["zombie_weak"]			= "foto_ohota_zombie",
	["zombie_normal"]			= "foto_ohota_zombie",
	["zombie_strong"]			= "foto_ohota_zombie",
	["zombie_trup"]				= "foto_ohota_zombie",
	["zombie_trup2"]			= "foto_ohota_zombie",
	["zombie_blow"]			= "foto_ohota_zombie",
	["zombie_beee"]			= "foto_ohota_zombie",
	["zombie_hell"]				= "foto_ohota_zombie",
	["zombie_hell1"]			= "foto_ohota_zombie",
	["zombie_hell2"]			= "foto_ohota_zombie",
	["zombie_hell3"]			= "foto_ohota_zombie",
	["zombie_hell4"]			= "foto_ohota_zombie",
	["zombie_hell5"]			= "foto_ohota_zombie",
	["zombie_hell6"]			= "foto_ohota_zombie",
	["zombie_hell7"]			= "foto_ohota_zombie",
	["zombie_hell8"]			= "foto_ohota_zombie",
	["zombie_hell9"]			= "foto_ohota_zombie",
	["zombie_hell10"]			= "foto_ohota_zombie",
	["zombie_hell11"]			= "foto_ohota_zombie",
	["zombie_hell12"]			= "foto_ohota_zombie",
	["zombie_hell13"]			= "foto_ohota_zombie",
	["zombie_hell14"]			= "foto_ohota_zombie",
	["zombie_hell16"]			= "foto_ohota_zombie",
	["zombie_hell17"]			= "foto_ohota_zombie_morlok",
	["zombie_hell18"]			= "foto_ohota_zombie_morlok",
	["zombie_babka_weak"]	= "foto_ohota_zombie_babka",
	["zombie_babka_normal"]	= "foto_ohota_zombie_babka",
	["zombie_babka_strong"]	= "foto_ohota_zombie_babka",
	["zombie_immortal"]		= "foto_ohota_zombie_immortal",
	["zombie_ghost"]			= "foto_ohota_zombie_ghost",
	["scelet_strong"]			= "foto_ohota_scelet_strong",
	["vodjanoj"]					= "foto_ohota_vodjanoj",
	["ghoul_strong"]				= "foto_ohota_ghoul_strong",
	["biomassa"]				= "foto_ohota_biomassa",
	["frog_mini"]				= "foto_ohota_frog",
	["komar"]					= "foto_ohota_komar",
	["fly_micro"]					= "foto_ohota_fly",
	["fly_small"]					= "foto_ohota_fly",
	["fly_ghost"]					= "foto_ohota_fly",
	["fly_plague"]				= "foto_ohota_fly",
	["bee_micro"]				= "foto_ohota_bee_micro",
	["new_hell"]					= "foto_ohota_new_hell"
}

local foto_unique_monster = {
	["white_wolf"]		= {has_info="ohota_wolf_start", info = "foto_ohota_white_wolf"},
	["eltush_normal"]	= {has_info="volk_anomaly_start", info = "foto_ohota_eltush_normal"},
	["eltush_strong"]	= {has_info="volk_anomaly_start", info = "foto_ohota_eltush_strong"},
	["fyreflyzloy"]		= {has_info="volk_anomaly_start", info = "foto_ohota_fyreflyzloy"}
}

local foto_ohota_anomaly = {
	["_zharka"]				= "foto_anomaly_zharka",
	["_galant"]				= "foto_anomaly_electra",
	["_buzz"]				= "foto_anomaly_holodec",
	["_fountain"]				= "foto_anomaly_fontan",
	["_mincer"]				= "foto_anomaly_karusel",
	["_mosquito_bald"]		= "foto_anomaly_tramplin",
	["_gravi_zone"]			= "foto_anomaly_voronka",
	["_ice"]					= "foto_anomaly_snow",
	["_sphere"]				= "foto_anomaly_puzyr",
	["_zavesa"]				= "foto_anomaly_tornado",
	["_smallrain"]			= "foto_anomaly_tuman",
	["_sakbuzz_average"]	= "foto_anomaly_oblako"
}

local foto_ohota_anomaly_text= {
	["foto_anomaly_zharka"]="task_foto_anomaly_1",
	["foto_anomaly_electra"]="task_foto_anomaly_2",
	["foto_anomaly_holodec"]="task_foto_anomaly_3",
	["foto_anomaly_fontan"]="task_foto_anomaly_4",
	["foto_anomaly_karusel"]="task_foto_anomaly_5",
	["foto_anomaly_tramplin"]="task_foto_anomaly_6",
	["foto_anomaly_voronka"]="task_foto_anomaly_7",
	["foto_anomaly_snow"]="task_foto_anomaly_8",
	["foto_anomaly_puzyr"]="task_foto_anomaly_9",
	["foto_anomaly_tornado"]="task_foto_anomaly_10",
	["foto_anomaly_tuman"]="task_foto_anomaly_11",
	["foto_anomaly_oblako"]="task_foto_anomaly_12"
}

-- Тихая охота монстров. Поиск по классу.
local silent_hunt_monsters = {
	[clsid.boar_s] 			= "boar_s",
	[clsid.bloodsucker_s] 	= "bloodsucker_s",
	[clsid.dog_s] 			= "dog_s",
	[clsid.flesh_s] 			= "flesh_s",
	[clsid.pseudodog_s] 	= "pseudodog_s",
	[clsid.burer_s] 			= "burer_s",
	[clsid.cat_s] 			= "cat_s",
	[clsid.chimera_s] 		= "chimera_s",
	[clsid.controller_s] 		= "controller_s",
	[clsid.fracture_s]	 	= "fracture_s",
	[clsid.gigant_s] 			= "gigant_s",
	[clsid.tushkano_s] 		= "tushkano_s",
	[clsid.snork_s]			= "snork_s"
}
local shm_replace_clsid={
	["controller_flame"]=clsid.controller_s
}

function init(obj)
    local new_binder = foto_binder(obj)
    obj:bind_object(new_binder)
end

class "foto_binder" (object_binder)
function foto_binder:__init(obj) super(obj)
end 

function foto_binder:reload(section)
    object_binder.reload(self, section)
end

function foto_binder:reinit()
    object_binder.reinit(self)
end

function foto_binder:net_save_relevant()
    return true
end

function foto_binder:save(packet)
    object_binder.save(self, packet)
end

function foto_binder:load(reader)
	object_binder.load(self, reader)
end

function foto_binder:net_spawn(data)
    if not object_binder.net_spawn(self, data) then
        return false
    end
    self.load = self.object:get_ammo_in_magazine()
    return true
end

function foto_binder:net_destroy()
    object_binder.net_destroy(self)
end

function foto_binder:update(delta)
    object_binder.update(self, delta)
	
	if db.actor:active_item() and db.actor:active_item():id() == self.object:id() then -- активен фотоаппарат
	
		--if self:check_territory_from_places() or self:check_creatures() or self:check_anomaly() then
		--end
        local load = self.object:get_ammo_in_magazine()
        if load < self.load and not has_info("ui_inventory") then -- разряжено, не инвентарь = выстрел

			-- if db.debug_mode then
				-- sms("foto_binder_update_0", nil, nil, 10000)
			-- end
			
			if self:check_creatures() or self:check_anomaly() or self:check_territory_from_places() then

			end
		end

		self.load = load
    end
end

-- фото местности с указанных точек
function foto_binder:check_territory_from_places()
	local a, b
	
	for i=1,#territory_from_places do
		a = territory_from_places[i]
		
		if has_info(a.has_info) and self:obj_in_shot(vector():set(a.position.x,a.position.y,a.position.z), 0, 1000, a.angle, a.scope, a.time, a.rain, a.blowout, a.loc, a.danger) then
			--log("Попали в цель")
			-- задание активно и попали в цель, проверяем ракурс
			for j=1,#territory_from_places[i].places do
				b = territory_from_places[i].places[j]

				if not has_info(b.info) and db.actor:position():distance_to(vector():set(b.position.x,b.position.y,b.position.z)) < b.radius then

					--log("Место фото правильное")
					-- этого снимка еще не было и ракурс правильный - засчитываем фото.
					sms(a.tip, nil, nil, 10000)
					give_info(b.info)

					
					return true
				end
			end
		end
	end
	
	return false
end

-- фото монстров и неписей
function foto_binder:check_creatures()
	local clsid, section
	
	--[[if db.actor:is_any_move() then --для фотки надо стоять на месте
		return false
	end]]
	
	for id,obj in pairs(db.creatures) do
		clsid = obj:clsid()
		section = obj:section()
		
		-- монстры
		if iAmMonster[clsid] --[[and obj:alive() and db.actor:see(obj)]] 
			and not protected_items.is_monster_friend(section) 
			and not section:endswith("_embrion")
		then
			-- сначала смотрим тихую охоту
			clsid=shm_replace_clsid[section] or clsid
			if  (has_info("silent_hunt_start") and not has_info("silent_hunt_done")) and
				(silent_hunt_monsters[clsid] and not has_info("monster_stealth_"..silent_hunt_monsters[clsid])) 
				--and	self:obj_in_shot(obj:bone_position("bip01_head"), 0, 2, 3.5, true, nil, nil, nil, nil, true)
			then
			
				clsid=shm_replace_clsid[section] or clsid
				-- удачный снимок и такого еще не было
				sms("%c[sender]"..translate("name_mechenii")..":\\n%c[sms_red]"..translate("sms_strelok_silent_hunt_1_0"), nil, nil, 10000, nil, [[sms\strelok\silent_hunt_1]])
				sms("%c[sender]"..translate("name_zahar")..":\\n%c[sms_red]"..translate("sms_zahar_silent_hunt_2_0"), 10, nil, 15000, nil, [[sms\zahar\silent_hunt_2]])
				give_info("monster_stealth_"..silent_hunt_monsters[clsid])

				
				return true
				
			-- затем фото уникальных монстров
			elseif 
				foto_unique_monster[section] and 
				has_info(foto_unique_monster[section].has_info) and not has_info(foto_unique_monster[section].info) and
				self:obj_in_shot(obj:center(), 0, 100, 25.0, false, nil, nil, nil, nil, false)
			then

				-- удачный снимок и такого еще не было
				sms("foto_binder_check_creatures_2", nil, nil, 10000)
				give_info(foto_unique_monster[section].info)


				return true

			-- затем обычную охоту
			elseif (has_info("foto_ohota_start") and not has_info("foto_ohota_done")) and
				foto_ohota_monsters[section] and not has_info(foto_ohota_monsters[section]) 
				--and self:obj_in_shot(obj:center(), 5, 10, 3.0, false, nil, nil, nil, nil, false)
			then

				-- удачный снимок и такого еще не было
				sms("foto_binder_check_creatures_3", nil, nil, 10000)
				give_info(foto_ohota_monsters[section])
			    local value = get_value("foto_ohota_value", 0)+1
			    set_value("foto_ohota_value", value)

				return true
			end
		end
	end
	
	return false
end

-- фото аномалий
function foto_binder:check_anomaly()
	if not has_info("foto_ohota_start") or has_info("foto_anomaly_done") then return false end

	local anoms = amk_anoms.get_anomaly_list(db.actor, 1000)
	for anom_sect, info in pairs(foto_ohota_anomaly) do
		if not has_info(info) then
			-- такого снимка еще не было, смотрим аномалии
			for _, anom in ipairs(anoms) do 	-- внутри это: {id=id,name=obj:name(),pos=o.pos,radius=o.radius}
				if string.find(anom.name, anom_sect) -- and self:obj_in_shot(anom.pos, 5, 10, 3.5, false, nil, nil, nil, nil, false) 

					then -- удачный снимок
					sms("foto_binder_check_anomaly_0", nil, nil, 10000)
					give_info(info)


					return true
				end
			end
		end
	end
	
	return false
end


function foto_binder:obj_in_shot(trg_pos, min_dist, max_dist, max_angle, use_scope, time, rain, blowout, trg_loc, actor_danger)

    if (trg_loc and trg_loc ~= level.name()) or 
		(use_scope and not bind_actor.scopeUsed) or
		(not use_scope and bind_actor.scopeUsed) or
		(time and (level.get_time_hours() < time[1] or level.get_time_hours() >= time[2])) or
		(rain and level.rain_factor() > rain+0.01) or
		(blowout and (get_value("blowout",-1) < blowout[1] or get_value("blowout",-1) > blowout[2])) or
		(actor_danger and db.actor:enemy_see_actor())
	then
		--log(""..(trg_loc and trg_loc.."="..level.name() or "")..", use_scope: "..tostring(use_scope).."="..tostring(bind_actor.scopeUsed)..(time and ", time: "..tostring(time[1])..","..tostring(time[2]).."="..level.get_time_hours() or "")..", rain: "..tostring(rain)..">"..level.rain_factor()..(blowout and ", blowout: "..tostring(blowout[1])..","..tostring(blowout[2]).."="..get_value("blowout",-1) or "")..", actor_danger: "..tostring(actor_danger))
		return false
	end

	local act_pos = screen.cam_pos
	local dist = act_pos:distance_to(trg_pos)
	if (dist >= min_dist) and (dist <= max_dist) then
		-- дистанция подходящая
		local trg_dir = vector():sub(trg_pos,act_pos):normalize()
		local angle_cos = screen.cam_dir:dotproduct(trg_dir)

		-- эффективный угол в пересчете на дистанцию в радианах
		local disp = math.sin(math.rad(max_angle))*max_dist -- дисперсия
		if disp > dist/2 then -- но не больше 30 градусов
			disp = dist/2
		end

		local eff_angle = math.asin(disp/dist)
		--log("disp: "..disp..", dist: "..dist..", angle_cos: "..angle_cos..", eff_angle cos: "..math.cos(eff_angle))
		if angle_cos >= math.cos(eff_angle) then
			return true
		end
	end

    return false
end

