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

79 lines
2.2 KiB
Lua
Raw Normal View History

2021-03-24 17:46:00 +02:00
local Functions = require 'maps.dungeons.functions'
2020-07-29 21:28:48 +02:00
local table_shuffle_table = table.shuffle_table
local table_insert = table.insert
local math_random = math.random
local rainbow_tiles = {
2021-03-24 17:46:00 +02:00
'cyan-refined-concrete',
'purple-refined-concrete'
2020-07-29 21:28:48 +02:00
}
-- balanced the same as end-game rocks from functions.lua:rocky_loot
2020-07-29 21:28:48 +02:00
local ores = {
'copper-ore',
'copper-ore',
2021-03-24 17:46:00 +02:00
'copper-ore',
'iron-ore',
'iron-ore',
'iron-ore',
'iron-ore',
'coal',
2021-03-24 17:46:00 +02:00
'coal',
'stone'
2020-07-29 21:28:48 +02:00
}
local function treasure(surface, room)
2021-03-24 17:46:00 +02:00
local tiles = {}
for _, tile in pairs(room.path_tiles) do
table_insert(tiles, tile)
end
for _, tile in pairs(room.room_border_tiles) do
table_insert(tiles, tile)
end
for _, tile in pairs(room.room_tiles) do
table_insert(tiles, tile)
end
local scale_factor = 5
if room.room_tiles[1] then
-- room.room_tiles[1] is set only if this is a real room not a walkway
-- Small rooms are 9x9, big ones are 29x29, so 100-1000 tiles
-- middle size about 400 tiles, but test at that showed treasure rooms over-buffed.
-- test#2 at 200.
scale_factor = 10 * 200 / #tiles
end
2021-03-24 17:46:00 +02:00
for _, tile in pairs(tiles) do
surface.set_tiles({{name = rainbow_tiles[math_random(1, 2)], position = tile.position}}, true)
if math_random(1, 3) == 1 then
surface.create_entity({name = ores[math_random(1, #ores)], position = tile.position, amount = Functions.get_common_resource_amount(surface.index) * scale_factor})
2021-03-24 17:46:00 +02:00
end
end
if not room.room_border_tiles[1] then
return
end
table_shuffle_table(room.room_tiles)
for key, tile in pairs(room.room_tiles) do
if math_random(1, 256) == 1 or key == 1 then
Functions.epic_loot_crate(surface, tile.position, true)
else
if math_random(1, 128) == 1 then
Functions.rare_loot_crate(surface, tile.position, true)
end
end
end
table_shuffle_table(room.room_border_tiles)
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
end
return treasure