1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00
ComfyFactorio/maps/deep_jungle/main.lua

155 lines
5.5 KiB
Lua
Raw Normal View History

2022-03-06 01:33:21 +02:00
require 'modules.no_deconstruction_of_neutral_entities'
require 'modules.spawners_contain_biters'
require 'modules.biters_yield_coins'
require 'modules.rocks_yield_coins'
require 'modules.flashlight_toggle_button'
require 'maps.deep_jungle.generate'
2022-03-15 20:59:38 +02:00
2022-03-06 01:33:21 +02:00
local Event = require 'utils.event'
2024-01-28 21:42:28 +02:00
local map_functions = require 'utils.tools.map_functions'
2022-03-15 20:59:38 +02:00
local Task = require 'utils.task'
local DPT = require 'maps.deep_jungle.table'
2022-03-06 01:33:21 +02:00
local random = math.random
local function on_chunk_charted(event)
2022-03-15 20:59:38 +02:00
local settings = DPT.get('settings')
2022-03-06 01:33:21 +02:00
local surface = game.get_surface(event.surface_index)
2024-09-25 16:38:14 +02:00
local deco = prototypes.decorative
2022-03-06 01:33:21 +02:00
local position = event.position
2022-03-15 20:59:38 +02:00
if settings.chunks_charted[tostring(position.x) .. tostring(position.y)] then
2022-03-06 01:33:21 +02:00
return
end
2022-03-15 20:59:38 +02:00
settings.chunks_charted[tostring(position.x) .. tostring(position.y)] = true
2022-03-06 01:33:21 +02:00
local decorative_names = {}
for k, v in pairs(deco) do
if v.autoplace_specification then
decorative_names[#decorative_names + 1] = k
end
end
2024-09-25 16:38:14 +02:00
surface.regenerate_decorative(decorative_names, { position })
2022-03-06 01:33:21 +02:00
if random(1, 14) ~= 1 then
return
end
2024-09-25 16:38:14 +02:00
map_functions.draw_rainbow_patch({ x = position.x * 32 + random(1, 32), y = position.y * 32 + random(1, 32) }, surface, random(14, 26), 2000)
2022-03-06 01:33:21 +02:00
end
local function on_player_joined_game(event)
local player = game.get_player(event.player_index)
local surface = game.get_surface('deep_jungle')
2024-09-25 16:38:14 +02:00
if player.online_time < 5 and surface.is_chunk_generated({ 0, 0 }) then
player.teleport(surface.find_non_colliding_position('character', { 0, 0 }, 2, 1), 'deep_jungle')
2022-03-06 01:33:21 +02:00
else
if player.online_time < 5 then
2024-09-25 16:38:14 +02:00
player.teleport({ 0, 0 }, 'deep_jungle')
2022-03-06 01:33:21 +02:00
end
end
if player.online_time < 2 then
2024-09-25 16:38:14 +02:00
player.insert { name = 'iron-plate', count = 32 }
2022-03-06 01:33:21 +02:00
end
end
local function on_entity_died(event)
local entity = event.entity
if not entity or not entity.valid then
return
end
local surface = entity.surface
if entity.type == 'tree' then
if random(1, 8) == 1 then
local p = surface.find_non_colliding_position('small-biter', entity.position, 2, 0.5)
if p then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'small-biter', position = entity.position }
2022-03-06 01:33:21 +02:00
end
return
end
if random(1, 16) == 1 then
local p = surface.find_non_colliding_position('medium-biter', entity.position, 2, 0.5)
if p then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'medium-biter', position = entity.position }
2022-03-06 01:33:21 +02:00
end
return
end
if random(1, 32) == 1 then
local p = surface.find_non_colliding_position('big-biter', entity.position, 2, 0.5)
if p then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'big-biter', position = entity.position }
2022-03-06 01:33:21 +02:00
end
return
end
if random(1, 512) == 1 then
local p = surface.find_non_colliding_position('behemoth-biter', entity.position, 2, 0.5)
if p then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'behemoth-biter', position = entity.position }
2022-03-06 01:33:21 +02:00
end
return
end
end
if entity.type == 'simple-entity' then
if random(1, 8) == 1 then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'small-worm-turret', position = entity.position }
2022-03-06 01:33:21 +02:00
return
end
if random(1, 16) == 1 then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'medium-worm-turret', position = entity.position }
2022-03-06 01:33:21 +02:00
return
end
if random(1, 32) == 1 then
2024-09-25 16:38:14 +02:00
surface.create_entity { name = 'big-worm-turret', position = entity.position }
2022-03-06 01:33:21 +02:00
return
end
end
end
2022-03-15 20:59:38 +02:00
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
2024-09-25 16:38:14 +02:00
local on_tick = function ()
2022-03-15 20:59:38 +02:00
local tick = game.tick
if tick % 40 == 0 then
chunk_load()
end
end
2022-03-06 01:33:21 +02:00
local function on_init()
local map_gen_settings = {}
2022-03-15 20:59:38 +02:00
local settings = DPT.get('settings')
2022-03-06 01:33:21 +02:00
map_gen_settings.moisture = 0.99
map_gen_settings.water = 'none'
map_gen_settings.starting_area = 'normal'
2024-09-25 16:38:14 +02:00
map_gen_settings.cliff_settings = { cliff_elevation_interval = 4, cliff_elevation_0 = 0.1 }
2022-03-06 01:33:21 +02:00
map_gen_settings.autoplace_controls = {
2024-09-25 16:38:14 +02:00
['coal'] = { frequency = 'none', size = 'none', richness = 'none' },
['stone'] = { frequency = 'none', size = 'none', richness = 'none' },
['copper-ore'] = { frequency = 'none', size = 'none', richness = 'none' },
['iron-ore'] = { frequency = 'none', size = 'none', richness = 'none' },
['crude-oil'] = { frequency = 'very-high', size = 'big', richness = 'normal' },
['trees'] = { frequency = 'none', size = 'none', richness = 'none' },
['enemy-base'] = { frequency = 'high', size = 'big', richness = 'good' }
2022-03-06 01:33:21 +02:00
}
game.create_surface('deep_jungle', map_gen_settings)
2024-09-25 16:38:14 +02:00
game.forces.player.set_spawn_position({ 0, 0 }, game.surfaces['deep_jungle'])
2022-03-15 20:59:38 +02:00
settings.force_chunk = true
settings.chunk_load_tick = game.tick + 200
2022-03-06 01:33:21 +02:00
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)
2022-03-15 20:59:38 +02:00
Event.on_nth_tick(10, on_tick)
2022-03-06 01:33:21 +02:00
require 'modules.rocks_yield_ore'