Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local light_zones = {}
- local indoor_levels = {
- 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
- }
- ---------------------------------------------------------------------------------------------------------------------
- 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") or stalker:object("device_torch_low") or stalker:object("device_torch_normal") or stalker:object("dev_torch_light_better") or stalker:object("dev_torch_light_better_1")
- -- 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 sim = alife()
- sim:release(sim:object(torch:id()),true)
- 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 sim = alife()
- sim:release(sim:object(torch:id()),true)
- 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 sim = alife()
- sim:release(sim:object(torch:id()),true)
- 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 sim = alife()
- sim:release(sim:object(torch:id()),true)
- end
- return
- end
- 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 not forced then
- local htime = level.get_time_hours()
- if htime <= 4 or htime >= 20 then
- light = true
- end
- if light == false then
- if indoor_levels[level.name()] == true then
- light = true
- end
- end
- end
- if (light) then
- if (torch) then
- if not (torch:attachable_item_enabled()) then
- torch:enable_attachable_item(true)
- end
- else
- local rnd = math.random(1,4)
- local sim = alife()
- if rnd == 1 and stalker:character_community() ~= "army" then
- sim:create("device_torch_low", vector(), 0, 0, stalker:id())
- elseif rnd == 2 and stalker:character_community() ~= "army" then
- sim:create("device_torch_normal", vector(), 0, 0, stalker:id())
- elseif rnd == 3 and stalker:character_community() ~= "army" then
- sim:create("dev_torch_light_better", vector(), 0, 0, stalker:id())
- elseif rnd == 4 or stalker:character_community() == "army" then
- sim:create("dev_torch_light_better_1", vector(), 0, 0, stalker:id())
- end
- end
- else
- if (torch) then
- if (torch:attachable_item_enabled()) then
- torch:enable_attachable_item(false)
- end
- local sim = alife()
- sim:release(sim:object(torch:id()),true)
- end
- end
- end
- function clean_up ()
- for k,v in pairs(light_zones) do
- light_zones[k] = nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement