From f66d5e0156d3ab3793ab9f162c08bf3cee33c849 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 08:11:06 -0500 Subject: [PATCH 01/18] Start of the deco overlay on picture maps -- working on a biome test area --- .../grilledham_map_gen/data/biome_test.lua | 47 +++++++++++++++++++ .../grilledham_map_gen/map_gen.lua | 26 +++++----- .../grilledham_map_gen/presets/biome_test.lua | 10 ++++ map_layout.lua | 5 +- 4 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 locale/gen_combined/grilledham_map_gen/data/biome_test.lua create mode 100644 locale/gen_combined/grilledham_map_gen/presets/biome_test.lua diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua new file mode 100644 index 00000000..d0c8058e --- /dev/null +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -0,0 +1,47 @@ +local tile_types = { + "concrete", +"deepwater", +"deepwater-green", +"dirt", +"dirt-dark", +"grass", +"grass-dry", +"grass-medium", +"hazard-concrete-left", +"hazard-concrete-right", +"lab-dark-1", +"lab-dark-2", +"out-of-map", +"red-desert", +"red-desert-dark", +"sand", +"sand-dark", +"stone-path", +"water", +"water-green" +} + +local tile_width = 32 +local tile_height = 32 + +local tile_data = {} + +local abs_y = 1 + +for e,_ in ipairs(tile_types) do + for y = 1, tile_width do + row = {} + for x = 1, tile_height do + table.insert( row, e) + end +-- abs_y = abs_y + 1 + table.insert(tile_data, row) +-- tile_data[abs_y] = row + end +end + +return { +height = tile_height * #tile_data, +width = tile_height, +data = tile_data +} diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 74327744..a4129ecc 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,7 +1,7 @@ require("locale.gen_combined.grilledham_map_gen.builders") function run_combined_module(event) - + if MAP_GEN == nil then game.print("MAP_GEN not set") return @@ -18,29 +18,29 @@ function run_combined_module(event) for y = top_y, top_y + 31 do for x = top_x, top_x + 31 do - - -- local coords need to be 'centered' to allow for correct rotation and scaling. - local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) - if type(tile) == "boolean" and not tile then - table.insert( tiles, {name = "out-of-map", position = {x, y}} ) + -- local coords need to be 'centered' to allow for correct rotation and scaling. + local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) + + if type(tile) == "boolean" and not tile then + table.insert( tiles, {name = "out-of-map", position = {x, y}} ) elseif type(tile) == "string" then - table.insert( tiles, {name = tile, position = {x, y}} ) + table.insert( tiles, {name = tile, position = {x, y}} ) end if entity then table.insert(entities, entity) end end - end + end -- set tiles. surface.set_tiles(tiles, false) -- set entities - for _, v in ipairs(entities) do - if surface.can_place_entity(v) then - surface.create_entity(v) + for _, v in ipairs(entities) do + if surface.can_place_entity(v) then + surface.create_entity(v) end - end -end \ No newline at end of file + end +end diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua new file mode 100644 index 00000000..d6d78abd --- /dev/null +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -0,0 +1,10 @@ +require "locale.gen_combined.grilledham_map_gen.map_gen" +require "locale.gen_combined.grilledham_map_gen.builders" + +local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" + +local shape = picture_builder(pic.data, pic.width, pic.height) + +shape = change_tile(shape, false, "deepwater") + +return shape diff --git a/map_layout.lua b/map_layout.lua index 10ac6515..be6fe40d 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -23,9 +23,10 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.cage" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" +MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" --shapes-- -require "locale.gen_shape.left" +--require "locale.gen_shape.left" --require "locale.gen_shape.right" --require "locale.gen_shape.up" --require "locale.gen_shape.maze" @@ -49,7 +50,7 @@ require "locale.gen_shape.left" --ores-- --require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.fluffy_rainbows" -require "locale.gen_ores.rso.rso_control" +--require "locale.gen_ores.rso.rso_control" --everything else. You may use more than one of these, but beware they might not be compatible miscs = {} From ddc4748e74ab6f4978a90f0241434ecbd7e61e81 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 11:41:30 -0500 Subject: [PATCH 02/18] Multi row and column representation for all tile types. --- .../grilledham_map_gen/builders.lua | 98 ++++++++++--------- .../grilledham_map_gen/data/biome_test.lua | 41 +++++--- .../grilledham_map_gen/presets/biome_test.lua | 3 +- 3 files changed, 80 insertions(+), 62 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/builders.lua b/locale/gen_combined/grilledham_map_gen/builders.lua index eb2401e8..c7f738d6 100644 --- a/locale/gen_combined/grilledham_map_gen/builders.lua +++ b/locale/gen_combined/grilledham_map_gen/builders.lua @@ -17,27 +17,27 @@ function full_builder(x, y) return true end -function path_builder(thickness, optional_thickness_height) +function path_builder(thickness, optional_thickness_height) local width = thickness / 2 local thickness2 = optional_thickness_height or thickness - local height = thickness2 / 2 - return function(x, y) + local height = thickness2 / 2 + return function(x, y) return (x > -width and x <= width) or (y > -height and y <= height) end end -function rectangle_builder(width, height) - width = width / 2 - height = height / 2 - return function (x, y) - return x > -width and x <= width and y > -height and y <= height +function rectangle_builder(width, height) + width = width / 2 + height = height / 2 + return function (x, y) + return x > -width and x <= width and y > -height and y <= height end end function square_diamond_builder(size) size = size / 2 - return function (x, y) - return math.abs(x) + math.abs(y) <= size + return function (x, y) + return math.abs(x) + math.abs(y) <= size end end @@ -52,14 +52,14 @@ function rectangle_diamond_builder(width, height) end end -function circle_builder(radius) +function circle_builder(radius) local rr = radius * radius return function (x, y) return x * x + y * y < rr end end -function oval_builder(x_radius, y_radius) +function oval_builder(x_radius, y_radius) local x_rr = x_radius * x_radius local y_rr = y_radius * y_radius return function (x, y) @@ -71,18 +71,24 @@ function picture_builder(data, width, height) -- the plus one is because lua tables are one based. local half_width = math.floor(width / 2) + 1 local half_height = math.floor(height / 2) + 1 + return function(x, y) x = math.floor(x) y = math.floor(y) local x2 = x + half_width - local y2 = y + half_height + local y2 = y + half_height if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then - local pixel = data[y2][x2] + local pixel = "out-of-map" + if data[y2] ~= nil then + if data[y2][x2] ~= nil then + pixel = data[y2][x2] + end + end return pixel else return false - end + end end end @@ -101,7 +107,7 @@ function scale(builder, x_scale, y_scale) return builder(x * x_scale, y * y_scale, world_x, world_y) end end - + function rotate(builder, angle) local qx = math.cos(angle) local qy = math.sin(angle) @@ -140,8 +146,8 @@ end -- For resource_module_builder it will return the first success. function compound_or(builders) return function(x, y, world_x, world_y) - for _, v in ipairs(builders) do - local tile, entity = v(x, y, world_x, world_y) + for _, v in ipairs(builders) do + local tile, entity = v(x, y, world_x, world_y) if tile then return tile, entity end end return false @@ -167,8 +173,8 @@ end function throttle_xy(builder, x_in, x_size, y_in, y_size) return function(x, y, world_x, world_y) - if x % x_size < x_in and y % y_size < y_in then - return builder(x, y, world_x, world_y) + if x % x_size < x_in and y % y_size < y_in then + return builder(x, y, world_x, world_y) else return false end @@ -188,7 +194,7 @@ end function linear_grow(shape, size) local half_size = size / 2 return function (local_x, local_y, world_x, world_y) - local t = math.ceil((local_y / size) + 0.5) + local t = math.ceil((local_y / size) + 0.5) local n = math.ceil((math.sqrt(8 * t + 1) - 1) / 2) local t_upper = n * (n + 1) * 0.5 local t_lower = t_upper - n @@ -200,11 +206,11 @@ function linear_grow(shape, size) end end -function project(shape, size, r) +function project(shape, size, r) local ln_r = math.log(r) local r2 = 1 / (r - 1) local a = 1 / size - + return function(local_x, local_y, world_x, world_y) local offset = 0.5 * size local sn = math.ceil(local_y + offset) @@ -215,21 +221,21 @@ function project(shape, size, r) local c = size * rn local sn_upper = size * (r ^ (n + 1) - 1) * r2 - local x = local_x * rn2 - local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 + local x = local_x * rn2 + local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 return shape(x, y, world_x, world_y) end end -function project_overlap(shape, size, r) +function project_overlap(shape, size, r) local ln_r = math.log(r) local r2 = 1 / (r - 1) local a = 1 / size local offset = 0.5 * size - + return function(local_x, local_y, world_x, world_y) - + local sn = math.ceil(local_y + offset) local n = math.ceil(math.log((r-1) * sn * a + 1) / ln_r - 1) @@ -238,8 +244,8 @@ function project_overlap(shape, size, r) local c = size * rn local sn_upper = size * (r ^ (n + 1) - 1) * r2 - local x = local_x * rn2 - local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 + local x = local_x * rn2 + local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 local tile local entity @@ -249,7 +255,7 @@ function project_overlap(shape, size, r) return tile, entity end - local n_above = n - 1 + local n_above = n - 1 local rn_above = rn / r local rn2_above = 1 / rn_above local c_above = size * rn_above @@ -270,8 +276,8 @@ function project_overlap(shape, size, r) local x_below = local_x * rn2_below local y_below = (local_y - (sn_upper_below - 0.5 * c_below ) + offset ) * rn2_below - return shape(x_below, y_below, world_x, world_y) - + return shape(x_below, y_below, world_x, world_y) + end end @@ -282,12 +288,12 @@ function resource_module_builder(builder, resource_type, amount_function) amount_function = amount_function or function(a, b) return 603 end return function(x, y, world_x, world_y) if builder(x, y, world_x, world_y) then - return + return { name = resource_type, position = {world_x, world_y}, amount = amount_function(world_x, world_y) - } + } else return nil end @@ -299,9 +305,9 @@ function builder_with_resource(land_builder, resource_module) local tile = land_builder(x, y) if tile then local entity = resource_module(x, y ,world_x, world_y) - return tile, entity + return tile, entity else - return false + return false end end end @@ -314,27 +320,27 @@ function single_pattern_builder(shape, width, height) local half_width = width / 2 local half_height = height / 2 - return function (local_x, local_y, world_x, world_y) - local_y = ((local_y + half_height) % height) - half_height - local_x = ((local_x + half_width) % width) - half_width + return function (local_x, local_y, world_x, world_y) + local_y = ((local_y + half_height) % height) - half_height + local_x = ((local_x + half_width) % width) - half_width return shape(local_x, local_y, world_x, world_y) end end function grid_pattern_builder(pattern, columns, rows, width, height) - + local half_width = width / 2 local half_height = height / 2 return function (local_x, local_y, world_x, world_y) - local local_y2 = ((local_y + half_height) % height) - half_height + local local_y2 = ((local_y + half_height) % height) - half_height local row_pos = math.floor(local_y / height + 0.5) local row_i = row_pos % rows + 1 - local row = pattern[row_i] or {} + local row = pattern[row_i] or {} - local local_x2 = ((local_x + half_width) % width) - half_width - local col_pos = math.floor(local_x / width + 0.5) + local local_x2 = ((local_x + half_width) % width) - half_width + local col_pos = math.floor(local_x / width + 0.5) local col_i = col_pos % columns + 1 local shape = row[col_i] or empty_builder @@ -400,4 +406,4 @@ function apply_effect(builder, func) tile, entity = func(local_x, local_y, world_x, world_y, tile, entity) return tile, entity end -end \ No newline at end of file +end diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index d0c8058e..73c97af0 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -11,37 +11,50 @@ local tile_types = { "hazard-concrete-right", "lab-dark-1", "lab-dark-2", -"out-of-map", "red-desert", "red-desert-dark", "sand", "sand-dark", "stone-path", "water", -"water-green" +"water-green", +"out-of-map", } +local cols = 5 +local rows = 20 / cols local tile_width = 32 local tile_height = 32 local tile_data = {} -local abs_y = 1 +local abs_y = 0 +local rel_x = 0 +local abs_col = 0 +local block = 0 -for e,_ in ipairs(tile_types) do - for y = 1, tile_width do - row = {} - for x = 1, tile_height do - table.insert( row, e) +for _,e in pairs(tile_types) do + block = _ - 1 + + abs_row = math.floor(block / cols) + abs_col = block % cols + + rel_x = tile_width * (abs_col) + rel_y = tile_height * (abs_row) + + for y = 1, tile_height do + if tile_data[rel_y + y] == nil then + tile_data[rel_y + y] = {} + end + for x = 1, tile_width do + tile_data[rel_y + y][rel_x + x] = e end --- abs_y = abs_y + 1 - table.insert(tile_data, row) --- tile_data[abs_y] = row end + end return { -height = tile_height * #tile_data, -width = tile_height, -data = tile_data + height = tile_height * rows, + width = tile_width * cols, + data = tile_data } diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua index d6d78abd..bcfbcd90 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -1,10 +1,9 @@ require "locale.gen_combined.grilledham_map_gen.map_gen" -require "locale.gen_combined.grilledham_map_gen.builders" local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" local shape = picture_builder(pic.data, pic.width, pic.height) -shape = change_tile(shape, false, "deepwater") +shape = change_tile(shape, false, "out-of-map") return shape From 53f55aba225fe5bf5bf23ecb26fdfa6296995032 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 16:30:17 -0500 Subject: [PATCH 03/18] Grass tiles now get dagobah swamp based values --- .../grilledham_map_gen/data/biome_test.lua | 4 +- .../grilledham_map_gen/map_gen.lua | 188 +++++++++++++++--- .../grilledham_map_gen/presets/biome_test.lua | 4 +- 3 files changed, 161 insertions(+), 35 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index 73c97af0..27dd30bc 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -23,8 +23,8 @@ local tile_types = { local cols = 5 local rows = 20 / cols -local tile_width = 32 -local tile_height = 32 +local tile_width = 64 +local tile_height = 64 local tile_data = {} diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index a4129ecc..84561827 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -2,45 +2,169 @@ require("locale.gen_combined.grilledham_map_gen.builders") function run_combined_module(event) - if MAP_GEN == nil then - game.print("MAP_GEN not set") - return - end + if MAP_GEN == nil then + game.print("MAP_GEN not set") + return + end - local area = event.area - local surface = event.surface - MAP_GEN_SURFACE = surface - local tiles = {} - local entities = {} + local area = event.area + local surface = event.surface + MAP_GEN_SURFACE = surface + local tiles = {} + local entities = {} + local decoratives = {} - local top_x = area.left_top.x - local top_y = area.left_top.y + local top_x = area.left_top.x + local top_y = area.left_top.y - for y = top_y, top_y + 31 do - for x = top_x, top_x + 31 do + if map_gen_decoratives then + for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do + e.destroy() + end + for _, e in pairs(surface.find_entities_filtered{area=area, type="tree"}) do + e.destroy() + end + end - -- local coords need to be 'centered' to allow for correct rotation and scaling. - local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) - if type(tile) == "boolean" and not tile then - table.insert( tiles, {name = "out-of-map", position = {x, y}} ) - elseif type(tile) == "string" then - table.insert( tiles, {name = tile, position = {x, y}} ) + for y = top_y, top_y + 31 do + for x = top_x, top_x + 31 do + + -- local coords need to be 'centered' to allow for correct rotation and scaling. + local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) + + if type(tile) == "boolean" and not tile then + table.insert( tiles, {name = "out-of-map", position = {x, y}} ) + elseif type(tile) == "string" then + table.insert( tiles, {name = tile, position = {x, y}} ) + + if map_gen_decoratives then + tile_decoratives = check_decorative(tile, x, y) + for _,tbl in ipairs(tile_decoratives) do + table.insert(decoratives, tbl) + end + + + tile_entities = check_entities(tile, x, y) + for _,entity in ipairs(tile_entities) do + table.insert(entities, entity) + end end + end - if entity then - table.insert(entities, entity) - end - end - end - - -- set tiles. - surface.set_tiles(tiles, false) + if entity then + table.insert(entities, entity) + end - -- set entities - for _, v in ipairs(entities) do - if surface.can_place_entity(v) then - surface.create_entity(v) - end + end + end + + -- set tiles. + surface.set_tiles(tiles, false) + + -- set entities + for _, entity in ipairs(entities) do + if surface.can_place_entity {name=entity.name, position=entity.position} then + surface.create_entity {name=entity.name, position=entity.position} + end + end + + for _,deco in pairs(decoratives) do + if deco ~= nil then + surface.create_decoratives({check_collision=true, decoratives={deco}}) + end end + +end + +local decorative_options = { + ["concrete"] = {}, + ["deepwater"] = {}, + ["deepwater-green"] = {}, + ["dirt"] = {}, + ["dirt-dark"] = {}, + ["grass"] = { + {"green-carpet-grass", 3}, + {"green-hairy-grass", 7}, + {"green-bush-mini", 10}, + {"green-pita", 6}, + {"green-small-grass", 12}, + {"green-asterisk", 25}, + {"green-bush-mini", 7}, + }, + ["grass-dry"] = {}, + ["grass-medium"] = {}, + ["hazard-concrete-left"] = {}, + ["hazard-concrete-right"] = {}, + ["lab-dark-1"] = {}, + ["lab-dark-2"] = {}, + ["red-desert"] = {}, + ["red-desert-dark"] = {}, + ["sand"] = {}, + ["sand-dark"] = {}, + ["stone-path"] = {}, + ["water"] = {}, + ["water-green"] = {}, + ["out-of-map"] = {}, +} + +function check_decorative(tile, x, y) + local options = decorative_options[tile] + local tile_decoratives = {} + + for _,e in ipairs(options) do + name = e[1] + high_roll = e[2] + if math.random(1, high_roll) == 1 then + table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) + end + end + + return tile_decoratives +end + +local entity_options = { + ["concrete"] = {}, + ["deepwater"] = {}, + ["deepwater-green"] = {}, + ["dirt"] = {}, + ["dirt-dark"] = {}, + ["grass"] = { + {"tree-04", 400}, + {"tree-06", 150}, + {"tree-07", 400}, + {"tree-09", 1000}, + {"stone-rock", 400}, + {"green-coral", 10000}, + }, + ["grass-dry"] = {}, + ["grass-medium"] = {}, + ["hazard-concrete-left"] = {}, + ["hazard-concrete-right"] = {}, + ["lab-dark-1"] = {}, + ["lab-dark-2"] = {}, + ["red-desert"] = {}, + ["red-desert-dark"] = {}, + ["sand"] = {}, + ["sand-dark"] = {}, + ["stone-path"] = {}, + ["water"] = {}, + ["water-green"] = {}, + ["out-of-map"] = {}, +} + +function check_entities(tile, x, y) + local options = entity_options[tile] + local tile_entity_list = {} + + for _,e in ipairs(options) do + name = e[1] + high_roll = e[2] + if math.random(1, high_roll) == 1 then + table.insert(tile_entity_list, {name=name, position={x,y}}) + end + end + + return tile_entity_list + end diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua index bcfbcd90..3cbd24db 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -1,9 +1,11 @@ require "locale.gen_combined.grilledham_map_gen.map_gen" +map_gen_decoratives = true + local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" local shape = picture_builder(pic.data, pic.width, pic.height) -shape = change_tile(shape, false, "out-of-map") +--shape = change_tile(shape, false, "out-of-map") return shape From 707f90255dacf86f750be370656c4de0cd2735ae Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 18:56:26 -0500 Subject: [PATCH 04/18] Current status, messing with decoratives --- .../grilledham_map_gen/builders.lua | 86 ++++++- .../grilledham_map_gen/data/biome_test.lua | 38 ++-- .../grilledham_map_gen/map_gen.lua | 210 +++++++++++++----- .../grilledham_map_gen/presets/GoT.lua | 2 +- .../grilledham_map_gen/presets/biome_test.lua | 2 +- map_layout.lua | 1 + 6 files changed, 253 insertions(+), 86 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/builders.lua b/locale/gen_combined/grilledham_map_gen/builders.lua index c7f738d6..aae09c9a 100644 --- a/locale/gen_combined/grilledham_map_gen/builders.lua +++ b/locale/gen_combined/grilledham_map_gen/builders.lua @@ -67,11 +67,64 @@ function oval_builder(x_radius, y_radius) end end -function picture_builder(data, width, height) +local tile_map = +{ + [1] = false, + [2] = true, + [3] = "concrete", + [4] = "deepwater", + [5] = "deepwater-green", + [6] = "dirt", + [7] = "dirt-dark", + [8] = "grass", + [9] = "grass-dry", + [10] = "grass-medium", + [11] = "lab-dark-1", + [12] = "lab-dark-2", + [13] = "out-of-map", + [14] = "red-desert", + [15] = "red-desert-dark", + [16] = "sand", + [17] = "sand-dark", + [18] = "stone-path", + [19] = "water", + [20] = "water-green", +} + +function decompress(pic) + local data = pic.data + local width = pic.width + local height = pic.height + + local uncompressed = {} + + for y = 1, height do + local row = data[y] + local u_row = {} + uncompressed[y] = u_row + local x = 1 + for index = 1, #row, 2 do + local pixel = tile_map[row[index]] + local count = row[index + 1] + + for i = 1, count do + u_row[x] = pixel + x = x + 1 + end + end + end + + return {width = width, height = height, data = uncompressed} +end + +function picture_builder(pic) + local data = pic.data + local width = pic.width + local height = pic.height + -- the plus one is because lua tables are one based. local half_width = math.floor(width / 2) + 1 local half_height = math.floor(height / 2) + 1 - return function(x, y) x = math.floor(x) y = math.floor(y) @@ -79,12 +132,7 @@ function picture_builder(data, width, height) local y2 = y + half_height if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then - local pixel = "out-of-map" - if data[y2] ~= nil then - if data[y2][x2] ~= nil then - pixel = data[y2][x2] - end - end + local pixel = data[y2][x2] return pixel else return false @@ -171,6 +219,26 @@ function invert(builder) end end +function throttle_x(builder, x_in, x_size) + return function(x, y, world_x, world_y) + if x % x_size < x_in then + return builder(x, y, world_x, world_y) + else + return false + end + end +end + +function throttle_y(builder, y_in, y_size) + return function(x, y, world_x, world_y) + if y % y_size < y_in then + return builder(x, y, world_x, world_y) + else + return false + end + end +end + function throttle_xy(builder, x_in, x_size, y_in, y_size) return function(x, y, world_x, world_y) if x % x_size < x_in and y % y_size < y_in then @@ -377,7 +445,7 @@ function change_map_gen_tile(builder, old_tile, new_tile) return function (local_x, local_y, world_x, world_y ) local tile, entity = builder(local_x, local_y, world_x, world_y) if type(tile) == "boolean" and tile then - local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y) + local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y).name if old_tile == gen_tile then tile = new_tile end diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index 27dd30bc..0c0fae65 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -1,24 +1,24 @@ local tile_types = { "concrete", -"deepwater", -"deepwater-green", -"dirt", -"dirt-dark", -"grass", -"grass-dry", -"grass-medium", -"hazard-concrete-left", -"hazard-concrete-right", -"lab-dark-1", -"lab-dark-2", -"red-desert", -"red-desert-dark", -"sand", -"sand-dark", -"stone-path", -"water", -"water-green", -"out-of-map", + "deepwater", + "deepwater-green", + "dirt", + "dirt-dark", + "grass", + "grass-medium", + "grass-dry", + "hazard-concrete-left", + "hazard-concrete-right", + "lab-dark-1", + "lab-dark-2", + "red-desert", + "red-desert-dark", + "sand", + "sand-dark", + "stone-path", + "water", + "water-green", + "out-of-map", } local cols = 5 local rows = 20 / cols diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 84561827..147c79ce 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,4 +1,89 @@ require("locale.gen_combined.grilledham_map_gen.builders") +local Thread = require "locale.utils.Thread" + + +function run_init(params) + global._tiles_hold = {} + global._decoratives_hold = {} + global._entities_hold = {} +end + +function run_place_tiles(params) + local surface = params.surface + surface.set_tiles(global._tiles_hold) +end + +function run_place_items(params) + local surface = params.surface + for _,deco in pairs(global._decoratives_hold) do + surface.create_decoratives{check_collision=false, decoratives={deco}} + end + for _,deco in pairs(global._decoratives_hold) do + surface.create_decoratives{check_collision=false, decoratives={deco}} + end + for _, entity in ipairs(global._entities_hold) do + if surface.can_place_entity {name=entity.name, position=entity.position} then + surface.create_entity {name=entity.name, position=entity.position} + end + end +end + +function run_calc_items(params) + local top_x = params.top_x + local top_y = params.top_y + + for y = top_y, top_y + 31 do + for x = top_x, top_x + 31 do + + -- local coords need to be 'centered' to allow for correct rotation and scaling. + local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) + + if type(tile) == "boolean" and not tile then + table.insert( global._tiles_hold, {name = "out-of-map", position = {x, y}} ) + elseif type(tile) == "string" then + table.insert( global._tiles_hold, {name = tile, position = {x, y}} ) + + if tile == "water" or tile == "deepwater" or tile == "water-green" or tile == "deepwater-green" then + local a = x + 1 + table.insert(global._tiles_hold, {name = tile, position = {a,y}}) + local a = y + 1 + table.insert(global._tiles_hold, {name = tile, position = {x,a}}) + local a = x - 1 + table.insert(global._tiles_hold, {name = tile, position = {a,y}}) + local a = y - 1 + table.insert(global._tiles_hold, {name = tile, position = {x,a}}) + end + + if map_gen_decoratives then + tile_decoratives = check_decorative(tile, x, y) + for _,tbl in ipairs(tile_decoratives) do + table.insert(global._decoratives_hold, tbl) + end + + + tile_entities = check_entities(tile, x, y) + for _,entity in ipairs(tile_entities) do + table.insert(global._entities_hold, entity) + end + end + end + + if entity then + table.insert(global._entities_hold, entity) + end + + end + end +end + +function run_chart_update(params) + local x = params.area.left_top.x / 32 + local y = params.area.left_top.y / 32 + if game.forces.player.is_chunk_charted(params.surface, {x,y} ) then + -- Don't use full area, otherwise adjacent chunks get charted + game.forces.player.chart(params.surface, {{ params.area.left_top.x, params.area.left_top.y}, { params.area.left_top.x+30, params.area.left_top.y+30} } ) + end +end function run_combined_module(event) @@ -10,70 +95,30 @@ function run_combined_module(event) local area = event.area local surface = event.surface MAP_GEN_SURFACE = surface - local tiles = {} - local entities = {} - local decoratives = {} + local top_x = area.left_top.x local top_y = area.left_top.y if map_gen_decoratives then - for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do + for _, e in pairs(surface.find_entities_filtered{area=area, type="decorative"}) do e.destroy() end for _, e in pairs(surface.find_entities_filtered{area=area, type="tree"}) do e.destroy() end - end - - - for y = top_y, top_y + 31 do - for x = top_x, top_x + 31 do - - -- local coords need to be 'centered' to allow for correct rotation and scaling. - local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) - - if type(tile) == "boolean" and not tile then - table.insert( tiles, {name = "out-of-map", position = {x, y}} ) - elseif type(tile) == "string" then - table.insert( tiles, {name = tile, position = {x, y}} ) - - if map_gen_decoratives then - tile_decoratives = check_decorative(tile, x, y) - for _,tbl in ipairs(tile_decoratives) do - table.insert(decoratives, tbl) - end - - - tile_entities = check_entities(tile, x, y) - for _,entity in ipairs(tile_entities) do - table.insert(entities, entity) - end - end - end - - if entity then - table.insert(entities, entity) - end - + for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do + e.destroy() end end - -- set tiles. - surface.set_tiles(tiles, false) + Thread.queue_action("run_init", {} ) - -- set entities - for _, entity in ipairs(entities) do - if surface.can_place_entity {name=entity.name, position=entity.position} then - surface.create_entity {name=entity.name, position=entity.position} - end - end + Thread.queue_action("run_calc_items", {surface = event.surface, top_x = top_x, top_y = top_y}) - for _,deco in pairs(decoratives) do - if deco ~= nil then - surface.create_decoratives({check_collision=true, decoratives={deco}}) - end - end + Thread.queue_action("run_place_tiles", {surface = event.surface}) + Thread.queue_action("run_place_items", {surface = event.surface}) + Thread.queue_action("run_chart_update", {area = event.area, surface = event.surface} ) end @@ -92,15 +137,46 @@ local decorative_options = { {"green-asterisk", 25}, {"green-bush-mini", 7}, }, - ["grass-dry"] = {}, - ["grass-medium"] = {}, + ["grass-medium"] = { + {"green-carpet-grass", 12}, + {"green-hairy-grass", 28}, + {"green-bush-mini", 40}, + {"green-pita", 24}, + {"green-small-grass", 48}, + {"green-asterisk", 100}, + {"green-bush-mini", 28}, + }, + ["grass-dry"] = { + {"green-carpet-grass", 24}, + {"green-hairy-grass", 56}, + {"green-bush-mini", 80}, + {"green-pita", 48}, + {"green-small-grass", 96}, + {"green-asterisk", 200}, + {"green-bush-mini", 56}, + }, ["hazard-concrete-left"] = {}, ["hazard-concrete-right"] = {}, ["lab-dark-1"] = {}, ["lab-dark-2"] = {}, - ["red-desert"] = {}, - ["red-desert-dark"] = {}, - ["sand"] = {}, + ["red-desert"] = { + {"brown-carpet-grass", 35}, + {"orange-coral-mini", 45}, + {"red-asterisk", 45}, + {"red-desert-bush", 12}, + {"red-desert-rock-medium", 375}, + {"red-desert-rock-small", 200}, + {"red-desert-rock-tiny", 30}, + }, + ["red-desert-dark"] = { + {"brown-carpet-grass", 70}, + {"orange-coral-mini", 90}, + {"red-asterisk", 90}, + {"red-desert-bush", 35}, + {"red-desert-rock-medium", 375}, + {"red-desert-rock-small", 200}, + {"red-desert-rock-tiny", 150}, + }, ["sand-dark"] = {}, ["stone-path"] = {}, ["water"] = {}, @@ -143,8 +219,30 @@ local entity_options = { ["hazard-concrete-right"] = {}, ["lab-dark-1"] = {}, ["lab-dark-2"] = {}, - ["red-desert"] = {}, - ["red-desert-dark"] = {}, + ["red-desert"] = { + {"dry-tree", 400}, + {"dry-hairy-tree", 400}, + {"tree-06", 500}, + {"tree-06", 500}, + {"tree-01", 500}, + {"tree-02", 500}, + {"tree-03", 500}, + {"red-desert-rock-big-01", 200}, + {"red-desert-rock-huge-01", 400}, + {"red-desert-rock-huge-02", 400}, + }, + ["red-desert-dark"] = { + {"dry-tree", 400}, + {"dry-hairy-tree", 400}, + {"tree-06", 500}, + {"tree-06", 500}, + {"tree-01", 500}, + {"tree-02", 500}, + {"tree-03", 500}, + {"red-desert-rock-big-01", 200}, + {"red-desert-rock-huge-01", 400}, + {"red-desert-rock-huge-02", 400}, + }, ["sand"] = {}, ["sand-dark"] = {}, ["stone-path"] = {}, diff --git a/locale/gen_combined/grilledham_map_gen/presets/GoT.lua b/locale/gen_combined/grilledham_map_gen/presets/GoT.lua index c99bfb06..595b73a8 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/GoT.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/GoT.lua @@ -1,6 +1,6 @@ require "locale.gen_combined.grilledham_map_gen.map_gen" require "locale.gen_combined.grilledham_map_gen.builders" - +map_gen_decoratives = true local pic = require "locale.gen_combined.grilledham_map_gen.data.GoT" local pic = decompress(pic) diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua index 3cbd24db..ef371e8e 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -4,7 +4,7 @@ map_gen_decoratives = true local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" -local shape = picture_builder(pic.data, pic.width, pic.height) +local shape = picture_builder(pic) --shape = change_tile(shape, false, "out-of-map") diff --git a/map_layout.lua b/map_layout.lua index be6fe40d..c2be0337 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -24,6 +24,7 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" +--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --shapes-- --require "locale.gen_shape.left" From 07c386ac321c4f7eb716b3af14c282dd8d9a00b0 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Mon, 13 Nov 2017 07:05:18 -0500 Subject: [PATCH 05/18] Additional tweaks and reordered the biomes to be next to each other --- .../grilledham_map_gen/data/biome_test.lua | 22 ++-- .../grilledham_map_gen/map_gen.lua | 101 ++++++++++++++---- 2 files changed, 93 insertions(+), 30 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index 0c0fae65..21ae110b 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -1,30 +1,30 @@ local tile_types = { + "hazard-concrete-left", "concrete", - "deepwater", - "deepwater-green", - "dirt", - "dirt-dark", + "stone-path", + "hazard-concrete-right", + "lab-dark-1", "grass", "grass-medium", "grass-dry", - "hazard-concrete-left", - "hazard-concrete-right", - "lab-dark-1", - "lab-dark-2", + "dirt", + "dirt-dark", "red-desert", "red-desert-dark", "sand", "sand-dark", - "stone-path", + "lab-dark-2", "water", + "deepwater", "water-green", + "deepwater-green", "out-of-map", } local cols = 5 local rows = 20 / cols -local tile_width = 64 -local tile_height = 64 +local tile_width = 32 +local tile_height = 32 local tile_data = {} diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 147c79ce..4c17f52f 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -10,7 +10,7 @@ end function run_place_tiles(params) local surface = params.surface - surface.set_tiles(global._tiles_hold) + surface.set_tiles(global._tiles_hold, true) end function run_place_items(params) @@ -18,9 +18,6 @@ function run_place_items(params) for _,deco in pairs(global._decoratives_hold) do surface.create_decoratives{check_collision=false, decoratives={deco}} end - for _,deco in pairs(global._decoratives_hold) do - surface.create_decoratives{check_collision=false, decoratives={deco}} - end for _, entity in ipairs(global._entities_hold) do if surface.can_place_entity {name=entity.name, position=entity.position} then surface.create_entity {name=entity.name, position=entity.position} @@ -125,9 +122,23 @@ end local decorative_options = { ["concrete"] = {}, ["deepwater"] = {}, - ["deepwater-green"] = {}, - ["dirt"] = {}, - ["dirt-dark"] = {}, + ["deepwater-green"] = { + {"brown-carpet-grass", 100}, + {"brown-cane-cluster", 500}, + }, + ["dirt"] = { + {"brown-carpet-grass", 100}, + {"brown-cane-cluster", 200}, + {"red-desert-rock-tiny", 150}, + }, + ["dirt-dark"] = { + {"red-desert-rock-tiny", 150}, + {"red-asterisk", 45}, + {"red-desert-bush", 12}, + {"red-desert-rock-medium", 375}, + + + }, ["grass"] = { {"green-carpet-grass", 3}, {"green-hairy-grass", 7}, @@ -136,6 +147,7 @@ local decorative_options = { {"green-small-grass", 12}, {"green-asterisk", 25}, {"green-bush-mini", 7}, + {"garballo", 20}, }, ["grass-medium"] = { {"green-carpet-grass", 12}, @@ -147,13 +159,14 @@ local decorative_options = { {"green-bush-mini", 28}, }, ["grass-dry"] = { - {"green-carpet-grass", 24}, {"green-hairy-grass", 56}, {"green-bush-mini", 80}, {"green-pita", 48}, {"green-small-grass", 96}, {"green-asterisk", 200}, {"green-bush-mini", 56}, + {"brown-cane-cluster", 100}, + {"brown-carpet-grass", 100}, }, ["hazard-concrete-left"] = {}, ["hazard-concrete-right"] = {}, @@ -177,7 +190,17 @@ local decorative_options = { {"red-desert-rock-small", 200}, {"red-desert-rock-tiny", 150}, }, - ["sand-dark"] = {}, + ["sand"] = { + {"brown-carpet-grass", 35}, + {"orange-coral-mini", 45}, + {"red-asterisk", 45}, + {"brown-asterisk", 45}, + }, + ["sand-dark"] = { + {"brown-carpet-grass", 35}, + {"orange-coral-mini", 45}, + {"brown-asterisk", 45}, + }, ["stone-path"] = {}, ["water"] = {}, ["water-green"] = {}, @@ -203,18 +226,48 @@ local entity_options = { ["concrete"] = {}, ["deepwater"] = {}, ["deepwater-green"] = {}, - ["dirt"] = {}, - ["dirt-dark"] = {}, - ["grass"] = { - {"tree-04", 400}, + ["water"] = {}, + ["water-green"] = {}, + ["dirt"] = { + {"tree-01", 500}, + {"tree-06", 300}, + {"tree-07", 800}, + {"tree-09", 2000}, + {"stone-rock", 400}, + }, + ["dirt-dark"] = { {"tree-06", 150}, {"tree-07", 400}, {"tree-09", 1000}, + {"stone-rock", 300}, + }, + ["grass"] = { + {"tree-01", 150}, + {"tree-04", 400}, + {"tree-06", 400}, + {"tree-07", 400}, + {"tree-09", 1000}, {"stone-rock", 400}, {"green-coral", 10000}, }, - ["grass-dry"] = {}, - ["grass-medium"] = {}, + ["grass-medium"] = { + {"tree-02", 400}, + {"tree-03", 400}, + {"tree-04", 800}, + {"tree-06", 300}, + {"tree-07", 800}, + {"tree-08", 400}, + {"tree-09", 2000}, + {"stone-rock", 400}, + }, + ["grass-dry"] = { + {"tree-04", 800}, + {"tree-06", 300}, + {"tree-07", 400}, + {"tree-09", 1000}, + {"dry-tree", 1000}, + {"stone-rock", 200}, + }, ["hazard-concrete-left"] = {}, ["hazard-concrete-right"] = {}, ["lab-dark-1"] = {}, @@ -243,11 +296,21 @@ local entity_options = { {"red-desert-rock-huge-01", 400}, {"red-desert-rock-huge-02", 400}, }, - ["sand"] = {}, - ["sand-dark"] = {}, + ["sand"] = { + {"dry-tree", 1000}, + {"dry-hairy-tree", 1000}, + {"dead-tree", 1000}, + {"stone-rock", 150}, + + }, + ["sand-dark"] = { + {"dead-tree", 1000}, + {"dry-tree", 1000}, + {"dry-hairy-tree", 1000}, + {"stone-rock", 150}, + + }, ["stone-path"] = {}, - ["water"] = {}, - ["water-green"] = {}, ["out-of-map"] = {}, } From 13d0b77b4d114814bba9c0c91bf0e5de2e4f5798 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Mon, 13 Nov 2017 15:50:14 -0500 Subject: [PATCH 06/18] Staging for play test --- map_layout.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/map_layout.lua b/map_layout.lua index c2be0337..c814e69d 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -23,8 +23,8 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.cage" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" -MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" ---MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" +--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" +MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --shapes-- --require "locale.gen_shape.left" @@ -51,7 +51,7 @@ MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" --ores-- --require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.fluffy_rainbows" ---require "locale.gen_ores.rso.rso_control" +require "locale.gen_ores.rso.rso_control" --everything else. You may use more than one of these, but beware they might not be compatible miscs = {} @@ -59,7 +59,7 @@ miscs = {} --require "locale.gen_misc.rusky_pvp" --miscs[1] = require "locale.gen_misc.wreck_items" --miscs[2] = require "locale.gen_misc.tris_chunk_grid" ---miscs[1] = require "locale.gen_ores.glitter_ores" +miscs[1] = require "locale.gen_ores.glitter_ores" local on_chunk_generated = function(event) if run_combined_module == nil then From 23a78b468e5a99cfdc4ce813e784a3ad5738b397 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Wed, 15 Nov 2017 05:53:49 -0500 Subject: [PATCH 07/18] Order of operations on Misc vs ores in map layout to allow glitter to take effect. Also implemented the poisson RNG --- .../grilledham_map_gen/map_gen.lua | 6 +++-- locale/gen_ores/glitter_ores.lua | 2 +- locale/gen_shared/poisson.lua | 27 +++++++++++++++++++ map_layout.lua | 8 +++--- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 locale/gen_shared/poisson.lua diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 4c17f52f..1682e88a 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,4 +1,6 @@ require("locale.gen_combined.grilledham_map_gen.builders") +require("locale.gen_shared.poisson") + local Thread = require "locale.utils.Thread" @@ -214,7 +216,7 @@ function check_decorative(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if math.random(1, high_roll) == 1 then + if poison_rng_next(high_roll / 2 ) == 1 then table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) end end @@ -321,7 +323,7 @@ function check_entities(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if math.random(1, high_roll) == 1 then + if poison_rng_next( high_roll / 2 ) == 1 then table.insert(tile_entity_list, {name=name, position={x,y}}) end end diff --git a/locale/gen_ores/glitter_ores.lua b/locale/gen_ores/glitter_ores.lua index 128632aa..6472854e 100644 --- a/locale/gen_ores/glitter_ores.lua +++ b/locale/gen_ores/glitter_ores.lua @@ -16,7 +16,7 @@ function run_ores_module_setup() ["stone"] = 0.25 } -- 1-100% chance of sprinkling any individual ore - sprinkle_factor = 10 + sprinkle_factor = 20 -- Sets the buffer distance before ores are scrambled starting_buffer = 125 diff --git a/locale/gen_shared/poisson.lua b/locale/gen_shared/poisson.lua new file mode 100644 index 00000000..7d9c1ac3 --- /dev/null +++ b/locale/gen_shared/poisson.lua @@ -0,0 +1,27 @@ +local function generate_pmf_chart(l) + chart = {[0] = math.exp(-l)} + for k=1,(l*2 + 1) do + chart[k] = (chart[k - 1] * l / k) + end + return chart +end + +local function generate_poisson_set(l, n) --n defines the resolution + local chart = generate_pmf_chart(l) + local set = {} + for x,y in pairs(chart) do + local m = math.floor(y * n + 0.5) + for i=0,m do + table.insert(set,x) + end + end + return set +end + +global.poisson_set = {} +function poison_rng_next(l) + if not global.poisson_set[l] then + global.poisson_set[l] = generate_poisson_set(l, 1000) + end + return global.poisson_set[l][math.random(1000)] +end diff --git a/map_layout.lua b/map_layout.lua index dad4709e..095293c5 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -53,7 +53,7 @@ MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --ores-- --require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.fluffy_rainbows" ---require "locale.gen_ores.rso.rso_control" +require "locale.gen_ores.rso.rso_control" --require "locale.gen_ores.harmonic_gen" --everything else. You may use more than one of these, but beware they might not be compatible @@ -88,12 +88,12 @@ local on_chunk_generated = function(event) end else run_combined_module(event) - for _,v in pairs(miscs) do - v.on_chunk_generated(event) - end if run_ores_module ~= nil then run_ores_module(event) end + for _,v in pairs(miscs) do + v.on_chunk_generated(event) + end end end From 10d1b0ebe3a9b9e18facc4b3bdaed5df780f7716 Mon Sep 17 00:00:00 2001 From: Maik Wild Date: Wed, 15 Nov 2017 13:41:34 +0100 Subject: [PATCH 08/18] Moved poisson rng to utils, fixed a potential nil reference and fixed poison typo --- locale/gen_combined/grilledham_map_gen/map_gen.lua | 7 +++---- locale/{gen_shared/poisson.lua => utils/poisson_rng.lua} | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) rename locale/{gen_shared/poisson.lua => utils/poisson_rng.lua} (79%) diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 1682e88a..d9fa884e 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,5 +1,5 @@ require("locale.gen_combined.grilledham_map_gen.builders") -require("locale.gen_shared.poisson") +require("locale.utils.poisson") local Thread = require "locale.utils.Thread" @@ -216,7 +216,7 @@ function check_decorative(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if poison_rng_next(high_roll / 2 ) == 1 then + if poisson_rng_next(high_roll / 2 ) == 1 then table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) end end @@ -323,11 +323,10 @@ function check_entities(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if poison_rng_next( high_roll / 2 ) == 1 then + if poisson_rng_next( high_roll / 2 ) == 1 then table.insert(tile_entity_list, {name=name, position={x,y}}) end end return tile_entity_list - end diff --git a/locale/gen_shared/poisson.lua b/locale/utils/poisson_rng.lua similarity index 79% rename from locale/gen_shared/poisson.lua rename to locale/utils/poisson_rng.lua index 7d9c1ac3..1a54e1b0 100644 --- a/locale/gen_shared/poisson.lua +++ b/locale/utils/poisson_rng.lua @@ -1,3 +1,5 @@ +--Author: Valansch + local function generate_pmf_chart(l) chart = {[0] = math.exp(-l)} for k=1,(l*2 + 1) do @@ -15,13 +17,14 @@ local function generate_poisson_set(l, n) --n defines the resolution table.insert(set,x) end end + set._n = #set return set end global.poisson_set = {} -function poison_rng_next(l) +function poisson_rng_next(l) if not global.poisson_set[l] then global.poisson_set[l] = generate_poisson_set(l, 1000) end - return global.poisson_set[l][math.random(1000)] + return global.poisson_set[l][math.random(global.poisson_set[l]._n)] end From 1d82203c4fd64396d991ce1eefc688cf0c9e750c Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Wed, 15 Nov 2017 19:24:20 -0500 Subject: [PATCH 09/18] As deployed / playtested with changes. --- locale/gen_combined/grilledham_map_gen/map_gen.lua | 2 +- map_layout.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index d9fa884e..70e94017 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,5 +1,5 @@ require("locale.gen_combined.grilledham_map_gen.builders") -require("locale.utils.poisson") +require("locale.utils.poisson_rng") local Thread = require "locale.utils.Thread" diff --git a/map_layout.lua b/map_layout.lua index 095293c5..0edd25ec 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -25,7 +25,7 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" -MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" +--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --require "locale.grilledham_map_gen.presets.UK" --shapes-- @@ -53,7 +53,7 @@ MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --ores-- --require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.fluffy_rainbows" -require "locale.gen_ores.rso.rso_control" +--require "locale.gen_ores.rso.rso_control" --require "locale.gen_ores.harmonic_gen" --everything else. You may use more than one of these, but beware they might not be compatible @@ -62,7 +62,7 @@ miscs = {} --require "locale.gen_misc.rusky_pvp" --miscs[1] = require "locale.gen_misc.wreck_items" --miscs[2] = require "locale.gen_misc.tris_chunk_grid" -miscs[1] = require "locale.gen_ores.glitter_ores" +--miscs[1] = require "locale.gen_ores.glitter_ores" local on_chunk_generated = function(event) if run_combined_module == nil then From 5a5d77f7cac832dcb576c92c6d8200780df46358 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 08:11:06 -0500 Subject: [PATCH 10/18] Start of the deco overlay on picture maps -- working on a biome test area --- .../grilledham_map_gen/data/biome_test.lua | 47 +++++++++++++++++++ .../grilledham_map_gen/map_gen.lua | 26 +++++----- .../grilledham_map_gen/presets/biome_test.lua | 10 ++++ 3 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 locale/gen_combined/grilledham_map_gen/data/biome_test.lua create mode 100644 locale/gen_combined/grilledham_map_gen/presets/biome_test.lua diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua new file mode 100644 index 00000000..d0c8058e --- /dev/null +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -0,0 +1,47 @@ +local tile_types = { + "concrete", +"deepwater", +"deepwater-green", +"dirt", +"dirt-dark", +"grass", +"grass-dry", +"grass-medium", +"hazard-concrete-left", +"hazard-concrete-right", +"lab-dark-1", +"lab-dark-2", +"out-of-map", +"red-desert", +"red-desert-dark", +"sand", +"sand-dark", +"stone-path", +"water", +"water-green" +} + +local tile_width = 32 +local tile_height = 32 + +local tile_data = {} + +local abs_y = 1 + +for e,_ in ipairs(tile_types) do + for y = 1, tile_width do + row = {} + for x = 1, tile_height do + table.insert( row, e) + end +-- abs_y = abs_y + 1 + table.insert(tile_data, row) +-- tile_data[abs_y] = row + end +end + +return { +height = tile_height * #tile_data, +width = tile_height, +data = tile_data +} diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 74327744..a4129ecc 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,7 +1,7 @@ require("locale.gen_combined.grilledham_map_gen.builders") function run_combined_module(event) - + if MAP_GEN == nil then game.print("MAP_GEN not set") return @@ -18,29 +18,29 @@ function run_combined_module(event) for y = top_y, top_y + 31 do for x = top_x, top_x + 31 do - - -- local coords need to be 'centered' to allow for correct rotation and scaling. - local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) - if type(tile) == "boolean" and not tile then - table.insert( tiles, {name = "out-of-map", position = {x, y}} ) + -- local coords need to be 'centered' to allow for correct rotation and scaling. + local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) + + if type(tile) == "boolean" and not tile then + table.insert( tiles, {name = "out-of-map", position = {x, y}} ) elseif type(tile) == "string" then - table.insert( tiles, {name = tile, position = {x, y}} ) + table.insert( tiles, {name = tile, position = {x, y}} ) end if entity then table.insert(entities, entity) end end - end + end -- set tiles. surface.set_tiles(tiles, false) -- set entities - for _, v in ipairs(entities) do - if surface.can_place_entity(v) then - surface.create_entity(v) + for _, v in ipairs(entities) do + if surface.can_place_entity(v) then + surface.create_entity(v) end - end -end \ No newline at end of file + end +end diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua new file mode 100644 index 00000000..d6d78abd --- /dev/null +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -0,0 +1,10 @@ +require "locale.gen_combined.grilledham_map_gen.map_gen" +require "locale.gen_combined.grilledham_map_gen.builders" + +local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" + +local shape = picture_builder(pic.data, pic.width, pic.height) + +shape = change_tile(shape, false, "deepwater") + +return shape From 910b55f65077ee20da43ed6a456fa977bd91797e Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 11:41:30 -0500 Subject: [PATCH 11/18] Multi row and column representation for all tile types. --- .../grilledham_map_gen/builders.lua | 98 ++++++++++--------- .../grilledham_map_gen/data/biome_test.lua | 41 +++++--- .../grilledham_map_gen/presets/biome_test.lua | 3 +- 3 files changed, 80 insertions(+), 62 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/builders.lua b/locale/gen_combined/grilledham_map_gen/builders.lua index 6fe45260..c41852a3 100644 --- a/locale/gen_combined/grilledham_map_gen/builders.lua +++ b/locale/gen_combined/grilledham_map_gen/builders.lua @@ -17,27 +17,27 @@ function full_builder(x, y) return true end -function path_builder(thickness, optional_thickness_height) +function path_builder(thickness, optional_thickness_height) local width = thickness / 2 local thickness2 = optional_thickness_height or thickness - local height = thickness2 / 2 - return function(x, y) + local height = thickness2 / 2 + return function(x, y) return (x > -width and x <= width) or (y > -height and y <= height) end end -function rectangle_builder(width, height) - width = width / 2 - height = height / 2 - return function (x, y) - return x > -width and x <= width and y > -height and y <= height +function rectangle_builder(width, height) + width = width / 2 + height = height / 2 + return function (x, y) + return x > -width and x <= width and y > -height and y <= height end end function square_diamond_builder(size) size = size / 2 - return function (x, y) - return math.abs(x) + math.abs(y) <= size + return function (x, y) + return math.abs(x) + math.abs(y) <= size end end @@ -52,14 +52,14 @@ function rectangle_diamond_builder(width, height) end end -function circle_builder(radius) +function circle_builder(radius) local rr = radius * radius return function (x, y) return x * x + y * y < rr end end -function oval_builder(x_radius, y_radius) +function oval_builder(x_radius, y_radius) local x_rr = x_radius * x_radius local y_rr = y_radius * y_radius return function (x, y) @@ -125,18 +125,24 @@ function picture_builder(pic) -- the plus one is because lua tables are one based. local half_width = math.floor(width / 2) + 1 local half_height = math.floor(height / 2) + 1 + return function(x, y) x = math.floor(x) y = math.floor(y) local x2 = x + half_width - local y2 = y + half_height + local y2 = y + half_height if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then - local pixel = data[y2][x2] + local pixel = "out-of-map" + if data[y2] ~= nil then + if data[y2][x2] ~= nil then + pixel = data[y2][x2] + end + end return pixel else return false - end + end end end @@ -155,7 +161,7 @@ function scale(builder, x_scale, y_scale) return builder(x * x_scale, y * y_scale, world_x, world_y) end end - + function rotate(builder, angle) local qx = math.cos(angle) local qy = math.sin(angle) @@ -194,8 +200,8 @@ end -- For resource_module_builder it will return the first success. function compound_or(builders) return function(x, y, world_x, world_y) - for _, v in ipairs(builders) do - local tile, entity = v(x, y, world_x, world_y) + for _, v in ipairs(builders) do + local tile, entity = v(x, y, world_x, world_y) if tile then return tile, entity end end return false @@ -241,8 +247,8 @@ end function throttle_xy(builder, x_in, x_size, y_in, y_size) return function(x, y, world_x, world_y) - if x % x_size < x_in and y % y_size < y_in then - return builder(x, y, world_x, world_y) + if x % x_size < x_in and y % y_size < y_in then + return builder(x, y, world_x, world_y) else return false end @@ -262,7 +268,7 @@ end function linear_grow(shape, size) local half_size = size / 2 return function (local_x, local_y, world_x, world_y) - local t = math.ceil((local_y / size) + 0.5) + local t = math.ceil((local_y / size) + 0.5) local n = math.ceil((math.sqrt(8 * t + 1) - 1) / 2) local t_upper = n * (n + 1) * 0.5 local t_lower = t_upper - n @@ -274,11 +280,11 @@ function linear_grow(shape, size) end end -function project(shape, size, r) +function project(shape, size, r) local ln_r = math.log(r) local r2 = 1 / (r - 1) local a = 1 / size - + return function(local_x, local_y, world_x, world_y) local offset = 0.5 * size local sn = math.ceil(local_y + offset) @@ -289,21 +295,21 @@ function project(shape, size, r) local c = size * rn local sn_upper = size * (r ^ (n + 1) - 1) * r2 - local x = local_x * rn2 - local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 + local x = local_x * rn2 + local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 return shape(x, y, world_x, world_y) end end -function project_overlap(shape, size, r) +function project_overlap(shape, size, r) local ln_r = math.log(r) local r2 = 1 / (r - 1) local a = 1 / size local offset = 0.5 * size - + return function(local_x, local_y, world_x, world_y) - + local sn = math.ceil(local_y + offset) local n = math.ceil(math.log((r-1) * sn * a + 1) / ln_r - 1) @@ -312,8 +318,8 @@ function project_overlap(shape, size, r) local c = size * rn local sn_upper = size * (r ^ (n + 1) - 1) * r2 - local x = local_x * rn2 - local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 + local x = local_x * rn2 + local y = (local_y - (sn_upper - 0.5 * c ) + offset ) * rn2 local tile local entity @@ -323,7 +329,7 @@ function project_overlap(shape, size, r) return tile, entity end - local n_above = n - 1 + local n_above = n - 1 local rn_above = rn / r local rn2_above = 1 / rn_above local c_above = size * rn_above @@ -344,8 +350,8 @@ function project_overlap(shape, size, r) local x_below = local_x * rn2_below local y_below = (local_y - (sn_upper_below - 0.5 * c_below ) + offset ) * rn2_below - return shape(x_below, y_below, world_x, world_y) - + return shape(x_below, y_below, world_x, world_y) + end end @@ -356,12 +362,12 @@ function resource_module_builder(builder, resource_type, amount_function) amount_function = amount_function or function(a, b) return 603 end return function(x, y, world_x, world_y) if builder(x, y, world_x, world_y) then - return + return { name = resource_type, position = {world_x, world_y}, amount = amount_function(world_x, world_y) - } + } else return nil end @@ -373,9 +379,9 @@ function builder_with_resource(land_builder, resource_module) local tile = land_builder(x, y) if tile then local entity = resource_module(x, y ,world_x, world_y) - return tile, entity + return tile, entity else - return false + return false end end end @@ -388,27 +394,27 @@ function single_pattern_builder(shape, width, height) local half_width = width / 2 local half_height = height / 2 - return function (local_x, local_y, world_x, world_y) - local_y = ((local_y + half_height) % height) - half_height - local_x = ((local_x + half_width) % width) - half_width + return function (local_x, local_y, world_x, world_y) + local_y = ((local_y + half_height) % height) - half_height + local_x = ((local_x + half_width) % width) - half_width return shape(local_x, local_y, world_x, world_y) end end function grid_pattern_builder(pattern, columns, rows, width, height) - + local half_width = width / 2 local half_height = height / 2 return function (local_x, local_y, world_x, world_y) - local local_y2 = ((local_y + half_height) % height) - half_height + local local_y2 = ((local_y + half_height) % height) - half_height local row_pos = math.floor(local_y / height + 0.5) local row_i = row_pos % rows + 1 - local row = pattern[row_i] or {} + local row = pattern[row_i] or {} - local local_x2 = ((local_x + half_width) % width) - half_width - local col_pos = math.floor(local_x / width + 0.5) + local local_x2 = ((local_x + half_width) % width) - half_width + local col_pos = math.floor(local_x / width + 0.5) local col_i = col_pos % columns + 1 local shape = row[col_i] or empty_builder @@ -474,4 +480,4 @@ function apply_effect(builder, func) tile, entity = func(local_x, local_y, world_x, world_y, tile, entity) return tile, entity end -end \ No newline at end of file +end diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index d0c8058e..73c97af0 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -11,37 +11,50 @@ local tile_types = { "hazard-concrete-right", "lab-dark-1", "lab-dark-2", -"out-of-map", "red-desert", "red-desert-dark", "sand", "sand-dark", "stone-path", "water", -"water-green" +"water-green", +"out-of-map", } +local cols = 5 +local rows = 20 / cols local tile_width = 32 local tile_height = 32 local tile_data = {} -local abs_y = 1 +local abs_y = 0 +local rel_x = 0 +local abs_col = 0 +local block = 0 -for e,_ in ipairs(tile_types) do - for y = 1, tile_width do - row = {} - for x = 1, tile_height do - table.insert( row, e) +for _,e in pairs(tile_types) do + block = _ - 1 + + abs_row = math.floor(block / cols) + abs_col = block % cols + + rel_x = tile_width * (abs_col) + rel_y = tile_height * (abs_row) + + for y = 1, tile_height do + if tile_data[rel_y + y] == nil then + tile_data[rel_y + y] = {} + end + for x = 1, tile_width do + tile_data[rel_y + y][rel_x + x] = e end --- abs_y = abs_y + 1 - table.insert(tile_data, row) --- tile_data[abs_y] = row end + end return { -height = tile_height * #tile_data, -width = tile_height, -data = tile_data + height = tile_height * rows, + width = tile_width * cols, + data = tile_data } diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua index d6d78abd..bcfbcd90 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -1,10 +1,9 @@ require "locale.gen_combined.grilledham_map_gen.map_gen" -require "locale.gen_combined.grilledham_map_gen.builders" local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" local shape = picture_builder(pic.data, pic.width, pic.height) -shape = change_tile(shape, false, "deepwater") +shape = change_tile(shape, false, "out-of-map") return shape From 1a770ecca2fc292f84fdaac5b0bbf7a1d09f1c09 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 16:30:17 -0500 Subject: [PATCH 12/18] Grass tiles now get dagobah swamp based values --- .../grilledham_map_gen/data/biome_test.lua | 4 +- .../grilledham_map_gen/map_gen.lua | 188 +++++++++++++++--- .../grilledham_map_gen/presets/biome_test.lua | 4 +- 3 files changed, 161 insertions(+), 35 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index 73c97af0..27dd30bc 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -23,8 +23,8 @@ local tile_types = { local cols = 5 local rows = 20 / cols -local tile_width = 32 -local tile_height = 32 +local tile_width = 64 +local tile_height = 64 local tile_data = {} diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index a4129ecc..84561827 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -2,45 +2,169 @@ require("locale.gen_combined.grilledham_map_gen.builders") function run_combined_module(event) - if MAP_GEN == nil then - game.print("MAP_GEN not set") - return - end + if MAP_GEN == nil then + game.print("MAP_GEN not set") + return + end - local area = event.area - local surface = event.surface - MAP_GEN_SURFACE = surface - local tiles = {} - local entities = {} + local area = event.area + local surface = event.surface + MAP_GEN_SURFACE = surface + local tiles = {} + local entities = {} + local decoratives = {} - local top_x = area.left_top.x - local top_y = area.left_top.y + local top_x = area.left_top.x + local top_y = area.left_top.y - for y = top_y, top_y + 31 do - for x = top_x, top_x + 31 do + if map_gen_decoratives then + for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do + e.destroy() + end + for _, e in pairs(surface.find_entities_filtered{area=area, type="tree"}) do + e.destroy() + end + end - -- local coords need to be 'centered' to allow for correct rotation and scaling. - local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) - if type(tile) == "boolean" and not tile then - table.insert( tiles, {name = "out-of-map", position = {x, y}} ) - elseif type(tile) == "string" then - table.insert( tiles, {name = tile, position = {x, y}} ) + for y = top_y, top_y + 31 do + for x = top_x, top_x + 31 do + + -- local coords need to be 'centered' to allow for correct rotation and scaling. + local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) + + if type(tile) == "boolean" and not tile then + table.insert( tiles, {name = "out-of-map", position = {x, y}} ) + elseif type(tile) == "string" then + table.insert( tiles, {name = tile, position = {x, y}} ) + + if map_gen_decoratives then + tile_decoratives = check_decorative(tile, x, y) + for _,tbl in ipairs(tile_decoratives) do + table.insert(decoratives, tbl) + end + + + tile_entities = check_entities(tile, x, y) + for _,entity in ipairs(tile_entities) do + table.insert(entities, entity) + end end + end - if entity then - table.insert(entities, entity) - end - end - end - - -- set tiles. - surface.set_tiles(tiles, false) + if entity then + table.insert(entities, entity) + end - -- set entities - for _, v in ipairs(entities) do - if surface.can_place_entity(v) then - surface.create_entity(v) - end + end + end + + -- set tiles. + surface.set_tiles(tiles, false) + + -- set entities + for _, entity in ipairs(entities) do + if surface.can_place_entity {name=entity.name, position=entity.position} then + surface.create_entity {name=entity.name, position=entity.position} + end + end + + for _,deco in pairs(decoratives) do + if deco ~= nil then + surface.create_decoratives({check_collision=true, decoratives={deco}}) + end end + +end + +local decorative_options = { + ["concrete"] = {}, + ["deepwater"] = {}, + ["deepwater-green"] = {}, + ["dirt"] = {}, + ["dirt-dark"] = {}, + ["grass"] = { + {"green-carpet-grass", 3}, + {"green-hairy-grass", 7}, + {"green-bush-mini", 10}, + {"green-pita", 6}, + {"green-small-grass", 12}, + {"green-asterisk", 25}, + {"green-bush-mini", 7}, + }, + ["grass-dry"] = {}, + ["grass-medium"] = {}, + ["hazard-concrete-left"] = {}, + ["hazard-concrete-right"] = {}, + ["lab-dark-1"] = {}, + ["lab-dark-2"] = {}, + ["red-desert"] = {}, + ["red-desert-dark"] = {}, + ["sand"] = {}, + ["sand-dark"] = {}, + ["stone-path"] = {}, + ["water"] = {}, + ["water-green"] = {}, + ["out-of-map"] = {}, +} + +function check_decorative(tile, x, y) + local options = decorative_options[tile] + local tile_decoratives = {} + + for _,e in ipairs(options) do + name = e[1] + high_roll = e[2] + if math.random(1, high_roll) == 1 then + table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) + end + end + + return tile_decoratives +end + +local entity_options = { + ["concrete"] = {}, + ["deepwater"] = {}, + ["deepwater-green"] = {}, + ["dirt"] = {}, + ["dirt-dark"] = {}, + ["grass"] = { + {"tree-04", 400}, + {"tree-06", 150}, + {"tree-07", 400}, + {"tree-09", 1000}, + {"stone-rock", 400}, + {"green-coral", 10000}, + }, + ["grass-dry"] = {}, + ["grass-medium"] = {}, + ["hazard-concrete-left"] = {}, + ["hazard-concrete-right"] = {}, + ["lab-dark-1"] = {}, + ["lab-dark-2"] = {}, + ["red-desert"] = {}, + ["red-desert-dark"] = {}, + ["sand"] = {}, + ["sand-dark"] = {}, + ["stone-path"] = {}, + ["water"] = {}, + ["water-green"] = {}, + ["out-of-map"] = {}, +} + +function check_entities(tile, x, y) + local options = entity_options[tile] + local tile_entity_list = {} + + for _,e in ipairs(options) do + name = e[1] + high_roll = e[2] + if math.random(1, high_roll) == 1 then + table.insert(tile_entity_list, {name=name, position={x,y}}) + end + end + + return tile_entity_list + end diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua index bcfbcd90..3cbd24db 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -1,9 +1,11 @@ require "locale.gen_combined.grilledham_map_gen.map_gen" +map_gen_decoratives = true + local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" local shape = picture_builder(pic.data, pic.width, pic.height) -shape = change_tile(shape, false, "out-of-map") +--shape = change_tile(shape, false, "out-of-map") return shape From 73878a00c9840bc7e629e4531d4327bc9a2abcac Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 18:56:26 -0500 Subject: [PATCH 13/18] Current status, messing with decoratives --- .../grilledham_map_gen/builders.lua | 18 +- .../grilledham_map_gen/data/biome_test.lua | 38 ++-- .../grilledham_map_gen/map_gen.lua | 210 +++++++++++++----- .../grilledham_map_gen/presets/GoT.lua | 2 +- .../grilledham_map_gen/presets/biome_test.lua | 2 +- map_layout.lua | 3 +- 6 files changed, 183 insertions(+), 90 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/builders.lua b/locale/gen_combined/grilledham_map_gen/builders.lua index c41852a3..aae09c9a 100644 --- a/locale/gen_combined/grilledham_map_gen/builders.lua +++ b/locale/gen_combined/grilledham_map_gen/builders.lua @@ -112,7 +112,7 @@ function decompress(pic) x = x + 1 end end - end + end return {width = width, height = height, data = uncompressed} end @@ -125,7 +125,6 @@ function picture_builder(pic) -- the plus one is because lua tables are one based. local half_width = math.floor(width / 2) + 1 local half_height = math.floor(height / 2) + 1 - return function(x, y) x = math.floor(x) y = math.floor(y) @@ -133,12 +132,7 @@ function picture_builder(pic) local y2 = y + half_height if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then - local pixel = "out-of-map" - if data[y2] ~= nil then - if data[y2][x2] ~= nil then - pixel = data[y2][x2] - end - end + local pixel = data[y2][x2] return pixel else return false @@ -227,8 +221,8 @@ end function throttle_x(builder, x_in, x_size) return function(x, y, world_x, world_y) - if x % x_size < x_in then - return builder(x, y, world_x, world_y) + if x % x_size < x_in then + return builder(x, y, world_x, world_y) else return false end @@ -237,8 +231,8 @@ end function throttle_y(builder, y_in, y_size) return function(x, y, world_x, world_y) - if y % y_size < y_in then - return builder(x, y, world_x, world_y) + if y % y_size < y_in then + return builder(x, y, world_x, world_y) else return false end diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index 27dd30bc..0c0fae65 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -1,24 +1,24 @@ local tile_types = { "concrete", -"deepwater", -"deepwater-green", -"dirt", -"dirt-dark", -"grass", -"grass-dry", -"grass-medium", -"hazard-concrete-left", -"hazard-concrete-right", -"lab-dark-1", -"lab-dark-2", -"red-desert", -"red-desert-dark", -"sand", -"sand-dark", -"stone-path", -"water", -"water-green", -"out-of-map", + "deepwater", + "deepwater-green", + "dirt", + "dirt-dark", + "grass", + "grass-medium", + "grass-dry", + "hazard-concrete-left", + "hazard-concrete-right", + "lab-dark-1", + "lab-dark-2", + "red-desert", + "red-desert-dark", + "sand", + "sand-dark", + "stone-path", + "water", + "water-green", + "out-of-map", } local cols = 5 local rows = 20 / cols diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 84561827..147c79ce 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,4 +1,89 @@ require("locale.gen_combined.grilledham_map_gen.builders") +local Thread = require "locale.utils.Thread" + + +function run_init(params) + global._tiles_hold = {} + global._decoratives_hold = {} + global._entities_hold = {} +end + +function run_place_tiles(params) + local surface = params.surface + surface.set_tiles(global._tiles_hold) +end + +function run_place_items(params) + local surface = params.surface + for _,deco in pairs(global._decoratives_hold) do + surface.create_decoratives{check_collision=false, decoratives={deco}} + end + for _,deco in pairs(global._decoratives_hold) do + surface.create_decoratives{check_collision=false, decoratives={deco}} + end + for _, entity in ipairs(global._entities_hold) do + if surface.can_place_entity {name=entity.name, position=entity.position} then + surface.create_entity {name=entity.name, position=entity.position} + end + end +end + +function run_calc_items(params) + local top_x = params.top_x + local top_y = params.top_y + + for y = top_y, top_y + 31 do + for x = top_x, top_x + 31 do + + -- local coords need to be 'centered' to allow for correct rotation and scaling. + local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) + + if type(tile) == "boolean" and not tile then + table.insert( global._tiles_hold, {name = "out-of-map", position = {x, y}} ) + elseif type(tile) == "string" then + table.insert( global._tiles_hold, {name = tile, position = {x, y}} ) + + if tile == "water" or tile == "deepwater" or tile == "water-green" or tile == "deepwater-green" then + local a = x + 1 + table.insert(global._tiles_hold, {name = tile, position = {a,y}}) + local a = y + 1 + table.insert(global._tiles_hold, {name = tile, position = {x,a}}) + local a = x - 1 + table.insert(global._tiles_hold, {name = tile, position = {a,y}}) + local a = y - 1 + table.insert(global._tiles_hold, {name = tile, position = {x,a}}) + end + + if map_gen_decoratives then + tile_decoratives = check_decorative(tile, x, y) + for _,tbl in ipairs(tile_decoratives) do + table.insert(global._decoratives_hold, tbl) + end + + + tile_entities = check_entities(tile, x, y) + for _,entity in ipairs(tile_entities) do + table.insert(global._entities_hold, entity) + end + end + end + + if entity then + table.insert(global._entities_hold, entity) + end + + end + end +end + +function run_chart_update(params) + local x = params.area.left_top.x / 32 + local y = params.area.left_top.y / 32 + if game.forces.player.is_chunk_charted(params.surface, {x,y} ) then + -- Don't use full area, otherwise adjacent chunks get charted + game.forces.player.chart(params.surface, {{ params.area.left_top.x, params.area.left_top.y}, { params.area.left_top.x+30, params.area.left_top.y+30} } ) + end +end function run_combined_module(event) @@ -10,70 +95,30 @@ function run_combined_module(event) local area = event.area local surface = event.surface MAP_GEN_SURFACE = surface - local tiles = {} - local entities = {} - local decoratives = {} + local top_x = area.left_top.x local top_y = area.left_top.y if map_gen_decoratives then - for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do + for _, e in pairs(surface.find_entities_filtered{area=area, type="decorative"}) do e.destroy() end for _, e in pairs(surface.find_entities_filtered{area=area, type="tree"}) do e.destroy() end - end - - - for y = top_y, top_y + 31 do - for x = top_x, top_x + 31 do - - -- local coords need to be 'centered' to allow for correct rotation and scaling. - local tile, entity = MAP_GEN(x + 0.5, y + 0.5, x, y) - - if type(tile) == "boolean" and not tile then - table.insert( tiles, {name = "out-of-map", position = {x, y}} ) - elseif type(tile) == "string" then - table.insert( tiles, {name = tile, position = {x, y}} ) - - if map_gen_decoratives then - tile_decoratives = check_decorative(tile, x, y) - for _,tbl in ipairs(tile_decoratives) do - table.insert(decoratives, tbl) - end - - - tile_entities = check_entities(tile, x, y) - for _,entity in ipairs(tile_entities) do - table.insert(entities, entity) - end - end - end - - if entity then - table.insert(entities, entity) - end - + for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do + e.destroy() end end - -- set tiles. - surface.set_tiles(tiles, false) + Thread.queue_action("run_init", {} ) - -- set entities - for _, entity in ipairs(entities) do - if surface.can_place_entity {name=entity.name, position=entity.position} then - surface.create_entity {name=entity.name, position=entity.position} - end - end + Thread.queue_action("run_calc_items", {surface = event.surface, top_x = top_x, top_y = top_y}) - for _,deco in pairs(decoratives) do - if deco ~= nil then - surface.create_decoratives({check_collision=true, decoratives={deco}}) - end - end + Thread.queue_action("run_place_tiles", {surface = event.surface}) + Thread.queue_action("run_place_items", {surface = event.surface}) + Thread.queue_action("run_chart_update", {area = event.area, surface = event.surface} ) end @@ -92,15 +137,46 @@ local decorative_options = { {"green-asterisk", 25}, {"green-bush-mini", 7}, }, - ["grass-dry"] = {}, - ["grass-medium"] = {}, + ["grass-medium"] = { + {"green-carpet-grass", 12}, + {"green-hairy-grass", 28}, + {"green-bush-mini", 40}, + {"green-pita", 24}, + {"green-small-grass", 48}, + {"green-asterisk", 100}, + {"green-bush-mini", 28}, + }, + ["grass-dry"] = { + {"green-carpet-grass", 24}, + {"green-hairy-grass", 56}, + {"green-bush-mini", 80}, + {"green-pita", 48}, + {"green-small-grass", 96}, + {"green-asterisk", 200}, + {"green-bush-mini", 56}, + }, ["hazard-concrete-left"] = {}, ["hazard-concrete-right"] = {}, ["lab-dark-1"] = {}, ["lab-dark-2"] = {}, - ["red-desert"] = {}, - ["red-desert-dark"] = {}, - ["sand"] = {}, + ["red-desert"] = { + {"brown-carpet-grass", 35}, + {"orange-coral-mini", 45}, + {"red-asterisk", 45}, + {"red-desert-bush", 12}, + {"red-desert-rock-medium", 375}, + {"red-desert-rock-small", 200}, + {"red-desert-rock-tiny", 30}, + }, + ["red-desert-dark"] = { + {"brown-carpet-grass", 70}, + {"orange-coral-mini", 90}, + {"red-asterisk", 90}, + {"red-desert-bush", 35}, + {"red-desert-rock-medium", 375}, + {"red-desert-rock-small", 200}, + {"red-desert-rock-tiny", 150}, + }, ["sand-dark"] = {}, ["stone-path"] = {}, ["water"] = {}, @@ -143,8 +219,30 @@ local entity_options = { ["hazard-concrete-right"] = {}, ["lab-dark-1"] = {}, ["lab-dark-2"] = {}, - ["red-desert"] = {}, - ["red-desert-dark"] = {}, + ["red-desert"] = { + {"dry-tree", 400}, + {"dry-hairy-tree", 400}, + {"tree-06", 500}, + {"tree-06", 500}, + {"tree-01", 500}, + {"tree-02", 500}, + {"tree-03", 500}, + {"red-desert-rock-big-01", 200}, + {"red-desert-rock-huge-01", 400}, + {"red-desert-rock-huge-02", 400}, + }, + ["red-desert-dark"] = { + {"dry-tree", 400}, + {"dry-hairy-tree", 400}, + {"tree-06", 500}, + {"tree-06", 500}, + {"tree-01", 500}, + {"tree-02", 500}, + {"tree-03", 500}, + {"red-desert-rock-big-01", 200}, + {"red-desert-rock-huge-01", 400}, + {"red-desert-rock-huge-02", 400}, + }, ["sand"] = {}, ["sand-dark"] = {}, ["stone-path"] = {}, diff --git a/locale/gen_combined/grilledham_map_gen/presets/GoT.lua b/locale/gen_combined/grilledham_map_gen/presets/GoT.lua index c99bfb06..595b73a8 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/GoT.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/GoT.lua @@ -1,6 +1,6 @@ require "locale.gen_combined.grilledham_map_gen.map_gen" require "locale.gen_combined.grilledham_map_gen.builders" - +map_gen_decoratives = true local pic = require "locale.gen_combined.grilledham_map_gen.data.GoT" local pic = decompress(pic) diff --git a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua index 3cbd24db..ef371e8e 100644 --- a/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/presets/biome_test.lua @@ -4,7 +4,7 @@ map_gen_decoratives = true local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test" -local shape = picture_builder(pic.data, pic.width, pic.height) +local shape = picture_builder(pic) --shape = change_tile(shape, false, "out-of-map") diff --git a/map_layout.lua b/map_layout.lua index 5dc937cc..12f2589c 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -24,7 +24,8 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.cage" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" ---require "locale.grilledham_map_gen.presets.UK" +MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" +--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --shapes-- --require "locale.gen_shape.left" From 51d646f026bf7454aec9aeacdacb648469456244 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Mon, 13 Nov 2017 07:05:18 -0500 Subject: [PATCH 14/18] Additional tweaks and reordered the biomes to be next to each other --- .../grilledham_map_gen/data/biome_test.lua | 22 ++-- .../grilledham_map_gen/map_gen.lua | 101 ++++++++++++++---- 2 files changed, 93 insertions(+), 30 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua index 0c0fae65..21ae110b 100644 --- a/locale/gen_combined/grilledham_map_gen/data/biome_test.lua +++ b/locale/gen_combined/grilledham_map_gen/data/biome_test.lua @@ -1,30 +1,30 @@ local tile_types = { + "hazard-concrete-left", "concrete", - "deepwater", - "deepwater-green", - "dirt", - "dirt-dark", + "stone-path", + "hazard-concrete-right", + "lab-dark-1", "grass", "grass-medium", "grass-dry", - "hazard-concrete-left", - "hazard-concrete-right", - "lab-dark-1", - "lab-dark-2", + "dirt", + "dirt-dark", "red-desert", "red-desert-dark", "sand", "sand-dark", - "stone-path", + "lab-dark-2", "water", + "deepwater", "water-green", + "deepwater-green", "out-of-map", } local cols = 5 local rows = 20 / cols -local tile_width = 64 -local tile_height = 64 +local tile_width = 32 +local tile_height = 32 local tile_data = {} diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 147c79ce..4c17f52f 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -10,7 +10,7 @@ end function run_place_tiles(params) local surface = params.surface - surface.set_tiles(global._tiles_hold) + surface.set_tiles(global._tiles_hold, true) end function run_place_items(params) @@ -18,9 +18,6 @@ function run_place_items(params) for _,deco in pairs(global._decoratives_hold) do surface.create_decoratives{check_collision=false, decoratives={deco}} end - for _,deco in pairs(global._decoratives_hold) do - surface.create_decoratives{check_collision=false, decoratives={deco}} - end for _, entity in ipairs(global._entities_hold) do if surface.can_place_entity {name=entity.name, position=entity.position} then surface.create_entity {name=entity.name, position=entity.position} @@ -125,9 +122,23 @@ end local decorative_options = { ["concrete"] = {}, ["deepwater"] = {}, - ["deepwater-green"] = {}, - ["dirt"] = {}, - ["dirt-dark"] = {}, + ["deepwater-green"] = { + {"brown-carpet-grass", 100}, + {"brown-cane-cluster", 500}, + }, + ["dirt"] = { + {"brown-carpet-grass", 100}, + {"brown-cane-cluster", 200}, + {"red-desert-rock-tiny", 150}, + }, + ["dirt-dark"] = { + {"red-desert-rock-tiny", 150}, + {"red-asterisk", 45}, + {"red-desert-bush", 12}, + {"red-desert-rock-medium", 375}, + + + }, ["grass"] = { {"green-carpet-grass", 3}, {"green-hairy-grass", 7}, @@ -136,6 +147,7 @@ local decorative_options = { {"green-small-grass", 12}, {"green-asterisk", 25}, {"green-bush-mini", 7}, + {"garballo", 20}, }, ["grass-medium"] = { {"green-carpet-grass", 12}, @@ -147,13 +159,14 @@ local decorative_options = { {"green-bush-mini", 28}, }, ["grass-dry"] = { - {"green-carpet-grass", 24}, {"green-hairy-grass", 56}, {"green-bush-mini", 80}, {"green-pita", 48}, {"green-small-grass", 96}, {"green-asterisk", 200}, {"green-bush-mini", 56}, + {"brown-cane-cluster", 100}, + {"brown-carpet-grass", 100}, }, ["hazard-concrete-left"] = {}, ["hazard-concrete-right"] = {}, @@ -177,7 +190,17 @@ local decorative_options = { {"red-desert-rock-small", 200}, {"red-desert-rock-tiny", 150}, }, - ["sand-dark"] = {}, + ["sand"] = { + {"brown-carpet-grass", 35}, + {"orange-coral-mini", 45}, + {"red-asterisk", 45}, + {"brown-asterisk", 45}, + }, + ["sand-dark"] = { + {"brown-carpet-grass", 35}, + {"orange-coral-mini", 45}, + {"brown-asterisk", 45}, + }, ["stone-path"] = {}, ["water"] = {}, ["water-green"] = {}, @@ -203,18 +226,48 @@ local entity_options = { ["concrete"] = {}, ["deepwater"] = {}, ["deepwater-green"] = {}, - ["dirt"] = {}, - ["dirt-dark"] = {}, - ["grass"] = { - {"tree-04", 400}, + ["water"] = {}, + ["water-green"] = {}, + ["dirt"] = { + {"tree-01", 500}, + {"tree-06", 300}, + {"tree-07", 800}, + {"tree-09", 2000}, + {"stone-rock", 400}, + }, + ["dirt-dark"] = { {"tree-06", 150}, {"tree-07", 400}, {"tree-09", 1000}, + {"stone-rock", 300}, + }, + ["grass"] = { + {"tree-01", 150}, + {"tree-04", 400}, + {"tree-06", 400}, + {"tree-07", 400}, + {"tree-09", 1000}, {"stone-rock", 400}, {"green-coral", 10000}, }, - ["grass-dry"] = {}, - ["grass-medium"] = {}, + ["grass-medium"] = { + {"tree-02", 400}, + {"tree-03", 400}, + {"tree-04", 800}, + {"tree-06", 300}, + {"tree-07", 800}, + {"tree-08", 400}, + {"tree-09", 2000}, + {"stone-rock", 400}, + }, + ["grass-dry"] = { + {"tree-04", 800}, + {"tree-06", 300}, + {"tree-07", 400}, + {"tree-09", 1000}, + {"dry-tree", 1000}, + {"stone-rock", 200}, + }, ["hazard-concrete-left"] = {}, ["hazard-concrete-right"] = {}, ["lab-dark-1"] = {}, @@ -243,11 +296,21 @@ local entity_options = { {"red-desert-rock-huge-01", 400}, {"red-desert-rock-huge-02", 400}, }, - ["sand"] = {}, - ["sand-dark"] = {}, + ["sand"] = { + {"dry-tree", 1000}, + {"dry-hairy-tree", 1000}, + {"dead-tree", 1000}, + {"stone-rock", 150}, + + }, + ["sand-dark"] = { + {"dead-tree", 1000}, + {"dry-tree", 1000}, + {"dry-hairy-tree", 1000}, + {"stone-rock", 150}, + + }, ["stone-path"] = {}, - ["water"] = {}, - ["water-green"] = {}, ["out-of-map"] = {}, } From 9b23a72289e77d51594beed292115c413a5572e7 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Mon, 13 Nov 2017 15:50:14 -0500 Subject: [PATCH 15/18] Staging for play test --- map_layout.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/map_layout.lua b/map_layout.lua index 12f2589c..65e8609b 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -24,8 +24,8 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.cage" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" -MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" ---MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" +--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" +MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --shapes-- --require "locale.gen_shape.left" @@ -61,7 +61,7 @@ miscs = {} --require "locale.gen_misc.rusky_pvp" --miscs[1] = require "locale.gen_misc.wreck_items" --miscs[2] = require "locale.gen_misc.tris_chunk_grid" ---miscs[1] = require "locale.gen_ores.glitter_ores" +miscs[1] = require "locale.gen_ores.glitter_ores" local on_chunk_generated = function(event) if run_combined_module == nil then From f1b3e0ffb8096bbe8a00be93685b351b353c82f8 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Wed, 15 Nov 2017 05:53:49 -0500 Subject: [PATCH 16/18] Order of operations on Misc vs ores in map layout to allow glitter to take effect. Also implemented the poisson RNG --- .../grilledham_map_gen/map_gen.lua | 6 +++-- locale/gen_ores/glitter_ores.lua | 2 +- locale/gen_shared/poisson.lua | 27 +++++++++++++++++++ map_layout.lua | 8 +++--- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 locale/gen_shared/poisson.lua diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 4c17f52f..1682e88a 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,4 +1,6 @@ require("locale.gen_combined.grilledham_map_gen.builders") +require("locale.gen_shared.poisson") + local Thread = require "locale.utils.Thread" @@ -214,7 +216,7 @@ function check_decorative(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if math.random(1, high_roll) == 1 then + if poison_rng_next(high_roll / 2 ) == 1 then table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) end end @@ -321,7 +323,7 @@ function check_entities(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if math.random(1, high_roll) == 1 then + if poison_rng_next( high_roll / 2 ) == 1 then table.insert(tile_entity_list, {name=name, position={x,y}}) end end diff --git a/locale/gen_ores/glitter_ores.lua b/locale/gen_ores/glitter_ores.lua index 128632aa..6472854e 100644 --- a/locale/gen_ores/glitter_ores.lua +++ b/locale/gen_ores/glitter_ores.lua @@ -16,7 +16,7 @@ function run_ores_module_setup() ["stone"] = 0.25 } -- 1-100% chance of sprinkling any individual ore - sprinkle_factor = 10 + sprinkle_factor = 20 -- Sets the buffer distance before ores are scrambled starting_buffer = 125 diff --git a/locale/gen_shared/poisson.lua b/locale/gen_shared/poisson.lua new file mode 100644 index 00000000..7d9c1ac3 --- /dev/null +++ b/locale/gen_shared/poisson.lua @@ -0,0 +1,27 @@ +local function generate_pmf_chart(l) + chart = {[0] = math.exp(-l)} + for k=1,(l*2 + 1) do + chart[k] = (chart[k - 1] * l / k) + end + return chart +end + +local function generate_poisson_set(l, n) --n defines the resolution + local chart = generate_pmf_chart(l) + local set = {} + for x,y in pairs(chart) do + local m = math.floor(y * n + 0.5) + for i=0,m do + table.insert(set,x) + end + end + return set +end + +global.poisson_set = {} +function poison_rng_next(l) + if not global.poisson_set[l] then + global.poisson_set[l] = generate_poisson_set(l, 1000) + end + return global.poisson_set[l][math.random(1000)] +end diff --git a/map_layout.lua b/map_layout.lua index 65e8609b..52753d55 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -52,7 +52,7 @@ MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --ores-- --require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.fluffy_rainbows" ---require "locale.gen_ores.rso.rso_control" +require "locale.gen_ores.rso.rso_control" --require "locale.gen_ores.harmonic_gen" --everything else. You may use more than one of these, but beware they might not be compatible @@ -87,12 +87,12 @@ local on_chunk_generated = function(event) end else run_combined_module(event) - for _,v in pairs(miscs) do - v.on_chunk_generated(event) - end if run_ores_module ~= nil then run_ores_module(event) end + for _,v in pairs(miscs) do + v.on_chunk_generated(event) + end end end From 6d65656cf0fb0f4e249f71f6c1b1975c6cd723a0 Mon Sep 17 00:00:00 2001 From: Maik Wild Date: Wed, 15 Nov 2017 13:41:34 +0100 Subject: [PATCH 17/18] Moved poisson rng to utils, fixed a potential nil reference and fixed poison typo --- locale/gen_combined/grilledham_map_gen/map_gen.lua | 7 +++---- locale/{gen_shared/poisson.lua => utils/poisson_rng.lua} | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) rename locale/{gen_shared/poisson.lua => utils/poisson_rng.lua} (79%) diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index 1682e88a..d9fa884e 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,5 +1,5 @@ require("locale.gen_combined.grilledham_map_gen.builders") -require("locale.gen_shared.poisson") +require("locale.utils.poisson") local Thread = require "locale.utils.Thread" @@ -216,7 +216,7 @@ function check_decorative(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if poison_rng_next(high_roll / 2 ) == 1 then + if poisson_rng_next(high_roll / 2 ) == 1 then table.insert(tile_decoratives, {name=name, amount=1, position={x,y}}) end end @@ -323,11 +323,10 @@ function check_entities(tile, x, y) for _,e in ipairs(options) do name = e[1] high_roll = e[2] - if poison_rng_next( high_roll / 2 ) == 1 then + if poisson_rng_next( high_roll / 2 ) == 1 then table.insert(tile_entity_list, {name=name, position={x,y}}) end end return tile_entity_list - end diff --git a/locale/gen_shared/poisson.lua b/locale/utils/poisson_rng.lua similarity index 79% rename from locale/gen_shared/poisson.lua rename to locale/utils/poisson_rng.lua index 7d9c1ac3..1a54e1b0 100644 --- a/locale/gen_shared/poisson.lua +++ b/locale/utils/poisson_rng.lua @@ -1,3 +1,5 @@ +--Author: Valansch + local function generate_pmf_chart(l) chart = {[0] = math.exp(-l)} for k=1,(l*2 + 1) do @@ -15,13 +17,14 @@ local function generate_poisson_set(l, n) --n defines the resolution table.insert(set,x) end end + set._n = #set return set end global.poisson_set = {} -function poison_rng_next(l) +function poisson_rng_next(l) if not global.poisson_set[l] then global.poisson_set[l] = generate_poisson_set(l, 1000) end - return global.poisson_set[l][math.random(1000)] + return global.poisson_set[l][math.random(global.poisson_set[l]._n)] end From bdf1bfdc6e749f0a062e0c31ddde8c42dc2d75a5 Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Wed, 15 Nov 2017 19:24:20 -0500 Subject: [PATCH 18/18] As deployed / playtested with changes. --- locale/gen_combined/grilledham_map_gen/map_gen.lua | 2 +- map_layout.lua | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/locale/gen_combined/grilledham_map_gen/map_gen.lua b/locale/gen_combined/grilledham_map_gen/map_gen.lua index d9fa884e..70e94017 100644 --- a/locale/gen_combined/grilledham_map_gen/map_gen.lua +++ b/locale/gen_combined/grilledham_map_gen/map_gen.lua @@ -1,5 +1,5 @@ require("locale.gen_combined.grilledham_map_gen.builders") -require("locale.utils.poisson") +require("locale.utils.poisson_rng") local Thread = require "locale.utils.Thread" diff --git a/map_layout.lua b/map_layout.lua index 52753d55..0edd25ec 100644 --- a/map_layout.lua +++ b/map_layout.lua @@ -25,7 +25,8 @@ in this file and your run_*type*_module(event) function will be called. --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.maori" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat" --MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.biome_test" -MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" +--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" +--require "locale.grilledham_map_gen.presets.UK" --shapes-- --require "locale.gen_shape.left" @@ -52,7 +53,7 @@ MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT" --ores-- --require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.fluffy_rainbows" -require "locale.gen_ores.rso.rso_control" +--require "locale.gen_ores.rso.rso_control" --require "locale.gen_ores.harmonic_gen" --everything else. You may use more than one of these, but beware they might not be compatible @@ -61,7 +62,7 @@ miscs = {} --require "locale.gen_misc.rusky_pvp" --miscs[1] = require "locale.gen_misc.wreck_items" --miscs[2] = require "locale.gen_misc.tris_chunk_grid" -miscs[1] = require "locale.gen_ores.glitter_ores" +--miscs[1] = require "locale.gen_ores.glitter_ores" local on_chunk_generated = function(event) if run_combined_module == nil then