-------------------------------------------------------------------------------- -- Dialog manager -------------------------------------------------------------- -- Made by Peacemaker ---------------------------------------------------------- -- 11.01.08 -------------------------------------------------------------------- -------------------------------------------------------------------------------- disabled_phrases = {} -- temporary table of phrases which have been disabled during a conversation local quest_disabled_phrases = {} -- temporary table of phrases which have been disabled during a conversation local id_counter = 5 -- start from 5 because of adding root phrases phrase_table = { hello = {}, job = {}, anomalies = {}, place = {}, information = {}, } priority_table = { hello = {}, job = {}, anomalies = {}, place = {}, information = {}, } -- Generate id for phrase function get_id() id_counter = id_counter + 1 return id_counter end -- Parse ini file and store all phrases and their parameters into phrase table function fill_phrase_table() printf("fill_phrase_table") -- local ltx file local dm_ini_file = ini_file("misc\\dialog_manager.ltx") local id = "" local value = "" local category = "" for i=0,dm_ini_file:line_count("list")-1 do temp1, id, temp2 = dm_ini_file:r_line("list", i, "", "") if(dm_ini_file:line_exist(id, "category")) then category = dm_ini_file:r_string(id, "category") if(category=="hello") then category = "hello" elseif(category=="anomalies") then category = "anomalies" elseif(category=="place") then category = "place" elseif(category=="job") then category = "job" elseif(category=="information") then category = "information" else category = "default" end else -- if there is no set category we don't know where we must store the phrase abort("Dialog manager error: not categoried section [%s].", id) end if(category~="default") then local temp_table = {} temp_table.name = id -- npc community: all or {dolg,freedom,bandit,military,zombied,ecolog,killer,monolith,csky...} if(dm_ini_file:line_exist(id, "npc_community")) then local temp = dm_ini_file:r_string(id, "npc_community") temp_table.npc_community = parse_names(temp) else temp_table.npc_community = "not_set" end -- level: all or level name if dm_ini_file:line_exist(id, "level") then local temp = dm_ini_file:r_string(id, "level") temp_table.level = parse_names(temp) else temp_table.level = "not_set" end -- actor community: all or {actor_dolg, actor, ...} if(dm_ini_file:line_exist(id, "actor_community")) then local temp = dm_ini_file:r_string(id, "actor_community") temp_table.actor_community = parse_names(temp) else temp_table.actor_community = "not_set" end -- is npc wounded? true, false if dm_ini_file:line_exist(id, "wounded") then temp_table.wounded = dm_ini_file:r_string(id, "wounded") else temp_table.wounded = "false" end -- phrase is said once: true, always, false(!!!don't set or will no say this phrase) if dm_ini_file:line_exist(id, "once") then temp_table.once = dm_ini_file:r_string(id, "once") else temp_table.once = "always" end if dm_ini_file:line_exist(id, "info") then if dm_ini_file:r_string(id, "info") ~= "" then temp_table.info = {} xr_logic.parse_infop1(temp_table.info, dm_ini_file:r_string(id, "info")) else temp_table.info = {} end else temp_table.info = {} end if category == "anomalies" or category == "place" then if dm_ini_file:line_exist(id, "smart") then temp_table.smart = dm_ini_file:r_string(id, "smart") else temp_table.smart = "" end end temp_table.id = tostring(get_id()) phrase_table[category][temp_table.id] = temp_table end end end -- Save function save_npc(packet, npc_id) set_save_marker(packet, "save", false, "dialog_manager") if(priority_table.hello[npc_id]~=nil) then packet:w_bool(true) --[[ local counter = 0 for phrase_id,priority in pairs(priority_table.hello[npc_id]) do counter = counter + 1 end packet:w_u16(counter) for phrase_id,priority in pairs(priority_table.hello[npc_id]) do if(phrase_id~="ignore_once") then packet:w_stringZ(tostring(phrase_id)) packet:w_u8(priority) else packet:w_stringZ(phrase_id) packet:w_bool(priority) end end ]] else packet:w_bool(false) end if(priority_table.job[npc_id]~=nil) then packet:w_bool(true) --[[ local counter = 0 for phrase_id,priority in pairs(priority_table.job[npc_id]) do counter = counter + 1 end packet:w_u16(counter) for phrase_id,priority in pairs(priority_table.job[npc_id]) do if(phrase_id~="ignore_once") then packet:w_stringZ(tostring(phrase_id)) packet:w_u8(priority) else packet:w_stringZ(phrase_id) packet:w_bool(priority) end end ]] else packet:w_bool(false) end if(priority_table.anomalies[npc_id]~=nil) then packet:w_bool(true) --[[ local counter = 0 for phrase_id,priority in pairs(priority_table.anomalies[npc_id]) do counter = counter + 1 end packet:w_u16(counter) for phrase_id,priority in pairs(priority_table.anomalies[npc_id]) do if(phrase_id~="ignore_once") then packet:w_stringZ(tostring(phrase_id)) packet:w_u8(priority) else packet:w_stringZ(phrase_id) packet:w_bool(priority) end end ]] else packet:w_bool(false) end if(priority_table.place[npc_id]~=nil) then packet:w_bool(true) --[[ local counter = 0 for phrase_id,priority in pairs(priority_table.place[npc_id]) do counter = counter + 1 end packet:w_u16(counter) for phrase_id,priority in pairs(priority_table.place[npc_id]) do if(phrase_id~="ignore_once") then packet:w_stringZ(tostring(phrase_id)) packet:w_u8(priority) else packet:w_stringZ(phrase_id) packet:w_bool(priority) end end ]] else packet:w_bool(false) end if(priority_table.information[npc_id]~=nil) then packet:w_bool(true) --[[ local counter = 0 for phrase_id,priority in pairs(priority_table.information[npc_id]) do counter = counter + 1 end packet:w_u16(counter) for phrase_id,priority in pairs(priority_table.information[npc_id]) do if(phrase_id~="ignore_once") then packet:w_stringZ(tostring(phrase_id)) packet:w_u8(priority) else packet:w_stringZ(phrase_id) packet:w_bool(priority) end end ]] else packet:w_bool(false) end set_save_marker(packet, "save", true, "dialog_manager") end -- Load function load_npc(reader, npc_id) set_save_marker(reader, "load", false, "dialog_manager") local is_saved = reader:r_bool() --[[ if(is_saved) then local counter = reader:r_u16() priority_table.hello[npc_id] = {} for i=1,counter do local phrase_id = reader:r_stringZ() if(phrase_id~="ignore_once") then priority_table.hello[npc_id][phrase_id] = reader:r_u8() else priority_table.hello[npc_id][phrase_id] = reader:r_bool() end end end ]] is_saved = reader:r_bool() --[[ if(is_saved) then local counter = reader:r_u16() priority_table.information[npc_id] = {} for i=1,counter do local phrase_id = reader:r_stringZ() if(phrase_id~="ignore_once") then priority_table.information[npc_id][phrase_id] = reader:r_u8() else priority_table.information[npc_id][phrase_id] = reader:r_bool() end end end ]] is_saved = reader:r_bool() --[[ if(is_saved) then local counter = reader:r_u16() priority_table.place[npc_id] = {} for i=1,counter do local phrase_id = reader:r_stringZ() if(phrase_id~="ignore_once") then priority_table.place[npc_id][phrase_id] = reader:r_u8() else priority_table.place[npc_id][phrase_id] = reader:r_bool() end end end ]] is_saved = reader:r_bool() --[[ if(is_saved) then local counter = reader:r_u16() priority_table.place[npc_id] = {} for i=1,counter do local phrase_id = reader:r_stringZ() if(phrase_id~="ignore_once") then priority_table.place[npc_id][phrase_id] = reader:r_u8() else priority_table.place[npc_id][phrase_id] = reader:r_bool() end end end ]] is_saved = reader:r_bool() set_save_marker(reader, "load", true, "dialog_manager") end -- Initialize npc start dialog function init_start_dialogs(dialog, str) local phrase = dialog:AddPhrase("", tostring(0), "", -10000) phrase = dialog:AddPhrase("", tostring(1), tostring(0), -10000) local script = phrase:GetPhraseScript() script:AddAction(string.format("dialog_manager.fill_priority_%s_table", str)) local ph = false for k,v in pairs(phrase_table[str]) do ph = true phrase = dialog:AddPhrase(v.name, tostring(v.id), tostring(1), -10000) if(phrase) then script = phrase:GetPhraseScript() script:AddPrecondition(string.format("dialog_manager.precondition_%s_dialogs", str)) -- script:AddPrecondition("dialog_manager.precondition_not_sim_action_dialog") script:AddAction(string.format("dialog_manager.action_%s_dialogs", str)) -- script:AddAction("dialog_manager.action_sim_action_dialog") if(v.wounded=="true") then script:AddPrecondition("dialogs.is_wounded") -- local bandage_id = get_id() local medkit_id = get_id() local sorry_id = get_id() local thanks_id = get_id() -- phrase = dialog:AddPhrase("dm_wounded_bandage", tostring(bandage_id), tostring(v.id), -10000) -- script = phrase:GetPhraseScript() -- script:AddPrecondition("dialogs.actor_have_bandage") -- script:AddAction("dialogs.transfer_bandage") -- script:AddAction("dialogs.break_dialog") -- phrase = dialog:AddPhrase("dm_wounded_thanks", tostring(thanks_id), tostring(bandage_id), -10000) phrase = dialog:AddPhrase("dm_wounded_medkit", tostring(medkit_id), tostring(v.id), -10000) script = phrase:GetPhraseScript() script:AddPrecondition("dialogs.actor_have_medkit") script:AddAction("dialogs.transfer_medkit") script:AddAction("dialogs.break_dialog") -- phrase = dialog:AddPhrase("dm_wounded_thanks", tostring(thanks_id), tostring(medkit_id), -10000) phrase = dialog:AddPhrase("dm_wounded_sorry", tostring(sorry_id), tostring(v.id), -10000) script = phrase:GetPhraseScript() script:AddAction("dialogs.break_dialog") else script:AddPrecondition("dialogs.is_not_wounded") end end end --[[ phrase = dialog:AddPhrase("dm_sim_action_attack_point_none", tostring(get_id()), tostring(1), -10000) script = phrase:GetPhraseScript() script:AddPrecondition("dialog_manager.precondition_sim_action_dialog") script:AddPrecondition("dialog_manager.precondition_sim_action_attack_point_none") script:AddAction("dialog_manager.action_sim_action_dialog") phrase = dialog:AddPhrase("dm_sim_action_attack_point_friend", tostring(get_id()), tostring(1), -10000) script = phrase:GetPhraseScript() script:AddPrecondition("dialog_manager.precondition_sim_action_dialog") script:AddPrecondition("dialog_manager.precondition_sim_action_attack_point_friend") script:AddAction("dialog_manager.action_sim_action_dialog") phrase = dialog:AddPhrase("dm_sim_action_attack_point_enemy", tostring(get_id()), tostring(1), -10000) script = phrase:GetPhraseScript() script:AddPrecondition("dialog_manager.precondition_sim_action_dialog") script:AddPrecondition("dialog_manager.precondition_sim_action_attack_point_enemy") script:AddAction("dialog_manager.action_sim_action_dialog") phrase = dialog:AddPhrase("dm_sim_action_stay_point_none_near", tostring(get_id()), tostring(1), -10000) script = phrase:GetPhraseScript() script:AddPrecondition("dialog_manager.precondition_sim_action_dialog") script:AddPrecondition("dialog_manager.precondition_sim_action_stay_point_none_near") script:AddAction("dialog_manager.action_sim_action_dialog") phrase = dialog:AddPhrase("dm_sim_action_stay_point_enemy_near", tostring(get_id()), tostring(1), -10000) script = phrase:GetPhraseScript() script:AddPrecondition("dialog_manager.precondition_sim_action_dialog") script:AddPrecondition("dialog_manager.precondition_sim_action_stay_point_enemy_near") script:AddAction("dialog_manager.action_sim_action_dialog") ]]-- if not(ph) then phrase = dialog:AddPhrase(string.format("dm_%s_general", str), tostring(v.id), tostring(1), -10000) end end ---- Initialize selected actor dialog --function init_actor_dialogs(dialog, str) -- printf(string.format("init_%s_dialogs", str)) ---- add actor question -- local phrase = dialog:AddPhrase(string.format("dm_%s_general", str), tostring(0), "", -10000) -- local script = phrase:GetPhraseScript() ---- set fill priority callback ---- script:AddPrecondition("dialog_manager.precondition_is_phrase_disabled") -- script:AddAction(string.format("dialog_manager.fill_priority_%s_table", str)) -- script:AddAction("dialog_manager.action_disable_phrase") ---- set default answer (if no avaliable) -- local answer = dialog:AddPhrase(string.format("dm_%s_no_more", str), tostring(1), tostring(0), -10000) -- local script = answer:GetPhraseScript() -- script:AddPrecondition(string.format("dialog_manager.precondition_%s_dialogs_no_more", str)) ---- add npc answers -- for k,v in pairs(phrase_table[str]) do -- phrase = dialog:AddPhrase(v.name, tostring(v.id), tostring(0), -10000) -- if(phrase) then -- script = phrase:GetPhraseScript() -- script:AddPrecondition(string.format("dialog_manager.precondition_%s_dialogs", str)) -- script:AddAction(string.format("dialog_manager.action_%s_dialogs", str)) -- end -- end --end -- Initialize new actor dialog function init_new_dialog(dialog) local actor_table = { [1] = "job", [2] = "anomalies", --[3] = "place", [3] = "information", } local start_phrase_table = { [1] = "dm_universal_npc_start_0", [2] = "dm_universal_npc_start_1", [3] = "dm_universal_npc_start_2", [4] = "dm_universal_npc_start_3", } local precond_table = { [1] = "dialogs.npc_stalker", [2] = "dialogs.npc_bandit", [3] = "dialogs.npc_freedom", [4] = "dialogs.npc_dolg", } printf("init_new_actor_dialog") local actor_phrase = dialog:AddPhrase("dm_universal_actor_start", tostring(0), "", -10000) local actor_script = actor_phrase:GetPhraseScript() for j = 1, 4 do local npc_phrase = dialog:AddPhrase(start_phrase_table[j], tostring(j), tostring(0), -10000) local npc_phrase_script = npc_phrase:GetPhraseScript() npc_phrase_script:AddPrecondition(precond_table[j]) for i = 1,#actor_table do local index = get_id() local str = actor_table[i] local phrase = dialog:AddPhrase("dm_"..str.."_general", tostring(index), tostring(j), -10000) local script = phrase:GetPhraseScript() if str == "anomalies" then script:AddPrecondition("dialogs.npc_stalker") end --script:AddPrecondition("dialog_manager.precondition_is_phrase_disabled") script:AddAction("dialog_manager.fill_priority_"..str.."_table") --script:AddAction("dialog_manager.action_disable_phrase") for k = 1,3 do local answer_no_more = dialog:AddPhrase("dm_"..str.."_no_more_"..tostring(k), tostring(get_id()), tostring(index), -10000) local script_no_more = answer_no_more:GetPhraseScript() script_no_more:AddPrecondition("dialog_manager.precondition_"..str.."_dialogs_no_more") local answer_do_not_know = dialog:AddPhrase("dm_"..str.."_do_not_know_"..tostring(k), tostring(get_id()), tostring(index), -10000) local script_do_not_know = answer_do_not_know:GetPhraseScript() script_do_not_know:AddPrecondition("dialog_manager.precondition_"..str.."_dialogs_do_not_know") end for k,v in pairs(phrase_table[str]) do phrase = dialog:AddPhrase(v.name, tostring(v.id), tostring(index), -10000) if(phrase) then script = phrase:GetPhraseScript() script:AddPrecondition("dialog_manager.precondition_"..str.."_dialogs") script:AddAction("dialog_manager.action_"..str.."_dialogs") end end end local actor_exit_phrase = dialog:AddPhrase("dm_universal_actor_exit", tostring(get_id()), tostring(j), -10000) end end -- Fill selected priority table function fill_priority_table(npc, PT_subtable, PRT_subtable) local npc_id = npc:id() if(PRT_subtable[npc_id]==nil) then -- if subtable for npc is not set - create it PRT_subtable[npc_id] = {} end for num, phrase in pairs(PT_subtable) do -- calculate priority for each phrase local pr = calculate_priority(PRT_subtable, phrase, npc, phrase.id) log("--->phrase ["..phrase.name.."] priority ["..pr.."]") end end function is_told(npc, str) if priority_table[str][npc:id()] and priority_table[str][npc:id()].told and priority_table[str][npc:id()].told == true then return true else return false end end -- Calculate precondition for default phrase in information dialog function precondition_no_more(npc, str) local pr, id = get_highest_priority_phrase(phrase_table[str], priority_table[str], npc) if(pr<0) or (id==0) then -- if there is no phrase with priority greater than -1 or there is no phrases in table printf("there is no avaliable "..str.." dialogs") -- show default phrase return true else return false end end -- Calculate phrase's preconditions function precondition(npc, PT_subtable, PRT_subtable, phrase_id) if PRT_subtable[npc:id()] and PRT_subtable[npc:id()].told and PRT_subtable[npc:id()].told == true then return false end -- recalculate current phrase priority local priority = calculate_priority(PRT_subtable, PT_subtable[phrase_id], npc, phrase_id) -- if current phrase is with highest priority - show it return is_highest_priority_phrase(PT_subtable, PRT_subtable, npc, phrase_id) end -- Calculate phrase priority function calculate_priority(PRT_subtable, PTID_subtable, npc, phrase_id) local f_level = false local f_comm = false local priority = -1 local npc_id = npc:id() if(PTID_subtable.npc_community=="not_set") then f_comm = true elseif(PTID_subtable.npc_community[1]=="all") then priority = priority + 1 f_comm = true else for i=1,#PTID_subtable.npc_community do if(PTID_subtable.npc_community[i]==character_community(npc)) then priority = priority + 2 f_comm = true break end end priority = priority - 1 end if(PTID_subtable.level=="not_set") then f_level = true elseif(PTID_subtable.level[1]=="all") then priority = priority + 1 f_level = true else for i=1,#PTID_subtable.level do if(PTID_subtable.level[i]==level.name()) then priority = priority + 2 f_level = true break end end end if(PTID_subtable.actor_community=="not_set") then priority = priority + 0 elseif(PTID_subtable.actor_community=="all") then priority = priority + 1 else for i=1,#PTID_subtable.actor_community do if(PTID_subtable.actor_community[i]==character_community(db.actor)) then priority = priority + 2 break end end end if(PTID_subtable.wounded=="true") then --if not(xr_wounded.is_heavy_wounded_by_id(npc:id())) then if not(xr_wounded.is_wounded(npc)) then priority = -1 else priority = priority + 1 end else --if(xr_wounded.is_heavy_wounded_by_id(npc:id())) then if(xr_wounded.is_wounded(npc)) then priority = -1 else priority = priority + 1 end end if f_comm == false or f_level == false then priority = -1 end if(PRT_subtable[npc:id()].ignore_once) then if(PTID_subtable.once=="true") then priority = -1 end end if(PRT_subtable[npc_id][phrase_id]~=nil) and (PRT_subtable[npc_id][phrase_id]==255) then -- if there was set the highest priority for phrase priority = 255 end for k,v in pairs(PTID_subtable.info) do if v.name then if v.required == true then if not has_alife_info(v.name) then priority = -1 break end else if has_alife_info(v.name) then priority = -1 break end end --[[ elseif v.func then if v.expected == true then else end ]]-- end end PRT_subtable[npc_id][phrase_id] = priority return priority end -- Set phrase end action function told(PRT_subtable, npc) PRT_subtable[npc:id()].told = true end function action(PT_subtable, PRT_subtable, cur_phrase_id, npc) if not(PRT_subtable[npc:id()].ignore_once) then if(PT_subtable[cur_phrase_id].once=="true") then set_phrase_highest_priority(PRT_subtable, npc:id(), cur_phrase_id) end PRT_subtable[npc:id()].ignore_once = true end end -- Set the highest priority to selected phrase function set_phrase_highest_priority(PRT_subtable, npc_id, phrase_id) if(PRT_subtable[npc_id]~=nil) then PRT_subtable[npc_id][phrase_id] = 255 else PRT_subtable[npc_id] = {} PRT_subtable[npc_id][phrase_id] = 255 end end -- Reset phrase priority function reset_phrase_priority(PT_subtable, PRT_subtable, npc, phrase_id) local npc_id = npc:id() if(PRT_subtable[npc_id]~=nil) then PRT_subtable[npc_id][phrase_id] = -1 else -- if there is no such npc id in table then create it PRT_subtable[npc_id] = {} -- and calculate priority for this phrase PRT_subtable[npc_id][phrase_id] = calculate_priority(PRT_subtable, PT_subtable[phrase_id], npc, phrase_id) end end -- Is the phrase priority the highest? function is_highest_priority_phrase(PT_subtable, PRT_subtable, npc, phrase_id) local npc_id = npc:id() if(PRT_subtable[npc_id]~=nil) then -- if there is a subtable for this npc local id = phrase_id local pr = PRT_subtable[npc_id][phrase_id] if pr < 0 then return false end for phr_id, priority in pairs(PRT_subtable[npc_id]) do -- iterate through array to get if selected phrase is with the highest priority if(phr_id~="ignore_once" and phr_id~="told") then if(priority>pr) then return false end end end return true else -- if there is no subtable for this npc - create it reset_phrase_priority(PT_subtable, PRT_subtable, npc, phrase_id) return false end end -- Get the phrase with the highest priority function get_highest_priority_phrase(PT_subtable, PRT_subtable, npc) local npc_id = npc:id() if(PRT_subtable[npc_id]~=nil) then -- if there is a subtable for this npc local id = 0 local pr = -1 for phr_id, priority in pairs(PRT_subtable[npc_id]) do -- iterate through array for the highest priority phrase if(phr_id~="ignore_once" and phr_id~="told") then if(priority>pr) then pr = priority id = phr_id end end end return pr, id else -- if there is no subtable for this npc - create it reset_phrase_priority(PT_subtable, PRT_subtable, npc, phrase_id) return -1, 0 end end -------------------------------------------------------------------------------- -- Initializing, filling priority tables, setting preconditions and actions -------------------------------------------------------------------------------- -- Initialize npc hello start dialog function init_hello_dialogs(dialog) init_start_dialogs(dialog, "hello") end -- Fill phrase priority table for hello start dialog function fill_priority_hello_table(actor, npc, dialog_name, phrase_id) fill_priority_table(npc, phrase_table.hello, priority_table.hello) end -- Fill phrase priority table for new dialog function fill_priority_job_table(actor, npc, dialog_name, phrase_id) fill_priority_table(npc, phrase_table.job, priority_table.job) end function fill_priority_anomalies_table(actor, npc, dialog_name, phrase_id) fill_priority_table(npc, phrase_table.anomalies, priority_table.anomalies) end --function fill_priority_place_table(actor, npc, dialog_name, phrase_id) -- fill_priority_table(npc, phrase_table.place, priority_table.place) --end function fill_priority_information_table(actor, npc, dialog_name, phrase_id) fill_priority_table(npc, phrase_table.information, priority_table.information) end -- Calculate precondition for phrases in hello start dialog function precondition_hello_dialogs(npc, actor, dialog_name, parent_id, id) return precondition(npc, phrase_table.hello, priority_table.hello, id) end -- Set phrase end action for hello start dialog function action_hello_dialogs(npc, actor, dialog_name, id) action(phrase_table.hello, priority_table.hello, id, npc) end -- Calculate precondition for default phrase in occupation dialog function precondition_job_dialogs_no_more(npc, actor, dialog_name, parent_id, id) if is_told(npc, "job") == true then return true end return false end function precondition_job_dialogs_do_not_know(npc, actor, dialog_name, parent_id, id) return precondition_no_more(npc, "job") end -- Calculate preconditions for phrases in occupation dialog function precondition_job_dialogs(npc, actor, dialog_name, parent_id, id) return precondition(npc, phrase_table.job, priority_table.job, id) end -- Set phrase end action for occupation dialog function action_job_dialogs(npc, actor, dialog_name, id) action(phrase_table.job, priority_table.job, id, npc) told(priority_table.job, npc) end -- Calculate precondition for default phrase in anomalies dialog function precondition_anomalies_dialogs_no_more(npc, actor, dialog_name, parent_id, id) if is_told(npc, "anomalies") == true then return true end return false end function precondition_anomalies_dialogs_do_not_know(npc, actor, dialog_name, parent_id, id) return precondition_no_more(npc, "anomalies") end -- Calculate preconditions for phrases in anomalies dialog function precondition_anomalies_dialogs(npc, actor, dialog_name, parent_id, id) local smart = xr_gulag.get_npc_smart(npc) if smart ~= nil and tostring(smart:name()) == phrase_table.anomalies[id].smart then priority_table.anomalies[npc:id()][id] = -1 return false end return precondition(npc, phrase_table.anomalies, priority_table.anomalies, id) end -- Set phrase end action for information dialog function action_anomalies_dialogs(npc, actor, dialog_name, id) action(phrase_table.anomalies, priority_table.anomalies, id, npc) told(priority_table.anomalies, npc) end --[[ -- Calculate precondition for default phrase in place dialog function precondition_place_dialogs_no_more(npc, actor, dialog_name, parent_id, id) local f_place = false if is_told(npc, "place") == true then return true end local smart = xr_gulag.get_npc_smart(npc) if not smart then return true end for k,v in pairs(phrase_table.place) do if smart:name() == v.smart then for i = 1,#v.level do if level.name() == v.level[i] then f_place = true break end end end if f_place == true then break end end if f_place == false then return true end return precondition_no_more(npc, "place") end -- Calculate preconditions for phrases in place dialog function precondition_place_dialogs(npc, actor, dialog_name, parent_id, id) local smart = xr_gulag.get_npc_smart(npc) if smart ~= nil then if tostring(smart:name()) ~= phrase_table.place[id].smart then priority_table.place[npc:id()][id] = -1 return false end else priority_table.place[npc:id()][id] = -1 return false end return precondition(npc, phrase_table.place, priority_table.place, id) end -- Set phrase end action for place dialog function action_place_dialogs(npc, actor, dialog_name, id) action(phrase_table.place, priority_table.place, id, npc) told(priority_table.place, npc) end ]]-- -- Calculate precondition for default phrase in information dialog function precondition_information_dialogs_no_more(npc, actor, dialog_name, parent_id, id) if is_told(npc, "information") == true then return true end return false end function precondition_information_dialogs_do_not_know(npc, actor, dialog_name, parent_id, id) return precondition_no_more(npc, "information") end -- Calculate preconditions for phrases in information dialog function precondition_information_dialogs(npc, actor, dialog_name, parent_id, id) return precondition(npc, phrase_table.information, priority_table.information, id) end -- Set phrase end action for information dialog function action_information_dialogs(npc, actor, dialog_name, id) action(phrase_table.information, priority_table.information, id, npc) told(priority_table.information, npc) end local rnd = 0 function precondition_is_phrase_disabled(fs,ss,dn,ppi,pi) local npc = dialogs.who_is_npc(fs, ss) if(pi=="") then pi = dn end if (disabled_phrases[npc:id()] and disabled_phrases[npc:id()][pi]) or (quest_disabled_phrases[npc:id()] and quest_disabled_phrases[npc:id()][pi]) then return false else return true end end function action_disable_phrase(fs,ss,dn,pi) local npc = dialogs.who_is_npc(fs, ss) if(pi=="0") then pi = dn end if(disabled_phrases[npc:id()]==nil) then disabled_phrases[npc:id()] = {} end disabled_phrases[npc:id()][pi] = true end function action_disable_quest_phrase(fs,ss,dn,pi) local npc = dialogs.who_is_npc(fs, ss) if(pi=="0") then pi = dn end if(quest_disabled_phrases[npc:id()]==nil) then quest_disabled_phrases[npc:id()] = {} end quest_disabled_phrases[npc:id()][pi] = true end function create_bye_phrase() if(rnd==0) then rnd = math.random(1, 99) end if(rnd>=66) then return game.translate_string("actor_break_dialog_1") elseif(rnd>=33) then return game.translate_string("actor_break_dialog_2") else return game.translate_string("actor_break_dialog_3") end end function uni_dialog_precond(first_speaker, second_speaker) local npc = dialogs.who_is_npc(first_speaker, second_speaker) return character_community(npc) == "stalker" or character_community(npc) == "bandit" or character_community(npc) == "freedom" or character_community(npc) == "dolg" end --[[ function restore_npc_disabled_phrases(npc_id) disabled_phrases[npc_id] = nil end -- Set phrase end action for place dialog function action_sim_action_dialog(npc, actor, dialog_name, id) rnd = 0 end -- Precondition for simulation answer function precondition_sim_action_dialog(npc, actor, dialog_name) local squad = get_object_squad(npc) if(xr_wounded.is_heavy_wounded_by_id(npc:id())) then return false end if(squad~=nil) then if(squad.current_action~=nil) then if(rnd==0) then rnd = math.random(1, 100) end if(rnd>0) then return true end end end return false end -- Precondition for simulation answer function precondition_not_sim_action_dialog(npc, actor, dialog_name) return not(precondition_sim_action_dialog(npc, actor, dialog_name)) end -- Precondition for simulation answer function precondition_sim_action_attack_point_none(npc, actor, dialog_name) local squad = get_object_squad(npc) if(squad.current_action.name=="attack_point") then local smart = sim_board.get_sim_board().smarts[squad.current_action.dest_smrt_id].smrt if(smart.player_name=="none") then return true end end return false end -- Precondition for simulation answer function precondition_sim_action_attack_point_friend(npc, actor, dialog_name) local squad = get_object_squad(npc) if(squad.current_action.name=="attack_point") then local smart = sim_board.get_sim_board().smarts[squad.current_action.dest_smrt_id].smrt if(smart.player_name==squad.player_id) then return true end end return false end -- Precondition for simulation answer function precondition_sim_action_attack_point_enemy(npc, actor, dialog_name) local squad = get_object_squad(npc) if(squad.current_action.name=="attack_point") then local smart = sim_board.get_sim_board().smarts[squad.current_action.dest_smrt_id].smrt if(smart.player_name~=squad.player_id) and (smart.player_name~="none") then return true end end return false end -- Precondition for simulation answer function precondition_sim_action_stay_point_none_near(npc, actor, dialog_name) return true end -- Precondition for simulation answer function precondition_sim_action_stay_point_enemy_near(npc, actor, dialog_name) return false end ]]--