Skip to content

Commit 83b1c51

Browse files
authored
Merge pull request #1224 from grilledham/danger-ore-one-direction
Add danger_ore_one_direction.
2 parents 8cf3c54 + 9e967b3 commit 83b1c51

File tree

7 files changed

+372
-48
lines changed

7 files changed

+372
-48
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
local b = require 'map_gen.shared.builders'
2+
local start_value = b.euclidean_value(0, 0.35)
3+
local value = b.exponential_value(0, 0.15, 1.1)
4+
5+
return {
6+
{
7+
name = 'copper-ore',
8+
['tiles'] = {
9+
[1] = 'red-desert-0',
10+
[2] = 'red-desert-1',
11+
[3] = 'red-desert-2',
12+
[4] = 'red-desert-3'
13+
},
14+
['start'] = start_value,
15+
['weight'] = 1,
16+
['ratios'] = {
17+
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 15},
18+
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 70},
19+
{resource = b.resource(b.full_shape, 'stone', value), weight = 10},
20+
{resource = b.resource(b.full_shape, 'coal', value), weight = 5}
21+
}
22+
},
23+
{
24+
name = 'coal',
25+
['tiles'] = {
26+
[1] = 'dirt-1',
27+
[2] = 'dirt-2',
28+
[3] = 'dirt-3',
29+
[4] = 'dirt-4',
30+
[5] = 'dirt-5',
31+
[6] = 'dirt-6',
32+
[7] = 'dirt-7'
33+
},
34+
['start'] = start_value,
35+
['weight'] = 1,
36+
['ratios'] = {
37+
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 18},
38+
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 9},
39+
{resource = b.resource(b.full_shape, 'stone', value), weight = 8},
40+
{resource = b.resource(b.full_shape, 'coal', value), weight = 65}
41+
}
42+
},
43+
{
44+
name = 'iron-ore',
45+
['tiles'] = {
46+
[1] = 'grass-1',
47+
[2] = 'grass-2',
48+
[3] = 'grass-3',
49+
[4] = 'grass-4'
50+
},
51+
['start'] = start_value,
52+
['weight'] = 1,
53+
['ratios'] = {
54+
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 75},
55+
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 13},
56+
{resource = b.resource(b.full_shape, 'stone', value), weight = 7},
57+
{resource = b.resource(b.full_shape, 'coal', value), weight = 5}
58+
}
59+
},
60+
--[[ {
61+
name = 'stone',
62+
['tiles'] = {
63+
[1] = 'sand-1',
64+
[2] = 'sand-2',
65+
[3] = 'sand-3'
66+
},
67+
['start'] = start_value,
68+
['weight'] = 1,
69+
['ratios'] = {
70+
{resource = b.resource(b.full_shape, 'iron-ore', value), weight = 25},
71+
{resource = b.resource(b.full_shape, 'copper-ore', value), weight = 10},
72+
{resource = b.resource(b.full_shape, 'stone', value), weight = 60},
73+
{resource = b.resource(b.full_shape, 'coal', value), weight = 5}
74+
}
75+
} ]]
76+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
local Helper = require 'map_gen.maps.danger_ores.modules.helper'
2+
local b = require 'map_gen.shared.builders'
3+
local table = require 'utils.table'
4+
5+
return function(config)
6+
local main_ores = config.main_ores
7+
local shuffle_order = config.main_ores_shuffle_order
8+
local main_ores_rotate = config.main_ores_rotate or 0
9+
local main_ores_split_count = config.main_ores_split_count or 1
10+
11+
main_ores = Helper.split_ore(main_ores, main_ores_split_count)
12+
13+
return function(tile_builder, ore_builder, spawn_shape, water_shape, random_gen)
14+
local shapes = {}
15+
16+
for _, ore_data in pairs(main_ores) do
17+
local ore_name = ore_data.name
18+
local tiles = ore_data.tiles
19+
local land = tile_builder(tiles)
20+
21+
local ratios = ore_data.ratios
22+
local weighted = b.prepare_weighted_array(ratios)
23+
local amount = ore_data.start
24+
25+
local ore = ore_builder(ore_name, amount, ratios, weighted)
26+
27+
local shape = b.apply_entity(land, ore)
28+
shapes[#shapes + 1] = {shape = shape, weight = ore_data.weight}
29+
end
30+
31+
if shuffle_order then
32+
table.shuffle_table(shapes, random_gen)
33+
end
34+
35+
local ores = b.grid_y_no_repeat_weighted_pattern(shapes, 32)
36+
37+
if main_ores_rotate ~= 0 then
38+
ores = b.rotate(ores, math.rad(main_ores_rotate))
39+
end
40+
41+
return b.any {spawn_shape, water_shape, ores}
42+
end
43+
end

map_gen/maps/danger_ores/modules/map.lua

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,43 +90,44 @@ return function(config)
9090
end
9191

9292
local map
93-
Global.register_init(
94-
{},
95-
function(tbl)
96-
tbl.seed = RS.get_surface().map_gen_settings.seed
97-
tbl.random = game.create_random_generator(tbl.seed)
98-
end,
99-
function(tbl)
100-
local spawn_shape = spawn_builder(config)
101-
local water_shape = (config.water or empty_builder)(config)
102-
local tile_builder = tile_builder_factory(config)
103-
local trees_shape = (config.trees or no_op)(config)
104-
local enemy_shape = (config.enemy or no_op)(config)
105-
local fish_spawn_rate = config.fish_spawn_rate
106-
local main_ores_builder = (config.main_ores_builder or deafult_main_ores_builder)(config)
107-
108-
start_ore_shape = config.start_ore_shape or b.circle(68)
109-
resource_patches = (config.resource_patches or no_op)(config) or b.empty_shape
110-
no_resource_patch_shape = config.no_resource_patch_shape or b.empty_shape
111-
dense_patches = (config.dense_patches or no_op)(config) or no_op
112-
113-
local random_gen = tbl.random
114-
random_gen.re_seed(tbl.seed)
115-
map = main_ores_builder(tile_builder, ore_builder, spawn_shape, water_shape, random_gen)
116-
117-
if enemy_shape then
118-
map = b.apply_entity(map, enemy_shape)
119-
end
93+
Global.register_init({}, function(tbl)
94+
tbl.seed = RS.get_surface().map_gen_settings.seed
95+
tbl.random = game.create_random_generator(tbl.seed)
96+
end, function(tbl)
97+
local spawn_shape = spawn_builder(config)
98+
local water_shape = (config.water or empty_builder)(config)
99+
local tile_builder = tile_builder_factory(config)
100+
local trees_shape = (config.trees or no_op)(config)
101+
local enemy_shape = (config.enemy or no_op)(config)
102+
local fish_spawn_rate = config.fish_spawn_rate
103+
local main_ores_builder = (config.main_ores_builder or deafult_main_ores_builder)(config)
104+
local post_map_func = config.post_map_func
105+
106+
start_ore_shape = config.start_ore_shape or b.circle(68)
107+
resource_patches = (config.resource_patches or no_op)(config) or b.empty_shape
108+
no_resource_patch_shape = config.no_resource_patch_shape or b.empty_shape
109+
dense_patches = (config.dense_patches or no_op)(config) or no_op
110+
111+
local random_gen = tbl.random
112+
random_gen.re_seed(tbl.seed)
113+
map = main_ores_builder(tile_builder, ore_builder, spawn_shape, water_shape, random_gen)
114+
115+
if enemy_shape then
116+
map = b.apply_entity(map, enemy_shape)
117+
end
120118

121-
if trees_shape then
122-
map = b.apply_entity(map, trees_shape)
123-
end
119+
if trees_shape then
120+
map = b.apply_entity(map, trees_shape)
121+
end
124122

125-
if fish_spawn_rate then
126-
map = b.fish(map, fish_spawn_rate)
127-
end
123+
if fish_spawn_rate then
124+
map = b.fish(map, fish_spawn_rate)
125+
end
126+
127+
if post_map_func then
128+
map = post_map_func(map)
128129
end
129-
)
130+
end)
130131

131132
return function(x, y, world)
132133
return map(x, y, world)

map_gen/maps/danger_ores/modules/terraforming.lua

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ return function(config)
1414
Generate.enable_register_events = false
1515

1616
local start_size = config.start_size
17+
local outer_bounds = config.bounds or b.full_shape
1718

1819
local pollution_data = {
1920
min_pollution = config.min_pollution or 400,
@@ -26,17 +27,13 @@ return function(config)
2627
local chunk_list = {index = 1}
2728
local surface
2829

29-
Global.register_init(
30-
{chunk_list = chunk_list, pollution_data = pollution_data},
31-
function(tbl)
32-
tbl.surface = RS.get_surface()
33-
end,
34-
function(tbl)
35-
chunk_list = tbl.chunk_list
36-
pollution_data = tbl.pollution_data
37-
surface = tbl.surface
38-
end
39-
)
30+
Global.register_init({chunk_list = chunk_list, pollution_data = pollution_data}, function(tbl)
31+
tbl.surface = RS.get_surface()
32+
end, function(tbl)
33+
chunk_list = tbl.chunk_list
34+
pollution_data = tbl.pollution_data
35+
surface = tbl.surface
36+
end)
4037

4138
local bounds = b.rectangle(start_size, start_size)
4239

@@ -59,7 +56,9 @@ return function(config)
5956
end
6057
surface.set_tiles(tiles, true)
6158

62-
chunk_list[#chunk_list + 1] = {left_top = left_top, id = nil}
59+
if (outer_bounds(x + 0.5, y + 0.5)) then
60+
chunk_list[#chunk_list + 1] = {left_top = left_top, id = nil}
61+
end
6362
end
6463
end
6564

@@ -102,8 +101,7 @@ return function(config)
102101

103102
local id = data.id
104103
if not id then
105-
data.id =
106-
rendering.draw_text {
104+
data.id = rendering.draw_text {
107105
text = text,
108106
surface = surface,
109107
target = {x + 16, y + 16},

0 commit comments

Comments
 (0)