Daemonion

entire bind_stalker

Dec 11th, 2012
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.28 KB | None | 0 0
  1. function init    (obj)
  2.     xr_motivator.AddToMotivator(obj)
  3. end
  4.  
  5. function actor_init    (npc)
  6.     npc:bind_object(actor_binder(npc))
  7. end
  8.  
  9. local game_difficulty_by_num = {
  10.     [0] = "gd_novice",
  11.     [1] = "gd_stalker",
  12.     [2] = "gd_veteran",
  13.     [3] = "gd_master"
  14.     }
  15.  
  16. local post_time = 0
  17. lasthealth  = 0
  18. lasttime    = 0
  19. post_process = 0
  20. local weapon_hide = false
  21. ----------------------------------------------------------------------------------------------------------------------
  22. class "actor_binder" (object_binder)
  23. ----------------------------------------------------------------------------------------------------------------------
  24. function actor_binder:__init (obj) super(obj)
  25.     self.bCheckStart = false
  26.     self.weather_manager = level_weathers.WeatherManager()
  27.     self.actor_detector = xr_detector.actor_detector()
  28. end
  29. ----------------------------------------------------------------------------------------------------------------------
  30. function actor_binder:net_spawn(data)
  31.     printf("actor net spawn")      
  32.  
  33.     level.show_indicators()
  34.  
  35.     self.bCheckStart = true
  36.     self.weapon_hide = false -- ñïðÿòàíî èëè íåò îðóæèå ïðè ðàçãîâîðå.
  37.     weapon_hide = false -- óñòàíàâëèâàåì ãëîáàëüíûé äåôîëòîâûé ôëàã.
  38.  
  39.     if object_binder.net_spawn(self,data) == false then
  40.         return false
  41.     end
  42.  
  43.     db.add_actor(self.object)
  44.    
  45.     if self.st.disable_input_time == nil then
  46.         level.enable_input()
  47.     end
  48.  
  49.     self.weather_manager:reset()
  50. --  game_stats.initialize ()
  51.  
  52.     if(actor_stats.add_to_ranking~=nil)then
  53.         actor_stats.add_to_ranking(self.object:id())
  54.     end
  55.  
  56.     --' Çàãðóæàåì íàñòðîéêè äðîïà
  57.     death_manager.init_drop_settings()
  58.     weather_init.on_game_load(obj)
  59.     return true
  60. end
  61. ----------------------------------------------------------------------------------------------------------------------
  62. function actor_binder:net_destroy()
  63.     if(actor_stats.remove_from_ranking~=nil)then
  64.         actor_stats.remove_from_ranking(self.object:id())
  65.     end
  66. --  game_stats.shutdown ()
  67.     db.del_actor(self.object)
  68.  
  69.     sr_light.clean_up ()
  70.  
  71.     self.object:set_callback(callback.inventory_info, nil)
  72.     self.object:set_callback(callback.article_info, nil)
  73.     self.object:set_callback(callback.on_item_take, nil)
  74.     self.object:set_callback(callback.on_item_drop, nil)
  75.     self.object:set_callback(callback.use_object, nil)
  76.     --self.object:set_callback(callback.actor_sleep, nil)
  77.     self.object:set_callback(callback.task_state, nil)
  78.     self.object:set_callback(callback.level_border_enter, nil)
  79.     self.object:set_callback(callback.level_border_exit, nil)
  80.     self.object:set_callback(callback.take_item_from_box, nil)
  81.  
  82.     if sr_psy_antenna.psy_antenna then
  83.         sr_psy_antenna.psy_antenna:destroy()
  84.         sr_psy_antenna.psy_antenna = false
  85.     end
  86.  
  87.     xr_sound.stop_all_sound_object()
  88.  
  89.     object_binder.net_destroy(self)
  90. end
  91. ----------------------------------------------------------------------------------------------------------------------
  92. function actor_binder:reinit()
  93.     object_binder.reinit(self)
  94.    
  95.     local npc_id = self.object:id()
  96.  
  97.     db.storage[npc_id] = { }
  98.  
  99.     self.st = db.storage[npc_id]
  100.     self.st.pstor = nil
  101.  
  102.     self.next_restrictors_update_time = -10000
  103.  
  104.     self.object:set_callback(callback.inventory_info, self.info_callback, self)
  105.     self.object:set_callback(callback.article_info, self.article_callback, self)
  106.     self.object:set_callback(callback.on_item_take, self.on_item_take, self)
  107.     self.object:set_callback(callback.on_item_drop, self.on_item_drop, self)
  108.     self.object:set_callback(callback.use_object, self.use_object, self)
  109.     self.object:set_callback(callback.trade_sell_buy_item, self.on_trade, self) -- for game stats
  110.     --self.object:set_callback(callback.actor_sleep, self.sleep_callback, self)
  111.     self.object:set_callback(callback.task_state, self.task_callback, self)
  112.     --self.object:set_callback(callback.map_location_added, self.map_location_added_callback, self)
  113.     self.object:set_callback(callback.level_border_enter, self.level_border_enter, self)
  114.     self.object:set_callback(callback.level_border_exit, self.level_border_exit, self)
  115.     self.object:set_callback(callback.take_item_from_box, self.take_item_from_box, self)
  116. end
  117. ----------------------------------------------------------------------------------------------------------------------
  118. function actor_binder:take_item_from_box(box, item)
  119.     local story_id = box:story_id()
  120.     if story_id == nil then
  121.         return
  122.     end
  123.  
  124.     treasure_manager.take_item_from_box(box, story_id)
  125. --[[   
  126.     local respawner = se_respawn.get_respawner_by_parent(story_id)
  127.     if respawner == nil then
  128.         return
  129.     end
  130.    
  131.     --' Íåîáõîäèìî óìåíüøèòü ñ÷åò÷èê â ðåñïàâíåðå
  132.     respawner:remove_spawned(item:id())
  133.  
  134.     local smart_terrain = db.strn_by_respawn[respawner:name()]
  135.     if smart_terrain == nil then
  136.         return
  137.     end
  138.  
  139.     local npc = smart_terrain.gulag:get_nearest_online_obj(db.actor:position())
  140.     if npc ~= nil then
  141.         xr_sound.set_sound_play(npc, "reac_box")
  142.         xr_gulag.setGulagEnemy(smart_terrain:name() , db.actor)    
  143.     end
  144. ]]
  145. end
  146. ----------------------------------------------------------------------------------------------------------------------
  147. function actor_binder:level_border_enter(npc, info_id)
  148.     self.actor_detector:actor_enter()
  149. end
  150. ----------------------------------------------------------------------------------------------------------------------
  151. function actor_binder:level_border_exit(npc, info_id)
  152.     self.actor_detector:actor_exit()
  153. end
  154. ----------------------------------------------------------------------------------------------------------------------
  155. function actor_binder:info_callback(npc, info_id)
  156.     printf("*INFO*: npc='%s' id='%s'", npc:name(), info_id)
  157.     --' Ñþæåò
  158.     level_tasks.proceed(self.object)
  159.     -- Îòìåòêè íà êàðòå
  160.     level_tasks.process_info_portion(info_id)
  161. end
  162. ----------------------------------------------------------------------------------------------------------------------
  163. function actor_binder:on_trade (item, sell_bye, money)
  164.     if sell_bye == true then
  165.        game_stats.money_trade_update (money)
  166.     else      
  167.        game_stats.money_trade_update (-money)
  168.     end  
  169. end
  170. ----------------------------------------------------------------------------------------------------------------------
  171. function actor_binder:article_callback(npc, group, name)
  172.     --printf("article_callback [%s][%s]", group, name)
  173.     if device().precache_frame >1 then return end
  174.    
  175.     if group == "Diary" then
  176.         news_manager.send_encyclopedy("diary", group)
  177.     else
  178.         news_manager.send_encyclopedy("encyclopedy", group)
  179.     end
  180. end
  181. ----------------------------------------------------------------------------------------------------------------------
  182. function actor_binder:on_item_take (obj)
  183.     level_tasks.proceed(self.object)
  184.     --game_stats.update_take_item (obj, self.object)
  185. end
  186. ----------------------------------------------------------------------------------------------------------------------
  187. function actor_binder:on_item_drop (obj)
  188.     level_tasks.proceed(self.object)
  189.     --game_stats.update_drop_item (obj, self.object)
  190.     abc_medkit.chk_medlot_object(obj)
  191. end
  192. ----------------------------------------------------------------------------------------------------------------------
  193.  
  194. function actor_binder:use_object(obj)
  195. lurk_inv_effects.start(obj)
  196. end
  197. function actor_binder:task_callback(_task, _objective, _state)
  198.     task_manager.task_callback(_task:get_id(), _objective:get_idx(), _state)
  199.     if _objective:get_idx() == 0 then
  200.         if _state == task.fail then
  201.             news_manager.send_task(db.actor, "fail", _task, _objective)
  202.         elseif _state == task.completed then
  203.             task_manager.reward_by_task(_task)
  204.             news_manager.send_task(db.actor, "complete", _task, _objective)
  205.         else
  206.             news_manager.send_task(db.actor, "new", _task, _objective)
  207.         end
  208.     else
  209.         if _task:get_objective(0):get_state() == task.in_progress then
  210.             news_manager.send_task(db.actor, "update", _task, _objective)
  211.         end
  212.     end
  213. end
  214.  
  215. ----------------------------------------------------------------------------------------------------------------------
  216. function actor_binder:map_location_added_callback(spot_type_str, object_id)
  217.     if (false==app_ready()) or (device().precache_frame>1) then return end
  218.     --'news_manager.send_task(db.actor, "new")
  219. end
  220. ----------------------------------------------------------------------------------------------------------------------
  221. function actor_binder:update(delta)
  222.     daemonion_sound.actor_on_update()
  223.     if se_obj then
  224.         alife():release(se_obj, true)
  225.     end
  226.     if se_obj2 then
  227.         alife():release(se_obj2, true)
  228.     end
  229.     if se_obj3 then
  230.         alife():release(se_obj3, true)
  231.     end
  232.     if se_obj4 then
  233.         alife():release(se_obj4, true)
  234.     end
  235.    
  236.     abc_medkit.chk_medlot_object()
  237.     lurk_inv_effects.weapontimer()
  238.        
  239.     object_binder.update(self, delta)
  240.  
  241.     -- DEBUG slowdown
  242. --  slowdown.update()
  243.  
  244.  
  245.     local time = time_global()
  246.    
  247.     game_stats.update (delta, self.object)
  248.  
  249.     -- àïäåéò ïîãîäû
  250.     self.weather_manager:update()
  251.    
  252.     -- àïäåéò ñõåìû äåòåêòîðà
  253.     self.actor_detector:update()
  254.  
  255.     -- àïäåéò çâóêîâîé ñõåìû àêòåðà
  256.     xr_sound.update_actor()
  257.    
  258.     --' Ïðîâåðêà ïîòåðè æèçíè
  259. --[[
  260.     if self.object.health - lasthealth > 0.001 or
  261.        self.object.health - lasthealth < -0.001 then
  262.         printf("%f | %f", self.object.health, self.object.health - lasthealth, game.time() - lasttime)
  263.         lasthealth = self.object.health
  264.         lasttime = game.time()
  265.     end
  266. ]] 
  267.     -- Îáíîâëåíèå îòêëþ÷åíèÿ ââîäà ñ êëàâèàòóðû.
  268.     if self.st.disable_input_time ~= nil and
  269.        game.get_game_time():diffSec(self.st.disable_input_time) >= self.st.disable_input_idle
  270.     then
  271.         level.enable_input()
  272.         self.st.disable_input_time = nil
  273.     end
  274.     -- Îáíîâëåíèå ñíà ñ ïåðåíîñîì ÷óâàêà â óêàçàííóþ ïîçèöèþ
  275.     if self.st.sleep_relocate_time ~= nil and
  276.        game.get_game_time():diffSec(self.st.sleep_relocate_time) >= self.st.sleep_relocate_idle
  277.     then
  278.         self.object:set_actor_position(self.st.sleep_relocate_point)
  279.         local dir = self.st.sleep_relocate_point:sub(self.st.sleep_relocate_look)
  280.         self.object:set_actor_direction(dir:getH())
  281.         self.st.sleep_relocate_time = nil
  282.     end
  283.  
  284.     -- Àïäåéò ïðÿòàíèå îðóæèÿ èãðîêà âî âðåìÿ äèàëîãà
  285.     if weapon_hide == true or self.object:is_talking() then
  286.         if self.weapon_hide == false then
  287.             self.object:hide_weapon()
  288.             self.weapon_hide = true
  289.         end
  290.     else
  291.         if self.weapon_hide == true then
  292.             self.object:restore_weapon()
  293.             self.weapon_hide = false
  294.         end
  295.     end
  296.  
  297.     -- îáíîâëåíèå ðåñòðèêòîðîâ, êîòîðûå ïîä ëîãèêîé, ñðàáàòûâàåò ÷åðåç èíòåðâàëû âðåìåíè
  298.     if self.next_restrictors_update_time < time then
  299.         bind_restrictor.actor_update(delta)
  300.  
  301.         self.next_restrictors_update_time = time + 200
  302.  
  303.         task_manager.actor_update()
  304.     end
  305.  
  306.     -- new sleep mod
  307.     if post_time < time then
  308.         post_time = time + 250
  309.  
  310.         if sleep_manager.is_sleep_active() and xr_conditions.actor_dead() then
  311.             xr_logic.issue_event(db.actor, db.storage[db.actor:id()]["ar_sleep"], "update")
  312.         end
  313.  
  314.         sleep_manager.update(delta)
  315.     end
  316.     -- îáíîâëåíèå ïîñòïðîöåññîâ
  317.     if post_process ~= 0 then
  318.         if post_process:update () == true then
  319.            post_process = 0
  320.         end
  321.     end
  322.  
  323.     -- îáíîâëåíèå ïñè-àíòåííû
  324.     if sr_psy_antenna.psy_antenna then
  325.         sr_psy_antenna.psy_antenna:update(delta)
  326.     end
  327.  
  328.     --' Âûâîä ñîîáùåíèÿ î áîëüøîé ðàäèàöèè
  329.     if self.object.radiation >= 0.7 then
  330.         local hud = get_hud()
  331.         local custom_static = hud:GetCustomStatic("cs_radiation_danger")
  332.         if custom_static == nil then
  333.             hud:AddCustomStatic("cs_radiation_danger", true)
  334.             hud:GetCustomStatic("cs_radiation_danger"):wnd():SetTextST("st_radiation_danger")
  335.         end
  336.     else
  337.         local hud = get_hud()
  338.         local custom_static = hud:GetCustomStatic("cs_radiation_danger")
  339.         if custom_static ~= nil then
  340.             hud:RemoveCustomStatic("cs_radiation_danger")
  341.         end
  342.     end
  343.    
  344.     --' Çàïóñêàåì çàòû÷êó îò âîçìîæíîé ïîòåðè ñîäåðæèìîãî òàéíèêîâ
  345.     treasure_manager.get_treasure_manager():loss_workaround()
  346.  
  347.  
  348.     if self.bCheckStart then
  349.         printf("SET DEFAULT INFOS")    
  350.  
  351.         if not has_alife_info("storyline_actor_start") and
  352.            (level.name() == "l01_escape")
  353.         then
  354.             self.object:give_info_portion("storyline_actor_start")
  355.             _G.g_start_avi = true
  356.             printf("*AVI* RUN START AVI")          
  357.         end
  358.  
  359. --      if not has_alife_info("encyclopedy") then
  360. --          self.object:give_info_portion("encyclopedy")
  361. --      end
  362.  
  363.         if not has_alife_info("global_dialogs") then
  364.             self.object:give_info_portion("global_dialogs")
  365.         end
  366.  
  367.         if not has_alife_info("level_changer_icons") then
  368.             self.object:give_info_portion("level_changer_icons")
  369.         end
  370.  
  371.         level_tasks.add_lchanger_location()
  372.  
  373.         self.bCheckStart = false       
  374.     end
  375.    
  376.     --- Ëàãåðü íîâè÷êîâ, Âîëê:
  377.     -- Âîëê:
  378.     escape_tasks.wolf_message()
  379.     -- Ëàãåðü ïðîùàåò îáèäû:
  380.     escape_tasks.esc_lager_forgive()
  381.  
  382.     abc_medkit.chk_medlot_object()
  383. end
  384. ----------------------------------------------------------------------------------------------------------------------
  385. function actor_binder:save(packet)
  386.    
  387.     local save_treasure_manager = true
  388.    
  389.     printf("actor_binder:save(): self.object:name()='%s'", self.object:name())
  390.     object_binder.save(self, packet)
  391.  
  392.     --' Ñîõðàíÿåì óðîâåíü ñëîæíîñòè
  393.     if save_treasure_manager == true then
  394.         packet:w_u8(level.get_game_difficulty() + 128)
  395.     else
  396.         packet:w_u8(level.get_game_difficulty())
  397.     end
  398.  
  399.  
  400.     --' Ñîõðàíÿåì äàííûå îá îòêëþ÷åííîì ââîäå
  401.     if self.st.disable_input_time == nil then
  402.         packet:w_bool(false)
  403.     else
  404.         packer:w_bool(true)
  405.         utils.w_CTime(packet, self.st.disable_input_time)
  406.     end
  407.  
  408.     xr_logic.pstor_save_all(self.object, packet)
  409.     self.weather_manager:save(packet)
  410.  
  411.     sr_psy_antenna.save( packet )
  412.    
  413.     if save_treasure_manager == true then
  414.         treasure_manager.save(packet)      
  415.     end                                  
  416.  
  417.     task_manager.save(packet)
  418.     self.actor_detector:save(packet)   
  419. end
  420. ----------------------------------------------------------------------------------------------------------------------
  421. function actor_binder:load(reader)
  422.     printf("actor_binder:load(): self.object:name()='%s'", self.object:name())
  423.     object_binder.load(self, reader)
  424.     printf("actor_binder:object_binder.load(): self.object:name()='%s'", self.object:name())
  425.  
  426.     --' Çàãðóæàåì óðîâåíü ñëîæíîñòè
  427.     local game_difficulty = reader:r_u8()
  428.    
  429.     local load_treasure_manager = false      
  430.     if game_difficulty >= 128 then          
  431.         game_difficulty = game_difficulty - 128
  432.         load_treasure_manager = true          
  433.     end                                      
  434.  
  435.    
  436.     get_console():execute("g_game_difficulty "..game_difficulty_by_num[game_difficulty])
  437.  
  438.     if reader:r_eof() then
  439.         abort("SAVE FILE IS CORRUPT")
  440.     end
  441.  
  442.     local stored_input_time = reader:r_u8()
  443.     if stored_input_time == true then
  444.         self.st.disable_input_time = utils.r_CTime(reader)
  445.     end
  446.  
  447.     xr_logic.pstor_load_all(self.object, reader)
  448.     self.weather_manager:load(reader)
  449.  
  450.     sr_psy_antenna.load(reader)
  451.    
  452.     if load_treasure_manager == true then
  453.         treasure_manager.load(reader)      
  454.     end                                  
  455.  
  456.    
  457.     task_manager.load(reader)
  458.     self.actor_detector:load(reader)   
  459. end
  460. ----------------------------------------------------------------------------------------------------------------------
  461.  
  462. --ñòàðò ïðåôåò÷à çâóêîâ
  463. --if string.find(command_line(), "-noprefetch") == nil then
  464. --  sound_prefetch.prefetch_sounds()
  465. --end
  466.  
  467.  
  468. -- Weapon functions
  469. function hide_weapon()
  470.     weapon_hide = true
  471. end
  472. function restore_weapon()
  473.     weapon_hide = false
  474. end
  475.  
  476. // this is test for section iteration
  477. /**
  478. local function test_section_iteration(file_name, section_name)
  479.     printf          ("file    : %s",file_name)
  480.     printf          ("section : %s",section_name)
  481.    
  482.     local           file = ini_file(file_name)
  483.     local           n = file:line_count(section_name)
  484.     printf          ("lines   : %d",n)
  485.    
  486.     local           id, value = "", "", result
  487.     for i=0,n-1 do
  488.         result, id, value   = file:r_line(section_name,i,"","")
  489.         printf      ("line %d : %s = %s",i,id,value)
  490.     end
  491. end
  492.  
  493. test_section_iteration("system.ltx","space_restrictor")
  494. /**/
Advertisement
Add Comment
Please, Sign In to add comment