Advertisement
Guest User

Untitled

a guest
Mar 16th, 2014
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.67 KB | None | 0 0
  1. -- Multiple Team Ai improvments by droidaka
  2.  
  3. -- Team Ai Timer's
  4. tweak_data.character.presets.gang_member_damage.REGENERATE_TIME = 0.2 -- Amount of time to pass before regenerate
  5. tweak_data.character.presets.gang_member_damage.REGENERATE_TIME_AWAY = 0.1 -- Amount of time to pass before regenerate when this criminal is far away from players
  6. tweak_data.character.presets.gang_member_damage.HEALTH_INIT = 365 --Amount of health Team Ai have before getting downed. (Default is 75)
  7. tweak_data.character.presets.gang_member_damage.DOWNED_TIME = 41 --(Amount of time in down until "dead", default is 30)
  8. tweak_data.character.presets.gang_member_damage.ARRESTED_TIME = 20 -- Amount of time in arrest before "dead" (Default is 60)
  9. tweak_data.character.presets.gang_member_damage.INCAPACITATED_TIME = 41 --(Amount of time in down until "dead", default is 30)
  10.  
  11. -- Team Ai movement speed
  12. tweak_data.character.russian.move_speed = tweak_data.character.presets.move_speed.lightning
  13. tweak_data.character.german.move_speed = tweak_data.character.presets.move_speed.lightning
  14. tweak_data.character.spanish.move_speed = tweak_data.character.presets.move_speed.lightning
  15. tweak_data.character.american.move_speed = tweak_data.character.presets.move_speed.lightning
  16.  
  17. -- Team Ai Weapons
  18. -- Dallas
  19. tweak_data.character.russian.weapon.weapons_of_choice = {
  20. primary = Idstring( "units/payday2/weapons/wpn_npc_lmg_m249/wpn_npc_lmg_m249" ),
  21. secondary = Idstring( "units/payday2/weapons/wpn_npc_c45/wpn_npc_c45" )
  22. }
  23. -- Wolf
  24. tweak_data.character.german.weapon.weapons_of_choice = {
  25. primary = Idstring( "units/payday2/weapons/wpn_npc_mp5/wpn_npc_mp5" ),
  26. secondary = Idstring( "units/payday2/weapons/wpn_npc_beretta92/wpn_npc_beretta92" )
  27. }
  28. -- Hoxton
  29. tweak_data.character.american.weapon.weapons_of_choice = {
  30. primary = Idstring( "units/payday2/weapons/wpn_npc_g36/wpn_npc_g36" ),
  31. secondary = Idstring( "units/payday2/weapons/wpn_npc_mp5_tactical/wpn_npc_mp5_tactical" )
  32. }
  33. -- Chains
  34. tweak_data.character.spanish.weapon = deep_clone( tweak_data.character.presets.weapon.gang_member )
  35. tweak_data.character.spanish.weapon.r870.FALLOFF[1].dmg_mul = 7.5
  36. tweak_data.character.spanish.weapon.r870.FALLOFF[2].dmg_mul = 6.5
  37. tweak_data.character.spanish.weapon.r870.FALLOFF[3].dmg_mul = 5.5
  38. tweak_data.character.spanish.weapon.r870.RELOAD_SPEED = 1
  39. tweak_data.character.spanish.weapon.weapons_of_choice = {
  40. primary = Idstring( "units/payday2/weapons/wpn_npc_r870/wpn_npc_r870" ),
  41. secondary = Idstring( "units/payday2/weapons/wpn_npc_raging_bull/wpn_npc_raging_bull" )
  42. }
  43. -- List of Weapons for the Ai
  44. -- self.weap_unit_names = {
  45. -- Primary Weapons
  46. -- primary = Idstring( "units/payday2/weapons/wpn_npc_m4/wpn_npc_m4" ),
  47. -- primary = Idstring( "units/payday2/weapons/wpn_npc_ak47/wpn_npc_ak47" ),
  48. -- primary = Idstring( "units/payday2/weapons/wpn_npc_r870/wpn_npc_r870" ),
  49. -- primary = Idstring( "units/payday2/weapons/wpn_npc_sawnoff_shotgun/wpn_npc_sawnoff_shotgun" ), --this one surprisingly actually DOES work with the Team Ai.
  50. -- primary = Idstring( "units/payday2/weapons/wpn_npc_mp5/wpn_npc_mp5" ),
  51. -- primary = Idstring( "units/payday2/weapons/wpn_npc_lmg_m249/wpn_npc_lmg_m249" ) --Actually works. Packs quite a punch to.
  52. -- primary = Idstring( "units/payday2/weapons/wpn_npc_s552/wpn_npc_s552" ) --NOT IN THE GAME YET!
  53. -- primary = Idstring( "units/payday2/weapons/wpn_npc_ump/wpn_npc_ump" )
  54. -- primary = Idstring( "units/payday2/weapons/wpn_npc_g36/wpn_npc_g36" )
  55. -- primary = Idstring( "units/payday2/weapons/wpn_npc_benelli/wpn_npc_benelli" ), --For some reason I have NEVER seen the gensec elite shotgun guy yet, still
  56. -- primary = Idstring( "units/payday2/weapons/wpn_npc_smg_mp9/wpn_npc_smg_mp9" ), --Have NOT tested this one, so not sure if it will work or not.
  57. -- primary = Idstring( "units/payday2/weapons/wpn_npc_sniper/wpn_npc_sniper" ), --does NOT work, will cause crash.
  58. -- primary = Idstring( "units/payday2/weapons/wpn_npc_saiga/wpn_npc_saiga" ), --does NOT work.
  59. -- Secondary Weapons
  60. -- secondary = Idstring( "units/payday2/weapons/wpn_npc_beretta92/wpn_npc_beretta92" ),
  61. -- secondary = Idstring( "units/payday2/weapons/wpn_npc_c45/wpn_npc_c45" ),
  62. -- secondary = Idstring( "units/payday2/weapons/wpn_npc_raging_bull/wpn_npc_raging_bull" ),
  63. -- secondary = Idstring( "units/payday2/weapons/wpn_npc_mp5_tactical/wpn_npc_mp5_tactical" ),
  64. -- secondary = Idstring( "units/payday2/weapons/wpn_npc_mac11/wpn_npc_mac11" ),}
  65.  
  66. -- This makes the Team Ai...BE ABLE TO DODGE!
  67. tweak_data.character.russian.dodge = tweak_data.character.presets.dodge.athletic
  68. tweak_data.character.spanish.dodge = tweak_data.character.presets.dodge.athletic
  69. tweak_data.character.american.dodge = tweak_data.character.presets.dodge.athletic
  70. tweak_data.character.german.dodge = tweak_data.character.presets.dodge.athletic
  71.  
  72. -- Team Ai gets cuffed instead of downed whenever a Cloaker attacks them
  73. function TeamAIMovement:on_SPOOCed()
  74. self._unit:brain():set_logic( "surrender" )
  75. self._unit:network():send( "arrested" )
  76. self._unit:character_damage():on_arrested()
  77. end
  78.  
  79. -- You get cuffed instead of being downed, whenever a cloaker attacks you
  80. function PlayerMovement:on_SPOOCed()
  81. if self._unit:character_damage()._god_mode then
  82. return
  83. end
  84. if self._current_state_name == "standard" or self._current_state_name == "bleed_out" then
  85. managers.player:set_player_state( "arrested" )
  86. end
  87. end
  88.  
  89. -- 3 Team Ai instead of the default 2
  90. CriminalsManager = CriminalsManager or class()
  91. CriminalsManager.MAX_NR_TEAM_AI = 3
  92. function CriminalsManager:init()
  93. self._characters =
  94. {
  95. -- Hoxton
  96. { taken = false, name = "american", unit = nil, peer_id = 0, static_data = { ai_character_id = "ai_hoxton", ssuffix = "d", color_id = 1, voice = "rb2", ai_mask_id = "hoxton", mask_id = 1 }, data = {} },
  97.  
  98. -- Wolf
  99. { taken = false, name = "german", unit = nil, peer_id = 0, static_data = { ai_character_id = "ai_wolf", ssuffix = "c", color_id = 2, voice = "rb3", ai_mask_id = "wolf", mask_id = 2 }, data = {} },
  100.  
  101. -- Dallas
  102. { taken = false, name = "russian", unit = nil, peer_id = 0, static_data = { ai_character_id = "ai_dallas", ssuffix = "a", color_id = 3, voice = "rb4", ai_mask_id = "dallas", mask_id = 3 }, data = {} },
  103.  
  104. -- Chains
  105. { taken = false, name = "spanish", unit = nil, peer_id = 0, static_data = { ai_character_id = "ai_chains", ssuffix = "b", color_id = 4, voice = "rb1", ai_mask_id = "chains", mask_id = 4 }, data = {} }
  106. }
  107. end
  108. -----------------------------------------------------------------------------------
  109. function CriminalsManager.convert_old_to_new_character_workname( workname )
  110. local t = { american = "hoxton", german = "wolf", russian = "dallas", spanish = "chains" }
  111. return t[ workname ]
  112. end
  113. function CriminalsManager.character_names()
  114. return { "russian", "german", "spanish", "american" }
  115. end
  116. function CriminalsManager.character_workname_by_peer_id( peer_id )
  117. local t = { "russian", "german", "spanish", "american" }
  118. return t[ peer_id ]
  119. end
  120. function CriminalsManager:on_simulation_ended()
  121. for id, data in pairs( self._characters ) do
  122. self:_remove( id )
  123. end
  124. end
  125. -----------------------------------------------------------------------------------
  126. function CriminalsManager:local_character_name()
  127. return self._local_character
  128. end
  129. function CriminalsManager:characters()
  130. return self._characters
  131. end
  132. -----------------------------------------------------------------------------------
  133. function CriminalsManager:get_any_unit()
  134. for id, data in pairs( self._characters ) do
  135. if data.taken and alive( data.unit ) and data.unit:id() ~= -1 then
  136. return data.unit
  137. end
  138. end
  139. end
  140. -----------------------------------------------------------------------------------
  141. function CriminalsManager:_remove( id )
  142. local data = self._characters[ id ]
  143.  
  144. print("[CriminalsManager:_remove]", inspect( data ) )
  145.  
  146. if data.name == self._local_character then
  147. self._local_character = nil
  148. end
  149. if data.unit then
  150. -- managers.hud:remove_hud_info_by_unit( data.unit )
  151. managers.hud:remove_mugshot_by_character_name( data.name )
  152. else
  153. managers.hud:remove_teammate_panel_by_name_id( data.name )
  154. end
  155. data.taken = false
  156. data.unit = nil
  157. data.peer_id = 0
  158. data.data = {}
  159. end
  160. -----------------------------------------------------------------------------------
  161. function CriminalsManager:add_character( name, unit, peer_id, ai )
  162. print("[CriminalsManager:add_character]", name, unit, peer_id, ai)
  163. Application:stack_dump()
  164.  
  165. if unit then
  166. unit:base()._tweak_table = name
  167. end
  168.  
  169. for id, data in pairs( self._characters ) do
  170. if data.name == name then
  171. if data.taken then
  172. Application:error( "[CriminalsManager:set_character] Error: Trying to take a unit slot that has already been taken!" )
  173. Application:stack_dump()
  174. Application:error( "[CriminalsManager:set_character] -----" )
  175.  
  176. self:_remove( id )
  177. end
  178.  
  179. data.taken = true
  180. data.unit = unit
  181. data.peer_id = peer_id
  182. data.data.ai = ai or false
  183. -- local mask_set = Global.game_settings.single_player and managers.network:session():local_peer():mask_set() or ((not ai) and managers.network:session():peer( peer_id ):mask_set() or "clowns")
  184. -- local set = tweak_data.mask_sets[ mask_set ][ data.static_data.mask_id ]
  185.  
  186. data.data.mask_obj = tweak_data.blackmarket.masks[ data.static_data.ai_mask_id ].unit -- set.mask_obj
  187. -- data.data.mask_icon = set.mask_icon
  188. data.data.mask_id = nil
  189. data.data.mask_blueprint = nil
  190.  
  191. if not ai and unit then
  192. local mask_id = managers.network:session():peer( peer_id ):mask_id()
  193. data.data.mask_obj = managers.blackmarket:mask_unit_name_by_mask_id( mask_id, peer_id ) -- tweak_data.blackmarket.masks[ mask_id ].unit
  194. data.data.mask_id = mask_id
  195. data.data.mask_blueprint = managers.network:session():peer( peer_id ):mask_blueprint()
  196. end
  197.  
  198. managers.hud:remove_mugshot_by_character_name( name )
  199. if unit then
  200. data.data.mugshot_id = managers.hud:add_mugshot_by_unit( unit )
  201. if unit:base().is_local_player then
  202. self._local_character = name
  203. managers.hud:reset_player_hpbar()
  204. end
  205.  
  206. unit:sound():set_voice( data.static_data.voice )
  207. unit:inventory():set_mask_visibility( unit:inventory()._mask_visibility )
  208. else
  209. data.data.mugshot_id = managers.hud:add_mugshot_without_unit( name, ai, peer_id,
  210. ai and managers.localization:text( "menu_"..name ) or managers.network:session():peer( peer_id ):name() )
  211. end
  212. break
  213. end
  214. end
  215. --print( "exited ok" )
  216. end
  217. -----------------------------------------------------------------------------------
  218. function CriminalsManager:set_unit( name, unit )
  219. print("[CriminalsManager:set_unit] name", name, "unit", unit )
  220. Application:stack_dump()
  221.  
  222. unit:base()._tweak_table = name
  223. for id, data in pairs( self._characters ) do
  224. if data.name == name then
  225. if not data.taken then
  226. Application:error( "[CriminalsManager:set_character] Error: Trying to set a unit on a slot that has not been taken!" )
  227. Application:stack_dump()
  228. return
  229. end
  230. --[[
  231. if data.unit then
  232. managers.hud:remove_hud_info_by_unit( data.unit )
  233. end
  234. ]]
  235. data.unit = unit
  236.  
  237. managers.hud:remove_mugshot_by_character_name( data.name )
  238. data.data.mugshot_id = managers.hud:add_mugshot_by_unit( unit )
  239.  
  240. data.data.mask_obj = tweak_data.blackmarket.masks[ data.static_data.ai_mask_id ].unit -- set.mask_obj
  241. -- data.data.mask_icon = set.mask_icon
  242. data.data.mask_id = nil
  243. data.data.mask_blueprint = nil
  244.  
  245. if not data.data.ai then
  246. local mask_id = managers.network:session():peer( data.peer_id ):mask_id()
  247. data.data.mask_obj = managers.blackmarket:mask_unit_name_by_mask_id( mask_id, data.peer_id ) -- tweak_data.blackmarket.masks[ mask_id ].unit
  248. data.data.mask_id = mask_id
  249. data.data.mask_blueprint = managers.network:session():peer( data.peer_id ):mask_blueprint()
  250. end
  251.  
  252. if unit:base().is_local_player then
  253. self._local_character = name
  254. managers.hud:reset_player_hpbar()
  255. end
  256.  
  257. unit:sound():set_voice( data.static_data.voice )
  258.  
  259. break
  260. end
  261. end
  262. --print( "exited ok" )
  263. end
  264. -----------------------------------------------------------------------------------
  265. function CriminalsManager:is_taken( name )
  266. for _, data in pairs( self._characters ) do
  267. if name == data.name then
  268. return data.taken
  269. end
  270. end
  271.  
  272. return false
  273. end
  274. -----------------------------------------------------------------------------------
  275. function CriminalsManager:character_name_by_peer_id( peer_id )
  276. for _, data in pairs( self._characters ) do
  277. if data.taken and peer_id == data.peer_id then
  278. return data.name
  279. end
  280. end
  281. end
  282. -----------------------------------------------------------------------------------
  283. function CriminalsManager:character_color_id_by_peer_id( peer_id )
  284. local workname = self.character_workname_by_peer_id( peer_id )
  285. return self:character_color_id_by_name( workname )
  286. --[[for _, data in pairs( self._characters ) do
  287. if data.taken and peer_id == data.peer_id then
  288. return data.static_data.color_id
  289. end
  290. end]]
  291. end
  292. -----------------------------------------------------------------------------------
  293. function CriminalsManager:character_color_id_by_unit( unit )
  294. local search_key = unit:key()
  295. for id, data in pairs( self._characters ) do
  296. if data.unit and data.taken and search_key == data.unit:key() then
  297. if data.data.ai then
  298. return 5
  299. end
  300. return data.peer_id -- self:character_color_id_by_peer_id( data.peer_id )
  301. -- local workname = managers.criminals:character_workname_by_peer_id( data.peer_id )
  302. -- return self:character_color_id_by_name( workname )
  303. -- return data.static_data.color_id
  304. end
  305. end
  306. end
  307. function CriminalsManager:character_color_id_by_name( name )
  308. --[[for i,c_name in ipairs( self:character_names() ) do
  309. if c_name == name then
  310. return i
  311. -- return self:character_color_id_by_peer_id( i )
  312. end
  313. end]]
  314. for id, data in pairs( self._characters ) do
  315. if name == data.name then
  316. -- return self:character_color_id_by_peer_id( data.peer_id )
  317. return data.static_data.color_id
  318. end
  319. end
  320. end
  321. -----------------------------------------------------------------------------------
  322. function CriminalsManager:character_data_by_name( name )
  323. for _, data in pairs( self._characters ) do
  324. if data.taken and name == data.name then
  325. return data.data
  326. end
  327. end
  328. end
  329. -----------------------------------------------------------------------------------
  330. function CriminalsManager:character_data_by_peer_id( peer_id )
  331. for _, data in pairs( self._characters ) do
  332. if data.taken and peer_id == data.peer_id then
  333. return data.data
  334. end
  335. end
  336. end
  337. -----------------------------------------------------------------------------------
  338. function CriminalsManager:character_data_by_unit( unit )
  339. local search_key = unit:key()
  340. for id, data in pairs( self._characters ) do
  341. if data.unit and data.taken and search_key == data.unit:key() then
  342. return data.data
  343. end
  344. end
  345. end
  346. -----------------------------------------------------------------------------------
  347. function CriminalsManager:character_static_data_by_name( name )
  348. for _, data in pairs( self._characters ) do
  349. if name == data.name then
  350. return data.static_data
  351. end
  352. end
  353. end
  354. -----------------------------------------------------------------------------------
  355. function CriminalsManager:character_unit_by_name( name )
  356. for _, data in pairs( self._characters ) do
  357. if data.taken and name == data.name then
  358. return data.unit
  359. end
  360. end
  361. end
  362. -----------------------------------------------------------------------------------
  363. function CriminalsManager:character_taken_by_name( name )
  364. for _, data in pairs( self._characters ) do
  365. if name == data.name then
  366. return data.taken
  367. end
  368. end
  369. end
  370. -----------------------------------------------------------------------------------
  371. function CriminalsManager:character_peer_id_by_name( name )
  372. for _, data in pairs( self._characters ) do
  373. if data.taken and name == data.name then
  374. return data.peer_id
  375. end
  376. end
  377. end
  378. -----------------------------------------------------------------------------------
  379. function CriminalsManager:get_free_character_name()
  380. local available = {}
  381. for id, data in pairs( self._characters ) do
  382. local taken = data.taken
  383.  
  384. if not taken then
  385. for _, member in pairs(managers.network:game():all_members()) do
  386. if member._assigned_name == data.name then
  387. taken = true
  388. break
  389. end
  390. end
  391. end
  392.  
  393. if not taken then
  394. table.insert( available, data.name )
  395. end
  396. end
  397.  
  398. if #available > 0 then
  399. return available[ math.random(#available) ]
  400. end
  401. end
  402. -----------------------------------------------------------------------------------
  403. function CriminalsManager:get_num_player_criminals()
  404. local num = 0
  405. for id, data in pairs( self._characters ) do
  406. if data.taken and not data.data.ai then
  407. num = num + 1
  408. end
  409. end
  410.  
  411. return num
  412. end
  413. -----------------------------------------------------------------------------------
  414. function CriminalsManager:remove_character_by_unit( unit )
  415. if type_name( unit ) ~= "Unit" then
  416. return
  417. end
  418. local rem_u_key = unit:key()
  419. for id, data in pairs( self._characters ) do
  420. if data.unit and data.taken and rem_u_key == data.unit:key() then
  421. self:_remove( id )
  422. return
  423. end
  424. end
  425. end
  426. -----------------------------------------------------------------------------------
  427. function CriminalsManager:remove_character_by_peer_id( peer_id )
  428. for id, data in pairs( self._characters ) do
  429. if data.taken and peer_id == data.peer_id then
  430. self:_remove( id )
  431. return
  432. end
  433. end
  434. end
  435. -----------------------------------------------------------------------------------
  436. function CriminalsManager:remove_character_by_name( name )
  437. for id, data in pairs( self._characters ) do
  438. if data.taken and name == data.name then
  439. self:_remove( id )
  440. return
  441. end
  442. end
  443. end
  444. -----------------------------------------------------------------------------------
  445. function CriminalsManager:character_name_by_unit( unit )
  446. if type_name( unit ) ~= "Unit" then
  447. return nil
  448. end
  449. local search_key = unit:key()
  450. for id, data in pairs( self._characters ) do
  451. if data.unit and data.taken and search_key == data.unit:key() then
  452. return data.name
  453. end
  454. end
  455. end
  456. -----------------------------------------------------------------------------------
  457. function CriminalsManager:character_name_by_panel_id( panel_id )
  458. for id, data in pairs( self._characters ) do
  459. if data.taken and data.data.panel_id == panel_id then
  460. return data.name
  461. end
  462. end
  463. end
  464. -----------------------------------------------------------------------------------
  465. function CriminalsManager:character_static_data_by_unit( unit )
  466. if type_name( unit ) ~= "Unit" then
  467. return nil
  468. end
  469. local search_key = unit:key()
  470. for id, data in pairs( self._characters ) do
  471. if data.unit and data.taken and search_key == data.unit:key() then
  472. return data.static_data
  473. end
  474. end
  475. end
  476. -----------------------------------------------------------------------------------
  477. function CriminalsManager:nr_AI_criminals()
  478. local nr_AI_criminals = 0
  479. for i, char_data in pairs( self._characters ) do
  480. if char_data.data.ai then
  481. nr_AI_criminals = nr_AI_criminals + 1
  482. end
  483. end
  484. return nr_AI_criminals
  485. end
  486.  
  487. -- fixes the Team Ai crouch bug
  488.  
  489. function TeamAILogicTravel.update( data )
  490. local unit = data.unit
  491. local objective = data.objective
  492.  
  493. if not objective then
  494. TeamAILogicIdle.on_new_objective( data, nil )
  495. return
  496. end
  497.  
  498. local my_data = data.internal_data
  499. local t = data.t
  500.  
  501. if my_data.processing_advance_path or my_data.processing_coarse_path then
  502. TeamAILogicTravel._upd_pathing( data, my_data )
  503. if my_data ~= data.internal_data then
  504. return
  505. end
  506. elseif my_data.advancing then
  507. if data.objective.type == "follow" then
  508. if (not unit:movement():chk_action_forbidden("walk") or unit:anim_data().act_idle) then
  509. local follow_unit_nav_seg = data.objective.follow_unit:movement():nav_tracker():nav_segment()
  510. if follow_unit_nav_seg ~= my_data.coarse_path[ my_data.coarse_path_index + 1 ][1] or my_data.coarse_path_index ~= #my_data.coarse_path - 1 then -- we are not moving to the follow_unit's nav_segment
  511. local my_nav_seg = data.unit:movement():nav_tracker():nav_segment()
  512. if follow_unit_nav_seg == my_nav_seg then
  513. --debug_pause_unit( data.unit, "Im next to my follow unit. STOP! follow_unit_nav_seg", follow_unit_nav_seg, "my_data.coarse_path", inspect( my_data.coarse_path ), "my_data.coarse_path_index", my_data.coarse_path_index )
  514. objective.in_place = true -- we have reached the objective area
  515. TeamAILogicTravel.on_new_objective( data ) -- re-evaluate our objective
  516. return
  517. end
  518. end
  519. end
  520. end
  521. elseif my_data.cover_leave_t then -- waiting in cover
  522. if not my_data.turning and (not unit:movement():chk_action_forbidden("walk") or not (not unit:anim_data().act_idle)) then
  523. if t > my_data.cover_leave_t then
  524. my_data.cover_leave_t = nil
  525. elseif my_data.best_cover then
  526. local action_taken
  527. if not unit:movement():attention() then
  528. action_taken = CopLogicTravel._chk_request_action_turn_to_cover( data, my_data )
  529. end
  530. if not action_taken then
  531. if not ( my_data.best_cover[4] or unit:anim_data().crouch or data.unit:movement():cool() ) then
  532. CopLogicAttack._chk_request_action_stand( data )
  533. end
  534. end
  535. end
  536. end
  537. elseif my_data.advance_path then
  538. if (not unit:movement():chk_action_forbidden("walk") or unit:anim_data().act_idle) then
  539. local haste, no_strafe
  540. if objective and objective.haste then
  541. haste = objective.haste
  542. elseif unit:movement():cool() then
  543. haste = "walk"
  544. else
  545. haste = "run"
  546. end
  547.  
  548. CopLogicTravel._chk_request_action_walk_to_advance_pos( data, my_data, haste, objective and objective.rot, no_strafe )
  549. if my_data.advancing then
  550. TeamAILogicTravel._check_start_path_ahead( data )
  551. end
  552. end
  553. elseif objective then
  554. if my_data.coarse_path then
  555. local coarse_path = my_data.coarse_path
  556. local cur_index = my_data.coarse_path_index
  557. local total_nav_points = #coarse_path
  558. if cur_index == total_nav_points then -- We have reached the final nav point. The area is investigated.
  559. objective.in_place = true -- we have reached the objective area
  560. if objective.type == "investigate_area" or objective.type == "free" then
  561. if not objective.action_duration then
  562. managers.groupai:state():on_criminal_objective_complete( unit, objective )
  563. return
  564. end
  565. end
  566. TeamAILogicTravel.on_new_objective( data ) -- re-evaluate our objective
  567. return
  568. else
  569. local to_pos = TeamAILogicTravel._get_exact_move_pos( data, cur_index + 1 )
  570. my_data.advance_path_search_id = tostring( data.key ).."advance"
  571. my_data.processing_advance_path = true
  572. local prio
  573. if objective and objective.follow_unit then
  574. prio = 5
  575. end
  576. local nav_segs = CopLogicTravel._get_allowed_travel_nav_segs( data, my_data, to_pos )
  577. --[[my_data._search_nav_segs = nav_segs
  578. my_data._path_trail = { mvector3.copy(data.m_pos), mvector3.copy(to_pos) }
  579. my_data._path_tag = "next"]]
  580. unit:brain():search_for_path( my_data.advance_path_search_id, to_pos, prio, nil, nav_segs )
  581. end
  582. else
  583. local search_id = tostring( unit:key() ).."coarse"
  584. local nav_seg
  585. if objective.follow_unit then
  586. nav_seg = objective.follow_unit:movement():nav_tracker():nav_segment()
  587. else
  588. nav_seg = objective.nav_seg
  589. end
  590. if unit:brain():search_for_coarse_path( search_id, nav_seg ) then
  591. my_data.coarse_path_search_id = search_id
  592. my_data.processing_coarse_path = true
  593. end
  594. end
  595. else
  596. CopLogicBase._exit( data.unit, "idle", { scan = true } )
  597. return
  598. end
  599. local action_taken = data.unit:movement():chk_action_forbidden("walk") and not unit:anim_data().act_idle
  600. local want_to_take_cover = TeamAILogicTravel._chk_wants_to_take_cover( data, my_data )
  601.  
  602. -- Check if we should crouch or stand
  603. if not action_taken then
  604. if want_to_take_cover or data.char_tweak.no_stand then -- I do not have cover or my cover is low and I am not crouched
  605. if not unit:anim_data().crouch then
  606. action_taken = CopLogicAttack._chk_request_action_crouch( data ) --Is bugged with Stand, testing with stand, but probably will have to just use crouch. Has bugged animations with stand.
  607. end
  608. elseif unit:anim_data().crouch then
  609. if not data.char_tweak.allow_crouch then
  610. action_taken = CopLogicAttack._chk_request_action_stand( data )
  611. end
  612. end
  613. end
  614. end
  615. -----------------------------------------------------------------------------
  616. function TeamAILogicAssault.update( data )
  617. local my_data = data.internal_data
  618. local t = data.t
  619. local unit = data.unit
  620. local focus_enemy = data.attention_obj
  621. local in_cover = my_data.in_cover
  622. local best_cover = my_data.best_cover
  623.  
  624. CopLogicAttack._process_pathing_results( data, my_data )
  625.  
  626. local focus_enemy = data.attention_obj
  627. if not focus_enemy or focus_enemy.reaction < AIAttentionObject.REACT_AIM then
  628. TeamAILogicAssault._upd_enemy_detection( data, true ) -- second param means it is not called as a queued task
  629. if my_data ~= data.internal_data or not data.attention_obj or data.attention_obj.reaction <= AIAttentionObject.REACT_SCARED then
  630. return
  631. end
  632. focus_enemy = data.attention_obj -- we found an enemy
  633. end
  634.  
  635. local enemy_visible = focus_enemy.verified
  636.  
  637. local action_taken = my_data.turning or data.unit:movement():chk_action_forbidden( "walk" ) or my_data.moving_to_cover or my_data.walking_to_cover_shoot_pos or my_data._turning_to_intimidate
  638.  
  639. my_data.want_to_take_cover = CopLogicAttack._chk_wants_to_take_cover( data, my_data ) -- out of ammo, suppressed etc
  640. local want_to_take_cover = my_data.want_to_take_cover
  641.  
  642. if not action_taken then
  643. if want_to_take_cover and ( not in_cover or not in_cover[4] ) or data.char_tweak.no_stand then -- I do not have cover or my cover is low and I am not crouched
  644. if not unit:anim_data().crouch then
  645. action_taken = CopLogicAttack._chk_request_action_stand( data )
  646. end
  647. elseif unit:anim_data().crouch then
  648. if not data.char_tweak.allow_crouch or my_data.cover_test_step > 2 then
  649. action_taken = CopLogicAttack._chk_request_action_stand( data )
  650. end
  651. end
  652. end
  653.  
  654. local move_to_cover
  655.  
  656. if action_taken then
  657. elseif want_to_take_cover then -- we don't want trouble
  658. move_to_cover = true
  659. end
  660. --[[if not enemy_visible then
  661. if not action_taken then
  662. if my_data.in_cover then
  663. if my_data.attitude == "engage" then -- I want to get back into action
  664. local shoot_from_pos
  665. if not my_data.sideways_chk_t or t > my_data.sideways_chk_t then
  666. local my_tracker = unit:movement():nav_tracker()
  667. my_data.cover_test_step = my_data.cover_test_step or 1
  668. shoot_from_pos = CopLogicAttack._peek_for_pos_sideways( data, my_data, my_tracker, focus_enemy.m_pos, 160 )
  669. if my_data.cover_test_step > 2 then
  670. my_data.cover_test_step = 1
  671. else
  672. my_data.cover_test_step = my_data.cover_test_step + 1
  673. end
  674. my_data.sideways_chk_t = t + 1
  675. end
  676. if shoot_from_pos then
  677. local my_tracker = unit:movement():nav_tracker()
  678. local path = { my_tracker:position(), shoot_from_pos }
  679. CopLogicAttack._chk_request_action_walk_to_cover_shoot_pos( data, my_data, path )
  680. end
  681. end
  682. elseif not ( my_data.in_cover[4] or unit:anim_data().crouch ) then
  683. --print( "I am behind a low cover and not crouching. Crouch" )
  684. CopLogicAttack._chk_request_action_crouch( data )
  685. end
  686. end
  687. end]]
  688.  
  689. if not ( my_data.processing_cover_path or my_data.cover_path or my_data.charge_path_search_id or action_taken )
  690. and best_cover
  691. and ( not in_cover or best_cover[1] ~= in_cover[1] )
  692. then
  693. CopLogicAttack._cancel_cover_pathing( data, my_data )
  694. local search_id = tostring( unit:key() ).."cover"
  695. if data.unit:brain():search_for_path_to_cover( search_id, best_cover[1], best_cover[5] ) then
  696. my_data.cover_path_search_id = search_id
  697. my_data.processing_cover_path = best_cover
  698. end
  699. end
  700.  
  701. if not action_taken and move_to_cover and my_data.cover_path then
  702. action_taken = CopLogicAttack._chk_request_action_walk_to_cover( data, my_data )
  703. end
  704.  
  705. if not data.objective and ( not data.path_fail_t or data.t - data.path_fail_t > 6 ) then
  706. managers.groupai:state():on_criminal_jobless( unit )
  707. if my_data ~= data.internal_data then
  708. return
  709. end
  710. end
  711.  
  712. if data.t > my_data.cover_chk_t then
  713. CopLogicAttack._update_cover( data )
  714. my_data.cover_chk_t = data.t + TeamAILogicAssault._COVER_CHK_INTERVAL
  715. end
  716. end
  717. --END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement