Advertisement
Guest User

xr_conditions.script

a guest
Dec 1st, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 60.52 KB | None | 0 0
  1. --[[
  2.     modified by Alundaio (original: ???? GSC)
  3.  
  4.  
  5.     Copyright (C) 2012 Alundaio
  6.  
  7.     This program is free software; you can redistribute and/or modify
  8.     it under the terms of the Open S.T.A.L.K.E.R. Mod License version 1.0.
  9. -]]
  10. function dist_to_lvid_ge(actor,npc,p)
  11.     local vid = tonumber(p[1])
  12.     if not (vid) then
  13.         return
  14.     end
  15.     local position = level.vertex_position(vid)
  16.     if (npc:position():distance_to_sqr(position) >= tonumber(p[2])) then
  17.         return true
  18.     end
  19.     return false
  20. end
  21.  
  22. function dist_to_job_point_le(actor, npc, p)
  23.     if not (npc) then
  24.         return false
  25.     end
  26.     local smart = xr_gulag.get_npc_smart(npc)
  27.     if smart == nil then return false end
  28.  
  29.         local npc_info = smart.npc_info[npc:id()]
  30.     if npc_info then
  31.         local npc_job = smart.job_data[npc_info.job_id]
  32.  
  33.         local alife_task = npc_job.alife_task
  34.         if alife_task then
  35.             return npc:position():distance_to_sqr(alife_task:position()) <= p[1]*p[1]
  36.         end
  37.     end
  38.  
  39.     return false
  40. end
  41. function dist_to_job_point_ge(actor, npc, p)
  42.     if not (npc) then
  43.         return false
  44.     end
  45.     local smart = xr_gulag.get_npc_smart(npc)
  46.     if smart == nil then return false end
  47.  
  48.         local npc_info = smart.npc_info[npc:id()]
  49.     if npc_info then
  50.         local npc_job = smart.job_data[npc_info.job_id]
  51.  
  52.         local alife_task = npc_job.alife_task
  53.         if alife_task then
  54.             return npc:position():distance_to_sqr(alife_task:position()) >= p[1]*p[1]
  55.         end
  56.     end
  57.  
  58.     return false
  59. end
  60.  
  61. function is_enemy_fighting_actor(actor,npc,p)
  62.     local be = npc:best_enemy()
  63.     if (be and xr_combat_ignore.fighting_with_actor_npcs[be:id()]) then
  64.         return true
  65.     end
  66.     return false
  67. end
  68.  
  69. -- Êàæäàÿ ôóíêöèÿ â ýòîì ôàéëå èñïîëüçóåòñÿ êàê óñëîâèå xr_logic: {=ôóíêöèÿ !ôóíêöèÿ}
  70. -- Åñëè â ôóíêöèþ íåîáõîäèìî ïåðåäàâàòü ïàðàìåòðû, òî:  {=ôóíêöèÿ(ïàðàì1:ïàðàì2:...) !ôóíêöèÿ(ïàðàì1:ïàðàì2:...)}
  71. -- Ôîðìàò: function f(actor, npc).  ñëó÷àå ïåðåäà÷è ïàðàìåòðîâ: function f(actor, npc, p).
  72. -- ----------------------------------------------------------------------------------------------------
  73. -- Ôóíêöèè äëÿ ðàáîòû ñ combat_ignore_cond
  74. -- ----------------------------------------------------------------------------------------------------
  75. function is_enemy_actor(actor, npc, p)
  76.     local st = db.storage[npc:id()]
  77.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  78.     return be and be:alive() and be:id() == db.actor:id()
  79. end
  80.  
  81. -- òåêóùèé âðàã íà ðàññòîÿíèè áîëüøå èëè ðàâíîì çàäàííîìó ðàññòîÿíèþ
  82. -- äëÿ combat_ignore
  83. function fighting_dist_ge(actor, npc, p)
  84.     local st = db.storage[npc:id()]
  85.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  86.     local d = p[1]
  87.     return be and be:alive() and be:position():distance_to_sqr(npc:position()) >= d * d
  88. end
  89.  
  90. -- ðàññòîÿíèå äî òåêóùåãî ðåàëüíîãî âðàãà ìåíüøå èëè ðàâíî çàäàííîãî çíà÷åíèÿ
  91. function fighting_dist_le(actor, npc, p)
  92.     local st = db.storage[npc:id()]
  93.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  94.     local d = p[1]
  95.     return be and be:alive() and be:position():distance_to_sqr(npc:position()) <= d * d
  96. end
  97.  
  98. function enemy_in_zone(actor, npc, p)
  99.     local st = db.storage[npc:id()]
  100.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  101.     local zone = db.zone_by_name[p[1]]
  102.     return zone and be and be:alive() and utils.npc_in_zone(be, zone)
  103. end
  104.  
  105.  
  106. -- ----------------------------------------------------------------------------------------------------
  107. -- Îáùèå ôóíêöèè
  108. -- ----------------------------------------------------------------------------------------------------
  109. -- âèäèì ëè ìû åùå "÷åðíûé ýêðàí" èëè íåò?
  110. function black_screen(actor, npc)
  111.     return device().precache_frame > 1
  112. end
  113. --Ïðîâåðêà, âñòðå÷àåòñÿ ëè â èìåíè ÷óâàêà îäíà èç ñòðîê .
  114. function check_npc_name (actor , npc , p)
  115.     if npc:name() == nil then return false end
  116.     for k,v in pairs(p) do
  117.         if string.find( npc:name(), v ) then
  118.             return true
  119.         end
  120.     end
  121.     return false
  122. end
  123.  
  124. function check_squad_name (actor , npc , p)
  125.     local squad = get_object_squad(npc)
  126.     if not (squad) then
  127.         return
  128.     end
  129.  
  130.     local sq
  131.     for k,v in pairs(p) do
  132.         sq = get_story_squad(v)
  133.         if (sq and sq.id == squad.id) then
  134.             return true
  135.         end
  136.     end
  137.     return
  138. end
  139.  
  140. function check_enemy_name (actor , npc , p)
  141.     local enemy_id = db.storage[npc:id()].enemy_id
  142.     local enemy = enemy_id and db.storage[enemy_id] and db.storage[enemy_id].object
  143.     local name
  144.     if enemy and enemy:alive() then
  145.         name = enemy:name()
  146.         for i, v in pairs(p) do
  147.             if string.find( name, v ) ~= nil then
  148.                 return true
  149.             end
  150.         end
  151.     end
  152.     return false
  153. end
  154.  
  155. function is_playing_sound (actor, npc)
  156.     return xr_sound.sound_table[npc:id()] ~= nil
  157. end
  158.  
  159. -- ïðîâåðêà, ÷òî àêòåð æèâ
  160. function actor_alive(actor, npc)
  161.     if db.actor and db.actor:alive() then
  162.         return true
  163.     end
  164.     return false
  165. end
  166.  
  167. function see_npc(actor, npc, p)
  168.     local npc1 = get_story_object(p[1])
  169.     if npc and npc1 then
  170.         --printf("cond <see_npc>: [%s]->[%s]", npc:name(), npc1:name())
  171.         return npc:see(npc1)
  172.     else
  173.         return false
  174.     end
  175. end
  176.  
  177. function actor_see_npc(actor, npc)
  178.     return db.actor:see(npc)
  179. end
  180.  
  181. function npc_in_actor_frustum(actor, npc)
  182.     return npc_in_actor_frustrum(npc)
  183. end
  184.  
  185. function is_wounded(actor, npc)
  186.     return xr_wounded.is_wounded(npc)
  187. end
  188.  
  189. function dist_to_actor_le(actor, npc, p)
  190.     local d = p[1]
  191.     if d == nil then
  192.         abort("Wrong parameter in 'dist_to_actor_le' function!!!")
  193.     end
  194.     return d and npc:position():distance_to_sqr(actor:position()) <= d * d
  195. end
  196.  
  197. function dist_to_actor_ge(actor, npc, p)
  198.     local d = p[1]
  199.     if d == nil then
  200.         abort("Wrong parameter in 'dist_to_actor_ge' function!!!")
  201.     end
  202.     return d and npc:position():distance_to_sqr(actor:position()) >= d * d
  203. end
  204.  
  205. -- Ïðîâåðêà âûïîëíÿåò ëè êòî óêàçàííóþ ðàáîòó
  206. function is_obj_on_job(actor, npc, p)
  207.     if not (npc) then
  208.         return false
  209.     end
  210.     local smart
  211.     if p and p[2] then
  212.         smart = sim_board.get_sim_board():get_smart_by_name(p[2])
  213.     else
  214.         smart = xr_gulag.get_npc_smart(npc)
  215.     end
  216.     if smart == nil then
  217.         return false
  218.     end
  219.     local npc_job
  220.     for k,v in pairs(smart.npc_info) do
  221.         npc_job = smart.job_data[v.job_id]
  222.         printf("section [%s]", tostring(npc_job.section))
  223.         if npc_job.section == p[1] then
  224.             return true
  225.         end
  226.     end
  227.     return false
  228. end
  229.  
  230. function is_enemy_on_job(actor, npc, p)
  231.     local enemy_id = db.storage[npc:id()].enemy_id
  232.     local enemy = enemy_id and db.storage[enemy_id] and db.storage[enemy_id].object
  233.     if not (enemy) then
  234.         return false
  235.     end
  236.     local smart
  237.     if p and p[2] then
  238.         smart = sim_board.get_sim_board():get_smart_by_name(p[2])
  239.     else
  240.         smart = xr_gulag.get_npc_smart(enemy)
  241.     end
  242.     if smart == nil then
  243.         return false
  244.     end
  245.     local npc_job
  246.     for k,v in pairs(smart.npc_info) do
  247.         npc_job = smart.job_data[v.job_id]
  248.         printf("section [%s]", tostring(npc_job.section))
  249.         if npc_job.section == p[1] then
  250.             return true
  251.         end
  252.     end
  253.     return false
  254. end
  255.  
  256. function enemy_smart(actor, npc, p)
  257.     if not (npc:best_enemy()) then
  258.         return
  259.     end
  260.  
  261.     local enemy_id = db.storage[npc:id()].enemy_id
  262.     local enemy = enemy_id and db.storage[enemy_id] and db.storage[enemy_id].object
  263.     if not (enemy) then
  264.         return
  265.     end
  266.  
  267.     local smart = xr_gulag.get_npc_smart(enemy)
  268.     if not (smart) then
  269.         return
  270.     end
  271.  
  272.     return p and smart:name() == p[1]
  273. end
  274. -- ïðîâåðêà òîãî ÷òî äèñòàíöèÿ äî îáüåêòà <= çàäàííîé
  275. -- ïàðàìåòðû: [sid,dist]
  276. function distance_to_obj_on_job_le(actor, npc, p)
  277.     if not (npc) then
  278.         return false
  279.     end
  280.     local smart = xr_gulag.get_npc_smart(npc)
  281.     local npc_job
  282.     for k,v in pairs(smart.npc_info) do
  283.         npc_job = smart.job_data[v.job_id]
  284.         if npc_job.section == p[1] then
  285.             return npc:position():distance_to_sqr(v.se_obj.position) <= p[2]*p[2]
  286.         end
  287.     end
  288.     return false
  289. end
  290.  
  291. -- ïðîâåðêà òîãî ÷òî npc íàõîäèòñÿ â çàäàííîé çîíå
  292. -- !!! ÂÛÇÛÂÀÒÜ ÒÎËÜÊÎ ÈÇ SPACE RESTRICTOR !!!
  293. -- ïàðàìåòðû: [sid1:sid2:...]
  294. -- !!! ÍÅÊÎÐÐÅÊÒÍÎ ÐÀÁÎÒÀÅÒ ÄËß ÎÁÜÅÊÒÎÂ Â offline'e !!!
  295. -- !!! ÄËß ÃÀÐÀÍÒÈÈ ÈÑÏÎËÜÇÎÂÀÒÜ one_obj_in_zone !!!
  296. function obj_in_zone(actor, zone, p)
  297.     local npc1, i, v = 0, 0, 0
  298.     for i, v in pairs(p) do
  299.         npc1 = get_story_object_id(v)
  300.         if npc1 and zone:inside(alife():object(npc1).position) then
  301.             return true
  302.         end
  303.     end
  304.     return false
  305. end
  306.  
  307. -- ïàðàìåòðû: [sid:def*] def=true|false
  308. -- * ïàðàìåòð íå îáÿçàòåëåí
  309. function one_obj_in_zone(actor, zone, p)
  310.     --local def_offline = (p[2] ~= "false") -- default (true) result if npc in offline
  311.     local obj1 = get_story_object_id(p[1])
  312.  
  313.     if obj1 then -- npc is online
  314.         return zone:inside(alife():object(obj1).position)
  315.     else -- npc is offline
  316.         return (p[2] ~= "false") -- default (true) result if npc in offline
  317.     end
  318. end
  319.  
  320. function story_obj_in_zone_by_name (actor, npc, p)
  321.     local obj = get_story_object_id(p[1])
  322.     local zone = db.zone_by_name[p[2]]
  323.     if obj and zone then -- npc is online
  324.         return zone:inside(alife():object(obj).position)
  325.     end
  326.     return false
  327. end
  328.  
  329. function actor_in_zone(actor, npc, p)
  330.     local zone = db.zone_by_name[p[1]]
  331.     return utils.npc_in_zone(db.actor, zone)
  332. end
  333.  
  334. function npc_in_zone(actor, npc, p)
  335.     local zone = db.zone_by_name[p[1]]
  336.  
  337.     if type(npc.id) ~= "function" then
  338.         npc_obj = db.storage[npc.id] and db.storage[npc.id].object
  339.         if zone == nil then
  340.             return true
  341.         end
  342.  
  343.         if npc_obj == nil then
  344.             return zone:inside(npc.position)
  345.         end
  346.     else
  347.         npc_obj = npc
  348.     end
  349.  
  350.     return utils.npc_in_zone(npc_obj, zone)
  351. end
  352.  
  353. -- true, åñëè çäîðîâüå npc <= çàäàííîìó çíà÷åíèþ
  354. -- false â ïðîòèâíîì ñëó÷àå
  355. function health_le(actor, npc, p)
  356.     return p[1] and npc.health < p[1]
  357. end
  358.  
  359. -- true, åñëè çäîðîâüå àêòåðà  <= çàäàííîìó çíà÷åíèþ
  360. -- false â ïðîòèâíîì ñëó÷àå
  361. function actor_health_le(actor, npc, p)
  362.     return p[1] and actor.health < p[1]
  363. end
  364.  
  365. --[[
  366. -- true, åñëè çäîðîâüå âåðòîë¸òà <= çàäàííîìó çíà÷åíèþ
  367. -- false â ïðîòèâíîì ñëó÷àå
  368. function heli_health_le(actor, obj, p)
  369.     return p[1] and obj:get_helicopter():GetfHealth() < p[1]
  370. end
  371.  
  372. -- âèäèò ëè âåðòîë¸ò npc (ïî story id)
  373. function heli_see_npc(actor, obj, p)
  374.     if p[1] then
  375.         local o = get_story_object( p[1] )
  376.         return o ~= nil and obj:get_helicopter():isVisible( o )
  377.     else
  378.         return false
  379.     end
  380. end
  381.  
  382. function heli_see_actor(actor, obj)
  383.     return actor ~= nil and obj:get_helicopter():isVisible( actor )
  384. end
  385.  
  386. -- Ïðîâåðêà íà ïðèíàäëåæíîñòü âðàãà ê îäíîé èç ãðóïï
  387. -- (ìîæíî çàäàâàòü íåñêîëüêî ÷åðåç äâîåòî÷èå)
  388. function enemy_group(actor, npc, p)
  389.     local enemy_id = db.storage[npc:id()].enemy_id
  390.     local enemy = db.storage[enemy_id] and db.storage[enemy_id].object
  391.     local g = enemy:group()
  392.     local i, v = 0, 0
  393.     for i, v in pairs(p) do
  394.         if v == g then
  395.             --printf("_bp: [%s]'s enemy is from group [%d]", npc:name(), v)
  396.             return true
  397.         end
  398.     end
  399.     return false
  400. end
  401.  
  402. function gulag_state(actor, npc, p)
  403.     if xr_gulag.getGulagState(p[1]) == p[2] then
  404.         return true
  405.     end
  406.     return false
  407. end
  408. ]]--
  409.  
  410. function npc_community(actor, npc, p)
  411.     local npc_obj
  412.  
  413.     if p[1] == nil then
  414.         abort("Wrong number of params in npc_community")
  415.     end
  416.  
  417.     if type(npc.id) ~= "function" then
  418.         npc_obj = db.storage[npc.id] and db.storage[npc.id].object
  419.  
  420.         if npc_obj == nil then return npc:community() == p[1] end
  421.     else
  422.         npc_obj = npc
  423.     end
  424.  
  425.     if character_community(npc_obj) == p[1] then
  426.         return true
  427.     end
  428.     return false
  429. end
  430.  
  431. --[[
  432. function npc_rank(actor, npc, p)
  433.     if p[1] == nil then
  434.         abort("Wrong number of params in npc_rank")
  435.     end
  436.  
  437.     if ranks.get_obj_rank_name(npc) == p[1] then
  438.         return true
  439.     end
  440.     return false
  441. end
  442.  
  443. function npc_profile(actor, npc, p)
  444.     if p[1] == nil then
  445.         abort("Wrong number of params in npc_profile")
  446.     end
  447.     if npc:profile_name() == p[1] then
  448.         return true
  449.     end
  450.     return false
  451. end
  452. ]]--
  453.  
  454. -- Ïðîâåðêà òîãî ÷òî óäàð áûë íàíåñåí êåì-òî èç npc óêàçàííûõ â ñïèñêå.
  455. -- Ïàðàìåòðû ýòî story_id ïåðñîíàæåé. Ìîæíî çàäàâàòü íåñêîëüêî story_id.
  456. function hitted_by(actor, npc, p)
  457.     local npc1
  458.     local t = db.storage[npc:id()].hit
  459.     if t then
  460.         for i, v in pairs(p) do
  461.             npc1 = get_story_object(v)
  462.             if npc1 and t.who == npc1:id() then
  463.                 return true
  464.             end
  465.         end
  466.     end
  467.     return false
  468. end
  469. -- Ôóíêöèÿ ïðîâåðêè ïîïàäàíèÿ â êîñòü ïî å¸ èíäåêñó.(Ïðîâåðêà òîëüêî äëÿ ñåêöèè hit)
  470. function hitted_on_bone(actor, npc, p)
  471.     for k,v in pairs (p) do
  472.         if db.storage[npc:id()].hit.bone_index == npc:get_bone_id(v) then
  473.             return true
  474.         end
  475.     end
  476.     return false
  477. end
  478.  
  479. -- Ïðîâåðêà, ÷òî ëó÷øåå îðóæèå ïåðñîíàæà - ïèñòîëåò
  480. function best_pistol(actor, npc)
  481.     local pistol = npc:item_in_slot(1)
  482.     if pistol ~= nil then
  483.         return true
  484.     else
  485.         return false
  486.     end
  487. end
  488.  
  489. -- Ïðîâåðêà, ÷òî ïåðñîíàæó íàíåñëè ñìåðòåëüíûé õèò. Ïðîâåðÿòü ÒÎËÜÊÎ íà on_hit
  490. function deadly_hit(actor, npc)
  491.     if db.storage[npc:id()] == nil or db.storage[npc:id()].hit == nil then
  492.         --printf("deadly hit false")
  493.         return false
  494.     end
  495.  
  496.     --printf("deadly hit [%s]", tostring(db.storage[npc:id()].hit.deadly_hit == true))
  497.     return db.storage[npc:id()].hit.deadly_hit == true
  498. end
  499.  
  500.  
  501.  
  502. -- Ïðîâåðêà òîãî ÷òî ïåðñîíàæ áûë óáèò êåì-òî èç npc óêàçàííûõ â ñïèñêå.
  503. -- Ïàðàìåòðû ýòî story_id ïåðñîíàæåé. Ìîæíî çàäàâàòü íåñêîëüêî story_id.
  504. function killed_by(actor, npc, p)
  505.     local npc1
  506.     local t = db.storage[npc:id()].death
  507.     if t then
  508.         for i, v in pairs(p) do
  509.             npc1 = get_story_object(v)
  510.             if npc1 and t.killer == npc1:id() then
  511.                 printf("_bp: killed_by(%d)", v)
  512.                 return true
  513.             end
  514.         end
  515.     end
  516.     return false
  517. end
  518.  
  519. -- ïðîâåðêà (ïî story_id) âñå ëè ïðîâåðÿåìûå ñòàëêåðû æèâû
  520. -- TODO: èñïðàâèòü ñèòóàöèþ, êîãäà âûäàåòñÿ íåïðàâèëüíûé ðåçóëüòàò äëÿ îáüåêòîâ, êîòîðûå
  521. --       íå óñïåëè ïðîñïàâíèòüñÿ.
  522. function is_alive_all(actor, npc, p)
  523.     local npc1
  524.     for i, v in pairs(p) do
  525.         npc1 = get_story_object_id(v)
  526.         if npc1 == nil then
  527.             return false
  528.         end
  529.         npc1 = alife():object(npc1)
  530.         if npc1 and (not IsStalker(npc1) or not npc1:alive()) then
  531.             return false
  532.         end
  533.     end
  534.     return true
  535. end
  536.  
  537. -- ïðîâåðêà (ïî story_id) òîãî, ÷òî ÷îòÿ áû îäèí èç ïðîâåðÿåìûõ ñòàëêåðîâ æèâ
  538. -- TODO: èñïðàâèòü ñèòóàöèþ, êîãäà âûäàåòñÿ íåïðàâèëüíûé ðåçóëüòàò äëÿ îáüåêòîâ, êîòîðûå
  539. --       íå óñïåëè ïðîñïàâíèòüñÿ.
  540. function is_alive_one(actor, npc, p)
  541.     local npc1
  542.     for i, v in pairs(p) do
  543.         npc1 = get_story_object_id(v)
  544.         if npc1 == nil then
  545.             return false
  546.         end
  547.         npc1 = alife():object(npc1)
  548.         if npc1 and IsStalker(npc1) and npc1:alive() then
  549.             return true
  550.         end
  551.     end
  552.     return false
  553. end
  554.  
  555. -- ïðîâåðêà (ïî story_id) òîãî, ÷òî ïðîâåðÿåìûq npc æèâ
  556. -- TODO: èñïðàâèòü ñèòóàöèþ, êîãäà âûäàåòñÿ íåïðàâèëüíûé ðåçóëüòàò äëÿ îáüåêòîâ, êîòîðûå
  557. --       íå óñïåëè ïðîñïàâíèòüñÿ.
  558. function is_alive(actor, npc, p)
  559.     local npc1
  560.  
  561.     if npc == nil or (p and p[1]) then
  562.         npc1 = get_story_object_id(p[1])
  563.     elseif (type(npc.id) == "number") then
  564.         npc1 = npc.id
  565.     else
  566.         npc1 = npc:id()
  567.     end
  568.  
  569.     if npc1 == nil then
  570.         return false
  571.     end
  572.  
  573.     npc1 = alife():object(npc1)
  574.  
  575.     if npc1 and IsStalker(npc1) and npc1:alive() then
  576.         return true
  577.     end
  578.  
  579.     return false
  580. end
  581.  
  582. -- ïðîâåðêà (ïî story_id) âñå ëè ïðîâåðÿåìûå ñòàëêåðû ìåðòâû
  583. -- TODO: èñïðàâèòü ñèòóàöèþ, êîãäà âûäàåòñÿ íåïðàâèëüíûé ðåçóëüòàò äëÿ îáüåêòîâ, êîòîðûå
  584. --       íå óñïåëè ïðîñïàâíèòüñÿ.
  585. function is_dead_all(actor, npc, p)
  586.     local npc1
  587.     for i, v in pairs(p) do
  588.         npc1 = get_story_object(v)
  589.         if npc1 then
  590.             if npc1:alive() then
  591.                 return false
  592.             else
  593.                 printf("_bp: is_dead_all(%d) = true", v)
  594.                 return true
  595.             end
  596.         end
  597.         return false
  598.     end
  599.     return true
  600. end
  601.  
  602. -- ïðîâåðêà (ïî story_id) òîãî, ÷òî õîòÿ áû îäèí èç ïðîâåðÿåìûõ ñòàëêåðîâ ìåðòâ
  603. -- TODO: èñïðàâèòü ñèòóàöèþ, êîãäà âûäàåòñÿ íåïðàâèëüíûé ðåçóëüòàò äëÿ îáüåêòîâ, êîòîðûå
  604. --       íå óñïåëè ïðîñïàâíèòüñÿ.
  605. function is_dead_one(actor, npc, p)
  606.     local npc1
  607.     for i, v in pairs(p) do
  608.         npc1 = get_story_object(v)
  609.         if not npc1 or not npc1:alive() then
  610.             printf("_bp: is_dead_one(%d) = true", v)
  611.             return true
  612.         end
  613.     end
  614.     return false
  615. end
  616.  
  617. -- ïðîâåðêà (ïî story_id) òîãî, ÷òî õîòÿ áû îäèí èç ïðîâåðÿåìûõ ñòàëêåðîâ ìåðòâ
  618. -- TODO: èñïðàâèòü ñèòóàöèþ, êîãäà âûäàåòñÿ íåïðàâèëüíûé ðåçóëüòàò äëÿ îáüåêòîâ, êîòîðûå
  619. --       íå óñïåëè ïðîñïàâíèòüñÿ.
  620. function is_dead(actor, npc, p)
  621.     local npc1
  622.     npc1 = get_story_object(p[1])
  623.     return not npc1 or not npc1:alive()
  624. end
  625.  
  626. -- Ïðîâåðÿåò , ñóùåñòâóåò ëè îáüåêò ñ çàäàííûì ñòîðè àéäè.
  627. function story_object_exist(actor, npc, p)
  628.     local npc1 = get_story_object(p[1])
  629.     return npc1 ~= nil
  630. end
  631.  
  632. --[[
  633. -- ïðîâåðêà (ïî story_id) òîãî, ÷òî íàøèì âðàãîì åñòü õîòÿ áû êîòî-òî îäèí èç ñïèñêà
  634. function check_fighting(actor, npc, p)
  635.     local enemy_id = db.storage[npc:id()].enemy_id
  636.     local enemy = db.storage[enemy_id] and db.storage[enemy_id].object
  637.     local sid
  638.     if enemy and enemy:alive() then
  639.             sid = enemy:story_id()
  640.             for i, v in pairs(p) do
  641.                     --printf("_bp: %s.check_fighting(%d)", npc:name(), v)
  642.                 if type(v) == 'number' and sid == v then
  643.                     --printf("TRUE")
  644.                     return true
  645.                 end
  646.             end
  647.     end
  648.     --printf("_bp: check_fighting() = false")
  649.     return false
  650. end
  651. ]]--
  652.  
  653.  
  654. -- true, åñëè ó àêò¸ðà â èíâåíòàðå åñòü óêàçàííûé ïðåäìåò
  655. -- false, åñëè íåòó, ëèáî íå çàäàíà ñåêöèÿ ïðåäìåòà
  656. function actor_has_item(actor, npc, p)
  657.     local story_actor  = get_story_object("actor")
  658.     return p[1] ~= nil and story_actor and story_actor:object( p[1] ) ~= nil
  659. end
  660.  
  661. function npc_has_item(actor, npc, p)
  662.     return p[1] ~= nil and npc:object( p[1] ) ~= nil
  663. end
  664. -- ïðîâåðÿåò íàëè÷èå çàäàíîãî êîëè÷åñòâà ïðåäìåòîâ â èíâåíòàðå èãðîêà.
  665. function actor_has_item_count(actor, npc, p)
  666.     local item_section  = p[1]
  667.     local need_count    = tonumber(p[2])
  668.     local has_count     = 0
  669.     local function calc(temp, item)
  670.         --printf("item [%s]",tostring(item:section()))
  671.         if item:section() == item_section then
  672.             has_count = has_count + 1
  673.         end
  674.     end
  675.     actor:iterate_inventory(calc, actor)
  676.     return has_count >= need_count
  677. end
  678.  
  679. -- âîçâðàùàåò true, åñëè â òåêóùåé ñõåìå ïåðñîíàæà âçâåä¸í óêàçàííûé ñèãíàë.
  680. function signal(actor, npc, p)
  681.     if p[1] then
  682.         local st   = db.storage[npc:id()]
  683.         local sigs = st[st.active_scheme].signals
  684. --      printf( "xr_conditions.signal: npc=%s, scheme=%s", npc:name(), tostring(st.active_scheme) )
  685.         return sigs ~= nil and sigs[p[1]] == true
  686.     else
  687.         return false
  688.     end
  689. end
  690.  
  691. -- âîçâðàùàåò true, åñëè çíà÷åíèå óêàçàííîãî ñ÷¸ò÷èêà àêò¸ðà áîëüøå óêàçàííîãî ÷èñëà
  692. function counter_greater(actor, npc, p)
  693.     if p[1] and p[2] then
  694.         local c = xr_logic.pstor_retrieve(actor, p[1], 0)
  695. --      if  c > p[2] then printf("pl: counter [%s]  greater [%s]", p[1], p[2]) end
  696.         return c > p[2]
  697.     else
  698.         return false
  699.     end
  700. end
  701. function counter_equal(actor, npc, p)
  702.     if p[1] and p[2] then
  703.         local c = xr_logic.pstor_retrieve(actor, p[1], 0)
  704.         return c == p[2]
  705.     else
  706.         return false
  707.     end
  708. end
  709.  
  710. --[[
  711. -- îïðåäåëÿåò íå÷¸òíîñòü èíòåðâàëà èãðîâîãî âðåìåíè. èíòåðâàë íóæíî ïåðåäàòü â p[1]
  712. function odd_time_interval(actor, npc, p)
  713.     return odd( game.time() / p[1] )
  714. end
  715. ]]--
  716. -------------------------------------------------------------------------------------------------------
  717. -- Ôóíêöèè ïîääåðæêè kamp
  718. function _kamp_talk(actor, npc)
  719.     if xr_kamp.kamp_stalkers[npc:id()] then
  720.         return xr_kamp.kamp_stalkers[npc:id()]
  721.     end
  722.     return false
  723. end
  724.  
  725. function _used(actor, npc)
  726.     return npc:is_talking()
  727. end
  728. -------------------------------------------------------------------------------------------------------
  729.  
  730. -------------------------------------------------------------------------------------------------------
  731. local alarm_statuses = {
  732.     normal = smart_terrain_control.NORMAL,
  733.     danger = smart_terrain_control.DANGER,
  734.     alarm = smart_terrain_control.ALARM
  735. }
  736.  
  737. -- Ôóíêöèè ïîääåðæêè áåçîïàñíîñòè áàç
  738. function check_smart_alarm_status(actor, npc, p)
  739.     local smart_name = p[1]
  740.     local status = alarm_statuses[p[2]]
  741.  
  742.     if status == nil then
  743.         abort("Wrong status[%s] in 'check_smart_alarm_status'", tostring(p[2]))
  744.     end
  745.  
  746.     local smart = sim_board.get_sim_board():get_smart_by_name(smart_name)
  747.  
  748.     local smart_control = smart.base_on_actor_control
  749.  
  750.     if smart_control == nil then
  751.         abort("Cannot calculate 'check_smart_alarm_status' for smart %s", tostring(smart_name))
  752.     end
  753.  
  754.     return smart_control:get_status() == status
  755. end
  756.  
  757. -------------------------------------------------------------------------------------------------------
  758. function has_enemy(actor, npc)
  759.     return npc:best_enemy() ~= nil
  760. end
  761.  
  762. function has_pure_enemy(actor, npc)
  763.     local st = db.storage[npc:id()]
  764.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  765.     return be and be:alive()
  766. end
  767.  
  768. function pure_enemy_mem_time_le(actor, npc, p)
  769.     local st = db.storage[npc:id()]
  770.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  771.     return p and p[1] and be and be:alive() and npc:memory_time(be) <= tonumber(p[1])
  772. end
  773.  
  774. function has_actor_enemy(actor, npc)
  775.     local best_enemy = npc:best_enemy()
  776.     return best_enemy ~= nil and best_enemy:id() == db.actor:id()
  777. end
  778.  
  779. function see_pure_enemy(actor,npc)
  780.     local st = db.storage[npc:id()]
  781.     local be = npc:best_enemy() or st and st.enemy_id and level.object_by_id(st.enemy_id)
  782.     return be and be:alive() and npc:see(be)
  783. end
  784.  
  785. function see_enemy(actor, npc)
  786.     local enemy = npc:best_enemy()
  787.  
  788.     if enemy ~= nil then
  789.             return npc:see(enemy)
  790.     end
  791.     return false
  792. end
  793.  
  794. function has_enemy_in_current_loopholes_fov(actor, npc)
  795.     return npc:in_smart_cover() and npc:best_enemy() ~= nil and npc:in_current_loophole_fov( npc:best_enemy():position())
  796. end
  797.  
  798. function talking(actor, npc)
  799.     return actor:is_talking()
  800. end
  801.  
  802. function npc_talking(actor, npc)
  803.     return npc:is_talking()
  804. end
  805.  
  806. function see_actor(actor, npc)
  807.     return npc:alive() and npc:see(actor)
  808. end
  809.  
  810. function actor_enemy(actor, npc)
  811.     local t = db.storage[npc:id()].death
  812.     return npc:relation(actor) == game_object.enemy or (t ~= nil and t.killer == actor:id())
  813. end
  814.  
  815. function actor_friend(actor, npc)
  816.     return npc:relation(actor) == game_object.friend
  817. end
  818.  
  819. function actor_neutral(actor, npc)
  820.     return npc:relation(actor) == game_object.neutral
  821. end
  822.  
  823. function is_factions_enemies(actor, npc, p)
  824.     if(p[1]~=nil) then
  825.         return game_relations.is_factions_enemies(character_community(actor), p[1])
  826.     else
  827.         return false
  828.     end
  829. end
  830.  
  831. function is_factions_neutrals(actor, npc, p)
  832.     return not(is_factions_enemies(actor, npc, p) or is_factions_friends(actor, npc, p))
  833. end
  834.  
  835. function is_factions_friends(actor, npc, p)
  836.     if(p[1]~=nil) then
  837.         return game_relations.is_factions_friends(character_community(actor), p[1])
  838.     else
  839.         return false
  840.     end
  841. end
  842.  
  843. function is_faction_enemy_to_actor(actor, npc, p)
  844.     if(p[1]~=nil) then
  845. --        return db.actor:community_goodwill(p[1])<-1000
  846.         return relation_registry.community_goodwill(p[1], db.actor:id())<=-1000
  847.     else
  848.         return false
  849.     end
  850. end
  851.  
  852. function is_faction_friend_to_actor(actor, npc, p)
  853.     if(p[1]~=nil) then
  854. --      return db.actor:community_goodwill(p[1])>1000
  855.         return relation_registry.community_goodwill(p[1], db.actor:id())>=1000
  856.     else
  857.         return false
  858.     end
  859. end
  860.  
  861. function is_faction_neutral_to_actor(actor, npc, p)
  862.     return not(is_faction_enemy_to_actor(actor, npc, p) or is_faction_friend_to_actor(actor, npc, p))
  863. end
  864.  
  865. function is_squad_friend_to_actor(actor, npc, p)
  866.     if(p[1]~=nil) then
  867. --     printf("squad check goodwill1 [%s]", p[1])
  868.         return game_relations.check_all_squad_members(p[1], "friend")
  869.     else
  870. --     printf("squad check goodwill5 [%s]", p[1])
  871.         return false
  872.     end
  873. end
  874.  
  875. function is_squad_enemy_to_actor(actor, npc, p)
  876.     if not p then
  877.         abort("Not enough arguments in 'is_squad_enemy_to_actor' funciton!")
  878.     end
  879.  
  880.     for k,v in pairs(p) do
  881. --      printf("squad check goodwill1 [%s]", v)
  882.         if game_relations.check_all_squad_members(v, "enemy") then
  883.             return true
  884.         end
  885.     end
  886.  
  887.     return false
  888. end
  889.  
  890. function is_squad_neutral_to_actor(actor, npc, p)
  891.     return not(is_squad_enemy_to_actor(actor, npc, p) or is_squad_friend_to_actor(actor, npc, p))
  892. end
  893.  
  894. -- òåêóùèé âðàã àêò¸ð?
  895. function fighting_actor(actor, npc)
  896.     local enemy_id = db.storage[npc:id()].enemy_id
  897.     local enemy = db.storage[enemy_id] and db.storage[enemy_id].object
  898.     return enemy and enemy:id() == actor:id()
  899. end
  900.  
  901.  
  902. function hit_by_actor(actor, npc)
  903.     local t = db.storage[npc:id()].hit
  904.     local hit_by_actor = (t ~= nil and t.who == actor:id())
  905.     printf("_bp: hit_by_actor: %s", if_then_else(hit_by_actor, "true", "false"))
  906.     return hit_by_actor
  907. end
  908.  
  909. function killed_by_actor(actor, npc)
  910.     local t = db.storage[npc:id()].death
  911.     local killed_by_actor = t ~= nil and t.killer == actor:id()
  912.     printf("_bp: killed_by_actor: %s", if_then_else(killed_by_actor, "true", "false"))
  913.     return killed_by_actor
  914. end
  915.  
  916. function actor_has_weapon (actor, npc)
  917.     local obj = actor:active_item ()
  918.     if obj == nil or isWeapon (obj) == false then return false end
  919.     return true
  920. end
  921.  
  922. function actor_active_detector(actor, npc, p)
  923.     local detector_section = p and p[1]
  924.     if detector_section == nil then abort("Wrong parameters in function 'actor_active_detector'") end
  925.     local actor_detector = db.actor:active_detector()
  926.     return (actor_detector ~= nil) and actor_detector:section() == detector_section
  927. end
  928.  
  929. function heavy_wounded(actor, npc)
  930.     return xr_wounded.is_heavy_wounded_by_id( npc:id() )
  931. end
  932.  
  933. --[[
  934. Ïðîâåðêà íà çàäàííûé ïåðèîä âðåìåíè
  935. Âðåìÿ çàäàåòñÿ â ìèíóòàõ
  936. Ïàðàìåòðû: (time_shift:period_min)
  937.                      time_shift - ïåðèîäè÷íîñòü ñðàáàòûâàíèÿ
  938.                      period - ïåðèîä ñðàáàòûâàíèÿ íà êîòîðîì ìû ïîëó÷àåì true
  939.  
  940. Ïðèìåðû:
  941. time_period(60:10) - âîçâðàùàåò true êàæäûé ÷àñ íà ïðîòÿæåíèè ïåðâûõ 10 ìèíóò
  942. --]]
  943. function time_period(actor, npc, p)
  944.     local tshift, period = p[1], p[2]
  945.     if tshift ~= nil and period ~= nil and db.actor ~= nil then
  946.         return tshift > period and level.get_time_minutes() % tshift <= period
  947.     end
  948.     return false
  949. end
  950.  
  951. function is_rain (actor, npc)
  952.     return db.actor ~= nil and level.rain_factor() > 0
  953. end
  954.  
  955. function is_heavy_rain (actor, npc)
  956.     return db.actor ~= nil and level.rain_factor() >= 0.5
  957. end
  958.  
  959. function is_day (actor, npc)
  960.     return db.actor ~= nil and level.get_time_hours() >= 6 and level.get_time_hours() < 21
  961. end
  962.  
  963. function is_dark_night (actor, npc)
  964.     return db.actor ~= nil and (level.get_time_hours() < 3 or level.get_time_hours() > 22)
  965. end
  966.  
  967. function is_jup_a12_mercs_time (actor, npc)
  968.     return db.actor ~= nil and (level.get_time_hours() >= 1 and level.get_time_hours() < 5)
  969. end
  970.  
  971. function zat_b7_is_night (actor, npc)
  972.     return db.actor ~= nil and (level.get_time_hours() >= 23 or level.get_time_hours() < 5)
  973. end
  974.  
  975. function zat_b7_is_late_attack_time (actor, npc)
  976.     return db.actor ~= nil and (level.get_time_hours() >= 23 or level.get_time_hours() < 9)
  977. end
  978.  
  979. function mob_has_enemy(actor, npc)
  980.     -- return false
  981.     if npc == nil then return false end
  982.     --if npc:get_enemy () then printf ("ENEMY PRESENT") else printf ("ENEMY NOT PRESENT") end
  983.     return npc:get_enemy() ~= nil
  984. end
  985.  
  986. function mob_was_hit(actor, npc)
  987.     local h = npc:get_monster_hit_info()
  988.     if h.who and h.time ~= 0 then
  989.         return true
  990.     end
  991.     return false
  992. end
  993.  
  994. function actor_on_level(actor, npc, p)
  995.     for k,v in pairs (p) do
  996.         --printf("level name: [%s], needed level name: [%s]", level.name(), v`)
  997.         if v == level.name() then
  998.             return true
  999.         end
  1000.     end
  1001.     return false
  1002. end
  1003.  
  1004. function treasure_exist(actor, npc, p)
  1005.     --printf("%s %s", actor:name(), npc:name())
  1006.     return true
  1007. end
  1008.  
  1009. --[[
  1010. --'-----------------------------------------------------------------------------------
  1011. --' Cover support
  1012. --'-----------------------------------------------------------------------------------
  1013. --' Åñëè âîçâðàùàåò true, òî ñîëäàòû çà êàâåðàìè íà÷èíàþò ñòðåëÿòü.
  1014. function cover_attack(actor, npc)
  1015.     --' Áåðåì ñêâàä îáúåêòà
  1016.     local squad = get_object_squad(npc)
  1017.  
  1018.     if squad == nil then
  1019.         return false
  1020.     end
  1021.  
  1022.     return squad:cover_attack()
  1023. end
  1024. ]]--
  1025.  
  1026. --'-----------------------------------------------------------------------------------
  1027. --' Squad support
  1028. --'-----------------------------------------------------------------------------------
  1029. function squad_in_zone(actor, npc, p)
  1030.     local story_id = p[1]
  1031.     local zone_name = p[2]
  1032.     if story_id == nil then
  1033.         abort("Insufficient params in squad_in_zone function. story_id[%s], zone_name[%s]", tostring(story_id), tostring(zone_name))
  1034.     end
  1035.     if zone_name == nil then
  1036.         zone_name = npc:name()
  1037.     end
  1038.  
  1039.     local sim_board = sim_board.get_sim_board()
  1040.  
  1041.     local squad = get_story_squad(story_id)
  1042.     if squad == nil then
  1043.         --abort("There is no squad with id[%s]", tostring(squad_id))
  1044.         return false
  1045.     end
  1046.  
  1047.     local zone = db.zone_by_name[zone_name]
  1048.     if zone == nil then
  1049.         --abort("There is no squad with id[%s]", tostring(zone_name))
  1050.         return false
  1051.     end
  1052.  
  1053.     for k in squad:squad_members() do
  1054.         local position = (db.storage[k.id] and db.storage[k.id].object and db.storage[k.id].object:position()) or k.object.position
  1055.         if zone:inside(position) then
  1056.             return true
  1057.         end
  1058.     end
  1059.     return false
  1060. end
  1061.  
  1062. function squad_has_enemy(actor, npc, p)
  1063.     local story_id = p[1]
  1064.  
  1065.     if story_id == nil then
  1066.         abort("Insufficient params in squad_has_enemy function. story_id [%s]", tostring(story_id))
  1067.     end
  1068.  
  1069.     local squad = get_story_squad(story_id)
  1070.     if squad == nil then
  1071.         --abort("There is no squad with id[%s]", tostring(story_id))
  1072.         return false
  1073.     end
  1074.  
  1075.     local al = alife()
  1076.     for k in squad:squad_members() do
  1077.         local npc_obj = level.object_by_id(k.object.id)
  1078.         if npc_obj == nil then
  1079.             return false
  1080.         end
  1081.         if npc_obj:best_enemy() ~= nil then
  1082.             return true
  1083.         end
  1084.     end
  1085.  
  1086.     return false
  1087. end
  1088.  
  1089. -- Functions for Yantar
  1090. function squad_in_zone_all(actor, npc, p)
  1091.     local story_id = p[1]
  1092.     local zone_name = p[2]
  1093.     if story_id == nil or zone_name == nil then
  1094.         abort("Insufficient params in squad_in_zone_all function. story_id[%s], zone_name[%s]", tostring(story_id), tostring(zone_name))
  1095.     end
  1096.     local squad = get_story_squad(story_id)
  1097.     if squad == nil then
  1098.         --abort("There is no squad with id[%s]", tostring(story_id))
  1099.         return false
  1100.     end
  1101.     local zone = db.zone_by_name[zone_name]
  1102.     if zone == nil then
  1103.         --abort("There is no squad with id[%s]", tostring(zone_name))
  1104.         return false
  1105.     end
  1106.     local al = alife()
  1107.     for k in squad:squad_members() do
  1108.         local position = (db.storage[k.id] and db.storage[k.id].object and db.storage[k.id].object:position()) or k.object.position
  1109.         if not zone:inside(position) then
  1110.             return false
  1111.         end
  1112.     end
  1113.     return true
  1114. end
  1115.  
  1116. function squads_in_zone_b41(actor, npc, p)
  1117.     local smart = sim_board.get_sim_board():get_smart_by_name("jup_b41")
  1118.     local zone = db.zone_by_name["jup_b41_sr_light"]
  1119.     local al = alife()
  1120.  
  1121.     if zone == nil then
  1122.         return false
  1123.     end
  1124.     if smart == nil then
  1125.         return false
  1126.     end
  1127.  
  1128.     for k,v in pairs(sim_board.get_sim_board().smarts[smart.id].squads) do
  1129.         if v ~= nil then
  1130.             for j in v:squad_members() do
  1131.                 if not zone:inside(j.object.position) then
  1132.                     return false
  1133.                 end
  1134.             end
  1135.         end
  1136.     end
  1137.  
  1138.     return true
  1139. end
  1140.  
  1141.  
  1142. --' Ïðîâåðêà â òàðãåò êîíäëèñòå çàäàíèÿ, ñîîòâåòñòâóåò ëè èìÿ ñêâàäà ïåðåäàííîìó
  1143. function target_squad_name(actor, obj, p)
  1144.     if p[1] == nil then
  1145.         abort("Wrong parameters")
  1146.     end
  1147.     if not(obj) then
  1148.         return false
  1149.     end
  1150.     --callstack()
  1151.     if IsStalker(obj) or IsMonster(obj) then
  1152.         if alife():object(obj.group_id) == nil then
  1153.             return false
  1154.         end
  1155.         if string.find( alife():object(obj.group_id):section_name(), p[1] ) ~= nil then
  1156.             return true
  1157.         end
  1158.         --return alife():object(obj.group_id):section_name() == p[1]
  1159.     end
  1160.     return obj:section_name() == p[1]
  1161. end
  1162.  
  1163. --' Ïðîâåðêà â òàðãåò êîíäëèñòå çàäàíèÿ, ñîîòâåòñòâóåò ëè èìÿ ñìàðòà ïåðåäàííîìó
  1164. function target_smart_name(actor, smart, p)
  1165.     if p[1] == nil then
  1166.         abort("Wrong parameters")
  1167.     end
  1168.     --callstack()
  1169.     return smart:name() == p[1]
  1170. end
  1171.  
  1172. --' Ïðîâåðÿåò æèâ ëè îòðÿä ñ óêàçàííûì ID
  1173. function squad_exist(actor, npc, p)
  1174.     local story_id = p[1]
  1175.     if story_id == nil then
  1176.         abort("Wrong parameter story_id[%s] in squad_exist function", tostring(story_id))
  1177.     end
  1178.     local squad = get_story_squad(story_id)
  1179.  
  1180. --  if squad == nil then
  1181. --      return false
  1182. --  end
  1183.     return squad ~= nil
  1184.     --  return squad.squad_power > 0
  1185. end
  1186.  
  1187. function is_squad_commander(actor, npc)
  1188.     if (type(npc.id) == "number") then
  1189.         npc_id = npc.id
  1190.     else
  1191.         npc_id = npc:id()
  1192.     end
  1193.     local squad = get_object_squad(npc)
  1194.     return squad and squad:commander_id() == npc_id or squad == nil
  1195. end
  1196.  
  1197. function squad_npc_count_ge(actor, npc, p)
  1198.     local story_id = p[1]
  1199.     if story_id == nil then
  1200.         abort("Wrong parameter squad_id[%s] in 'squad_npc_count_ge' function", tostring(squad_id))
  1201.     end
  1202.     local squad = get_story_squad(story_id)
  1203.  
  1204.     if squad then
  1205.         return squad:npc_count() > tonumber(p[2])
  1206.     else
  1207.         return false
  1208.     end
  1209. end
  1210.  
  1211. function surge_complete()
  1212.     return surge_manager.is_finished()
  1213. end
  1214.  
  1215. function surge_started()
  1216.     return surge_manager.is_started() or psi_storm_manager and psi_storm_manager.is_started() or fallout_manager and fallout_manager.is_started()
  1217. end
  1218.  
  1219. function surge_kill_all()
  1220.     return surge_manager.is_killing_all()
  1221. end
  1222.  
  1223. function signal_rocket_flying(actor, npc, p)
  1224.     if p==nil then
  1225.         abort("Signal rocket name is not set!")
  1226.     end
  1227.     if db.signal_light[p[1]] then
  1228.         return db.signal_light[p[1]]:is_flying()
  1229.     else
  1230.         abort("No such signal rocket: [%s] on level", tostring(p[1]))
  1231.     end
  1232.     return false
  1233. end
  1234.  
  1235. function quest_npc_enemy_actor(actor, npc, p)
  1236.     if p[1] == nil then
  1237.         abort("wrong story id")
  1238.     else
  1239.         local obj = get_story_object(p[1])
  1240.         if obj and IsStalker(obj) then
  1241.             if db.actor and obj:general_goodwill(db.actor)<=-1000 then
  1242.                 return true
  1243.             end
  1244.         end
  1245.     end
  1246.     return false
  1247. end
  1248.  
  1249. function animpoint_reached(actor, npc)
  1250.     local animpoint_storage = db.storage[npc:id()].animpoint
  1251.  
  1252.     if animpoint_storage == nil then
  1253.         return false
  1254.     end
  1255.  
  1256.     local animpoint_class = animpoint_storage.animpoint
  1257.  
  1258.     return animpoint_class:position_riched()
  1259. end
  1260.  
  1261. --[[
  1262. function npc_stay_offline(actor, npc, p)
  1263.     if p == nil then
  1264.         abort("Wrong parameter!!!")
  1265.     end
  1266.     if npc and db.actor then
  1267.         if is_smart_in_combat(actor, npc, p) then
  1268.             if npc.position:distance_to(db.actor:position())>=30 or game_relations.get_gulag_relation_actor(p[1], "enemy") then
  1269.                 return true
  1270.             end
  1271.         end
  1272.     end
  1273.     return false
  1274. end
  1275. ]]--
  1276.  
  1277. -- ïðîâåðêà òîãî ÷òî äèñòàíöèÿ äî îáüåêòà >= çàäàííîé
  1278. -- ïàðàìåòðû: [sid,dist]
  1279. function distance_to_obj_ge(actor, npc, p)
  1280.     local npc_id = get_story_object_id(p[1])
  1281.     local npc1 = npc_id and alife():object(npc_id)
  1282.     if npc1 then
  1283.         return db.actor:position():distance_to_sqr(npc1.position) >= p[2]*p[2]
  1284.     end
  1285.     return false
  1286. end
  1287.  
  1288. function distance_to_obj_le(actor, npc, p)
  1289.     local npc_id = get_story_object_id(p[1])
  1290.     local npc1 = npc_id and alife():object(npc_id)
  1291.     if npc1 then
  1292.         return db.actor:position():distance_to_sqr(npc1.position) < p[2]*p[2]
  1293.     end
  1294.     return false
  1295. end
  1296.  
  1297. function in_dest_smart_cover(actor, npc, p)
  1298.     return npc:in_smart_cover()
  1299. end
  1300.  
  1301. function active_item(actor, npc, p)
  1302.     if p and p[1] then
  1303.         for k,v  in pairs(p) do
  1304.             if actor:item_in_slot(3) ~= nil and actor:item_in_slot(3):section() == v then return true end
  1305.         end
  1306.     end
  1307.     return false
  1308. end
  1309.  
  1310. function actor_nomove_nowpn()
  1311.     if (not isWeapon(db.actor:active_item())) or db.actor:is_talking() then
  1312.         return true
  1313.     end
  1314.     return false
  1315. end
  1316.  
  1317. function jup_b16_is_zone_active(actor, npc)
  1318.     return has_alife_info(npc:name())
  1319. end
  1320.  
  1321. --Ôóíêöèÿ ïðîâåðêè ñîñòîÿíèÿ âèäèìîñòè êðîâîñîñà.
  1322. -- Âîçìîæíûé íàáîð ïàðàìåòðîâ --> story_id:visibility_state(ìîæíî âûçûâàòü îòêóäà óãîäíî) èëè visibility_state(åñëè âûçûâàåòñÿ èç êàñòîìäàòû êðîâîñîñà)
  1323. --  visibility_state -->
  1324. --                      0 - íåâèäèìûé
  1325. --                      1 - ïîëóâèäèìûé
  1326. --                      2 - ïîëíîñòüþ âèäèìûé
  1327.  
  1328. function check_bloodsucker_state(actor, npc, p)
  1329.     if (p and p[1]) == nil then abort("Wrong parameters in function 'check_bloodsucker_state'!!!") end
  1330.     local state = p[1]
  1331.     if p[2] ~= nil then
  1332.         state = p[2]
  1333.         npc = get_story_object(p[1])
  1334.     end
  1335.     if npc ~= nil then
  1336.         return npc:get_visibility_state () == tonumber(state)
  1337.     end
  1338.     return false
  1339. end
  1340.  
  1341. function dist_to_story_obj_ge(actor, npc, p)
  1342.     local story_id = p and p[1]
  1343.     local story_obj_id = get_story_object_id(story_id)
  1344.     if story_obj_id == nil then return true end
  1345.     local se_obj = alife():object(story_obj_id)
  1346.     return se_obj.position:distance_to(db.actor:position()) > p[2]
  1347. end
  1348.  
  1349. function actor_has_nimble_weapon(actor, npc)
  1350.     local need_item = {}
  1351.     need_item["wpn_groza_nimble"] = true
  1352.     need_item["wpn_desert_eagle_nimble"] = true
  1353.     need_item["wpn_fn2000_nimble"] = true
  1354.     need_item["wpn_g36_nimble"] = true
  1355.     need_item["wpn_protecta_nimble"] = true
  1356.     need_item["wpn_mp5_nimble"] = true
  1357.     need_item["wpn_sig220_nimble"] = true
  1358.     need_item["wpn_spas12_nimble"] = true
  1359.     need_item["wpn_usp_nimble"] = true
  1360.     need_item["wpn_vintorez_nimble"] = true
  1361.     need_item["wpn_svu_nimble"] = true
  1362.     need_item["wpn_svd_nimble"] = true
  1363.     for k,v in pairs(need_item) do
  1364.         if actor:object(k) ~= nil then
  1365.             return true
  1366.         end
  1367.     end
  1368.     return false
  1369. end
  1370.  
  1371. function actor_has_active_nimble_weapon(actor, npc)
  1372.     local need_item = {}
  1373.     need_item["wpn_groza_nimble"] = true
  1374.     need_item["wpn_desert_eagle_nimble"] = true
  1375.     need_item["wpn_fn2000_nimble"] = true
  1376.     need_item["wpn_g36_nimble"] = true
  1377.     need_item["wpn_protecta_nimble"] = true
  1378.     need_item["wpn_mp5_nimble"] = true
  1379.     need_item["wpn_sig220_nimble"] = true
  1380.     need_item["wpn_spas12_nimble"] = true
  1381.     need_item["wpn_usp_nimble"] = true
  1382.     need_item["wpn_vintorez_nimble"] = true
  1383.     need_item["wpn_svu_nimble"] = true
  1384.     need_item["wpn_svd_nimble"] = true
  1385.  
  1386.     if actor:item_in_slot(2) ~= nil and need_item[actor:item_in_slot(2):section()] == true then
  1387.         return true
  1388.     end
  1389.     if actor:item_in_slot(3) ~= nil and need_item[actor:item_in_slot(3):section()] == true then
  1390.         return true
  1391.     end
  1392.     return false
  1393. end
  1394.  
  1395. function jup_b202_inventory_box_empty(actor, npc)
  1396.     local inv_box = get_story_object("jup_b202_actor_treasure")
  1397.     return inv_box:is_inv_box_empty()
  1398. end
  1399. --[[
  1400. function jup_b46_actor_has_active_science_detector(actor, npc)
  1401.     if actor:item_in_slot(9) ~= nil and actor:item_in_slot(9):section() == "detector_scientific" then return true end
  1402.     return false
  1403. end
  1404. ]]--
  1405. function is_in_danger(actor, npc, p)
  1406.     if p and p[1] then
  1407.         npc = get_story_object(p[1])
  1408.     end
  1409.     --printf("npc: [%s] is in danger [%s]", tostring(npc:id()), tostring(db.storage[npc:id()].danger_flag))
  1410.     return db.storage[npc:id()].danger_flag
  1411. end
  1412.  
  1413. function object_exist(actor , npc , p)
  1414.     return get_story_object(p[1]) ~= nil
  1415. end
  1416.  
  1417. function squad_curr_action(actor, npc, p)
  1418.     local squad = get_object_squad(npc)
  1419.     return squad.current_action and squad.current_action.name == p[1]
  1420. end
  1421.  
  1422. function is_monster_snork(actor, npc)
  1423.     return npc:clsid() == clsid.snork_s
  1424. end
  1425.  
  1426. function is_monster_dog(actor, npc)
  1427.     return npc:clsid() == clsid.dog_s
  1428. end
  1429.  
  1430. function is_monster_psy_dog(actor, npc)
  1431.     return npc:clsid() == clsid.psy_dog_s
  1432. end
  1433.  
  1434. function is_monster_polter(actor, npc)
  1435.     return npc:clsid() == clsid.poltergeist_s
  1436. end
  1437.  
  1438. function is_monster_tushkano(actor, npc)
  1439.     return npc:clsid() == clsid.tushkano_s
  1440. end
  1441.  
  1442. function is_monster_burer(actor, npc)
  1443.     return npc:clsid() == clsid.burer_s
  1444. end
  1445.  
  1446. function is_monster_controller(actor, npc)
  1447.     return npc:clsid() == clsid.controller_s
  1448. end
  1449.  
  1450. function is_monster_flesh(actor, npc)
  1451.     return npc:clsid() == clsid.flesh_s
  1452. end
  1453.  
  1454. function is_monster_boar(actor, npc)
  1455.     return npc:clsid() == clsid.boar_s
  1456. end
  1457.  
  1458.  
  1459. function dead_body_searching(actor, npc)
  1460.     return actor_menu.dead_body_searching
  1461. end
  1462.  
  1463. function jup_b47_npc_online(actor, npc, p)
  1464. --  printf("function jup_b47_npc_online: story_obj[%s]", tostring(p[1]))
  1465.     local story_obj = get_story_object(p[1])
  1466.     if story_obj == nil then
  1467.         return false
  1468.     end
  1469.     local obj = alife():object(story_obj:id())
  1470.     return obj ~= nil
  1471. end
  1472.  
  1473. function anomaly_has_artefact(actor, npc, p)
  1474.     local az_name = p and p[1]
  1475.     local af_name = p and p[2]
  1476.  
  1477.     local anomal_zone = db.anomaly_by_name[az_name]
  1478.     if anomal_zone == nil then
  1479.         return false
  1480.     end
  1481.  
  1482.     if anomal_zone.spawned_count < 1 then
  1483.         return false
  1484.     end
  1485.  
  1486.     if af_name == nil then
  1487.         local af_table = {}
  1488.         for k,v in pairs(anomal_zone.artefact_ways_by_id) do
  1489.             if alife():object(tonumber(k)) then
  1490.                 table.insert(af_table, alife():object(tonumber(k)):section_name())
  1491.             end
  1492.         end
  1493.         return true, af_table
  1494.     end
  1495.  
  1496.     for k,v in pairs(anomal_zone.artefact_ways_by_id) do
  1497.         if alife():object(tonumber(k)) and af_name == alife():object(tonumber(k)):section_name() then
  1498.             return true
  1499.         end
  1500.     end
  1501.  
  1502.     return false
  1503. end
  1504.  
  1505. function zat_b29_anomaly_has_af(actor, npc, p)
  1506.     local az_name = p and p[1]
  1507.     local af_name
  1508.  
  1509.     local anomal_zone = db.anomaly_by_name[az_name]
  1510.     if anomal_zone == nil then
  1511.         return false
  1512.     end
  1513.  
  1514.     if anomal_zone.spawned_count < 1 then
  1515.         return false
  1516.     end
  1517.  
  1518.     for i = 16, 23 do
  1519.         if has_alife_info(dialogs_zaton.zat_b29_infop_bring_table[i]) then
  1520.             af_name = dialogs_zaton.zat_b29_af_table[i]
  1521.             break
  1522.         end
  1523.     end
  1524.  
  1525.     for k,v in pairs(anomal_zone.artefact_ways_by_id) do
  1526.         if alife():object(tonumber(k)) and af_name == alife():object(tonumber(k)):section_name() then
  1527.             db.actor:give_info_portion(az_name)
  1528.             return true
  1529.         end
  1530.     end
  1531.  
  1532.     return false
  1533. end
  1534.  
  1535. function jup_b221_who_will_start(actor, npc, p) -- äîñòóïíûå ïàðàìåòðû: ability - ïðîâåðèòü åñòü ëè äîñòóïíûå òåìû, choose - âûáðàòü ãðóïèðîâêó êîòîðàÿ íà÷íåò ïåðåïàëêó
  1536.     local reachable_theme = {}
  1537.     local faction_table = {}
  1538.     local info_table = {
  1539. ---------duty
  1540.         [1] = "jup_b25_freedom_flint_gone",
  1541.         [2] = "jup_b25_flint_blame_done_to_duty",
  1542.         [3] = "jup_b4_monolith_squad_in_duty",
  1543.         [4] = "jup_a6_duty_leader_bunker_guards_work",
  1544.         [5] = "jup_a6_duty_leader_employ_work",
  1545.         [6] = "jup_b207_duty_wins",
  1546. ---------freedom
  1547.         [7] = "jup_b207_freedom_know_about_depot",
  1548.         [8] = "jup_b46_duty_founder_pda_to_freedom",
  1549.         [9] = "jup_b4_monolith_squad_in_freedom",
  1550.         [10] = "jup_a6_freedom_leader_bunker_guards_work",
  1551.         [11] = "jup_a6_freedom_leader_employ_work",
  1552.         [12] = "jup_b207_freedom_wins"
  1553.     }
  1554. --Ñîñòàâëÿåì òàáëèöó äîñòûïíûõ òåì(òëüêî íîìåðà òåì).
  1555.     for k,v in pairs(info_table) do
  1556.         if k <= 6 then
  1557.             faction_table[1] = "duty"
  1558.             faction_table[2] = "0"
  1559.         else
  1560.             faction_table[1] = "freedom"
  1561.             faction_table[2] = "6"
  1562.         end
  1563.         if (has_alife_info(v)) and (not has_alife_info("jup_b221_" .. faction_table[1] .. "_main_" .. tostring(k - tonumber(faction_table[2])) .. "_played")) then
  1564.             table.insert(reachable_theme,k)
  1565.             printf("jup_b221_who_will_start: table reachable_theme ------------------------------> [%s]", tostring(k))
  1566.         end
  1567.     end
  1568.     if (p and p[1]) == nil then
  1569.         abort("No such parameters in function 'jup_b221_who_will_start'")
  1570.     end
  1571.     if tostring(p[1]) == "ability" then
  1572.         return #reachable_theme ~= 0 -- åñëè òàáëèöà ïóñòà çíà÷èò íåò äîñòóïíûõ òåì è íåíàäî èãðàòü ñöåíó
  1573.     elseif  tostring(p[1]) == "choose" then
  1574. ---------Âûáåðåì ðàíäîìàì åëåìåíò ñîñòàâëåíîé òàáëèöû è ïðîâåðèì ê êàêîé ãðóïåðîâêè îí ïðåíàäëåæèò :)
  1575.         return reachable_theme[math.random(1, #reachable_theme)] <= 6 -- åñëè ìåíüøå 6-òè çíà÷èò ÄÎËà åñëè áîëüøå 6-òè çíà÷èò ÑÂÎÁÎÄÀ
  1576.     else
  1577.         abort("Wrong parameters in function 'jup_b221_who_will_start'")
  1578.     end
  1579. end
  1580.  
  1581. function pas_b400_actor_far_forward(actor, npc)
  1582.     local fwd_obj = get_story_object("pas_b400_fwd")
  1583.  
  1584.     if fwd_obj then
  1585.         if distance_between(fwd_obj, db.actor) > distance_between(fwd_obj, npc) then
  1586.             return false
  1587.         end
  1588.     else
  1589.         return false
  1590.     end
  1591.  
  1592.     local distance = 70 * 70
  1593.     local self_dist = npc:position():distance_to_sqr(actor:position())
  1594.     if self_dist < distance then
  1595.         return false
  1596.     end
  1597.  
  1598.     local squad = alife():object(alife():object(npc:id()).group_id)
  1599.  
  1600.     for k in squad:squad_members() do
  1601.         local other_dist = k.object.position:distance_to_sqr(actor:position())
  1602.         if other_dist < distance then
  1603.             return false
  1604.         end
  1605.     end
  1606.  
  1607.     --printf("npc: [%s], actor is far forward - self_dist [%s] distance [%s]", tostring(npc:name()), self_dist, distance)
  1608.  
  1609.     return true
  1610. end
  1611.  
  1612. function pas_b400_actor_far_backward(actor, npc)
  1613.     local bwd_obj = get_story_object("pas_b400_bwd")
  1614.  
  1615.     if bwd_obj then
  1616.         if distance_between(bwd_obj, db.actor) > distance_between(bwd_obj, npc) then
  1617.             return false
  1618.         end
  1619.     else
  1620.         return false
  1621.     end
  1622.  
  1623.     local distance = 70 * 70
  1624.     local self_dist = npc:position():distance_to_sqr(actor:position())
  1625.     if self_dist < distance then
  1626.         return false
  1627.     end
  1628.  
  1629.     local squad = alife():object(alife():object(npc:id()).group_id)
  1630.  
  1631.     for k in squad:squad_members() do
  1632.         local other_dist = k.object.position:distance_to_sqr(actor:position())
  1633.         if other_dist < distance then
  1634.             return false
  1635.         end
  1636.     end
  1637.  
  1638.     --printf("npc: [%s], actor is far backward - self_dist [%s] distance [%s]", tostring(npc:name()), self_dist, distance)
  1639.  
  1640.     return true
  1641. end
  1642.  
  1643. function pri_a28_actor_is_far(actor, npc)
  1644.     local distance = 150 * 150
  1645.     local squad = get_story_squad("pri_a16_military_squad")
  1646.  
  1647.     for k in squad:squad_members() do
  1648.         local npc_dist = k.object.position:distance_to_sqr(actor:position())
  1649.         if npc_dist < distance then
  1650.             return false
  1651.         end
  1652.     end
  1653.  
  1654.     return true
  1655. end
  1656.  
  1657. function check_enemy_smart(actor , npc , p)
  1658.     local enemy_id = db.storage[npc:id()].enemy_id
  1659.     local enemy = db.storage[enemy_id] and db.storage[enemy_id].object
  1660.     if enemy == nil or enemy_id == alife():actor().id then
  1661.         return false
  1662.     end
  1663.     local enemy_smart = xr_gulag.get_npc_smart(enemy)
  1664.  
  1665.     if (enemy_smart ~= nil) and (enemy_smart:name() == p[1]) then
  1666.         return true
  1667.     end
  1668.     return false
  1669. end
  1670.  
  1671. function zat_b103_actor_has_needed_food(actor, npc, p)
  1672.     return (dialogs_zaton.zat_b103_actor_has_needed_food(actor, npc)) or (has_alife_info("zat_b103_merc_task_done"))
  1673. end
  1674.  
  1675. function zat_b29_rivals_dialog_precond(actor, npc)
  1676.     local squads_table = {
  1677.                         "zat_b29_stalker_rival_default_1_squad",
  1678.                         "zat_b29_stalker_rival_default_2_squad",
  1679.                         "zat_b29_stalker_rival_1_squad",
  1680.                         "zat_b29_stalker_rival_2_squad"
  1681.                         }
  1682.  
  1683.     local zones_table = {
  1684.                         "zat_b29_sr_1",
  1685.                         "zat_b29_sr_2",
  1686.                         "zat_b29_sr_3",
  1687.                         "zat_b29_sr_4",
  1688.                         "zat_b29_sr_5",
  1689.                         }
  1690.  
  1691.     local f_squad = false
  1692.  
  1693.     for k,v in pairs(squads_table) do
  1694.         if alife():object(alife():object(npc:id()).group_id):section_name() == v then
  1695.             f_squad = true
  1696.             break
  1697.         end
  1698.     end
  1699.  
  1700.     if not f_squad then
  1701.         return false
  1702.     end
  1703.  
  1704.     for k,v in pairs(zones_table) do
  1705.         if utils.npc_in_zone(npc, db.zone_by_name[v]) then
  1706.             return true
  1707.         end
  1708.     end
  1709.  
  1710.     return false
  1711. end
  1712.  
  1713. function polter_ignore_actor(actor, npc)
  1714.     return npc:poltergeist_get_actor_ignore()
  1715. end
  1716.  
  1717. function burer_gravi_attack(actor, npc)
  1718.     return npc:burer_get_force_gravi_attack()
  1719. end
  1720.  
  1721. function burer_anti_aim(actor, npc)
  1722.     return npc:burer_get_force_anti_aim()
  1723. end
  1724.  
  1725. function jup_b202_actor_treasure_not_in_steal(actor, npc)
  1726.     local before = ((not has_alife_info("jup_b52_actor_items_can_be_stolen")) and (not has_alife_info("jup_b202_actor_items_returned")))
  1727.     local after  = (has_alife_info("jup_b52_actor_items_can_be_stolen") and has_alife_info("jup_b202_actor_items_returned"))
  1728.     return (before or after)
  1729. end
  1730.  
  1731. function jup_b25_senya_spawn_condition(actor, npc)
  1732.     return (has_alife_info("jup_b16_oasis_found") or has_alife_info("zat_b57_bloodsucker_lair_clear") or has_alife_info("jup_b6_complete_end") or has_alife_info("zat_b215_gave_maps")) and has_alife_info("zat_b106_search_soroka")
  1733. end
  1734.  
  1735. function jup_b25_flint_gone_condition(actor, npc)
  1736.     return has_alife_info("jup_b25_flint_blame_done_to_duty") or has_alife_info("jup_b25_flint_blame_done_to_freedom") or has_alife_info("zat_b106_found_soroka_done")
  1737. end
  1738.  
  1739. -------------------------------------------------------------------------------------------------------------------------------------------
  1740. --  STALKER TRADE FUNCTIONS
  1741. -------------------------------------------------------------------------------------------------------------------------------------------
  1742. function has_tradable_stuff(actor, npc)
  1743.  
  1744.  
  1745. end
  1746.  
  1747.  
  1748. -------------------------------------------------------------------------------------------------------------------------------------------
  1749. --  end of STALKER TRADE FUNCTIONS
  1750. -------------------------------------------------------------------------------------------------------------------------------------------
  1751.  
  1752.  
  1753. pioneer_functor = xr_statistic.pioneer_functor
  1754.  
  1755. mutant_hunter_functor = xr_statistic.mutant_hunter_functor
  1756.  
  1757. detective_functor = xr_statistic.detective_functor
  1758.  
  1759. one_of_the_lads_functor = xr_statistic.one_of_the_lads_functor
  1760.  
  1761. kingpin_functor = xr_statistic.kingpin_functor
  1762.  
  1763. herald_of_justice_functor = xr_statistic.herald_of_justice_functor
  1764.  
  1765. seeker_functor = xr_statistic.seeker_functor
  1766.  
  1767. battle_systems_master_functor = xr_statistic.battle_systems_master_functor
  1768.  
  1769. high_tech_master_functor = xr_statistic.high_tech_master_functor
  1770.  
  1771. skilled_stalker_functor = xr_statistic.skilled_stalker_functor
  1772.  
  1773. leader_functor = xr_statistic.leader_functor
  1774.  
  1775. diplomat_functor = xr_statistic.diplomat_functor
  1776.  
  1777. research_man_functor = xr_statistic.research_man_functor
  1778.  
  1779. friend_of_duty_functor = xr_statistic.friend_of_duty_functor
  1780.  
  1781. friend_of_freedom_functor = xr_statistic.friend_of_freedom_functor
  1782.  
  1783. balance_advocate_functor = xr_statistic.balance_advocate_functor
  1784.  
  1785. wealthy_functor = xr_statistic.wealthy_functor
  1786.  
  1787. keeper_of_secrets_functor = xr_statistic.keeper_of_secrets_functor
  1788.  
  1789. marked_by_zone_functor = xr_statistic.marked_by_zone_functor
  1790.  
  1791. information_dealer_functor = xr_statistic.information_dealer_functor
  1792.  
  1793. friend_of_stalkers_functor = xr_statistic.friend_of_stalkers_functor
  1794.  
  1795.  
  1796. --------------------------------------------------------------------------------
  1797. function check_deimos_phase(actor, npc, p)
  1798.     if(p[1] and p[2]) then
  1799.         local obj = db.storage[npc:id()]
  1800.         local delta = sr_deimos.check_intensity_delta(obj)
  1801.                 if(p[2]=="increasing" and delta) then
  1802.                         return false
  1803.                 elseif(p[2]=="decreasing" and not(delta)) then
  1804.                         return false
  1805.                 end
  1806.         if(p[1]=="disable_bound") then
  1807.             if(p[2]=="increasing") then
  1808.                                 if not(sr_deimos.check_disable_bound(obj)) then
  1809.                     return true
  1810.                 end
  1811.             elseif(p[2]=="decreasing") then
  1812.                                 return sr_deimos.check_disable_bound(obj)
  1813.             end
  1814.         elseif(p[1]=="lower_bound") then
  1815.             if(p[2]=="increasing") then
  1816.                                 if not(sr_deimos.check_lower_bound(obj)) then
  1817.                     return true
  1818.                 end
  1819.             elseif(p[2]=="decreasing") then
  1820.                                 return sr_deimos.check_lower_bound(obj)
  1821.             end
  1822.         elseif(p[1]=="upper_bound") then
  1823.             if(p[2]=="increasing") then
  1824.                                 if not(sr_deimos.check_upper_bound(obj)) then
  1825.                     return true
  1826.                 end
  1827.             elseif(p[2]=="decreasing") then
  1828.                                 return sr_deimos.check_upper_bound(obj)
  1829.             end
  1830.         end
  1831.     end
  1832. end
  1833.  
  1834. --------------------------------------------------------------------------------
  1835.  
  1836. function actor_in_surge_cover(actor, npc, p)
  1837.     return surge_manager.actor_in_cover()
  1838. end
  1839.  
  1840. function is_door_blocked_by_npc(actor, obj)
  1841.     return obj:is_door_blocked_by_npc()
  1842. end
  1843.  
  1844. function has_active_tutorial()
  1845.     return game.has_active_tutorial()
  1846. end
  1847.  
  1848. function upgrade_hint_kardan(actor, npc, p)
  1849.     local hint_table = {}
  1850.     local can_upgrade = 0
  1851.     local tools = (p and tonumber(p[1])) or 0
  1852.  
  1853.     if not has_alife_info("zat_b3_all_instruments_brought") then
  1854.         if not has_alife_info("zat_b3_tech_instrument_1_brought") and (tools == 0 or tools == 1) then
  1855.             table.insert(hint_table, "st_upgr_toolkit_1")
  1856.         elseif tools == 1 then
  1857.             can_upgrade = can_upgrade + 1
  1858.         end
  1859.         if not has_alife_info("zat_b3_tech_instrument_2_brought") and (tools == 0 or tools == 2) then
  1860.             table.insert(hint_table, "st_upgr_toolkit_2")
  1861.         elseif tools == 2 then
  1862.             can_upgrade = can_upgrade + 1
  1863.         end
  1864.         if not has_alife_info("zat_b3_tech_instrument_3_brought") and (tools == 0 or tools == 3) then
  1865.             table.insert(hint_table, "st_upgr_toolkit_3")
  1866.         elseif tools == 3 then
  1867.             can_upgrade = can_upgrade + 1
  1868.         end
  1869.     else
  1870.         can_upgrade = can_upgrade + 1
  1871.     end
  1872.  
  1873.     if not has_alife_info("zat_b3_tech_see_produce_62") then
  1874.         if (tools == 1) and not has_alife_info("zat_b3_tech_have_one_dose") then
  1875.             table.insert(hint_table, "st_upgr_vodka")
  1876.         elseif (tools ~= 1) and (not has_alife_info("zat_b3_tech_have_couple_dose")) then
  1877.             table.insert(hint_table, "st_upgr_vodka")
  1878.         else
  1879.             can_upgrade = can_upgrade + 1
  1880.         end
  1881.     else
  1882.         can_upgrade = can_upgrade + 1
  1883.     end
  1884.  
  1885.     inventory_upgrades.cur_hint = hint_table
  1886.  
  1887.     return can_upgrade >= 2
  1888. end
  1889.  
  1890. -- AtmosFear Fallout
  1891. function fallout_complete()
  1892.     return fallout_manager.is_finished()
  1893. end
  1894.  
  1895. -- AtmosFear Psi Storm
  1896. function psi_storm_complete()
  1897.     return psi_storm_manager.is_finished()
  1898. end
  1899.  
  1900. function npc_surrendered(actor,npc,p)
  1901.     local st = db.storage[npc:id()]
  1902.     local po = st and st.victim_surrender and level.object_by_id(st.victim_surrender)
  1903.     --alun_utils.printf("surrendered = %s",po and po:id() == db.actor:id())
  1904.     return po and po:id() == db.actor:id()
  1905. end
  1906.  
  1907. function actor_class(actor,npc,p)
  1908.     return p and p[1] and axr_misery and axr_misery.ActorClass == p[1]
  1909. end
  1910.  
  1911. function black_road_enabled(actor,npc,p)
  1912.     return axr_misery and axr_misery.MiseryBlackRoad
  1913. end
  1914.  
  1915. function squad_behavior(actor,npc,p)
  1916.     local se_npc = type(npc.id) == "function" and alife():object(npc:id()) or npc
  1917.     local squad = se_npc and se_npc.parent_id ~= 65535 and alife():object(se_npc.parent_id)
  1918.     return p and p[1] and squad and squad.player_id == p[1]
  1919. end
  1920.  
  1921. function anim_state(actor,npc,p)
  1922.     return p and p[1] and state_mgr.get_state(npc) == p[1]
  1923. end
  1924.  
  1925. function smart_empty(actor,npc,p)
  1926.     local board = sim_board.get_sim_board()
  1927.     local smart = p[1] and board.smarts_by_names[p[1]]
  1928.     if not (smart) then
  1929.         return
  1930.     end
  1931.     local smart_id = smart.id
  1932.     local sim = alife()
  1933.     for k,v in pairs(board.smarts[smart_id].squads) do
  1934.         if (v.id and sim:object(v.id)) then
  1935.             return false
  1936.         end
  1937.     end
  1938.     return true
  1939. end
  1940.  
  1941. function job_on_point(actor,npc,p)
  1942.     -- p[1] = smart_name p[2] = logic p[3] = index p[4] = less_than_equal_to Distance p[5] = return true if object is dead or doesn't exist
  1943.     local board = sim_board.get_sim_board()
  1944.     local smart = p[1] and board and board.smarts_by_names[p[1]]
  1945.     local obj = smart and smart.npc_by_job_section["logic@"..p[2]]
  1946.     obj = obj and level.object_by_id(obj)
  1947.     if (not obj or not obj:alive()) then
  1948.         return p[5] ~= nil
  1949.     end
  1950.  
  1951.     local st = db.storage[obj:id()]
  1952.     local index = st.active_scheme and st.active_scheme == "beh" and alun_utils.load_var(obj,"path_index",nil) or obj:get_current_point_index()
  1953.  
  1954.     if (p[4] and index == tonumber(p[3])) then
  1955.         if (st.active_scheme and st.active_scheme == "beh") then
  1956.             if (axr_beh.am_i_reached(obj)) then
  1957.                 return true
  1958.             end
  1959.             return false
  1960.         end
  1961.  
  1962.         local path = obj:patrol()
  1963.         local pos = path and patrol(path):point(tonumber(p[3]))
  1964.         local dist = pos and obj:position():distance_to_sqr(pos)
  1965.         return dist <= tonumber(p[4])
  1966.     end
  1967.  
  1968.     return index == tonumber(p[3])
  1969. end
  1970.  
  1971. function beh_reached(actor,npc,p)
  1972.     return p[1] and axr_beh.am_i_reached(npc,tonumber(p[1])) or axr_beh.am_i_reached(npc)
  1973. end
  1974.  
  1975. function obj_on_job(actor,npc,p)
  1976.     local board = sim_board.get_sim_board()
  1977.     local smart = p[1] and board and board.smarts_by_names[p[1]]
  1978.     local obj = smart and smart.npc_by_job_section["logic@"..p[2]]
  1979.     obj = obj and level.object_by_id(obj)
  1980.     return obj and obj:alive()
  1981. end
  1982.  
  1983. function see_obj_on_job(actor,npc,p)
  1984.     local board = sim_board.get_sim_board()
  1985.     local smart = p[1] and board and board.smarts_by_names[p[1]]
  1986.     local obj = smart and smart.npc_by_job_section["logic@"..p[2]]
  1987.     obj = obj and level.object_by_id(obj)
  1988.     return obj and obj:alive() and npc:memory_time(obj) < 5000
  1989. end
  1990.  
  1991. function obj_on_job_danger(actor,npc,p)
  1992.     local board = sim_board.get_sim_board()
  1993.     local smart = p[1] and board and board.smarts_by_names[p[1]]
  1994.     local obj = smart and smart.npc_by_job_section["logic@"..p[2]]
  1995.     obj = obj and level.object_by_id(obj)
  1996.     return obj and db.storage[obj:id()].danger_flag
  1997. end
  1998.  
  1999. function obj_on_job_hit_by(actor,npc,p)
  2000.     local board = sim_board.get_sim_board()
  2001.     local smart = p[1] and board and board.smarts_by_names[p[1]]
  2002.     local obj = smart and smart.npc_by_job_section["logic@"..p[2]]
  2003.     obj = obj and level.object_by_id(obj)
  2004.     if (not obj and not obj:alive()) then
  2005.         return false
  2006.     end
  2007.  
  2008.     local id = db.storage[obj:id()].hitted_by
  2009.     return id and id == npc:id()
  2010. end
  2011.  
  2012.  
  2013. function job_active_section(actor,npc,p)
  2014.     local board = sim_board.get_sim_board()
  2015.     local smart = p[1] and board and board.smarts_by_names[p[1]]
  2016.     local obj = smart and smart.npc_by_job_section["logic@"..p[2]]
  2017.     obj = obj and level.object_by_id(obj)
  2018.     local st = obj and db.storage[obj:id()]
  2019.     return st and st.active_section == p[3]
  2020. end
  2021.  
  2022. function weather_veryfoggy(actor,npc,p)
  2023.     return string.find(level.get_weather(),"veryfoggy")
  2024. end
  2025.  
  2026. function npc_squad_has_enemy(actor,npc,p)
  2027.     local squad = get_object_squad(npc)
  2028.     if not (squad) then
  2029.         return
  2030.     end
  2031.  
  2032.     local o
  2033.     for k in squad:squad_members() do
  2034.         o = level.object_by_id(k.object.id)
  2035.         if (o and o:best_enemy()) then
  2036.             return true
  2037.         end
  2038.     end
  2039. end
  2040.  
  2041. function hit_by_enemy_on_smart(actor,npc,p)
  2042.     local id = db.storage[npc:id()].hitted_by
  2043.     local who = id and level.object_by_id(id)
  2044.     if (not who or not who:alive()) then
  2045.         return
  2046.     end
  2047.  
  2048.     local smart = xr_gulag.get_npc_smart(who)
  2049.     return p and p[1] and smart and smart:name() == p[1]
  2050. end
  2051.  
  2052. function squad_hit_by_smart(actor,npc,p)
  2053.     local squad = get_object_squad(npc)
  2054.     if not (squad) then
  2055.         return
  2056.     end
  2057.  
  2058.     local who,smart
  2059.     for k in squad:squad_members() do
  2060.         who = db.storage[k.object.id].hitted_by and level.object_by_id(db.storage[k.object.id].hitted_by)
  2061.         smart = who and xr_gulag.get_npc_smart(who)
  2062.         if (smart and smart:name() == p[1]) then
  2063.             return true
  2064.         end
  2065.     end
  2066.     return false
  2067. end
  2068.  
  2069. function actor_look_away(actor,npc)
  2070.     if (not db.actor:see(npc) or (alun_utils.angle_diff(db.actor:direction(), db.actor:position():sub(npc:position()))<90 and npc:position():distance_to(db.actor:position()) > 2.5) or npc:position():distance_to(db.actor:position())>100) then
  2071.         return true
  2072.     end
  2073.     return false
  2074. end
  2075.  
  2076. function between_time(actor,npc,p)
  2077.     return in_time_interval(tonumber(p[1]),tonumber(p[2]))
  2078. end
  2079.  
  2080. function is_squad_monster(actor,squad,p)
  2081.     return sim_squad_scripted.is_squad_monster[squad.player_id] == true
  2082. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement