Advertisement
Guest User

rx_ff.script

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