Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.52 KB | None | 0 0
  1.  
  2.  
  3.  
  4. NUM_PLAYERS = 6
  5.  
  6.  
  7.  
  8. if not ProfileSynchronizer_reserve_profile then
  9. ProfileSynchronizer_reserve_profile = ProfileSynchronizer.reserve_profile
  10. ProfileSynchronizer.reserve_profile = function (self, profile_index, peer_id, local_player_id)
  11.  
  12. writelog("reserve_profile")
  13.  
  14. return
  15. end
  16. end
  17.  
  18. if not ProfileSynchronizer_unreserve_profile then
  19. ProfileSynchronizer_unreserve_profile = ProfileSynchronizer.unreserve_profile
  20. ProfileSynchronizer.unreserve_profile = function (self, profile_index, peer_id, local_player_id)
  21.  
  22. writelog("unreserve_profile")
  23.  
  24. return
  25. end
  26. end
  27.  
  28. -- if not ProfileSynchronizer_get_first_free_profile then
  29. -- ProfileSynchronizer_get_first_free_profile = ProfileSynchronizer.get_first_free_profile
  30. -- ProfileSynchronizer.get_first_free_profile = function (self)
  31. --
  32. -- writelog("get_first_free_profile")
  33. --
  34. -- -- return ProfilePriority[1]
  35. -- return 3
  36. -- end
  37. -- end
  38.  
  39. -- if not SpawnManager__update_bot_spawns then
  40. -- SpawnManager__update_bot_spawns = SpawnManager._update_bot_spawns
  41. -- SpawnManager._update_bot_spawns = function (self, dt, t)
  42. --
  43. -- -- self._available_profile_order = {4,4,4,4,4}
  44. -- -- SpawnManager._available_profile_order = {4,4,4,4,4}
  45. --
  46. -- return SpawnManager__update_bot_spawns(self, dt, t)
  47. -- end
  48. -- end
  49.  
  50. if not SpawnManager__update_available_profiles then
  51. SpawnManager__update_available_profiles = SpawnManager._update_available_profiles
  52. SpawnManager._update_available_profiles = function (self, profile_synchronizer, available_profile_order, available_profiles)
  53. local delta = 0
  54. local bots = 0
  55. local humans = 0
  56.  
  57. available_profiles[1] = true
  58. available_profiles[2] = true
  59. available_profiles[3] = true
  60. available_profiles[4] = true
  61. available_profiles[5] = true
  62.  
  63. -- this is the modified line (1=WH, 2=BW, 3=DR, 4=WE, 5=ES).
  64. for _,profile_index in ipairs({3,3,3,3,3}) do
  65. table.insert(available_profile_order, 1, profile_index)
  66. available_profiles[profile_index] = true
  67. -- --for _,profile_index in ipairs({3,1,2,4,5}) do
  68. -- local owner_type = profile_synchronizer.owner_type(profile_synchronizer, profile_index)
  69. --
  70. -- if owner_type == "human" then
  71. -- table.insert(available_profile_order, 1, profile_index)
  72. -- available_profiles[profile_index] = true
  73. -- -- humans = humans + 1
  74. -- -- local index = table.find(available_profile_order, profile_index)
  75. -- --
  76. -- -- if index then
  77. -- -- table.remove(available_profile_order, index)
  78. -- --
  79. -- -- available_profiles[profile_index] = false
  80. -- -- delta = delta - 1
  81. -- -- end
  82. -- -- elseif (owner_type == "available" or owner_type == "bot") and not table.contains(available_profile_order, profile_index) then
  83. -- elseif (owner_type == "available" or owner_type == "bot") then
  84. -- table.insert(available_profile_order, 1, profile_index)
  85. --
  86. -- available_profiles[profile_index] = true
  87. -- delta = delta + 1
  88. -- end
  89. --
  90. -- if owner_type == "bot" then
  91. -- bots = bots + 1
  92. -- end
  93. end
  94.  
  95. -- if self._forced_bot_profile_index then
  96. -- local forced_bot_profile_index = self._forced_bot_profile_index
  97. -- local index = table.find(available_profile_order, forced_bot_profile_index)
  98. -- local available = (index and profile_synchronizer.owner_type(profile_synchronizer, forced_bot_profile_index) == "available") or false
  99. --
  100. -- fassert(available, "Bot profile (%s) is not available!", SPProfilesAbbreviation[forced_bot_profile_index])
  101. --
  102. -- if index ~= 1 then
  103. -- available_profile_order[index] = available_profile_order[1]
  104. -- available_profile_order[1] = available_profile_order[index]
  105. -- end
  106. -- end
  107.  
  108. return 2, 1, 3
  109. end
  110. end
  111.  
  112.  
  113. if not ProfileSynchronizer_owner_type then
  114. ProfileSynchronizer_owner_type = ProfileSynchronizer.owner_type
  115. ProfileSynchronizer.owner_type = function (self, profile_index)
  116. writelog("owner type")
  117.  
  118. -- return "available"
  119.  
  120. if self._reserved_profiles[profile_index] then
  121. return "human", "reserved"
  122. end
  123.  
  124. local owner_table = self._profile_owners[profile_index]
  125.  
  126. if owner_table and self.is_human_player(self, owner_table.peer_id, owner_table.local_player_id) then
  127. return "human"
  128. elseif owner_table then
  129. return "bot"
  130. else
  131. return "available"
  132. end
  133.  
  134. return
  135.  
  136. end
  137. end
  138.  
  139. if not ProfileSynchronizer_set_profile_peer_id then
  140. ProfileSynchronizer_set_profile_peer_id = ProfileSynchronizer.set_profile_peer_id
  141. ProfileSynchronizer.set_profile_peer_id = function (self, profile_index, peer_id, local_player_id)
  142. writelog("set_profile_peer_id")
  143. -- profile_index = 4
  144.  
  145. -- if local_player_id == nil then
  146. -- return
  147. -- end
  148.  
  149. if local_player_id ~= nil and local_player_id > 1 then
  150. profile_index = 3
  151. end
  152.  
  153. return ProfileSynchronizer_set_profile_peer_id(self, profile_index, peer_id, local_player_id)
  154. end
  155. end
  156.  
  157. if not SpawnManager__assign_status_slot then
  158.  
  159. local out = assert(io.open("profileSyncLog.txt", "w"))
  160. out:close()
  161.  
  162. SpawnManager.in_inn = true
  163. SpawnManager.next_slot_index = 0
  164. SpawnManager.num_bots_ = 0
  165. SpawnManager.assigned_slots = {}
  166.  
  167.  
  168. SpawnManager__assign_status_slot = SpawnManager._assign_status_slot
  169. SpawnManager._assign_status_slot = function (self, peer_id, local_player_id, profile_index)
  170. writelog("SpawnManager__assign_status_slot")
  171. writelog("peer_id: "..tostring(peer_id).." l_p_id: "..tostring(local_player_id).." with profile_index "..tostring(profile_index))
  172.  
  173. local NUM_PLAYERS = 6
  174.  
  175. local latest_slot = nil
  176. local latest_time = -math.huge
  177. local first_empty, slot_index = nil
  178. local found_slot = false
  179.  
  180. -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key ~= "inn" and SpawnManager.in_inn then
  181. -- writelog("OUT OF INN")
  182. -- SpawnManager.in_inn = false
  183. -- SpawnManager.next_slot_index = 0
  184. -- end
  185. -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key == "inn" and not SpawnManager.in_inn then
  186. -- writelog("INTO INNw")
  187. -- SpawnManager.in_inn = true
  188. -- SpawnManager.next_slot_index = 0
  189. -- end
  190.  
  191. writelog("---------------CURRENT STATUS------------------")
  192. for i = 1, NUM_PLAYERS, 1 do
  193. local status = self._player_statuses[i]
  194.  
  195. writelog("STATUS: "..tostring(status.peer_id).." "..tostring(status.local_player_id))
  196. end
  197. writelog("------------------------------------")
  198.  
  199. for i = 1, NUM_PLAYERS, 1 do
  200. local status = self._player_statuses[i]
  201.  
  202. -- writelog("STATUS: "..tostring(status.peer_id).." "..tostring(status.local_player_id))
  203.  
  204. if status.peer_id == peer_id and status.local_player_id == local_player_id then
  205. status.profile_index = profile_index
  206. -- status.profile_index = 3
  207. found_slot = true
  208. writelog("--------------FOUND SLOT------------")
  209. -- slot_index = i
  210.  
  211. -- self._take_status_slot(self, SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
  212.  
  213. -- status.profile_index = SpawnManager.assigned_slots[peer_id..local_player_id]
  214. slot_index = SpawnManager.assigned_slots[peer_id..local_player_id]
  215.  
  216. -- self._take_status_slot(self,SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
  217.  
  218. -- SpawnManager:_take_status_slot(SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
  219.  
  220. break
  221. end
  222. end
  223.  
  224. if not found_slot then
  225. SpawnManager.next_slot_index = SpawnManager.next_slot_index+1
  226. if SpawnManager.next_slot_index < NUM_PLAYERS+1 then
  227. writelog("SpawnManager__assign_status_slot: assigning slot_index "..SpawnManager.next_slot_index.." to "..peer_id..local_player_id)
  228. self._take_status_slot(self,SpawnManager.next_slot_index, peer_id, local_player_id, profile_index)
  229. -- self._take_status_slot(self,SpawnManager.next_slot_index, peer_id, local_player_id, 3)
  230. slot_index = SpawnManager.next_slot_index
  231. SpawnManager.assigned_slots[peer_id..local_player_id] = slot_index
  232. end
  233. end
  234.  
  235. writelog("---------------NEW STATUS------------------")
  236. for i = 1, NUM_PLAYERS, 1 do
  237. local status = self._player_statuses[i]
  238.  
  239. writelog("STATUS: "..tostring(status.peer_id).." "..tostring(status.local_player_id))
  240. end
  241. writelog("------------------------------------")
  242.  
  243. -- if not found_slot then
  244. -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
  245. -- slot_index = SpawnManager.next_slot_index+1
  246. -- -- for i = 1, NUM_PLAYERS, 1 do
  247. -- -- local status = self._player_statuses[i]
  248. -- -- local last_update = status.last_update
  249. -- --
  250. -- -- if status.profile_index == profile_index then
  251. -- -- -- fassert(not status.peer_id, "Trying to take slot for profile already in use. old player: %q:%q, new player: %q:%q", status.peer_id, status.local_player_id, peer_id, local_player_id)
  252. -- -- -- self._take_status_slot(self, i, peer_id, local_player_id, profile_index)
  253. -- -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
  254. -- --
  255. -- -- slot_index = i
  256. -- -- found_slot = true
  257. -- --
  258. -- -- break
  259. -- -- elseif not first_empty and not status.profile_index then
  260. -- -- first_empty = i
  261. -- -- end
  262. -- --
  263. -- -- if not status.peer_id and latest_time < last_update then
  264. -- -- latest_time = last_update
  265. -- -- latest_slot = i
  266. -- -- end
  267. -- -- end
  268. -- end
  269. --
  270. -- if not found_slot then
  271. -- if latest_slot then
  272. -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
  273. --
  274. -- slot_index = SpawnManager.next_slot_index+1
  275. -- elseif first_empty then
  276. -- self._take_status_slot(self, SpawnManager.next_slot_index+1, peer_id, local_player_id, profile_index)
  277. --
  278. -- slot_index = SpawnManager.next_slot_index+1
  279. -- end
  280. -- end
  281. --
  282. -- if not slot_index then
  283. -- table.dump(self._player_statuses, "", 3)
  284. -- end
  285.  
  286. assert(slot_index, "Did not find status slot index.")
  287.  
  288. local cutscene_system = Managers.state.entity:system("cutscene_system")
  289. local first_spawn = not cutscene_system.has_intro_cutscene_finished_playing(cutscene_system)
  290.  
  291. return first_spawn, slot_index
  292.  
  293. end
  294. end
  295.  
  296. -- if not MatchmakingManager_update then
  297. -- MatchmakingManager_update = MatchmakingManager.update
  298. -- MatchmakingManager.update = function (self, dt, t)
  299. -- -- Call orginal function
  300. -- MatchmakingManager_update(self, dt, t)
  301. --
  302. -- -- Call modded function
  303. -- -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key ~= "inn" and SpawnManager.in_inn then
  304. -- -- writelog("OUT OF INN")
  305. -- -- SpawnManager.in_inn = false
  306. -- -- SpawnManager.next_slot_index = 0
  307. -- -- end
  308. -- -- if Managers.state.game_mode ~= nil and Managers.state.game_mode._game_mode_key == "inn" and not SpawnManager.in_inn then
  309. -- -- writelog("INTO INNw")
  310. -- -- SpawnManager.in_inn = true
  311. -- -- SpawnManager.next_slot_index = 0
  312. -- -- end
  313. --
  314. -- return
  315. -- end
  316. -- end
  317.  
  318. -- if not SpawnManager__take_status_slot then
  319. -- SpawnManager__take_status_slot = SpawnManager._take_status_slot
  320. -- SpawnManager._take_status_slot = function (self, i, peer_id, local_player_id, profile_index)
  321. --
  322. -- -- if SpawnManager._player_statuses == nil then
  323. -- -- SpawnManager._player_statuses = SpawnManager._default_player_statuses(self)
  324. -- -- end
  325. -- --
  326. -- local status = self._player_statuses[i]
  327. -- --
  328. -- -- if status == nil then
  329. -- -- local settings = Managers.state.difficulty:get_difficulty_settings()
  330. -- --
  331. -- -- local CONSUMABLE_SLOTS = {
  332. -- -- "slot_healthkit",
  333. -- -- "slot_potion",
  334. -- -- "slot_grenade"
  335. -- -- }
  336. -- --
  337. -- -- status = {
  338. -- -- damage = 0,
  339. -- -- spawn_state = "not_spawned",
  340. -- -- health_state = "alive",
  341. -- -- last_update = -math.huge,
  342. -- -- consumables = {},
  343. -- -- ammo = {
  344. -- -- slot_ranged = 1,
  345. -- -- slot_melee = 1
  346. -- -- }
  347. -- -- }
  348. -- -- local consumables = status.consumables
  349. -- --
  350. -- -- for _, slot_name in ipairs(CONSUMABLE_SLOTS) do
  351. -- -- consumables[slot_name] = settings[slot_name]
  352. -- -- end
  353. -- -- end
  354. --
  355. -- -- local old_peer_id = status.peer_id
  356. -- -- local old_local_player_id = status.local_player_id
  357. --
  358. -- -- fassert(not old_peer_id and not old_local_player_id, "Trying to take slot that already belongs to %q %q", old_peer_id, old_local_player_id)
  359. --
  360. -- status.peer_id = peer_id
  361. -- status.local_player_id = local_player_id
  362. -- status.profile_index = profile_index
  363. -- status.last_update = 0
  364. --
  365. -- if status.health_state == "disabled" then
  366. -- status.health_state = "knocked_down"
  367. -- status.damage = 0
  368. -- end
  369. --
  370. -- -- SpawnManager._player_statuses[i] = status
  371. --
  372. -- return
  373. -- end
  374. -- end
  375.  
  376. function writelog(line)
  377. local out = assert(io.open("profileSyncLog.txt", "a+"))
  378. -- EchoConsole(tostring(speaker)..": "..tostring(text))
  379. local now = os.date("*t")
  380.  
  381. out:write(tostring(now["hour"])..":"..tostring(now["min"]).." "..tostring(line).."\n")
  382. out:close()
  383. end
  384.  
  385.  
  386. if not SpawnManager__update_bot_spawns then
  387. SpawnManager__update_bot_spawns = SpawnManager._update_bot_spawns
  388. SpawnManager._update_bot_spawns = function (self, dt, t)
  389.  
  390. -- writelog("-- calling SpawnManager._update_bot_spawns")
  391.  
  392. local NUM_PLAYERS = 6
  393.  
  394. local player_manager = Managers.player
  395. local profile_synchronizer = self._profile_synchronizer
  396. local available_profile_order = self._available_profile_order
  397. local available_profiles = self._available_profiles
  398. local profile_release_list = self._bot_profile_release_list
  399. local delta, humans, bots = self._update_available_profiles(self, profile_synchronizer, available_profile_order, available_profiles)
  400.  
  401. for local_player_id, bot_player in pairs(self._bot_players) do
  402. local profile_index = bot_player.profile_index
  403.  
  404. if not available_profiles[profile_index] then
  405. local peer_id = bot_player.network_id(bot_player)
  406. local local_player_id = bot_player.local_player_id(bot_player)
  407. profile_release_list[profile_index] = true
  408. local bot_unit = bot_player.player_unit
  409.  
  410. if bot_unit then
  411. bot_player.despawn(bot_player)
  412. end
  413.  
  414. local status_slot_index = bot_player.status_slot_index
  415.  
  416. self._free_status_slot(self, status_slot_index)
  417. player_manager.remove_player(player_manager, peer_id, local_player_id)
  418.  
  419. self._bot_players[local_player_id] = nil
  420. end
  421. end
  422.  
  423. local allowed_bots = math.min(NUM_PLAYERS - humans, (not script_data.ai_bots_disabled or 0) and (script_data.cap_num_bots or NUM_PLAYERS))
  424. local bot_delta = allowed_bots - bots
  425. local local_peer_id = Network.peer_id()
  426.  
  427. bot_delta = SpawnManager.num_bots_ - #Managers.player:bots()
  428. -- bot_delta = 2
  429. -- bot_delta = 3 - #self._bot_players
  430. -- writelog("num bots"..#self._bot_players)
  431. -- bot_delta = 3 - #self._bot_players
  432.  
  433. if 0 < bot_delta then
  434.  
  435. writelog("SPAWNING BOT")
  436.  
  437. local i = 1
  438. local bots_spawned = 0
  439.  
  440. while bots_spawned < bot_delta do
  441. -- local profile_index = available_profile_order[i]
  442. local profile_index = 3
  443.  
  444. -- fassert(profile_index, "Tried to add more bots than there are profiles available")
  445.  
  446. -- local owner_type = profile_synchronizer.owner_type(profile_synchronizer, profile_index)
  447. --
  448. -- if owner_type == "available" then
  449. local local_player_id = player_manager.next_available_local_player_id(player_manager, local_peer_id)
  450. local bot_player = player_manager.add_bot_player(player_manager, SPProfiles[profile_index].display_name, local_peer_id, "default", profile_index, local_player_id)
  451. local is_initial_spawn, status_slot_index = self._assign_status_slot(self, local_peer_id, local_player_id, profile_index)
  452. bot_player.status_slot_index = status_slot_index
  453.  
  454. profile_synchronizer.set_profile_peer_id(profile_synchronizer, profile_index, local_peer_id, local_player_id)
  455. bot_player.create_game_object(bot_player)
  456.  
  457. self._bot_players[local_player_id] = bot_player
  458. self._spawn_list[#self._spawn_list + 1] = bot_player
  459. bots_spawned = bots_spawned + 1
  460. -- end
  461.  
  462. i = i + 1
  463. end
  464. elseif bot_delta < 0 then
  465.  
  466. writelog("NOT SPAWNING BOT, bot_delta < 0")
  467.  
  468. local bots_despawned = 0
  469. local i = 1
  470.  
  471. while bots_despawned < -bot_delta do
  472. local profile_index = available_profile_order[i]
  473.  
  474. fassert(profile_index, "Tried to remove more bots than there are profiles belonging to bots")
  475.  
  476. -- local owner_type = profile_synchronizer.owner_type(profile_synchronizer, profile_index)
  477. --
  478. -- if owner_type == "bot" then
  479. local bot_player, bot_local_player_id = nil
  480.  
  481. for local_player_id, player in pairs(self._bot_players) do
  482. if player.profile_index == profile_index then
  483. bot_player = player
  484. bot_local_player_id = local_player_id
  485.  
  486. break
  487. end
  488. end
  489.  
  490. fassert(bot_player, "Did not find bot player with profile_index profile_index %i", profile_index)
  491.  
  492. profile_release_list[profile_index] = true
  493. local bot_unit = bot_player.player_unit
  494.  
  495. if bot_unit then
  496. bot_player.despawn(bot_player)
  497. end
  498.  
  499. local status_slot_index = bot_player.status_slot_index
  500.  
  501. self._free_status_slot(self, status_slot_index)
  502. player_manager.remove_player(player_manager, local_peer_id, bot_local_player_id)
  503.  
  504. self._bot_players[bot_local_player_id] = nil
  505. bots_despawned = bots_despawned + 1
  506. -- end
  507.  
  508. i = i + 1
  509. end
  510. end
  511.  
  512. local statuses = self._player_statuses
  513.  
  514. if self._network_server:has_all_peers_loaded_packages() then
  515. for _, bot_player in ipairs(self._spawn_list) do
  516. local bot_local_player_id = bot_player.local_player_id(bot_player)
  517. local bot_peer_id = bot_player.network_id(bot_player)
  518.  
  519. if player_manager.player(player_manager, bot_peer_id, bot_local_player_id) == bot_player then
  520. local status_slot_index = bot_player.status_slot_index
  521. local status = statuses[status_slot_index]
  522.  
  523. local position
  524. local rotation
  525. if status.position then
  526. position = status.position:unbox()
  527. rotation = status.rotation:unbox()
  528. else
  529.  
  530. local settings = Managers.state.difficulty:get_difficulty_settings()
  531.  
  532. local status1 = {
  533. damage = 0,
  534. spawn_state = "not_spawned",
  535. health_state = "alive",
  536. last_update = -math.huge,
  537. consumables = {},
  538. ammo = {
  539. slot_ranged = 1,
  540. slot_melee = 1
  541. }
  542. }
  543. local consumables = status1.consumables
  544.  
  545. local CONSUMABLE_SLOTS = {
  546. "slot_healthkit",
  547. "slot_potion",
  548. "slot_grenade"
  549. }
  550.  
  551. for _, slot_name in ipairs(CONSUMABLE_SLOTS) do
  552. consumables[slot_name] = settings[slot_name]
  553. end
  554.  
  555. statuses[status_slot_index] = status1
  556.  
  557. position = statuses[1].position:unbox()
  558. rotation = statuses[1].rotation:unbox()
  559. statuses[status_slot_index].position = statuses[1].position
  560. statuses[status_slot_index].rotation = statuses[1].rotation
  561.  
  562. -- statuses[status_slot_index].health_state = "respawning"
  563. -- statuses[status_slot_index].respawn_unit = self.respawn_handler:get_respawn_unit()
  564. -- statuses[status_slot_index].damage = Managers.state.difficulty:get_difficulty_settings().respawn.damage
  565.  
  566. end
  567. local is_initial_spawn = false
  568.  
  569. if status.health_state ~= "dead" and status.health_state ~= "respawn" and status.health_state ~= "respawning" then
  570. local consumables = status.consumables
  571. local ammo = status.ammo
  572.  
  573. local CONSUMABLE_SLOTS = {
  574. "slot_healthkit",
  575. "slot_potion",
  576. "slot_grenade"
  577. }
  578.  
  579. bot_player.spawn(bot_player, position, rotation, is_initial_spawn, ammo.slot_melee, ammo.slot_ranged, consumables[CONSUMABLE_SLOTS[1]], consumables[CONSUMABLE_SLOTS[2]], consumables[CONSUMABLE_SLOTS[3]])
  580. end
  581.  
  582. status.spawn_state = "spawned"
  583. end
  584. end
  585.  
  586. table.clear(self._spawn_list)
  587. end
  588.  
  589. return
  590. end
  591. end
  592.  
  593. ------------------UNUSED ALREADY DECLARED ABOVE-----------------------
  594. local inventory_map_to_network_array = nil
  595. local EMPTY_TABLE = {}
  596. local NO_PEER = "0"
  597. local NO_LOCAL_PLAYER_ID = 0
  598. local IS_LOCAL_CALL = "is_local_call"
  599. ----------------UNUSED ALREADY DECLARED ABOVE-----------------------
  600. -- if not ProfileSynchronizer_set_profile_peer_id then ------------------UNUSED ALREADY DECLARED ABOVE-----------------------
  601. -- ProfileSynchronizer_set_profile_peer_id = ProfileSynchronizer.set_profile_peer_id
  602. -- ProfileSynchronizer.set_profile_peer_id = function (self, profile_index, peer_id, local_player_id)
  603. -- assert(self._is_server)
  604. -- assert(profile_index)
  605. -- assert((peer_id and local_player_id) or (not peer_id and not local_player_id), "Missing local_player_id despite assigning to peer.")
  606. --
  607. -- local new_profile_index, previous_profile_index = nil
  608. --
  609. -- writelog("-- entered set_profile_peer_id --")
  610. --
  611. --
  612. -- if peer_id then
  613. --
  614. -- writelog("-- there is peer_id")
  615. --
  616. -- new_profile_index = profile_index
  617. -- previous_profile_index = self.profile_by_peer(self, peer_id, local_player_id)
  618. --
  619. -- profile_printf("[ProfileSynchronizer] set_profile_peer_id from profile %s to %s for peer id %s:%i", tostring(previous_profile_index), tostring(new_profile_index), peer_id, local_player_id)
  620. -- else
  621. --
  622. -- writelog("there ISNT peer_id")
  623. --
  624. -- new_profile_index = nil
  625. -- previous_profile_index = profile_index
  626. -- local previous_owner = self._profile_owners[previous_profile_index]
  627. -- local peer_table = self._loaded_peers[previous_owner.peer_id]
  628. --
  629. -- if peer_table then
  630. -- peer_table[previous_owner.local_player_id] = nil
  631. --
  632. -- if table.is_empty(peer_table) then
  633. -- self._loaded_peers[previous_owner.peer_id] = nil
  634. -- end
  635. --
  636. -- profile_printf("[ProfileSynchronizer] set_profile_peer_id %s is no longer owned by %s:%i", tostring(previous_profile_index), (previous_owner and previous_owner.peer_id) or "<none>", (previous_owner and previous_owner.local_player_id) or 0)
  637. -- end
  638. -- end
  639. --
  640. -- if previous_profile_index then
  641. -- local sender = nil
  642. --
  643. -- --
  644. -- -- previous_profile_index = 3
  645. -- self._profile_select_inventory(self, previous_profile_index, EMPTY_TABLE, EMPTY_TABLE, sender, local_player_id, NO_CLIENT_SYNC_ID)
  646. -- end
  647. --
  648. -- transmit_peer_id = peer_id or NO_PEER
  649. -- local transmit_local_player_id = local_player_id or NO_LOCAL_PLAYER_ID
  650. --
  651. -- self.rpc_server_mark_profile_used(self, IS_LOCAL_CALL, transmit_peer_id, transmit_local_player_id, previous_profile_index or 0, new_profile_index or 0)
  652. -- self._send_rpc_lobby_clients(self, "rpc_server_mark_profile_used", transmit_peer_id, transmit_local_player_id, previous_profile_index or 0, new_profile_index or 0)
  653. --
  654. -- self._all_synced = false
  655. --
  656. -- return
  657. -- end
  658. -- end
  659.  
  660.  
  661. if not InventoryPackageSynchronizer_set_inventory_list then
  662. InventoryPackageSynchronizer_set_inventory_list = InventoryPackageSynchronizer.set_inventory_list
  663. InventoryPackageSynchronizer.set_inventory_list = function (self, profile_index, inventory_list, inventory_list_first_person)
  664.  
  665. -- profile_index = 3
  666.  
  667. writelog("-- entered set_inventory_list --")
  668.  
  669. local profile_data = self.packages_by_profile[profile_index]
  670.  
  671. if profile_data == nil then
  672. writelog("proflie_data is nil")
  673. profile_data = self.packages_by_profile[3]
  674. else
  675. writelog("proflie_data is valid for ".. profile_index)
  676. end
  677.  
  678. local package_map = profile_data.package_map
  679.  
  680. -- table.clear(package_map)
  681.  
  682. local package_map_first_person = profile_data.package_map_first_person
  683.  
  684. -- table.clear(package_map_first_person)
  685.  
  686. for _, package_name in ipairs(inventory_list) do
  687. package_map[package_name] = true
  688. end
  689.  
  690. for _, package_name in ipairs(inventory_list_first_person) do
  691. package_map_first_person[package_name] = true
  692. end
  693.  
  694. return
  695. end
  696. end
  697.  
  698.  
  699. if not PlayerBot_spawn then
  700. PlayerBot_spawn = PlayerBot.spawn
  701. PlayerBot.spawn = function (self, position, rotation, is_initial_spawn, ammo_melee, ammo_ranged, healthkit, potion, grenade)
  702.  
  703. writelog("-- entered PlayerBot.spawn --")
  704.  
  705. local profile_index = self.profile_index
  706. profile_index = 3
  707. local profile = SPProfiles[profile_index]
  708. if profile == nil then
  709. profile = SPProfiles[2]
  710. end
  711. if profile == nil then
  712. profile = SPProfiles[4]
  713. end
  714. profile = {
  715. character_vo = "dwarf_ranger",
  716. default_wielded_slot = "slot_melee",
  717. display_name = "dwarf_ranger",
  718. ingame_short_display_name = "dwarf_ranger_short",
  719. character_name = "lorebook_dwarf_ranger",
  720. ingame_display_name = "inventory_name_dwarf_ranger",
  721. unit_name = "dwarf_ranger",
  722. sound_character = "dwarf_ranger",
  723. equipment_slots = {
  724. slot_melee = ItemMasterList.dr_2h_hammer_0001,
  725. slot_ranged = ItemMasterList.dr_crossbow_0001,
  726. slot_hat = ItemMasterList.dr_helmet_0001,
  727. slot_healthkit = ItemMasterList.healthkit_first_aid_kit_01
  728. },
  729. room_profile = RoomProfiles.dwarf_ranger,
  730. base_units = {
  731. first_person_bot = "units/beings/player/first_person_base/chr_first_person_bot_base",
  732. third_person_bot = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
  733. third_person = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
  734. first_person = "units/beings/player/first_person_base/chr_first_person_base",
  735. third_person_husk = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_husk_base"
  736. },
  737. first_person_attachment = FirstPersonAttachments.dwarf_ranger,
  738. first_person_heights = {
  739. knocked_down = 0.7,
  740. crouch = 0.7,
  741. stand = 3.3
  742. },
  743. mood_settings = {}
  744. }
  745.  
  746. -- fassert(profile, "[SpawnManager] Trying to spawn with profile %q that doesn't exist in %q.", profile_index, "SPProfiles")
  747.  
  748. local nav_world = Managers.state.entity:system("ai_system"):nav_world()
  749. local difficulty_manager = Managers.state.difficulty
  750. local difficulty_settings = difficulty_manager.get_difficulty_settings(difficulty_manager)
  751. local player_health = difficulty_settings.max_hp
  752. local player_wounds = difficulty_settings.wounds
  753.  
  754. if script_data.player_invincible then
  755. player_health = -1
  756. end
  757.  
  758. local character_state_class_list = {
  759. PlayerCharacterStateDead,
  760. PlayerCharacterStateInteracting,
  761. PlayerCharacterStateJumping,
  762. PlayerCharacterStateClimbingLadder,
  763. PlayerCharacterStateLeavingLadderTop,
  764. PlayerCharacterStateEnterLadderTop,
  765. PlayerCharacterStateFalling,
  766. PlayerCharacterStateKnockedDown,
  767. PlayerCharacterStatePouncedDown,
  768. PlayerCharacterStateStanding,
  769. PlayerCharacterStateWalking,
  770. PlayerCharacterStateDodging,
  771. PlayerCharacterStateLedgeHanging,
  772. PlayerCharacterStateLeaveLedgeHangingPullUp,
  773. PlayerCharacterStateLeaveLedgeHangingFalling,
  774. PlayerCharacterStateCatapulted,
  775. PlayerCharacterStateStunned,
  776. PlayerCharacterStateUsingTransport,
  777. PlayerCharacterStateGrabbedByPackMaster,
  778. PlayerCharacterStateWaitingForAssistedRespawn,
  779. PLayerCharacterStateOverchargeExploding
  780. }
  781. local initial_inventory = self._get_initial_inventory(self, healthkit, potion, grenade)
  782. local extension_init_data = {
  783. ai_system = {
  784. player = self,
  785. bot_profile = self.bot_profile,
  786. nav_world = nav_world
  787. },
  788. input_system = {
  789. player = self
  790. },
  791. character_state_machine_system = {
  792. start_state = "standing",
  793. nav_world = nav_world,
  794. character_state_class_list = character_state_class_list,
  795. player = self
  796. },
  797. health_system = {
  798. health = player_health,
  799. player = self
  800. },
  801. status_system = {
  802. wounds = player_wounds,
  803. profile_id = profile_index,
  804. player = self
  805. },
  806. hit_reaction_system = {
  807. is_husk = false,
  808. hit_reaction_template = "player"
  809. },
  810. death_system = {
  811. death_reaction_template = "player",
  812. is_husk = false
  813. },
  814. inventory_system = {
  815. profile = profile,
  816. initial_inventory = initial_inventory,
  817. player = self,
  818. ammo_percent = {
  819. slot_melee = ammo_melee,
  820. slot_ranged = ammo_ranged
  821. }
  822. },
  823. locomotion_system = {
  824. player = self
  825. },
  826. camera_system = {
  827. player = self
  828. },
  829. dialogue_context_system = {
  830. profile = profile
  831. },
  832. dialogue_system = {
  833. faction = "player",
  834. wwise_voice_switch_group = "character",
  835. profile = profile,
  836. wwise_voice_switch_value = profile.character_vo
  837. },
  838. first_person_system = {
  839. profile = profile
  840. },
  841. ai_navigation_system = {
  842. nav_world = nav_world
  843. },
  844. aim_system = {
  845. is_husk = false,
  846. template = "player"
  847. },
  848. attachment_system = {
  849. profile = profile,
  850. player = self
  851. },
  852. buff_system = {
  853. is_husk = false
  854. },
  855. statistics_system = {
  856. template = "player",
  857. statistics_id = self.peer_id
  858. },
  859. ai_slot_system = {
  860. profile_index = profile_index
  861. }
  862. }
  863. local unit_template_name = "player_bot_unit"
  864. local unit_name = profile.base_units.third_person_bot
  865. local spawn_data = {
  866. unit_template_name = unit_template_name,
  867. unit_name = unit_name,
  868. extension_init_data = extension_init_data
  869. }
  870. local unit = Managers.state.spawn:spawn_unit(spawn_data, position, rotation)
  871.  
  872. ScriptUnit.extension(unit, "attachment_system"):show_attachments(true)
  873. Unit.set_data(unit, "sound_character", profile.sound_character)
  874. Unit.create_actor(unit, "bot_collision", false)
  875.  
  876. if GameSettingsDevelopment.use_telemetry and self.is_server then
  877. self._add_spawn_telemetry(self, "host")
  878. end
  879.  
  880. return unit
  881. end
  882. end
  883.  
  884. --
  885. -- if not BulldozerPlayer_spawn then
  886. -- BulldozerPlayer_spawn = BulldozerPlayer.spawn
  887. -- BulldozerPlayer.spawn = function (self, optional_position, optional_rotation, is_initial_spawn, ammo_melee, ammo_ranged, healthkit, potion, grenade)
  888. --
  889. -- writelog("-- entered PBulldozerPlayer.spawn --")
  890. --
  891. -- local profile_index = self.profile_index
  892. -- local profile = SPProfiles[profile_index]
  893. -- -- profile_index = 3
  894. -- -- local profile = SPProfiles[3]
  895. --
  896. -- -- profile = {
  897. -- -- character_vo = "dwarf_ranger",
  898. -- -- default_wielded_slot = "slot_melee",
  899. -- -- display_name = "dwarf_ranger",
  900. -- -- ingame_short_display_name = "dwarf_ranger_short",
  901. -- -- character_name = "lorebook_dwarf_ranger",
  902. -- -- ingame_display_name = "inventory_name_dwarf_ranger",
  903. -- -- unit_name = "dwarf_ranger",
  904. -- -- sound_character = "dwarf_ranger",
  905. -- -- equipment_slots = {
  906. -- -- slot_melee = ItemMasterList.dr_2h_hammer_0001,
  907. -- -- slot_ranged = ItemMasterList.dr_crossbow_0001,
  908. -- -- slot_hat = ItemMasterList.dr_helmet_0001,
  909. -- -- slot_healthkit = ItemMasterList.healthkit_first_aid_kit_01
  910. -- -- },
  911. -- -- room_profile = RoomProfiles.dwarf_ranger,
  912. -- -- base_units = {
  913. -- -- first_person_bot = "units/beings/player/first_person_base/chr_first_person_bot_base",
  914. -- -- third_person_bot = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
  915. -- -- third_person = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_base",
  916. -- -- first_person = "units/beings/player/first_person_base/chr_first_person_base",
  917. -- -- third_person_husk = "units/beings/player/dwarf_ranger/third_person_base/chr_third_person_husk_base"
  918. -- -- },
  919. -- -- first_person_attachment = FirstPersonAttachments.dwarf_ranger,
  920. -- -- first_person_heights = {
  921. -- -- knocked_down = 0.7,
  922. -- -- crouch = 0.7,
  923. -- -- stand = 1.3
  924. -- -- },
  925. -- -- mood_settings = {}
  926. -- -- }
  927. --
  928. -- writelog("spawning with profile_index "..tostring(profile_index))
  929. -- fassert(profile, "[SpawnManager] Trying to spawn with profile %q that doesn't exist in %q.", profile_index, "SPProfiles")
  930. -- print(is_initial_spawn, ammo_melee, ammo_ranged, healthkit, potion, grenade)
  931. --
  932. -- local nav_world = Managers.state.entity:system("ai_system"):nav_world()
  933. -- local difficulty_manager = Managers.state.difficulty
  934. -- local difficulty_settings = difficulty_manager.get_difficulty_settings(difficulty_manager)
  935. -- local player_health = difficulty_settings.max_hp
  936. -- local player_wounds = difficulty_settings.wounds
  937. --
  938. -- if script_data.player_invincible then
  939. -- player_health = -1
  940. -- end
  941. --
  942. -- if self.spawn_position then
  943. -- optional_position = self.spawn_position:unbox()
  944. -- self.spawn_position = nil
  945. -- end
  946. --
  947. -- if self.spawn_rotation then
  948. -- optional_rotation = self.spawn_rotation:unbox()
  949. -- self.spawn_rotation = nil
  950. -- end
  951. --
  952. -- local character_state_class_list = {
  953. -- PlayerCharacterStateDead,
  954. -- PlayerCharacterStateInteracting,
  955. -- PlayerCharacterStateInspecting,
  956. -- PlayerCharacterStateJumping,
  957. -- PlayerCharacterStateClimbingLadder,
  958. -- PlayerCharacterStateLeavingLadderTop,
  959. -- PlayerCharacterStateEnterLadderTop,
  960. -- PlayerCharacterStateFalling,
  961. -- PlayerCharacterStateKnockedDown,
  962. -- PlayerCharacterStatePouncedDown,
  963. -- PlayerCharacterStateStanding,
  964. -- PlayerCharacterStateWalking,
  965. -- PlayerCharacterStateDodging,
  966. -- PlayerCharacterStateLedgeHanging,
  967. -- PlayerCharacterStateLeaveLedgeHangingPullUp,
  968. -- PlayerCharacterStateLeaveLedgeHangingFalling,
  969. -- PlayerCharacterStateCatapulted,
  970. -- PlayerCharacterStateStunned,
  971. -- PlayerCharacterStateHammerLeap,
  972. -- PlayerCharacterStateUsingTransport,
  973. -- PlayerCharacterStateGrabbedByPackMaster,
  974. -- PlayerCharacterStateWaitingForAssistedRespawn,
  975. -- PLayerCharacterStateOverchargeExploding
  976. -- }
  977. -- local initial_inventory = self._get_initial_inventory(self, healthkit, potion, grenade)
  978. -- local extension_init_data = {
  979. -- input_system = {
  980. -- player = self
  981. -- },
  982. -- character_state_machine_system = {
  983. -- start_state = "standing",
  984. -- character_state_class_list = character_state_class_list,
  985. -- player = self,
  986. -- nav_world = nav_world
  987. -- },
  988. -- health_system = {
  989. -- health = player_health,
  990. -- player = self
  991. -- },
  992. -- status_system = {
  993. -- wounds = player_wounds,
  994. -- profile_id = profile_index,
  995. -- player = self
  996. -- },
  997. -- hit_reaction_system = {
  998. -- is_husk = false,
  999. -- hit_reaction_template = "player"
  1000. -- },
  1001. -- death_system = {
  1002. -- death_reaction_template = "player",
  1003. -- is_husk = false
  1004. -- },
  1005. -- inventory_system = {
  1006. -- profile = profile,
  1007. -- initial_inventory = initial_inventory,
  1008. -- player = self,
  1009. -- ammo_percent = {
  1010. -- slot_melee = ammo_melee,
  1011. -- slot_ranged = ammo_ranged
  1012. -- }
  1013. -- },
  1014. -- attachment_system = {
  1015. -- profile = profile,
  1016. -- player = self
  1017. -- },
  1018. -- locomotion_system = {
  1019. -- player = self
  1020. -- },
  1021. -- camera_system = {
  1022. -- player = self
  1023. -- },
  1024. -- first_person_system = {
  1025. -- profile = profile
  1026. -- },
  1027. -- dialogue_context_system = {
  1028. -- profile = profile
  1029. -- },
  1030. -- dialogue_system = {
  1031. -- local_player = true,
  1032. -- faction = "player",
  1033. -- wwise_voice_switch_group = "character",
  1034. -- profile = profile,
  1035. -- wwise_voice_switch_value = profile.character_vo
  1036. -- },
  1037. -- whereabouts_system = {
  1038. -- nav_world = nav_world
  1039. -- },
  1040. -- aim_system = {
  1041. -- is_husk = false,
  1042. -- template = "player"
  1043. -- },
  1044. -- buff_system = {
  1045. -- is_husk = false
  1046. -- },
  1047. -- statistics_system = {
  1048. -- template = "player",
  1049. -- statistics_id = self.telemetry_id(self)
  1050. -- },
  1051. -- ai_slot_system = {
  1052. -- profile_index = profile_index
  1053. -- }
  1054. -- }
  1055. -- local unit_template_name = nil
  1056. -- local unit_name = profile.base_units.third_person
  1057. -- local spawn_data = {
  1058. -- unit_template_name = unit_template_name,
  1059. -- unit_name = unit_name,
  1060. -- extension_init_data = extension_init_data
  1061. -- }
  1062. -- local spawn_manager = Managers.state.spawn
  1063. -- local unit = spawn_manager.spawn_unit(spawn_manager, spawn_data, optional_position, optional_rotation)
  1064. -- local player_manager = Managers.player
  1065. --
  1066. -- Unit.set_data(unit, "unit_name", profile.unit_name)
  1067. --
  1068. -- local world = spawn_manager.world
  1069. --
  1070. -- LevelHelper:set_flow_parameter(world, "local_player_profile_name", profile.display_name)
  1071. -- Unit.set_data(unit, "sound_character", profile.sound_character)
  1072. -- Unit.create_actor(unit, "human_collision", false)
  1073. --
  1074. -- local is_player_unit = true
  1075. --
  1076. -- player_manager.assign_unit_ownership(player_manager, unit, self, is_player_unit)
  1077. -- LevelHelper:flow_event(world, "local_player_spawned")
  1078. --
  1079. -- if is_initial_spawn then
  1080. -- LevelHelper:flow_event(world, "level_start_local_player_spawned")
  1081. -- end
  1082. --
  1083. -- Managers.state.event:trigger("level_start_local_player_spawned")
  1084. --
  1085. -- if GameSettingsDevelopment.use_telemetry then
  1086. -- local peer_type = (self.is_server and "host") or "client"
  1087. --
  1088. -- self._add_spawn_telemetry(self, peer_type)
  1089. -- end
  1090. --
  1091. -- return unit
  1092. -- end
  1093. -- end
  1094.  
  1095. -- if not World_spawn_unit_ then
  1096. -- World_spawn_unit_ = World.spawn_unit
  1097. -- World.spawn_unit = function (world, unit_name, pos, rot)
  1098. --
  1099. -- writelog("-- entered World.spawn_unit --")
  1100. -- writelog("spawning "..tostring(unit_name))
  1101. -- local unit = World_spawn_unit(world, unit_name, pos, rot)
  1102. -- return unit
  1103. -- -- return World_spawn_unit_(world, unit_name, pos, rot)
  1104. -- end
  1105. -- end
  1106.  
  1107. if not SpawnManager__default_player_statuses then
  1108. SpawnManager__default_player_statuses = SpawnManager._default_player_statuses
  1109. SpawnManager._default_player_statuses = function (self)
  1110. local settings = Managers.state.difficulty:get_difficulty_settings()
  1111. local statuses = {}
  1112.  
  1113. local NUM_PLAYERS = 6
  1114.  
  1115. for i = 1, NUM_PLAYERS, 1 do
  1116. local status = {
  1117. damage = 0,
  1118. spawn_state = "not_spawned",
  1119. health_state = "alive",
  1120. last_update = -math.huge,
  1121. consumables = {},
  1122. ammo = {
  1123. slot_ranged = 1,
  1124. slot_melee = 1
  1125. }
  1126. }
  1127. local consumables = status.consumables
  1128.  
  1129. local CONSUMABLE_SLOTS = {
  1130. "slot_healthkit",
  1131. "slot_potion",
  1132. "slot_grenade"
  1133. }
  1134.  
  1135. for _, slot_name in ipairs(CONSUMABLE_SLOTS) do
  1136. consumables[slot_name] = settings[slot_name]
  1137. end
  1138.  
  1139. statuses[i] = status
  1140. end
  1141.  
  1142. return statuses
  1143. end
  1144. end
  1145.  
  1146. if not SpawnManager__force_update_spawn_positions then
  1147. SpawnManager__force_update_spawn_positions = SpawnManager._force_update_spawn_positions
  1148. SpawnManager._force_update_spawn_positions = function (self, safe_position, safe_rotation)
  1149.  
  1150. local NUM_PLAYERS = 6
  1151.  
  1152. return SpawnManager__force_update_spawn_positions(self, safe_position, safe_rotation)
  1153. end
  1154. end
  1155.  
  1156. if not SpawnManager__update_respawns then
  1157. SpawnManager__update_respawns = SpawnManager._update_respawns
  1158. SpawnManager._update_respawns = function (self, dt, t)
  1159.  
  1160. local NUM_PLAYERS = 6
  1161.  
  1162. SpawnManager__update_respawns(self, dt, t)
  1163.  
  1164. return
  1165. end
  1166. end
  1167.  
  1168. if not SpawnManager_flow_callback_add_spawn_point then
  1169. SpawnManager_flow_callback_add_spawn_point = SpawnManager.flow_callback_add_spawn_point
  1170. SpawnManager.flow_callback_add_spawn_point = function (self, unit)
  1171.  
  1172.  
  1173. local NUM_PLAYERS = 6
  1174.  
  1175. SpawnManager_flow_callback_add_spawn_point(self, unit)
  1176.  
  1177. return
  1178.  
  1179. end
  1180. end
  1181.  
  1182. if not SpawnManager__update_spawning then
  1183. SpawnManager__update_spawning = SpawnManager._update_spawning
  1184. SpawnManager._update_spawning = function (self, dt, t)
  1185.  
  1186. local NUM_PLAYERS = 6
  1187.  
  1188. return SpawnManager__update_spawning(self, dt, t)
  1189. end
  1190. end
  1191.  
  1192.  
  1193. if not SpawnManager__spawn_pos_rot_from_index then
  1194. SpawnManager__spawn_pos_rot_from_index = SpawnManager._spawn_pos_rot_from_index
  1195. SpawnManager._spawn_pos_rot_from_index = function (self, index)
  1196.  
  1197. writelog("-- endered _spawn_pos_rot_from_index with index "..index)
  1198.  
  1199. if(index == 5) then index = 4 end
  1200.  
  1201. position, rotation = SpawnManager__spawn_pos_rot_from_index(self, index)
  1202. return position, rotation
  1203.  
  1204. end
  1205. end
  1206.  
  1207. if not ConflictDirector_get_cluster_and_loneliness then
  1208. ConflictDirector_get_cluster_and_loneliness = ConflictDirector.get_cluster_and_loneliness
  1209. ConflictDirector.get_cluster_and_loneliness = function (self, min_dist)
  1210.  
  1211. writelog("-- endered get_cluster_and_loneliness --")
  1212.  
  1213. if self._cluster_and_loneliness[min_dist] then
  1214. local stored = self._cluster_and_loneliness[min_dist]
  1215.  
  1216. return stored[1], stored[2], stored[3], stored[4]
  1217. end
  1218.  
  1219. local positions = PLAYER_POSITIONS
  1220.  
  1221. writelog("PLAYER_POSITIONS has num of elements: "..tostring(#positions))
  1222.  
  1223. local new_positions = {}
  1224.  
  1225. for i, v in ipairs(positions) do
  1226. table.insert(new_positions, v)
  1227. end
  1228.  
  1229. while #new_positions ~= 1 do
  1230. table.remove(new_positions, #new_positions)
  1231. end
  1232.  
  1233. writelog("new_positions has num of elements: "..tostring(#new_positions))
  1234.  
  1235. local units = PLAYER_AND_BOT_UNITS
  1236. local cluster_utility, loneliness_index, loneliness_value = ConflictUtils.cluster_weight_and_loneliness(new_positions, min_dist or 10)
  1237. local loneliest_player_unit = units[loneliness_index]
  1238. local fill = FrameTable.alloc_table()
  1239. fill[1] = cluster_utility
  1240. fill[2] = positions[loneliness_index]
  1241. fill[3] = loneliness_value
  1242. fill[4] = loneliest_player_unit
  1243. self._cluster_and_loneliness[min_dist] = fill
  1244.  
  1245. return cluster_utility, positions[loneliness_index], loneliness_value, loneliest_player_unit
  1246. end
  1247. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement