Guest User

bind_stalker.script

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