Advertisement
Guest User

Untitled

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