-- nv100913 - internationalized a couple of phrases, some clean-up
-- nv091107 - "add_nothing" option for TZIO supported, equip slot fixed (now rifle slot)
-- nv111212 - Emergency shutdown notice support added
-- nv120307 - queue_entity_for_insertion, delayed timer support (non-persistent)
-- nv120320 - revised story item support, TZIO fixes for add_nothing
-- nv130224 - updated to support new bar_darklab_document_gain/_done usage in dialogs_bar.xml
-- nv140820 - re-added "Find out what happened to Ghost", re-ordered door messages per MrSeyker
-- nv150315 - support for more spawning
-- nv150321 - event cancellation support
-- nv150416 - deferred delete by id for 1.0006+ support of ammo destruction
-- nv150429 - attempt to speed up some table inserts via table[#table+1]=item
-- nv170408, nv170527 - use global actor, 0 for actor id, some cleanup

-- set true to make "Just equip for level" mean just complete the storyline, don't give stuff
add_nothing = false

delayed_enable_ui = false
delayed_exit      = false
local alarm_message = ""

local enable_note_death = true
local enable_show_MM_death_coords = true
local enable_show_create_count = true
local show_create_count = false

local delayed_release_item = false
local delayed_create_item = false
local delayed_mapspot_removal = false

local info_portion_queue = {}
local release_item_queue = {}
local create_entity_queue = {}
local create_item_queue = {}
local current_count_total = {}
local current_count_alive = {}

local delayed_event_queue = {}

local task_mapspot_queue = {}

function do_update()
	if delayed_exit then
		if zrp_notice then
			zrp_notice.ShowFatalError(alarm_message)
		else
			_z.show_large_msg(alarm_message.." - See log file.")
			_z.show_blinking_msg("Do NOT proceed until fixed!")
		end
		return
	end
	local this_level = level.name()
	for k,v in pairs(info_portion_queue) do
		if v.key ~= nil then
			if v.disable and has_alife_info(v.key) then
				dbglog("Update: Disabling info_portion %s", v.key)
				actor:disable_info_portion(v.key)
			elseif not v.disable and not has_alife_info(v.key) then
				dbglog("Update: Getting info_portion %s", v.key)
				actor:give_info_portion(v.key)
			end
		end
	end
	info_portion_queue = {}
	if delayed_enable_ui then
		xr_effects.enable_ui(actor, nil)
		delayed_enable_ui = false
	end
	if delayed_release_item then
		for k,v in pairs(release_item_queue) do
			local sobj = alife():object(v)
			if sobj then
				-- dbglog("releasing %s, id=%s",sobj:name(),v)
				alife():release(sobj,false)
			end
		end
		release_item_queue = {}
		delayed_release_item = false
	end
	if delayed_create_entity then
		local limit_reached = false
		local actor_lid = actor:level_vertex_id()
		local actor_gid = actor:game_vertex_id()
		-- dbglog("create_entity_queue size is "..#create_entity_queue)
		for k,v in pairs(create_entity_queue) do
			if limit_reached then break end
			if v.section == nil then
				dbglog("_dev.do_update(): no section for create entity!")
				break
			end
			if v.name == nil then v.name = v.section end
			if current_count_total[v.name] == nil then current_count_total[v.name] = 0 end
			if current_count_alive[v.name] == nil then current_count_alive[v.name] = 0 end
			if v.min ~= nil and v.min > 0 then
				if v.max == nil or v.max <= v.min then v.max = v.min + 1 end
				if v.level_max == nil or v.level_max < v.max then v.level_max = v.max end
				dbglog("current_count_total is %s for %s",current_count_total[v.name], v.name)
				local new_max = v.max - current_count_total[v.name]
				local new_min = v.min - current_count_total[v.name]
				if new_min < 0 then new_min = 0 end
				if new_max <= new_min then new_max = new_min + 1 end
				local new_count = math.random(new_min, new_max)
				-- dbglog("Max is %s, New count is %s",v.max, new_count)
				for cc_ = 1, new_count do
					local new_npc = alife():create(v.section, v.pos, v.lid or actor_lid, v.gid or actor_gid)
					switch_online(new_npc.id)
				end
				current_count_alive[v.name] = current_count_alive[v.name] + new_count
				dbglog("adding %s new %s",new_count, v.section)
				current_count_total[v.name] = current_count_total[v.name] + new_count
				if current_count_total[v.name] >= v.level_max then
					limit_reached = true
				end
			else
				alife():create(v.section, v.pos, v.lid or actor_lid, v.gid or actor_gid)
				dbglog("One new %s",v.section)
				current_count_alive[v.name] = current_count_alive[v.name] + 1
			end
		end
		create_entity_queue = {}
		delayed_create_entity = false
	end
	if enable_show_create_count and show_create_count then
		for k,v in pairs(current_count_alive) do
			if v > 0 then
				_z.nvDebug(game.translate_string(this_level)..":\\n"..tostring(v).." "..game.translate_string(k))
				if k ~= "stranger" then current_count_alive[k] = 0 end --nv150315 hack to reduce unnecessary notifications
			end
		end
		show_create_count = false
	end
	if delayed_create_item then
		for k,v in pairs(create_item_queue) do
			if v.section == nil then
				dbglog("_dev.do_update(): no section for create item!")
				break
			end
			if v.quantity == nil then v.quantity = 1 end
			for cc_ = 1, v.quantity do
				alife():create(v.section, v.pos, v.lid, v.gid, v.pid)
			end
		end
		create_item_queue = {}
		delayed_create_item = false
	end
	if delayed_mapspot_removal then
		for k,v in pairs(task_mapspot_queue) do
			-- do we need to breathe between spot removals?
			-- dbglog(">>>_z.task_mapspot_cleanup_deferred_for_sid=%s,_type=%s",v.sid, v.type)
			level_tasks.remove_location_safe(v.sid, v.type)
		end
		task_mapspot_queue = {}
		delayed_mapspot_removal = false
	end

end

function set_alarm_message(alarm_msg)
	alarm_message = alarm_msg
	delayed_exit = true
end

function execute_func(func_string)
	local response1, response2
	-- dbglog("Attempting to execute: "..func_string)
	local exec_func = loadstring(func_string)
	if type(exec_func) == "function" then
		response1, response2 = pcall(exec_func) -- returns true on success, false with error msg otherwise
		if response1 == false then
			dbglog(tostring(response2))
		end
	else
		dbglog("Delayed event string is not executable")
	end
end

function check_timer()
	bind_stalker.nv_timer_pending = false -- turn it off for the moment
	for k,v in pairs(delayed_event_queue) do
		-- these might need to be sorted eventually
		if v.delay < time_global() and not v.done then -- ready to fire
			v.done = true -- prevent re-entrancy if v.event takes too long
			execute_func(v.event)
			table.remove(delayed_event_queue, k)
		end
	end
	if #delayed_event_queue > 0 then
		bind_stalker.nv_timer_pending = true
		-- dbglog("timer task(s) pending: %d", #delayed_event_queue)
	end
end

function queue_delayed_event(event_struct)
	local msec_delay = tonumber(event_struct.delay)
	if msec_delay == nil or msec_delay <= 0 then
		dbglog("queue_delayed_event() - delay is invalid")
		return -- no timed event set
	end
	event_struct.done = false -- in case the same table is reused
	-- dbglog("queue_delayed_event() called with delay of %d",msec_delay)
	event_struct.delay = msec_delay + time_global()
	table.insert(delayed_event_queue, event_struct)
	-- delayed_event_queue[#delayed_event_queue+1] = event_struct
	bind_stalker.nv_timer_pending = true
end

function cancel_delayed_event(event_struct)
	local removed = false
	bind_stalker.nv_timer_pending = false -- turn it off for the moment
	for k,v in pairs(delayed_event_queue) do
		-- these might need to be sorted eventually
		if v == event_struct then
			table.remove(delayed_event_queue, k)
			removed = true
		end
	end
	if #delayed_event_queue > 0 then -- at least one event remains
		bind_stalker.nv_timer_pending = true
	end
	return removed
end

function queue_entity_for_insertion(entity_struct)
	-- table.insert(create_entity_queue, entity_struct)
	create_entity_queue[#create_entity_queue+1] = entity_struct
	delayed_create_entity = true
end

-- function queue_item_for_deletion(item_name) --old way
	-- table.insert(release_item_queue, {name = item_name})
	-- delayed_release_item = true
-- end

-- nv150416 deferred delete by id instead of name
function queue_item_for_deletion_by_id(item_id)
	-- table.insert(release_item_queue, item_id)
	release_item_queue[#release_item_queue+1] = item_id
	delayed_release_item = true
end

function queue_item_for_insertion(item_struct)
	-- table.insert(create_item_queue, item_struct)
	create_item_queue[#create_item_queue+1] = item_struct
	delayed_create_item = true
end

function queue_mapspot_for_removal(mapspot_struct)
	-- table.insert(task_mapspot_queue, mapspot_struct)
	task_mapspot_queue[#task_mapspot_queue+1] = mapspot_struct
	delayed_mapspot_removal = true
end

function queue_delayed_info(info_string, disable_flag)
	-- table.insert(info_portion_queue, {disable = disable_flag, key = info_string})
	info_portion_queue[#info_portion_queue+1] = {disable = disable_flag, key = info_string}
end

function set_current_count_total(name, value)
	if name ~= nil then current_count_total[name] = value end
	show_create_count = true
end

function set_current_count_alive(name, value)
	if name ~= nil then current_count_alive[name] = value end
	show_create_count = true
end

function note_death(npc, char_community)
	if not enable_note_death then return end
	if npc ~= nil then
		if current_count_alive[char_community] ~= nil then
			current_count_alive[char_community] = current_count_alive[char_community] - 1
			if char_community == "stranger" then
				local noticeString = npc:character_name()..": 'Monolith!'\\n"
				if enable_show_MM_death_coords then
					local npc_pos = npc:position()
					local posxz = string.format("%f, %f", npc_pos.x, npc_pos.z).."\\n"
					noticeString = noticeString..posxz
				end
				if current_count_alive[char_community] > 0 then
					_z.nvDebug(noticeString..
						tostring(current_count_alive[char_community]).." left in area")
				else
					_z.nvDebug(noticeString.."No other PDA signals detected")
				end
				--nv081011 removed (npc could be destroyed in anomaly before spot placed)
				-- -- nv081006 mark death location
				-- local str = "MonoMartyr".." "..npc:character_name()
				-- level.map_add_object_spot(npc:id(), "red_location", str)
			end
		end
	end
end

local msg = "none"

function jump_local(lc_name, game_vertex_id)
	local sim = alife()
	for id_ = 1, 65534, 1 do
		local lobj = sim:object(id_)
		if lobj ~= nil then
			if lobj:clsid() == clsid.level_changer then
				if lobj:name() == lc_name then
					if game_vertex_id == nil or
							game_vertex_id == lobj.m_game_vertex_id then
						local tpos = lobj.position
						tpos.y = tpos.y + 1
						actor:set_actor_position(tpos)
						return true
					end
				end
			end
		end
	end
	msg = "Level Changer "..lc_name.." not found"
	return false
end

function jump_somewhere(mmw, dik, keyboard_action)
	local garbage_jump = vector():set(27,16.557,685.8675)
	local escape_post_x18_jump = vector():set(345.363,15.06,-26.6)

	if level.name() == "l01_escape" then
		_z.save_current_pos_dir()
		actor:set_actor_direction(1)
		if dik == DIK_keys.DIK_G then
			actor:set_actor_position(garbage_jump)
			msg = "l02_garbage"
		elseif dik == DIK_keys.DIK_A then
			msg = "l03_agroprom"
			jump_local("jump_to_agroprom_01")
		elseif dik == DIK_keys.DIK_U then
			jump_local("jump_to_agroprom_underground_01")
			msg = "l03u_agr_underground"
		elseif dik == DIK_keys.DIK_B then
			msg = "l05_bar"
			if jump_local("jump_to_bar_01") == false then
				-- not a game based on 1.07 or later
				msg = "l05_bar"
				jump_local("exit_to_bar_01",9)
			end
		elseif dik == DIK_keys.DIK_D then
			msg = "l04_darkvalley"
			jump_local("jump_to_dark_valley_01")
		elseif dik == DIK_keys.DIK_8 then
			msg = "l04u_labx18"
			jump_local("jump_to_labx18_01")
		elseif dik == DIK_keys.DIK_C then
			msg = "l01_escape_dv"
			actor:set_actor_direction(-0.71)
			actor:set_actor_position(escape_post_x18_jump)
		elseif dik == DIK_keys.DIK_W then
			msg = "l06_rostok"
			jump_local("jump_to_rostok_01")
		elseif dik == DIK_keys.DIK_Y then
			msg = "l08_yantar"
			jump_local("jump_to_yantar_01")
		elseif dik == DIK_keys.DIK_L then
			msg = "l08_yantar_tunnels"
			jump_local("jump_to_yantar_tunnel_01")
		elseif dik == DIK_keys.DIK_6 then
			msg = "l08u_brainlab"
			jump_local("jump_to_brainlab_01")
		elseif dik == DIK_keys.DIK_M then
			msg = "l07_military"
			jump_local("jump_to_military_01")
		elseif dik == DIK_keys.DIK_R then
			msg = "l10_radar"
			jump_local("jump_to_radar_01")
		elseif dik == DIK_keys.DIK_9 or dik == DIK_keys.DIK_0 then
			msg = "l10u_bunker"
			jump_local("jump_to_bunker_01")
		elseif dik == DIK_keys.DIK_P then
			msg = "l11_pripyat"
			jump_local("jump_to_pripyat_01")
		elseif dik == DIK_keys.DIK_N then
			msg = "l12_stancia"
			jump_local("jump_to_stancia_01")
		elseif dik == DIK_keys.DIK_S then
			msg = "l12u_sarcofag"
			jump_local("jump_to_sarcophagus_01")
		elseif dik == DIK_keys.DIK_H then
			msg = "l12u_control_monolith"
			jump_local("jump_to_control_monolith_01")
		elseif dik == DIK_keys.DIK_2 or dik == DIK_keys.DIK_F then
			msg = "l12_stancia_2"
			jump_local("jump_to_stancia_02")
		else
			msg = "ui_zs_no_jump_found"
		end
	else
		msg = "ui_zs_must_be_in_cordon"
	end
	_z.show_large_msg(game.translate_string(msg))
	bind_stalker.nv_debug = false
	_z.remove_debug_static()
	get_console():execute("main_menu off")
end

local spawn_items = {}

-- if you don't already have any, get all
function add_if_needed(item, quantity)
	if not actor:object(item) then
		if quantity == nil then quantity = 1 end
		for i = 1, quantity do
			table.insert(spawn_items, item)
		end
	end
end

function remove_existing_unique(section_name)
	local sim = alife()
	for id_ = 1,65534,1 do
		local lobj = sim:object(id_)
		if lobj and lobj:section_name() == section_name then
			sim:release(lobj, true)
			break -- assumes there's only one
		end
	end
end

function add_unique_if_needed(section_name)
	remove_existing_unique(section_name)
	table.insert(spawn_items, section_name)
end

function set_money(amount)
	if actor:money() < amount then
		actor:give_money(amount - actor:money())
	end
end

function add_dark_valley_loadout()
	add_if_needed("wpn_pb")
	add_if_needed("wpn_mp5")
	add_unique_if_needed("wpn_ak74_m1")
	add_if_needed("ammo_9x18_fmj",3)
	add_if_needed("ammo_9x19_fmj",3)
	add_if_needed("ammo_5.45x39_fmj",5)
	add_if_needed("grenade_rgd5",5)
	add_if_needed("grenade_f1",2)
end

function add_rostok_loadout()
	add_dark_valley_loadout()
	add_if_needed("wpn_addon_scope")
	add_if_needed("wpn_addon_grenade_launcher")
	add_if_needed("ammo_vog-25",2)
	add_if_needed("af_cristall_flower",2)
	add_if_needed("af_fireball")
end

function add_yantar_loadout()
	add_if_needed("wpn_walther")
	add_if_needed("wpn_mp5")
	add_unique_if_needed("wpn_ak74_m1")
	add_if_needed("ammo_9x19_fmj",4)
	add_if_needed("ammo_5.45x39_fmj",5)
	add_if_needed("grenade_rgd5",5)
	add_if_needed("grenade_f1",2)
	add_if_needed("wpn_addon_scope")
	add_if_needed("wpn_addon_grenade_launcher")
	add_if_needed("ammo_vog-25",2)
	add_if_needed("wpn_lr300")
	add_if_needed("ammo_5.56x45_ss190",2)
	add_if_needed("wpn_addon_silencer")
	add_if_needed("af_cristall_flower",2)
	add_if_needed("af_fireball")
	add_if_needed("af_gravi")
	add_if_needed("af_electra_flash")
end

function add_radar_loadout()
	add_if_needed("wpn_walther")
	add_unique_if_needed("wpn_ak74_m1")
	add_if_needed("ammo_9x19_fmj",2)
	add_if_needed("ammo_5.45x39_fmj",3)
	add_if_needed("ammo_5.45x39_ap",2)
	add_if_needed("grenade_rgd5",4)
	add_if_needed("grenade_f1",2)
	add_if_needed("wpn_addon_scope")
	add_if_needed("wpn_addon_grenade_launcher")
	add_if_needed("ammo_vog-25",2)
	add_if_needed("wpn_g36")
	add_if_needed("ammo_5.56x45_ss190",2)
	add_if_needed("ammo_5.56x45_ap",5)
	add_if_needed("wpn_vintorez")
	add_if_needed("ammo_9x39_sp5",5)
	add_if_needed("wpn_addon_silencer")
	add_if_needed("protection_outfit")
	add_if_needed("af_cristall")
	add_if_needed("af_fireball")
	add_if_needed("af_ameba_mica")
	add_if_needed("af_dummy_glassbeads")
	add_if_needed("af_night_star")
	add_if_needed("af_cristall_flower")
	add_if_needed("af_electra_moonlight")
	add_if_needed("af_soul")
	table.insert(spawn_items, "antirad")
	table.insert(spawn_items, "antirad")
	table.insert(spawn_items, "antirad")
	table.insert(spawn_items, "antirad")
	set_money(40000) -- set_money(50001) for different monolith ending
end

function add_stancia_loadout()
	add_radar_loadout()
	add_if_needed("wpn_groza")
	add_if_needed("ammo_9x39_ap",3)
	add_if_needed("military_outfit")
end

function add_story_item_if_needed(section_name, required_info, remove_info)
	if required_info and has_alife_info(required_info) then
		remove_existing_unique(section_name)
		if remove_info and has_alife_info(remove_info) then
			return -- item no longer needed
		end
		table.insert(spawn_items, section_name)
	-- else requirement not yet met; do nothing
	end
end

function get_quest_items(this_level)
	spawn_items = {}
	-- add_if_needed("section"[,quantity])

	if add_nothing then
		add_if_needed("wpn_knife")
		this_level = "l01_escape" --ignore other loadouts
	else
		add_if_needed("wpn_knife")
		add_if_needed("antirad",3)
		add_if_needed("conserva",3)
		add_if_needed("bandage",10)
		add_if_needed("medkit",6)
		if _custom_zrp and _custom_zrp.use_my_special_loadout then
			_custom_zrp.add_my_special_loadout()
		end
	end
	-- keep these for objective support even if you use a special loadout
	if this_level == "l01_escape" then
	elseif this_level == "l02_garbage" then
		add_if_needed("bandit_outfit")
		set_money(4000)
		add_if_needed("wpn_pb")
		add_if_needed("wpn_mp5")
		add_if_needed("ammo_9x18_fmj",5)
		add_if_needed("ammo_9x19_fmj",4)
	elseif this_level == "l03_agroprom" then
		add_if_needed("bandit_outfit")
		set_money(4000)
		add_if_needed("wpn_pb")
		add_if_needed("wpn_mp5")
		add_if_needed("wpn_ak74u")
		add_if_needed("ammo_9x18_fmj",5)
		add_if_needed("ammo_9x19_fmj",4)
		add_if_needed("ammo_5.45x39_fmj",4)
	elseif this_level == "l03u_agr_underground" then
		add_if_needed("killer_outfit")
		set_money(4000)
		add_if_needed("wpn_pb")
		add_if_needed("wpn_mp5")
		add_if_needed("wpn_ak74")
		add_if_needed("ammo_9x18_fmj",2)
		add_if_needed("ammo_9x19_fmj",3)
		add_if_needed("ammo_5.45x39_fmj",4)
	elseif this_level == "l05_bar" then
		add_if_needed("stalker_outfit")
		set_money(4000)
		add_if_needed("wpn_pb")
		add_if_needed("wpn_mp5")
		add_unique_if_needed("wpn_ak74_m1")
		add_if_needed("ammo_9x18_fmj",3)
		add_if_needed("ammo_9x19_fmj",3)
		add_if_needed("ammo_5.45x39_fmj",5)
	elseif this_level == "l04_darkvalley" then
		add_if_needed("stalker_outfit")
		set_money(20000)
		add_dark_valley_loadout()
	elseif this_level == "l04u_labx18" then
		add_if_needed("stalker_outfit")
		set_money(20000)
		add_dark_valley_loadout()
		add_if_needed("wpn_addon_scope")
	elseif this_level == "k01_darkscape" then
		add_if_needed("stalker_outfit")
		set_money(20000)
		add_rostok_loadout()
	elseif this_level == "l06_rostok" then
		add_if_needed("dolg_outfit")
		set_money(30000)
		add_rostok_loadout()
	elseif this_level == "l08_yantar" then
		add_if_needed("dolg_outfit")
		set_money(30000)
		add_yantar_loadout()
	elseif this_level == "l08u_brainlab" then
		add_if_needed("protection_outfit")
		add_yantar_loadout()
		set_money(40000)
	elseif this_level == "l08_yantar_tunnels" then
		add_if_needed("protection_outfit")
		add_if_needed("lab_x16_documents")
		add_yantar_loadout()
		set_money(40000)
	elseif this_level == "l07_military" then
		add_yantar_loadout()
		add_if_needed("ammo_5.56x45_ap",2)
		add_if_needed("protection_outfit")
		set_money(40000)
	elseif this_level == "l10_radar" then
		add_radar_loadout()
	elseif this_level == "l10u_bunker" then
		add_radar_loadout()
	elseif this_level == "l11_pripyat" then
		add_radar_loadout()
	elseif this_level == "l12_stancia" then
		add_stancia_loadout()
	elseif this_level == "l12u_sarcofag" then
		add_stancia_loadout()
	elseif this_level == "l12u_control_monolith" then
		add_stancia_loadout()
		add_if_needed("wpn_fn2000")
	elseif this_level == "l12_stancia_2" then
		add_stancia_loadout()
		add_if_needed("wpn_fn2000")
	end
	add_story_item_if_needed("quest_case_02", "agroprom_military_case_have", "agroprom_military_case_done")
	add_story_item_if_needed("gunslinger_flash", "agr_gunslinger_flash_have", "sar_monolith_destroy")
	-- remove_info should be "bar_darklab_document_done", but it is deferred; use "good enough" alternative
	add_story_item_if_needed("dar_document4", "dar_document4", "bar_x16_documents_start")
	add_story_item_if_needed("quest_case_01", "escape_blockpost_case_have", "escape_blockpost_case_done")
	add_story_item_if_needed("bar_ecolog_flash", "bar_rescue_research_reward", "bar_deactivate_radar_start")
	add_story_item_if_needed("good_psy_helmet", "yan_find_vasilyev_start", "bar_deactivate_radar_done")
	add_story_item_if_needed("decoder", "pri_monolith_decoder_got", "sar_finish_decoding")

	-- local k,v = 0,0 -- nv170527 not used
	for k,v in pairs(spawn_items) do
		alife():create(v,
			actor:position(),
			actor:level_vertex_id(),
			actor:game_vertex_id(),
			0) --db.actor:id())
	end
	 actor:activate_slot(2)
end

local infos = {
	garbage = {
	"esc_kill_gunslinger",
	"storyline_actor_start",
	"global_dialogs",
	-- "level_changer_icons", -- nv140331 not used
	"esc_blockpost_normal",
	"esc_trader_experienced",
	"esc_trader_tutorial_chosen",
	"esc_trader_can_leave",
	"encyclopedy_tutorial_binocular",
	"encyclopedy_tutorial_crouch",
	"encyclopedy_tutorial_hide_weapon",
	"encyclopedy_tutorial_jump",
	"encyclopedy_tutorial_overload",
	"encyclopedy_tutorial_radiation",
	"encyclopedy_tutorial_relation",
	"encyclopedy_tutorial_sprint",
	"encyclopedy_tutorial_weakness",
	"encyclopedy_tutorial_weapon",
	"encyclopedy_tutorial_wound",
	"tutorial_part_15_hide_weapon",
	-- "tutorial_artefact_start",
	"tutorial_flesh_start",
	"tutorial_flesh_die",
	"tips_esc_trader_about_anomalies",
	-- "tutorial_artefact_gain",
	-- "tutorial_artefact_done",
	"tutorial_wounded_start",
	"esc_kill_bandits_quest_have",
	"esc_petruha_report",
	"esc_heli_go",
	"esc_tutorial_secret",
	"tutorial_wounded_help",
	"tutorial_end",
	"esc_heli_direct",
	"escape_factory_assault_say_hello",
	-- "esc_bandits_start",
	-- "esc_bandits_assault",
	-- "esc_assault_start",
	"tutorial_wounded_heal",
	-- "esc_prison",
	"esc_kill_bandits_quest_kill",
	-- "esc_petruha_report2",
	"tutorial_wounded_give_info",
	"esc_shustryi_secret",
	"esc_boar_dogs_restrictor",
	"esc_kill_bandits_quest_done",
	"esc_petruha_great",
	"esc_serious_talk",
	"agroprom_military_case",
	"esc_close_door",
	"esc_find_railroad_passage_find_stalker", -- nv140331 per MrSeyker
	"esc_find_railroad_passage_done",
	-- "esc_bridge_pass_fire", -- makes bridge soldiers shoot on sight
	"escape_stalker_meet",
	"escape_stalker_help",
	"escape_stalker_dog_spawn",
	"escape_stalker_dog_die",
	"escape_fox_heal",
	"escape_stalker_give",
	"garbage_meetstalker_start",
	"escape_stalker_done",
	"encyclopedy_zone_locations_escape",
	"encyclopedy_mutant_rat_general"
	},
	agroprom = {
	"gar_dm_bandit3_dead",
	"gar_dm_bandit2_dead",
	"gar_dm_bandit1_dead",
	-- "gar_add_fake_spot1",
	-- "gar_add_fake_spot4",
	"gar_start_graveyard",
	"gar_animation_radio",
	-- "gar_add_fake_spot2",
	"gar_start_quest",
	"gar_hellcar_help",
	"gar_bandits_raid",
	"gar_hellcar_alarm",
	"gar_direction",
	"gar_counter_fire",
	"gar_open_fire",
	"gar_bandit_leader_dead",
	"sar2_death_23",
	"gar_dm_novice_change_st",
	"gar_alarm",
	"gar_bandits_killed",
	-- "gar_hellcar_tips_end",
	"gar_hellcar_dialog_end",
	"gar_hellcar_thanks",
	-- "gar_add_fake_spot9",
	-- "gar_add_fake_spot10",
	-- "gar_add_fake_spot11",
	-- "gar_add_fake_spot5",
	-- "gar_add_fake_spot6",
	"gar_distance_shooting",
	"gar_seryi_actor_enter",
	"gar_seryi_meet",
	"gar_seryi_open_fire",
	"gar_seryi_counter_fire",
	"gar_begin_assault",
	"garbage_meetstalker_done",
	"agr_can_ask_krot_about_gunslinger",
	"agr_krot_band_start",
	"garbage_meetstalker_end",
	"gar_help_newbie_done"
	},
	agroprom_underground = {
	"agr_factory_heli_start",
	"agr_factory_assault_start",
	"agr_factory_assault_skirmish",
	"agr_meet_krot_band_done",
	"agr_attack_begin",
	"agr_help_stalkers_start",
	"agr_help_stalkers_done",
	"agr_help_stalkers_assault_dead",
	"agr_krot_skirmish_start",
	"agr_help_krot_done",
	"agr_factory_spawn_spetsnaz",
	"agr_krot_met",
	"agr_krot_go_to_well",
	"agr_krot_secret_info",
	"agr_find_gunslinger_cache_start",
	"agr_krot_task_complete",
	"agr_krot_band_done"
	},
	bar = {
	"agr_u_zombie_start",
	-- "agr_find_gunslinger_cache_found",
	"agr_gunslinger_flash_have", -- test
	"agr_find_gunslinger_cache_final",
	"agr_find_ghost_start", -- nv140820 given regardless of agr_krot_secret_info
	"agr_u_controller_start",
	"agr_sniper_killed_2",
	"agr_nii_alarm",
	"agr_nii_rupor_off",
	"agr_factory_spawn_spetznaz_start",
	"agr_sniper_killed_1",
	"agr_sniper_killed_3",
	"agroprom_military_case_have",
	"agr_nii_helicopter_atack",
	"gar_test_info1",
	-- "gar_kill_boars_quest",
	"gar_wounded_help",
	"gar_wounded_fight",
	"ui_pda_map_local",
	-- "gar_kill_boars_done",
	"gar_kill_boars_request",
	"gar_free_pass"
	},
	dark_valley = {
	"bar_scared_novice_attack",
	"bar_barman_stay_hole",
	"bar_dolg_base_rules_start",
	"agroprom_military_case_done",
	"agroprom_military_case_learn",
	"bar_darklab_document_start",
	"val_show_zones",
	"val_actor_has_barman_key"
	},
	lab_x18 = {
	"val_escort_begin",
	"val_nap1_phrase1_end",
	"val_halfdead_phrase_end",
	"val_nap1_stop_talk_to_bandit",
	"val_escort_task_start",
	"val_escort_start",
	"val_escort_actor_at_ambush",
	"val_escort_combat",
	"val_escort_actor_helped",
	"val_escort_captive_enemy",
	"val_escort_guard1_dead",
	-- "bar_arena_territory_death", -- nv090806 may not be needed
	"val_escort_guard2_dead",
	"val_escort_captive_phrase1_end",
	"val_escort_nap1_phrase1_end",
	"val_escort_got_reward",
	"val_escort_captive_give_main_info",
	"val_escort_captive_give_info",
	-- "val_escort_help_prisoner_task", -- starts "Free Captive" task
	-- "val_sos_start_task",
	-- "val_sos_actor_near_wounded",
	-- "val_sos_got_medkit",
	-- "val_show_farm_zone",
	-- "val_sos_give_info",
	"encyclopedy_mutant_crow_general",
	"val_sacrifice_spawn",
	"val_actor_on_bandits_base",
	"val_sacrifice_start",
	"val_sacrifice_guard2_dead",
	"val_sacrifice_victim_dead",
	"val_sacrifice_plr_detected",
	"val_sacrifice_finish",
	"val_sacrifice_guard1_dead",
	"val_lager_bandits_show_nedostroyka_company",
	"val_lager_bandits_show_leader_company",
	-- "val_prisoner_near_door",
	-- "val_prisoner_door_unlocked",
	-- "val_prisoner_free",
	"val_prisoner_give_info",
	"val_escort_scene_end",
	"val_actor_has_borov_key",
	"encyclopedy_zone_zone-story_story-raid",
	"val_actor_leave_bandits_base",
	"val_x18_door_open",
	"dar_run_quest"
	},
	lab_x18_done = {
	"dar_door1_closed",
	"dar_document1",
	"dar_document2",
	"dar_password_info1",
	"dar_password_info1_know",
	"dar_codelock1_unlock",
	"dar_open_door1",
	"dar_door2_closed", -- nv140820 moved up per MrSekyer to match PDA text to progress order
	"dar_document3",
	"dar_document4",
	"dar_password_info2",
	"dar_password_info2_know",
	"encyclopedy_zone_artifact_af-soul",
	"dar_codelock2_unlock",
	"dar_open_door2",
	"ui_pda_events",
	"ui_pda_news_hide",
	-- "dar_door3_closed", -- let players fight the pyrogeist
	-- "dar_door3_free", -- and don't start dream until it is dead
	"dar_x18_dream", -- prevent dream if freeplay (new game)
	"bar_darklab_document_gain",
	"dar_document5",
	"val_raid_start",
	"val_raid_go1",
	"val_raid_go2",
	"val_raid_go3",
	"val_chase_start",
	"val_raid_end"
	},
	wild_territory = {
	"val_come_to_trader_task",
	"esc_return",
	"esc_trader_speak",
	"esc_darklab_documents_read",
	"esc_trader_return",
	"escape_blockpost_case",
	"escape_blockpost_case_have",
	"escape_blockpost_case_done",
	"esc_blockpost_normal",
	"ui_pda_contacts",
	-- "bar_darklab_document_done", -- deferred to let trader task complete first
	"bar_x16_documents_start" --,
	-- "bar_heli_scene_stay_online"
	},
	yantar = {
	"rostok_sniper_1_die",
	"bar_arena_territory_death",
	"rostok_sniper_3_die",
	"rostok_sniper_2_die",
	"rostok_sniper_4_die",
	"bar_ecolog_crush_heli_start",
	"rostok_actor_kill_killer",
	"bar_freedom_attack_ecolog",
	"bar_ecolog_crush_heli_down",
	"bar_actor_heared_freedom_talk",
	"bar_kill_professor_volkodav_dead",
	"bar_heli_scene_volkodav_die",
	"sar2_death_44",
	"bar_rescue_research_start",
	"bar_freedom_defence_ecolog",
	"rostok_objective_1",
	"bar_kruglov_follow_actor",
	"bar_actor_helps_kruglov",
	"bar_rescue_research_chasing_start",
	"bar_rescue_research_chasing_end",
	"bar_bandits_alive",
	"bar_bandits_dead",
	"rostok_spawn_naemniki",
	"rostok_ambush_killer_2_die",
	"rostok_ambush_killer_1_die",
	"rostok_ambush_killer_3_die",
	"bar_ambush_dead",
	"bar_fire_anomaly_forward",
	"bar_kruglov_follow_tunnel",
	"bar_go_through_anomaly",
	"bar_rescue_research_follow",
	"bar_ecolog_research_normal",
	"bar_rescue_research_reward",
	"bar_rescue_research_done",
	},
	lab_x16 = {
	"yantar_scientists_talk",
	"yantar_kruglov_phrase_1",
	"yantar_professor_phrase_2",
	"yantar_kruglov_phrase_2",
	"yan_ecolog_outfit_given",
	"yantar_professor_talk_about_brain",
	"yan_find_scientist_start",
	"yan_find_scientist_task_start",
	"yan_kruglov_after_actor",
	"yan_scientist_point_to_1",
	"yantar_kruglov_talk",
	"yan_scientist_researching",
	--"yan_spawn_ghost",
	"yan_scientist_return_to_bunker",
	"yan_scientist_gulag_state_3",
	"yan_find_scientist_done",
	"yan_find_vasilyev_start",
	"yan_find_vasilyev_end",
	"encyclopedy_zone_anomalies_gravi"
	},
	yantar_tunnels = {
	"yan_find_laboratory_end",
	"yantar_vasilyev_info",
	"yan_zombied_respawn_01",
	"yan_zombied_respawn_02",
	"yan_zombied_respawn_04",
	"yan_zombied_respawn_08",
	"yan_zombied_respawn_05",
	"labx16_find",
	"yan_test_info",
	"yan_labx16_switcher_3_off",
	"yan_labx16_switcher_3_end",
	"yan_labx16_switcher_2_off",
	"yan_labx16_switcher_2_end",
	"yan_labx16_switcher_1_off",
	"yan_labx16_switcher_1_end",
	"yan_labx16_switcher_primary_off",
	"yantar_attack_start",
	"brain_snork_respawn_01",
	"yan_has_ghost_pda",
	"encyclopedy_zone_artifact_af-gold-fish",
	"yan_provodnik_spawn",
	"yantar_find_ghost_task_end",
	"yan_x16_documents_gain",
	"yan_kill_brain_task_start"
	},
	military_warehouses = {
	"yantar_tunnel_start",
	"yantar_tunnel_finish",
	"yan_kill_brain_done",
	"bar_psih_come",
	"bar_x16_documents_done",
	"esc_find_doctor_start",
	"agr_knockdown", -- nv090806 prevent agr_u explosion
	"esc_find_doctor_done",
	"cit_doctor_meet_conclusion_info",
	"cit_jail_doctor_pryp_task",
	"bar_deactivate_radar_start",
	"bar_dolg_base_rules_finish",
	"bar_dolg_base_pass",
	"bar_dolg_community_start",
	"bar_dolg_community_leader",
	"bar_svoboda_rg6_start",
	"mil_freedom_rg6_task"
	},
	red_forest = {
	"mil_actor_nearest",
	"mil_patrol_kill_continue",
	"mil_patrol_go_cover",
	"mil_patrol_man2_dead",
	"mil_patrol_man3_dead",
	"mil_patrol_man1_dead",
	"mil_patrol_dead",
	"encyclopedy_zone_artifact_af-electra-flash",
	"encyclopedy_social_stalker-clans_loners",
	"mil_zoneguard_talk",
	"mil_lukash_guard_talked",
	"mil_freedom_cook_rg6_ask",
	"mil_cook_question_already",
	"mil_svoboda_rg6_gain",
	"bar_svoboda_rg6_done",
	"mil_lukash_dolg_task",
	"mil_max_arrive",
	"mil_max_talk3",
	"mil_freedom_attack_continue1",
	"mil_scull_dead",
	"sar2_death_38",
	"mil_dolg_dead",
	"mil_freedom_arrive",
	"mil_lukash_dolg_task_complete",
	"mil_lukash_task_dolg_end",
	"mil_leader_quest2_start",
	"mil_actor_in_khutor_zone",
	"mil_courier_in_khutor_zone",
	"mil_actor_in_khutor_zone_inside",
	"mil_courier_call",
	"mil_courier_dead",
	"sar2_death_33",
	"mil_courier_khutor_leave",
	"mil_ara_entered",
	"mil_ara_arrive",
	"mil_ara_dead",
	"sar2_death_20",
	"encyclopedy_mutant_controller_general",
	"mil_leader_quest2_complete",
	"mil_lukash_blockpost",
	"mil_freedom_quests_end",
	"mil_blockpost_free_task",
	"mil_freedom_commander_talk",
	"mil_fblockpost_quest",
	"mil_fblockpost_rush_wave1",
	"mil_fblockpost_rush_wave2",
	"mil_fblockpost_rush_wave3",
	"mil_fblockpost_rush_wave4",
	"mil_fblockpost_quest_complete",
	"mil_fblockpost_quest_reward",
	"mil_fblockpost_actor_outside",
	"rad_pre_drop_barrel3",
	"rad_start_ambush_after_valley",
	"rad_start_ambush_before_tramplin",
	"rad_start_ambush_after_tramplin"
	},
	lab_x19 = {
	"rad_start_far_road_ambush",
	"rad_start_far_road_btr_ambush",
	"rad_here_i_come",
	"rad_pre_drop_barrel4",
	"rad_alarm",
	"rad_antennas_reached",
	"rad_bun_found",
	"rad_start_ambush_in_antenna_tunnel"
	},
	pripyat = {
	"bar_deactivate_radar_done",
	"bun_actor_fall",
	"bun_patrol_start",
	"sar_monolith_call",
	"bun_antenna_off",
	"rad_start_svoboda_vs_dolg",
	"rad_pre_start_monolith_vs_military",
	"rad_start_monolith_vs_military",
	},
	stancia_1 = {
	"pri_followers_leader_phrase1_end",
	"pri_followers_mission_accept",
	"pri_followers_start",
	"pri_helicopters_start",
	"pri_followers_heli_look",
	"pri_wave1_monolith3_dead",
	"pri_wave1_start",
	"pri_wave1_monolith2_dead",
	"pri_wave1_monolith1_dead",
	"pri_wave1_end",
	"pri_wave2_start_phrase",
	"pri_wave2_start",
	"pri_wave2_monolith1_dead",
	"pri_wave2_monolith3_dead",
	"pri_wave2_monolith2_dead",
	"pri_wave2_monolith4_dead",
	"pri_wave2_end",
	"pri_wave3_end",
	"pri_wave3_start",
	"pri_wave4_start_phrase",
	"pri_wave4_start",
	"pri_wave4_monolith5_dead",
	"pri_wave4_monolith1_dead",
	"pri_wave4_monolith3_dead",
	"pri_wave4_monolith4_dead",
	"pri_wave4_monolith2_dead",
	"pri_wave4_end",
	"pri_wave5_start",
	"pri_wave5_monolith1_dead",
	"pri_wave5_monolith4_dead",
	"pri_wave5_monolith3_dead",
	"pri_wave5_monolith2_dead",
	"pri_wave5_end",
	"pri_wave5_leader_phrase_end",
	"pri_wave6_start",
	"pri_wave6_monolith2_dead",
	"pri_wave6_monolith1_dead",
	"pri_wave6_end",
	"pri_monolith_spawn1",
	"pri_monolith_base_attacked",
	"pri_wave7_leader_phrase_start",
	"pri_wave7_leader_phrase_end",
	"pri_wave7_start",
	"pri_corner_start",
	"pri_undeground_respawn_start",
	"pri_wave7_end",
	"pri_show_zones",
	"pri_followers_leader_give_info",
	"pri_corner_end",
	-- "pri_followers_actor_leave",
	"pri_actor_in_hotel",
	"pri_decoder_docs_conclusion_info",
	"pri_followers_scene_end",
	"pri_aes_mapspot",
	"pri_actor_in_hiding_place",
	"pri_monolith_decoder_got",
	"pri_stadium_reached",
	"pri_stadium_scene_start"
	},
	sarcophagus = {
	"rad_task_aes",
	-- --"aes_arrive_to", -- NOTE: This makes some AW Freedom folks move/disappear
	-- "aes_first_sound",
	-- "aes_desant_go",
	-- "aes_gonduras_sound",
	-- "aes_2chopers_attack",
	-- "aes_actor_btr",
	-- "aes_zabor",
	-- "aes_first_wave_sound",
	-- "aes_actor_gate",
	-- "aes_monolit_blockpost2",
	-- "aes_uknown_sound",
	-- "aes_desant_wave3",
	-- "aes_choper_anomaly",
	-- "aes_actor_ambush5",
	-- "aes_actor_road",
	-- "aes_choper_hunt_1",
	-- "aes_desant_wave2",
	-- "aes_desant_wave1",
	-- "aes_road_sound2",
	-- "aes_actor_ambush",
	-- "aes_actor_road2",
	-- "aes_desant_wave4",
	-- "aes_desant_proceed1",
	-- "aes_rpg_sound1",
	-- "aes_rpg_sound2",
	-- "aes_actor_ambush3",
	-- "aes_sniper_desant_sound",
	-- "aes_desant_proceed3",
	-- "aes_actor_btr_ambush",
	-- "aes_lun_desant_sound",
	-- "aes_desant_proceed2",
	-- "aes_desant_wave7",
	"aes_found_sarcofag"
	},
	control_monolith = {
	"sar_monolith_find",
	"sar_secret_door_find",
	"sar_finish_decoding"
	},
	stancia_2 = {
	"sar_enter_command_center",
	"sar_monolith_destroy",
	"sar_monolith_off",
	"oso_question"
	-- ,"aes2_monolit_teleport_ready_final" --test for m_osoznanie removal
	},
	pda_finish = {
	"ui_inventory_hide",
	"ui_pda_hide"
	}
}

function get_info_portions(info_table)
	-- local actor = db.actor
	for k,v in pairs(infos[info_table]) do
		if has_alife_info(v) then
			dbglog("Already have info_portion %s", v)
		else
			dbglog("Getting info_portion %s", v)
			actor:give_info_portion(v)
		end
	end
end

function get_agroprom_u_info_portions()
	get_info_portions("garbage")
	get_info_portions("agroprom")
	get_info_portions("agroprom_underground")
	-- delayed key stuff, fix Seriy dialog
	-- queue_delayed_info(info_string, disable_flag)
	queue_delayed_info("agr_can_ask_krot_about_gunslinger", true)
end

function get_bar_info_portions()
	get_agroprom_u_info_portions()
	get_info_portions("bar")
	-- delayed key stuff, fix Mole task
	queue_delayed_info("agr_find_gunslinger_cache_found", false)
	bind_stalker.nv_need_update = true
end

function get_wild_territory_info_portions()
	get_bar_info_portions()
	get_info_portions("dark_valley")
	get_info_portions("lab_x18")
	get_info_portions("lab_x18_done")
	get_info_portions("wild_territory")
	-- -- delayed key stuff, fix trader return
	queue_delayed_info("bar_darklab_document_done", false)
	-- nv130224 this hack no longer needed with corrected logic in dialogs_bar.xml
	-- queue_delayed_info("bar_darklab_document_gain", true)
	bind_stalker.nv_need_update = true
end

function get_army_warehouses_info_portions()
	get_wild_territory_info_portions()
	get_info_portions("yantar")
	get_info_portions("lab_x16")
	get_info_portions("yantar_tunnels")
	get_info_portions("military_warehouses")
end

function get_stancia_1_info_portions()
	get_army_warehouses_info_portions()
	get_info_portions("red_forest")
	get_info_portions("lab_x19")
	get_info_portions("pripyat")
	get_info_portions("stancia_1")
end

function equip(mmw, dik, keyboard_action)
	dbglog("equip()")
	-- quest_items.main()
	local success = true
	local msg = "none"
	if dik == DIK_keys.DIK_G then
		get_info_portions("garbage")
		get_quest_items("l02_garbage")
		msg = "l02_garbage"
	elseif dik == DIK_keys.DIK_A then
		get_info_portions("garbage")
		get_info_portions("agroprom")
		get_quest_items("l03_agroprom")
		msg = "l03_agroprom"
	elseif dik == DIK_keys.DIK_U then
		get_agroprom_u_info_portions()
		get_quest_items("l03u_agr_underground")
		msg = "l03u_agr_underground"
	elseif dik == DIK_keys.DIK_B then
		get_bar_info_portions()
		get_quest_items("l05_bar")
		msg = "l05_bar"
	elseif dik == DIK_keys.DIK_D then
		get_bar_info_portions()
		get_info_portions("dark_valley")
		get_quest_items("l04_darkvalley")
		msg = "l04_darkvalley"
	elseif dik == DIK_keys.DIK_8 then
		get_bar_info_portions()
		get_info_portions("dark_valley")
		get_info_portions("lab_x18")
		get_quest_items("l04u_labx18")
		msg = "l04u_labx18"
	elseif dik == DIK_keys.DIK_C then
		get_bar_info_portions()
		get_info_portions("dark_valley")
		get_info_portions("lab_x18")
		get_info_portions("lab_x18_done")
		-- nv130224 now already given earlier
		-- actor:give_info_portion("bar_darklab_document_gain")
		get_quest_items("k01_darkscape")
		msg = "l01_escape_dv"
	elseif dik == DIK_keys.DIK_W then
		get_wild_territory_info_portions()
		get_quest_items("l06_rostok")
		msg = "l06_rostok"
	elseif dik == DIK_keys.DIK_Y then
		get_wild_territory_info_portions()
		get_info_portions("yantar")
		get_quest_items("l08_yantar")
		msg = "l08_yantar"
	elseif dik == DIK_keys.DIK_6 then
		get_wild_territory_info_portions()
		get_info_portions("yantar")
		get_info_portions("lab_x16")
		get_quest_items("l08u_brainlab")
		msg = "l08u_brainlab"
	elseif dik == DIK_keys.DIK_L then
		get_wild_territory_info_portions()
		get_info_portions("yantar")
		get_info_portions("lab_x16")
		get_info_portions("yantar_tunnels")
		get_quest_items("l08_yantar_tunnels")
		msg = "l08_yantar_tunnels"
	elseif dik == DIK_keys.DIK_M then
		get_army_warehouses_info_portions()
		get_quest_items("l07_military")
		msg = "l07_military"
	elseif dik == DIK_keys.DIK_R then
		get_army_warehouses_info_portions()
		get_info_portions("red_forest")
		get_quest_items("l10_radar")
		msg = "l10_radar"
	elseif dik == DIK_keys.DIK_9 or dik == DIK_keys.DIK_0 then
		get_army_warehouses_info_portions()
		get_info_portions("red_forest")
		get_info_portions("lab_x19")
		get_quest_items("l10u_bunker")
		msg = "l10u_bunker"
	elseif dik == DIK_keys.DIK_P then
		get_army_warehouses_info_portions()
		get_info_portions("red_forest")
		get_info_portions("lab_x19")
		get_info_portions("pripyat")
		get_quest_items("l11_pripyat")
		msg = "l11_pripyat"
	elseif dik == DIK_keys.DIK_N then
		get_stancia_1_info_portions()
		get_quest_items("l12_stancia")
		msg = "l12_stancia"
	elseif dik == DIK_keys.DIK_S then
		get_stancia_1_info_portions()
		get_info_portions("sarcophagus")
		get_quest_items("l12u_sarcofag")
		msg = "l12u_sarcofag"
	elseif dik == DIK_keys.DIK_H then
		get_stancia_1_info_portions()
		get_info_portions("sarcophagus")
		get_info_portions("control_monolith")
		get_quest_items("l12u_control_monolith")
		msg = "l12u_control_monolith"
	elseif dik == DIK_keys.DIK_2 or dik == DIK_keys.DIK_F then
		get_stancia_1_info_portions()
		get_info_portions("sarcophagus")
		get_info_portions("control_monolith")
		get_info_portions("stancia_2")
		actor:disable_info_portion("oso_init_dialog")
		get_quest_items("l12_stancia_2")
		msg = "Final_Level_or_Free_Play"
	else
		_z.show_large_msg("No supported equipment for keypress")
		success = false
	end
	if success then
		get_info_portions("pda_finish")
		_z.show_blinking_msg(game.translate_string("ui_zs_prepare_for").." "..game.translate_string(msg))
		-- dbglog("Got stuff")
	end

	-- hack fix for relationship problems for "freedom", "dolg" (Duty), "stalker"
	-- normal game_relations.ltx values: -400 = enemy, 0 = neutral, 500 = friend
	-- relation_registry.set_community_goodwill ("freedom", actor:id(), 0)
	-- relation_registry.set_community_goodwill ("dolg", actor:id(), 0)
	-- relation_registry.set_community_goodwill ("stalker", actor:id(), 0)

	bind_stalker.nv_debug = false
	_z.remove_debug_static()
	get_console():execute("main_menu off")
end
