mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-05-13 21:56:29 +02:00
room files
This commit is contained in:
parent
64a297a8af
commit
0b8bc35877
154
maps/stone_maze/1x1_rooms.lua
Normal file
154
maps/stone_maze/1x1_rooms.lua
Normal file
@ -0,0 +1,154 @@
|
||||
local room = {}
|
||||
|
||||
room.empty = function(surface, cell_left_top, direction)
|
||||
|
||||
end
|
||||
|
||||
room.checkerboard_ore = function(surface, cell_left_top, direction)
|
||||
local ores = {"coal", "iron-ore", "copper-ore", "stone"}
|
||||
table.shuffle_table(ores)
|
||||
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 1, grid_size - 2, 1 do
|
||||
for y = 1, grid_size - 2, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if x % 2 == y % 2 then
|
||||
surface.create_entity({name = ores[1], position = pos, force = "neutral", amount = 64 + global.maze_depth * 2})
|
||||
else
|
||||
surface.create_entity({name = ores[2], position = pos, force = "neutral", amount = 64 + global.maze_depth * 2})
|
||||
end
|
||||
surface.set_tiles({{name = "grass-2", position = pos}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.tons_of_trees = function(surface, cell_left_top, direction)
|
||||
local tree = tree_raffle[math.random(1, #tree_raffle)]
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 0.5, grid_size - 0.5, 1 do
|
||||
for y = 0.5, grid_size - 0.5, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,2) ~= 1 then
|
||||
surface.create_entity({name = tree, position = pos, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.single_rock = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.5, left_top.y + grid_size * 0.5}, force = "neutral"})
|
||||
end
|
||||
|
||||
room.three_rocks = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.2, left_top.y + grid_size * 0.8}, force = "neutral"})
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.8, left_top.y + grid_size * 0.8}, force = "neutral"})
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.5, left_top.y + grid_size * 0.2}, force = "neutral"})
|
||||
end
|
||||
|
||||
room.quad_rocks = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.15, left_top.y + grid_size * 0.15}, force = "neutral"})
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.15, left_top.y + grid_size * 0.85}, force = "neutral"})
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.85, left_top.y + grid_size * 0.15}, force = "neutral"})
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = {left_top.x + grid_size * 0.85, left_top.y + grid_size * 0.85}, force = "neutral"})
|
||||
end
|
||||
|
||||
room.tons_of_rocks = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 0.5, grid_size - 0.5, 1 do
|
||||
for y = 0.5, grid_size - 0.5, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,4) ~= 1 then
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = pos, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.lots_of_rocks = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 0.5, grid_size - 0.5, 1 do
|
||||
for y = 0.5, grid_size - 0.5, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,2) ~= 1 then
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = pos, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.some_scrap = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = math.floor(grid_size * 0.15), math.floor(grid_size * 0.85) - 1, 1 do
|
||||
for y = math.floor(grid_size * 0.15), math.floor(grid_size * 0.85) - 1, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,16) == 1 then
|
||||
surface.create_entity({name = "mineable-wreckage", position = pos, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.lots_of_scrap = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 0.5, grid_size - 0.5, 1 do
|
||||
for y = 0.5, grid_size - 0.5, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,8) == 1 then
|
||||
surface.create_entity({name = "mineable-wreckage", position = pos, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.tons_of_scrap = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 0.5, grid_size - 0.5, 1 do
|
||||
for y = 0.5, grid_size - 0.5, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,2) == 1 then
|
||||
surface.create_entity({name = "mineable-wreckage", position = pos, force = "neutral"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.pond = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = math.floor(grid_size * 0.25), math.floor(grid_size * 0.75) - 1, 1 do
|
||||
for y = math.floor(grid_size * 0.25), math.floor(grid_size * 0.75) - 1, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
surface.set_tiles({{name = "water", position = pos}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local room_weights = {
|
||||
|
||||
{func = room.tons_of_trees, weight = 25},
|
||||
{func = room.lots_of_rocks, weight = 50},
|
||||
{func = room.tons_of_rocks, weight = 25},
|
||||
{func = room.quad_rocks, weight = 5},
|
||||
{func = room.three_rocks, weight = 5},
|
||||
{func = room.single_rock, weight = 10},
|
||||
|
||||
{func = room.checkerboard_ore, weight = 5},
|
||||
{func = room.some_scrap, weight = 10},
|
||||
{func = room.lots_of_scrap, weight = 4},
|
||||
{func = room.tons_of_scrap, weight = 2},
|
||||
{func = room.empty, weight = 15},
|
||||
|
||||
{func = room.pond, weight = 10}
|
||||
}
|
||||
|
||||
local room_shuffle = {}
|
||||
for _, r in pairs(room_weights) do
|
||||
for c = 1, r.weight, 1 do
|
||||
room_shuffle[#room_shuffle + 1] = r.func
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return room_shuffle
|
98
maps/stone_maze/2x2_rooms.lua
Normal file
98
maps/stone_maze/2x2_rooms.lua
Normal file
@ -0,0 +1,98 @@
|
||||
local room = {}
|
||||
|
||||
room.empty = function(surface, cell_left_top, direction)
|
||||
|
||||
end
|
||||
|
||||
room.stone_block = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 2.5, grid_size * 2 - 2.5, 1 do
|
||||
for y = 2.5, grid_size * 2 - 2.5, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if math.random(1,6) ~= 1 then surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = pos, force = "neutral"}) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.circle_pond_with_trees = function(surface, cell_left_top, direction)
|
||||
local tree = tree_raffle[math.random(1, #tree_raffle)]
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
local center_pos = {x = left_top.x + grid_size, y = left_top.y + grid_size}
|
||||
|
||||
map_functions.draw_noise_tile_circle({x = left_top.x + grid_size, y = left_top.y + grid_size}, "water", surface, grid_size * 0.5)
|
||||
|
||||
for x = math.floor(grid_size * 2 * 0.1), math.floor(grid_size * 2 * 0.9), 1 do
|
||||
for y = math.floor(grid_size * 2 * 0.1), math.floor(grid_size * 2 * 0.9), 1 do
|
||||
local pos = {x = left_top.x + x, y = left_top.y + y}
|
||||
local distance_to_center = math.sqrt((center_pos.x - pos.x) ^ 2 + (center_pos.y - pos.y) ^ 2)
|
||||
if math.random(1,5) == 1 and distance_to_center < grid_size * 0.85 then
|
||||
if surface.can_place_entity({name = tree, position = pos, force = "neutral"}) then surface.create_entity({name = tree, position = pos, force = "neutral"}) end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.checkerboard_ore = function(surface, cell_left_top, direction)
|
||||
local ores = {"coal", "iron-ore", "copper-ore", "stone"}
|
||||
table.shuffle_table(ores)
|
||||
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
for x = 2, grid_size * 2 - 3, 1 do
|
||||
for y = 2, grid_size * 2 - 3, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if x % 2 == y % 2 then
|
||||
surface.create_entity({name = ores[1], position = pos, force = "neutral", amount = 64 + global.maze_depth * 2})
|
||||
else
|
||||
surface.create_entity({name = ores[2], position = pos, force = "neutral", amount = 64 + global.maze_depth * 2})
|
||||
end
|
||||
surface.set_tiles({{name = "grass-2", position = pos}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
room.minefield_chest = function(surface, cell_left_top, direction)
|
||||
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
|
||||
|
||||
local chest = surface.create_entity({
|
||||
name = "steel-chest",
|
||||
position = {left_top.x + grid_size + (direction[1] * grid_size * 0.5), left_top.y + grid_size + (direction[2] * grid_size * 0.5)},
|
||||
force = "neutral",
|
||||
})
|
||||
chest.insert({name = "grenade", count = "1"})
|
||||
|
||||
for x = 0, grid_size * 2 - 1, 1 do
|
||||
for y = 0, grid_size * 2 - 1, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
if x <= 1 or x >= grid_size * 2 - 2 or y <= 1 or y >= grid_size * 2 - 2 then
|
||||
surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = pos, force = "neutral"})
|
||||
else
|
||||
if x == 2 or x == grid_size * 2 - 3 or y == 2 or y == grid_size * 2 - 3 then
|
||||
surface.create_entity({name = "stone-wall", position = pos, force = "enemy"})
|
||||
else
|
||||
if math.random(1,6) == 1 then
|
||||
surface.create_entity({name = "land-mine", position = pos, force = "enemy"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local room_weights = {
|
||||
{func = room.circle_pond_with_trees, weight = 25},
|
||||
|
||||
{func = room.stone_block, weight = 25},
|
||||
{func = room.minefield_chest, weight = 5},
|
||||
{func = room.checkerboard_ore, weight = 10},
|
||||
{func = room.empty, weight = 1},
|
||||
}
|
||||
|
||||
local room_shuffle = {}
|
||||
for _, r in pairs(room_weights) do
|
||||
for c = 1, r.weight, 1 do
|
||||
room_shuffle[#room_shuffle + 1] = r.func
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return room_shuffle
|
@ -1,11 +1,50 @@
|
||||
--optionals
|
||||
require "modules.satellite_score"
|
||||
require "modules.dynamic_landfill"
|
||||
require "modules.dangerous_goods"
|
||||
|
||||
--essentials
|
||||
require "modules.biters_yield_coins"
|
||||
require "modules.rocks_yield_ore"
|
||||
require "modules.mineable_wreckage_yields_scrap"
|
||||
require 'utils.table'
|
||||
|
||||
local event = require 'utils.event'
|
||||
local table_insert = table.insert
|
||||
local math_random = math.random
|
||||
|
||||
local grid_size = 8
|
||||
local rooms_1x1 = require 'maps.stone_maze.1x1_rooms'
|
||||
local multirooms = {}
|
||||
multirooms["2x2"] = require 'maps.stone_maze.2x2_rooms'
|
||||
|
||||
map_functions = require "tools.map_functions"
|
||||
grid_size = 8
|
||||
rock_raffle = {"rock-huge", "rock-big", "rock-big", "rock-big"}
|
||||
tree_raffle = {"tree-01", "tree-02", "tree-03", "tree-04", "tree-05", "tree-06", "tree-07", "tree-08", "tree-09", "tree-02-red", "tree-06-brown", "tree-08-brown", "tree-08-red","tree-09-brown","tree-09-red","dead-dry-hairy-tree","dry-hairy-tree","dry-tree","dead-tree-desert","dead-grey-trunk"}
|
||||
|
||||
|
||||
local visited_tile_translation = {
|
||||
["dirt-3"] = "dirt-7",
|
||||
["dirt-5"] = "dirt-7",
|
||||
["grass-2"] = "grass-1"
|
||||
}
|
||||
|
||||
local function draw_depth_gui()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.gui.top.evolution_gui then player.gui.top.evolution_gui.destroy() end
|
||||
local element = player.gui.top.add({type = "sprite-button", name = "evolution_gui", caption = "Depth: " .. global.maze_depth, tooltip = "Delve deep and face increased dangers."})
|
||||
local style = element.style
|
||||
style.minimal_height = 38
|
||||
style.maximal_height = 38
|
||||
style.minimal_width = 146
|
||||
style.top_padding = 2
|
||||
style.left_padding = 4
|
||||
style.right_padding = 4
|
||||
style.bottom_padding = 2
|
||||
style.font_color = {r = 125, g = 75, b = 25}
|
||||
style.font = "default-large-bold"
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
@ -63,16 +102,26 @@ local function set_cell_tiles(surface, cell_position, tile_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function can_multicell_expand(cell_position, direction, cell_type)
|
||||
|
||||
local function set_visted_cell_tiles(surface, cell_position)
|
||||
local left_top = {x = cell_position.x * grid_size, y = cell_position.y * grid_size}
|
||||
for x = 0, grid_size - 1, 1 do
|
||||
for y = 0, grid_size - 1, 1 do
|
||||
local pos = {left_top.x + x, left_top.y + y}
|
||||
local tile_name = surface.get_tile(pos).name
|
||||
if visited_tile_translation[tile_name] then
|
||||
surface.set_tiles({{name = visited_tile_translation[tile_name], position = pos}}, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function can_multicell_expand(cell_position, direction, cell_type)
|
||||
local left_top_index = {}
|
||||
for i = 1, #cells[cell_type][coord_to_string(direction)], 1 do
|
||||
left_top_index[#left_top_index + 1] = i
|
||||
end
|
||||
table.shuffle_table(left_top_index)
|
||||
|
||||
game.print(left_top_index[1])
|
||||
|
||||
for i = 1, #left_top_index, 1 do
|
||||
|
||||
local left_top = cells[cell_type][coord_to_string(direction)][left_top_index[i]]
|
||||
@ -103,34 +152,51 @@ local function can_1x1_expand(cell_position, direction)
|
||||
return true
|
||||
end
|
||||
|
||||
local multi_cell_chances = {
|
||||
{"2x2"},
|
||||
}
|
||||
|
||||
local function set_cell(surface, cell_position, direction)
|
||||
|
||||
local cell_left_top_2x2 = can_multicell_expand(cell_position, direction, "2x2")
|
||||
local multi_cell_type = "2x2"
|
||||
|
||||
if cell_left_top_2x2 then
|
||||
if cells_to_open == 0 then return end
|
||||
cells_to_open = cells_to_open - 1
|
||||
|
||||
for x = 0, cells["2x2"].size_x - 1, 1 do
|
||||
for y = 0, cells["2x2"].size_y - 1, 1 do
|
||||
local p = {x = cell_left_top_2x2.x + x, y = cell_left_top_2x2.y + y}
|
||||
set_cell_tiles(surface, p, "dirt-3")
|
||||
init_cell(p)
|
||||
global.maze_cells[coord_to_string(p)].occupied = true
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
if math_random(1,3) == 1 then
|
||||
local cell_left_top = can_multicell_expand(cell_position, direction, multi_cell_type)
|
||||
if cell_left_top then
|
||||
if cells_to_open == 0 then return end
|
||||
cells_to_open = cells_to_open - 1
|
||||
|
||||
for x = 0, cells[multi_cell_type].size_x - 1, 1 do
|
||||
for y = 0, cells[multi_cell_type].size_y - 1, 1 do
|
||||
local p = {x = cell_left_top.x + x, y = cell_left_top.y + y}
|
||||
set_cell_tiles(surface, p, "dirt-3")
|
||||
|
||||
init_cell(p)
|
||||
global.maze_cells[coord_to_string(p)].occupied = true
|
||||
|
||||
global.maze_depth = global.maze_depth + 1
|
||||
draw_depth_gui()
|
||||
end
|
||||
end
|
||||
|
||||
multirooms[multi_cell_type][math_random(1,#multirooms[multi_cell_type])](surface, cell_left_top, direction)
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if can_1x1_expand(cell_position, direction) then
|
||||
if cells_to_open == 0 then return end
|
||||
cells_to_open = cells_to_open - 1
|
||||
|
||||
set_cell_tiles(surface, cell_position, "dirt-3")
|
||||
|
||||
rooms_1x1[math_random(1,#rooms_1x1)](surface, cell_position, direction)
|
||||
|
||||
init_cell(cell_position)
|
||||
global.maze_cells[coord_to_string(cell_position)].occupied = true
|
||||
global.maze_cells[coord_to_string(cell_position)].occupied = true
|
||||
|
||||
global.maze_depth = global.maze_depth + 1
|
||||
draw_depth_gui()
|
||||
end
|
||||
end
|
||||
|
||||
@ -167,7 +233,7 @@ local function on_player_changed_position(event)
|
||||
set_cells(surface, cell_position)
|
||||
|
||||
global.maze_cells[coord_to_string(cell_position)].visited = true
|
||||
set_cell_tiles(surface, cell_position, "dirt-7")
|
||||
set_visted_cell_tiles(surface, cell_position)
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
@ -199,6 +265,7 @@ end
|
||||
|
||||
local function on_init(event)
|
||||
global.maze_cells = {}
|
||||
global.maze_depth = 0
|
||||
game.forces["player"].set_spawn_position({x = grid_size * 0.5, y = grid_size * 0.5}, game.surfaces.nauvis)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user