1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/maps/mountain_fortress_v2/terrain.lua

675 lines
26 KiB
Lua
Raw Normal View History

2019-10-07 04:37:23 +02:00
local math_random = math.random
2019-10-07 07:19:41 +02:00
local simplex_noise = require "utils.simplex_noise".d2
2019-10-25 08:09:39 +02:00
local rock_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
2019-10-07 04:37:23 +02:00
local spawner_raffle = {"biter-spawner", "biter-spawner", "biter-spawner", "spitter-spawner"}
2019-10-07 07:19:41 +02:00
local noises = {
2019-10-08 19:26:40 +02:00
["no_rocks"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
2019-10-10 19:33:32 +02:00
["no_rocks_2"] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}},
2019-10-08 19:26:40 +02:00
["large_caves"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
2019-10-25 11:37:56 +02:00
["small_caves"] = {{modifier = 0.008, weight = 1}, {modifier = 0.03, weight = 0.15}, {modifier = 0.25, weight = 0.05}},
["small_caves_2"] = {{modifier = 0.009, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.25, weight = 0.05}},
2019-10-07 09:48:17 +02:00
["cave_ponds"] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}},
2019-10-10 02:50:00 +02:00
["cave_rivers"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.25}, {modifier = 0.05, weight = 0.01}},
2019-10-25 11:37:56 +02:00
["cave_rivers_2"] = {{modifier = 0.003, weight = 1}, {modifier = 0.01, weight = 0.21}, {modifier = 0.05, weight = 0.01}},
2019-10-07 07:19:41 +02:00
}
2019-10-21 07:16:03 +02:00
local level_depth = 1024
local worm_level_modifier = 0.25
2019-10-07 04:37:23 +02:00
2019-10-07 07:19:41 +02:00
local function get_noise(name, pos, seed)
local noise = 0
local d = 0
for _, n in pairs(noises[name]) do
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
d = d + n.weight
seed = seed + 10000
2019-10-06 18:16:32 +02:00
end
2019-10-07 07:19:41 +02:00
noise = noise / d
return noise
end
2019-10-11 21:52:32 +02:00
local function get_replacement_tile(surface, position)
for i = 1, 128, 1 do
local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}}
table.shuffle_table(vectors)
for k, v in pairs(vectors) do
local tile = surface.get_tile(position.x + v[1], position.y + v[2])
if not tile.collides_with("resource-layer") then return tile.name end
end
end
return "grass-1"
end
2019-10-25 11:37:56 +02:00
local function process_level_6_position(p, seed, tiles, entities, markets, treasure)
2019-10-21 07:16:03 +02:00
local large_caves = get_noise("large_caves", p, seed)
if large_caves > -0.03 and large_caves < 0.03 then
tiles[#tiles + 1] = {name = "water-green", position = p}
if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
local cave_rivers = get_noise("cave_rivers", p, seed)
if cave_rivers > -0.05 and cave_rivers < 0.05 then
if math_random(1,48) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end
if math_random(1,768) == 1 then
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
else
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,8) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
if math_random(1,320) == 1 then treasure[#treasure + 1] = p end
if math_random(1,1536) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 1000} end
if math_random(1,4096) == 1 then markets[#markets + 1] = p end
end
end
2019-10-25 11:37:56 +02:00
local function process_level_5_position(p, seed, tiles, entities, markets, treasure)
2019-10-21 07:16:03 +02:00
local small_caves = get_noise("small_caves", p, seed)
2019-10-25 11:37:56 +02:00
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
2019-10-26 13:56:02 +02:00
if small_caves > -0.10 and small_caves < 0.10 then
2019-10-21 07:16:03 +02:00
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
if math_random(1,2) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
return
end
2019-10-25 11:37:56 +02:00
if small_caves < -0.50 or small_caves > 0.50 then
2019-10-21 07:16:03 +02:00
tiles[#tiles + 1] = {name = "deepwater-green", position = p}
if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end
if math_random(1,128) == 1 then
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
return
end
2019-10-25 11:37:56 +02:00
2019-10-26 13:56:02 +02:00
if small_caves > -0.30 and small_caves < 0.30 then
2019-10-25 11:37:56 +02:00
if noise_cave_ponds > 0.35 then
tiles[#tiles + 1] = {name = "dirt-" .. math.random(1, 4), position = p}
if math_random(1,128) == 1 then treasure[#treasure + 1] = p end
if math_random(1,256) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end
return
end
if noise_cave_ponds > 0.25 then
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
if math_random(1,2) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
return
end
end
2019-10-21 07:16:03 +02:00
tiles[#tiles + 1] = {name = "out-of-map", position = p}
end
2019-10-25 11:37:56 +02:00
local function process_level_4_position(p, seed, tiles, entities, markets, treasure)
local noise_large_caves = get_noise("large_caves", p, seed)
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
local small_caves = get_noise("small_caves", p, seed)
2019-10-21 07:16:03 +02:00
2019-10-25 11:37:56 +02:00
if math.abs(noise_large_caves) > 0.7 then
tiles[#tiles + 1] = {name = "water", position = p}
if math_random(1,16) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
if math.abs(noise_large_caves) > 0.6 then
if math_random(1,16) == 1 then entities[#entities + 1] = {name="tree-02", position=p} end
if math_random(1,32) == 1 then markets[#markets + 1] = p end
end
if math.abs(noise_large_caves) > 0.5 then
tiles[#tiles + 1] = {name = "grass-2", position = p}
if math_random(1,620) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end
if math_random(1,384) == 1 then
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
if math_random(1, 1024) == 1 then treasure[#treasure + 1] = p end
return
end
if math.abs(noise_large_caves) > 0.475 then
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,3) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
return
end
--Chasms
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.45 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.45 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
end
if small_caves > -0.15 and small_caves < 0.15 then
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,5) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
if math_random(1, 1024) == 1 then treasure[#treasure + 1] = p end
return
end
2019-10-21 07:16:03 +02:00
2019-10-25 11:37:56 +02:00
if noise_large_caves > -0.1 and noise_large_caves < 0.1 then
--Main Rock Terrain
local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000)
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p}
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,100) > 30 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
return
end
2019-10-08 19:26:40 +02:00
2019-10-25 11:37:56 +02:00
tiles[#tiles + 1] = {name = "out-of-map", position = p}
end
local function process_level_3_position(p, seed, tiles, entities, markets, treasure)
local small_caves = get_noise("small_caves", p, seed + 50000)
local small_caves_2 = get_noise("small_caves_2", p, seed + 70000)
local noise_large_caves = get_noise("large_caves", p, seed + 60000)
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
2019-10-10 02:50:00 +02:00
2019-10-25 11:37:56 +02:00
--Market Spots
if noise_cave_ponds < -0.77 then
if noise_cave_ponds > -0.79 then
tiles[#tiles + 1] = {name = "dirt-7", position = p}
entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p}
else
tiles[#tiles + 1] = {name = "grass-" .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p}
if math_random(1,32) == 1 then markets[#markets + 1] = p end
if math_random(1,16) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end
end
return
end
if noise_large_caves > -0.2 and noise_large_caves < 0.2 or small_caves_2 > 0 then
2019-10-08 19:26:40 +02:00
--Green Water Ponds
2019-10-07 09:48:17 +02:00
if noise_cave_ponds > 0.80 then
tiles[#tiles + 1] = {name = "deepwater-green", position = p}
if math_random(1,16) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
2019-10-10 02:50:00 +02:00
end
--Chasms
if noise_cave_ponds < 0.12 and noise_cave_ponds > -0.12 then
if small_caves > 0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
2019-10-25 11:37:56 +02:00
end
--Rivers
local cave_rivers = get_noise("cave_rivers", p, seed + 100000)
if cave_rivers < 0.014 and cave_rivers > -0.014 then
if noise_cave_ponds > 0.2 then
tiles[#tiles + 1] = {name = "water-shallow", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
end
local cave_rivers_2 = get_noise("cave_rivers_2", p, seed)
if cave_rivers_2 < 0.024 and cave_rivers_2 > -0.024 then
if noise_cave_ponds < 0.5 then
tiles[#tiles + 1] = {name = "water", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
end
if noise_cave_ponds > 0.775 then
tiles[#tiles + 1] = {name = "dirt-" .. math_random(4, 6), position = p}
return
end
local no_rocks = get_noise("no_rocks", p, seed + 25000)
--Worm oil Zones
if no_rocks < 0.15 and no_rocks > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p}
if math_random(1,320) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end
if math_random(1,50) == 1 then
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end
return
end
end
--Main Rock Terrain
local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000)
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p}
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,100) > 30 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
return
end
tiles[#tiles + 1] = {name = "out-of-map", position = p}
end
local function process_level_2_position(p, seed, tiles, entities, markets, treasure)
local small_caves = get_noise("small_caves", p, seed)
local noise_large_caves = get_noise("large_caves", p, seed)
if noise_large_caves > -0.75 and noise_large_caves < 0.75 then
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
--Chasms
if noise_cave_ponds < 0.13 and noise_cave_ponds > -0.13 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.35 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
2019-10-10 02:50:00 +02:00
end
2019-10-25 11:37:56 +02:00
--Green Water Ponds
if noise_cave_ponds > 0.80 then
tiles[#tiles + 1] = {name = "deepwater-green", position = p}
if math_random(1,16) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
2019-10-10 02:50:00 +02:00
--Rivers
local cave_rivers = get_noise("cave_rivers", p, seed + 100000)
2019-10-25 11:37:56 +02:00
if cave_rivers < 0.027 and cave_rivers > -0.027 then
if noise_cave_ponds < 0.1 then
2019-10-10 02:50:00 +02:00
tiles[#tiles + 1] = {name = "water-shallow", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
2019-10-07 09:48:17 +02:00
end
2019-10-08 19:26:40 +02:00
2019-10-25 11:37:56 +02:00
if noise_cave_ponds > 0.76 then
tiles[#tiles + 1] = {name = "dirt-" .. math_random(4, 6), position = p}
return
end
2019-10-08 19:26:40 +02:00
--Market Spots
2019-10-07 09:48:17 +02:00
if noise_cave_ponds < -0.80 then
2019-10-10 02:50:00 +02:00
tiles[#tiles + 1] = {name = "grass-" .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p}
2019-10-09 21:09:53 +02:00
if math_random(1,32) == 1 then markets[#markets + 1] = p end
2019-10-19 09:20:40 +02:00
if math_random(1,16) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end
2019-10-07 09:48:17 +02:00
return
end
2019-10-10 02:50:00 +02:00
local no_rocks = get_noise("no_rocks", p, seed + 25000)
2019-10-25 11:37:56 +02:00
--Worm oil Zones
if no_rocks < 0.15 and no_rocks > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p}
if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end
if math_random(1,64) == 1 then
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"}
2019-10-08 19:26:40 +02:00
end
2019-10-25 11:37:56 +02:00
if math_random(1,1024) == 1 then treasure[#treasure + 1] = p end
if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end
return
2019-10-08 19:26:40 +02:00
end
end
2019-10-07 22:40:05 +02:00
2019-10-25 11:37:56 +02:00
2019-10-21 07:16:03 +02:00
--Main Rock Terrain
2019-10-10 19:33:32 +02:00
local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000)
2019-10-19 09:20:40 +02:00
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p}
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
2019-10-21 07:16:03 +02:00
if math_random(1,100) > 30 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
2019-10-07 07:19:41 +02:00
return
end
2019-10-25 11:37:56 +02:00
tiles[#tiles + 1] = {name = "out-of-map", position = p}
end
local function process_level_1_position(p, seed, tiles, entities, markets, treasure)
local small_caves = get_noise("small_caves", p, seed)
local noise_large_caves = get_noise("large_caves", p, seed)
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
--Chasms
if noise_cave_ponds < 0.12 and noise_cave_ponds > -0.12 then
if small_caves > 0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
end
--Green Water Ponds
if noise_cave_ponds > 0.80 then
tiles[#tiles + 1] = {name = "deepwater-green", position = p}
2019-10-07 09:48:17 +02:00
if math_random(1,16) == 1 then entities[#entities + 1] = {name="fish", position=p} end
2019-10-07 07:19:41 +02:00
return
2019-10-25 11:37:56 +02:00
end
--Rivers
local cave_rivers = get_noise("cave_rivers", p, seed + 100000)
if cave_rivers < 0.024 and cave_rivers > -0.024 then
if noise_cave_ponds > 0 then
tiles[#tiles + 1] = {name = "water-shallow", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
2019-10-08 06:53:06 +02:00
end
2019-10-07 07:19:41 +02:00
end
2019-10-25 11:37:56 +02:00
if noise_cave_ponds > 0.76 then
tiles[#tiles + 1] = {name = "dirt-" .. math_random(4, 6), position = p}
return
end
--Market Spots
if noise_cave_ponds < -0.75 then
tiles[#tiles + 1] = {name = "grass-" .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p}
if math_random(1,32) == 1 then markets[#markets + 1] = p end
if math_random(1,32) == 1 then entities[#entities + 1] = {name = "tree-0" .. math_random(1, 9), position=p} end
2019-10-08 19:26:40 +02:00
return
end
2019-10-07 07:19:41 +02:00
2019-10-25 11:37:56 +02:00
local no_rocks = get_noise("no_rocks", p, seed + 25000)
--Worm oil Zones
if p.y < -64 + noise_cave_ponds * 10 then
if no_rocks < 0.08 and no_rocks > -0.08 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p}
if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = p, amount = math.abs(p.y) * 500} end
if math_random(1,96) == 1 then
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
if math_random(1,1024) == 1 then treasure[#treasure + 1] = p end
if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end
return
end
end
end
--Main Rock Terrain
local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000)
if no_rocks_2 > 0.70 or no_rocks_2 < -0.70 then
tiles[#tiles + 1] = {name = "dirt-" .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p}
if math_random(1,32) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,100) > 30 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
2019-10-06 18:16:32 +02:00
end
2019-10-25 11:37:56 +02:00
local levels = {
process_level_1_position,
process_level_2_position,
process_level_3_position,
process_level_4_position,
process_level_5_position,
process_level_6_position,
}
2019-10-07 04:37:23 +02:00
local function rock_chunk(surface, left_top)
2019-10-07 07:19:41 +02:00
local tiles = {}
local entities = {}
2019-10-07 09:48:17 +02:00
local markets = {}
local treasure = {}
2019-10-08 09:32:54 +02:00
local seed = surface.map_gen_settings.seed
2019-10-25 11:37:56 +02:00
local process_level = levels[math.floor(math.abs(left_top.y) / level_depth) + 1]
if not process_level then process_level = process_level_6_position end
2019-10-07 07:19:41 +02:00
for y = 0, 31, 1 do
for x = 0, 31, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
2019-10-25 11:37:56 +02:00
process_level(p, seed, tiles, entities, markets, treasure)
2019-10-07 07:19:41 +02:00
end
end
surface.set_tiles(tiles, true)
2019-10-08 19:26:40 +02:00
if #markets > 0 then
local position = markets[math_random(1, #markets)]
if surface.count_entities_filtered{area = {{position.x - 96, position.y - 96}, {position.x + 96, position.y + 96}}, name = "market", limit = 1} == 0 then
2019-10-12 02:19:37 +02:00
local market = mountain_market(surface, position, math.abs(position.y) * 0.004)
2019-10-08 19:26:40 +02:00
market.destructible = false
end
end
for _, p in pairs(treasure) do treasure_chest(surface, p) end
2019-10-07 07:19:41 +02:00
for _, e in pairs(entities) do
2019-10-08 09:32:54 +02:00
if game.entity_prototypes[e.name].type == "simple-entity" or game.entity_prototypes[e.name].type == "turret" then
2019-10-07 07:19:41 +02:00
surface.create_entity(e)
else
if surface.can_place_entity(e) then
surface.create_entity(e)
end
2019-10-07 04:37:23 +02:00
end
end
end
local function border_chunk(surface, left_top)
local trees = {"dead-grey-trunk", "dead-grey-trunk", "dry-tree"}
for x = 0, 31, 1 do
for y = 5, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
if math_random(1, math.ceil(pos.y + pos.y) + 64) == 1 then
surface.create_entity({name = trees[math_random(1, #trees)], position = pos})
end
end
end
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
if math_random(1, pos.y + 2) == 1 then
surface.create_decoratives{
check_collision=false,
decoratives={
{name = "rock-medium", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))}
}
}
end
if math_random(1, pos.y + 2) == 1 then
surface.create_decoratives{
check_collision=false,
decoratives={
{name = "rock-small", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))}
}
}
end
if math_random(1, pos.y + 2) == 1 then
surface.create_decoratives{
check_collision=false,
decoratives={
{name = "rock-tiny", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))}
}
}
end
if math_random(1, math.ceil(pos.y + pos.y) + 2) == 1 then
surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = pos})
end
end
end
2019-10-07 09:48:17 +02:00
for _, e in pairs(surface.find_entities_filtered({area = {{left_top.x, left_top.y},{left_top.x + 32, left_top.y + 32}}, type = "cliff"})) do e.destroy() end
2019-10-07 04:37:23 +02:00
end
local function biter_chunk(surface, left_top)
local tile_positions = {}
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
tile_positions[#tile_positions + 1] = p
end
end
2019-10-25 08:09:39 +02:00
for i = 1, 1, 1 do
2019-10-07 04:37:23 +02:00
local position = surface.find_non_colliding_position("biter-spawner", tile_positions[math_random(1, #tile_positions)], 16, 2)
if position then
2019-10-08 23:50:57 +02:00
local e = surface.create_entity({name = spawner_raffle[math_random(1, #spawner_raffle)], position = position})
e.destructible = false
e.active = false
2019-10-07 04:37:23 +02:00
end
end
2019-10-25 08:09:39 +02:00
--for _, e in pairs(surface.find_entities_filtered({area = {{left_top.x, left_top.y},{left_top.x + 32, left_top.y + 32}}, type = "cliff"})) do e.destroy() end
2019-10-07 04:37:23 +02:00
end
2019-10-11 21:52:32 +02:00
local function replace_water(surface, left_top)
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
if surface.get_tile(p).collides_with("resource-layer") then
surface.set_tiles({{name = get_replacement_tile(surface, p), position = p}}, true)
end
end
end
end
2019-10-07 04:37:23 +02:00
local function out_of_map(surface, left_top)
for x = 0, 31, 1 do
for y = 0, 31, 1 do
surface.set_tiles({{name = "out-of-map", position = {x = left_top.x + x, y = left_top.y + y}}})
end
end
end
2019-10-21 07:16:03 +02:00
2019-10-17 00:06:18 +02:00
local function wall(surface, left_top, seed)
local entities = {}
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
local small_caves = get_noise("small_caves", p, seed)
local cave_ponds = get_noise("cave_rivers", p, seed + 100000)
if y > 9 + cave_ponds * 6 and y < 23 + small_caves * 6 then
2019-10-21 07:16:03 +02:00
if small_caves > 0.10 or cave_ponds > 0.10 then
--surface.set_tiles({{name = "water-shallow", position = p}})
surface.set_tiles({{name = "deepwater", position = p}})
if math_random(1,48) == 1 then surface.create_entity({name = "fish", position = p}) end
2019-10-17 00:06:18 +02:00
else
surface.set_tiles({{name = "dirt-7", position = p}})
if math_random(1, 5) ~= 1 then
surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = p})
end
end
else
surface.set_tiles({{name = "dirt-7", position = p}})
if surface.can_place_entity({name = "stone-wall", position = p, force = "enemy"}) then
if math_random(1,512) == 1 and y > 3 and y < 28 then
treasure_chest(surface, p)
else
2019-10-21 07:16:03 +02:00
2019-10-25 11:37:56 +02:00
if y < 5 or y > 26 then
2019-10-17 00:06:18 +02:00
if y <= 15 then
if math_random(1, y + 1) == 1 then
2019-10-26 15:36:13 +02:00
local e = surface.create_entity({name = "stone-wall", position = p, force = "player"})
2019-10-21 07:16:03 +02:00
e.minable = false
2019-10-17 00:06:18 +02:00
end
else
if math_random(1, 32 - y) == 1 then
2019-10-26 15:36:13 +02:00
local e = surface.create_entity({name = "stone-wall", position = p, force = "player"})
2019-10-21 07:16:03 +02:00
e.minable = false
2019-10-17 00:06:18 +02:00
end
end
end
2019-10-21 07:16:03 +02:00
2019-10-17 00:06:18 +02:00
end
end
2019-10-21 07:16:03 +02:00
if math_random(1, 16) == 1 then
2019-10-17 00:06:18 +02:00
if surface.can_place_entity({name = "small-worm-turret", position = p, force = "enemy"}) then
2019-10-21 07:16:03 +02:00
wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier)
2019-10-17 00:06:18 +02:00
surface.create_entity({name = wave_defense_roll_worm_name(), position = p, force = "enemy"})
end
2019-10-25 11:37:56 +02:00
end
if math_random(1, 32) == 1 then
if surface.can_place_entity({name = "gun-turret", position = p, force = "enemy"}) then
local e = surface.create_entity({name = "gun-turret", position = p, force = "enemy"})
if math.abs(p.y) < level_depth * 2.5 then
e.insert({name = "piercing-rounds-magazine", count = math.random(64, 128)})
else
e.insert({name = "uranium-rounds-magazine", count = math.random(64, 128)})
end
end
end
2019-10-17 00:06:18 +02:00
end
end
end
end
2019-10-21 07:16:03 +02:00
2019-10-07 16:40:52 +02:00
local function process_chunk(surface, left_top)
2019-10-09 03:25:00 +02:00
if not surface then return end
if not surface.valid then return end
2019-10-09 21:09:53 +02:00
if left_top.x >= 768 then return end
if left_top.x < -768 then return end
2019-10-17 00:06:18 +02:00
2019-10-21 07:16:03 +02:00
if left_top.y % level_depth == 0 and left_top.y < 0 and left_top.y > level_depth * -6 then wall(surface, left_top, surface.map_gen_settings.seed) return end
2019-10-17 00:06:18 +02:00
2019-10-11 21:52:32 +02:00
if left_top.y >= 0 then replace_water(surface, left_top) end
if left_top.y > 32 then game.forces.player.chart(surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) end
2019-10-17 00:06:18 +02:00
if left_top.y == -128 and left_top.x == -128 then
2019-10-07 04:37:23 +02:00
local p = global.locomotive.position
2019-10-13 12:57:54 +02:00
for _, entity in pairs(surface.find_entities_filtered({area = {{p.x - 3, p.y - 4},{p.x + 3, p.y + 10}}, type = "simple-entity"})) do entity.destroy() end
2019-10-07 04:37:23 +02:00
end
if left_top.y < 0 then rock_chunk(surface, left_top) return end
2019-10-09 21:09:53 +02:00
if left_top.y > 96 then out_of_map(surface, left_top) return end
2019-10-08 23:50:57 +02:00
if left_top.y > 64 then biter_chunk(surface, left_top) return end
2019-10-07 04:37:23 +02:00
if left_top.y >= 0 then border_chunk(surface, left_top) return end
end
2019-10-16 00:23:54 +02:00
--[[
2019-10-07 04:37:23 +02:00
local function process_chunk_queue()
2019-10-09 03:25:00 +02:00
for k, chunk in pairs(global.chunk_queue) do
process_chunk(game.surfaces[chunk.surface_index], chunk.left_top)
2019-10-07 04:37:23 +02:00
global.chunk_queue[k] = nil
return
end
end
2019-10-17 00:06:18 +02:00
2019-10-16 00:23:54 +02:00
local function process_chunk_queue()
local chunk = global.chunk_queue[#global.chunk_queue]
if not chunk then return end
process_chunk(game.surfaces[chunk.surface_index], chunk.left_top)
global.chunk_queue[#global.chunk_queue] = nil
end
2019-10-17 00:06:18 +02:00
]]
2019-10-07 04:37:23 +02:00
2019-10-06 18:16:32 +02:00
local function on_chunk_generated(event)
2019-10-07 16:40:52 +02:00
if event.surface.index == 1 then return end
2019-10-16 00:23:54 +02:00
process_chunk(event.surface, event.area.left_top)
--global.chunk_queue[#global.chunk_queue + 1] = {left_top = {x = event.area.left_top.x, y = event.area.left_top.y}, surface_index = event.surface.index}
2019-10-06 18:16:32 +02:00
end
local event = require 'utils.event'
2019-10-11 21:52:32 +02:00
event.on_nth_tick(4, process_chunk_queue)
2019-10-06 18:16:32 +02:00
event.add(defines.events.on_chunk_generated, on_chunk_generated)