1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-26 03:52:00 +02:00

moved perlin requires into files that acually call it.

This commit is contained in:
Valansch 2017-07-18 21:26:12 +02:00
parent 1c62f974fa
commit a816b88278
4 changed files with 98 additions and 95 deletions

View File

@ -1,3 +1,5 @@
require "locale.gen_shared.perlin_noise"
if ores_module then return end if ores_module then return end
ores_module = true ores_module = true
@ -15,52 +17,52 @@ function run_ores_module(event)
run_ores_module_setup() run_ores_module_setup()
--if not global.ores_seed_A then global.ores_seed_A = math.random(10,10000) end --if not global.ores_seed_A then global.ores_seed_A = math.random(10,10000) end
--if not global.ores_seed_B then global.ores_seed_B = math.random(10,10000) end --if not global.ores_seed_B then global.ores_seed_B = math.random(10,10000) end
local area = event.area local area = event.area
local surface = event.surface local surface = event.surface
local tiles = {} local tiles = {}
local entities = surface.find_entities(area) local entities = surface.find_entities(area)
for _, entity in pairs(entities) do for _, entity in pairs(entities) do
if entity.type == "resource" then if entity.type == "resource" then
entity.destroy() entity.destroy()
end end
end end
local top_left = area.left_top --make a more direct reference local top_left = area.left_top --make a more direct reference
local distance_bonus = 200 + math.sqrt(top_left.x*top_left.x + top_left.y*top_left.y) * 0.2 local distance_bonus = 200 + math.sqrt(top_left.x*top_left.x + top_left.y*top_left.y) * 0.2
for x = top_left.x, top_left.x + 31 do for x = top_left.x, top_left.x + 31 do
for y = top_left.y, top_left.y + 31 do for y = top_left.y, top_left.y + 31 do
--table.insert(tiles, {name = "out-of-map", position = {x,y}}) --table.insert(tiles, {name = "out-of-map", position = {x,y}})
local wiggle = 100 + perlin:noise((x*0.005),(y*0.005),global.ores_seed_A + 41) * 60 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 Ores_A = perlin:noise((x*0.01),(y*0.01),global.ores_seed_B + 57) * wiggle
if Ores_A > 35 then --we place ores 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 local a = 5
-- --
if Ores_A < 76 then a = math.floor(Ores_A*0.75 + Ores_B*0.5) % 4 + 1 end --if its not super high we place normal ores if Ores_A < 76 then a = math.floor(Ores_A*0.75 + Ores_B*0.5) % 4 + 1 end --if its not super high we place normal ores
-- --
local res_amount = distance_bonus local res_amount = distance_bonus
res_amount = math.floor(res_amount * random_dense[a]) res_amount = math.floor(res_amount * random_dense[a])
-- --
if surface.can_place_entity {name=random_ores[a], position={x,y}} then if surface.can_place_entity {name=random_ores[a], position={x,y}} then
surface.create_entity {name=random_ores[a], position={x,y}, amount=res_amount} surface.create_entity {name=random_ores[a], position={x,y}, amount=res_amount}
end end
elseif Ores_A < -60 then elseif Ores_A < -60 then
if math.random(1,200) == 1 and surface.can_place_entity {name="crude-oil", position={x,y}} then if math.random(1,200) == 1 and surface.can_place_entity {name="crude-oil", position={x,y}} then
surface.create_entity {name="crude-oil", position={x,y}, amount = math.random(5000,20000) +math.floor(distance_bonus)* 1500 } surface.create_entity {name="crude-oil", position={x,y}, amount = math.random(5000,20000) +math.floor(distance_bonus)* 1500 }
end end
end end
end end
end end
end end
--used when terrain modual passes to it, can save extra calculations --used when terrain modual passes to it, can save extra calculations
@ -70,25 +72,24 @@ function run_ores_module_tile(surface,x,y)
local wiggle = 100 + perlin:noise((x*0.005),(y*0.005),global.ores_seed_A + 41) * 60 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 Ores_A = perlin:noise((x*0.01),(y*0.01),global.ores_seed_B + 57) * wiggle
if Ores_A > 35 then --we place ores 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 local a = 5
-- --
if Ores_A < 76 then a = math.floor(Ores_A*0.75 + Ores_B*0.5) % 4 + 1 end --if its not super high we place normal ores if Ores_A < 76 then a = math.floor(Ores_A*0.75 + Ores_B*0.5) % 4 + 1 end --if its not super high we place normal ores
-- --
local res_amount = distance_bonus local res_amount = distance_bonus
res_amount = math.floor(res_amount * random_dense[a]) res_amount = math.floor(res_amount * random_dense[a])
-- --
--if surface.can_place_entity {name=random_ores[a], position={x,y}} then --if surface.can_place_entity {name=random_ores[a], position={x,y}} then
--We assume it can be places because terrain gen told us to. --We assume it can be places because terrain gen told us to.
surface.create_entity {name=random_ores[a], position={x,y}, amount=res_amount} surface.create_entity {name=random_ores[a], position={x,y}, amount=res_amount}
--end --end
elseif Ores_A < -60 then elseif Ores_A < -60 then
if math.random(1,200) == 1 then if math.random(1,200) == 1 then
surface.create_entity {name="crude-oil", position={x,y}, amount = math.random(5000,20000) +math.floor(distance_bonus)* 1500 } surface.create_entity {name="crude-oil", position={x,y}, amount = math.random(5000,20000) +math.floor(distance_bonus)* 1500 }
end end
end end
end
end

