From 644d008e861ac48709d3d096da9fed221cf3a2a1 Mon Sep 17 00:00:00 2001 From: Oarcinae Date: Fri, 29 Mar 2019 21:27:42 -0400 Subject: [PATCH] Changed base removal to be more forceful. Ignores pollution and removes chunks properly now. (Still only works in a 10 chunk radius square around the spawn pos.) Double checked that regrowth is still working as intended even with this change. (It seems to be.) --- lib/regrowth_map.lua | 19 +++++++++++++------ lib/separate_spawns.lua | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/regrowth_map.lua b/lib/regrowth_map.lua index 288ccd2..98ce85b 100644 --- a/lib/regrowth_map.lua +++ b/lib/regrowth_map.lua @@ -148,7 +148,7 @@ function OarcRegrowthMarkForRemoval(pos, chunk_radius) global.chunk_regrow.map[x] = {} end global.chunk_regrow.map[x][y] = nil - table.insert(global.chunk_regrow.removal_list, {x=x,y=y}) + table.insert(global.chunk_regrow.removal_list, {pos={x=x,y=y},force=true}) end end end @@ -269,8 +269,9 @@ function OarcRegrowthCheckArray() -- Check chunk actually exists if (game.surfaces[GAME_SURFACE_NAME].is_chunk_generated({x=(global.chunk_regrow.x_index), y=(global.chunk_regrow.y_index)})) then - table.insert(global.chunk_regrow.removal_list, {x=global.chunk_regrow.x_index, - y=global.chunk_regrow.y_index}) + table.insert(global.chunk_regrow.removal_list, {pos={x=global.chunk_regrow.x_index, + y=global.chunk_regrow.y_index}, + force=false}) global.chunk_regrow.map[global.chunk_regrow.x_index][global.chunk_regrow.y_index] = nil end end @@ -279,14 +280,20 @@ end -- Remove all chunks at same time to reduce impact to FPS/UPS function OarcRegrowthRemoveAllChunks() while (#global.chunk_regrow.removal_list > 0) do - local c_pos = table.remove(global.chunk_regrow.removal_list) + local c_remove = table.remove(global.chunk_regrow.removal_list) + local c_pos = c_remove.pos local c_timer = global.chunk_regrow.map[c_pos.x][c_pos.y] -- Confirm chunk is still expired if (c_timer == nil) then - -- Check for pollution - if (game.surfaces[GAME_SURFACE_NAME].get_pollution({c_pos.x*32,c_pos.y*32}) > 0) then + -- If it is FORCE removal, then remove it regardless of pollution. + if (c_remove.force) then + game.surfaces[GAME_SURFACE_NAME].delete_chunk(c_pos) + global.chunk_regrow.map[c_pos.x][c_pos.y] = nil + + -- If it is a normal timeout removal, don't do it if there is pollution in the chunk. + elseif (game.surfaces[GAME_SURFACE_NAME].get_pollution({c_pos.x*32,c_pos.y*32}) > 0) then global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick -- Else delete the chunk diff --git a/lib/separate_spawns.lua b/lib/separate_spawns.lua index 269daf4..5468f89 100644 --- a/lib/separate_spawns.lua +++ b/lib/separate_spawns.lua @@ -107,6 +107,7 @@ function FindUnusedSpawns(event) global.uniqueSpawns[player.name] = nil + log("Removing base: " .. spawnPos.x .. "," .. spawnPos.y) SendBroadcastMsg(player.name .. "'s base was marked for immediate clean up because they left within "..MIN_ONLINE_TIME_IN_MINUTES.." minutes of joining.") OarcRegrowthMarkForRemoval(spawnPos, 10) global.chunk_regrow.force_removal_flag = game.tick