188 lines
4.6 KiB
Plaintext
188 lines
4.6 KiB
Plaintext
local light_zones = {}
|
|
|
|
local indoor_levels = {
|
|
labx8 = true,
|
|
jupiter_underground = true,
|
|
|
|
-- Call of Chernobyl
|
|
l03u_agr_underground = true,
|
|
l04u_labx18 = true,
|
|
l08u_brainlab = true,
|
|
l10u_bunker = true,
|
|
l12u_sarcofag = true,
|
|
l12u_control_monolith = true,
|
|
l13u_warlab = true
|
|
}
|
|
local lightOn = 19
|
|
local lightOff = 5
|
|
---------------------------------------------------------------------------------------------------------------------
|
|
class "action_light"
|
|
function action_light:__init (obj, storage)
|
|
self.object = obj
|
|
self.st = storage
|
|
self.active = false
|
|
self.id = obj:id()
|
|
end
|
|
function action_light:reset_scheme()
|
|
light_zones[self.id] = self
|
|
end
|
|
function action_light:update(delta)
|
|
if xr_logic.try_switch_to_another_section(self.object, self.st, db.actor) then
|
|
self.active = false
|
|
light_zones[self.id] = nil
|
|
return
|
|
end
|
|
self.active = true
|
|
end
|
|
function action_light:check_stalker(stalker)
|
|
if self.active == false then
|
|
return false, false
|
|
end
|
|
|
|
if self.object:inside(stalker:position()) then
|
|
return self.st.light, true
|
|
end
|
|
|
|
return false, false
|
|
end
|
|
|
|
---------------------------------------------------------------------------------------------------------------------
|
|
function add_to_binder(npc, ini, scheme, section, storage)
|
|
--' printf("DEBUG: add_to_binder: scheme='%s', section='%s'", scheme, section)
|
|
local new_action = action_light (npc, storage)
|
|
xr_logic.subscribe_action_for_events(npc, storage, new_action)
|
|
end
|
|
|
|
function set_scheme(npc, ini, scheme, section, gulag_name)
|
|
local st = xr_logic.assign_storage_and_bind(npc, ini, scheme, section)
|
|
st.logic = xr_logic.cfg_get_switch_conditions(ini, section, npc)
|
|
st.light = ini:r_bool_ex(section,"light_on",false)
|
|
end
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------------------------------------------------
|
|
function check_light(stalker)
|
|
|
|
local st = db.storage[stalker:id()]
|
|
local tg = time_global()
|
|
|
|
if (st.srlight_timer and tg < st.srlight_timer) then
|
|
return
|
|
end
|
|
st.srlight_timer = tg + 2000 + math.random(100)
|
|
|
|
local torch = stalker:object("device_torch")
|
|
|
|
-- Stalker dead or sleep animstate; release torch
|
|
local anm = state_mgr.get_state(stalker)
|
|
if (not stalker:alive() or anm == "zat_b106_wounded_idle" or anm == "sleep" or anm == "play_guitar" or string.find(anm,"animpoint") or string.find(anm,"sneak")) then
|
|
if torch then
|
|
if (torch:attachable_item_enabled()) then
|
|
torch:enable_attachable_item(false)
|
|
end
|
|
|
|
local se_torch = alife_object(torch:id())
|
|
if se_torch then
|
|
alife_release(se_torch)
|
|
end
|
|
end
|
|
return
|
|
end
|
|
|
|
-- Stalker in danger mode; release torch
|
|
--[[
|
|
if (st.danger_flag) then
|
|
if torch then
|
|
if (torch:attachable_item_enabled()) then
|
|
torch:enable_attachable_item(false)
|
|
end
|
|
local se_torch = alife_object(torch:id())
|
|
if se_torch then
|
|
alife_release(se_torch)
|
|
end
|
|
end
|
|
return
|
|
end
|
|
--]]
|
|
|
|
-- Non-headlamp scheme in use; release torch
|
|
local scheme = st.active_scheme
|
|
if (scheme == "kamp" or scheme == "camper" or scheme == "sleeper") then
|
|
if torch then
|
|
if (torch:attachable_item_enabled()) then
|
|
torch:enable_attachable_item(false)
|
|
end
|
|
local se_torch = alife_object(torch:id())
|
|
if se_torch then
|
|
alife_release(se_torch)
|
|
end
|
|
end
|
|
return
|
|
end
|
|
|
|
-- Stalker has enemy and is not underground; release torch
|
|
--[[
|
|
if (stalker:best_enemy() and not indoor_levels[level.name()]) then
|
|
if torch then
|
|
if (torch:attachable_item_enabled()) then
|
|
torch:enable_attachable_item(false)
|
|
end
|
|
local se_torch = alife_object(torch:id())
|
|
if se_torch then
|
|
alife_release(se_torch)
|
|
end
|
|
end
|
|
return
|
|
end
|
|
--]]
|
|
|
|
-- Daytime and place condition
|
|
local forced, light = false, false
|
|
|
|
for k,v in pairs(light_zones) do
|
|
light, forced = v:check_stalker(stalker)
|
|
if forced == true then
|
|
break
|
|
end
|
|
end
|
|
|
|
if (forced == false) then
|
|
local htime = level.get_time_hours()
|
|
if htime <= lightOff or htime >= lightOn then light = true end
|
|
|
|
if (light == false) then
|
|
if indoor_levels[level.name()] == true then
|
|
light = true
|
|
end
|
|
end
|
|
end
|
|
|
|
if (stalker:has_info("npcx_is_companion")) then
|
|
if (stalker:has_info("npcx_light_on")) then light = true else light = false end
|
|
end
|
|
|
|
if (light) then
|
|
if (torch) then
|
|
if not (torch:attachable_item_enabled()) then
|
|
torch:enable_attachable_item(true)
|
|
end
|
|
else
|
|
alife_create_item("device_torch", stalker)
|
|
end
|
|
else
|
|
if torch and alife_object(torch:id()) then
|
|
if (torch:attachable_item_enabled()) then
|
|
torch:enable_attachable_item(false)
|
|
end
|
|
alife_release_id(torch:id())
|
|
end
|
|
end
|
|
end
|
|
|
|
function clean_up ()
|
|
for k,v in pairs(light_zones) do
|
|
light_zones[k] = nil
|
|
end
|
|
end
|