Advertisement
Guest User

_g.script

a guest
Jun 2nd, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.67 KB | None | 0 0
  1. if (jit == nil) then
  2. profiler.setup_hook ()
  3. end
  4.  
  5.  
  6. function empty (container)
  7. if (type(container) == "function") then
  8. for i in container do
  9. return (false)
  10. end
  11. return (true)
  12. end
  13. assert (type(container) == "table")
  14. if (container[1] ~= nil) then
  15. return (false)
  16. end
  17. for i,j in pairs(container) do
  18. return (false)
  19. end
  20. return (true)
  21. end
  22.  
  23.  
  24. schemes = {} -- соответствие схем модулям
  25. stypes = {} -- типv схем
  26.  
  27. -- іагружает схему из файла на диске и активирует в мотиваторе.
  28. -- ідесь:
  29. -- filename - имя файла, в котором реализована схема, без расширения
  30. -- scheme - имя схем
  31. function load_scheme(filename, scheme, stype)
  32. schemes[scheme] = filename
  33. stypes[scheme] = stype
  34. end
  35.  
  36. ----------------------------------------------------------------------
  37. dev_debug = false
  38. sim_debug = false
  39. mus_vol = 0
  40. amb_vol = 0
  41. b_discard_settings_shown = false
  42. ----------------------------------------------------------------------
  43. local scripts_to_print = {
  44. ["stalker_generic"] = true,
  45. ["xr_smartcover"] = true,
  46. ["xr_logic"] = true,
  47. ["xr_conditions"] = true,
  48. ["xr_cover"] = true,
  49. ["xr_motivator"] = true,
  50. ["xr_walker"] = true,
  51. ["xr_camper"] = true,
  52. ["xr_kamp"] = true,
  53. ["restrictor_manager"] = true,
  54. ["sim_board"] = true,
  55. ["sim_faction"] = true,
  56. ["post_combat_idle"] = true,
  57. ["xr_death"] = true,
  58. ["xr_sound"] = true,
  59. ["utils"] = true,
  60. ["treasure_manager"] = true,
  61. ["object_collection"] = true,
  62. ["se_actor"] = true,
  63. ["smart_terrain"] = true,
  64. ["bind_physic_object"] = true,
  65. ["bind_heli"] = true,
  66. ["bind_anomaly_zone"] = true,
  67. ["bind_stalker"] = true,
  68. ["state_mgr_animation"] = true,
  69. ["se_stalker"] = true,
  70. ["db"] = true,
  71. ["sim_squad_generic"] = true,
  72. ["sim_squad_scripted"] = true,
  73. ["se_smart_cover"] = true,
  74. ["se_monster"] = true,
  75. ["dialog_manager"] = true,
  76. ["xr_combat_ignore"] = true,
  77. ["xr_remark"] = true,
  78. ["cover_manager"] = true,
  79. ["xr_danger"] = true,
  80. ["task_manager"] = true,
  81. ["task_objects"] = true
  82. }
  83. function printf(fmt,...)
  84. if not (fmt) then return end
  85. local fmt = tostring(fmt)
  86.  
  87. if (select('#',...) >= 1) then
  88. local i = 0
  89. local p = {...}
  90. local function sr(a)
  91. i = i + 1
  92. if (type(p[i]) == 'userdata') then
  93. return 'userdata'
  94. end
  95. return tostring(p[i])
  96. end
  97. fmt = string.gsub(fmt,"%%s",sr)
  98. end
  99.  
  100. get_console():execute("load ~#debug msg:"..fmt)
  101. end
  102.  
  103. ----------------------------------------------------------------------
  104. if nil == time_global then
  105. time_global = function () return device():time_global() end
  106. end
  107.  
  108. function wait_game(time_to_wait)
  109. verify_if_thread_is_running()
  110. if (time_to_wait == nil) then
  111. coroutine.yield()
  112. else
  113. local time_to_stop = game.time() + time_to_wait
  114. while game.time() <= time_to_stop do
  115. coroutine.yield()
  116. end
  117. end
  118. end
  119.  
  120. function wait(time_to_wait)
  121. verify_if_thread_is_running()
  122. if (time_to_wait == nil) then
  123. coroutine.yield()
  124. else
  125. local time_to_stop = time_global() + time_to_wait
  126. while time_global() <= time_to_stop do
  127. coroutine.yield()
  128. end
  129. end
  130. end
  131.  
  132. function action(obj,...)
  133. local arg = {...}
  134. local act = entity_action()
  135. local i = 1
  136. while true do
  137. if (arg[i] ~= nil) then
  138. act:set_action(arg[i])
  139. else
  140. break
  141. end
  142. i = i + 1
  143. end
  144. if (obj ~= nil) then
  145. obj:command(act,false)
  146. end
  147. return entity_action(act)
  148. end
  149.  
  150. function action_first(obj,...)
  151. local arg = {...}
  152. local act = entity_action()
  153. local i = 1
  154. while true do
  155. if (arg[i] ~= nil) then
  156. act:set_action(arg[i])
  157. else
  158. break
  159. end
  160. i = i + 1
  161. end
  162. if (obj ~= nil) then
  163. obj:command(act,true)
  164. end
  165. return entity_action(act)
  166. end
  167.  
  168. function round (value)
  169. local min = math.floor (value)
  170. local max = min + 1
  171. if value - min > max - value then return max end
  172. return min
  173. end
  174.  
  175.  
  176. function distance_between(obj1, obj2)
  177. return obj1:position():distance_to(obj2:position())
  178. end
  179.  
  180. -- +сли один объект nil, например нет актера, то считаем, что он далеко
  181. function distance_between_safe(obj1, obj2)
  182. if(obj1 == nil or obj2 == nil) then return 100000 end
  183. return obj1:position():distance_to(obj2:position())
  184. end
  185.  
  186. local aa = nil
  187. --' іроверка на инфопоршнv, даже если игрока не су ествует
  188. function has_alife_info(info_id)
  189. if aa == nil then
  190. return false
  191. end
  192. return aa:has_info(0, info_id)
  193. end
  194.  
  195.  
  196.  
  197. function reset_action (npc, script_name)
  198. if npc:get_script () then
  199. npc:script (false, script_name)
  200. end
  201. npc:script (true, script_name)
  202. end
  203.  
  204. --------------------------------------------------
  205. -- Functions and variables added by Zmey
  206. --------------------------------------------------
  207.  
  208. -- іонстанта, которуі использовать в местах, где нужно задать неограниченное время действия
  209. time_infinite = 100000000
  210.  
  211. -- +сли в даннvй момент вvполняется какое-то действие, прерvвает его и отклічает скриптовvй режим
  212. function interrupt_action(who, script_name)
  213. if who:get_script() then
  214. who:script(false, script_name)
  215. end
  216. end
  217.  
  218. function random_choice(...)
  219. local arg = {...}
  220. local r = math.random(1, #arg)
  221. return arg[r]
  222. end
  223.  
  224. function if_then_else(cond, if_true, if_false)
  225. if cond then
  226. return if_true
  227. end
  228. return if_false
  229. end
  230.  
  231.  
  232. function set_current_time (hour, min, sec)
  233. local current_time_factor = level.get_time_factor ()
  234. printf ("Need time : %d:%d:%d", hour, min, sec)
  235. local current_time = game.time ()
  236. local c_day = math.floor (current_time / 86400000)
  237. local c_time = current_time - c_day * 86400000
  238. local n_time = (sec + min * 60 + hour * 3600) * 1000
  239.  
  240. if c_time > n_time then c_day = c_day + 1 end
  241. n_time = n_time + c_day * 86400000
  242. level.set_time_factor (10000)
  243. while game.time () < n_time do wait () end
  244. level.set_time_factor (current_time_factor)
  245. end
  246.  
  247. function random_number (min_value, max_value)
  248. math.randomseed (device ():time_global ())
  249. if min_value == nil and max_value == nil then
  250. return math.random ()
  251. else
  252. return math.random (min_value, max_value)
  253. end
  254. end
  255.  
  256.  
  257. function parse_names( s )
  258. local t = {}
  259. for name in string.gfind( s, "([%w_\\]+)%p*" ) do
  260. --for name in string.gfind( s, "%s*([^%,]+)%s*" ) do
  261. table.insert( t, name )
  262. end
  263. return t
  264. end
  265.  
  266. function parse_key_value( s )
  267. local t = {}
  268. if s == nil then
  269. return nil
  270. end
  271. local key, nam = nil, nil
  272. for name in string.gfind( s, "([%w_\\]+)%p*" ) do
  273. if key == nil then
  274. key = name
  275. else
  276. t[key] = name
  277. key = nil
  278. end
  279. end
  280. return t
  281. end
  282.  
  283. function parse_nums( s )
  284. local t = {}
  285. for entry in string.gfind( s, "([%-%d%.]+)%,*" ) do
  286. table.insert( t, tonumber( entry ) )
  287. end
  288. return t
  289. end
  290.  
  291. -- Находится ли обьект в онлайне.
  292. function is_object_online(obj_id)
  293. return level.object_by_id(obj_id) ~= nil
  294. end
  295.  
  296. function get_clsid(npc)
  297. if npc == nil then return nil end
  298. return npc:clsid()
  299. end
  300.  
  301. --Tvчисляет yaw в радианах
  302. function yaw( v1, v2 )
  303. return math.acos( ( (v1.x*v2.x) + (v1.z*v2.z ) ) / ( math.sqrt(v1.x*v1.x + v1.z*v1.z ) * math.sqrt(v2.x*v2.x + v2.z*v2.z ) ) )
  304. end
  305. function yaw_degree( v1, v2 )
  306. return (math.acos( ( (v1.x*v2.x) + (v1.z*v2.z ) ) / ( math.sqrt(v1.x*v1.x + v1.z*v1.z ) * math.sqrt(v2.x*v2.x + v2.z*v2.z ) ) ) * 57.2957)
  307. end
  308. function yaw_degree3d( v1, v2 )
  309. return (math.acos((v1.x*v2.x + v1.y*v2.y + v1.z*v2.z)/(math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z )*math.sqrt(v2.x*v2.x + v2.y*v2.y + v2.z*v2.z)))*57.2957)
  310. end
  311. function vector_cross(v1, v2)
  312. return vector():set(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x)
  313. end
  314.  
  315. --Поворачивает вектор вокруг оси y против часовой стрелки.
  316. function vector_rotate_y(v, angle)
  317. angle = angle * 0.017453292519943295769236907684886
  318. local c = math.cos (angle)
  319. local s = math.sin (angle)
  320. return vector ():set (v.x * c - v.z * s, v.y, v.x * s + v.z * c)
  321. end
  322.  
  323. -- очистка таблицы.
  324. function clear_table (t)
  325. while #t > 0 do
  326. table.remove (t, #t)
  327. end
  328. end
  329.  
  330. function stop_play_sound(obj)
  331. if obj:alive() == true then
  332. obj:set_sound_mask(-1)
  333. obj:set_sound_mask(0)
  334. end
  335. end
  336.  
  337. -- Печатает таблицу как дерево.
  338. function print_table(table, subs)
  339. local sub
  340. if subs ~= nil then
  341. sub = subs
  342. else
  343. sub = ""
  344. end
  345. for k,v in pairs(table) do
  346. if type(v) == "table" then
  347. printf(sub.."%s:", tostring(k))
  348. print_table(v, sub.." ")
  349. elseif type(v) == "function" then
  350. printf(sub.."%s:function", tostring(k))
  351. elseif type(v) == "userdata" then
  352. printf(sub.."%s:userdata", tostring(k))
  353. elseif type(v) == "boolean" then
  354. if v == true then
  355. if(type(k)~="userdata") then
  356. printf(sub.."%s:true", tostring(k))
  357. else
  358. printf(sub.."userdata:true")
  359. end
  360. else
  361. if(type(k)~="userdata") then
  362. printf(sub.."%s:false", tostring(k))
  363. else
  364. printf(sub.."userdata:false")
  365. end
  366. end
  367. else
  368. if v ~= nil then
  369. printf(sub.."%s:%s", tostring(k),v)
  370. else
  371. printf(sub.."%s:nil", tostring(k),v)
  372. end
  373. end
  374. end
  375. end
  376. function store_table(table, subs)
  377. local sub
  378. if subs ~= nil then
  379. sub = subs
  380. else
  381. sub = ""
  382. end
  383. printf(sub.."{")
  384. for k,v in pairs(table) do
  385. if type(v) == "table" then
  386. printf(sub.."%s = ", tostring(k))
  387. store_table(v, sub.." ")
  388. elseif type(v) == "function" then
  389. printf(sub.."%s = \"func\",", tostring(k))
  390. elseif type(v) == "userdata" then
  391. printf(sub.."%s = \"userdata\",", tostring(k))
  392. elseif type(v) == "string" then
  393. printf(sub.."%s = \"%s\",", tostring(k), tostring(v))
  394. else
  395. printf(sub.."%s = %s,", tostring(k), tostring(v))
  396. end
  397. end
  398. printf(sub.."},")
  399. end
  400.  
  401. -------------------------------------------------------------------------------------------
  402. local monster_classes = {}
  403. local stalker_classes = {}
  404. local weapon_classes = {}
  405. local artefact_classes = {}
  406.  
  407. function IsMonster (object, class_id)
  408. local id = class_id or get_clsid(object)
  409. return monster_classes[id] == true
  410. end
  411. function IsStalker (object, class_id)
  412. local id = class_id or get_clsid(object)
  413. return stalker_classes[id] == true
  414. end
  415.  
  416. function isWeapon(object, class_id)
  417. local id = class_id or get_clsid(object)
  418. return weapon_classes[id] == true
  419. end
  420.  
  421. function isArtefact(object, class_id)
  422. local id = class_id or get_clsid(object)
  423. return artefact_classes[id] == true
  424. end
  425.  
  426.  
  427. -------------------------------------------------------------------------------------------
  428. function get_object_community(obj)
  429. if type(obj.id) == "function" then
  430. return character_community(obj)
  431. else
  432. return alife_character_community(obj)
  433. end
  434. end
  435.  
  436. function character_community (obj)
  437. if IsStalker(obj) then
  438. return obj:character_community()
  439. end
  440. return "monster"
  441. end
  442.  
  443. function alife_character_community (obj)
  444. if IsStalker(obj, obj:clsid()) then
  445. return obj:community()
  446. end
  447. return "monster"
  448. end
  449.  
  450. -- получить геймобжект по стори_айди.
  451. function level_object_by_sid( sid )
  452. local sim = alife()
  453. if sim then
  454. local se_obj = sim:story_object( sid )
  455. if se_obj then
  456. return level.object_by_id( se_obj.id )
  457. end
  458. end
  459. return nil
  460. end
  461. -- Получить айдишник обьекта по стори айди.
  462. function id_by_sid( sid )
  463. local sim = alife()
  464. if sim then
  465. local se_obj = sim:story_object( sid )
  466. if se_obj then
  467. return se_obj.id
  468. end
  469. end
  470. return nil
  471. end
  472.  
  473. -- Крешнуть игру (после вывода сообщения об ошибке в лог)
  474. function abort(fmt, ...)
  475. if not (fmt) then return end
  476. local fmt = tostring(fmt)
  477.  
  478. if (select('#',...) >= 1) then
  479. local i = 0
  480. local p = {...}
  481. local function sr(a)
  482. i = i + 1
  483. if (type(p[i]) == 'userdata') then
  484. return 'userdata'
  485. end
  486. return tostring(p[i])
  487. end
  488. fmt = string.gsub(fmt,"%%s",sr)
  489. end
  490.  
  491. get_console():execute("load ~#debug msg:"..fmt)
  492. end
  493.  
  494. function set_inactivate_input_time(delta)
  495. db.storage[db.actor:id()].disable_input_time = game.get_game_time()
  496. db.storage[db.actor:id()].disable_input_idle = delta
  497. level.disable_input()
  498. end
  499.  
  500. -- іринимает: позициі положения, позициі куда смотреть, время сна в минутах.
  501. --[[
  502. function set_sleep_relocate(point, look, timeout)
  503. db.storage[db.actor:id()].sleep_relocate_time = game.get_game_time()
  504. db.storage[db.actor:id()].sleep_relocate_idle = timeout*60
  505. db.storage[db.actor:id()].sleep_relocate_point = point
  506. db.storage[db.actor:id()].sleep_relocate_look = look
  507. end
  508. ]]--
  509.  
  510. -- проверяет целую часть числа на нечетность
  511. function odd( x )
  512. return math.floor( x * 0.5 ) * 2 == math.floor( x )
  513. end
  514.  
  515. --' находится ли NPC во фруструме игрока
  516. function npc_in_actor_frustrum(npc)
  517. local actor_dir = device().cam_dir
  518. --local actor_dir = db.actor:direction()
  519. local npc_dir = npc:position():sub(db.actor:position())
  520. local yaw = yaw_degree3d(actor_dir, npc_dir)
  521. --printf("YAW %s", tostring(yaw))
  522. return yaw < 35
  523. end
  524.  
  525. function start_game_callback()
  526. aa = alife()
  527.  
  528. squad_community_by_behaviour = {
  529. ["stalker"] = "stalker",
  530. ["bandit"] = "bandit",
  531. ["dolg"] = "dolg",
  532. ["freedom"] = "freedom",
  533. ["army"] = "army",
  534. ["ecolog"] = "ecolog",
  535. ["killer"] = "killer",
  536. ["zombied"] = "zombied",
  537. ["monolith"] = "monolith",
  538. ["monster"] = "monster",
  539. ["monster_predatory_day"] = "monster",
  540. ["monster_predatory_night"] = "monster",
  541. ["monster_vegetarian"] = "monster",
  542. ["monster_zombied_day"] = "monster",
  543. ["monster_zombied_night"] = "monster",
  544. ["monster_special"] = "monster"
  545. }
  546.  
  547.  
  548.  
  549.  
  550. monster_classes = {
  551. [clsid.bloodsucker_s] = true,
  552. [clsid.boar_s] = true,
  553. [clsid.dog_s] = true,
  554. [clsid.flesh_s] = true,
  555. [clsid.pseudodog_s] = true,
  556. [clsid.burer_s] = true,
  557. -- [clsid.cat_s] = true,
  558. [clsid.chimera_s] = true,
  559. [clsid.controller_s] = true,
  560. -- [clsid.fracture_s] = true,
  561. [clsid.poltergeist_s] = true,
  562. [clsid.gigant_s] = true,
  563. -- [clsid.zombie_s] = true,
  564. [clsid.snork_s] = true,
  565. [clsid.tushkano_s] = true,
  566. [clsid.psy_dog_s] = true,
  567. [clsid.psy_dog_phantom_s] = true}
  568.  
  569. stalker_classes = {
  570. [clsid.script_actor] = true,
  571. [clsid.script_stalker] = true}
  572.  
  573. weapon_classes = {
  574. [clsid.wpn_vintorez_s] = true,
  575. [clsid.wpn_ak74_s] = true,
  576. [clsid.wpn_lr300_s] = true,
  577. [clsid.wpn_hpsa_s] = true,
  578. [clsid.wpn_pm_s] = true,
  579. [clsid.wpn_shotgun_s] = true,
  580. [clsid.wpn_auto_shotgun_s] = true,
  581. [clsid.wpn_bm16_s] = true,
  582. [clsid.wpn_svd_s] = true,
  583. [clsid.wpn_svu_s] = true,
  584. [clsid.wpn_rg6_s] = true,
  585. [clsid.wpn_rpg7_s] = true,
  586. [clsid.wpn_val_s] = true,
  587. [clsid.wpn_walther_s] = true,
  588. [clsid.wpn_usp45_s] = true,
  589. [clsid.wpn_groza_s] = true,
  590. [clsid.wpn_knife_s] = true,
  591. [clsid.wpn_grenade_f1_s] = true,
  592. [clsid.wpn_grenade_rgd5_s] = true,
  593. [clsid.wpn_grenade_launcher] = true,
  594. [clsid.wpn_grenade_fake] = true}
  595.  
  596. artefact_classes = {
  597. [clsid.art_bast_artefact] = true,
  598. [clsid.art_black_drops] = true,
  599. [clsid.art_dummy] = true,
  600. [clsid.art_electric_ball] = true,
  601. [clsid.art_faded_ball] = true,
  602. [clsid.art_galantine] = true,
  603. [clsid.art_gravi] = true,
  604. [clsid.art_gravi_black] = true,
  605. [clsid.art_mercury_ball] = true,
  606. [clsid.art_needles] = true,
  607. [clsid.art_rusty_hair] = true,
  608. [clsid.art_thorn] = true,
  609. [clsid.art_zuda] = true,
  610. [clsid.artefact] = true,
  611. [clsid.artefact_s] = true}
  612.  
  613. printf ("start_game_callback called")
  614. smart_names.init_smart_names_table()
  615. task_manager.clear_task_manager()
  616. sound_theme.load_sound()
  617. xr_sound.start_game_callback()
  618. dialog_manager.fill_phrase_table()
  619. xr_s.init()
  620. sim_objects.clear()
  621. sim_board.clear()
  622. sr_light.clean_up ()
  623. pda.add_quick_slot_items_on_game_start()
  624. -- Tестирование оптимизации
  625. --local test_object = test_object.test_object_class()
  626. --test_object:test()
  627. end
  628.  
  629. --' Lсталость
  630. function on_actor_critical_power()
  631.  
  632. end
  633.  
  634. function on_actor_critical_max_power()
  635. end
  636.  
  637. --' іровотечение
  638. function on_actor_bleeding()
  639.  
  640. end
  641.  
  642. function on_actor_satiety()
  643. end
  644.  
  645. --' іадиация
  646. function on_actor_radiation()
  647.  
  648. end
  649.  
  650. --' іаклинило оружие
  651. function on_actor_weapon_jammed()
  652.  
  653. end
  654.  
  655. --' не может ходить изза веса
  656. function on_actor_cant_walk_weight()
  657.  
  658. end
  659.  
  660. --' пси воздействие
  661. function on_actor_psy()
  662. end
  663.  
  664. function give_info (info)
  665. db.actor:give_info_portion(info)
  666. end
  667. function disable_info (info)
  668. if has_alife_info(info) then
  669. printf("*INFO*: disabled npc='single_player' id='%s'", info)
  670. db.actor:disable_info_portion(info)
  671. end
  672. end
  673.  
  674. function create_ammo(section, position, lvi, gvi, pid, num)
  675. local ini = system_ini()
  676.  
  677. local num_in_box = ini:r_u32(section, "box_size")
  678. local t = {}
  679. while num > num_in_box do
  680. local obj = alife():create_ammo(section, position, lvi, gvi, pid, num_in_box)
  681. table.insert(t, obj)
  682. num = num - num_in_box
  683. end
  684. local obj = alife():create_ammo(section, position, lvi, gvi, pid, num)
  685. table.insert(t, obj)
  686. return t
  687. end
  688.  
  689. ammo_section = {}
  690. ammo_section["ammo_9x18_fmj"] = true
  691. ammo_section["ammo_9x18_pmm"] = true
  692. ammo_section["ammo_9x19_fmj"] = true
  693. ammo_section["ammo_9x19_pbp"] = true
  694. ammo_section["ammo_5.45x39_fmj"] = true
  695. ammo_section["ammo_5.45x39_ap"] = true
  696. ammo_section["ammo_5.56x45_ss190"] = true
  697. ammo_section["ammo_5.56x45_ap"] = true
  698. ammo_section["ammo_5.7x28_fmj"] = true
  699. ammo_section["ammo_5.7x28_ap"] = true
  700. ammo_section["ammo_7.62x54_7h1"] = true
  701. ammo_section["ammo_9x39_pab9"] = true
  702. ammo_section["ammo_gauss"] = true
  703. ammo_section["ammo_9x39_ap"] = true
  704. ammo_section["ammo_11.43x23_fmj"] = true
  705. ammo_section["ammo_11.43x23_hydro"] = true
  706. ammo_section["ammo_12x70_buck"] = true
  707. ammo_section["ammo_12x76_zhekan"] = true
  708. ammo_section["ammo_pkm_100"] = true
  709.  
  710. quest_section = {}
  711. -- преобразует строку в соответствии со значением
  712. function get_param_string(src_string , obj)
  713. --printf("src_string is [%s] obj name is [%s]", tostring(src_string), obj:name())
  714. local script_ids = db.script_ids[obj:id()]
  715. local out_string, num = string.gsub(src_string, "%$script_id%$", tostring(script_ids))
  716. if num > 0 then
  717. return out_string , true
  718. else
  719. return src_string , false
  720. end
  721. end
  722.  
  723. local save_markers = {}
  724.  
  725. -- Функции для проверки корректности сейв лоад
  726. function set_save_marker(p, mode, check, prefix)
  727.  
  728. -- определяем ключ маркера.
  729. local result = ""
  730. -- if debug ~= nil then
  731. -- local info_table = debug.getinfo(2)
  732. -- local script_name = string.gsub(info_table.short_src, "%.script", "")
  733. -- script_name = string.gsub(script_name, "gamedata\\scripts\\", "")
  734. -- result = script_name
  735. -- end
  736.  
  737. -- if prefix ~= nil then
  738. result = result .. "_" .. prefix
  739. -- end
  740.  
  741. if check == true then
  742. if save_markers[result] == nil then
  743. abort("Trying to check without marker %s", result)
  744. end
  745.  
  746. if mode == "save" then
  747. local dif = p:w_tell() - save_markers[result]
  748. printf(result..": SAVE DIF: %s", dif)
  749. if dif >= 8000 then
  750. printf("WARNING! may be this is problem save point")
  751. end
  752. if dif >= 10240 then
  753. -- abort("You are saving too much")
  754. end
  755. p:w_u16(dif)
  756. else
  757. local c_dif = p:r_tell() - save_markers[result]
  758. local dif = p:r_u16()
  759. if dif ~= c_dif then
  760. abort("INCORRECT LOAD [%s].[%s][%s]", result, dif, c_dif)
  761. else
  762. printf(result..": LOAD DIF: %s", dif)
  763. end
  764. end
  765. return
  766. end
  767.  
  768. if mode == "save" then
  769. printf(result..": set save marker: %s", p:w_tell())
  770. save_markers[result] = p:w_tell()
  771. if p:w_tell() > 16000 then
  772. abort("You are saving too much")
  773. end
  774. else
  775. printf(result..": set load marker: %s", p:r_tell())
  776. save_markers[result] = p:r_tell()
  777. end
  778.  
  779. end
  780. -- переводит вектор в строку.
  781. function vec_to_str (vector)
  782. if vector == nil then return "nil" end
  783. return string.format("[%s:%s:%s]", vector.x, vector.y, vector.z)
  784. end
  785. -- выводит в лог стэк вызова функций.
  786. function callstack()
  787. if debug ~= nil then
  788. log(debug.traceback(2))
  789. end
  790. end
  791. -- меняет team:squad:group обьекта.
  792. function change_team_squad_group(se_obj, team, squad, group)
  793. local cl_obj = db.storage[se_obj.id] and db.storage[se_obj.id].object
  794. if cl_obj ~= nil then
  795. cl_obj:change_team(team, squad, group)
  796. else
  797. se_obj.team = team
  798. se_obj.squad = squad
  799. se_obj.group = group
  800. end
  801. --printf("_G:TSG: [%s][%s][%s]", tostring(se_obj.team), tostring(se_obj.squad), tostring(se_obj.group))
  802. end
  803. -- Story_ID -------------------------------------------------------------
  804. function add_story_object(obj_id , story_obj_id)
  805. story_objects.get_story_objects_registry():register(obj_id , story_obj_id)
  806. end
  807.  
  808. function get_story_object(story_obj_id)
  809. local obj_id = story_objects.get_story_objects_registry():get(story_obj_id)
  810. if obj_id == nil then return nil end
  811. return (db.storage[obj_id] and db.storage[obj_id].object) or (level ~= nil and level.object_by_id(obj_id))
  812. end
  813.  
  814. function get_object_story_id(obj_id)
  815. return story_objects.get_story_objects_registry():get_story_id(obj_id)
  816. end
  817.  
  818. function get_story_object_id(story_obj_id)
  819. return story_objects.get_story_objects_registry().id_by_story_id[story_obj_id]
  820. end
  821.  
  822. function unregister_story_object_by_id(obj_id)
  823. story_objects.get_story_objects_registry():unregister_by_id(obj_id)
  824. end
  825.  
  826. function unregister_story_id(story_id)
  827. story_objects.get_story_objects_registry():unregister_by_story_id(story_id)
  828. end
  829.  
  830. -----------------------------------------------------------------------------------------------
  831. -- Получить сквад обьекта!!!!!
  832. function get_object_squad(object)
  833. if object == nil then abort("You are trying to get squad_object from NIL object!!!") end
  834. local obj_id = nil
  835. if type(object.id) == "function" then
  836. obj_id = object:id()
  837. else
  838. obj_id = object.id
  839. end
  840. local se_obj = alife():object(obj_id)
  841. if se_obj and se_obj.group_id ~= 65535 then
  842. return alife():object(se_obj.group_id)
  843. end
  844. return nil
  845. end
  846.  
  847. function get_story_squad(story_id)
  848. local squad_id = get_story_object_id(story_id)
  849. return squad_id and alife():object(squad_id)
  850. end
  851.  
  852. --Проверка по временному интервалу.
  853. function in_time_interval(val1, val2)
  854. local game_hours = level.get_time_hours()
  855. if val1 >= val2 then
  856. return game_hours < val2 or game_hours >= val1
  857. else
  858. return game_hours < val2 and game_hours >= val1
  859. end
  860. end
  861.  
  862. function show_all_ui(show)
  863. local hud = get_hud()
  864. if(show) then
  865. level.show_indicators()
  866. -- db.actor:restore_weapon()
  867. db.actor:disable_hit_marks(false)
  868. hud:show_messages()
  869. else
  870. if db.actor:is_talking() then
  871. db.actor:stop_talk()
  872. end
  873. level.hide_indicators_safe()
  874. hud:HideActorMenu()
  875. hud:HidePdaMenu()
  876. hud:hide_messages()
  877. -- db.actor:hide_weapon()
  878. db.actor:disable_hit_marks(true)
  879. end
  880. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement