
news = {
	tips_esc_trader_about_pda		= sound_object([[characters_voice\scenario\trader\trader_tutorial_contacts_1]]),
	tips_esc_trader_about_anomalies		= sound_object([[characters_voice\scenario\trader\trader_tutorial_anomalies_1]]),
	escape_stalker_killed			= sound_object([[characters_voice\scenario\trader\trader_tutorial_end_2]]),
	escape_stalker_helped			= sound_object([[characters_voice\scenario\trader\trader_tutorial_end_1]]),
	tutorial_trader_look_vagon		= sound_object([[characters_voice\scenario\trader\trader_tutorial_go_help_tolik_1]]),
	gar_dolg_warning				= sound_object([[characters_voice\scenario\duty\duty_warning1]]),
	esc_return_dv					= sound_object([[characters_voice\scenario\trader\return_from_dv]]),
	escape_fox_quest				= sound_object([[characters_voice\scenario\trader\trader_pda_fox]]),

	tips_agr_krot_sos				= sound_object([[characters_voice\scenario_eng\agroprom\krot_help_pda_1]]),
	tips_agr_krot_sos1				= sound_object([[characters_voice\scenario_eng\agroprom\krot_help_pda_2]]),
	tips_agr_krot_sos2				= sound_object([[characters_voice\scenario_eng\agroprom\krot_help_pda_2]]),
    tips_agr_stalker_help_2			= sound_object([[characters_voice\scenario_eng\agroprom\stalker_help_2]]),
    tips_agr_stalker_help_1			= sound_object([[characters_voice\scenario_eng\agroprom\stalker_help_1]]),

	tips_agr_trader_documents		= sound_object([[characters_voice\scenario\agroprom\trader_pda_1]]),

	bar_ecolog_crush_heli_down		= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_1]]),
	bar_freedom_attack_attract_actor= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_2]]),
	bar_freedom_spam_1				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_6]]),
	bar_freedom_spam_2				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_4]]),
	bar_freedom_spam_3				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_3]]),
	bar_freedom_spam_4				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_5]]),
	bar_freedom_attack				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_7]]),
	bar_freedom_attack_spy			= sound_object([[characters_voice\scenario\Rostok\Heli_crush\wolfhound_pda_8]]),
	bar_ecolog_crush_start_heli		= sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_1]]),
	bar_ecolog_crush_attract_actor  = sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_2]]),
	bar_ecolog_spam_1				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_3]]),
	bar_ecolog_spam_2				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_4]]),
	bar_ecolog_spam_3				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_5]]),
	bar_ecolog_spam_4				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_6]]),
	bar_ecolog_attack				= sound_object([[characters_voice\scenario\Rostok\Heli_crush\kruglov_pda_7]]),
    rostok_kruglov_spam_1			= sound_object([[characters_voice\scenario\Rostok\kruglov_pda_help_1]]),
    rostok_kruglov_spam_2			= sound_object([[characters_voice\scenario\Rostok\kruglov_pda_help_3]]),
	bar_ecolog_escape				= sound_object([[characters_voice\scenario\Rostok\volkodav_pda_kruglov_escape_1]]),
    storyline_vasilyev_tip			= sound_object([[characters_voice\scenario\yantar\vasiliev_pda]]),
    storyline_ghost_tip 			= sound_object([[characters_voice\scenario\yantar\ghost_pda]]),
    yan_saharov_message 			= sound_object([[characters_voice\scenario\yantar\professor_to_actor_pda_3]]),
	yan_saharov_message_2 			= sound_object([[characters_voice\scenario\yantar\professor_to_actor_pda_4]]),
    yan_saharov_message_3 			= sound_object([[characters_voice\scenario\yantar\professor_to_actor_pda_5]]),
	test_mega_remark 				= sound_object([[characters_voice\scenario\yantar\pda_professor_brain_quest_good_2]]),

	bar_psih_come					= sound_object([[characters_voice\scenario\bar\barman\barman_pda_psycho]]),

	bar_territory_dolg_1_hit		= sound_object([[characters_voice\scenario\bar\pda\voronin_gunfire_pda_1]]),
	bar_territory_dolg_2_hit		= sound_object([[characters_voice\scenario\bar\pda\voronin_gunfire_pda_2]]),
	bar_territory_dolg_3_hit		= sound_object([[characters_voice\scenario\bar\pda\voronin_gunfire_pda_3]]),
	bar_territory_dolg_kill			= sound_object([[characters_voice\scenario\bar\pda\voronin_gunfire_pda_4]]),
	
	tips_bun_komand                 = sound_object([[characters_voice\scenario\bun\patrol_prikaz]]),

	general_ecolog_tip_1            = sound_object([[characters_voice\scenario\yantar\professor_to_actor_pda_1]]),
    general_ecolog_tip_2            = sound_object([[characters_voice\scenario\yantar\professor_to_actor_pda_2]]),


    tips_gar_hellcar_alarm			= sound_object([[characters_voice\scenario\garbage\neutrals_commander_pda_1]]),
	gar_dolg_blokpost_warning		= sound_object([[characters_voice\scenario\duty\duty_warning1]]),
	gar_dolg_monster_rush			= sound_object([[characters_voice\scenario\duty\duty_request1]]),
	gar_direction_fire				= sound_object([[characters_voice\scenario\garbage\junkyard_combat_ambush]]),
	gar_hellcar_victory				= sound_object([[characters_voice\scenario\garbage\junkyard_combat_end]]),
	gar_actor_looser				= sound_object([[characters_voice\scenario\garbage\duty_after_rush_bad]]),
	gar_actor_normal				= sound_object([[characters_voice\scenario\garbage\duty_after_rush_normal]]),
	gar_actor_winner				= sound_object([[characters_voice\scenario\garbage\duty_after_rush_good]]),


	esc_direction_fire				= sound_object([[characters_voice\scenario\escape\lager_fanat_attack]]),
	esc_fanat_victory				= sound_object([[characters_voice\scenario\escape\lager_fanat_victory]]),
	esc_wolf_thanks					= sound_object([[characters_voice\scenario\escape\wolf_to_dialog]]),
	
	rad_barman_spam					= sound_object([[characters_voice\scenario\radar\rad_barman_message]]),


	val_monolith_trader_pda1		= sound_object([[characters_voice\scenario\val\trader_dialog1]]),
	o_soznanie_text					= sound_object([[characters_voice\scenario\sarcofag\o_soznanie_call]])
	
}

