1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/dungeons/biome_dirtlands.lua

131 lines
5.2 KiB
Lua
Raw Normal View History

2021-03-24 17:46:00 +02:00
local Functions = require 'maps.dungeons.functions'
local Get_noise = require 'utils.get_noise'
local DungeonsTable = require 'maps.dungeons.table'
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
2021-03-24 17:46:00 +02:00
local decoratives = {'brown-asterisk', 'brown-carpet-grass', 'brown-fluff', 'brown-fluff-dry', 'brown-hairy-grass', 'brown-asterisk', 'brown-fluff', 'brown-fluff-dry'}
local ores = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'copper-ore', 'coal', 'coal', 'stone', 'stone'}
local trees = {'dead-dry-hairy-tree', 'dead-grey-trunk', 'dead-tree-desert', 'dry-hairy-tree', 'dry-tree'}
2020-04-04 04:55:05 +02:00
local size_of_trees = #trees
2020-04-04 20:50:58 +02:00
local function draw_deco(surface, position, decorative_name, seed)
2021-03-24 17:46:00 +02:00
if math_random(1, 3) == 1 then
return
end
if surface.get_tile(position).name == 'water' then
return
end
local noise = Get_noise('decoratives', position, seed)
if math_abs(noise) > 0.38 then
surface.create_decoratives {check_collision = false, decoratives = {{name = decorative_name, position = position, amount = math.floor(math.abs(noise * 3)) + 1}}}
end
2020-04-04 20:50:58 +02:00
end
local function draw_room_decoratives(surface, room)
2021-03-24 17:46:00 +02:00
local seed = game.surfaces[surface.index].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
2020-04-04 20:50:58 +02:00
end
2020-04-06 21:41:56 +02:00
local function add_enemy_units(surface, room)
2021-03-24 17:46:00 +02:00
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
2020-04-06 21:41:56 +02:00
end
2020-04-04 04:55:05 +02:00
local function dirtlands(surface, room)
2021-03-24 17:46:00 +02:00
local dungeontable = DungeonsTable.get_dungeontable()
local path_tile = 'dirt-' .. math_random(1, 3)
for _, tile in pairs(room.path_tiles) do
surface.set_tiles({{name = path_tile, position = tile.position}}, true)
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
if not room.room_border_tiles[1] then
draw_room_decoratives(surface, room)
return
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
table_shuffle_table(room.room_tiles)
for key, tile in pairs(room.room_tiles) do
surface.set_tiles({{name = 'dirt-7', position = tile.position}}, true)
if math_random(1, 64) == 1 then
surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = Functions.get_common_resource_amount(surface.index)})
else
if math_random(1, 2048) == 1 then
surface.create_entity({name = 'crude-oil', position = tile.position, amount = Functions.get_crude_oil_amount(surface.index)})
end
if math_random(1, 128) == 1 then
surface.create_entity({name = trees[math_random(1, size_of_trees)], position = tile.position})
end
end
if key % 128 == 1 and math_random(1, 2) == 1 and dungeontable.depth[surface.index] > 8 then
Functions.set_spawner_tier(
surface.create_entity({name = Functions.roll_spawner_name(), position = tile.position, force = dungeontable.enemy_forces[surface.index]}),
surface.index
)
end
if math_random(1, 320) == 1 and dungeontable.depth[surface.index] > 8 then
surface.create_entity({name = Functions.roll_worm_name(surface.index), position = tile.position, force = dungeontable.enemy_forces[surface.index]})
end
if math_random(1, 512) == 1 then
Functions.create_scrap(surface, tile.position)
end
if math_random(1, 256) == 1 then
surface.create_entity({name = 'rock-huge', position = tile.position})
end
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
Functions.add_room_loot_crates(surface, room)
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
if room.center then
if math_random(1, 16) == 1 then
for x = -1, 1, 1 do
for y = -1, 1, 1 do
local p = {room.center.x + x, room.center.y + y}
surface.set_tiles({{name = 'water', position = p}})
if math_random(1, 4) == 1 then
surface.create_entity({name = 'fish', position = p})
end
end
end
end
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
table_shuffle_table(room.room_border_tiles)
for key, tile in pairs(room.room_border_tiles) do
surface.set_tiles({{name = 'dirt-4', position = tile.position}}, true)
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
for key, tile in pairs(room.room_border_tiles) do
if key % 8 == 1 then
Functions.place_border_rock(surface, tile.position)
end
end
2020-07-29 21:28:48 +02:00
2021-03-24 17:46:00 +02:00
draw_room_decoratives(surface, room)
draw_room_decoratives(surface, room)
add_enemy_units(surface, room)
2020-04-04 04:55:05 +02:00
end
2020-07-29 21:28:48 +02:00
return dirtlands