1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00

Merge pull request #187 from grilledham/random-gen-refactor

Random gen refactor
This commit is contained in:
grilledham 2018-06-12 17:33:35 +01:00 committed by GitHub
commit 637fb6dff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 212 additions and 211 deletions

View File

@ -385,15 +385,15 @@ function run_combined_module(event)
local seed_increment_number = 10000
local seed = global.perlin_noise_seed
local noise_borg_defense_1 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
local noise_borg_defense_1 = perlin.noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_borg_defense_2 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
local noise_borg_defense_2 = perlin.noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_borg_defense = noise_borg_defense_1 + noise_borg_defense_2 * 0.15
local noise_trees_1 = perlin:noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
local noise_trees_1 = perlin.noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_trees_2 = perlin:noise(((pos_x + seed) / 15), ((pos_y + seed) / 15), 0)
local noise_trees_2 = perlin.noise(((pos_x + seed) / 15), ((pos_y + seed) / 15), 0)
seed = seed + seed_increment_number
local noise_trees = noise_trees_1 + noise_trees_2 * 0.3
@ -465,11 +465,11 @@ function run_combined_module(event)
end
end
local noise_walls_1 = perlin:noise(((pos_x + seed) / 200), ((pos_y + seed) / 200), 0)
local noise_walls_1 = perlin.noise(((pos_x + seed) / 200), ((pos_y + seed) / 200), 0)
seed = seed + seed_increment_number
local noise_walls_2 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
local noise_walls_2 = perlin.noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_walls_3 = perlin:noise(((pos_x + seed) / 25), ((pos_y + seed) / 25), 0)
local noise_walls_3 = perlin.noise(((pos_x + seed) / 25), ((pos_y + seed) / 25), 0)
seed = seed + seed_increment_number
local noise_walls = noise_walls_1 + noise_walls_2 + noise_walls_3 * 0.05

View File

