2020-02-14 21:06:52 +01:00
--require "maps.chronosphere.ores"
2020-02-19 15:15:16 +01:00
local Ores = require " maps.chronosphere.ores "
2020-03-05 15:56:59 +01:00
local Specials = require " maps.chronosphere.terrain_specials "
2020-02-14 21:06:52 +01:00
local math_random = math.random
local math_floor = math.floor
2020-04-01 05:24:22 +02:00
local math_min = math.min
2020-02-14 21:06:52 +01:00
local math_abs = math.abs
local math_sqrt = math.sqrt
local level_depth = 960
2020-02-19 15:15:16 +01:00
local lake_noise_value = - 0.9
local labyrinth_cell_size = 32 --valid values are 2, 4, 8, 16, 32
2020-02-14 21:06:52 +01:00
local Treasure = require ' maps.chronosphere.treasure '
local simplex_noise = require " utils.simplex_noise " . d2
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 " }
local size_of_rock_raffle = # rock_raffle
local dead_tree_raffle = { " dead-dry-hairy-tree " , " dead-grey-trunk " , " dead-tree-desert " , " dry-hairy-tree " , " dry-tree " }
local tree_raffle = { " tree-01 " , " tree-02 " , " tree-02-red " , " tree-03 " , " tree-04 " , " tree-05 " , " tree-06 " , " tree-06-brown " , " tree-07 " ,
" tree-08 " , " tree-08-brown " , " tree-08-red " , " tree-09 " , " tree-09-brown " , " tree-09-red " }
local s_tree_raffle = # tree_raffle
local spawner_raffle = { " biter-spawner " , " biter-spawner " , " biter-spawner " , " spitter-spawner " }
local worm_raffle = {
" small-worm-turret " , " small-worm-turret " , " medium-worm-turret " , " small-worm-turret " ,
" medium-worm-turret " , " medium-worm-turret " , " big-worm-turret " , " medium-worm-turret " ,
" big-worm-turret " , " big-worm-turret " , " behemoth-worm-turret " , " big-worm-turret " ,
" behemoth-worm-turret " , " behemoth-worm-turret " , " behemoth-worm-turret " , " big-worm-turret " , " behemoth-worm-turret "
}
local scrap_entities = { " crash-site-assembling-machine-1-broken " , " crash-site-assembling-machine-2-broken " , " crash-site-assembling-machine-1-broken " , " crash-site-assembling-machine-2-broken " , " crash-site-lab-broken " ,
" medium-ship-wreck " , " small-ship-wreck " , " medium-ship-wreck " , " small-ship-wreck " , " medium-ship-wreck " , " small-ship-wreck " , " medium-ship-wreck " , " small-ship-wreck " ,
" crash-site-chest-1 " , " crash-site-chest-2 " , " crash-site-chest-1 " , " crash-site-chest-2 " , " crash-site-chest-1 " , " crash-site-chest-2 " }
local scrap_entities_index = # scrap_entities
2020-02-19 15:15:16 +01:00
local maze_things_raffle = { " camp " , " lab " , " treasure " , " crashsite " }
2020-02-14 21:06:52 +01:00
local noises = {
[ " 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 } } ,
[ " no_rocks_2 " ] = { { modifier = 0.013 , weight = 1 } , { modifier = 0.1 , weight = 0.1 } } ,
[ " 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 } } ,
[ " 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 } } ,
[ " cave_ponds " ] = { { modifier = 0.01 , weight = 1 } , { modifier = 0.1 , weight = 0.06 } } ,
[ " cave_rivers " ] = { { modifier = 0.005 , weight = 1 } , { modifier = 0.01 , weight = 0.25 } , { modifier = 0.05 , weight = 0.01 } } ,
[ " cave_rivers_2 " ] = { { modifier = 0.003 , weight = 1 } , { modifier = 0.01 , weight = 0.21 } , { modifier = 0.05 , weight = 0.01 } } ,
[ " cave_rivers_3 " ] = { { modifier = 0.002 , weight = 1 } , { modifier = 0.01 , weight = 0.15 } , { modifier = 0.05 , weight = 0.01 } } ,
[ " cave_rivers_4 " ] = { { modifier = 0.001 , weight = 1 } , { modifier = 0.01 , weight = 0.11 } , { modifier = 0.05 , weight = 0.01 } } ,
[ " scrapyard " ] = { { modifier = 0.005 , weight = 1 } , { modifier = 0.01 , weight = 0.35 } , { modifier = 0.05 , weight = 0.23 } , { modifier = 0.1 , weight = 0.11 } } ,
[ " forest_location " ] = { { modifier = 0.006 , weight = 1 } , { modifier = 0.01 , weight = 0.25 } , { modifier = 0.05 , weight = 0.15 } , { modifier = 0.1 , weight = 0.05 } } ,
[ " forest_density " ] = { { modifier = 0.01 , weight = 1 } , { modifier = 0.05 , weight = 0.5 } , { modifier = 0.1 , weight = 0.025 } } ,
2020-02-19 15:15:16 +01:00
[ " ores " ] = { { modifier = 0.05 , weight = 1 } , { modifier = 0.02 , weight = 0.55 } , { modifier = 0.05 , weight = 0.05 } } ,
[ " hedgemaze " ] = { { modifier = 0.001 , weight = 1 } }
}
local modifiers = {
{ x = 0 , y = - 1 } , { x = - 1 , y = 0 } , { x = 1 , y = 0 } , { x = 0 , y = 1 }
}
local modifiers_diagonal = {
{ diagonal = { x = - 1 , y = 1 } , connection_1 = { x = - 1 , y = 0 } , connection_2 = { x = 0 , y = 1 } } ,
{ diagonal = { x = 1 , y = - 1 } , connection_1 = { x = 1 , y = 0 } , connection_2 = { x = 0 , y = - 1 } } ,
{ diagonal = { x = 1 , y = 1 } , connection_1 = { x = 1 , y = 0 } , connection_2 = { x = 0 , y = 1 } } ,
{ diagonal = { x = - 1 , y = - 1 } , connection_1 = { x = - 1 , y = 0 } , connection_2 = { x = 0 , y = - 1 } }
2020-02-14 21:06:52 +01:00
}
local function pos_to_key ( position )
return tostring ( position.x .. " _ " .. position.y )
end
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
end
noise = noise / d
return noise
end
local function get_size_of_ore ( ore , planet )
local base_size = 0.04 + 0.04 * planet [ 1 ] . ore_richness.factor
local final_size = 1
2020-02-20 23:19:00 +01:00
if planet [ 1 ] . name.id == 1 and ore == " iron-ore " then --iron planet
2020-02-14 21:06:52 +01:00
final_size = base_size * 5
2020-02-20 23:19:00 +01:00
elseif planet [ 1 ] . name.id == 2 and ore == " copper-ore " then --copper planet
2020-02-14 21:06:52 +01:00
final_size = base_size * 5
2020-02-20 23:19:00 +01:00
elseif planet [ 1 ] . name.id == 3 and ore == " stone " then --stone planet
2020-02-14 21:06:52 +01:00
final_size = base_size * 5
2020-02-20 23:19:00 +01:00
elseif planet [ 1 ] . name.id == 9 and ore == " coal " then --coal planet
2020-02-14 21:06:52 +01:00
final_size = base_size * 5
2020-02-20 23:19:00 +01:00
elseif planet [ 1 ] . name.id == 5 and ore == " uranium-ore " then --uranium planet
2020-02-14 21:06:52 +01:00
final_size = base_size * 5
2020-02-20 23:19:00 +01:00
elseif planet [ 1 ] . name.id == 6 then --mixed planet
2020-02-14 21:06:52 +01:00
final_size = base_size * 2
else
final_size = base_size / 2
end
return final_size
end
2020-02-19 15:15:16 +01:00
local function get_path_connections_count ( cell_pos )
local connections = 0
for _ , m in pairs ( modifiers ) do
if global.lab_cells [ tostring ( cell_pos.x + m.x ) .. " _ " .. tostring ( cell_pos.y + m.y ) ] then
connections = connections + 1
end
end
return connections
end
local function process_labyrinth_cell ( pos , seed )
local cell_position = { x = pos.x / labyrinth_cell_size , y = pos.y / labyrinth_cell_size }
local mazenoise = get_noise ( " hedgemaze " , cell_position , seed )
if mazenoise < lake_noise_value and math_sqrt ( ( pos.x / 32 ) ^ 2 + ( pos.y / 32 ) ^ 2 ) > 65 then return false end
global.lab_cells [ tostring ( cell_position.x ) .. " _ " .. tostring ( cell_position.y ) ] = false
for _ , modifier in pairs ( modifiers_diagonal ) do
if global.lab_cells [ tostring ( cell_position.x + modifier.diagonal . x ) .. " _ " .. tostring ( cell_position.y + modifier.diagonal . y ) ] then
local connection_1 = global.lab_cells [ tostring ( cell_position.x + modifier.connection_1 . x ) .. " _ " .. tostring ( cell_position.y + modifier.connection_1 . y ) ]
local connection_2 = global.lab_cells [ tostring ( cell_position.x + modifier.connection_2 . x ) .. " _ " .. tostring ( cell_position.y + modifier.connection_2 . y ) ]
if not connection_1 and not connection_2 then
return false
end
end
end
for _ , m in pairs ( modifiers ) do
if get_path_connections_count ( { x = cell_position.x + m.x , y = cell_position.y + m.y } ) >= math_random ( 2 , 3 ) then return false end
end
if get_path_connections_count ( cell_position ) >= math_random ( 2 , 3 ) then return false end
global.lab_cells [ tostring ( cell_position.x ) .. " _ " .. tostring ( cell_position.y ) ] = true
return true
end
2020-03-05 15:56:59 +01:00
local function process_dangerevent_position ( p , seed , tiles , entities , treasure , planet )
local scrapyard = get_noise ( " scrapyard " , p , seed )
--Chasms
local noise_cave_ponds = get_noise ( " cave_ponds " , p , seed )
local small_caves = get_noise ( " small_caves " , p , seed )
if noise_cave_ponds < 0.15 and noise_cave_ponds > - 0.15 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
end
if scrapyard < - 0.20 or scrapyard > 0.20 then
if math_random ( 1 , 128 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 50 then
entities [ # entities + 1 ] = { name = " gun-turret " , position = p , force = " scrapyard " }
end
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
if scrapyard < - 0.38 or scrapyard > 0.38 then
if math_random ( 1 , 36 ) == 1 then entities [ # entities + 1 ] = { name = scrap_entities [ math_random ( 1 , scrap_entities_index ) ] , position = p , force = " enemy " } end
if math_random ( 1 , 6 ) == 1 then entities [ # entities + 1 ] = { name = " mineable-wreckage " , position = p } end
return
end
return
end
local cave_ponds = get_noise ( " cave_ponds " , p , seed )
if cave_ponds < - 0.6 and scrapyard > - 0.2 and scrapyard < 0.2 then
tiles [ # tiles + 1 ] = { name = " deepwater-green " , position = p }
if math_random ( 1 , 128 ) == 1 then entities [ # entities + 1 ] = { name = " fish " , position = p } end
return
end
local large_caves = get_noise ( " large_caves " , p , seed )
if scrapyard > - 0.15 and scrapyard < 0.15 then
if math_floor ( large_caves * 10 ) % 4 < 3 then
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
return
end
end
2020-04-01 05:24:22 +02:00
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
tiles [ # tiles + 1 ] = { name = " stone-path " , position = p }
2020-03-05 15:56:59 +01:00
end
2020-02-19 15:15:16 +01:00
local function process_hedgemaze_position ( p , seed , tiles , entities , treasure , planet , cell , things )
--local labyrinth_cell_size = 16 --valid values are 2, 4, 8, 16, 32
local biters = planet [ 1 ] . name.biters
local mazenoise = get_noise ( " hedgemaze " , { x = p.x - p.x % labyrinth_cell_size , y = p.y - p.y % labyrinth_cell_size } , seed )
if mazenoise < lake_noise_value and math_sqrt ( ( p.x - p.x % labyrinth_cell_size ) ^ 2 + ( p.y - p.y % labyrinth_cell_size ) ^ 2 ) > 65 then
tiles [ # tiles + 1 ] = { name = " deepwater " , position = p }
if math_random ( 1 , 256 ) == 1 then entities [ # entities + 1 ] = { name = " fish " , position = p } end
return
elseif mazenoise > 0.7 then
if cell then --path
if things then
if things == " lake " and p.x % 32 > 8 and p.x % 32 < 24 and p.y % 32 > 8 and p.y % 32 < 24 then
tiles [ # tiles + 1 ] = { name = " water " , position = p }
return
elseif things == " prospect " then
2020-02-20 23:19:00 +01:00
if math_random ( 1 , 252 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 300 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
2020-02-19 15:15:16 +01:00
elseif things == " camp " then
if p.x % 32 > 12 and p.x % 32 < 20 and p.y % 32 > 12 and p.y % 32 < 20 and math_random ( 1 , 6 ) == 1 then
treasure [ # treasure + 1 ] = p
end
elseif things == " crashsite " then
if math_random ( 1 , 10 ) == 1 then
entities [ # entities + 1 ] = { name = " mineable-wreckage " , position = p }
end
elseif things == " treasure " then
local roll = math_random ( 1 , 128 )
if roll == 1 then
treasure [ # treasure + 1 ] = p
elseif roll == 2 then
entities [ # entities + 1 ] = { name = " land-mine " , position = p , force = " scrapyard " }
end
end
else
2020-02-20 23:19:00 +01:00
if math_random ( 1 , 150 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 200 then
2020-02-19 15:15:16 +01:00
entities [ # entities + 1 ] = { name = worm_raffle [ math_random ( 1 + math_floor ( game.forces [ " enemy " ] . evolution_factor * 8 ) , math_floor ( 1 + game.forces [ " enemy " ] . evolution_factor * 16 ) ) ] , position = p }
end
end
tiles [ # tiles + 1 ] = { name = " dirt-4 " , position = p }
else --wall
tiles [ # tiles + 1 ] = { name = " dirt-6 " , position = p }
if math_random ( 1 , 3 ) == 1 then
entities [ # entities + 1 ] = { name = " dead-tree-desert " , position = p }
else
if math_random ( 1 , 4 ) == 1 then entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , # rock_raffle ) ] , position = p } end
end
end
else
if cell then --path
if things then
if things == " lake " and p.x % 32 > 8 and p.x % 32 < 24 and p.y % 32 > 8 and p.y % 32 < 24 then
tiles [ # tiles + 1 ] = { name = " water " , position = p }
return
elseif things == " prospect " then
2020-02-20 23:19:00 +01:00
if math_random ( 1 , 252 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 300 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
2020-02-19 15:15:16 +01:00
elseif things == " camp " then
if p.x % 32 > 12 and p.x % 32 < 20 and p.y % 32 > 12 and p.y % 32 < 20 and math_random ( 1 , 6 ) == 1 then
treasure [ # treasure + 1 ] = p
end
elseif things == " crashsite " then
if math_random ( 1 , 10 ) == 1 then
entities [ # entities + 1 ] = { name = " mineable-wreckage " , position = p }
end
elseif things == " treasure " then
if math_random ( 1 , 128 ) == 1 then
treasure [ # treasure + 1 ] = p
end
end
else
2020-02-20 23:19:00 +01:00
if math_random ( 1 , 150 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 200 then
2020-02-19 15:15:16 +01:00
entities [ # entities + 1 ] = { name = worm_raffle [ math_random ( 1 + math_floor ( game.forces [ " enemy " ] . evolution_factor * 8 ) , math_floor ( 1 + game.forces [ " enemy " ] . evolution_factor * 16 ) ) ] , position = p }
end
end
tiles [ # tiles + 1 ] = { name = " grass-1 " , position = p }
else --wall
tiles [ # tiles + 1 ] = { name = " grass-2 " , position = p }
if math_random ( 1 , 3 ) == 1 then
entities [ # entities + 1 ] = { name = " tree-04 " , position = p }
else
if math_random ( 1 , 4 ) == 1 then entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , # rock_raffle ) ] , position = p } end
end
end
end
end
2020-02-14 21:06:52 +01:00
local function process_rocky_position ( p , seed , tiles , entities , treasure , planet )
local biters = planet [ 1 ] . name.biters
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 )
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
end
if math_abs ( noise_large_caves ) > 0.5 then
tiles [ # tiles + 1 ] = { name = " grass-2 " , position = p }
2020-02-19 15:15:16 +01:00
if math_random ( 1 , 122 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 150 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
2020-02-14 21:06:52 +01:00
if math_random ( 1 , 1024 ) == 1 then treasure [ # treasure + 1 ] = p end
return
end
if math_abs ( noise_large_caves ) > 0.375 then
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
2020-03-17 21:36:00 +01:00
if math_random ( 1 , 5 ) > 1 then entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , size_of_rock_raffle ) ] , position = p } end
2020-02-14 21:06:52 +01:00
if math_random ( 1 , 2048 ) == 1 then treasure [ # treasure + 1 ] = p end
return
end
--Chasms
if noise_cave_ponds < 0.25 and noise_cave_ponds > - 0.25 then
if small_caves > 0.75 then
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
return
end
if small_caves < - 0.75 then
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
return
end
end
if small_caves > - 0.25 and small_caves < 0.25 then
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
local roll = math_random ( 1 , 1000 )
2020-03-17 21:36:00 +01:00
if roll > 830 then
2020-02-14 21:06:52 +01:00
entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , size_of_rock_raffle ) ] , position = p }
2020-03-17 21:36:00 +01:00
elseif roll > 820 and math_sqrt ( p.x * p.x + p.y * p.y ) > 150 then
2020-02-14 21:06:52 +01:00
entities [ # entities + 1 ] = { name = worm_raffle [ math_random ( 1 + math_floor ( game.forces [ " enemy " ] . evolution_factor * 8 ) , math_floor ( 1 + game.forces [ " enemy " ] . evolution_factor * 16 ) ) ] , position = p }
else
end
if math_random ( 1 , 1024 ) == 1 then treasure [ # treasure + 1 ] = p end
return
end
if noise_large_caves > - 0.28 and noise_large_caves < 0.28 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 }
2020-03-17 21:36:00 +01:00
if math_random ( 1 , 100 ) > 50 then entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , size_of_rock_raffle ) ] , position = p } end
2020-02-14 21:06:52 +01:00
return
end
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
end
local function process_forest_position ( p , seed , tiles , entities , treasure , planet )
local biters = planet [ 1 ] . name.biters
local noise_forest_location = get_noise ( " forest_location " , p , seed )
if noise_forest_location > 0.095 then
if noise_forest_location > 0.6 then
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = " tree-08-brown " , position = p } end
else
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = " tree-01 " , position = p } end
end
return
else
if math_random ( 1 , 152 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 250 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
end
if noise_forest_location < - 0.095 then
if noise_forest_location < - 0.6 then
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = " tree-04 " , position = p } end
else
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = " tree-02-red " , position = p } end
end
return
else
if math_random ( 1 , 152 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 250 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
end
end
local function process_river_position ( p , seed , tiles , entities , treasure , planet )
local biters = planet [ 1 ] . name.biters
2020-03-14 08:55:13 +01:00
local richness = math_random ( 50 + 20 * global.objective . chronojumps , 100 + 20 * global.objective . chronojumps ) * planet [ 1 ] . ore_richness.factor * 0.5
2020-02-17 00:46:22 +01:00
local iron_size = get_size_of_ore ( " iron-ore " , planet ) * 3
local copper_size = get_size_of_ore ( " copper-ore " , planet ) * 3
local stone_size = get_size_of_ore ( " stone " , planet ) * 3
local coal_size = get_size_of_ore ( " coal " , planet ) * 4
2020-02-14 21:06:52 +01:00
if not biters then biters = 4 end
local large_caves = get_noise ( " large_caves " , p , seed )
local cave_rivers = get_noise ( " cave_rivers " , p , seed )
local ores = get_noise ( " ores " , p , seed )
local noise_forest_location = get_noise ( " forest_location " , p , seed )
--Chasms
local noise_cave_ponds = get_noise ( " cave_ponds " , p , seed )
local small_caves = get_noise ( " small_caves " , p , seed )
if noise_cave_ponds < 0.45 and noise_cave_ponds > - 0.45 then
if small_caves > 0.75 then
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
return
end
if small_caves < - 0.75 then
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
return
end
end
if large_caves > - 0.05 and large_caves < 0.05 and cave_rivers < 0.25 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
2020-02-17 00:46:22 +01:00
elseif large_caves > - 0.20 and large_caves < 0.20 and math_abs ( cave_rivers ) < 0.95 then
2020-02-14 21:06:52 +01:00
if ores > - coal_size and ores < coal_size then
entities [ # entities + 1 ] = { name = " coal " , position = p , amount = richness }
end
end
if cave_rivers > - 0.70 and cave_rivers < 0.70 then
if math_random ( 1 , 48 ) == 1 then entities [ # entities + 1 ] = { name = " tree-0 " .. math_random ( 1 , 9 ) , position = p } end
if cave_rivers > - 0.05 and cave_rivers < 0.05 then
if ores > - iron_size and ores < iron_size then
entities [ # entities + 1 ] = { name = " iron-ore " , position = p , amount = richness }
end
elseif cave_rivers > - 0.10 and cave_rivers < 0.10 then
if ores > - copper_size and ores < copper_size then
entities [ # entities + 1 ] = { name = " copper-ore " , position = p , amount = richness }
end
end
else
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
if ores > - stone_size and ores < stone_size then
entities [ # entities + 1 ] = { name = " stone " , position = p , amount = richness }
end
if math_random ( 1 , 52 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 200 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
if math_random ( 1 , 2048 ) == 1 then treasure [ # treasure + 1 ] = p end
end
if noise_forest_location > 0.9 then
local tree = tree_raffle [ math_random ( 1 , s_tree_raffle ) ]
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p } end
return
end
if noise_forest_location < - 0.9 then
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p } end
return
end
end
local function process_biter_position ( p , seed , tiles , entities , treasure , planet )
local scrapyard = get_noise ( " scrapyard " , p , seed )
local noise_forest_location = get_noise ( " forest_location " , p , seed )
local large_caves = get_noise ( " large_caves " , p , seed )
local biters = planet [ 1 ] . name.biters
local ore_size = planet [ 1 ] . ore_richness.factor
2020-02-17 00:46:22 +01:00
local handicap = 0
if global.objective . chronojumps < 5 then handicap = 150 end
2020-02-14 21:06:52 +01:00
if scrapyard < - 0.75 or scrapyard > 0.75 then
2020-02-17 00:46:22 +01:00
if math_random ( 1 , 52 - biters ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 150 + handicap then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
2020-02-14 21:06:52 +01:00
end
if scrapyard > - 0.05 - 0.01 * ore_size and scrapyard < 0.05 + 0.01 * ore_size then
if math_random ( 1 , 20 ) == 1 then entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , size_of_rock_raffle ) ] , position = p } end
end
2020-02-17 00:46:22 +01:00
if scrapyard + 0.5 > - 0.1 - 0.1 * planet [ 1 ] . name.moisture and scrapyard + 0.5 < 0.1 + 0.1 * planet [ 1 ] . name.moisture then
local treetypes = tree_raffle [ math_random ( 1 , s_tree_raffle ) ]
2020-02-20 23:19:00 +01:00
if planet [ 1 ] . name.id == 14 then treetypes = dead_tree_raffle [ math_random ( 1 , 5 ) ] end --lava planet
2020-03-05 15:56:59 +01:00
if math_random ( 1 , 100 ) > 42 - handicap / 6 then
if math_random ( 1 , 800 ) == 1 then
treasure [ # treasure + 1 ] = p
else
entities [ # entities + 1 ] = { name = treetypes , position = p }
end
end
2020-02-14 21:06:52 +01:00
end
if scrapyard > - 0.10 and scrapyard < 0.10 then
if math_floor ( large_caves * 10 ) % 4 < 3 then
local jumps = global.objective . chronojumps * 5
if global.objective . chronojumps > 20 then jumps = 100 end
local roll = math_random ( 1 , 200 - jumps - biters )
2020-02-17 00:46:22 +01:00
if math_sqrt ( p.x * p.x + p.y * p.y ) > 200 + handicap then
2020-02-14 21:06:52 +01:00
if roll == 1 then
entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p }
elseif roll == 2 then
entities [ # entities + 1 ] = { name = worm_raffle [ math_random ( 1 + math_floor ( game.forces [ " enemy " ] . evolution_factor * 8 ) , math_floor ( 1 + game.forces [ " enemy " ] . evolution_factor * 16 ) ) ] , position = p }
2020-02-17 00:46:22 +01:00
elseif roll == 3 then
--if math_random(1, 1024) == 1 then treasure[#treasure + 1] = p end
2020-02-14 21:06:52 +01:00
end
return
end
end
end
end
local function process_scrapyard_position ( p , seed , tiles , entities , treasure , planet )
local scrapyard = get_noise ( " scrapyard " , p , seed )
local biters = planet [ 1 ] . name.biters
--Chasms
local noise_cave_ponds = get_noise ( " cave_ponds " , p , seed )
local small_caves = get_noise ( " small_caves " , p , seed )
if noise_cave_ponds < 0.15 and noise_cave_ponds > - 0.15 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
end
if scrapyard < - 0.25 or scrapyard > 0.25 then
if math_random ( 1 , 256 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 50 then
2020-02-17 17:37:22 +01:00
entities [ # entities + 1 ] = { name = " gun-turret " , position = p , force = " scrapyard " }
2020-02-14 21:06:52 +01:00
end
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
if scrapyard < - 0.55 or scrapyard > 0.55 then
2020-02-17 00:46:22 +01:00
if math_random ( 1 , 40 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 150 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
2020-02-14 21:06:52 +01:00
return
end
if scrapyard + 0.5 > - 0.05 - 0.1 * planet [ 1 ] . name.moisture and scrapyard + 0.5 < 0.05 + 0.1 * planet [ 1 ] . name.moisture then
if math_random ( 1 , 100 ) > 42 then entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p } end
end
if scrapyard < - 0.28 or scrapyard > 0.28 then
2020-03-22 22:30:29 +01:00
if math_random ( 1 , 48 ) == 1 then entities [ # entities + 1 ] = { name = scrap_entities [ math_random ( 1 , scrap_entities_index ) ] , position = p , force = " enemy " } end
if math_random ( 1 , 3 ) == 1 then entities [ # entities + 1 ] = { name = " mineable-wreckage " , position = p } end
2020-02-14 21:06:52 +01:00
return
end
return
end
local cave_ponds = get_noise ( " cave_ponds " , p , seed )
if cave_ponds < - 0.6 and scrapyard > - 0.2 and scrapyard < 0.2 then
tiles [ # tiles + 1 ] = { name = " deepwater-green " , position = p }
if math_random ( 1 , 128 ) == 1 then entities [ # entities + 1 ] = { name = " fish " , position = p } end
return
end
local large_caves = get_noise ( " large_caves " , p , seed )
if scrapyard > - 0.15 and scrapyard < 0.15 then
if math_floor ( large_caves * 10 ) % 4 < 3 then
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
local jumps = global.objective . chronojumps * 5
if global.objective . chronojumps > 20 then jumps = 100 end
2020-02-17 00:46:22 +01:00
if math_random ( 1 , 200 - jumps ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 150 then entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p } end
2020-02-14 21:06:52 +01:00
return
end
end
2020-04-01 05:24:22 +02:00
tiles [ # tiles + 1 ] = { name = " dirt-7 " , position = p }
tiles [ # tiles + 1 ] = { name = " stone-path " , position = p }
2020-02-14 21:06:52 +01:00
end
2020-02-24 07:13:38 +01:00
local function process_swamp_position ( p , seed , tiles , entities , treasure , planet )
local scrapyard = get_noise ( " scrapyard " , p , seed )
local biters = planet [ 1 ] . name.biters
if scrapyard < - 0.70 or scrapyard > 0.70 then
tiles [ # tiles + 1 ] = { name = " grass-3 " , position = p }
2020-03-05 15:56:59 +01:00
if math_random ( 1 , 40 ) == 1 then treasure [ # treasure + 1 ] = p end
2020-02-24 07:13:38 +01:00
return
end
2020-03-05 15:56:59 +01:00
if scrapyard < - 0.65 or scrapyard > 0.65 then
2020-02-24 07:13:38 +01:00
tiles [ # tiles + 1 ] = { name = " water-green " , position = p }
return
end
2020-03-05 15:56:59 +01:00
if math_abs ( scrapyard ) > 0.50 and math_abs ( scrapyard ) < 0.65 then
if math_random ( 1 , 70 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 140 then entities [ # entities + 1 ] = { name = worm_raffle [ math_random ( 1 + math_floor ( game.forces [ " enemy " ] . evolution_factor * 8 ) , math_floor ( 1 + game.forces [ " enemy " ] . evolution_factor * 16 ) ) ] , position = p } end
2020-02-24 07:13:38 +01:00
tiles [ # tiles + 1 ] = { name = " water-mud " , position = p }
return
end
2020-03-05 15:56:59 +01:00
if math_abs ( scrapyard ) > 0.35 and math_abs ( scrapyard ) < 0.50 then
if math_random ( 1 , 140 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 140 then entities [ # entities + 1 ] = { name = worm_raffle [ math_random ( 1 + math_floor ( game.forces [ " enemy " ] . evolution_factor * 8 ) , math_floor ( 1 + game.forces [ " enemy " ] . evolution_factor * 16 ) ) ] , position = p } end
2020-02-24 07:13:38 +01:00
tiles [ # tiles + 1 ] = { name = " water-shallow " , position = p }
return
end
2020-03-05 15:56:59 +01:00
if scrapyard > - 0.15 and scrapyard < 0.15 then
if math_random ( 1 , 100 ) > 58 then
2020-02-24 07:13:38 +01:00
entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p }
else
2020-03-05 15:56:59 +01:00
if math_random ( 1 , 8 ) == 1 then entities [ # entities + 1 ] = { name = rock_raffle [ math_random ( 1 , size_of_rock_raffle ) ] , position = p } end
2020-02-24 07:13:38 +01:00
end
tiles [ # tiles + 1 ] = { name = " grass-1 " , position = p }
return
end
2020-03-05 15:56:59 +01:00
if math_random ( 1 , 160 ) == 1 and math_sqrt ( p.x * p.x + p.y * p.y ) > 150 then
2020-02-24 07:13:38 +01:00
entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p }
end
tiles [ # tiles + 1 ] = { name = " grass-2 " , position = p }
end
2020-02-21 22:58:14 +01:00
local function process_fish_position ( p , seed , tiles , entities , treasure , planet )
local body_radius = 1984 --3072
local body_square_radius = body_radius ^ 2
local body_center_position = { x = 0 , y = 0 }
local body_spacing = math_floor ( body_radius * 0.82 )
local body_circle_center_1 = { x = body_center_position.x , y = body_center_position.y - body_spacing }
local body_circle_center_2 = { x = body_center_position.x , y = body_center_position.y + body_spacing }
local fin_radius = 200
local square_fin_radius = fin_radius ^ 2
local fin_circle_center_1 = { x = - 600 , y = 0 }
local fin_circle_center_2 = { x = - 600 - 120 , y = 0 }
--if math_abs(p.y) > 480 and p.x <= 160 and p.x > body_center_position.x then return true end
--Main Fish Body
local distance_to_center_1 = ( ( p.x - body_circle_center_1.x ) ^ 2 + ( p.y - body_circle_center_1.y ) ^ 2 )
local distance_to_center_2 = ( ( p.x - body_circle_center_2.x ) ^ 2 + ( p.y - body_circle_center_2.y ) ^ 2 )
local distance_to_fin_1 = ( ( p.x - fin_circle_center_1.x ) ^ 2 + ( p.y - fin_circle_center_1.y ) ^ 2 )
local distance_to_fin_2 = ( ( p.x - fin_circle_center_2.x ) ^ 2 + ( p.y - fin_circle_center_2.y ) ^ 2 )
local eye_center = { x = - 500 , y = - 150 }
if distance_to_center_1 < body_square_radius and distance_to_center_2 < body_square_radius then
if p.x < - 600 and p.x > - 1090 and p.y < 64 and p.y > - 64 then --mouth
local noise = simplex_noise ( p.x * 0.006 , 0 , seed ) * 20
if p.y <= 12 + noise and p.y >= - 12 + noise then
tiles [ # tiles + 1 ] = { name = " water " , position = p }
else
tiles [ # tiles + 1 ] = { name = " grass-1 " , position = p }
local roll = math_random ( 1 , 500 )
if roll < 4 and p.x > - 800 then
entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p }
elseif roll == 5 and p.x > - 800 then
entities [ # entities + 1 ] = { name = " behemoth-worm-turret " , position = p }
elseif roll == 6 then
entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p }
end
end
else
local distance = math_sqrt ( ( ( eye_center.x - p.x ) ^ 2 ) + ( ( eye_center.y - p.y ) ^ 2 ) )
if distance < 33 and distance >= 15 then --eye
tiles [ # tiles + 1 ] = { name = " water-green " , position = p }
elseif distance < 15 then --eye
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
else --rest
tiles [ # tiles + 1 ] = { name = " grass-1 " , position = p }
local roll = math_random ( 1 , 500 )
if roll < 4 and p.x > - 800 then
entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p }
elseif roll == 5 and p.x > - 800 then
entities [ # entities + 1 ] = { name = " behemoth-worm-turret " , position = p }
elseif roll == 6 then
entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p }
end
end
end
-- elseif distance_to_fin_2 < square_fin_radius and distance_to_fin_1 + math_abs(simplex_noise(0, p.y * 0.075, seed) * 32000) > square_fin_radius then
-- tiles[#tiles + 1 ] = {name = "dirt-7", position = p}
else
if p.x > 800 and math_abs ( p.y ) < p.x - 800 then --tail
tiles [ # tiles + 1 ] = { name = " grass-1 " , position = p }
local roll = math_random ( 1 , 500 )
if roll < 4 and p.x > - 800 then
entities [ # entities + 1 ] = { name = spawner_raffle [ math_random ( 1 , 4 ) ] , position = p }
elseif roll == 5 and p.x > - 800 then
entities [ # entities + 1 ] = { name = " behemoth-worm-turret " , position = p }
elseif roll == 6 then
entities [ # entities + 1 ] = { name = tree_raffle [ math_random ( 1 , s_tree_raffle ) ] , position = p }
end
else
tiles [ # tiles + 1 ] = { name = " out-of-map " , position = p }
end
end
end
2020-02-14 21:06:52 +01:00
local levels = {
process_level_1_position ,
2020-03-05 15:56:59 +01:00
process_dangerevent_position ,
2020-02-19 15:15:16 +01:00
process_hedgemaze_position ,
2020-02-14 21:06:52 +01:00
process_rocky_position ,
process_forest_position ,
process_river_position ,
process_biter_position ,
process_scrapyard_position ,
2020-02-24 07:13:38 +01:00
process_swamp_position ,
2020-02-21 22:58:14 +01:00
process_fish_position ,
2020-02-14 21:06:52 +01:00
}
local entity_functions = {
[ " turret " ] = function ( surface , entity ) surface.create_entity ( entity ) end ,
[ " simple-entity " ] = function ( surface , entity ) surface.create_entity ( entity ) end ,
[ " ammo-turret " ] = function ( surface , entity )
local e = surface.create_entity ( entity )
e.insert ( { name = " uranium-rounds-magazine " , count = math_random ( 16 , 64 ) } )
end ,
[ " container " ] = function ( surface , entity )
Treasure ( surface , entity.position , entity.name )
end ,
2020-02-19 15:15:16 +01:00
[ " lab " ] = function ( surface , entity )
local e = surface.create_entity ( entity )
2020-04-01 05:24:22 +02:00
local evo = 1 + math_min ( math_floor ( global.objective . chronojumps / 4 ) , 4 )
2020-02-19 15:15:16 +01:00
local research = {
{ " automation-science-pack " , " logistic-science-pack " } ,
{ " automation-science-pack " , " logistic-science-pack " , " military-science-pack " } ,
{ " automation-science-pack " , " logistic-science-pack " , " military-science-pack " , " chemical-science-pack " } ,
{ " automation-science-pack " , " logistic-science-pack " , " military-science-pack " , " chemical-science-pack " , " production-science-pack " } ,
{ " automation-science-pack " , " logistic-science-pack " , " military-science-pack " , " chemical-science-pack " , " production-science-pack " , " utility-science-pack " }
}
for _ , science in pairs ( research [ evo ] ) do
2020-04-01 05:24:22 +02:00
e.insert ( { name = science , count = math_random ( math_min ( 32 + global.objective . chronojumps , 100 ) , math_min ( 64 + global.objective . chronojumps , 200 ) ) } )
2020-02-19 15:15:16 +01:00
end
end ,
2020-02-14 21:06:52 +01: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
2020-03-05 15:56:59 +01:00
if global.objective . planet [ 1 ] . name.id == 18 then return " grass-2 " end
2020-02-14 21:06:52 +01:00
return " grass-1 "
end
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
local function forest_chunk ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local treasure = { }
local seed = surface.map_gen_settings . seed
local process_level = levels [ level ]
for y = 0.5 , 31.5 , 1 do
for x = 0.5 , 31.5 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet )
end
end
surface.set_tiles ( tiles , true )
for _ , entity in pairs ( entities ) do
if surface.can_place_entity ( entity ) then
local e = surface.create_entity ( entity )
2020-02-17 17:37:22 +01:00
if e.name == " biter-spawner " or e.name == " spitter-spawner " or e.name == " small-worm-turret " or e.name == " medium-worm-turret " or e.name == " big-worm-turret " or e.name == " behemoth-worm-turret " then
2020-02-14 21:06:52 +01:00
if math_abs ( e.position . x ) > 420 or math_abs ( e.position . y ) > 420 then e.destructible = false end
end
end
end
end
local function biter_chunk ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local treasure = { }
local seed = surface.map_gen_settings . seed
local process_level = levels [ level ]
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet )
end
end
2020-02-17 00:46:22 +01:00
for _ , p in pairs ( treasure ) do
local name = " wooden-chest "
if math_random ( 1 , 6 ) == 1 then name = " iron-chest " end
Treasure ( surface , p , name )
end
2020-02-14 21:06:52 +01:00
surface.set_tiles ( tiles , true )
for _ , entity in pairs ( entities ) do
if surface.can_place_entity ( entity ) then
local e = surface.create_entity ( entity )
2020-02-17 17:37:22 +01:00
if e.name == " biter-spawner " or e.name == " spitter-spawner " or e.name == " small-worm-turret " or e.name == " medium-worm-turret " or e.name == " big-worm-turret " or e.name == " behemoth-worm-turret " then
2020-02-14 21:06:52 +01:00
if math_abs ( e.position . x ) > 420 or math_abs ( e.position . y ) > 420 then e.destructible = false end
end
end
end
end
local function empty_chunk ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local treasure = { }
local seed = surface.map_gen_settings . seed
local process_level = levels [ level ]
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
2020-02-19 15:15:16 +01:00
if planet [ 1 ] . name.id == 16 then
process_level ( p , seed , tiles , entities , treasure , planet , true , nil )
else
process_level ( p , seed , tiles , entities , treasure , planet )
end
2020-02-14 21:06:52 +01:00
end
end
surface.set_tiles ( tiles , true )
replace_water ( surface , left_top )
2020-03-05 15:56:59 +01:00
if planet [ 1 ] . name.id == 18 and left_top.y > 31 and left_top.x > 31 then
for x = 1 , 5 , 1 do
for y = 1 , 5 , 1 do
local pos = { x = left_top.x + x , y = left_top.y + y }
surface.set_tiles ( { { name = " deepwater-green " , position = pos } } )
end
end
end
end
local function danger_chunk ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local treasure = { }
local seed = surface.map_gen_settings . seed
local process_level = levels [ level ]
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet )
end
end
surface.set_tiles ( tiles , true )
replace_water ( surface , left_top )
Specials.danger_event ( surface , left_top )
2020-02-14 21:06:52 +01:00
end
2020-02-21 22:58:14 +01:00
local function fish_market ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local seed = surface.map_gen_settings . seed
local process_level = levels [ level ]
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet )
end
end
surface.set_tiles ( tiles , true )
2020-03-05 15:56:59 +01:00
Specials.fish_market ( surface , left_top )
2020-02-21 22:58:14 +01:00
end
local function fish_chunk ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local treasure = { }
local seed = surface.map_gen_settings . seed
local process_level = levels [ level ]
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet )
end
end
surface.set_tiles ( tiles , true )
for _ , p in pairs ( treasure ) do
local name = " wooden-chest "
if math_random ( 1 , 6 ) == 1 then name = " iron-chest " end
Treasure ( surface , p , name )
end
for _ , entity in pairs ( entities ) do
if entity_functions [ game.entity_prototypes [ entity.name ] . type ] then
entity_functions [ game.entity_prototypes [ entity.name ] . type ] ( surface , entity )
else
if surface.can_place_entity ( entity ) then
local e = surface.create_entity ( entity )
end
end
end
end
2020-02-14 21:06:52 +01:00
local function normal_chunk ( surface , left_top , level , planet )
local tiles = { }
local entities = { }
local treasure = { }
local seed = surface.map_gen_settings . seed
2020-02-19 15:15:16 +01:00
local process_level = levels [ level ]
if planet [ 1 ] . name.id == 16 then
local cell = false
local roll = math_random ( 1 , 20 )
local things = nil
if roll == 1 then
things = maze_things_raffle [ math_random ( 1 , 4 ) ]
elseif roll == 2 then
things = " lake "
elseif roll > 10 then
things = " prospect "
end
if process_labyrinth_cell ( left_top , seed ) then
cell = true
if things == " prospect " then
Ores.prospect_ores ( nil , surface , { x = left_top.x + 16 , y = left_top.y + 16 } )
elseif things == " camp " or things == " lab " then
local positions = {
{ x = left_top.x + 9 , y = left_top.y + 9 } , { x = left_top.x + 9 , y = left_top.y + 16 } , { x = left_top.x + 9 , y = left_top.y + 23 } ,
{ x = left_top.x + 16 , y = left_top.y + 9 } , { x = left_top.x + 16 , y = left_top.y + 23 } ,
{ x = left_top.x + 23 , y = left_top.y + 9 } , { x = left_top.x + 23 , y = left_top.y + 16 } , { x = left_top.x + 23 , y = left_top.y + 23 }
}
for i = 1 , 8 , 1 do
entities [ # entities + 1 ] = { name = " gun-turret " , position = positions [ i ] , force = " scrapyard " }
end
if things == " lab " then
entities [ # entities + 1 ] = { name = " lab " , position = { x = left_top.x + 15 , y = left_top.y + 15 } , force = " neutral " }
end
end
end
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet , cell , things )
end
end
else
for y = 0 , 31 , 1 do
for x = 0 , 31 , 1 do
local p = { x = left_top.x + x , y = left_top.y + y }
process_level ( p , seed , tiles , entities , treasure , planet )
end
end
end
2020-02-14 21:06:52 +01:00
surface.set_tiles ( tiles , true )
for _ , p in pairs ( treasure ) do
local name = " wooden-chest "
if math_random ( 1 , 6 ) == 1 then name = " iron-chest " end
Treasure ( surface , p , name )
end
for _ , entity in pairs ( entities ) do
if entity_functions [ game.entity_prototypes [ entity.name ] . type ] then
entity_functions [ game.entity_prototypes [ entity.name ] . type ] ( surface , entity )
else
if surface.can_place_entity ( entity ) then
local e = surface.create_entity ( entity )
2020-02-17 17:37:22 +01:00
if e.name == " biter-spawner " or e.name == " spitter-spawner " or e.name == " small-worm-turret " or e.name == " medium-worm-turret " or e.name == " big-worm-turret " or e.name == " behemoth-worm-turret " then
2020-02-14 21:06:52 +01:00
if math_abs ( e.position . x ) > 420 or math_abs ( e.position . y ) > 420 then e.destructible = false end
end
end
end
end
end
local function process_chunk ( surface , left_top )
if not surface then return end
if not surface.valid then return end
2020-02-21 22:58:14 +01:00
local planet = global.objective . planet
if planet [ 1 ] . name.id == 17 then level_depth = 2176 end
if left_top.x >= level_depth * 0.5 or left_top.y >= level_depth * 0.5 then return end
if left_top.x < level_depth * - 0.5 or left_top.y < level_depth * - 0.5 then return end
2020-02-14 21:06:52 +01: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
-- if left_top.y == -128 and left_top.x == -128 then
-- local p = global.locomotive.position
-- 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
-- end
2020-02-21 22:58:14 +01:00
2020-02-19 15:15:16 +01:00
local id = planet [ 1 ] . name.id --from chronobubbles
if id == 10 then --scrapyard
2020-02-14 21:06:52 +01:00
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 8 , planet ) return end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then normal_chunk ( surface , left_top , 8 , planet ) return end
2020-02-19 15:15:16 +01:00
elseif id == 13 then --river planet
2020-02-14 21:06:52 +01:00
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 6 , planet ) return end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then normal_chunk ( surface , left_top , 6 , planet ) return end
2020-02-19 15:15:16 +01:00
elseif id == 12 then --choppy planet
2020-02-14 21:06:52 +01:00
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 5 , planet ) return end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then forest_chunk ( surface , left_top , 5 , planet ) return end
2020-02-19 15:15:16 +01:00
elseif id == 11 then --rocky planet
2020-02-14 21:06:52 +01:00
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 4 , planet ) return end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then normal_chunk ( surface , left_top , 4 , planet ) return end
2020-02-19 15:15:16 +01:00
elseif id == 14 then --lava planet
2020-02-17 00:46:22 +01:00
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 7 , planet ) end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then biter_chunk ( surface , left_top , 7 , planet ) end
replace_water ( surface , left_top )
return
2020-02-19 15:15:16 +01:00
elseif id == 16 then --hedge maze
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 3 , planet ) return end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then normal_chunk ( surface , left_top , 3 , planet ) return end
2020-02-21 22:58:14 +01:00
elseif id == 17 then --fish market
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x - 864 ) <= 31 then fish_market ( surface , left_top , 10 , planet ) return end
fish_chunk ( surface , left_top , 10 , planet )
2020-02-24 07:13:38 +01:00
elseif id == 18 then --swamp planet
2020-03-05 15:56:59 +01:00
if math_abs ( left_top.y ) <= 63 and math_abs ( left_top.x ) <= 63 then empty_chunk ( surface , left_top , 9 , planet ) return end
if math_abs ( left_top.y ) > 63 or math_abs ( left_top.x ) > 63 then normal_chunk ( surface , left_top , 9 , planet ) return end
elseif id == 19 then --danger event
if math_abs ( left_top.y ) <= 63 and math_abs ( left_top.x ) <= 63 then empty_chunk ( surface , left_top , 2 , planet ) return end
if math_abs ( left_top.y ) == 448 and math_abs ( left_top.x ) == 448 then danger_chunk ( surface , left_top , 2 , planet ) return end
if math_abs ( left_top.y ) > 63 or math_abs ( left_top.x ) > 63 then normal_chunk ( surface , left_top , 2 , planet ) return end
2020-02-14 21:06:52 +01:00
else
if math_abs ( left_top.y ) <= 31 and math_abs ( left_top.x ) <= 31 then empty_chunk ( surface , left_top , 7 , planet ) return end
if math_abs ( left_top.y ) > 31 or math_abs ( left_top.x ) > 31 then biter_chunk ( surface , left_top , 7 , planet ) return end
end
--if left_top.y > 96 then out_of_map(surface, left_top) return end
--if left_top.y > 64 then biter_chunk(surface, left_top) return end
--if left_top.y >= 0 then border_chunk(surface, left_top) return end
--rock_chunk(surface, left_top)
--return
end
local function on_chunk_generated ( event )
if string.sub ( event.surface . name , 0 , 12 ) ~= " chronosphere " then return end
process_chunk ( event.surface , event.area . left_top )
end
local event = require ' utils.event '
event.add ( defines.events . on_chunk_generated , on_chunk_generated )