2020-04-04 19:07:08 +02:00
|
|
|
local Functions = require "maps.dungeons.functions"
|
2020-04-04 20:24:05 +02:00
|
|
|
local Get_noise = require "utils.get_noise"
|
2020-04-04 19:07:08 +02:00
|
|
|
|
2020-04-04 04:55:05 +02:00
|
|
|
local table_shuffle_table = table.shuffle_table
|
|
|
|
local table_insert = table.insert
|
|
|
|
local table_remove = table.remove
|
|
|
|
local math_random = math.random
|
|
|
|
local math_abs = math.abs
|
|
|
|
local math_sqrt = math.sqrt
|
2020-04-04 06:25:13 +02:00
|
|
|
local math_floor = math.floor
|
2020-04-04 04:55:05 +02:00
|
|
|
|
2020-04-04 20:24:05 +02:00
|
|
|
local decoratives = {"green-asterisk", "green-bush-mini", "green-carpet-grass", "green-hairy-grass", "green-small-grass"}
|
2020-04-09 01:04:36 +02:00
|
|
|
local ores = {"iron-ore", "iron-ore", "coal"}
|
2020-04-04 04:55:05 +02:00
|
|
|
local trees = {"tree-01", "tree-02", "tree-03", "tree-04", "tree-05"}
|
|
|
|
local size_of_trees = #trees
|
2020-04-04 20:24:05 +02:00
|
|
|
|
|
|
|
local function draw_deco(surface, position, decorative_name, seed)
|
|
|
|
if surface.get_tile(position).name == "water" then return end
|
2020-04-10 03:15:29 +02:00
|
|
|
if surface.count_entities_filtered({type = "resource", position = position}) > 0 then return end
|
2020-04-04 20:24:05 +02:00
|
|
|
local noise = Get_noise("decoratives", position, seed)
|
|
|
|
if math_abs(noise) > 0.28 then
|
|
|
|
surface.create_decoratives{check_collision = false, decoratives = {{name = decorative_name, position = position, amount = math.floor(math.abs(noise * 3)) + 1}}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function draw_room_decoratives(surface, room)
|
|
|
|
local seed = game.surfaces[1].map_gen_settings.seed + math_random(1, 1000000)
|
|
|
|
local decorative_name = decoratives[math_random(1, #decoratives)]
|
|
|
|
for _, tile in pairs(room.path_tiles) do draw_deco(surface, tile.position, decorative_name, seed) end
|
|
|
|
for _, tile in pairs(room.room_border_tiles) do draw_deco(surface, tile.position, decorative_name, seed) end
|
|
|
|
for _, tile in pairs(room.room_tiles) do draw_deco(surface, tile.position, decorative_name, seed) end
|
|
|
|
end
|
2020-04-04 04:55:05 +02:00
|
|
|
|
2020-04-06 21:41:56 +02:00
|
|
|
local function add_enemy_units(surface, room)
|
|
|
|
for _, tile in pairs(room.room_border_tiles) do if math_random(1, 32) == 1 then Functions.spawn_random_biter(surface, tile.position) end end
|
|
|
|
for _, tile in pairs(room.room_tiles) do if math_random(1, 32) == 1 then Functions.spawn_random_biter(surface, tile.position) end end
|
|
|
|
end
|
|
|
|
|
2020-04-04 04:55:05 +02:00
|
|
|
local function grasslands(surface, room)
|
|
|
|
for _, tile in pairs(room.path_tiles) do
|
|
|
|
surface.set_tiles({{name = "grass-1", position = tile.position}}, true)
|
|
|
|
end
|
|
|
|
|
2020-04-04 20:24:05 +02:00
|
|
|
if not room.room_tiles[1] then draw_room_decoratives(surface, room) return end
|
|
|
|
|
2020-04-10 03:15:29 +02:00
|
|
|
local seed = game.surfaces[1].map_gen_settings.seed + math_random(1, 1000000)
|
2020-04-04 20:24:05 +02:00
|
|
|
local tree_name = trees[math_random(1, size_of_trees)]
|
|
|
|
|
|
|
|
table_shuffle_table(room.room_tiles)
|
2020-04-04 04:55:05 +02:00
|
|
|
for key, tile in pairs(room.room_tiles) do
|
|
|
|
surface.set_tiles({{name = "grass-2", position = tile.position}}, true)
|
2020-04-10 03:15:29 +02:00
|
|
|
if math_random(1, 16) == 1 and Get_noise("n3", tile.position, seed) > 0.1 then
|
|
|
|
surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = Functions.get_common_resource_amount()})
|
2020-04-04 04:55:05 +02:00
|
|
|
else
|
2020-04-10 03:15:29 +02:00
|
|
|
if math_random(1, math_random(2, 20)) == 1 and math_abs(Get_noise("decoratives", tile.position, seed + 100000)) > 0.2 then
|
2020-04-04 20:24:05 +02:00
|
|
|
surface.create_entity({name = tree_name, position = tile.position})
|
2020-04-04 04:55:05 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-06 21:41:56 +02:00
|
|
|
if key % 128 == 1 and math_random(1, 3) == 1 then
|
|
|
|
Functions.set_spawner_tier(surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = "enemy"}))
|
2020-04-05 03:39:52 +02:00
|
|
|
end
|
2020-04-06 21:41:56 +02:00
|
|
|
if math_random(1, 320) == 1 then
|
|
|
|
surface.create_entity({name = Functions.roll_worm_name(), position = tile.position})
|
|
|
|
end
|
2020-04-04 04:55:05 +02:00
|
|
|
if math_random(1, 1024) == 1 then
|
|
|
|
surface.create_entity({name = "rock-huge", position = tile.position})
|
2020-04-05 00:05:13 +02:00
|
|
|
end
|
2020-04-04 04:55:05 +02:00
|
|
|
end
|
|
|
|
|
2020-04-10 03:15:29 +02:00
|
|
|
Functions.add_room_loot_crates(surface, room)
|
|
|
|
|
2020-04-04 04:55:05 +02:00
|
|
|
if room.center then
|
2020-04-04 19:07:08 +02:00
|
|
|
if math_random(1, 4) == 1 then
|
2020-04-09 01:04:36 +02:00
|
|
|
local r = math_floor(math_sqrt(#room.room_tiles) * 0.225) + 1
|
2020-04-04 04:55:05 +02:00
|
|
|
for x = r * -1, r, 1 do
|
|
|
|
for y = r * -1, r, 1 do
|
|
|
|
local p = {room.center.x + x, room.center.y + y}
|
|
|
|
surface.set_tiles({{name = "water", position = p}})
|
2020-04-04 06:25:13 +02:00
|
|
|
if math_random(1, 8) == 1 then
|
2020-04-04 04:55:05 +02:00
|
|
|
surface.create_entity({name = "fish", position = p})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-04 06:25:13 +02:00
|
|
|
|
2020-04-04 20:24:05 +02:00
|
|
|
table_shuffle_table(room.room_border_tiles)
|
2020-04-04 06:25:13 +02:00
|
|
|
for key, tile in pairs(room.room_border_tiles) do
|
|
|
|
surface.set_tiles({{name = "grass-3", position = tile.position}}, true)
|
2020-04-07 10:02:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
for key, tile in pairs(room.room_border_tiles) do
|
2020-04-04 20:24:05 +02:00
|
|
|
if key % 8 == 1 then
|
2020-04-07 10:02:32 +02:00
|
|
|
Functions.place_border_rock(surface, tile.position)
|
2020-04-04 06:25:13 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-04 20:24:05 +02:00
|
|
|
|
|
|
|
draw_room_decoratives(surface, room)
|
2020-04-06 21:41:56 +02:00
|
|
|
draw_room_decoratives(surface, room)
|
|
|
|
add_enemy_units(surface, room)
|
2020-04-04 04:55:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return grasslands
|