pda_news = sound_object([[device\pda\pda_news]])
pda_tips = sound_object([[device\pda\pda_tip]])
pda_task = sound_object([[device\pda\pda_objective]])

tips_icons = {
	trader	 = {   0, 100 },
	dolg     = { 150,   0 },
	freedom  = {   0, 150 },
	ecolog   = { 450, 100 },
	arena    = { 350, 150 },
	stalker  = { 100, 150 },
	krot     = { 200,  50 },
	barman   = { 400,  50 },
	wolf	 = { 0, 50 },
	o_soznanie = { 100, 50 },
	monolith = { 100, 150 },
    saharov  = { 450, 150 },
    prizrak  = {   0,  50 },
    killer   = {   0, 200 }
}


function send_news(actor, news_id, timeout, showtime)
	if db.actor == nil or news_id == nil then return false end

	if timeout == nil then timeout = 0 end
	if showtime == nil then showtime = 5000 end
	
	--' Играем дефолтный звук
	pda_news:play(db.actor, timeout, sound_object.s2d)	
	if news[news_id] ~= nil then
		--' Играем звук забитый	
		news[news_id]:play(db.actor, timeout+1, sound_object.s2d)
		
		--' Необходимо поставить время показа по длине сцены
		local length = news[news_id]:length()
		if length > showtime then
			showtime = length
		end
	end

	local news_text = "%c<255,160,160,160>".."news".."\\n".."%c<default>"..game.translate_string(news_id)
	db.actor:give_game_news(news_text, "ui\\ui_icons_task", Frect():set(0,100,50,50) ,timeout*1000, showtime)
end

function send_tip(actor, news_id, timeout, sender, showtime, sender_id)
	if news_id == nil then return false end
	printf("try to send tips for [%s]", tostring(sender_id))
	if sender_id ~= nil then
		local sim = alife()
		if sim ~= nil then
			local npc = sim:story_object(sender_id)
			if npc ~= nil then
				if npc.online then
					--в онлайне проверяем на раненность
					if xr_wounded.is_heavy_wounded_by_id(npc.id) then
						printf("[PDA]Cannot send tips [%s], sender is heavy wounded", tostring(news_id))
						return false
					end
				end
				-- в других случаях только на смерть
				if npc:alive() == 1 then
					printf("[PDA]Cannot send tips [%s], sender is dead", tostring(news_id))
					return false
				end
			end
		end
	end

	if timeout == nil then timeout = 0 end
	if showtime == nil then showtime = 5000 end

	--' Играем дефолтный звук
	pda_tips:play(db.actor, timeout, sound_object.s2d)
	if news[news_id] ~= nil then
		--' Играем звук забитый
		news[news_id]:play(db.actor, timeout+1, sound_object.s2d)

		--' Необходимо поставить время показа по длине сцены
		local length = news[news_id]:length()
		if length > showtime then
			showtime = length
		end
	end
	local x = 50
	local y = 100
	if sender ~= nil and tips_icons[sender] ~= nil then
		x = tips_icons[sender][1]
		y = tips_icons[sender][2]
	end
	local news_text = "%c<255,160,160,160>".."tip".."\\n".."%c<default>"..game.translate_string(news_id)
