--[[-----------------------------------------------------------------------------------------------
 File       : dialog_darkscape.script
 Description: Dialogs darkscape
 Copyright  : 2012 © LA-team
 Author     : vintar
 Editors    : lox(28.04.2013)
 Last edit  : 29.04.2017 [Skyloader and lox fix]
--]]-----------------------------------------------------------------------------------------------

--/ -----------------------------------------------------------------
--/ VARIABLEs
--/ -----------------------------------------------------------------
local keep_list = {
	["bolt"]              	     = true,
	["wpn_knife"]                = true,
	["binocular_a"]              = true,
	["sleeping_bag"]             = true,
	["device_torch"]             = true,
	["device_torch_adv"]         = true,
	["device_torch_eco"]         = true,
	["detector_simple"]          = true,
	["detector_advances"]        = true,
	["detector_elite"]           = true,
	["detector_af_simple"]       = true,
	["detector_af_simple_m1"]    = true,
	["detector_af_advanced"]     = true,
	["detector_af_elite"]        = true,
	["device_pda"]          	 = true,
	["xray_pda"]                 = true,
	["xray_pda_skills"] 		 = true,
	["xray_pda_downs"]			 = true,
	["gasmask"]                  = true,
	["item_battery"]             = true,
	["repair_kit"]               = true,
	["vodka"]                    = true,
	["vodka_b"]                  = true,
	["absolut_vodka"]            = true,
	["absolut_vodka_hud"]        = true,
	["nemiroff_vodka"]           = true,
	["smirnoff_vodka"]           = true,
	["mineral_water"]            = true,
	["energy_drink"]             = true,
	["energy_drink_nonstop"]     = true,
	["bread"]                    = true,
	["kolbasa"]                  = true,
	["conserva"]                 = true,
	["korn_conserva"]            = true,
	["olives_conserva"]          = true,
	["sardinia_conserva"]        = true,
	["yantar_food"]              = true,
	["peanut_conserva"]          = true,
	["tushenka_conserva"]        = true,
	["crow_meat"]                = true,
	["rat_meat"]                 = true,
	["antirad"]                  = true,
	["antidote"]                 = true,
	["bandage"]                  = true,
	["dolg_bandage"]             = true,
	["medkit"]                   = true,
	["medkit_army"]              = true,
	["medkit_scientic"]          = true,
	["esc_killed_flash"]         = true,
	["rad_lab_access_documents"] = true,
	["hermit_belongings"]        = true,
	["cit_doctors_key"]          = true,
	["cit_leader_killer_pda"]    = true,
	["af_electra_maddog"]        = true,
	["documents"]                = true,
	["dynamite"]                 = true,
	["esc_wounded_flash"]        = true,
	["quest_case_01"]            = true,
	["quest_case_02"]            = true,
	["gunslinger_flash"]         = true,
	["agr_strelok_book"]         = true,
	["val_key_to_underground"]   = true,
	["bar_tiran_pda"]            = true,
	["bar_lucky_pda"]            = true,
	["bar_ecolog_flash"]         = true,
	["lab_x16_documents"]        = true,
	["bar_vip_card"]       		 = true,
	["bad_psy_helmet"]           = true,
	["good_psy_helmet"]          = true,
	["kruglov_flash"]            = true,
	["righthand_pda"]            = true,
	["mil_svoboda_leader_pda"]   = true,
	["crazy_flash"]              = true,
	["cit_killers_documents"]    = true,
	["decoder"]                  = true,
	["pri_decoder_documents"]    = true,
	["dar_pass_document"]        = true,
	["dar_document1"]            = true,
	["dar_document2"]            = true,
	["dar_document3"]            = true,
	["dar_document4"]            = true,
	["dar_document5"]            = true,
	["af_electra_maddog"]        = true,
	["esc_maddog_pda"]           = true,
	["scientist_package"]        = true,
	["bandit_outfit"]            = true,
	["wpn_binoc"]				 = true,
	["esc_vagon_key"]			 = true,
	["wave_registrator_detector"] = true,
}

local out_object,in_object
--/ -------------------------
local sModule = script_name()
--/ -----------------------------------------------------------------
local log = function(fmt,...) _G.log(sModule..":"..tostring(fmt),...) end
--/ -----------------------------------------------------------------
--/ Process (functions)
--/ -----------------------------------------------------------------
local function transfer_object_item(item)
	if not keep_list[item:section()] then
		out_object:transfer_item(item, in_object)
	end
end

function give_bandit_gear()
 local stash = level_object_by_sid(7512)
 if stash then
  out_object = db.actor
  in_object = stash
  local bHasWeapon = false
  db.actor:iterate_inventory(
   function (dummy,oItem)
    if not bHasWeapon and oItem:section() == "wpn_mp5" then
     bHasWeapon = true
    else
     if not keep_list[oItem:section()] then
      out_object:transfer_item(oItem, in_object)
     end
    end
   end
  ,nil)
  if not bHasWeapon then
   Spawn_ItemsInInv("wpn_mp5", 1)
  end
	Spawn_ItemsInInv("bandit_outfit", 1)
	Spawn_ItemsInInv("ammo_9x19_fmj", 2)
	Spawn_ItemsInInv("xray_pda_downs", 1)
 else
	abort("cannot find stash with story_id 7512")
 end
end

function take_gear()
 local stash = level_object_by_sid(7512)
 if stash then
  out_object = db.actor
  in_object = stash
  local bHasWeapon = false
  db.actor:iterate_inventory(
   function (dummy,oItem)
    if not bHasWeapon and oItem:section() == "wpn_ak74" then
     bHasWeapon = true
    else
     if not keep_list[oItem:section()] then
      out_object:transfer_item(oItem, in_object)
     end
    end
   end
  ,nil)
  if not bHasWeapon then
   Spawn_ItemsInInv("wpn_ak74", 1)
  end
  Spawn_ItemsInInv("ammo_5.45x39_fmj", 2)
  Spawn_ItemsInInv("xray_pda_downs", 1)
 else
  abort("cannot find stash with sid 7512")
 end
end

function give_secret_docs(first, second)
	dialogs.relocate_item_section(second, "secret_documents", "out")
	start_real_timer(3, nil, {info_id = "ds_yantar_dolg_message"}) --/ 3 real-sec
end

function actor_has_bandit_suit()
	return db.actor:object("bandit_outfit") ~= nil
end

function actor_not_has_bandit_suit()
	return not actor_has_bandit_suit()
end

function ds_sin_has_another_artefact(oSpeaker1, oSpeaker2)
	return has_info("ds_prisoner_task_start") and oSpeaker1:object("af_electra_moonlight") ~= nil
end

function ds_check_sin_lead_death(oSpeaker1, oSpeaker2)
	dialogs.break_dialog(oSpeaker1, oSpeaker2)
	if has_info("ds_sin_death") then
		give_info("ds_actor_killed_sin")
	end
end

function give_borov_docs(oSpeaker1, oSpeaker2)
	local oNPC = dialogs.get_npc(oSpeaker1, oSpeaker2)
	dialogs.relocate_item_section(oNPC, "borov_docs")
end
--/ -----------------------------------------------------------------------------------------------