diff --git a/maps/deep_jungle/generate.lua b/maps/deep_jungle/generate.lua index 38147912..fc4b456a 100644 --- a/maps/deep_jungle/generate.lua +++ b/maps/deep_jungle/generate.lua @@ -2,10 +2,10 @@ local Task = require 'utils.task' local Token = require 'utils.token' local Event = require 'utils.event' local Terrain = require 'maps.deep_jungle.terrain' +local DPT = require 'maps.deep_jungle.table' local Public = {} -local force_chunk = false local ceil = math.ceil local queue_task = Task.queue_task local tiles_per_call = 12 @@ -496,7 +496,11 @@ local do_chunk = Public.do_chunk local schedule_chunk = Public.schedule_chunk local function on_chunk(event) - if force_chunk then + local settings = DPT.get('settings') + if settings.stop_chunk then + return + end + if settings.force_chunk then do_chunk(event) else schedule_chunk(event) diff --git a/maps/deep_jungle/main.lua b/maps/deep_jungle/main.lua index 3d741a8c..0b175d24 100644 --- a/maps/deep_jungle/main.lua +++ b/maps/deep_jungle/main.lua @@ -4,32 +4,22 @@ require 'modules.biters_yield_coins' require 'modules.rocks_yield_coins' require 'modules.flashlight_toggle_button' require 'maps.deep_jungle.generate' -local Global = require 'utils.global' + local Event = require 'utils.event' local map_functions = require 'tools.map_functions' +local Task = require 'utils.task' +local DPT = require 'maps.deep_jungle.table' local random = math.random -local this = { - chunks_charted = {} -} - -Global.register( - this, - function(tbl) - this = tbl - end -) - -local Public = {} - local function on_chunk_charted(event) + local settings = DPT.get('settings') local surface = game.get_surface(event.surface_index) local deco = game.decorative_prototypes local position = event.position - if this.chunks_charted[tostring(position.x) .. tostring(position.y)] then + if settings.chunks_charted[tostring(position.x) .. tostring(position.y)] then return end - this.chunks_charted[tostring(position.x) .. tostring(position.y)] = true + settings.chunks_charted[tostring(position.x) .. tostring(position.y)] = true local decorative_names = {} for k, v in pairs(deco) do @@ -113,8 +103,29 @@ local function on_entity_died(event) end end +local function chunk_load() + local tick = game.tick + local settings = DPT.get('settings') + if settings.chunk_load_tick then + if settings.chunk_load_tick < tick then + settings.force_chunk = false + DPT.remove('settings', 'chunk_load_tick') + Task.set_queue_speed(8) + end + end +end + +local on_tick = function() + local tick = game.tick + if tick % 40 == 0 then + chunk_load() + end +end + local function on_init() local map_gen_settings = {} + local settings = DPT.get('settings') + map_gen_settings.moisture = 0.99 map_gen_settings.water = 'none' map_gen_settings.starting_area = 'normal' @@ -130,13 +141,14 @@ local function on_init() } game.create_surface('deep_jungle', map_gen_settings) game.forces.player.set_spawn_position({0, 0}, game.surfaces['deep_jungle']) + settings.force_chunk = true + settings.chunk_load_tick = game.tick + 200 end Event.on_init(on_init) Event.add(defines.events.on_chunk_charted, on_chunk_charted) Event.add(defines.events.on_entity_died, on_entity_died) Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.on_nth_tick(10, on_tick) require 'modules.rocks_yield_ore' - -return Public diff --git a/maps/deep_jungle/table.lua b/maps/deep_jungle/table.lua new file mode 100644 index 00000000..37ed3bb8 --- /dev/null +++ b/maps/deep_jungle/table.lua @@ -0,0 +1,48 @@ +local Global = require 'utils.global' + +local this = { + settings = { + chunk_load_tick = false, + chunks_charted = {} + } +} + +Global.register( + this, + function(tbl) + this = tbl + end +) + +local Public = {} + +function Public.get(key) + if key then + return this[key] + else + return this + end +end + +function Public.set(key, value) + if key and (value or value == false) then + this[key] = value + return this[key] + elseif key then + return this[key] + else + return this + end +end + +function Public.remove(key, sub_key) + if key then + if this[key] and this[key][sub_key] then + this[key][sub_key] = nil + elseif this[key] then + this[key] = nil + end + end +end + +return Public