Advertisement
Guest User

rx_ff.script

a guest
Feb 18th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 KB | None | 0 0
  1. ---- Rulix aka Bak --- 29.7.2009
  2.  
  3. function printf(s,...)
  4. -- rx_ai.printf("ff:"..s,...)
  5. -- get_console():execute("flush")
  6. end
  7.  
  8. local ff_ini = ini_file("misc\\rx_ff.ltx")
  9. local ff_sets = {forbiddens = {factions = {},npcs = {}},
  10. check_prd = rx_utils.read_from_ini(ff_ini,"main","check_period",200),
  11. enabled = rx_utils.read_from_ini(ff_ini,"main","enabled",true,0)}
  12.  
  13. local good_acts = {[xr_actions_id.smartcover_action] = true,[xr_actions_id.smartcover_action+2] = true}
  14.  
  15. function init()
  16. ff_sets.forbiddens.factions = rx_utils.parse_list(ff_ini,"main","forbidden_factions",true)
  17. ff_sets.forbiddens.npcs = rx_utils.parse_list(ff_ini,"main","forbidden_npcs",true)
  18. ff_sets.inited = true
  19. ff_ini = nil
  20. end
  21.  
  22. class "evaluator_dont_shoot" (property_evaluator)
  23. function evaluator_dont_shoot:__init(npc,name,storage) super (nil,name)
  24. self.st = storage
  25. end
  26. function evaluator_dont_shoot:evaluate()
  27. local npc = self.object
  28. if good_acts[npc:motivation_action_manager():current_action_id()] then
  29. return false
  30. end
  31. local enemy = npc:best_enemy()
  32. local res = false
  33. if enemy and npc:see(enemy) and not xr_wounded.is_wounded(enemy) then
  34. local enemy_id = enemy:id()
  35. if rx_knife and rx_knife.targets[enemy_id] and rx_knife.targets[enemy_id] ~= npc:id() then
  36. local hunter = level.object_by_id(rx_knife.targets[enemy_id])
  37. if hunter and npc:relation(hunter) ~= game_object.enemy and npc:see(hunter) then
  38. local n_dist = npc:position():distance_to(enemy:position())
  39. local h_dist = hunter:position():distance_to(enemy:position())
  40. if h_dist < 3.5 and h_dist < n_dist then
  41. res = true
  42. self.st.vdist = 5
  43. end
  44. end
  45. else
  46. local f,d = friends_on_fire_line(npc)
  47. -- printf("eva[%s]:%s",npc:character_name(),tostring(f))
  48. res = f
  49. self.st.vdist = d
  50. end
  51. end
  52. -- printf("enemy[%s]: %s",npc:character_name(),tostring(enemy~=nil))
  53. return res
  54. end
  55.  
  56. class "action_verso" (action_base)
  57. function action_verso:__init (npc,action_name,storage) super (nil,action_name)
  58. self.st = storage
  59. end
  60. function action_verso:initialize()
  61. action_base.initialize(self)
  62. local npc = self.object
  63. npc:set_desired_position()
  64. npc:set_desired_direction()
  65. npc:set_mental_state(anim.danger)
  66. npc:set_item(object.aim1,npc:active_item())
  67. local enemy = npc:best_enemy()
  68. if enemy then
  69. npc:set_sight(look.fire_point,rx_utils.safe_bone_pos(enemy))
  70. end
  71. self.vertex = get_vertex(npc,self.st.vdist)
  72. self.timer = time_global()+800*self.st.vdist
  73. printf("act2[%s]:init vertex = %s, vdist = %s",npc:character_name(),tostring(self.vertex),self.st.vdist)
  74. state_mgr.set_state(npc,"assault")
  75. end
  76. function action_verso:execute()
  77. action_base.execute(self)
  78. local npc,tg = self.object,time_global()
  79. local enemy = npc:best_enemy()
  80. if enemy then
  81. npc:set_sight(look.fire_point,rx_utils.safe_bone_pos(enemy))
  82. end
  83. npc:set_item(object.aim1,npc:active_item())
  84. if self.vertex then
  85. npc:set_dest_level_vertex_id(self.vertex)
  86. end
  87. if not self.vertex or npc:level_vertex_id() == self.vertex or self.timer < tg then
  88. printf("act2[%s]:vertex re",npc:character_name())
  89. self.vertex = get_vertex(npc,self.st.vdist)
  90. self.timer = tg+700*self.st.vdist
  91. end
  92. end
  93. function action_verso:finalize()
  94. action_base.finalize(self)
  95. printf("act2[%s]:fin",self.object:character_name())
  96. end
  97.  
  98. evid_dont_shoot = rx_ai.base_id+25
  99. actid_dont_shoot = evid_dont_shoot
  100.  
  101. function add_to_binder(npc,ini,scheme,section,storage)
  102. if not ff_sets.inited then
  103. init()
  104. end
  105. local manager = npc:motivation_action_manager()
  106. if not (ff_sets.enabled and not ff_sets.forbiddens.factions[npc:character_community()] and not ff_sets.forbiddens.npcs[npc:name()]) then
  107. manager:add_evaluator(evid_dont_shoot,property_evaluator_const(false))
  108. return
  109. else
  110. manager:add_evaluator(evid_dont_shoot,evaluator_dont_shoot(npc,"eva_dont_shoot",storage))
  111. end
  112. local action = action_verso(npc,"act_dont_shoot",storage)
  113. action:add_precondition(world_property(stalker_ids.property_alive,true))
  114. action:add_precondition(world_property(xr_evaluators_id.sidor_wounded_base,false))
  115. if rx_bandage then
  116. action:add_precondition(world_property(rx_bandage.evid_bandage,false))
  117. end
  118. if rx_gl then
  119. action:add_precondition(world_property(rx_gl.evid_gl_reload,false))
  120. end
  121. if rx_facer then
  122. action:add_precondition(world_property(rx_facer.evid_facer,false))
  123. end
  124. if rx_knife then
  125. action:add_precondition(world_property(rx_knife.evid_knife_attack,false))
  126. end
  127. if xrs_grenade and xrs_grenade.evid_aaa_grenade then
  128. -- action:add_precondition(world_property(xrs_grenade.evid_crazy_grenadier,false))
  129. action:add_precondition(world_property(xrs_grenade.evid_aaa_grenade,false))
  130. end
  131. if blowout_scheme and blowout_scheme.evid_outside then
  132. action:add_precondition(world_property(blowout_scheme.evid_outside,false))
  133. end
  134. action:add_precondition(world_property(evid_dont_shoot,true))
  135. action:add_effect(world_property(evid_dont_shoot,false))
  136. manager:add_action(actid_dont_shoot,action)
  137. action = manager:action(stalker_ids.action_combat_planner)
  138. action:add_precondition(world_property(evid_dont_shoot,false))
  139. -- action = manager:action(xr_actions_id.alife)
  140. -- action:add_precondition(world_property(evid_dont_shoot,false))
  141. end
  142.  
  143. function get_vertex(npc,dist)
  144. local rnd1,ang = math.random(100)
  145. if rnd1 < 43 then
  146. ang = math.random(50,60)
  147. elseif rnd1 < 58 then
  148. ang = math.random(160,200)
  149. else
  150. ang = math.random(300,310)
  151. end
  152. local dir = vector_rotate_y(npc:direction(),ang)
  153. return npc:vertex_in_direction(npc:level_vertex_id(),dir,dist)
  154. end
  155.  
  156. function npc_update(npc)
  157. end
  158.  
  159. function set_scheme(npc,ini,scheme,section)
  160. local st = xr_logic.assign_storage_and_bind(npc,ini,scheme,section)
  161. end
  162.  
  163. function disable_scheme(npc, scheme)
  164. local st = db.storage[npc:id()][scheme]
  165. if st then
  166. st.enabled = false
  167. end
  168. end
  169.  
  170. function friends_on_fire_line(npc)
  171. local sid = npc:id()
  172. local st = rx_ai.get_storage(sid,"friends_on_fire_line")
  173. local tg = time_global()
  174. if (st.wait or 0) >= tg then
  175. return st.f,st.d
  176. end
  177. st.wait = tg+ff_sets.check_prd
  178. st.f = false
  179. st.d = 4
  180. local friends = {}
  181. local function check_object(obj)
  182. if obj and obj.clsid and obj:alive() and obj:id() ~= sid then
  183. if IsStalker(obj) and npc:relation(obj) ~= game_object.enemy then
  184. table.insert(friends,obj)
  185. end
  186. end
  187. end
  188. for o in npc:memory_visible_objects() do
  189. check_object(o:object())
  190. end
  191. for o in npc:memory_sound_objects() do
  192. -- check_object(o:object())
  193. end
  194. if #friends ~= 0 then
  195. local npc_pos = npc:bone_position("bip01_l_finger02")
  196. local be = npc:best_enemy()
  197. local be_pos = rx_utils.safe_bone_pos(be,"bip01_spine")
  198. local be_dist = npc_pos:distance_to(be_pos)
  199. if be_dist > 2 then
  200. local dir_aim = be_pos:sub(npc_pos)
  201. for i,friend in ipairs(friends) do
  202. -- if friend:relation(be) == game_object.enemy or npc:relation(friend) == game_object.friend then
  203. local friend_pos = friend:bone_position("bip01_spine")
  204. local friend_dist = npc_pos:distance_to(friend_pos)-0.5
  205. if friend_dist < be_dist then
  206. local dir_friend = utils.vector_copy_by_val(friend_pos):sub(npc_pos)
  207. local vec_e,vec_f = utils.vector_copy_by_val(dir_aim):set_length(friend_dist),dir_friend:set_length(friend_dist)
  208. -- printf("vec_e=%s,vec_f=%s",rx_utils.vec_to_str(vec_e),rx_utils.vec_to_str(vec_f))
  209. local er = 1
  210. if friend_dist < 1.6 then
  211. er = 0
  212. end
  213. local myfr = vec_f:similar(vec_e,er)
  214. if myfr == 1 then
  215. st.f = true
  216. st.d = 4*be_dist/(be_dist-friend_dist)
  217. if st.d > 25 then
  218. st.d = 25
  219. end
  220. break
  221. end
  222. end
  223. -- end
  224. end
  225. end
  226. end
  227. return st.f,st.d
  228. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement