--news = {}
--[[
tips_icons = {
	default  = { 0, 658},      -- ui_iconsTotal_grouping
	trader	 = { 332, 893},    -- ui_iconsNpc_trader
	dolg     = { 0, 658},
	freedom  = { 0, 658},
	ecolog   = { 498, 0},      -- ui_iconsNpc_ecolog
	army     = { 332, 141},    -- ui_iconsNpc_stalker_neytral_balon_6
	stalker  = { 0, 658},
	csky  	 = { 0, 658},
	krot     = { 332, 47},     -- ui_iconsNpc_stalker_neytral_rukzak_4
	barman   = { 332, 235},    -- ui_iconsNpc_barman
	wolf	 = { 332, 940},    -- ui_iconsNpc_stalker_neytral_balon_1
	o_soznanie = { 498, 893},
	monolith = { 0, 658},
    saharov  = { 332, 470},    -- ui_iconsNpc_ucheniy_2
    prizrak  = { 0, 658},
    killer   = { 0, 658},
    bandit   = { 0, 658},
    renegade = { 0, 658}
}
]]
tips_icons = {
	bandit 		= "ui_npc_small_bandit_1",
	csky     	= "ui_npc_small_nebo_1",
	dolg		= "ui_npc_small_dolg_1",
	ecolog   	= "ui_iconsNpc_ecolog",
	freedom		= "ui_npc_small_freedom_1",
	killer		= "ui_npc_small_merc_2",
	army 		= "ui_npc_small_soldier_2",
	monolith	= "ui_npc_small_monolith_1",
    stalker		= "ui_npc_small_neutral_1",
	trader   	= "ui_iconsNpc_trader",
	zombied		= "ui_npc_small_zombied_1",
    renegade 	= "ui_npc_small_bandit_1",

	mar_csky_commander_name 		= "ui_npc_small_nebo_2_face_1",
	mar_csky_scientist_name 		= "ui_npc_small_nebo_2_face_2",
	mar_csky_tech_name				= "ui_npc_small_nebo_2_face_3",
	mar_csky_barman					= "ui_npc_small_nebo_2_face_4",

	escape_trader_name				= "ui_npc_small_trader_1",
	esc_leader_stalkerbase_name		= "ui_npc_small_neutral_2_face_2",
	esc_driver_name					= "ui_npc_small_soldier_1",
	esc_zak_stalkerbase_name		= "ui_npc_small_soldier_2_face_1",

	gar_bandit_leader_name			= "ui_npc_small_bandit_3_face_1",
	gar_bandit_barman_name			= "ui_npc_small_bandit_3_face_2",
	gar_digger_quester_name			= "ui_npc_small_neutral_2_face_1",

	agr_duty_base_commander_name 	= "ui_npc_small_dolg_2_face_1",
	agr_weaponmaster_name			= "ui_npc_small_dolg_2_mask",
    agr_barman_name					= "ui_npc_u_dolg_2_face_2",

--	val_freedom_trader_name			= "ui_npc_small_freedom_2_face_1",
	val_freedom_leader_name			= "ui_npc_small_freedom_2_face_2",
	val_freedom_trader_name			= "ui_npc_small_freedom_2_mask",

	red_forester_name				= "ui_npc_small_lesnik_1",

	yan_st_sakharov_name			= "ui_npc_small_ucheniy_1",
}


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

	--' Играем дефолтный звук
    xr_sound.set_sound_play(actor:id(), "pda_tips")


    local texture = "ui_iconsTotal_grouping"
    if sender ~= nil then
		if type(sender) == "string" then
	        if tips_icons[sender] then
	            texture = tips_icons[sender]
	        end
 		elseif is_npc_stalker(sender:clsid()) then
            texture = sender:character_icon()
		end
	end
	local news_caption = game.translate_string("st_tip")
	local news_text = game.translate_string(news_id)
--	actor:give_game_news(news_caption, news_text, texture, timeout*1000, showtime)
	actor:give_game_news(news_caption, news_text, texture, timeout*1000, showtime, 1)

	return true
end


function send_sound(npc, faction, point, str, str2)
	--callstack()
	if faction ~= nil then
		--printf("---------------------")
		--printf(tostring(faction))
        local point_name = ""
		if point ~= nil then
			local smart = sim_board.get_sim_board().smarts[point]
			if smart then
		        point_name = smart_names.get_smart_terrain_name(smart.smrt)
			else
				point_name = game.translate_string(point)
			end
		end
		--printf(point_name)
		local txt = ""
        if str2 == nil then
	        txt = string.gsub(str, "(characters_voice\\human_..\\)([^\\]*)", "%2")
	        txt = string.gsub(txt, "[\\]([^\\]*)", "_%1")
		else
			txt = str2
		end
		--printf("--->"..tostring(txt))

		local news_text = game.translate_string(txt)
		if news_text == txt then
			return
		end