View File

@ -68,4 +68,7 @@ function grad( hash, x, y, z )
local u = h < 8 and x or y local u = h < 8 and x or y
local v = h < 4 and y or ((h == 12 or h == 14) and x or z) local v = h < 4 and y or ((h == 12 or h == 14) and x or z)
return ((h % 2) == 0 and u or -u) + ((h % 3) == 0 and v or -v) return ((h % 2) == 0 and u or -u) + ((h % 3) == 0 and v or -v)
end end
perlin:load( )

View File

@ -1,63 +1,66 @@
require "locale.gen_shared.perlin_noise"
if terrain_module then return end if terrain_module then return end
terrain_module = true terrain_module = true
local tree_to_place = {"dry-tree","dry-hairy-tree","tree-06","tree-06","tree-01","tree-02","tree-03"} local tree_to_place = {"dry-tree","dry-hairy-tree","tree-06","tree-06","tree-01","tree-02","tree-03"}
function run_terrain_module(event) function run_terrain_module(event)
if not global.terrain_seed_A then global.terrain_seed_A = math.random(10,10000) end if not global.terrain_seed_A then global.terrain_seed_A = math.random(10,10000) end
if not global.terrain_seed_B then global.terrain_seed_B = math.random(10,10000) end if not global.terrain_seed_B then global.terrain_seed_B = math.random(10,10000) end
local area = event.area local area = event.area
local surface = event.surface local surface = event.surface
local tiles = {} local tiles = {}
local tileswater = {} local tileswater = {}
local entities = surface.find_entities(area) local entities = surface.find_entities(area)
for _, entity in pairs(entities) do for _, entity in pairs(entities) do
--if entity.type == "simple-entity" or entity.type == "resource" or entity.type == "tree" then --if entity.type == "simple-entity" or entity.type == "resource" or entity.type == "tree" then
if entity.type == "simple-entity" or entity.type == "tree"then if entity.type == "simple-entity" or entity.type == "tree"then
entity.destroy() entity.destroy()
--end --end
elseif (ores_module and entity.type == "resource") then elseif (ores_module and entity.type == "resource") then
entity.destroy() entity.destroy()
end end
end end
local top_left = area.left_top --make a more direct reference local top_left = area.left_top --make a more direct reference
--do it only per chunk, cause cheaper than every square, and who care anyway. --do it only per chunk, cause cheaper than every square, and who care anyway.
--local distance_bonus = 200 + math.sqrt(top_left.x*top_left.x + top_left.y*top_left.y) * 0.2 --local distance_bonus = 200 + math.sqrt(top_left.x*top_left.x + top_left.y*top_left.y) * 0.2
--for x = 0, 31, 1 do --for x = 0, 31, 1 do
-- for y = 0, 31, 1 do -- for y = 0, 31, 1 do
--game.print(top_left.x .."-" ..top_left.y .. " to " .. area.right_bottom.x .. "-" .. area.right_bottom.y) --game.print(top_left.x .."-" ..top_left.y .. " to " .. area.right_bottom.x .. "-" .. area.right_bottom.y)
for x = top_left.x-1, top_left.x + 32 do for x = top_left.x-1, top_left.x + 32 do
for y = top_left.y-1, top_left.y + 32 do for y = top_left.y-1, top_left.y + 32 do
--local pos_x = top_left.x + x --local pos_x = top_left.x + x
--local pos_y = top_left.y + y --local pos_y = top_left.y + y
local tile = surface.get_tile(x,y) local tile = surface.get_tile(x,y)
if tile.name ~= "out-of-map" then if tile.name ~= "out-of-map" then
local tile_to_insert = "grass-medium" local tile_to_insert = "grass-medium"
local wiggle = 50 + perlin:noise((x*0.005),(y*0.005),global.terrain_seed_A + 71) * 60 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_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_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 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 terrain_A = simplex_2d((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_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_2d((x*0.001),(y*0.001),global.terrain_seed_A + 5) * wiggle --terrain layer
if terrain_sqr < 50 then --Main water areas if terrain_sqr < 50 then --Main water areas
--local deep = (terrain_sqr < 20) and true or false --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 = 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 = 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
if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer if terrain_A * terrain_A > 40 then --creates random bridges over the water by overlapping with another noise layer
tile_to_insert = "water" tile_to_insert = "water"
@ -75,50 +78,50 @@ function run_terrain_module(event)
--wiggle = 100 + simplex_2d((x*0.01),(y*0.01),global.terrain_seed_B + 41) * 60 --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 --local terrain_C = simplex_2d((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 --if surface.can_place_entity {name="stone", position={x,y}} then
-- surface.create_entity {name="stone", position={x,y}, amount=math.floor(terrain_sqr)} -- surface.create_entity {name="stone", position={x,y}, amount=math.floor(terrain_sqr)}
--end --end
if ores_module then if ores_module then
run_ores_module_setup() run_ores_module_setup()
if x > top_left.x-1 and x < top_left.x+32 and y > top_left.y-1 and y < top_left.y+32 then if x > top_left.x-1 and x < top_left.x+32 and y > top_left.y-1 and y < top_left.y+32 then
run_ores_module_tile(surface,x,y) run_ores_module_tile(surface,x,y)
end end
end end
--if terrain_B > 35 then --we place ores --if terrain_B > 35 then --we place ores
-- local a = 5 -- local a = 5
-- --
-- if terrain_B < 76 then a = math.floor(terrain_B*0.75 + terrain_C*0.5) % 4 + 1 end --if its not super high we place normal ores -- if terrain_B < 76 then a = math.floor(terrain_B*0.75 + terrain_C*0.5) % 4 + 1 end --if its not super high we place normal ores
-- --
-- local res_amount = distance_bonus + terrain_sqr * 0.1 -- local res_amount = distance_bonus + terrain_sqr * 0.1
-- res_amount = math.floor(res_amount * random_dense[a]) -- res_amount = math.floor(res_amount * random_dense[a])
-- --
-- if surface.can_place_entity {name=random_ores[a], position={pos_x,pos_y}} then -- if surface.can_place_entity {name=random_ores[a], position={pos_x,pos_y}} then
-- surface.create_entity {name=random_ores[a], position={pos_x,pos_y}, amount=res_amount} -- surface.create_entity {name=random_ores[a], position={pos_x,pos_y}, amount=res_amount}
-- end -- end
--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_D < 20 then
if terrain_C < 4 then --we set grass around near forest areas if terrain_C < 4 then --we set grass around near forest areas
tile_to_insert = "grass" tile_to_insert = "grass"
if terrain_C < -20 and math.random(1,3) == 1 then --dense trees if terrain_C < -20 and math.random(1,3) == 1 then --dense trees
local treenum = math.random(3,7) local treenum = math.random(3,7)
if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then
surface.create_entity {name=tree_to_place[treenum], position={x,y}} surface.create_entity {name=tree_to_place[treenum], position={x,y}}
end end
else else
if terrain_C < 0 and math.random(1,7) == 1 then --less dense trees if terrain_C < 0 and math.random(1,7) == 1 then --less dense trees
local treenum = math.random(3,5) local treenum = math.random(3,5)
if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then
surface.create_entity {name=tree_to_place[treenum], position={x,y}} surface.create_entity {name=tree_to_place[treenum], position={x,y}}
end end
end end
@ -127,55 +130,55 @@ function run_terrain_module(event)
else else
if terrain_D < 30 then if terrain_D < 30 then
tile_to_insert = "sand" tile_to_insert = "sand"
if terrain_C < -20 and math.random(1,7) == 1 then --dense trees if terrain_C < -20 and math.random(1,7) == 1 then --dense trees
local treenum = math.random(1,3) local treenum = math.random(1,3)
if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then
surface.create_entity {name=tree_to_place[treenum], position={x,y}} surface.create_entity {name=tree_to_place[treenum], position={x,y}}
end end
elseif terrain_C < 0 and math.random(1,13) == 1 then --less dense trees elseif terrain_C < 0 and math.random(1,13) == 1 then --less dense trees
local treenum = math.random(1,2) local treenum = math.random(1,2)
if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then if surface.can_place_entity {name=tree_to_place[treenum], position={x,y}} then
surface.create_entity {name=tree_to_place[treenum], position={x,y}} surface.create_entity {name=tree_to_place[treenum], position={x,y}}
end end
end end
else else
tile_to_insert = "sand-dark" tile_to_insert = "sand-dark"
--if terrain_C > 40 and math.random(1,200) == 1 and surface.can_place_entity {name="crude-oil", position={pos_x,pos_y}} then --if terrain_C > 40 and math.random(1,200) == 1 and surface.can_place_entity {name="crude-oil", position={pos_x,pos_y}} then
-- surface.create_entity {name="crude-oil", position={pos_x,pos_y}, amount = math.random(20000,60000) +distance_bonus* 2000 } -- surface.create_entity {name="crude-oil", position={pos_x,pos_y}, amount = math.random(20000,60000) +distance_bonus* 2000 }
--end --end
end end
end end
if math.floor(terrain_D) % 5 == 1 and math.random(1,70) == 1 and surface.can_place_entity {name="stone-rock", position={x,y}} then if math.floor(terrain_D) % 5 == 1 and math.random(1,70) == 1 and surface.can_place_entity {name="stone-rock", position={x,y}} then
surface.create_entity {name="stone-rock", position={x,y}} surface.create_entity {name="stone-rock", position={x,y}}
end end
else
if terrain_D >= 20 then else
if terrain_D < 30 then
tile_to_insert = "sand" if terrain_D >= 20 then
if terrain_D < 30 then
tile_to_insert = "sand"
else else
tile_to_insert = "sand-dark" tile_to_insert = "sand-dark"
end end
end end
end end
--if tile_to_insert == "water" then --if tile_to_insert == "water" then
--table.insert(tileswater, {name = tile_to_insert, position = {x,y}}) --table.insert(tileswater, {name = tile_to_insert, position = {x,y}})
--else --else
table.insert(tiles, {name = tile_to_insert, position = {x,y}}) table.insert(tiles, {name = tile_to_insert, position = {x,y}})
--end --end
end end
end end
end end
--game.print("break end") --game.print("break end")
--game.print(lowest .. " to " .. highest) --game.print(lowest .. " to " .. highest)
surface.set_tiles(tiles,true) surface.set_tiles(tiles,true)
--surface.set_tiles(tileswater,true) --surface.set_tiles(tileswater,true)
end end

View File

@ -2,10 +2,6 @@
Neko Does stuff to key files because Im a derp Neko Does stuff to key files because Im a derp
--]] --]]
require "locale.gen_shared.perlin_noise"
perlin:load( )
require "locale.gen_shared.ent_functions"
require "locale.gen_shared.simplex_noise"
--shapes-- --shapes--
--require "locale.gen_shape.right" --require "locale.gen_shape.right"
@ -17,7 +13,7 @@ require "locale.gen_shared.simplex_noise"
--require "locale.gen_shape.donut" --require "locale.gen_shape.donut"
--terrain-- --terrain--
--require "locale.gen_terrain.neko_bridged_rivers" require "locale.gen_terrain.neko_bridged_rivers"
--ores-- --ores--
--require "locale.gen_ores.neko_crazy_ores" --require "locale.gen_ores.neko_crazy_ores"