Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------------------------
- -- Decane torch logic.
- ------------------------------------------------------------------------------------------------
- function dbgmsg(msg)
- db.actor:give_game_news("Debug message:", msg, "ui_npc_small_ucheniy_1", 0, 2000, 1)
- end
- ------------------------------------------------------------------------------------------------
- local light_zones = {}
- local indoor_levels = {
- ["agroprom_underground"] = 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
- self.stalkers = {}
- 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)
- 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 = utils.cfg_get_bool(ini, section, "light_on", npc, false, false)
- end
- ------------------------------------------------------------------------------------------------
- function check_light(stalker)
- local torch = stalker:object("device_torch")
- local sim = alife()
- -- stalker is not alive; release torch
- if not stalker:alive() then
- if (torch) then
- sim:release(sim:object(torch:id()),true)
- end
- return
- end
- -- Non-headlamp scheme in use; release torch
- local scheme = db.storage[stalker:id()].active_scheme
- if scheme == "kamp" or scheme == "camper" or scheme == "sleeper" then
- if (torch) then
- 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
- 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
- torch:enable_attachable_item(true)
- else
- sim:create("device_torch", vector(), 0, 0, stalker:id())
- end
- else
- if (torch) then
- torch:enable_attachable_item(false)
- sim:release(sim:object(torch:id()),true)
- end
- end
- end
- function clean_up()
- light_zones = {}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement