Advertisement
Guest User

sr_light.script

a guest
Mar 13th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | None | 0 0
  1. ------------------------------------------------------------------------------------------------
  2. -- Decane torch logic.
  3. ------------------------------------------------------------------------------------------------
  4.  
  5. function dbgmsg(msg)
  6.     db.actor:give_game_news("Debug message:", msg, "ui_npc_small_ucheniy_1", 0, 2000, 1)
  7. end
  8.  
  9. ------------------------------------------------------------------------------------------------
  10.  
  11. local light_zones = {}
  12. local indoor_levels =   {
  13.                             ["agroprom_underground"] = true
  14.                         }
  15.  
  16. class "action_light"
  17.  
  18. function action_light:__init(obj, storage)
  19.     self.object = obj
  20.     self.st = storage
  21.     self.active = false
  22.     self.id = obj:id()
  23. end
  24.  
  25. function action_light:reset_scheme()
  26.     light_zones[self.id] = self
  27. end
  28.  
  29. function action_light:update(delta)
  30.     if xr_logic.try_switch_to_another_section(self.object, self.st, db.actor) then
  31.         self.active = false
  32.         self.stalkers = {}
  33.         light_zones[self.id] = nil
  34.         return
  35.     end
  36.     self.active = true
  37. end
  38.  
  39. function action_light:check_stalker(stalker)
  40.  
  41.     if self.active == false then
  42.         return false, false
  43.     end
  44.  
  45.     if self.object:inside(stalker:position()) then
  46.         return self.st.light, true
  47.     end
  48.  
  49.     return false, false
  50. end
  51.  
  52. ------------------------------------------------------------------------------------------------
  53.  
  54. function add_to_binder(npc, ini, scheme, section, storage)
  55.     local new_action = action_light(npc, storage)
  56.     xr_logic.subscribe_action_for_events(npc, storage, new_action)
  57. end
  58.  
  59. function set_scheme(npc, ini, scheme, section, gulag_name)
  60.     local st = xr_logic.assign_storage_and_bind(npc, ini, scheme, section)
  61.     st.logic = xr_logic.cfg_get_switch_conditions(ini, section, npc)
  62.     st.light = utils.cfg_get_bool(ini, section, "light_on", npc, false, false)
  63. end
  64.  
  65. ------------------------------------------------------------------------------------------------
  66.  
  67. function check_light(stalker)
  68.  
  69.     local torch = stalker:object("device_torch")
  70.     local sim = alife()
  71.  
  72.     -- stalker is not alive; release torch
  73.     if not stalker:alive() then
  74.         if (torch) then
  75.             sim:release(sim:object(torch:id()),true)
  76.         end
  77.         return
  78.     end
  79.  
  80.     -- Non-headlamp scheme in use; release torch
  81.     local scheme = db.storage[stalker:id()].active_scheme
  82.     if scheme == "kamp" or scheme == "camper" or scheme == "sleeper" then
  83.         if (torch) then
  84.             sim:release(sim:object(torch:id()),true)
  85.         end
  86.         return
  87.     end
  88.  
  89.     -- Stalker has enemy and is not underground; release torch
  90.     if (stalker:best_enemy() and not indoor_levels[level.name()]) then
  91.         if (torch) then
  92.             sim:release(sim:object(torch:id()),true)
  93.         end
  94.         return
  95.     end
  96.  
  97.     local forced, light = false, false
  98.  
  99.     for k,v in pairs(light_zones) do
  100.         light, forced = v:check_stalker(stalker)
  101.         if forced == true then
  102.             break
  103.         end
  104.     end
  105.  
  106.     if not forced then
  107.         local htime = level.get_time_hours()
  108.         if htime <= 4 or htime >= 20 then
  109.             light = true
  110.         end
  111.  
  112.         if light == false then
  113.             if indoor_levels[level.name()] == true then
  114.                 light = true
  115.             end
  116.         end
  117.     end
  118.  
  119.     if (light) then
  120.         if (torch) then
  121.             torch:enable_attachable_item(true)
  122.         else
  123.             sim:create("device_torch", vector(), 0, 0, stalker:id())
  124.         end
  125.     else
  126.         if (torch) then
  127.             torch:enable_attachable_item(false)
  128.             sim:release(sim:object(torch:id()),true)
  129.         end
  130.     end
  131. end
  132.  
  133. function clean_up()
  134.     light_zones = {}
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement