Skip to content

Commit

Permalink
Merge pull request #1224 from grilledham/danger-ore-one-direction
Browse files Browse the repository at this point in the history
Add danger_ore_one_direction.
  • Loading branch information
grilledham authored Aug 1, 2021
2 parents 8cf3c54 + 9e967b3 commit 83b1c51
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 48 deletions.
76 changes: 76 additions & 0 deletions map_gen/maps/danger_ores/config/vanilla_ores_one_direction.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
local b = require 'map_gen.shared.builders'
local start_value = b.euclidean_value(0, 0.35)
local value = b.exponential_value(0, 0.15, 1.1)

return {
{
name = 'copper-ore',
['tiles'] = {
[1] = 'red-desert-0',
[2] = 'red-desert-1',
[3] = 'red-desert-2',
[4] = 'red-desert-3'
},
['start'] = start_value,
['weight'] = 1,
['ratios'] = {
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 15},
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 70},
{resource = b.resource(b.full_shape, 'stone', value), weight = 10},
{resource = b.resource(b.full_shape, 'coal', value), weight = 5}
}
},
{
name = 'coal',
['tiles'] = {
[1] = 'dirt-1',
[2] = 'dirt-2',
[3] = 'dirt-3',
[4] = 'dirt-4',
[5] = 'dirt-5',
[6] = 'dirt-6',
[7] = 'dirt-7'
},
['start'] = start_value,
['weight'] = 1,
['ratios'] = {
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 18},
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 9},
{resource = b.resource(b.full_shape, 'stone', value), weight = 8},
{resource = b.resource(b.full_shape, 'coal', value), weight = 65}
}
},
{
name = 'iron-ore',
['tiles'] = {
[1] = 'grass-1',
[2] = 'grass-2',
[3] = 'grass-3',
[4] = 'grass-4'
},
['start'] = start_value,
['weight'] = 1,
['ratios'] = {
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 75},
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 13},
{resource = b.resource(b.full_shape, 'stone', value), weight = 7},
{resource = b.resource(b.full_shape, 'coal', value), weight = 5}
}
},
--[[ {
name = 'stone',
['tiles'] = {
[1] = 'sand-1',
[2] = 'sand-2',
[3] = 'sand-3'
},
['start'] = start_value,
['weight'] = 1,
['ratios'] = {
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 25},
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 10},
{resource = b.resource(b.full_shape, 'stone', value), weight = 60},
{resource = b.resource(b.full_shape, 'coal', value), weight = 5}
}
} ]]
}
43 changes: 43 additions & 0 deletions map_gen/maps/danger_ores/modules/main_ores_one_direction.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local Helper = require 'map_gen.maps.danger_ores.modules.helper'
local b = require 'map_gen.shared.builders'
local table = require 'utils.table'

return function(config)
local main_ores = config.main_ores
local shuffle_order = config.main_ores_shuffle_order
local main_ores_rotate = config.main_ores_rotate or 0
local main_ores_split_count = config.main_ores_split_count or 1

main_ores = Helper.split_ore(main_ores, main_ores_split_count)

return function(tile_builder, ore_builder, spawn_shape, water_shape, random_gen)
local shapes = {}

for _, ore_data in pairs(main_ores) do
local ore_name = ore_data.name
local tiles = ore_data.tiles
local land = tile_builder(tiles)

local ratios = ore_data.ratios
local weighted = b.prepare_weighted_array(ratios)
local amount = ore_data.start

local ore = ore_builder(ore_name, amount, ratios, weighted)

local shape = b.apply_entity(land, ore)
shapes[#shapes + 1] = {shape = shape, weight = ore_data.weight}
end

if shuffle_order then
table.shuffle_table(shapes, random_gen)
end

local ores = b.grid_y_no_repeat_weighted_pattern(shapes, 32)

if main_ores_rotate ~= 0 then
ores = b.rotate(ores, math.rad(main_ores_rotate))
end

return b.any {spawn_shape, water_shape, ores}
end
end
69 changes: 35 additions & 34 deletions map_gen/maps/danger_ores/modules/map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,43 +90,44 @@ return function(config)
end

local map
Global.register_init(
{},
function(tbl)
tbl.seed = RS.get_surface().map_gen_settings.seed
tbl.random = game.create_random_generator(tbl.seed)
end,
function(tbl)
local spawn_shape = spawn_builder(config)
local water_shape = (config.water or empty_builder)(config)
local tile_builder = tile_builder_factory(config)
local trees_shape = (config.trees or no_op)(config)
local enemy_shape = (config.enemy or no_op)(config)
local fish_spawn_rate = config.fish_spawn_rate
local main_ores_builder = (config.main_ores_builder or deafult_main_ores_builder)(config)

start_ore_shape = config.start_ore_shape or b.circle(68)
resource_patches = (config.resource_patches or no_op)(config) or b.empty_shape
no_resource_patch_shape = config.no_resource_patch_shape or b.empty_shape
dense_patches = (config.dense_patches or no_op)(config) or no_op

local random_gen = tbl.random
random_gen.re_seed(tbl.seed)
map = main_ores_builder(tile_builder, ore_builder, spawn_shape, water_shape, random_gen)

if enemy_shape then
map = b.apply_entity(map, enemy_shape)
end
Global.register_init({}, function(tbl)
tbl.seed = RS.get_surface().map_gen_settings.seed
tbl.random = game.create_random_generator(tbl.seed)
end, function(tbl)
local spawn_shape = spawn_builder(config)
local water_shape = (config.water or empty_builder)(config)
local tile_builder = tile_builder_factory(config)
local trees_shape = (config.trees or no_op)(config)
local enemy_shape = (config.enemy or no_op)(config)
local fish_spawn_rate = config.fish_spawn_rate
local main_ores_builder = (config.main_ores_builder or deafult_main_ores_builder)(config)
local post_map_func = config.post_map_func

start_ore_shape = config.start_ore_shape or b.circle(68)
resource_patches = (config.resource_patches or no_op)(config) or b.empty_shape
no_resource_patch_shape = config.no_resource_patch_shape or b.empty_shape
dense_patches = (config.dense_patches or no_op)(config) or no_op

local random_gen = tbl.random
random_gen.re_seed(tbl.seed)
map = main_ores_builder(tile_builder, ore_builder, spawn_shape, water_shape, random_gen)

if enemy_shape then
map = b.apply_entity(map, enemy_shape)
end

if trees_shape then
map = b.apply_entity(map, trees_shape)
end
if trees_shape then
map = b.apply_entity(map, trees_shape)
end

if fish_spawn_rate then
map = b.fish(map, fish_spawn_rate)
end
if fish_spawn_rate then
map = b.fish(map, fish_spawn_rate)
end

if post_map_func then
map = post_map_func(map)
end
)
end)

return function(x, y, world)
return map(x, y, world)
Expand Down
26 changes: 12 additions & 14 deletions map_gen/maps/danger_ores/modules/terraforming.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ return function(config)
Generate.enable_register_events = false

local start_size = config.start_size
local outer_bounds = config.bounds or b.full_shape

local pollution_data = {
min_pollution = config.min_pollution or 400,
Expand All @@ -26,17 +27,13 @@ return function(config)
local chunk_list = {index = 1}
local surface

Global.register_init(
{chunk_list = chunk_list, pollution_data = pollution_data},
function(tbl)
tbl.surface = RS.get_surface()
end,
function(tbl)
chunk_list = tbl.chunk_list
pollution_data = tbl.pollution_data
surface = tbl.surface
end
)
Global.register_init({chunk_list = chunk_list, pollution_data = pollution_data}, function(tbl)
tbl.surface = RS.get_surface()
end, function(tbl)
chunk_list = tbl.chunk_list
pollution_data = tbl.pollution_data
surface = tbl.surface
end)

local bounds = b.rectangle(start_size, start_size)

Expand All @@ -59,7 +56,9 @@ return function(config)
end
surface.set_tiles(tiles, true)

chunk_list[#chunk_list + 1] = {left_top = left_top, id = nil}
if (outer_bounds(x + 0.5, y + 0.5)) then
chunk_list[#chunk_list + 1] = {left_top = left_top, id = nil}
end
end
end

Expand Down Expand Up @@ -102,8 +101,7 @@ return function(config)

local id = data.id
if not id then
data.id =
rendering.draw_text {
data.id = rendering.draw_text {
text = text,
surface = surface,
target = {x + 16, y + 16},
Expand Down
Loading

0 comments on commit 83b1c51

Please sign in to comment.