--		callstack()
		--' Играем дефолтный звук
--	    xr_sound.set_sound_play(db.actor:id(), "pda_tips")

	    local texture = "ui_iconsTotal_grouping"
		if npc ~= nil and is_npc_stalker(npc:clsid()) then
            texture = npc:character_icon()
		else
	        if tips_icons[faction] then
	            texture = tips_icons[faction]
	        end
	        if tips_icons[point] then
	            texture = tips_icons[point]
	        end
		end
--		printf("--->texture="..tostring(texture))
		local news_caption = game.translate_string("st_tip").." "..game.translate_string(faction)
		if point_name ~= "" then
			news_caption = news_caption..". "..point_name..":"
		else
			news_caption = news_caption..":"
		end


--		db.actor:give_game_news(news_caption, news_text, texture, 1000, 5000)
		db.actor:give_game_news(news_caption, news_text, texture, 1000, 5000, 1)

		return true

    end
end

function is_npc_stalker(class_id)
	if class_id==clsid.script_stalker or
	   class_id==clsid.stalker or
	   class_id==clsid.script_trader or
	   class_id==clsid.trader then
	    return true
	end
    return false
end

local action_descr_by_type = {
	                            new = "general_new_task",
	                            complete = "general_complete_task",
	                            fail = "general_fail_task",
	                            reversed = "general_reverse_task"
	                         }

function send_task(actor, type, task)
	if db.actor == nil then
		return false
	end
    xr_sound.set_sound_play(db.actor:id(), "pda_task")
	local news_caption = game.translate_string(action_descr_by_type[type])
	local news_text = game.translate_string(task:get_title())
	local task_type = task_manager.get_task_manager():get_task_by_entity_id(tonumber(task:get_id())).type
    db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_"..task_type, 0, 15000)
--[[
	if db.actor:is_talking() then
        db.actor:give_talk_message2(news_caption, news_text, "ui_iconsTotal_"..task_type, "iconed_answer_item")
	else
	    db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_"..task_type, 0, 15000)
	end
]]
end

function send_treasure(name)
	local news_caption = game.translate_string("st_found_new_treasure")
	local news_text = game.translate_string(name)

	db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_found_thing", 0, 3000)
end

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

function relocate_item(actor, type, item, amount)
	if db.actor == nil then return false end
	--' Играем дефолтный звук
	if not amount then
		amount = 1
	end
	local news_caption = ""
	local news_text = ""
	if type == "in" then
		if amount == 1 then
			news_caption = game.translate_string("general_in_item")
			news_text = game.translate_string(get_inv_name(item))
		else
			news_caption = game.translate_string("general_in_item")
			news_text = game.translate_string(get_inv_name(item)).." x"..amount
		end
		if db.actor:is_talking() then
	        db.actor:give_talk_message2(news_caption, news_text, "ui_iconsTotal_found_thing", "iconed_answer_item")
		else
            db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_found_thing", 0, 3000)
		end
	elseif type == "out" then
		if amount == 1 then
			news_caption = game.translate_string("general_out_item")
			news_text = game.translate_string(get_inv_name(item))
		else
			news_caption = game.translate_string("general_out_item")
			news_text = game.translate_string(get_inv_name(item)).." x"..amount
		end
		if db.actor:is_talking() then
	        db.actor:give_talk_message2(news_caption, news_text, "ui_iconsTotal_lost_thing", "iconed_answer_item")
		else
			db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_lost_thing", 0, 3000)
		end
	end
end

function relocate_money(actor, type, amount)
	if db.actor == nil then return false end
	--' Играем дефолтный звук
	if type == "in" then
		local news_caption = game.translate_string("general_in_money")
		local news_text = game.translate_string(tostring(amount))

		if db.actor:is_talking() then
	        db.actor:give_talk_message2(news_caption, news_text, "ui_iconsTotal_found_money", "iconed_answer_item")
		else
			db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_found_money", 0, 3000)
		end
	elseif type == "out" then
		local news_caption = game.translate_string("general_out_money")
		local news_text = game.translate_string(tostring(amount))

		if db.actor:is_talking() then
	        db.actor:give_talk_message2(news_caption, news_text, "ui_iconsTotal_lost_money", "iconed_answer_item")
		else
			db.actor:give_game_news(news_caption, news_text, "ui_iconsTotal_lost_money", 0, 3000)
		end
	end
end