--temporary for e3 by andy !!!	actor:give_game_news(news_text, "ui\\ui_icons_task", Frect():set(x,y,50,50), timeout*1000, showtime)
    local task_texture, task_rect = get_texture_info("ui_icons_task_kill_stalker", "ui_iconsTotalSmall_locations")
	actor:give_game_news(news_text, task_texture, task_rect, timeout*1000, showtime)
	return true
end
function send_tip_nosound(actor, news_id, timeout, sender)
	if news_id == nil then return end

	showtime = 5000
	timeout = 0

	--' Играем дефолтный звук
	pda_tips:play(db.actor, timeout, sound_object.s2d)
	local news_sound = news[news_id]
	if news_sound ~= nil then
		--' Необходимо поставить время показа по длине сцены
		local length = news_sound:length()
		if length > showtime then
			showtime = length
		end
	end
	local x = 50
	local y = 100
	if sender ~= nil and tips_icons[sender] ~= nil then
		x = tips_icons[sender][1]
		y = tips_icons[sender][2]
	end
	local news_text = "%c<255,160,160,160>".."tip".."\\n".."%c<default>"..game.translate_string(news_id)
--temporary for e3 by andy !!!		actor:give_game_news(news_text, "ui\\ui_icons_task", Frect():set(x,y,50,50), timeout*1000, showtime)
    local task_texture, task_rect = get_texture_info("ui_icons_task_kill_stalker", "ui_iconsTotalSmall_locations")
	actor:give_game_news(news_text, task_texture, task_rect, timeout*1000, showtime)
	return news_sound
end

local action_descr_by_type = {
	new = "general_new_task",
	update = "general_update_task",
	complete = "general_complete_task",
	fail = "general_fail_task"
}
function send_task(actor, type, task)
	if db.actor == nil then return false end
	
	--' Берем координаты из текстуры таска
    local task_texture, task_rect = get_texture_info("ui_icons_task_"..task:get_id().."_small", "ui_iconsTotalSmall_locations")
        
	--' Играем дефолтный звук
	pda_task:play(db.actor, 0, sound_object.s2d)

	local news_text = "%c<255,160,160,160>"..game.translate_string(action_descr_by_type[type]).."\\n".."%c<default>"..game.translate_string(task:get_title())
	if db.actor:is_talking() then
		db.actor:give_talk_message(news_text, task_texture, task_rect,"iconed_answer_item")
	else
		db.actor:give_game_news(news_text, task_texture, task_rect, 0, 0)
	end	
end
function send_encyclopedy(type)
	pda_task:play(db.actor, 0, sound_object.s2d)
end

function get_inv_name(item)
	return system_ini():r_string(item:section(),"inv_name")
end

function relocate_item(actor, type, item)
	if db.actor == nil then return false end
	--' Играем дефолтный звук
	if type == "in" then
		local task_texture, task_rect = get_texture_info("ui_iconsTotal_found_thing_small")
		local news_text = "%c<255,160,160,160>"..game.translate_string("general_in_item").."\\n".."%c<default>"..game.translate_string(get_inv_name(item))
		db.actor:give_game_news(news_text, task_texture, task_rect, 0, 0)
		if db.actor:is_talking() then
			db.actor:give_talk_message(news_text, task_texture, task_rect,"iconed_answer_item")
		end		
	elseif type == "out" then
		local task_texture, task_rect = get_texture_info("ui_iconsTotal_lost_thing_small")
		local news_text = "%c<255,160,160,160>"..game.translate_string("general_out_item").."\\n".."%c<default>"..game.translate_string(get_inv_name(item))
		db.actor:give_game_news(news_text, task_texture, task_rect, 0, 0)
		if db.actor:is_talking() then
			db.actor:give_talk_message(news_text, task_texture, task_rect,"iconed_answer_item")
		end		
	end
	
end
function relocate_money(actor, type, amount)
	if db.actor == nil then return false end


	--' Играем дефолтный звук
	if type == "in" then
		local task_texture, task_rect = get_texture_info("ui_iconsTotal_found_money_small")
		local news_text = "%c<255,160,160,160>"..game.translate_string("general_in_money").."\\n".."%c<default>"..game.translate_string(tostring(amount))

		db.actor:give_game_news(news_text, task_texture, task_rect, 0, 0)
		if db.actor:is_talking() then
			db.actor:give_talk_message(news_text, task_texture, task_rect, "iconed_answer_item")
		end		
	elseif type == "out" then
		local task_texture, task_rect = get_texture_info("ui_iconsTotal_lost_money_small")
		local news_text = "%c<255,160,160,160>"..game.translate_string("general_out_money").."\\n".."%c<default>"..game.translate_string(tostring(amount))

		db.actor:give_game_news(news_text, task_texture, task_rect, 0, 0)
		if db.actor:is_talking() then
			db.actor:give_talk_message(news_text, task_texture, task_rect, "iconed_answer_item")
		end		
	end
	
end