mirror of
https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git
synced 2025-01-18 02:58:37 +02:00
Fixing regrowth issues, hopefully. Changed player refresh and added on build_entity event refreshes.
This commit is contained in:
parent
a0f1ad9f36
commit
294c1c05fb
@ -11,7 +11,7 @@
|
||||
|
||||
WELCOME_MSG = "[INSERT SERVER OWNER MSG HERE!]"
|
||||
GAME_MODE_MSG = "In the current game mode, a satellite must be launched from an existing far away rocket silo to win!"
|
||||
MODULES_ENABLED = "Mods Enabled: Separate Spawns, RSO, Long-Reach, Autofill, Undecorator, Player List"
|
||||
MODULES_ENABLED = "Mods Enabled: Separate Spawns, Regrowth, RSO, Long-Reach, Autofill, Undecorator, Player List"
|
||||
|
||||
WELCOME_MSG_TITLE = "[INSERT SERVER OWNER MSG HERE!]"
|
||||
WELCOME_MSG1 = "Rules: Be polite. Ask before changing other players's stuff. Have fun!"
|
||||
|
24
control.lua
24
control.lua
@ -289,13 +289,37 @@ end)
|
||||
|
||||
----------------------------------------
|
||||
-- Refreshes regrowth timers around an active timer
|
||||
-- Refresh areas where stuff is built, and mark any chunks with
|
||||
-- railways as off limits.
|
||||
----------------------------------------
|
||||
if ENABLE_REGROWTH then
|
||||
script.on_event(defines.events.on_sector_scanned, function (event)
|
||||
OarcRegrowthSectorScan(event)
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_built_entity, function (event)
|
||||
if (event.created_entity.name == "straight-rail") then
|
||||
OarcRegrowthOffLimits(event.created_entity.position, 1)
|
||||
elseif (event.created_entity.name == "curved-rail") then
|
||||
OarcRegrowthOffLimits(event.created_entity.position, 1)
|
||||
else
|
||||
OarcRegrowthRefreshArea(event.created_entity.position, 1)
|
||||
end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_robot_built_entity, function (event)
|
||||
if (event.created_entity.name == "straight-rail") then
|
||||
OarcRegrowthOffLimits(event.created_entity.position, 1)
|
||||
elseif (event.created_entity.name == "curved-rail") then
|
||||
OarcRegrowthOffLimits(event.created_entity.position, 1)
|
||||
else
|
||||
OarcRegrowthRefreshArea(event.created_entity.position, 1)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
----------------------------------------
|
||||
-- Shared chat, so you don't have to type /s
|
||||
----------------------------------------
|
||||
|
134
regrowth_map.lua
134
regrowth_map.lua
@ -17,7 +17,7 @@
|
||||
-- 7. For now, oarc spawns are deletion safe as well, but only immediate area.
|
||||
|
||||
|
||||
REGROWTH_TIMEOUT_TICKS = 60*60 -- 1 hour
|
||||
REGROWTH_TIMEOUT_TICKS = 60*30 -- 1 hour
|
||||
|
||||
-- Init globals and set player join area to be off limits.
|
||||
function OarcRegrowthInit()
|
||||
@ -27,6 +27,7 @@ function OarcRegrowthInit()
|
||||
global.chunk_regrow.num_chunks = 0
|
||||
global.chunk_regrow.chunk_index = 1
|
||||
global.chunk_regrow.rso_region_roll_counter = 0
|
||||
global.chunk_regrow.player_refresh_index = 1
|
||||
|
||||
OarcRegrowthOffLimits({x=0,y=0}, 15)
|
||||
end
|
||||
@ -74,7 +75,19 @@ function OarcRegrowthMarkForRemoval(pos, chunk_radius)
|
||||
end
|
||||
end
|
||||
|
||||
-- Marks a safe area around around a position that won't ever be deleted.
|
||||
-- Marks a chunk a position that won't ever be deleted.
|
||||
function OarcRegrowthOffLimitsChunk(pos)
|
||||
local c_pos = {x=pos.x-(pos.x % 32),
|
||||
y=pos.y-(pos.y % 32)}
|
||||
|
||||
if (global.chunk_regrow.map[c_pos.x] == nil) then
|
||||
global.chunk_regrow.map[c_pos.y] = {}
|
||||
end
|
||||
global.chunk_regrow.map[c_pos.x][c_pos.y] = -1
|
||||
end
|
||||
|
||||
|
||||
-- Marks a safe area around a position that won't ever be deleted.
|
||||
function OarcRegrowthOffLimits(pos, chunk_radius)
|
||||
local c_pos = {x=pos.x-(pos.x % 32),
|
||||
y=pos.y-(pos.y % 32)}
|
||||
@ -91,6 +104,19 @@ function OarcRegrowthOffLimits(pos, chunk_radius)
|
||||
end
|
||||
end
|
||||
|
||||
-- Refreshes timers on a chunk containing position
|
||||
function OarcRegrowthRefreshChunk(pos)
|
||||
local c_pos = {x=pos.x-(pos.x % 32),
|
||||
y=pos.y-(pos.y % 32)}
|
||||
|
||||
if (global.chunk_regrow.map[c_pos.x] == nil) then
|
||||
global.chunk_regrow.map[c_pos.y] = {}
|
||||
end
|
||||
if (global.chunk_regrow.map[c_pos.x][c_pos.y] ~= -1) then
|
||||
global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick
|
||||
end
|
||||
global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick
|
||||
end
|
||||
|
||||
-- Refreshes timers on all chunks around a certain area
|
||||
function OarcRegrowthRefreshArea(pos, chunk_radius)
|
||||
@ -104,14 +130,16 @@ function OarcRegrowthRefreshArea(pos, chunk_radius)
|
||||
if (global.chunk_regrow.map[x] == nil) then
|
||||
global.chunk_regrow.map[x] = {}
|
||||
end
|
||||
global.chunk_regrow.map[x][y] = game.tick
|
||||
if (global.chunk_regrow.map[x][y] ~= -1) then
|
||||
global.chunk_regrow.map[x][y] = game.tick
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Refreshes timers on all chunks near an ACTIVE radar
|
||||
function OarcRegrowthSectorScan(event)
|
||||
OarcRegrowthRefreshArea(event.radar.position, 17)
|
||||
OarcRegrowthRefreshArea(event.radar.position, 16)
|
||||
end
|
||||
|
||||
|
||||
@ -120,9 +148,29 @@ end
|
||||
-- file.
|
||||
function OarcRegrowthOnTick(event)
|
||||
|
||||
-- We always check of value exists first... Due to the way events work,
|
||||
-- this is a necessary check.
|
||||
if (global.chunk_regrow.list[global.chunk_regrow.chunk_index]) then
|
||||
-- Every half a second, refresh all chunks near a single player
|
||||
if ((game.tick % (30))==2) then
|
||||
global.chunk_regrow.player_refresh_index = global.chunk_regrow.player_refresh_index + 1
|
||||
if (global.chunk_regrow.player_refresh_index > #game.connected_players) then
|
||||
global.chunk_regrow.player_refresh_index = 1
|
||||
end
|
||||
for _,force in pairs(game.forces) do
|
||||
if (force ~= nil) then
|
||||
if ((force.name ~= enemy) and
|
||||
(force.name ~= neutral) and
|
||||
(force.name ~= player)) then
|
||||
|
||||
if (game.connected_players[global.chunk_regrow.player_refresh_index]) then
|
||||
OarcRegrowthRefreshArea(game.connected_players[global.chunk_regrow.player_refresh_index].position, 20)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Every 5 ticks
|
||||
if (((game.tick % 5) ==0 ) and (global.chunk_regrow.list[global.chunk_regrow.chunk_index] ~= nil)) then
|
||||
|
||||
-- Position of left_top of the chunk in the list.
|
||||
local x = global.chunk_regrow.list[global.chunk_regrow.chunk_index].x
|
||||
@ -135,67 +183,53 @@ function OarcRegrowthOnTick(event)
|
||||
-- Check this chunk is NOT timed out, this should be the most common reason
|
||||
-- to go to the next list item, so I put it first to optimize the logic
|
||||
if ((global.chunk_regrow.map[x][y]+REGROWTH_TIMEOUT_TICKS) > game.tick) then
|
||||
goto GO_NEXT_CHUNK
|
||||
end
|
||||
|
||||
-- Do nothing
|
||||
|
||||
-- Check if this chunk is off limits
|
||||
if (global.chunk_regrow.map[x][y] == -1) then
|
||||
elseif (global.chunk_regrow.map[x][y] == -1) then
|
||||
-- DebugPrint("Marking chunk as off limits: X:"..x.." Y:"..y)
|
||||
global.chunk_regrow.num_chunks = global.chunk_regrow.num_chunks - 1
|
||||
table.remove(global.chunk_regrow.list, global.chunk_regrow.chunk_index)
|
||||
global.chunk_regrow.chunk_index = global.chunk_regrow.chunk_index - 1
|
||||
goto GO_NEXT_CHUNK
|
||||
end
|
||||
|
||||
-- Check for pollution, refresh timer if found
|
||||
if (game.surfaces[GAME_SURFACE_NAME].get_pollution(pos) > 0) then
|
||||
elseif (game.surfaces[GAME_SURFACE_NAME].get_pollution(pos) > 0) then
|
||||
global.chunk_regrow.map[x][y] = game.tick
|
||||
goto GO_NEXT_CHUNK
|
||||
end
|
||||
|
||||
-- Check for players nearby, don't delete anything near players.
|
||||
-- And refresh the area around them if they happen to be near.
|
||||
local players_found = game.surfaces[GAME_SURFACE_NAME].find_entities_filtered{area = {{x-(32*5), y-(32*5)}, {x+(32*5), y+(32*5)}}, type= "player"}
|
||||
if (next(players_found) ~= nil) then
|
||||
OarcRegrowthRefreshArea(pos, 5)
|
||||
goto GO_NEXT_CHUNK
|
||||
end
|
||||
|
||||
-- Check for railway lines
|
||||
local railway_found = game.surfaces[GAME_SURFACE_NAME].find_entities_filtered{area = {{x-(32*2), y-(32*2)}, {x+(32*2), y+(32*2)}}, name= "railway"}
|
||||
if (next(railway_found) ~= nil) then
|
||||
OarcRegrowthRefreshArea(pos, 2)
|
||||
goto GO_NEXT_CHUNK
|
||||
end
|
||||
|
||||
|
||||
-- Else, let's see if we can delete the chunk.
|
||||
local chunk_x = x/32
|
||||
local chunk_y = y/32
|
||||
else
|
||||
|
||||
-- Only delete chunks near map edges.
|
||||
local ungenerate_chunk_count = 0
|
||||
for i=-1,1 do
|
||||
for k=-1,1 do
|
||||
if (not game.surfaces[GAME_SURFACE_NAME].is_chunk_generated({chunk_x+i,chunk_y+k})) then
|
||||
ungenerate_chunk_count = ungenerate_chunk_count +1
|
||||
local chunk_x = x/32
|
||||
local chunk_y = y/32
|
||||
|
||||
-- Only delete chunks near map edges.
|
||||
local ungenerate_chunk_count = 0
|
||||
for i=-1,1 do
|
||||
for k=-1,1 do
|
||||
if (not game.surfaces[GAME_SURFACE_NAME].is_chunk_generated({chunk_x+i,chunk_y+k})) then
|
||||
ungenerate_chunk_count = ungenerate_chunk_count +1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Delete the chunk and remove it from the list.
|
||||
if (ungenerate_chunk_count >= 3) then
|
||||
game.surfaces[GAME_SURFACE_NAME].delete_chunk({chunk_x,chunk_y})
|
||||
global.chunk_regrow.num_chunks = global.chunk_regrow.num_chunks -1
|
||||
table.remove(global.chunk_regrow.list, global.chunk_regrow.chunk_index)
|
||||
global.chunk_regrow.chunk_index = global.chunk_regrow.chunk_index - 1
|
||||
global.chunk_regrow.map[x][y] = nil
|
||||
DebugPrint("Deleting Chunk: X="..x..",Y="..y)
|
||||
-- Delete the chunk and remove it from the list.
|
||||
if (ungenerate_chunk_count >= 3) then
|
||||
game.surfaces[GAME_SURFACE_NAME].delete_chunk({chunk_x,chunk_y})
|
||||
global.chunk_regrow.num_chunks = global.chunk_regrow.num_chunks -1
|
||||
table.remove(global.chunk_regrow.list, global.chunk_regrow.chunk_index)
|
||||
global.chunk_regrow.chunk_index = global.chunk_regrow.chunk_index - 1
|
||||
global.chunk_regrow.map[x][y] = nil
|
||||
-- DebugPrint("Deleting Chunk: X="..x..",Y="..y)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- I don't think should ever happen...
|
||||
DebugPrint("No matching map entry: X="..x..",Y="..y)
|
||||
global.chunk_regrow.num_chunks = global.chunk_regrow.num_chunks -1
|
||||
table.remove(global.chunk_regrow.list, global.chunk_regrow.chunk_index)
|
||||
global.chunk_regrow.chunk_index = global.chunk_regrow.chunk_index - 1
|
||||
end
|
||||
|
||||
::GO_NEXT_CHUNK::
|
||||
global.chunk_regrow.chunk_index = global.chunk_regrow.chunk_index + 1
|
||||
if (global.chunk_regrow.chunk_index > global.chunk_regrow.num_chunks) then
|
||||
global.chunk_regrow.chunk_index = 1
|
||||
|
@ -191,9 +191,6 @@ function InitSpawnGlobalsAndForces()
|
||||
if (global.playerCooldowns == nil) then
|
||||
global.playerCooldowns = {}
|
||||
end
|
||||
if (global.tick_counter == nil) then
|
||||
global.tick_counter = 0
|
||||
end
|
||||
|
||||
game.create_force(MAIN_FORCE)
|
||||
game.forces[MAIN_FORCE].set_spawn_position(game.forces["player"].get_spawn_position(GAME_SURFACE_NAME), GAME_SURFACE_NAME)
|
||||
@ -225,9 +222,9 @@ function SendPlayerToNewSpawnAndCreateIt(player, spawn, moatEnabled)
|
||||
|
||||
-- If we get a valid spawn point, setup the area
|
||||
if ((spawn.x ~= 0) and (spawn.y ~= 0)) then
|
||||
if ENABLE_REGROWTH then
|
||||
OarcRegrowthOffLimits(spawn, 5)
|
||||
end
|
||||
-- if ENABLE_REGROWTH then
|
||||
-- OarcRegrowthOffLimits(spawn, 5)
|
||||
-- end
|
||||
global.uniqueSpawns[player.name] = {pos=spawn,moat=moatEnabled}
|
||||
ClearNearbyEnemies(player, SAFE_AREA_TILE_DIST)
|
||||
else
|
||||
@ -293,7 +290,7 @@ end
|
||||
-- we'll have to figure out how to change it.
|
||||
function ShareVisionBetweenPlayers()
|
||||
|
||||
if (global.tick_counter >= (TICKS_PER_SECOND*5)) then
|
||||
if ((game.tick % (TICKS_PER_SECOND*5)) == 0) then
|
||||
|
||||
for _,force in pairs(game.forces) do
|
||||
if (force ~= nil) then
|
||||
|
Loading…
x
Reference in New Issue
Block a user