datsexyanon

Untitled

Apr 24th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.09 KB | None | 0 0
  1. ---------------- Схема поведения НПС при выбросе для OGSM 2.x -----------------
  2.  
  3. ------------------------- Copyright 2007-2008 DEXXX ---------------------------
  4.  
  5. restrictor_list = {}
  6.  
  7. local npc_psy = {}
  8. local npc_run = {}
  9. local npc_sit = {}
  10. local npc_go = {}
  11.  
  12.  
  13. -- We check whether NPC is in specific rectangle zone (are set for special places,
  14. -- such as bar, where NPCs should not react to blowout at all)
  15. function npc_in_zone(obj,lev,pos_psy_x,pos_psy_y,size_psy_x,size_psy_y,z1,z2)
  16. local level_name = level.name()
  17. if level_name ~= lev then
  18.     return false
  19. end
  20. local pos = obj:position()
  21. local x1 = pos_psy_x
  22. local x2 = pos_psy_y
  23. local y1 = size_psy_x
  24. local y2 = size_psy_y
  25. if (pos.x >= x1 and pos.x <= x2) and (pos.z >= y1 and pos.z <= y2) and (pos.y >= z1) and (pos.y <= z2) then
  26.     return true
  27. end
  28. return false
  29. end
  30.  
  31. -- We get the nearest to NPC hide
  32. function get_nearest_hide(npc)
  33. local hideout_list = {}
  34. for k,v in pairs(restrictor_list) do
  35.     local community, radius = get_community_hide(v)
  36.     local obj = level.object_by_id(v.id)
  37.     if obj and string.find(community, npc:character_community()) then
  38.         local npc_pos = npc:position()
  39.         local hide_pos = obj:position()
  40.         local distance = npc_pos:distance_to(hide_pos)
  41.         local hide = {obj = obj, rad = radius, dist = distance}
  42.         table.insert(hideout_list, hide)
  43.     end
  44. end
  45. table.sort(hideout_list, function(a,b) return a.dist < b.dist end)
  46. local nearest_hide = hideout_list[1]
  47. return nearest_hide
  48. end
  49.  
  50.  
  51. -- We get the hideout data (communities, radius)
  52. function get_community_hide(obj)
  53. if not obj then return "none" end
  54. local packet = net_packet()
  55. obj:STATE_Write(packet)
  56. local game_vertex_id = packet:r_u16()
  57. local cse_alife_object__unk1_f32 = packet:r_float()
  58. local cse_alife_object__unk2_u32 = packet:r_s32()
  59. local level_vertex_id = packet:r_s32()
  60. local object_flags = packet:r_s32()
  61. local custom_data = packet:r_stringZ()
  62. local cd = parse_custom_data(custom_data)
  63. if not cd.parameters then return "none" end
  64. if not cd.parameters.community then return "none" end
  65. if not cd.parameters.radius then return "none" end
  66. return cd.parameters.community, cd.parameters.radius
  67. end
  68.  
  69. function is_in_specific_zone(npc)
  70.     if npc_in_zone(npc,"l01_escape",-256,-246,-137,-132,-25,-20) or     -- Бункер Сидора
  71.        npc_in_zone(npc,"l03_agroprom",-198.31,-195.66,85.4,96.54,2,5.3) or  -- Вагон дезертира
  72.        npc_in_zone(npc,"l04_darkvalley",30,50,-60,-25,-4,0) or          -- Тюрьма в Темной долине
  73.        npc_in_zone(npc,"l05_bar",123,140,18,30,-6,0) or                 -- Бар
  74.        npc_in_zone(npc,"l05_bar",118,121,34,41,-4,1) or                 -- Охранник Бара
  75.        npc_in_zone(npc,"l05_bar",149,158,67,74,0,4) or              -- Приемная Арни
  76.        npc_in_zone(npc,"l05_bar",136,168,73,134,-22,-10) or         -- Арена
  77.        npc_in_zone(npc,"l05_bar",208,234,120,139,-6,2) or               -- База Долга
  78.        npc_in_zone(npc,"l06_rostok",-90,-87,125,151,0,6) or             -- Блокпост наемников
  79.        npc_in_zone(npc,"l07_military",-27,-16,-33,-14,-9,0) or          -- База Свободы
  80.        npc_in_zone(npc,"l08_yantar",23,40,-282,-269,-16,0) or           -- Бункер ученых
  81.        npc_in_zone(npc,"l08_yantar",-265,-22,-218,-6,-20,-11) or            -- Кишка
  82.        npc_in_zone(npc,"l11_pripyat",-16,-2,188,204,-5,0) then          -- Подвал ДК
  83.         return true
  84.     end
  85.     return false
  86. end
  87.  
  88. function is_in_hide(npc)
  89.     if npc_in_zone(npc,"l01_escape",-211,-198,-132,-125,-23,-20) or     -- Подвал 1 в лагере новичков
  90.        npc_in_zone(npc,"l01_escape",-216,-209,-133,-120,-24,-20) or     -- Подвал 2 в лагере новичков
  91.        npc_in_zone(npc,"l02_garbage",-112,-57,-6,25,-9,90) or       -- Ангар на Свалке
  92.        npc_in_zone(npc,"l05_bar",206,213,50,68,0,4) or          -- Магазин Петренко
  93.        npc_in_zone(npc,"l06_rostok",-285,-235,78,112,-7,0) or       -- Тоннель Фримена
  94.        npc_in_zone(npc,"l10_radar",639,664,167,189,-45,-37) or      -- Секретная база Монолита
  95.        npc_in_zone(npc,"l10_radar",86.73,153,-27,-21.70,-10,-4.6) or    -- Вход в бункер
  96.        npc_in_zone(npc,"l11_pripyat",-18,-12,58,83,-6,-3) or        -- Подземный переход
  97.        npc_in_zone(npc,"l11_pripyat",167,173,58,83,-6,-3) or        -- Подземный переход
  98.        npc_in_zone(npc,"l11_pripyat",-24,55,116,122,-4,0) then      -- Канализация
  99.         return true
  100.     else
  101.         local hide = get_nearest_hide(npc)
  102.         if hide then
  103.             if utils.npc_in_zone(npc, hide.obj) then
  104.                 return true
  105.             end
  106.         end
  107.     end
  108.     return false
  109. end
  110.  
  111.  
  112. -- Spawn function. Better watch out :)
  113. function spawn_restrictor(p_level, p_vector, p_lv, p_gv, p_type, p_radius)
  114.  
  115. local p_name
  116.  
  117. p_name = p_level.."_hide_restrictor"
  118.  
  119. local obj = alife():create(p_name, p_vector, p_lv, p_gv)
  120.  
  121. local hide_name
  122. if string.find(p_type, "_") then hide_name = "ogsm_common_hide"
  123. else hide_name = "ogsm_"..p_type.."_hide" end
  124.  
  125. local mapspot
  126. if p_radius < 4 then mapspot = "ogsm_hide_spot_min"
  127. elseif p_radius < 11 then mapspot = "ogsm_hide_spot_mdl"
  128. else mapspot = "ogsm_hide_spot_max" end
  129.  
  130. local packet = net_packet()
  131.  
  132. obj:STATE_Write(packet)
  133.  
  134. -- свойства cse_alife_object
  135. local game_vertex_id = packet:r_u16()
  136. local cse_alife_object__unk1_f32 = packet:r_float()
  137. local cse_alife_object__unk2_u32 = packet:r_s32()
  138. local level_vertex_id = packet:r_s32()
  139. local object_flags = packet:r_s32()
  140. local custom_data = packet:r_stringZ()
  141. local story_id = packet:r_s32()
  142. local cse_alife_object__unk3_u32 = packet:r_s32()
  143.  
  144. -- свойства cse_shape
  145. local shape_count = packet:r_u8()
  146. local shape_type
  147. local center
  148. local radius
  149.  
  150. if shape_count == 0 then
  151.     shape_type = 0
  152.     center = vector():set(0,0,0)
  153.     radius = 10.0
  154.     shape_count = 1
  155. else
  156. for i=1,shape_count do
  157.     local shape_type = packet:r_u8()
  158.     if shape_type == 0 then
  159.         local center = packet:r_vec3()
  160.         local radius = packet:r_float()
  161.     else
  162.         local v1 = packet:r_vec3()
  163.         local v2 = packet:r_vec3()
  164.         local v3 = packet:r_vec3()
  165.         local v4 = packet:r_vec3()
  166.     end
  167. end
  168. end
  169.  
  170. -- свойства cse_alife_space_restrictor
  171. local restrictor_type = packet:r_u8()
  172.  
  173. -- свойства cse_alife_object
  174. packet:w_u16(game_vertex_id)
  175. packet:w_float(cse_alife_object__unk1_f32)
  176. packet:w_s32(cse_alife_object__unk2_u32)
  177. packet:w_s32(level_vertex_id)
  178. packet:w_s32(object_flags)
  179.  
  180. custom_data = "[logic] \nactive = sr_mapspot \n[sr_mapspot] \nhint = "..hide_name.." \nlocation = "..mapspot
  181.  
  182. local cd = parse_custom_data(custom_data)
  183. if not cd then cd={} end
  184. if not cd.parameters then cd.parameters = {} end
  185. cd.parameters.community = p_type
  186. cd.parameters.radius = p_radius
  187. custom_data = gen_custom_data(cd)
  188.  
  189. packet:w_stringZ(custom_data)
  190. packet:w_s32(story_id)
  191. packet:w_s32(cse_alife_object__unk3_u32)
  192.  
  193. -- свойства cse_shape
  194. packet:w_u8(shape_count)
  195.  
  196. for i=1,shape_count do
  197.     packet:w_u8(shape_type)
  198.     if shape_type == 0 then
  199.         packet:w_vec3(center)
  200.         packet:w_float(p_radius)
  201.     else
  202.         packet:w_vec3(v1)
  203.         packet:w_vec3(v2)
  204.         packet:w_vec3(v3)
  205.         packet:w_vec3(v4)
  206.     end
  207. end
  208.  
  209. -- свойства cse_alife_space_restrictor
  210. packet:w_u8(restrictor_type)
  211.  
  212. obj:STATE_Read(packet, packet:w_tell()-packet:r_tell())
  213.  
  214. return obj
  215. end
  216.  
  217.  
  218. -- Don't touch this too.
  219. function parse_custom_data(str)
  220.  local t={}
  221.  if str then
  222.   for section, section_data in string.gfind(str,"%s*%[([^%]]*)%]%s*([^%[%z]*)%s*") do
  223.    section = trim(section)
  224.    t[section]={}
  225.    for line in string.gfind(trim(section_data), "([^\n]*)\n*") do
  226.     if string.find(line,"=")~=nil then
  227.      for k, v in string.gfind(line, "([^=]-)%s*=%s*(.*)") do
  228.       k = trim(k)
  229.       if k~=nil and k~='' and v~=nil then
  230.        t[section][k]=trim(v)
  231.       end
  232.      end
  233.     else
  234.      for k, v in string.gfind(line, "(.*)") do
  235.       k = trim(k)
  236.       if k~=nil and k~='' then
  237.        t[section][k]="<<no_value>>"
  238.       end
  239.      end
  240.     end
  241.    end
  242.   end
  243.  end
  244.  return t
  245. end
  246. function gen_custom_data(tbl)
  247.  local str=''
  248.  for key, value in pairs(tbl) do
  249.   str = str.."["..key.."]\n"
  250.   for k, v in pairs(value) do
  251.    if v~="<<no_value>>" then
  252.     str=str..k.." = "..v.."\n"
  253.    else
  254.     str=str..k.."\n"
  255.    end
  256.   end
  257.  end
  258.  return str
  259. end
  260. function trim (s)
  261.  return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
  262. end
  263.  
  264.  
  265. -- Getting the list of hideouts on game load
  266. function get_level_hides()
  267. for i=1,65535 do
  268.     local obj = alife():object(i)
  269.     if obj then
  270.         if string.find(obj:name(), level.name().."_hide_restrictor") then
  271.             table.insert(restrictor_list, obj)
  272.         end
  273.     end
  274. end
  275. end
  276.  
  277.  
  278. -- First run spawn. If parameter p_type is "fake_" - it means that the hide is fake - it is only for actor
  279. -- NPCs ignore such fake hides
  280. function first_run()
  281.  
  282. ------------------
  283. -- Escape Hides --
  284. ------------------
  285.  
  286. -- Бункер Сидора
  287. spawn_restrictor("l01_escape", vector():set(-249.9,-24.8,-134.4), 10136, 7, "fake_", 3)
  288. -- Лагерь новичков
  289. spawn_restrictor("l01_escape", vector():set(-206.5,-22.53,-128.1), 46582, 58, "stalker", 3)
  290. spawn_restrictor("l01_escape", vector():set(-211.4,-23.17,-129.5), 41963, 59, "stalker", 3)
  291. -- Ферма
  292. spawn_restrictor("l01_escape", vector():set(-8.4,0.64,258.3), 268724, 183, "stalker", 4)
  293. -- Заброшенный дом рядом с Лисом
  294. spawn_restrictor("l01_escape", vector():set(133.0,0.22,339.5), 437657, 232, "stalker_bandit", 3)
  295. -- АТП
  296. spawn_restrictor("l01_escape", vector():set(109.9,-7.48,7.7), 411371, 118, "stalker_bandit", 5)
  297. -- Блокпост
  298. spawn_restrictor("l01_escape", vector():set(-119.7,-30.04,-386.4), 133789, 27, "military", 4)
  299. spawn_restrictor("l01_escape", vector():set(-140.7,-29.68,-361.2), 109717, 18, "military", 4)
  300. -- Мельница
  301. spawn_restrictor("l01_escape", vector():set(13.3,2.7,98.7), 290783, 92, "military", 3)
  302.  
  303. -------------------
  304. -- Garbage Hides --
  305. -------------------
  306.  
  307. -- Ангар - восточная часть
  308. spawn_restrictor("l02_garbage", vector():set(-61.6,0.75,9.1), 135489, 330, "stalker", 6)
  309. -- Изгородь
  310. spawn_restrictor("l02_garbage", vector():set(66.5,0.6,144.9), 237602, 364, "bandit", 2)
  311. -- Ангар - западная часть
  312. spawn_restrictor("l02_garbage", vector():set(-102.9,0.44,11.9), 110339, 328, "bandit", 6)
  313.  
  314. --------------------
  315. -- Agroprom Hides --
  316. --------------------
  317.  
  318. -- Строение в районе Крота
  319. spawn_restrictor("l03_agroprom", vector():set(16.8,0,14), 256750, 693, "stalker_bandit_military", 6)
  320. -- Убежище Крота
  321. spawn_restrictor("l03_agroprom", vector():set(39.9,2.5,-10.5), 278041, 693, "stalker", 6)
  322. -- Казармы у подземелья
  323. spawn_restrictor("l03_agroprom", vector():set(-158.2,1.1,-151.2), 79088, 693, "military", 5)
  324. -- Казармы у НИИ
  325. spawn_restrictor("l03_agroprom", vector():set(-153.3,1.1,-166.6), 84356, 693, "military", 5)
  326. -- Строение у НИИ
  327. spawn_restrictor("l03_agroprom", vector():set(-179.9,0,-187.6), 56704, 693, "military", 6)
  328. -- НИИ Агропром
  329. spawn_restrictor("l03_agroprom", vector():set(-145.6,0,-200.9), 92513, 693, "military", 6)
  330.  
  331. ----------------------
  332. -- Darkvalley Hides --
  333. ----------------------
  334.  
  335. -- Строения над входом в Х18
  336. spawn_restrictor("l04_darkvalley", vector():set(146.3,0.22,-263.2), 345170, 813, "bandit_military_dolg", 15)
  337. spawn_restrictor("l04_darkvalley", vector():set(128.1,0.14,-294), 325149, 813, "bandit_military_dolg", 7)
  338. -- Ферма
  339. spawn_restrictor("l04_darkvalley", vector():set(-135.1,0.97,-511), 22718, 813, "stalker", 8)
  340. -- Бензоколонка
  341. spawn_restrictor("l04_darkvalley", vector():set(101.5,0.7,-7.7), 297166, 813, "stalker_", 6)
  342. -- Подвал рядом с ямой
  343. spawn_restrictor("l04_darkvalley", vector():set(34.3,-2.93,-0.7), 216848, 813, "bandit_dolg", 4)
  344. -- Элеватор
  345. spawn_restrictor("l04_darkvalley", vector():set(-7,0.11,-57.4), 165893, 813, "bandit", 4)
  346. -- Комната Борова
  347. spawn_restrictor("l04_darkvalley", vector():set(39.2,4.54,-84), 223238, 813, "bandit", 5)
  348. -- Холл
  349. spawn_restrictor("l04_darkvalley", vector():set(37.1,0.375,-66.5), 220567, 813, "bandit", 5)
  350. -- Над тюрьмой
  351. spawn_restrictor("l04_darkvalley", vector():set(40.6,1.01,-31.5), 225406, 813, "bandit", 7)
  352.  
  353. ---------------
  354. -- Bar Hides --
  355. ---------------
  356.  
  357. -- Бункер на заставе
  358. spawn_restrictor("l05_bar", vector():set(214.2,-1.57,-18.9), 52736, 1233, "stalker_dolg", 3)
  359. -- Иди своей дорогой, сталкер...
  360. spawn_restrictor("l05_bar", vector():set(178.5,0.09,49.0), 44766, 1233, "stalker_dolg", 6)
  361. -- Магазин Петренко
  362. spawn_restrictor("l05_bar", vector():set(210.0,0.42,61.6), 51205, 1233, "dolg", 5)
  363. -- База Долга
  364. spawn_restrictor("l05_bar", vector():set(224.0,-5.26,130.9), 56342, 1233, "fake_", 8)
  365. -- Предбанник Арены
  366. spawn_restrictor("l05_bar", vector():set(142.8,0.09,93.1), 38428, 1233, "stalker_dolg", 6)
  367. -- Строения у Бара
  368. spawn_restrictor("l05_bar", vector():set(112.7,0.097,68.6), 33337, 1233, "stalker_dolg", 6)
  369. spawn_restrictor("l05_bar", vector():set(144.9,-0.012,40.6), 38939, 1233, "stalker_dolg", 6)
  370. -- Бар
  371. spawn_restrictor("l05_bar", vector():set(131.6,-4.83,23.8), 36240, 1233, "fake_", 10)
  372.  
  373. ------------------
  374. -- Rostok Hides --
  375. ------------------
  376.  
  377. -- Блокпост наемников
  378. spawn_restrictor("l06_rostok", vector():set(-88.9,0,137.2), 46715, 1311, "stalker_dolg_killer_ecolog", 2)
  379. spawn_restrictor("l06_rostok", vector():set(-82.6,1.95,156.8), 48150, 1311, "stalker_dolg_killer_ecolog", 3)
  380. -- Ангар с пси-зоной
  381. spawn_restrictor("l06_rostok", vector():set(-191.8,0,130.9), 28448, 1311, "stalker_dolg_killer_ecolog", 6)
  382. -- Тоннель Фримена
  383. spawn_restrictor("l06_rostok", vector():set(-280,-6,109.2), 1769, 1311, "ecolog", 3)
  384. -- Засады наемников
  385. spawn_restrictor("l06_rostok", vector():set(-242.9,0,140), 12634, 1311, "killer", 2)
  386. spawn_restrictor("l06_rostok", vector():set(-228.2,0.13,141.4), 19047, 1311, "killer", 2)
  387. spawn_restrictor("l06_rostok", vector():set(-250.6,1.43,14), 9490, 1311, "killer", 2)
  388.  
  389. --------------------
  390. -- Military Hides --
  391. --------------------
  392.  
  393. -- База Долга
  394. spawn_restrictor("l07_military", vector():set(-191.8,-13,39.9), 133097, 1546, "dolg", 4)
  395. -- Деревня кровососов
  396. spawn_restrictor("l07_military", vector():set(-228.9,-21.78,196.7), 102257, 1546, "freedom", 4)
  397. -- Стоянка нейтралов
  398. spawn_restrictor("l07_military", vector():set(-71.4,-16.83,242.9), 240966, 1546, "stalker", 3)
  399. -- Барьер
  400. spawn_restrictor("l07_military", vector():set(84.7,-7,341.6), 382116, 1546, "freedom", 3)
  401. -- Хутор Павлика
  402. spawn_restrictor("l07_military", vector():set(-190.4,-16,371), 134714, 1546, "killer_freedom", 4)
  403. -- Штаб Свободы
  404. spawn_restrictor("l07_military", vector():set(-21.7,-4.12,-23.8), 285439, 1546, "fake_", 6)
  405. -- Казармы
  406. spawn_restrictor("l07_military", vector():set(9.1,-7.28,16.1), 316470, 1546, "freedom", 6)
  407. spawn_restrictor("l07_military", vector():set(57.4,-8.054,16.8), 356438, 1546, "freedom", 6)
  408. -- Кухня
  409. spawn_restrictor("l07_military", vector():set(-77,-11.34,30.1), 235657, 1546, "freedom", 6)
  410.  
  411. ------------------
  412. -- Yantar Hides --
  413. ------------------
  414.  
  415. -- Бункер ученых
  416. spawn_restrictor("l08_yantar", vector():set(31.5,-11.68,-272.3), 54643, 1459, "fake_", 6)
  417.  
  418. -----------------
  419. -- Radar Hides --
  420. -----------------
  421.  
  422. -- Секретная база Монолита
  423. spawn_restrictor("l10_radar", vector():set(650.955,-43.887,182.48), 226701, 1868, "dolg_freedom_stalker_military_monolith", 7)
  424. -- Вход в бункер
  425. spawn_restrictor("l10_radar", vector():set(147.35,-9.277,-24.21), 52689, 1868, "dolg_freedom_stalker_military_monolith", 4)
  426. -- Казармы на Радаре
  427. spawn_restrictor("l10_radar", vector():set(33.6,-3.38,-42), 21487, 1868, "dolg_freedom_stalker_military_monolith", 4)
  428.  
  429. -------------------
  430. -- Pripyat Hides --
  431. -------------------
  432.  
  433. -- Подземная автостоянка
  434. spawn_restrictor("l11_pripyat", vector():set(85.4,-7.39,20.3), 196856, 2269, "stalker_military_freedom_dolg_killer", 15)
  435. -- Сберкасса
  436. spawn_restrictor("l11_pripyat", vector():set(60.2,-1.74,33.6), 172091, 2269, "stalker_military_freedom_dolg_killer", 4)
  437. -- Милиция
  438. spawn_restrictor("l11_pripyat", vector():set(-35.7,-1.68,34.3), 63044, 2269, "stalker_military_freedom_dolg_killer", 6)
  439. -- Сельхозуправление
  440. spawn_restrictor("l11_pripyat", vector():set(-51.1,0,140), 48522, 2269, "stalker_military_freedom_dolg_killer", 12)
  441. -- Подвал Дома культуры
  442. spawn_restrictor("l11_pripyat", vector():set(-5.6,-5.169,193.2), 95262, 2269, "fake_", 6)
  443. -- Подземные переходы
  444. spawn_restrictor("l11_pripyat", vector():set(-15.4,-5.55,69.3), 83833, 2269, "stalker_military_freedom_dolg_killer", 3)
  445. spawn_restrictor("l11_pripyat", vector():set(170.8,-5.55,69.3), 253270, 2269, "stalker_military_freedom_dolg_killer", 3)
  446. -- Канализация
  447. spawn_restrictor("l11_pripyat", vector():set(19.6,-3.634,121.1), 125990, 2269, "stalker_military_freedom_dolg_killer", 2)
  448.  
  449. end
  450.  
  451.  
  452. -- The Scheme itself below should not be edited if you don't how to do it
  453.  
  454. property_base = 12221
  455. property_blowout = property_base+1
  456. property_hideout_lost = property_base+2
  457. property_inhide = property_base+3
  458. act_base = 13332
  459. act_hideout = act_base+1
  460. act_psy_effect = act_base+2
  461. act_inhide = act_base+3
  462.  
  463. -- Создаем эвалуатор - проверяем, начался ли выброс
  464. class "evaluator_blowout" (property_evaluator)
  465. function evaluator_blowout:__init(name, storage) super (nil, name)
  466.     self.st = storage
  467. end
  468. function evaluator_blowout:evaluate()
  469.     if not self.object:best_enemy() and
  470.        db.Flag2==1 and db.Dead2==0 and
  471.        not (level.name()=="l11_pripyat" and self.object:character_community() == "monolith") and
  472.        not is_in_hide(self.object) and not is_in_specific_zone(self.object) then
  473.         self.st.blowout = true
  474.     else
  475.         self.st.blowout = false
  476.     end
  477.     return self.st.blowout == true
  478. end
  479.  
  480. -- Создаем эвалуатор - проверяем, потерял ли непись укрытие
  481. class "evaluator_hideout" (property_evaluator)
  482. function evaluator_hideout:__init(name, storage) super (nil, name)
  483.     self.st = storage
  484. end
  485. function evaluator_hideout:evaluate()
  486.     if db.Dead2==1 and not is_in_hide(self.object) and not is_in_specific_zone(self.object) then
  487.         self.st.hideout_lost = true
  488.     else
  489.         self.st.hideout_lost = false
  490.     end
  491.     return self.st.hideout_lost == true
  492. end
  493.  
  494. -- Создаем эвалуатор - проверяем, сидит ли уже непись в укрытии
  495. class "evaluator_inhide" (property_evaluator)
  496. function evaluator_inhide:__init(name, storage) super (nil, name)
  497.     self.st = storage
  498. end
  499. function evaluator_inhide:evaluate()
  500.     if db.Flag2==1 and is_in_hide(self.object) then
  501.         self.st.inhide = true
  502.     else
  503.         self.st.inhide = false
  504.     end
  505.     return self.st.inhide == true
  506. end
  507.  
  508.  
  509. -- Создаем оператор - направляем НПС в укрытие
  510. class "action_hideout" (action_base)
  511. function action_hideout:__init(name, storage) super (nil, name)
  512.     self.st = storage
  513. end
  514. function action_hideout:initialize()
  515.     local npc = self.object
  516.     npc:set_desired_position()
  517.     npc:set_desired_direction()
  518.     npc:clear_animations()
  519.     npc:set_detail_path_type(move.line)
  520.     npc:set_path_type(game_object.level_path)
  521.     npc:remove_all_restrictions()
  522.     if npc_run[npc:id()] ~= 1 then
  523.         self.hide = get_nearest_hide(npc)
  524.         if self.hide then
  525.             npc:add_restrictions(self.hide.obj:name(), "")
  526.             state_mgr.set_state(npc, "assault")
  527.         else
  528.             npc:remove_all_restrictions()
  529.             state_mgr.set_state(npc, "hide")
  530.         end
  531.         npc_run[npc:id()] = 1
  532.     end
  533. end
  534. function action_hideout:execute()
  535.     local npc = self.object
  536.     npc:disable_talk()
  537. end
  538. function action_hideout:finalize()
  539.     action_base.finalize(self)
  540.     local npc = self.object
  541.     npc_run[npc:id()] = 0
  542. end
  543.  
  544. -- Создаем оператор - колбасим НПС, если он не нашел укрытие
  545. class "action_raskolbas" (action_base)
  546. function action_raskolbas:__init(name, storage) super (nil, name)
  547.     self.st = storage
  548. end
  549. function action_raskolbas:initialize() --Some kind of brain frying thing
  550.     local npc = self.object
  551.     npc:set_desired_position()
  552.     npc:set_desired_direction()
  553.     npc:clear_animations()
  554.     npc:remove_all_restrictions()
  555.     local ran = math.random(1,2)
  556.     if npc_psy[npc:id()] ~= 1 then
  557.         if npc:character_community() == "monolith" then
  558.             state_mgr.set_state(npc, "trans_1")
  559.         else
  560.             if ran == 1 then
  561.                 state_mgr.set_state(npc, "psycho_pain")
  562.             else
  563.                 state_mgr.set_state(npc, "psy_pain")
  564.             end
  565.         end
  566.         npc_psy[npc:id()] = 1
  567.     end
  568. end
  569. function action_raskolbas:execute()
  570.     local npc=self.object
  571.     npc:disable_talk()
  572. end
  573. function action_raskolbas:finalize()
  574.     action_base.finalize(self)
  575.     local npc = self.object
  576.     npc_psy[npc:id()] = 0
  577. end
  578.  
  579. -- Создаем оператор - усаживаем НПС, если он нашел укрытие
  580. class "action_inhide" (action_base)
  581. function action_inhide:__init(name, storage) super (nil, name)
  582.     self.st = storage
  583. end
  584. function action_inhide:initialize()
  585.     local npc = self.object
  586.     npc:set_desired_position()
  587.     npc:set_desired_direction()
  588.     npc:clear_animations()
  589.     npc:set_detail_path_type(move.line)
  590.     npc:set_path_type(game_object.level_path)
  591.     npc:remove_all_restrictions()
  592.     self.hide = get_nearest_hide(npc)
  593.     if self.hide then
  594.         self.vertex = self.hide.obj:level_vertex_id()
  595.         self.offset = vector():set(math.random()*3-1, 0, math.random()*3-1)
  596.         self.offset:normalize()
  597.         self.radius = math.random(1, self.hide.rad-1)
  598.         self.lvid = npc:vertex_in_direction(self.vertex, self.offset, self.radius)
  599.         if npc:level_vertex_id()~=self.lvid then
  600.             state_mgr.set_state(npc,"raid")
  601.             utils.send_to_nearest_accessible_vertex(npc, self.lvid)
  602.         else
  603.             state_mgr.set_state(npc,"hide")
  604.         end
  605.     else
  606.         state_mgr.set_state(npc,"hide")
  607.     end
  608. end
  609. function action_inhide:execute()
  610.     local npc = self.object
  611.     npc:disable_talk()
  612.     if npc:level_vertex_id()~=self.lvid then
  613.         if npc_go[npc:id()]~=1 then
  614.             state_mgr.set_state(npc,"raid")
  615.             utils.send_to_nearest_accessible_vertex(npc, self.lvid)
  616.             npc_go[npc:id()] = 1
  617.             npc_sit[npc:id()] = 0
  618.         end
  619.     else
  620.         if npc_sit[npc:id()]~=1 then
  621.             if npc:character_community()=="monolith" then
  622.                 state_mgr.set_state(npc,"trans_0")
  623.             else
  624.                 state_mgr.set_state(npc,"hide")
  625.             end
  626.             npc_sit[npc:id()] = 1
  627.             npc_go[npc:id()] = 0
  628.         end
  629.     end
  630. end
  631. function action_inhide:finalize()
  632.     action_base.finalize(self)
  633.     local npc = self.object
  634.     npc_sit[npc:id()] = 0
  635.     npc_go[npc:id()] = 0
  636.     npc:remove_all_restrictions()
  637. end
  638.  
  639.  
  640. -- Добавляем в планировщик нашу схему
  641. function add_to_binder(object, char_ini, scheme, section, st)
  642.     local manager = object:motivation_action_manager()
  643.     local property_wounded = xr_evaluators_id.sidor_wounded_base
  644.  
  645.     manager:remove_evaluator(property_blowout)
  646.     manager:add_evaluator(property_blowout, evaluator_blowout("evaluator_blowout", st))
  647.  
  648.     manager:remove_evaluator(property_hideout_lost)
  649.     manager:add_evaluator(property_hideout_lost, evaluator_hideout("evaluator_hideout", st))
  650.  
  651.     manager:remove_evaluator(property_inhide)
  652.     manager:add_evaluator(property_inhide, evaluator_inhide("evaluator_inhide", st))
  653.  
  654.     local action = action_hideout("action_hideout", st)
  655.     action:add_precondition(world_property(stalker_ids.property_alive, true))
  656.     action:add_precondition(world_property(property_wounded, false))
  657.     action:add_precondition(world_property(stalker_ids.property_enemy, false))
  658.     action:add_precondition(world_property(stalker_ids.property_danger, false))
  659.     action:add_precondition(world_property(property_hideout_lost, false))
  660.     action:add_precondition(world_property(property_inhide, false))
  661.     action:add_precondition(world_property(property_blowout, true))
  662.     action:add_effect(world_property(property_blowout, false))
  663.     manager:add_action(act_hideout, action)
  664.  
  665.     local action = action_raskolbas("action_raskolbas", st)
  666.     action:add_precondition(world_property(stalker_ids.property_alive, true))
  667.     action:add_precondition(world_property(property_wounded, false))
  668.     action:add_precondition(world_property(property_blowout, false))
  669.     action:add_precondition(world_property(property_inhide, false))
  670.     action:add_precondition(world_property(property_hideout_lost, true))
  671.     action:add_effect(world_property(property_hideout_lost, false))
  672.     manager:add_action(act_psy_effect, action)
  673.  
  674.     local action = action_inhide("action_inhide", st)
  675.     action:add_precondition(world_property(stalker_ids.property_alive, true))
  676.     action:add_precondition(world_property(property_wounded, false))
  677.     action:add_precondition(world_property(stalker_ids.property_enemy, false))
  678.     action:add_precondition(world_property(stalker_ids.property_danger, false))
  679.     action:add_precondition(world_property(property_blowout, false))
  680.     action:add_precondition(world_property(property_hideout_lost, false))
  681.     action:add_precondition(world_property(property_inhide, true))
  682.     action:add_effect(world_property(property_inhide, false))
  683.     manager:add_action(act_inhide, action)
  684.  
  685.     action = manager:action(stalker_ids.action_alife_planner)
  686.     action:add_precondition(world_property(property_blowout, false))
  687.     action:add_precondition(world_property(property_hideout_lost, false))
  688.     action:add_precondition(world_property(property_inhide, false))
  689.  
  690.     action = manager:action(stalker_ids.action_combat_planner)
  691.     action:add_precondition(world_property(property_hideout_lost, false))
  692.  
  693.     action = manager:action(stalker_ids.action_danger_planner)
  694.     action:add_precondition(world_property(property_hideout_lost, false))
  695. end
  696.  
  697.  
  698. -- Функции включения/выключения схемы
  699. function enable_scheme(npc, ini)
  700.     local st = xr_logic.assign_storage_and_bind(npc, ini, "ogsm_hideout")
  701.     st.enabled=true
  702. end
  703. function disable_scheme(npc, scheme)
  704.     local st = db.storage[npc:id()][scheme]
  705.     if st then
  706.         st.enabled = false
  707.     end
  708. end
  709.  
  710.  
  711. ---------------- Схема поведения НПС при выбросе для OGSM 2.x -----------------
  712.  
  713. ------------------------- Copyright 2007-2008 DEXXX ---------------------------
  714.  
  715. --[[
  716.  
  717. If you're going to use the whole of this script or its parts in your own creative
  718. developments for the S.T.A.L.K.E.R. game, please don't become such a goddamn
  719. motherfucker like the notorious author of the ABC Mod - Carbrobro. Leave the
  720. copyrights, note the real author(s) and don't claim others' ideas and their
  721. realization to be your own ones. It's just simple Modmakers' Ethics. Thank you!
  722.  
  723. Если вы собираетесь использовать данный скрипт целиком или частично в своих
  724. разработках по игре S.T.A.L.K.E.R., пожалуйста не опускайтесь до уровня печально
  725. известного автора ABC мода - Carbrobro. Не удаляйте копирайты, указывайте настоящего
  726. автора(ов) и не выдавайте чужие идеи и их реализацию за свои. Ведь это элементарная
  727. этика модостроителей! Спасибо за понимание.
  728.  
  729. ]]--
Advertisement
Add Comment
Please, Sign In to add comment