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

fix deep_jungle

This commit is contained in:
Gerkiz 2022-03-06 00:33:21 +01:00
parent 980a97d1cb
commit 590b58504c
5 changed files with 941 additions and 891 deletions

View File

@ -1,414 +0,0 @@
--luacheck: ignore
--deep jungle-- mewmew made this --
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'
local map_functions = require 'tools.map_functions'
local simplex_noise = require 'utils.simplex_noise'
simplex_noise = simplex_noise.d2
local event = require 'utils.event'
local math_random = math.random
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math.random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local function secret_shop(pos, surface)
local secret_market_items = {
{price = {{'coin', math_random(300, 600)}}, offer = {type = 'give-item', item = 'combat-shotgun'}},
{price = {{'coin', math_random(200, 400)}}, offer = {type = 'give-item', item = 'rocket-launcher'}},
{price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'piercing-rounds-magazine'}},
--{price = {{"coin", math_random(150,250)}}, offer = {type = 'give-item', item = 'uranium-rounds-magazine'}},
{price = {{'coin', math_random(15, 30)}}, offer = {type = 'give-item', item = 'piercing-shotgun-shell'}},
{price = {{'coin', math_random(10, 20)}}, offer = {type = 'give-item', item = 'rocket'}},
{price = {{'coin', math_random(20, 30)}}, offer = {type = 'give-item', item = 'explosive-rocket'}},
{price = {{'coin', math_random(30, 60)}}, offer = {type = 'give-item', item = 'cluster-grenade'}},
{price = {{'coin', math_random(8, 16)}}, offer = {type = 'give-item', item = 'land-mine'}},
{price = {{'coin', math_random(200, 300)}}, offer = {type = 'give-item', item = 'heavy-armor'}},
{price = {{'coin', math_random(400, 800)}}, offer = {type = 'give-item', item = 'modular-armor'}},
{price = {{'coin', math_random(1000, 2000)}}, offer = {type = 'give-item', item = 'power-armor'}},
{price = {{'coin', math_random(2500, 5000)}}, offer = {type = 'give-item', item = 'fusion-reactor-equipment'}},
{price = {{'coin', math_random(200, 400)}}, offer = {type = 'give-item', item = 'battery-equipment'}},
{price = {{'coin', math_random(150, 250)}}, offer = {type = 'give-item', item = 'belt-immunity-equipment'}},
{price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'night-vision-equipment'}},
{price = {{'coin', math_random(400, 800)}}, offer = {type = 'give-item', item = 'exoskeleton-equipment'}},
{price = {{'coin', math_random(200, 300)}}, offer = {type = 'give-item', item = 'personal-roboport-equipment'}},
{price = {{'coin', math_random(25, 50)}}, offer = {type = 'give-item', item = 'construction-robot'}},
-- {price = {{"coin", math_random(10000,20000)}}, offer = {type = 'give-item', item = 'energy-shield-equipment'}},
-- {price = {{"coin", math_random(5000,15000)}}, offer = {type = 'give-item', item = 'personal-laser-defense-equipment'}},
{price = {{'coin', math_random(100, 300)}}, offer = {type = 'give-item', item = 'loader'}},
{price = {{'coin', math_random(200, 400)}}, offer = {type = 'give-item', item = 'fast-loader'}},
{price = {{'coin', math_random(300, 500)}}, offer = {type = 'give-item', item = 'express-loader'}},
{price = {{'coin', math_random(150, 300)}}, offer = {type = 'give-item', item = 'locomotive'}},
{price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'cargo-wagon'}},
{price = {{'coin', math_random(5, 15)}}, offer = {type = 'give-item', item = 'grenade'}},
{price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'cliff-explosives'}},
{price = {{'coin', math_random(10, 20)}}, offer = {type = 'give-item', item = 'explosives', count = 50}},
{price = {{'coin', math_random(4, 8)}}, offer = {type = 'give-item', item = 'rail', count = 4}},
{price = {{'coin', math_random(20, 30)}}, offer = {type = 'give-item', item = 'train-stop'}},
{price = {{'coin', math_random(4, 12)}}, offer = {type = 'give-item', item = 'small-lamp'}},
{price = {{'coin', math_random(1, 4)}}, offer = {type = 'give-item', item = 'firearm-magazine'}},
{price = {{'coin', math_random(60, 150)}}, offer = {type = 'give-item', item = 'car', count = 1}},
{price = {{'coin', math_random(75, 150)}}, offer = {type = 'give-item', item = 'gun-turret', count = 1}},
{price = {{'coin', math_random(500, 750)}}, offer = {type = 'give-item', item = 'laser-turret', count = 1}},
{price = {{'coin', math_random(1000, 2000)}}, offer = {type = 'give-item', item = 'artillery-turret', count = 1}},
{price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'artillery-shell', count = 1}},
{price = {{'coin', math_random(50, 150)}}, offer = {type = 'give-item', item = 'artillery-targeting-remote', count = 1}},
{price = {{'coin', math_random(5, 15)}}, offer = {type = 'give-item', item = 'shotgun-shell', count = 1}},
{price = {{'coin', math_random(8000, 16000)}}, offer = {type = 'give-item', item = 'power-armor-mk2', count = 1}},
{price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'solar-panel-equipment', count = 1}},
{price = {{'coin', math_random(4, 8)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
{price = {{'coin', math_random(4, 8)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
{price = {{'coin', math_random(4, 8)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
{price = {{'coin', math_random(4, 8)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
{price = {{'coin', math_random(4, 8)}}, offer = {type = 'give-item', item = 'coal', count = 50}}
--{price = {{"coin", math_random(4,8)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}
}
secret_market_items = shuffle(secret_market_items)
local market = surface.create_entity {name = 'market', position = pos}
market.destructible = false
for i = 1, math.random(6, 10), 1 do
market.add_market_item(secret_market_items[i])
end
end
local function treasure_chest(position)
if not game.surfaces['deep_jungle'].can_place_entity({name = 'steel-chest', position = position, force = 'player'}) then
return
end
treasure_chest_raffle_table = {}
treasure_chest_loot_weights = {}
table.insert(treasure_chest_loot_weights, {{name = 'landfill', count = math_random(8, 16)}, 16})
table.insert(treasure_chest_loot_weights, {{name = 'iron-gear-wheel', count = math_random(16, 48)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'coal', count = math_random(16, 48)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'copper-cable', count = math_random(64, 128)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'inserter', count = math_random(4, 8)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'fast-inserter', count = math_random(4, 8)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'burner-inserter', count = math_random(4, 8)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'rocket-fuel', count = math_random(1, 5)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'small-electric-pole', count = math_random(4, 8)}, 7})
table.insert(treasure_chest_loot_weights, {{name = 'firearm-magazine', count = math_random(16, 48)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'submachine-gun', count = 1}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'grenade', count = math_random(6, 12)}, 5})
table.insert(treasure_chest_loot_weights, {{name = 'land-mine', count = math_random(8, 16)}, 5})
table.insert(treasure_chest_loot_weights, {{name = 'light-armor', count = 1}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'heavy-armor', count = 1}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'pipe', count = math_random(10, 100)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'explosives', count = math_random(40, 50)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'shotgun', count = 1}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'shotgun-shell', count = math_random(8, 16)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'stone-brick', count = math_random(80, 100)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'small-lamp', count = math_random(2, 4)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'rail', count = math_random(16, 48)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'coin', count = math_random(32, 320)}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-1', count = math_random(1, 3)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-2', count = math_random(1, 3)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-3', count = math_random(1, 2)}, 1})
for _, t in pairs(treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
table.insert(treasure_chest_raffle_table, t[1])
end
end
local e = game.surfaces['deep_jungle'].create_entity {name = 'wooden-chest', position = position, force = 'player'}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(3, 7), 1 do
local loot = treasure_chest_raffle_table[math_random(1, #treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function rare_treasure_chest(position)
if not game.surfaces['deep_jungle'].can_place_entity({name = 'steel-chest', position = position, force = 'player'}) then
return
end
local rare_treasure_chest_raffle_table = {}
local rare_treasure_chest_loot_weights = {}
table.insert(rare_treasure_chest_loot_weights, {{name = 'combat-shotgun', count = 1}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = math_random(8, 16)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket-launcher', count = 1}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = math_random(4, 8)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = math_random(4, 8)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'modular-armor', count = 1}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = math_random(32, 64)}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = math_random(4, 8)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = math_random(3, 5)}, 4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = math_random(2, 3)}, 3})
for _, t in pairs(rare_treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
table.insert(rare_treasure_chest_raffle_table, t[1])
end
end
local e = game.surfaces['deep_jungle'].create_entity {name = 'steel-chest', position = position, force = 'player'}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(2, 3), 1 do
local loot = rare_treasure_chest_raffle_table[math_random(1, #rare_treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function get_noise(name, pos)
local seed = game.surfaces[1].map_gen_settings.seed
local noise_seed_add = 25000
if name == 1 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.001, pos.y * 0.001, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed + noise_seed_add)
local noise = noise[1] + noise[2] * 0.1
return noise
end
if name == 2 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.015, pos.y * 0.015, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.15, pos.y * 0.15, seed + noise_seed_add)
local noise = noise[1] + noise[2] * 0.2
return noise
end
if name == 3 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.025, pos.y * 0.025, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.2, pos.y * 0.2, seed + noise_seed_add)
local noise = noise[1] + noise[2] * 0.2
return noise
end
if name == 'greenwater' then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.003, pos.y * 0.003, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.03, pos.y * 0.03, seed + noise_seed_add)
local noise = noise[1] + noise[2] * 0.1
return noise
end
end
local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'}
local tree_raffle = {'tree-04', 'tree-07', 'tree-09', 'tree-06', 'tree-04', 'tree-07', 'tree-09', 'tree-04'}
local function process_tile(pos)
local noise_1 = get_noise(1, pos)
if noise_1 > -0.03 and noise_1 < 0.03 then
return 'deepwater'
end
if noise_1 > -0.05 and noise_1 < 0.05 then
return 'water'
end
local noise_greenwater = get_noise('greenwater', pos)
if noise_greenwater > -0.035 and noise_greenwater < 0.035 then
return 'water-green'
end
if noise_1 > -0.08 and noise_1 < 0.08 then
return false
end
local noise_2 = get_noise(2, pos)
if noise_2 > 0.37 or noise_2 < -0.37 then
if math_random(1, 4) == 1 then
return false, tree_raffle[math.ceil(math.abs(noise_1 * 8))]
end
end
local noise_3 = get_noise(3, pos)
if noise_3 > 0.5 then
if math_random(1, 3) == 1 then
return false, rock_raffle[math_random(1, #rock_raffle)]
end
end
return false
end
local function on_chunk_generated(event)
local surface = game.surfaces['deep_jungle']
if event.surface.name ~= surface.name then
return
end
local chunk_pos_x = event.area.left_top.x
local chunk_pos_y = event.area.left_top.y
local tiles = {}
local entities_to_place = {}
local treasure_chests = {}
local rare_treasure_chests = {}
local secret_shops = {}
local tile_to_insert = false
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = chunk_pos_x + x, y = chunk_pos_y + y}
tile_to_insert, entity_to_place = process_tile(pos)
if entity_to_place then
table.insert(entities_to_place, {name = entity_to_place, position = pos, force = 'player'})
end
if tile_to_insert then
table.insert(tiles, {name = tile_to_insert, position = pos})
if math_random(1, 40) == 1 and tile_to_insert == 'deepwater' then
surface.create_entity({name = 'fish', position = pos})
end
end
if math_random(1, 1500) == 1 then
table.insert(treasure_chests, pos)
end
if math_random(1, 16000) == 1 then
table.insert(rare_treasure_chests, pos)
end
if math_random(1, 8000) == 1 then
table.insert(secret_shops, pos)
end
end
end
surface.set_tiles(tiles, true)
for _, e in pairs(entities_to_place) do
if not surface.get_tile(e.position).collides_with('player-layer') then
surface.create_entity(e)
end
end
for _, p in pairs(treasure_chests) do
treasure_chest(p)
end
for _, p in pairs(rare_treasure_chests) do
rare_treasure_chest(p)
end
for _, p in pairs(secret_shops) do
if not surface.get_tile(p).collides_with('player-layer') then
local area = {{p.x - 128, p.y - 128}, {p.x + 128, p.y + 128}}
if surface.count_entities_filtered({name = 'market', area = area}) == 0 then
secret_shop(p, surface)
end
end
end
end
local function on_chunk_charted(event)
if not global.chunks_charted then
global.chunks_charted = {}
end
local surface = game.surfaces[event.surface_index]
local position = event.position
if global.chunks_charted[tostring(position.x) .. tostring(position.y)] then
return
end
global.chunks_charted[tostring(position.x) .. tostring(position.y)] = true
local decorative_names = {}
for k, v in pairs(game.decorative_prototypes) do
if v.autoplace_specification then
decorative_names[#decorative_names + 1] = k
end
end
surface.regenerate_decorative(decorative_names, {position})
if math_random(1, 14) ~= 1 then
return
end
map_functions.draw_rainbow_patch({x = position.x * 32 + math_random(1, 32), y = position.y * 32 + math_random(1, 32)}, surface, math_random(14, 26), 2000)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
local surface = game.surfaces['deep_jungle']
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')
else
if player.online_time < 5 then
player.teleport({0, 0}, 'deep_jungle')
end
end
if player.online_time < 2 then
player.insert {name = 'iron-plate', count = 32}
end
end
local function on_entity_died(event)
local surface = event.entity.surface
if event.entity.type == 'tree' then
if math_random(1, 8) == 1 then
local p = surface.find_non_colliding_position('small-biter', event.entity.position, 2, 0.5)
if p then
surface.create_entity {name = 'small-biter', position = event.entity.position}
end
return
end
if math_random(1, 16) == 1 then
local p = surface.find_non_colliding_position('medium-biter', event.entity.position, 2, 0.5)
if p then
surface.create_entity {name = 'medium-biter', position = event.entity.position}
end
return
end
if math_random(1, 32) == 1 then
local p = surface.find_non_colliding_position('big-biter', event.entity.position, 2, 0.5)
if p then
surface.create_entity {name = 'big-biter', position = event.entity.position}
end
return
end
if math_random(1, 512) == 1 then
local p = surface.find_non_colliding_position('behemoth-biter', event.entity.position, 2, 0.5)
if p then
surface.create_entity {name = 'behemoth-biter', position = event.entity.position}
end
return
end
end
if event.entity.type == 'simple-entity' then
if math_random(1, 8) == 1 then
surface.create_entity {name = 'small-worm-turret', position = event.entity.position}
return
end
if math_random(1, 16) == 1 then
surface.create_entity {name = 'medium-worm-turret', position = event.entity.position}
return
end
if math_random(1, 32) == 1 then
surface.create_entity {name = 'big-worm-turret', position = event.entity.position}
return
end
end
end
local function on_init()
local map_gen_settings = {}
map_gen_settings.moisture = 0.99
map_gen_settings.water = 'none'
map_gen_settings.starting_area = 'normal'
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
map_gen_settings.autoplace_controls = {
['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'}
}
game.create_surface('deep_jungle', map_gen_settings)
game.forces['player'].set_spawn_position({0, 0}, game.surfaces['deep_jungle'])
end
event.on_init(on_init)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
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)
require 'modules.rocks_yield_ore'

View File

@ -0,0 +1,508 @@
local Task = require 'utils.task'
local Token = require 'utils.token'
local Event = require 'utils.event'
local Terrain = require 'maps.deep_jungle.terrain'
local Public = {}
local force_chunk = false
local ceil = math.ceil
local queue_task = Task.queue_task
local tiles_per_call = 12
local total_calls = ceil(1024 / tiles_per_call)
local regen_decoratives = false
local generate_map = Terrain.heavy_functions
-- Set to false by modules that want to control the on_chunk_generated event themselves.
Public.enable_register_events = true
-- Simple "loop" that is UPS friendly.
local function get_position(data)
data.yv = data.yv + 1
if data.yv == 32 then
if data.xv == 32 then
data.xv = 0
end
if data.yv == 32 then
data.yv = 0
end
data.xv = data.xv + 1
end
data.position = {x = data.top_x + data.xv, y = data.top_y + data.yv}
end
local function do_tile_inner(tiles, tile, pos)
if type(tile) == 'string' then
tiles[#tiles + 1] = {name = tile, position = pos}
end
end
local function do_tile(x, y, data, shape)
local pos = {x, y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(data)
if type(tile) == 'table' then
do_tile_inner(data.tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
data.hidden_tiles[#data.hidden_tiles + 1] = {tile = hidden_tile, position = pos}
end
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
data.entities[#data.entities + 1] = entity
end
end
local buildings = tile.buildings
if buildings then
for _, entity in ipairs(buildings) do
if not entity.position then
entity.position = pos
end
data.buildings[#data.buildings + 1] = entity
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
data.decoratives[#data.decoratives + 1] = decorative
end
end
local markets = tile.markets
if markets then
for _, t in ipairs(markets) do
if not t.position then
t.position = pos
end
data.markets[#data.markets + 1] = t
end
end
local treasure = tile.treasure
if treasure then
for _, t in ipairs(treasure) do
if not t.position then
t.position = pos
end
data.treasure[#data.treasure + 1] = t
end
end
else
do_tile_inner(data.tiles, tile, pos)
end
end
local function do_row(row, data, shape)
local y = data.top_y + row
local top_x = data.top_x
local tiles = data.tiles
data.y = y
for x = top_x, top_x + 31 do
data.x = x
local pos = {data.x, data.y}
get_position(data)
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(data)
if type(tile) == 'table' then
do_tile_inner(tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
data.hidden_tiles[#data.hidden_tiles + 1] = {tile = hidden_tile, position = pos}
end
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
data.entities[#data.entities + 1] = entity
end
end
local buildings = tile.buildings
if buildings then
for _, entity in ipairs(buildings) do
if not entity.position then
entity.position = pos
end
data.buildings[#data.buildings + 1] = entity
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
if not decorative.position then
decorative.position = pos
end
data.decoratives[#data.decoratives + 1] = decorative
end
end
local markets = tile.markets
if markets then
for _, t in ipairs(markets) do
if not t.position then
t.position = pos
end
data.markets[#data.markets + 1] = t
end
end
local treasure = tile.treasure
if treasure then
for _, t in ipairs(treasure) do
if not t.position then
t.position = pos
end
data.treasure[#data.treasure + 1] = t
end
end
else
do_tile_inner(tiles, tile, pos)
end
end
end
local function do_place_tiles(data)
local surface = data.surface
surface.set_tiles(data.tiles, true)
end
local function do_place_hidden_tiles(data)
local surface = data.surface
surface.set_tiles(data.hidden_tiles, true)
end
local function do_place_decoratives(data)
local surface = data.surface
if regen_decoratives then
surface.regenerate_decorative(nil, {{data.top_x / 32, data.top_y / 32}})
end
local dec = data.decoratives
if #dec > 0 then
surface.create_decoratives({check_collision = true, decoratives = dec})
end
end
local function do_place_buildings(data)
local surface = data.surface
local entity
local callback
for _, e in ipairs(data.buildings) do
if e.e_type then
local p = e.position
if
surface.count_entities_filtered {
area = {{p.x - 32, p.y - 32}, {p.x + 32, p.y + 32}},
type = e.e_type,
limit = 1
} == 0
then
entity = surface.create_entity(e)
if entity and entity.valid then
if e.direction then
entity.direction = e.direction
end
if e.force then
entity.force = e.force
end
if e.callback then
local c = e.callback.callback
if c then
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback(entity)
else
callback = Token.get(c)
callback(entity, d)
end
end
end
end
end
end
end
end
local function do_place_entities(data)
local surface = data.surface
local entity
local callback
for _, e in ipairs(data.entities) do
if e.collision then
if surface.can_place_entity(e) then
entity = surface.create_entity(e)
if entity then
if e.direction then
entity.direction = e.direction
end
if e.force then
entity.force = e.force
end
if e.amount then
entity.amount = e.amount
end
if e.callback then
local c = e.callback.callback
if not c then
return
end
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback(entity)
else
callback = Token.get(c)
callback(entity, d)
end
end
end
end
else
entity = surface.create_entity(e)
if entity then
if e.direction then
entity.direction = e.direction
end
if e.force then
entity.force = e.force
end
if e.amount then
entity.amount = e.amount
end
if e.callback then
local c = e.callback.callback
if c then
local d = {callback_data = e.callback.data}
if not d then
callback = Token.get(c)
callback(entity)
else
callback = Token.get(c)
callback(entity, d)
end
end
end
end
end
end
end
local function run_chart_update(data)
local x = data.top_x / 32
local y = data.top_y / 32
local surface = data.surface
if not surface or not surface.valid then
return
end
if game.forces.player.is_chunk_charted(surface, {x, y}) then
-- Don't use full area, otherwise adjacent chunks get charted
game.forces.player.chart(
surface,
{
{data.top_x, data.top_y},
{data.top_x + 1, data.top_y + 1}
}
)
end
end
local function map_gen_action(data)
local state = data.y
if state < 32 then
local shape = generate_map
if shape == nil then
return false
end
if not data.surface.valid then
return
end
local count = tiles_per_call
local y = state + data.top_y
local x = data.x
local max_x = data.top_x + 32
data.y = y
repeat
count = count - 1
get_position(data)
do_tile(x, y, data, shape)
x = x + 1
if x == max_x then
y = y + 1
if y == data.top_y + 32 then
break
end
x = data.top_x
data.y = y
end
data.x = x
until count == 0
data.y = y - data.top_y
return true
elseif state == 32 then
do_place_tiles(data)
data.y = 33
return true
elseif state == 33 then
do_place_hidden_tiles(data)
data.y = 34
return true
elseif state == 34 then
do_place_entities(data)
data.y = 35
return true
elseif state == 35 then
do_place_buildings(data)
data.y = 36
return true
elseif state == 36 then
do_place_decoratives(data)
data.y = 37
return true
elseif state == 37 then
run_chart_update(data)
return false
end
end
local map_gen_action_token = Token.register(map_gen_action)
--- Adds generation of a Chunk of the map to the queue
-- @param event <table> the event table from on_chunk_generated
function Public.schedule_chunk(event)
local surface = event.surface
local shape = generate_map
if event.tick < 1 then
return
end
if not surface.valid then
return
end
if not shape then
return
end
local area = event.area
local data = {
yv = -0,
xv = 0,
y = 0,
x = area.left_top.x,
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
buildings = {},
decoratives = {},
markets = {},
treasure = {}
}
if not data.surface or not data.surface.valid then
return
end
queue_task(map_gen_action_token, data, total_calls)
end
--- Generates a Chunk of map when called
-- @param event <table> the event table from on_chunk_generated
function Public.do_chunk(event)
local surface = event.surface
local shape = generate_map
if not surface.valid then
return
end
if not shape then
return
end
local area = event.area
local data = {
yv = -0,
xv = 0,
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
buildings = {},
decoratives = {},
markets = {},
treasure = {}
}
if not data.surface.valid then
return
end
for row = 0, 31 do
do_row(row, data, shape)
end
do_place_tiles(data)
do_place_hidden_tiles(data)
do_place_entities(data)
do_place_buildings(data)
do_place_decoratives(data)
end
local do_chunk = Public.do_chunk
local schedule_chunk = Public.schedule_chunk
local function on_chunk(event)
if force_chunk then
do_chunk(event)
else
schedule_chunk(event)
end
end
Event.add(defines.events.on_chunk_generated, on_chunk)
return Public

142
maps/deep_jungle/main.lua Normal file
View File

@ -0,0 +1,142 @@
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'
local Global = require 'utils.global'
local Event = require 'utils.event'
local map_functions = require 'tools.map_functions'
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 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
return
end
this.chunks_charted[tostring(position.x) .. tostring(position.y)] = true
local decorative_names = {}
for k, v in pairs(deco) do
if v.autoplace_specification then
decorative_names[#decorative_names + 1] = k
end
end
surface.regenerate_decorative(decorative_names, {position})
if random(1, 14) ~= 1 then
return
end
map_functions.draw_rainbow_patch({x = position.x * 32 + random(1, 32), y = position.y * 32 + random(1, 32)}, surface, random(14, 26), 2000)
end
local function on_player_joined_game(event)
local player = game.get_player(event.player_index)
local surface = game.get_surface('deep_jungle')
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')
else
if player.online_time < 5 then
player.teleport({0, 0}, 'deep_jungle')
end
end
if player.online_time < 2 then
player.insert {name = 'iron-plate', count = 32}
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
surface.create_entity {name = 'small-biter', position = entity.position}
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
surface.create_entity {name = 'medium-biter', position = entity.position}
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
surface.create_entity {name = 'big-biter', position = entity.position}
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
surface.create_entity {name = 'behemoth-biter', position = entity.position}
end
return
end
end
if entity.type == 'simple-entity' then
if random(1, 8) == 1 then
surface.create_entity {name = 'small-worm-turret', position = entity.position}
return
end
if random(1, 16) == 1 then
surface.create_entity {name = 'medium-worm-turret', position = entity.position}
return
end
if random(1, 32) == 1 then
surface.create_entity {name = 'big-worm-turret', position = entity.position}
return
end
end
end
local function on_init()
local map_gen_settings = {}
map_gen_settings.moisture = 0.99
map_gen_settings.water = 'none'
map_gen_settings.starting_area = 'normal'
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
map_gen_settings.autoplace_controls = {
['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'}
}
game.create_surface('deep_jungle', map_gen_settings)
game.forces.player.set_spawn_position({0, 0}, game.surfaces['deep_jungle'])
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)
require 'modules.rocks_yield_ore'
return Public

View File

@ -0,0 +1,291 @@
local simplex_noise = require 'utils.simplex_noise'
local random = math.random
local Public = {}
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math.random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local function secret_shop(pos, surface)
local secret_market_items = {
{price = {{'coin', random(300, 600)}}, offer = {type = 'give-item', item = 'combat-shotgun'}},
{price = {{'coin', random(200, 400)}}, offer = {type = 'give-item', item = 'rocket-launcher'}},
{price = {{'coin', random(5, 10)}}, offer = {type = 'give-item', item = 'piercing-rounds-magazine'}},
--{price = {{"coin", random(150,250)}}, offer = {type = 'give-item', item = 'uranium-rounds-magazine'}},
{price = {{'coin', random(15, 30)}}, offer = {type = 'give-item', item = 'piercing-shotgun-shell'}},
{price = {{'coin', random(10, 20)}}, offer = {type = 'give-item', item = 'rocket'}},
{price = {{'coin', random(20, 30)}}, offer = {type = 'give-item', item = 'explosive-rocket'}},
{price = {{'coin', random(30, 60)}}, offer = {type = 'give-item', item = 'cluster-grenade'}},
{price = {{'coin', random(8, 16)}}, offer = {type = 'give-item', item = 'land-mine'}},
{price = {{'coin', random(200, 300)}}, offer = {type = 'give-item', item = 'heavy-armor'}},
{price = {{'coin', random(400, 800)}}, offer = {type = 'give-item', item = 'modular-armor'}},
{price = {{'coin', random(1000, 2000)}}, offer = {type = 'give-item', item = 'power-armor'}},
{price = {{'coin', random(2500, 5000)}}, offer = {type = 'give-item', item = 'fusion-reactor-equipment'}},
{price = {{'coin', random(200, 400)}}, offer = {type = 'give-item', item = 'battery-equipment'}},
{price = {{'coin', random(150, 250)}}, offer = {type = 'give-item', item = 'belt-immunity-equipment'}},
{price = {{'coin', random(100, 200)}}, offer = {type = 'give-item', item = 'night-vision-equipment'}},
{price = {{'coin', random(400, 800)}}, offer = {type = 'give-item', item = 'exoskeleton-equipment'}},
{price = {{'coin', random(200, 300)}}, offer = {type = 'give-item', item = 'personal-roboport-equipment'}},
{price = {{'coin', random(25, 50)}}, offer = {type = 'give-item', item = 'construction-robot'}},
-- {price = {{"coin", random(10000,20000)}}, offer = {type = 'give-item', item = 'energy-shield-equipment'}},
-- {price = {{"coin", random(5000,15000)}}, offer = {type = 'give-item', item = 'personal-laser-defense-equipment'}},
{price = {{'coin', random(100, 300)}}, offer = {type = 'give-item', item = 'loader'}},
{price = {{'coin', random(200, 400)}}, offer = {type = 'give-item', item = 'fast-loader'}},
{price = {{'coin', random(300, 500)}}, offer = {type = 'give-item', item = 'express-loader'}},
{price = {{'coin', random(150, 300)}}, offer = {type = 'give-item', item = 'locomotive'}},
{price = {{'coin', random(100, 200)}}, offer = {type = 'give-item', item = 'cargo-wagon'}},
{price = {{'coin', random(5, 15)}}, offer = {type = 'give-item', item = 'grenade'}},
{price = {{'coin', random(80, 160)}}, offer = {type = 'give-item', item = 'cliff-explosives'}},
{price = {{'coin', random(10, 20)}}, offer = {type = 'give-item', item = 'explosives', count = 50}},
{price = {{'coin', random(4, 8)}}, offer = {type = 'give-item', item = 'rail', count = 4}},
{price = {{'coin', random(20, 30)}}, offer = {type = 'give-item', item = 'train-stop'}},
{price = {{'coin', random(4, 12)}}, offer = {type = 'give-item', item = 'small-lamp'}},
{price = {{'coin', random(1, 4)}}, offer = {type = 'give-item', item = 'firearm-magazine'}},
{price = {{'coin', random(60, 150)}}, offer = {type = 'give-item', item = 'car', count = 1}},
{price = {{'coin', random(75, 150)}}, offer = {type = 'give-item', item = 'gun-turret', count = 1}},
{price = {{'coin', random(500, 750)}}, offer = {type = 'give-item', item = 'laser-turret', count = 1}},
{price = {{'coin', random(1000, 2000)}}, offer = {type = 'give-item', item = 'artillery-turret', count = 1}},
{price = {{'coin', random(100, 200)}}, offer = {type = 'give-item', item = 'artillery-shell', count = 1}},
{price = {{'coin', random(50, 150)}}, offer = {type = 'give-item', item = 'artillery-targeting-remote', count = 1}},
{price = {{'coin', random(5, 15)}}, offer = {type = 'give-item', item = 'shotgun-shell', count = 1}},
{price = {{'coin', random(8000, 16000)}}, offer = {type = 'give-item', item = 'power-armor-mk2', count = 1}},
{price = {{'coin', random(80, 160)}}, offer = {type = 'give-item', item = 'solar-panel-equipment', count = 1}},
{price = {{'coin', random(4, 8)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
{price = {{'coin', random(4, 8)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
{price = {{'coin', random(4, 8)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
{price = {{'coin', random(4, 8)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
{price = {{'coin', random(4, 8)}}, offer = {type = 'give-item', item = 'coal', count = 50}}
--{price = {{"coin", random(4,8)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}
}
secret_market_items = shuffle(secret_market_items)
local market = surface.create_entity {name = 'market', position = pos}
market.destructible = false
for i = 1, math.random(6, 10), 1 do
market.add_market_item(secret_market_items[i])
end
end
local function treasure_chest(position)
if not game.surfaces['deep_jungle'].can_place_entity({name = 'steel-chest', position = position, force = 'player'}) then
return
end
local treasure_chest_raffle_table = {}
local treasure_chest_loot_weights = {}
table.insert(treasure_chest_loot_weights, {{name = 'landfill', count = random(8, 16)}, 16})
table.insert(treasure_chest_loot_weights, {{name = 'iron-gear-wheel', count = random(16, 48)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'coal', count = random(16, 48)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'copper-cable', count = random(64, 128)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'inserter', count = random(4, 8)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'fast-inserter', count = random(4, 8)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'burner-inserter', count = random(4, 8)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'rocket-fuel', count = random(1, 5)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'small-electric-pole', count = random(4, 8)}, 7})
table.insert(treasure_chest_loot_weights, {{name = 'firearm-magazine', count = random(16, 48)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'submachine-gun', count = 1}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'grenade', count = random(6, 12)}, 5})
table.insert(treasure_chest_loot_weights, {{name = 'land-mine', count = random(8, 16)}, 5})
table.insert(treasure_chest_loot_weights, {{name = 'light-armor', count = 1}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'heavy-armor', count = 1}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'pipe', count = random(10, 100)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'explosives', count = random(40, 50)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'shotgun', count = 1}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'shotgun-shell', count = random(8, 16)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'stone-brick', count = random(80, 100)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'small-lamp', count = random(2, 4)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'rail', count = random(16, 48)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'coin', count = random(32, 320)}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-1', count = random(1, 3)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-2', count = random(1, 3)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-3', count = random(1, 2)}, 1})
for _, t in pairs(treasure_chest_loot_weights) do
for _ = 1, t[2], 1 do
table.insert(treasure_chest_raffle_table, t[1])
end
end
local e = game.surfaces['deep_jungle'].create_entity {name = 'wooden-chest', position = position, force = 'player'}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for _ = 1, random(3, 7), 1 do
local loot = treasure_chest_raffle_table[random(1, #treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function rare_treasure_chest(position)
if not game.surfaces['deep_jungle'].can_place_entity({name = 'steel-chest', position = position, force = 'player'}) then
return
end
local rare_treasure_chest_raffle_table = {}
local rare_treasure_chest_loot_weights = {}
table.insert(rare_treasure_chest_loot_weights, {{name = 'combat-shotgun', count = 1}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = random(8, 16)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket-launcher', count = 1}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = random(4, 8)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = random(4, 8)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'modular-armor', count = 1}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = random(32, 64)}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = random(4, 8)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = random(3, 5)}, 4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = random(2, 3)}, 3})
for _, t in pairs(rare_treasure_chest_loot_weights) do
for _ = 1, t[2], 1 do
table.insert(rare_treasure_chest_raffle_table, t[1])
end
end
local e = game.surfaces['deep_jungle'].create_entity {name = 'steel-chest', position = position, force = 'player'}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for _ = 1, random(2, 3), 1 do
local loot = rare_treasure_chest_raffle_table[random(1, #rare_treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function get_noise(name, pos)
local seed = game.surfaces[1].map_gen_settings.seed
local d2 = simplex_noise.d2
local noise_seed_add = 25000
if name == 1 then
local noise = {}
noise[1] = d2(pos.x * 0.001, pos.y * 0.001, seed)
seed = seed + noise_seed_add
noise[2] = d2(pos.x * 0.01, pos.y * 0.01, seed + noise_seed_add)
noise = noise[1] + noise[2] * 0.1
return noise
end
if name == 2 then
local noise = {}
noise[1] = d2(pos.x * 0.015, pos.y * 0.015, seed)
seed = seed + noise_seed_add
noise[2] = d2(pos.x * 0.15, pos.y * 0.15, seed + noise_seed_add)
noise = noise[1] + noise[2] * 0.2
return noise
end
if name == 3 then
local noise = {}
noise[1] = d2(pos.x * 0.025, pos.y * 0.025, seed)
seed = seed + noise_seed_add
noise[2] = d2(pos.x * 0.2, pos.y * 0.2, seed + noise_seed_add)
noise = noise[1] + noise[2] * 0.2
return noise
end
if name == 'greenwater' then
local noise = {}
noise[1] = d2(pos.x * 0.003, pos.y * 0.003, seed)
seed = seed + noise_seed_add
noise[2] = d2(pos.x * 0.03, pos.y * 0.03, seed + noise_seed_add)
noise = noise[1] + noise[2] * 0.1
return noise
end
end
local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'}
local tree_raffle = {'tree-04', 'tree-07', 'tree-09', 'tree-06', 'tree-04', 'tree-07', 'tree-09', 'tree-04'}
local function process_tile(pos)
local noise_1 = get_noise(1, pos)
if noise_1 > -0.03 and noise_1 < 0.03 then
return 'deepwater'
end
if noise_1 > -0.05 and noise_1 < 0.05 then
return 'water'
end
local noise_greenwater = get_noise('greenwater', pos)
if noise_greenwater > -0.035 and noise_greenwater < 0.035 then
return 'water-green'
end
if noise_1 > -0.08 and noise_1 < 0.08 then
return false
end
local noise_2 = get_noise(2, pos)
if noise_2 > 0.37 or noise_2 < -0.37 then
if random(1, 4) == 1 then
return false, tree_raffle[math.ceil(math.abs(noise_1 * 8))]
end
end
local noise_3 = get_noise(3, pos)
if noise_3 > 0.5 then
if random(1, 3) == 1 then
return false, rock_raffle[random(1, #rock_raffle)]
end
end
return false
end
local function process_bits(data)
local pos = data.position
local tiles = data.tiles
local entities = data.entities
local surface = game.surfaces['deep_jungle']
local treasure_chests = {}
local rare_treasure_chests = {}
local secret_shops = {}
local tile_to_insert, entity_to_place = process_tile(pos)
if entity_to_place then
entities[#entities + 1] = {name = entity_to_place, position = pos, force = 'player'}
end
if tile_to_insert then
tiles[#tiles + 1] = {name = tile_to_insert, position = pos}
if random(1, 40) == 1 and tile_to_insert == 'deepwater' then
entities[#entities + 1] = {name = 'fish', position = pos}
end
end
if random(1, 1500) == 1 then
table.insert(treasure_chests, pos)
end
if random(1, 16000) == 1 then
table.insert(rare_treasure_chests, pos)
end
if random(1, 8000) == 1 then
table.insert(secret_shops, pos)
end
for _, v in pairs(treasure_chests) do
treasure_chest(v)
end
for _, v in pairs(rare_treasure_chests) do
rare_treasure_chest(v)
end
for _, v in pairs(secret_shops) do
if not surface.get_tile(v).collides_with('player-layer') then
local area = {{v.x - 128, v.y - 128}, {v.x + 128, v.y + 128}}
if surface.count_entities_filtered({name = 'market', area = area}) == 0 then
secret_shop(v, surface)
end
end
end
end
function Public.heavy_functions(data)
local surface = data.surface
local map_name = 'deep_jungle'
if string.sub(surface.name, 0, #map_name) ~= map_name then
return
end
if not data.seed then
data.seed = surface.map_gen_settings.seed
end
process_bits(data)
end
return Public

View File

@ -1,477 +0,0 @@
--luacheck: ignore
--deep jungle-- mewmew made this --
local map_functions = require 'tools.map_functions'
local simplex_noise = require 'utils.simplex_noise'
simplex_noise = simplex_noise.d2
local event = require 'utils.event'
local math_random = math.random
local function treasure_chest(position)
local p = game.surfaces['deep_jungle'].find_non_colliding_position('wooden-chest', position, 2, 0.5)
if not p then
return
end
treasure_chest_raffle_table = {}
treasure_chest_loot_weights = {}
table.insert(treasure_chest_loot_weights, {{name = 'iron-gear-wheel', count = math_random(16, 48)}, 10})
table.insert(treasure_chest_loot_weights, {{name = 'coal', count = math_random(16, 48)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'copper-cable', count = math_random(64, 128)}, 10})
table.insert(treasure_chest_loot_weights, {{name = 'inserter', count = math_random(8, 16)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'fast-inserter', count = math_random(4, 8)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'stack-filter-inserter', count = math_random(2, 4)}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'stack-inserter', count = math_random(2, 4)}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'burner-inserter', count = math_random(16, 32)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'electric-engine-unit', count = math_random(1, 16)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'engine-unit', count = math_random(1, 16)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'rocket-fuel', count = math_random(1, 5)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'empty-barrel', count = math_random(1, 10)}, 7})
table.insert(treasure_chest_loot_weights, {{name = 'lubricant-barrel', count = math_random(1, 10)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'crude-oil-barrel', count = math_random(1, 10)}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'iron-stick', count = math_random(1, 100)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'small-electric-pole', count = math_random(8, 32)}, 9})
table.insert(treasure_chest_loot_weights, {{name = 'firearm-magazine', count = math_random(16, 48)}, 8})
table.insert(treasure_chest_loot_weights, {{name = 'grenade', count = math_random(16, 32)}, 5})
table.insert(treasure_chest_loot_weights, {{name = 'land-mine', count = math_random(24, 48)}, 5})
table.insert(treasure_chest_loot_weights, {{name = 'light-armor', count = 1}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'heavy-armor', count = 1}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'pipe', count = math_random(10, 100)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'wooden-chest', count = 1}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'burner-mining-drill', count = 1}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'iron-axe', count = 1}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'steel-axe', count = 1}, 3})
table.insert(treasure_chest_loot_weights, {{name = 'raw-wood', count = math_random(5, 50)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'sulfur', count = math_random(20, 50)}, 7})
table.insert(treasure_chest_loot_weights, {{name = 'explosives', count = math_random(20, 50)}, 6})
table.insert(treasure_chest_loot_weights, {{name = 'shotgun', count = 1}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'stone-brick', count = math_random(80, 100)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'small-lamp', count = math_random(3, 10)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'rail', count = math_random(32, 100)}, 4})
table.insert(treasure_chest_loot_weights, {{name = 'coin', count = math_random(32, 100)}, 1})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-1', count = math_random(1, 4)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-2', count = math_random(1, 3)}, 2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-3', count = math_random(1, 2)}, 1})
for _, t in pairs(treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
table.insert(treasure_chest_raffle_table, t[1])
end
end
local e = game.surfaces['deep_jungle'].create_entity {name = 'wooden-chest', position = p, force = 'player'}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(3, 7), 1 do
local loot = treasure_chest_raffle_table[math_random(1, #treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function rare_treasure_chest(position)
local p = game.surfaces['deep_jungle'].find_non_colliding_position('steel-chest', position, 2, 0.5)
if not p then
return
end
local rare_treasure_chest_raffle_table = {}
local rare_treasure_chest_loot_weights = {}
table.insert(rare_treasure_chest_loot_weights, {{name = 'combat-shotgun', count = 1}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = math_random(16, 48)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket-launcher', count = 1}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = math_random(16, 48)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = math_random(16, 48)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'modular-armor', count = 1}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'power-armor', count = 1}, 1})
table.insert(rare_treasure_chest_loot_weights, {{name = 'uranium-rounds-magazine', count = math_random(16, 48)}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = math_random(64, 128)}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'exoskeleton-equipment', count = 1}, 2})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = math_random(8, 16)}, 5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = math_random(4, 8)}, 4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = math_random(4, 8)}, 3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'atomic-bomb', count = 1}, 1})
for _, t in pairs(rare_treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
table.insert(rare_treasure_chest_raffle_table, t[1])
end
end
local e = game.surfaces['deep_jungle'].create_entity {name = 'steel-chest', position = p, force = 'player'}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(2, 3), 1 do
local loot = rare_treasure_chest_raffle_table[math_random(1, #rare_treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function get_noise(name, pos)
local seed = game.surfaces[1].map_gen_settings.seed
local noise_seed_add = 25000
seed = seed + noise_seed_add
if name == 1 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local noise = noise[1] + noise[2] * 0.1
return noise
end
seed = seed + noise_seed_add
seed = seed + noise_seed_add
if name == 2 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local noise = noise[1] + noise[2] * 0.1
return noise
end
seed = seed + noise_seed_add
seed = seed + noise_seed_add
if name == 3 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.001, pos.y * 0.001, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
local noise = noise[1] + noise[2] * 0.1
return noise
end
seed = seed + noise_seed_add
seed = seed + noise_seed_add
if name == 4 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local noise = noise[1] + noise[2] * 0.2
return noise
end
seed = seed + noise_seed_add
seed = seed + noise_seed_add
if name == 5 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local noise = noise[1]
return noise
end
seed = seed + noise_seed_add
seed = seed + noise_seed_add
if name == 6 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local noise = noise[1]
return noise
end
end
local worm_raffle = {'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret'}
local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'}
local function on_chunk_generated(event)
local surface = game.surfaces['deep_jungle']
if event.surface.name ~= surface.name then
return
end
local chunk_pos_x = event.area.left_top.x
local chunk_pos_y = event.area.left_top.y
local tiles = {}
local entities_to_place = {
rocks = {},
worms = {},
enemy_buildings = {},
trees = {},
fish = {},
treasure_chests = {},
rare_treasure_chests = {}
}
local decoratives = {}
local entities = surface.find_entities(event.area)
for _, e in pairs(entities) do
if e.type == 'tree' or e.force.name == 'enemy' then
e.destroy()
end
end
local tile_to_insert = false
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos_x = chunk_pos_x + x
local pos_y = chunk_pos_y + y
local pos = {x = pos_x, y = pos_y}
tile_to_insert = false
local noise_3 = get_noise(3, pos)
if noise_3 > -0.1 and noise_3 < 0.1 then
if noise_3 > -0.05 and noise_3 < 0.05 then
tile_to_insert = 'water'
if math_random(1, 40) == 1 then
table.insert(entities_to_place.fish, pos)
end
end
if noise_3 > -0.03 and noise_3 < 0.03 then
tile_to_insert = 'deepwater'
if math_random(1, 40) == 1 then
table.insert(entities_to_place.fish, pos)
end
end
else
local tile_distance_to_center = pos_x ^ 2 + pos_y ^ 2
local noise_1 = get_noise(1, pos)
local noise_2 = get_noise(2, pos)
local noise_4 = get_noise(4, pos)
if tile_distance_to_center > 10000 then
if math_random(1, 500) == 1 then
table.insert(entities_to_place.worms, pos)
end
if noise_4 > -0.1 and noise_4 < 0.1 and noise_1 > 0.3 and noise_2 > 0.3 then
if math_random(1, 8) == 1 then
table.insert(entities_to_place.rocks, pos)
end
end
end
if noise_4 < -0.8 or noise_4 > 0.8 then
tile_to_insert = 'dirt-6'
end
if noise_3 < -0.1 then
if noise_1 > 0.2 then
if math_random(1, 4) == 1 then
table.insert(entities_to_place.trees, {'tree-02', pos})
end
if math_random(1, 7500) == 1 then
table.insert(entities_to_place.rare_treasure_chests, pos)
end
if math_random(1, 1250) == 1 then
table.insert(entities_to_place.treasure_chests, pos)
end
if noise_1 > 0.8 and tile_distance_to_center > 8000 then
tile_to_insert = 'water-green'
if math_random(1, 24) == 1 then
table.insert(entities_to_place.fish, pos)
end
end
end
if noise_1 < -0.2 then
if math_random(1, 4) == 1 then
table.insert(entities_to_place.trees, {'tree-04', pos})
end
if math_random(1, 7500) == 1 then
table.insert(entities_to_place.rare_treasure_chests, pos)
end
if math_random(1, 1250) == 1 then
table.insert(entities_to_place.treasure_chests, pos)
end
if noise_1 < -0.75 and tile_distance_to_center > 8000 then
if math_random(1, 36) == 1 then
table.insert(entities_to_place.enemy_buildings, pos)
end
end
end
else
if noise_2 > 0.2 then
if math_random(1, 4) == 1 then
table.insert(entities_to_place.trees, {'tree-07', pos})
end
if math_random(1, 7500) == 1 then
table.insert(entities_to_place.rare_treasure_chests, pos)
end
if math_random(1, 1250) == 1 then
table.insert(entities_to_place.treasure_chests, pos)
end
if noise_2 > 0.75 and tile_distance_to_center > 8000 then
if math_random(1, 36) == 1 then
table.insert(entities_to_place.enemy_buildings, pos)
end
end
end
if noise_2 < -0.2 then
if math_random(1, 4) == 1 then
table.insert(entities_to_place.trees, {'tree-09', pos})
end
if math_random(1, 7500) == 1 then
table.insert(entities_to_place.rare_treasure_chests, pos)
end
if math_random(1, 1250) == 1 then
table.insert(entities_to_place.treasure_chests, pos)
end
if noise_2 < -0.8 and tile_distance_to_center > 8000 then
tile_to_insert = 'water-green'
if math_random(1, 24) == 1 then
table.insert(entities_to_place.fish, pos)
end
end
end
end
end
if tile_to_insert ~= 'deepwater' and tile_to_insert ~= 'water' and tile_to_insert ~= 'water-green' then
if math_random(1, 3) == 1 then
local noise = get_noise(5, pos)
if noise > 0.2 then
table.insert(decoratives, {name = 'green-hairy-grass', position = pos, amount = 2})
end
if noise < -0.7 then
table.insert(decoratives, {name = 'green-pita', position = pos, amount = 2})
end
local noise = get_noise(6, pos)
if noise > 0.7 then
table.insert(decoratives, {name = 'green-croton', position = pos, amount = 3})
end
if noise < -0.2 then
table.insert(decoratives, {name = 'green-asterisk', position = pos, amount = 2})
end
end
end
if tile_to_insert == false then
table.insert(tiles, {name = 'grass-1', position = {pos_x, pos_y}})
else
table.insert(tiles, {name = tile_to_insert, position = {pos_x, pos_y}})
end
end
end
surface.set_tiles(tiles, true)
surface.create_decoratives {check_collision = false, decoratives = decoratives}
for _, p in pairs(entities_to_place.enemy_buildings) do
if math_random(1, 3) == 1 then
if surface.can_place_entity({name = 'spitter-spawner', position = p}) then
surface.create_entity {name = 'spitter-spawner', position = p}
end
else
if surface.can_place_entity({name = 'biter-spawner', position = p}) then
surface.create_entity {name = 'biter-spawner', position = p}
end
end
end
for _, p in pairs(entities_to_place.worms) do
local e = worm_raffle[math_random(1, #worm_raffle)]
if surface.can_place_entity({name = e, position = p}) then
surface.create_entity {name = e, position = p}
end
end
for _, p in pairs(entities_to_place.rocks) do
local e = rock_raffle[math_random(1, #rock_raffle)]
surface.create_entity {name = e, position = p}
end
for _, p in pairs(entities_to_place.trees) do
if surface.can_place_entity({name = p[1], position = p[2]}) then
surface.create_entity {name = p[1], position = p[2]}
end
end
for _, p in pairs(entities_to_place.treasure_chests) do
treasure_chest(p)
end
for _, p in pairs(entities_to_place.rare_treasure_chests) do
rare_treasure_chest(p)
end
for _, p in pairs(entities_to_place.fish) do
surface.create_entity {name = 'fish', position = p}
end
end
local function on_chunk_charted(event)
if not global.chunks_charted then
global.chunks_charted = {}
end
local surface = game.surfaces[event.surface_index]
local position = event.position
if global.chunks_charted[tostring(position.x) .. tostring(position.y)] then
return
end
global.chunks_charted[tostring(position.x) .. tostring(position.y)] = true
local force = event.force
if math_random(1, 12) ~= 1 then
return
end
map_functions.draw_rainbow_patch({x = position.x * 32 + math_random(1, 32), y = position.y * 32 + math_random(1, 32)}, surface, math_random(14, 26), 2000)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not global.map_init_done then
game.forces['player'].technologies['flamethrower'].enabled = false
local map_gen_settings = {}
map_gen_settings.water = 'none'
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
map_gen_settings.autoplace_controls = {
['coal'] = {frequency = 'high', size = 'big', richness = 'normal'},
['stone'] = {frequency = 'high', size = 'big', richness = 'normal'},
['copper-ore'] = {frequency = 'high', size = 'big', richness = 'normal'},
['iron-ore'] = {frequency = 'high', size = 'big', richness = 'normal'},
['crude-oil'] = {frequency = 'high', size = 'big', richness = 'normal'},
['trees'] = {frequency = 'none', size = 'none', richness = 'none'},
['enemy-base'] = {frequency = 'none', size = 'none', richness = 'none'},
--["grass"] = {frequency = "none", size = "none", richness = "none"},
['sand'] = {frequency = 'none', size = 'none', richness = 'none'},
['desert'] = {frequency = 'none', size = 'none', richness = 'none'},
['dirt'] = {frequency = 'none', size = 'none', richness = 'none'}
}
game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.create_surface('deep_jungle', map_gen_settings)
game.forces['player'].set_spawn_position({0, 0}, game.surfaces['deep_jungle'])
global.map_init_done = true
end
local surface = game.surfaces['deep_jungle']
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')
else
if player.online_time < 5 then
player.teleport({0, 0}, 'deep_jungle')
end
end
if player.online_time < 10 then
player.insert {name = 'submachine-gun', count = 1}
player.insert {name = 'raw-fish', count = 12}
player.insert {name = 'firearm-magazine', count = 32}
player.insert {name = 'steel-axe', count = 1}
player.insert {name = 'light-armor', count = 1}
end
end
local function on_marked_for_deconstruction(event)
if event.entity.name == 'rock-huge' or event.entity.name == 'rock-big' or event.entity.name == 'sand-rock-big' or event.entity.name == 'fish' or event.entity.type == 'tree' then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
end
local function on_entity_died(event)
if event.entity.type == 'tree' then
if math_random(1, 6) == 1 then
local surface = game.surfaces['deep_jungle']
local p = surface.find_non_colliding_position('small-biter', event.entity.position, 2, 0.5)
if p then
surface.create_entity {name = 'small-biter', position = event.entity.position}
end
end
end
end
function cheat_mode()
local cheat_mode_enabed = true
if cheat_mode_enabed == true then
local surface = game.surfaces['deep_jungle']
game.player.cheat_mode = true
game.players[1].insert({name = 'power-armor-mk2'})
game.players[1].insert({name = 'fusion-reactor-equipment', count = 4})
game.players[1].insert({name = 'personal-laser-defense-equipment', count = 8})
game.players[1].insert({name = 'rocket-launcher'})
game.players[1].insert({name = 'explosive-rocket', count = 200})
game.speed = 2
surface.daytime = 1
game.player.force.research_all_technologies()
game.forces['enemy'].evolution_factor = 0.2
local chart = 300
local surface = game.surfaces['deep_jungle']
game.forces['player'].chart(surface, {lefttop = {x = chart * -1, y = chart * -1}, rightbottom = {x = chart, y = chart}})
end
end
event.add(defines.events.on_chunk_generated, on_chunk_generated)
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_marked_for_deconstruction, on_marked_for_deconstruction)
event.add(defines.events.on_player_joined_game, on_player_joined_game)