From 707f90255dacf86f750be370656c4de0cd2735ae Mon Sep 17 00:00:00 2001 From: TWLTriston Date: Sun, 12 Nov 2017 18:56:26 -0500 Subject: [PATCH] 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"