mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
Current status, messing with decoratives
This commit is contained in:
parent
53f55aba22
commit
707f90255d
@ -67,11 +67,64 @@ function oval_builder(x_radius, y_radius)
|
|||||||
end
|
end
|
||||||
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.
|
-- the plus one is because lua tables are one based.
|
||||||
local half_width = math.floor(width / 2) + 1
|
local half_width = math.floor(width / 2) + 1
|
||||||
local half_height = math.floor(height / 2) + 1
|
local half_height = math.floor(height / 2) + 1
|
||||||
|
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
x = math.floor(x)
|
x = math.floor(x)
|
||||||
y = math.floor(y)
|
y = math.floor(y)
|
||||||
@ -79,12 +132,7 @@ function picture_builder(data, width, height)
|
|||||||
local y2 = y + half_height
|
local y2 = y + half_height
|
||||||
|
|
||||||
if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then
|
if y2 > 0 and y2 <= height and x2 > 0 and x2 <= width then
|
||||||
local pixel = "out-of-map"
|
local pixel = data[y2][x2]
|
||||||
if data[y2] ~= nil then
|
|
||||||
if data[y2][x2] ~= nil then
|
|
||||||
pixel = data[y2][x2]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return pixel
|
return pixel
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
@ -171,6 +219,26 @@ function invert(builder)
|
|||||||
end
|
end
|
||||||
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)
|
function throttle_xy(builder, x_in, x_size, y_in, y_size)
|
||||||
return function(x, y, world_x, world_y)
|
return function(x, y, world_x, world_y)
|
||||||
if x % x_size < x_in and y % y_size < y_in then
|
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 )
|
return function (local_x, local_y, world_x, world_y )
|
||||||
local tile, entity = builder(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
|
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
|
if old_tile == gen_tile then
|
||||||
tile = new_tile
|
tile = new_tile
|
||||||
end
|
end
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
local tile_types = {
|
local tile_types = {
|
||||||
"concrete",
|
"concrete",
|
||||||
"deepwater",
|
"deepwater",
|
||||||
"deepwater-green",
|
"deepwater-green",
|
||||||
"dirt",
|
"dirt",
|
||||||
"dirt-dark",
|
"dirt-dark",
|
||||||
"grass",
|
"grass",
|
||||||
"grass-dry",
|
"grass-medium",
|
||||||
"grass-medium",
|
"grass-dry",
|
||||||
"hazard-concrete-left",
|
"hazard-concrete-left",
|
||||||
"hazard-concrete-right",
|
"hazard-concrete-right",
|
||||||
"lab-dark-1",
|
"lab-dark-1",
|
||||||
"lab-dark-2",
|
"lab-dark-2",
|
||||||
"red-desert",
|
"red-desert",
|
||||||
"red-desert-dark",
|
"red-desert-dark",
|
||||||
"sand",
|
"sand",
|
||||||
"sand-dark",
|
"sand-dark",
|
||||||
"stone-path",
|
"stone-path",
|
||||||
"water",
|
"water",
|
||||||
"water-green",
|
"water-green",
|
||||||
"out-of-map",
|
"out-of-map",
|
||||||
}
|
}
|
||||||
local cols = 5
|
local cols = 5
|
||||||
local rows = 20 / cols
|
local rows = 20 / cols
|
||||||
|
@ -1,4 +1,89 @@
|
|||||||
require("locale.gen_combined.grilledham_map_gen.builders")
|
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)
|
function run_combined_module(event)
|
||||||
|
|
||||||
@ -10,70 +95,30 @@ function run_combined_module(event)
|
|||||||
local area = event.area
|
local area = event.area
|
||||||
local surface = event.surface
|
local surface = event.surface
|
||||||
MAP_GEN_SURFACE = surface
|
MAP_GEN_SURFACE = surface
|
||||||
local tiles = {}
|
|
||||||
local entities = {}
|
|
||||||
local decoratives = {}
|
|
||||||
|
|
||||||
local top_x = area.left_top.x
|
local top_x = area.left_top.x
|
||||||
local top_y = area.left_top.y
|
local top_y = area.left_top.y
|
||||||
|
|
||||||
if map_gen_decoratives then
|
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()
|
e.destroy()
|
||||||
end
|
end
|
||||||
for _, e in pairs(surface.find_entities_filtered{area=area, type="tree"}) do
|
for _, e in pairs(surface.find_entities_filtered{area=area, type="tree"}) do
|
||||||
e.destroy()
|
e.destroy()
|
||||||
end
|
end
|
||||||
end
|
for _, e in pairs(surface.find_entities_filtered{area=area, type="simple-entity"}) do
|
||||||
|
e.destroy()
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set tiles.
|
Thread.queue_action("run_init", {} )
|
||||||
surface.set_tiles(tiles, false)
|
|
||||||
|
|
||||||
-- set entities
|
Thread.queue_action("run_calc_items", {surface = event.surface, top_x = top_x, top_y = top_y})
|
||||||
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
|
Thread.queue_action("run_place_tiles", {surface = event.surface})
|
||||||
if deco ~= nil then
|
Thread.queue_action("run_place_items", {surface = event.surface})
|
||||||
surface.create_decoratives({check_collision=true, decoratives={deco}})
|
Thread.queue_action("run_chart_update", {area = event.area, surface = event.surface} )
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -92,15 +137,46 @@ local decorative_options = {
|
|||||||
{"green-asterisk", 25},
|
{"green-asterisk", 25},
|
||||||
{"green-bush-mini", 7},
|
{"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-left"] = {},
|
||||||
["hazard-concrete-right"] = {},
|
["hazard-concrete-right"] = {},
|
||||||
["lab-dark-1"] = {},
|
["lab-dark-1"] = {},
|
||||||
["lab-dark-2"] = {},
|
["lab-dark-2"] = {},
|
||||||
["red-desert"] = {},
|
["red-desert"] = {
|
||||||
["red-desert-dark"] = {},
|
{"brown-carpet-grass", 35},
|
||||||
["sand"] = {},
|
{"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"] = {},
|
["sand-dark"] = {},
|
||||||
["stone-path"] = {},
|
["stone-path"] = {},
|
||||||
["water"] = {},
|
["water"] = {},
|
||||||
@ -143,8 +219,30 @@ local entity_options = {
|
|||||||
["hazard-concrete-right"] = {},
|
["hazard-concrete-right"] = {},
|
||||||
["lab-dark-1"] = {},
|
["lab-dark-1"] = {},
|
||||||
["lab-dark-2"] = {},
|
["lab-dark-2"] = {},
|
||||||
["red-desert"] = {},
|
["red-desert"] = {
|
||||||
["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},
|
||||||
|
},
|
||||||
|
["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"] = {},
|
||||||
["sand-dark"] = {},
|
["sand-dark"] = {},
|
||||||
["stone-path"] = {},
|
["stone-path"] = {},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require "locale.gen_combined.grilledham_map_gen.map_gen"
|
require "locale.gen_combined.grilledham_map_gen.map_gen"
|
||||||
require "locale.gen_combined.grilledham_map_gen.builders"
|
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 = require "locale.gen_combined.grilledham_map_gen.data.GoT"
|
||||||
local pic = decompress(pic)
|
local pic = decompress(pic)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ map_gen_decoratives = true
|
|||||||
|
|
||||||
local pic = require "locale.gen_combined.grilledham_map_gen.data.biome_test"
|
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")
|
--shape = change_tile(shape, false, "out-of-map")
|
||||||
|
|
||||||
|
@ -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.maori"
|
||||||
--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.goat"
|
--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.biome_test"
|
||||||
|
--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.GoT"
|
||||||
|
|
||||||
--shapes--
|
--shapes--
|
||||||
--require "locale.gen_shape.left"
|
--require "locale.gen_shape.left"
|
||||||
|
Loading…
Reference in New Issue
Block a user