@ -102,23 +102,23 @@ return function(x, y, world)
local seed_increment_number = 10000
local seed = surface.map_gen_settings.seed
local noise_borg_defense_1 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
local noise_borg_defense_1 = perlin.noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_borg_defense_2 = perlin:noise(((world.x + seed) / 20), ((world.y + seed) / 20), 0)
local noise_borg_defense_2 = perlin.noise(((world.x + seed) / 20), ((world.y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_borg_defense = noise_borg_defense_1 + noise_borg_defense_2 * 0.15
local noise_trees_1 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
local noise_trees_1 = perlin.noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_trees_2 = perlin:noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
local noise_trees_2 = perlin.noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
seed = seed + seed_increment_number
local noise_trees = noise_trees_1 + noise_trees_2 * 0.3
local noise_walls_1 = perlin:noise(((world.x + seed) / 150), ((world.y + seed) / 150), 0)
local noise_walls_1 = perlin.noise(((world.x + seed) / 150), ((world.y + seed) / 150), 0)
seed = seed + seed_increment_number
local noise_walls_2 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
local noise_walls_2 = perlin.noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_walls_3 = perlin:noise(((world.x + seed) / 20), ((world.y + seed) / 20), 0)
local noise_walls_3 = perlin.noise(((world.x + seed) / 20), ((world.y + seed) / 20), 0)
seed = seed + seed_increment_number
local noise_walls = noise_walls_1 + noise_walls_2 * 0.1 + noise_walls_3 * 0.03
@ -208,23 +208,23 @@ return function(x, y, world)
table.insert(entities, {name = 'rock-big'})
end
local noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
local noise_water_1 = perlin.noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
seed = seed + seed_increment_number
local noise_water_2 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
local noise_water_2 = perlin.noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_water_3 = perlin:noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
local noise_water_3 = perlin.noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
seed = seed + seed_increment_number
local noise_water_4 = perlin:noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
local noise_water_4 = perlin.noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
seed = seed + seed_increment_number
local noise_water = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
noise_water_1 = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
noise_water_1 = perlin.noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
seed = seed + seed_increment_number
noise_water_2 = perlin:noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
noise_water_2 = perlin.noise(((world.x + seed) / 100), ((world.y + seed) / 100), 0)
seed = seed + seed_increment_number
noise_water_3 = perlin:noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
noise_water_3 = perlin.noise(((world.x + seed) / 25), ((world.y + seed) / 25), 0)
seed = seed + seed_increment_number
noise_water_4 = perlin:noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
noise_water_4 = perlin.noise(((world.x + seed) / 10), ((world.y + seed) / 10), 0)
seed = seed + seed_increment_number
noise_water_2 = noise_water_1 + noise_water_2 + noise_water_3 * 0.07 + noise_water_4 * 0.07
@ -254,9 +254,9 @@ return function(x, y, world)
end
end
local noise_decoratives_1 = perlin:noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
local noise_decoratives_1 = perlin.noise(((world.x + seed) / 50), ((world.y + seed) / 50), 0)
seed = seed + seed_increment_number
local noise_decoratives_2 = perlin:noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
local noise_decoratives_2 = perlin.noise(((world.x + seed) / 15), ((world.y + seed) / 15), 0)
local noise_decoratives = noise_decoratives_1 + noise_decoratives_2 * 0.3
local decoratives

View File

@ -349,10 +349,10 @@ function run_swamp_river(params)
for y = 0, 31, 1 do
local pos_y = area.left_top.y + y
local noise_terrain_1 = perlin:noise(((pos_x + seed) / 150), ((pos_y + seed) / 150), 0)
local noise_terrain_2 = perlin:noise(((pos_x + seed) / 75), ((pos_y + seed) / 75), 0)
local noise_terrain_3 = perlin:noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
local noise_terrain_4 = perlin:noise(((pos_x + seed) / 7), ((pos_y + seed) / 7), 0)
local noise_terrain_1 = perlin.noise(((pos_x + seed) / 150), ((pos_y + seed) / 150), 0)
local noise_terrain_2 = perlin.noise(((pos_x + seed) / 75), ((pos_y + seed) / 75), 0)
local noise_terrain_3 = perlin.noise(((pos_x + seed) / 50), ((pos_y + seed) / 50), 0)
local noise_terrain_4 = perlin.noise(((pos_x + seed) / 7), ((pos_y + seed) / 7), 0)
local noise_terrain =
noise_terrain_1 + (noise_terrain_2 * 0.2) + (noise_terrain_3 * 0.1) + (noise_terrain_4 * 0.02)
local tile_to_insert

View File

@ -28,58 +28,58 @@ return function(x, y, world)
local seed_increment = 10000
seed = seed + seed_increment
local noise_island_starting_1 = perlin:noise(((x + seed) / 30), ((y + seed) / 30), 0)
local noise_island_starting_1 = perlin.noise(((x + seed) / 30), ((y + seed) / 30), 0)
seed = seed + seed_increment
local noise_island_starting_2 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_starting_2 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
seed = seed + seed_increment
local noise_island_starting = noise_island_starting_1 + (noise_island_starting_2 * 0.3)
noise_island_starting = noise_island_starting * 8000
seed = seed + seed_increment
local noise_island_iron_and_copper_1 = perlin:noise(((x + seed) / 300), ((y + seed) / 300), 0)
local noise_island_iron_and_copper_1 = perlin.noise(((x + seed) / 300), ((y + seed) / 300), 0)
seed = seed + seed_increment
local noise_island_iron_and_copper_2 = perlin:noise(((x + seed) / 40), ((y + seed) / 40), 0)
local noise_island_iron_and_copper_2 = perlin.noise(((x + seed) / 40), ((y + seed) / 40), 0)
seed = seed + seed_increment
local noise_island_iron_and_copper_3 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_iron_and_copper_3 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_iron_and_copper =
noise_island_iron_and_copper_1 + (noise_island_iron_and_copper_2 * 0.1) +
(noise_island_iron_and_copper_3 * 0.05)
seed = seed + seed_increment
local noise_island_stone_and_coal_1 = perlin:noise(((x + seed) / 300), ((y + seed) / 300), 0)
local noise_island_stone_and_coal_1 = perlin.noise(((x + seed) / 300), ((y + seed) / 300), 0)
seed = seed + seed_increment
local noise_island_stone_and_coal_2 = perlin:noise(((x + seed) / 40), ((y + seed) / 40), 0)
local noise_island_stone_and_coal_2 = perlin.noise(((x + seed) / 40), ((y + seed) / 40), 0)
seed = seed + seed_increment
local noise_island_stone_and_coal_3 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_stone_and_coal_3 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_stone_and_coal =
noise_island_stone_and_coal_1 + (noise_island_stone_and_coal_2 * 0.1) + (noise_island_stone_and_coal_3 * 0.05)
seed = seed + seed_increment
local noise_island_oil_and_uranium_1 = perlin:noise(((x + seed) / 300), ((y + seed) / 300), 0)
local noise_island_oil_and_uranium_1 = perlin.noise(((x + seed) / 300), ((y + seed) / 300), 0)
seed = seed + seed_increment
local noise_island_oil_and_uranium_2 = perlin:noise(((x + seed) / 40), ((y + seed) / 40), 0)
local noise_island_oil_and_uranium_2 = perlin.noise(((x + seed) / 40), ((y + seed) / 40), 0)
seed = seed + seed_increment
local noise_island_oil_and_uranium_3 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_oil_and_uranium_3 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_oil_and_uranium =
noise_island_oil_and_uranium_1 + (noise_island_oil_and_uranium_2 * 0.1) +
(noise_island_oil_and_uranium_3 * 0.05)
seed = seed + seed_increment
local noise_island_resource = perlin:noise(((x + seed) / 60), ((y + seed) / 60), 0)
local noise_island_resource = perlin.noise(((x + seed) / 60), ((y + seed) / 60), 0)
seed = seed + seed_increment
local noise_island_resource_2 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_island_resource_2 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
noise_island_resource = noise_island_resource + noise_island_resource_2 * 0.15
seed = seed + seed_increment
local noise_trees_1 = perlin:noise(((x + seed) / 30), ((y + seed) / 30), 0)
local noise_trees_1 = perlin.noise(((x + seed) / 30), ((y + seed) / 30), 0)
seed = seed + seed_increment
local noise_trees_2 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_trees_2 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_trees = noise_trees_1 + noise_trees_2 * 0.5
seed = seed + seed_increment
local noise_decoratives_1 = perlin:noise(((x + seed) / 50), ((y + seed) / 50), 0)
local noise_decoratives_1 = perlin.noise(((x + seed) / 50), ((y + seed) / 50), 0)
seed = seed + seed_increment
local noise_decoratives_2 = perlin:noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_decoratives_2 = perlin.noise(((x + seed) / 10), ((y + seed) / 10), 0)
local noise_decoratives = noise_decoratives_1 + noise_decoratives_2 * 0.5
local tile_to_insert = 'water'
@ -204,7 +204,7 @@ return function(x, y, world)
local c = math.max(math.abs(world.x), math.abs(world.y))
local resource_amount_distance_multiplicator = (((c + 1) / 75) / 75) + 1
local noise_resource_amount_modifier = perlin:noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
local noise_resource_amount_modifier = perlin.noise(((world.x + seed) / 200), ((world.y + seed) / 200), 0)
local resource_amount =
1 + ((500 + (500 * noise_resource_amount_modifier * 0.2)) * resource_amount_distance_multiplicator)

View File

@ -43,7 +43,7 @@ local function init_blocks()
end
local function get_resource(x, y)
local value = perlin:noise(x / 16, y / 16)
local value = perlin.noise(x / 16, y / 16)
value = value + 1
value = value * 500
@ -63,7 +63,7 @@ local function get_resource(x, y)
return nil
end
value = perlin:noise(y / 64, x / 64)
value = perlin.noise(y / 64, x / 64)
value = value + 1
value = value * 500

View File

@ -168,80 +168,80 @@ function run_planet(params)
local seed_increment_number = 10000
local noise_terrain_1 = perlin:noise(((pos_x + seed) / 400), ((pos_y + seed) / 400), 0)
local noise_terrain_1 = perlin.noise(((pos_x + seed) / 400), ((pos_y + seed) / 400), 0)
noise_terrain_1 = noise_terrain_1 * 100
seed = seed + seed_increment_number
local noise_terrain_2 = perlin:noise(((pos_x + seed) / 250), ((pos_y + seed) / 250), 0)
local noise_terrain_2 = perlin.noise(((pos_x + seed) / 250), ((pos_y + seed) / 250), 0)
noise_terrain_2 = noise_terrain_2 * 100
seed = seed + seed_increment_number
local noise_terrain_3 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
local noise_terrain_3 = perlin.noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
noise_terrain_3 = noise_terrain_3 * 50
seed = seed + seed_increment_number
local noise_terrain_4 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
local noise_terrain_4 = perlin.noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
noise_terrain_4 = noise_terrain_4 * 10
seed = seed + seed_increment_number
local noise_terrain_5 = perlin:noise(((pos_x + seed) / 5), ((pos_y + seed) / 5), 0)
local noise_terrain_5 = perlin.noise(((pos_x + seed) / 5), ((pos_y + seed) / 5), 0)
noise_terrain_5 = noise_terrain_5 * 4
seed = seed + seed_increment_number
local noise_sand = perlin:noise(((pos_x + seed) / 18), ((pos_y + seed) / 18), 0)
local noise_sand = perlin.noise(((pos_x + seed) / 18), ((pos_y + seed) / 18), 0)
noise_sand = noise_sand * 10
--DECORATIVES
seed = seed + seed_increment_number
local noise_decoratives_1 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
local noise_decoratives_1 = perlin.noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
noise_decoratives_1 = noise_decoratives_1
seed = seed + seed_increment_number
local noise_decoratives_2 = perlin:noise(((pos_x + seed) / 30), ((pos_y + seed) / 30), 0)
local noise_decoratives_2 = perlin.noise(((pos_x + seed) / 30), ((pos_y + seed) / 30), 0)
noise_decoratives_2 = noise_decoratives_2
seed = seed + seed_increment_number
local noise_decoratives_3 = perlin:noise(((pos_x + seed) / 30), ((pos_y + seed) / 30), 0)
local noise_decoratives_3 = perlin.noise(((pos_x + seed) / 30), ((pos_y + seed) / 30), 0)
noise_decoratives_3 = noise_decoratives_3
seed = seed + seed_increment_number
local noise_water_1 = perlin:noise(((pos_x + seed) / 250), ((pos_y + seed) / 300), 0)
local noise_water_1 = perlin.noise(((pos_x + seed) / 250), ((pos_y + seed) / 300), 0)
noise_water_1 = noise_water_1 * 100
seed = seed + seed_increment_number
local noise_water_2 = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 150), 0)
local noise_water_2 = perlin.noise(((pos_x + seed) / 100), ((pos_y + seed) / 150), 0)
noise_water_2 = noise_water_2 * 50
--RESOURCES
seed = seed + seed_increment_number
local noise_resources = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
local noise_resources = perlin.noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
seed = seed + seed_increment_number
local noise_resources_2 = perlin:noise(((pos_x + seed) / 40), ((pos_y + seed) / 40), 0)
local noise_resources_2 = perlin.noise(((pos_x + seed) / 40), ((pos_y + seed) / 40), 0)
seed = seed + seed_increment_number
local noise_resources_3 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
local noise_resources_3 = perlin.noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
noise_resources = noise_resources * 50 + noise_resources_2 * 20 + noise_resources_3 * 20
noise_resources = noise_resources_2 * 100
seed = seed + seed_increment_number
local noise_resource_amount_modifier = perlin:noise(((pos_x + seed) / 200), ((pos_y + seed) / 200), 0)
local noise_resource_amount_modifier = perlin.noise(((pos_x + seed) / 200), ((pos_y + seed) / 200), 0)
local resource_amount =
1 + ((400 + (400 * noise_resource_amount_modifier * 0.2)) * resource_amount_distance_multiplicator)
seed = seed + seed_increment_number
local noise_resources_iron_and_copper = perlin:noise(((pos_x + seed) / 250), ((pos_y + seed) / 250), 0)
local noise_resources_iron_and_copper = perlin.noise(((pos_x + seed) / 250), ((pos_y + seed) / 250), 0)
noise_resources_iron_and_copper = noise_resources_iron_and_copper * 100
seed = seed + seed_increment_number
local noise_resources_coal_and_uranium = perlin:noise(((pos_x + seed) / 250), ((pos_y + seed) / 250), 0)
local noise_resources_coal_and_uranium = perlin.noise(((pos_x + seed) / 250), ((pos_y + seed) / 250), 0)
noise_resources_coal_and_uranium = noise_resources_coal_and_uranium * 100
seed = seed + seed_increment_number
local noise_resources_stone_and_oil = perlin:noise(((pos_x + seed) / 150), ((pos_y + seed) / 150), 0)
local noise_resources_stone_and_oil = perlin.noise(((pos_x + seed) / 150), ((pos_y + seed) / 150), 0)
noise_resources_stone_and_oil = noise_resources_stone_and_oil * 100
seed = seed + seed_increment_number
local noise_red_desert_rocks_1 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
local noise_red_desert_rocks_1 = perlin.noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
noise_red_desert_rocks_1 = noise_red_desert_rocks_1 * 100
seed = seed + seed_increment_number
local noise_red_desert_rocks_2 = perlin:noise(((pos_x + seed) / 10), ((pos_y + seed) / 10), 0)
local noise_red_desert_rocks_2 = perlin.noise(((pos_x + seed) / 10), ((pos_y + seed) / 10), 0)
noise_red_desert_rocks_2 = noise_red_desert_rocks_2 * 50
seed = seed + seed_increment_number
local noise_red_desert_rocks_3 = perlin:noise(((pos_x + seed) / 5), ((pos_y + seed) / 5), 0)
local noise_red_desert_rocks_3 = perlin.noise(((pos_x + seed) / 5), ((pos_y + seed) / 5), 0)
noise_red_desert_rocks_3 = noise_red_desert_rocks_3 * 100
seed = seed + seed_increment_number
local noise_forest = perlin:noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
local noise_forest = perlin.noise(((pos_x + seed) / 100), ((pos_y + seed) / 100), 0)
noise_forest = noise_forest * 100
seed = seed + seed_increment_number
local noise_forest_2 = perlin:noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
local noise_forest_2 = perlin.noise(((pos_x + seed) / 20), ((pos_y + seed) / 20), 0)
noise_forest_2 = noise_forest_2 * 20
local terrain_smoothing = math.random(0, 1)

View File

@ -22,7 +22,7 @@ Event.on_init(init)
local function do_resource(name, x, y, world, noise_terrain, noise_band_high, noise_band_low, seed)
if noise_terrain > -noise_band_high * width_modifier and noise_terrain <= -noise_band_low * width_modifier then
local noise_resource_amount_modifier = perlin:noise(((x + seed) / 200), ((y + seed) / 200), 0)
local noise_resource_amount_modifier = perlin.noise(((x + seed) / 200), ((y + seed) / 200), 0)
local resource_amount =
1 +
((ore_base_amounts[name] + (ore_base_amounts[name] * noise_resource_amount_modifier * 0.2)) *
@ -48,8 +48,8 @@ return function(x, y, world)
local seed = global.perlin_noise_seed
local noise_terrain_1 = perlin:noise(((x + seed) / 350), ((y + seed) / 350), 0)
local noise_terrain_2 = perlin:noise(((x + seed) / 50), ((y + seed) / 50), 0)
local noise_terrain_1 = perlin.noise(((x + seed) / 350), ((y + seed) / 350), 0)
local noise_terrain_2 = perlin.noise(((x + seed) / 50), ((y + seed) / 50), 0)
local noise_terrain = noise_terrain_1 + (noise_terrain_2 * 0.01)
return do_resource('iron-ore', x, y, world, noise_terrain, 0.11, 0.085, seed) or

View File

@ -14,7 +14,7 @@ local function harmonic(x, y)
local max = -1
local richness = 0
for i, e in ipairs(ctrs) do
local noise = perlin:noise(x / 32, y / 32, ctrs[i][6])
local noise = perlin.noise(x / 32, y / 32, ctrs[i][6])
local h_coeff =
1 /
(1 +

View File

@ -25,11 +25,11 @@ return function(x, y, world)
local distance_bonus = 200 + math.sqrt(world.x * world.x + world.y * world.y) * 0.2
local wiggle = 100 + perlin:noise((x * 0.005), (y * 0.005), global.ores_seed_A + 41) * 60
local Ores_A = perlin:noise((x * 0.01), (y * 0.01), global.ores_seed_B + 57) * wiggle
local wiggle = 100 + perlin.noise((x * 0.005), (y * 0.005), global.ores_seed_A + 41) * 60
local Ores_A = perlin.noise((x * 0.01), (y * 0.01), global.ores_seed_B + 57) * wiggle
if Ores_A > 35 then --we place ores
local Ores_B = perlin:noise((x * 0.02), (y * 0.02), global.ores_seed_B + 13) * wiggle
local Ores_B = perlin.noise((x * 0.02), (y * 0.02), global.ores_seed_B + 13) * wiggle
local a = 5
--
if Ores_A < 76 then

View File

@ -1,13 +1,23 @@
local b = require 'map_gen.shared.builders'
local perlin = require 'map_gen.shared.perlin_noise'
local Event = require "utils.event"
local sand_width = 64
local sand_width_inv = tau / sand_width
--perlin options
local noise_variance = 0.05 --The lower this number the smoother the curve is gonna be
local noise_level = 25 --Factor for the magnitude of the curve
Event.on_init(function()
global.beach_perlin_seed_A = math.random(1,10000)
global.beach_perlin_seed_B = math.random(1,10000)
end)
local function sand_shape(x, y)
local h = 6 * math.sin(0.9 * x * sand_width_inv)
h = h + 3 * math.sin(0.7 * x * sand_width_inv)
h = h + math.sin(0.33 * x * sand_width_inv)
return y < h
local wiggle = 1 + math.abs(perlin.noise((x * noise_variance), (y * noise_variance), global.beach_perlin_seed_A + 17) * noise_level / 50)
return y < perlin.noise(x * noise_variance / 2, y * noise_variance / 2, global.beach_perlin_seed_A) * noise_level * wiggle
end
sand_shape = b.change_tile(sand_shape, true, 'sand-1')
@ -53,10 +63,8 @@ local water_width = 64
local water_width_inv = tau / water_width
local function water_shape(x, y)
local h = 6 * math.sin(1.1 * x * water_width_inv)
h = h + 3 * math.sin(0.74 * x * water_width_inv)
h = h + math.sin(0.3 * x * water_width_inv)
return y < h
local wiggle = 1 + math.abs(perlin.noise((x * noise_variance), (y * noise_variance), global.beach_perlin_seed_B + 17) * noise_level / 50)
return y < perlin.noise(x * noise_variance, y * noise_variance, global.beach_perlin_seed_B) * noise_level * wiggle
end
water_shape = b.change_tile(water_shape, true, 'water')

View File

@ -3,8 +3,8 @@
http://flafla2.github.io/2014/08/09/perlinnoise.html
]]--
local perlin = {}
perlin.p = {}
local Perlin = {}
local p = {}
-- Hash lookup table as defined by Ken Perlin
-- This is a randomly arranged array of all numbers from 0-255 inclusive
@ -26,16 +26,54 @@ local permutation = {151,160,137,91,90,15,
-- p is used to hash unit cube coordinates to [0, 255]
for i=0,255 do
-- Convert to 0 based index table
perlin.p[i] = permutation[i+1]
p[i] = permutation[i+1]
-- Repeat the array to avoid buffer overflow in hash function
perlin.p[i+256] = permutation[i+1]
p[i+256] = permutation[i+1]
end
-- Gradient function finds dot product between pseudorandom gradient vector
-- and the vector from input coordinate to a unit cube vertex
local dot_product = {
[0x0]=function(x,y,z) return x + y end,
[0x1]=function(x,y,z) return -x + y end,
[0x2]=function(x,y,z) return x - y end,
[0x3]=function(x,y,z) return -x - y end,
[0x4]=function(x,y,z) return x + z end,
[0x5]=function(x,y,z) return -x + z end,
[0x6]=function(x,y,z) return x - z end,
[0x7]=function(x,y,z) return -x - z end,
[0x8]=function(x,y,z) return y + z end,
[0x9]=function(x,y,z) return -y + z end,
[0xA]=function(x,y,z) return y - z end,
[0xB]=function(x,y,z) return -y - z end,
[0xC]=function(x,y,z) return y + x end,
[0xD]=function(x,y,z) return -y + z end,
[0xE]=function(x,y,z) return y - x end,
[0xF]=function(x,y,z) return -y - z end
}
local function grad(hash, x, y, z)
return dot_product[bit32.band(hash,0xF)](x,y,z)
end
-- Fade function is used to smooth final output
local function fade(t)
return t * t * t * (t * (t * 6 - 15) + 10)
end
local function lerp(t, a, b)
return a + t * (b - a)
end
-- Return range: [-1, 1]
function perlin:noise(x, y, z)
function Perlin.noise(x, y, z)
y = y or 0
z = z or 0
-- This prevents integer inputs returning 0, which casues 'straight line' artifacts.
x = x - 0.55077056353912
y = y - 0.131357755512
z = z - 0.20474238274619
-- Calculate the "unit cube" that the point asked will be located in
local xi = bit32.band(math.floor(x),255)
local yi = bit32.band(math.floor(y),255)
@ -47,12 +85,11 @@ function perlin:noise(x, y, z)
z = z - math.floor(z)
-- We also fade the location to smooth the result
local u = self.fade(x)
local v = self.fade(y)
local w = self.fade(z)
local u = fade(x)
local v = fade(y)
local w = fade(z)
-- Hash all 8 unit cube coordinates surrounding input coordinate
local p = self.p
local A, AA, AB, AAA, ABA, AAB, ABB, B, BA, BB, BAA, BBA, BAB, BBB
A = p[xi ] + yi
AA = p[A ] + zi
@ -71,59 +108,26 @@ function perlin:noise(x, y, z)
BBB = p[ BB+1 ]
-- Take the weighted average between all 8 unit cube coordinates
return self.lerp(w,
self.lerp(v,
self.lerp(u,
self:grad(AAA,x,y,z),
self:grad(BAA,x-1,y,z)
return lerp(w,
lerp(v,
lerp(u,
grad(AAA,x,y,z),
grad(BAA,x-1,y,z)
),
self.lerp(u,
self:grad(ABA,x,y-1,z),
self:grad(BBA,x-1,y-1,z)
lerp(u,
grad(ABA,x,y-1,z),
grad(BBA,x-1,y-1,z)
)
),
self.lerp(v,
self.lerp(u,
self:grad(AAB,x,y,z-1), self:grad(BAB,x-1,y,z-1)
lerp(v,
lerp(u,
grad(AAB,x,y,z-1), grad(BAB,x-1,y,z-1)
),
self.lerp(u,
self:grad(ABB,x,y-1,z-1), self:grad(BBB,x-1,y-1,z-1)
lerp(u,
grad(ABB,x,y-1,z-1), grad(BBB,x-1,y-1,z-1)
)
)
)
end
-- Gradient function finds dot product between pseudorandom gradient vector
-- and the vector from input coordinate to a unit cube vertex
perlin.dot_product = {
[0x0]=function(x,y,z) return x + y end,
[0x1]=function(x,y,z) return -x + y end,
[0x2]=function(x,y,z) return x - y end,
[0x3]=function(x,y,z) return -x - y end,
[0x4]=function(x,y,z) return x + z end,
[0x5]=function(x,y,z) return -x + z end,
[0x6]=function(x,y,z) return x - z end,
[0x7]=function(x,y,z) return -x - z end,
[0x8]=function(x,y,z) return y + z end,
[0x9]=function(x,y,z) return -y + z end,
[0xA]=function(x,y,z) return y - z end,
[0xB]=function(x,y,z) return -y - z end,
[0xC]=function(x,y,z) return y + x end,
[0xD]=function(x,y,z) return -y + z end,
[0xE]=function(x,y,z) return y - x end,
[0xF]=function(x,y,z) return -y - z end
}
function perlin:grad(hash, x, y, z)
return self.dot_product[bit32.band(hash,0xF)](x,y,z)
end
-- Fade function is used to smooth final output
function perlin.fade(t)
return t * t * t * (t * (t * 6 - 15) + 10)
end
function perlin.lerp(t, a, b)
return a + t * (b - a)
end
return perlin
return Perlin

View File

@ -15,24 +15,39 @@ function Random.new(seed1, seed2)
return random
end
local function get_uint(self)
self.z = 36969 * bit32.band(self.z, 65535) + bit32.rshift(self.z, 16)
self.w = 18000 * bit32.band(self.w, 65535) + bit32.rshift(self.w, 16)
local ret = bit32.lshift(self.z, 16) + self.w
return bit32.band(ret, 4294967295)
end
local e = 1 / (2 ^ 32 + 2)
-- return float (0, 1) exclusive
function Random:next()
local u = get_uint(self)
return (u + 1.0) * e
function Random.next(self)
local z, w = self.z, self.w
z = 36969 * bit32.band(z, 65535) + bit32.rshift(z, 16)
w = 18000 * bit32.band(w, 65535) + bit32.rshift(w, 16)
self.z, self.w = z, w
local ret = bit32.lshift(z, 16) + w
ret = bit32.band(ret, 4294967295)
return (ret + 1.0) * e
end
-- returns int [min, max] inclusive
function Random:next_int(min, max)
local u = self:next()
function Random.next_int(self, min, max)
local u = Random.next(self)
u = u * (max - min + 1) + min
return math.floor(u)
end
function Random.next_from_point(x, y)
x = 36969 * bit32.band(x, 65535) + bit32.rshift(x, 16)
y = 18000 * bit32.band(y, 65535) + bit32.rshift(y, 16)
local ret = bit32.lshift(x, 16) + y
ret = bit32.band(ret, 4294967295)
return (ret + 1.0) * e
end
function Random.next_int_from_point(x, y, min, max)
local u = Random.next_from_point(x, y)
u = u * (max - min + 1) + min
return math.floor(u)

View File

@ -1,6 +1,7 @@
--from https://github.com/thenumbernine/lua-simplexnoise/blob/master/2d.lua
--Mostly as a test, does not give same results as perlin but is designed to give patterns all the same
local bit = bit32 or require 'bit'
local Simplex = {}
-- 2D simplex noise
@ -25,7 +26,7 @@ local p = {151,160,137,91,90,15,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180}
local perm = {}
for i=0,511 do
perm[i+1] = p[bit.band(i, 255) + 1]
perm[i+1] = p[bit32.band(i, 255) + 1]
end
local function dot(g, ...)
@ -37,7 +38,7 @@ local function dot(g, ...)
return sum
end
function simplex_2d(xin, yin,seed)
function Simplex.d2(xin, yin,seed)
xin = xin + seed
yin = yin + seed
local n0, n1, n2 -- Noise contributions from the three corners
@ -70,8 +71,8 @@ function simplex_2d(xin, yin,seed)
local x2 = x0 - 1 + 2 * G2 -- Offsets for last corner in (x,y) unskewed coords
local y2 = y0 - 1 + 2 * G2
-- Work out the hashed gradient indices of the three simplex corners
local ii = bit.band(i, 255)
local jj = bit.band(j, 255)
local ii = bit32.band(i, 255)
local jj = bit32.band(j, 255)
local gi0 = perm[ii + perm[jj+1]+1] % 12
local gi1 = perm[ii + i1 + perm[jj + j1+1]+1] % 12
local gi2 = perm[ii + 1 + perm[jj + 1+1]+1] % 12
@ -101,3 +102,5 @@ function simplex_2d(xin, yin,seed)
-- The result is scaled to return values in the interval [-1,1].
return 70.0 * (n0 + n1 + n2)
end
return Simplex

View File

@ -1,4 +1,5 @@
local perlin = require 'map_gen.shared.perlin_noise'
local simplex = require 'map_gen.shared.simplex_noise'
local tree_to_place = {'dry-tree', 'dry-hairy-tree', 'tree-06', 'tree-06', 'tree-01', 'tree-02', 'tree-03'}
@ -45,20 +46,20 @@ function run_terrain_module(event)
if tile.name ~= 'out-of-map' then
local tile_to_insert = 'grass-3'
local wiggle = 50 + perlin:noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 71) * 60
local terrain_A = perlin:noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 19) * wiggle --For determining where water is
local wiggle = 50 + perlin.noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 71) * 60
local terrain_A = perlin.noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 19) * wiggle --For determining where water is
local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well
local terrain_D = 10 + perlin:noise((x * 0.001), (y * 0.001), global.terrain_seed_A + 5) * wiggle --terrain layer
local terrain_D = 10 + perlin.noise((x * 0.001), (y * 0.001), global.terrain_seed_A + 5) * wiggle --terrain layer
--local wiggle = 50 + simplex_2d((x*0.005),(y*0.005),global.terrain_seed_A + 71) * 60
--local terrain_A = simplex_2d((x*0.005),(y*0.005),global.terrain_seed_A + 19) * wiggle --For determining where water is
--local wiggle = 50 + Simplex.d2((x*0.005),(y*0.005),global.terrain_seed_A + 71) * 60
--local terrain_A = Simplex.d2((x*0.005),(y*0.005),global.terrain_seed_A + 19) * wiggle --For determining where water is
--local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well
--local terrain_D = 10 + simplex_2d((x*0.001),(y*0.001),global.terrain_seed_A + 5) * wiggle --terrain layer
--local terrain_D = 10 + Simplex.d2((x*0.001),(y*0.001),global.terrain_seed_A + 5) * wiggle --terrain layer
if terrain_sqr < 50 then --Main water areas
--local deep = (terrain_sqr < 20) and true or false
terrain_A = perlin:noise((x * 0.01), (y * 0.01), global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
--terrain_A = simplex_2d((x*0.01),(y*0.01),global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
terrain_A = perlin.noise((x * 0.01), (y * 0.01), global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
--terrain_A = Simplex.d2((x*0.01),(y*0.01),global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer
--table.insert(tileswater, {name = "water", position = {x,y}})
@ -72,11 +73,11 @@ function run_terrain_module(event)
end
end
elseif terrain_sqr > 70 then
wiggle = 100 + perlin:noise((x * 0.01), (y * 0.01), global.terrain_seed_B + 41) * 60
local terrain_C = perlin:noise((x * 0.02), (y * 0.02), global.terrain_seed_A + 13) * wiggle --tree layer
wiggle = 100 + perlin.noise((x * 0.01), (y * 0.01), global.terrain_seed_B + 41) * 60
local terrain_C = perlin.noise((x * 0.02), (y * 0.02), global.terrain_seed_A + 13) * wiggle --tree layer
--wiggle = 100 + simplex_2d((x*0.01),(y*0.01),global.terrain_seed_B + 41) * 60
--local terrain_C = simplex_2d((x*0.02),(y*0.02),global.terrain_seed_A + 13) * wiggle --tree layer
--wiggle = 100 + Simplex.d2((x*0.01),(y*0.01),global.terrain_seed_B + 41) * 60
--local terrain_C = Simplex.d2((x*0.02),(y*0.02),global.terrain_seed_A + 13) * wiggle --tree layer
--if surface.can_place_entity {name="stone", position={x,y}} then
-- surface.create_entity {name="stone", position={x,y}, amount=math.floor(terrain_sqr)}
@ -102,7 +103,7 @@ function run_terrain_module(event)
-- end
--end
--wiggle = 100 + perlin:noise((pos_x*0.02),(pos_y*0.02),global.terrain_seed_B + 71) * 60
--wiggle = 100 + perlin.noise((pos_x*0.02),(pos_y*0.02),global.terrain_seed_B + 71) * 60
if terrain_D < 20 then
if terrain_C < 4 then --we set grass-1 around near forest areas

View File

@ -9,12 +9,12 @@ end
Event.on_init(init)
return function(x, y, world)
local wiggle = 50 + perlin:noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 71) * 60
local terrain_A = perlin:noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 19) * wiggle --For determining where water is
local wiggle = 50 + perlin.noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 71) * 60
local terrain_A = perlin.noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 19) * wiggle --For determining where water is
local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well
if terrain_sqr < 50 then --Main water areas
terrain_A = perlin:noise((x * 0.01), (y * 0.01), global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
terrain_A = perlin.noise((x * 0.01), (y * 0.01), global.terrain_seed_A + 31) * 90 + (wiggle * -0.2) --we only gen this when we consider placing water
if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer
return 'water'

View File

@ -1,30 +0,0 @@
--Author: Valansch
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
set._n = #set
return set
end
global.poisson_set = {}
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(global.poisson_set[l]._n)]
end