Divergent/mods/Sound Clues for HTS/gamedata/scripts/hts_sound_clue.script

141 lines
4.0 KiB
Plaintext

local tmr_upd
-- local test_sound = sound_object("device\\radio_call")
local stats_level = {0.20, 0.30, 0.40, 0.55, 0.70, 0.85}
local player_hunger_level = 0
local player_thirst_level = 0
local player_sleepy_level = 0
local play_hungry = false
local play_thirst = false
local play_sleepy = false
local sound_stat = {}
function on_game_start()
RegisterScriptCallback("actor_on_update", actor_on_update)
for i = 1, #stats_level do
sound_stat["actor\\hts_hunger_" .. i] = sound_object("actor\\hts_hunger_" .. i)
sound_stat["actor\\hts_thirst_" .. i] = sound_object("actor\\hts_thirst_" .. i)
sound_stat["actor\\hts_yawn_" .. i] = sound_object("actor\\hts_yawn_" .. i)
end
end
local function get_stat_change(level, stat)
local did_decrease = false
-- i = 0; i <= 5; ++i
-- j = 5; j >= 0; --j
for i = 0, #stats_level - 1 do
local j = #stats_level - i
if level == j and stat <= stats_level[j] then
level = j - 1
did_decrease = true
end
end
-- i = 1; i <= 6; ++i
for i = 1, #stats_level do
if stat > stats_level[i] and level == i - 1 then level = i end
end
return level, did_decrease
end
local function play_stat_sound(sound)
sound_stat[sound]:play(db.actor, 0, sound_object.s2d)
sound_stat[sound].volume = 1.0
-- sound_stat.volume = 1.0 - player_thirst_level / 12.0
-- news_manager.send_tip(db.actor, string.format("%s Debug %s", sound, sound_stat[sound]:playing()), 0, nil, 1500)
end
function actor_on_update()
local tg = time_global()
if (tmr_upd and tg < tmr_upd) then return end
tmr_upd = tg + 1000
local satiety = get_satiety_val()
player_hunger_level, play_hungry = get_stat_change(player_hunger_level, satiety)
local thirst = get_thirst_val()
player_thirst_level, play_thirst = get_stat_change(player_thirst_level, thirst)
local sleep = get_sleep_val()
player_sleepy_level, play_sleepy = get_stat_change(player_sleepy_level, sleep)
if play_hungry then
play_stat_sound(string.format("actor\\hts_hunger_%i", player_hunger_level + 1))
play_hungry = false
return
end
if play_thirst then
play_stat_sound(string.format("actor\\hts_thirst_%i", player_thirst_level + 1))
play_thirst = false
return
end
if play_sleepy then
play_stat_sound(string.format("actor\\hts_yawn_%i", player_sleepy_level + 1))
play_sleepy = false
return
end
end
function get_local_val(path, script_name, str_to_find)
if _G[script_name] then
if not file_exists(path) then
return
end
for line in io.lines(path) do
if string.find(line, str_to_find) then
_,_, loc_val = string.find(line, "start_blur_4%s*=%s*(%d+)")
if type(tonumber(loc_val)) == "number" then
return loc_val
end
end
end
end
end
function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
function get_red_thirst()
local max_thirst = get_local_val([[gamedata\scripts\actor_status_thirst.script]], "actor_status_thirst", "local start_blur_4") or 5760
return max_thirst
end
function get_red_sleep()
local max_sleep = get_local_val([[gamedata\scripts\actor_status_sleep.script]], "actor_status_sleep", "local start_blur_4") or 8750
return max_sleep
end
function get_satiety_val()
local conditions = db.actor:cast_Actor():conditions()
local satiety = conditions:GetSatiety()
local red_icon_satiety = conditions:SatietyCritical() * 0.5
satiety = normalize(satiety, red_icon_satiety, 1)
return satiety
end
function get_thirst_val()
local thirst = 1 - actor_status_thirst.get_water_deprivation()
local red_icon_thirst = get_red_thirst()
red_icon_thirst = 1 - normalize(red_icon_thirst, 0, 10000)
thirst = normalize(thirst, red_icon_thirst, 1)
return thirst
end
function get_sleep_val()
local sleep = 1 - actor_status_sleep.get_sleep_deprivation()
local red_icon_sleep = get_red_sleep()
red_icon_sleep = 1 - normalize(red_icon_sleep, 0, 10000)
sleep = normalize(sleep, red_icon_sleep, 1)
return sleep
end