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

Merge pull request #683 from Refactorio/pr/675

Formatting cleanup, localize insert
This commit is contained in:
Matthew 2019-01-24 18:10:36 -05:00 committed by GitHub
commit a3515da216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,18 +1,24 @@
-- Dependencies
local b = require 'map_gen.shared.builders' local b = require 'map_gen.shared.builders'
local Random = require 'map_gen.shared.random' local Random = require 'map_gen.shared.random'
local table = require "utils.table" local table = require 'utils.table'
local ore_seed1 = 9000
local ore_seed2 = ore_seed1 * 2
local Event = require 'utils.event' local Event = require 'utils.event'
-- Setup surface and map settings
local RS = require 'map_gen.shared.redmew_surface' local RS = require 'map_gen.shared.redmew_surface'
local MGSP = require 'resources.map_gen_settings' local MGSP = require 'resources.map_gen_settings'
-- Localized functions
local insert = table.insert
-- Local vars
local ore_seed1 = 9000
local ore_seed2 = ore_seed1 * 2
-- Setup surface and map settings
RS.set_map_gen_settings( RS.set_map_gen_settings(
{ {
MGSP.ore_oil_none, MGSP.ore_oil_none,
MGSP.cliff_none, MGSP.cliff_none,
MGSP.grass_only, MGSP.grass_only
} }
) )
@ -36,36 +42,37 @@ hail_hydra.hydras = {
-- Create the Sierpinski carpet shape -- Create the Sierpinski carpet shape
local function grid(x, y) local function grid(x, y)
return not(x %3 <2 or y %3 <2) return not (x % 3 < 2 or y % 3 < 2)
end end
grid = b.translate(grid,2,2) grid = b.translate(grid, 2, 2)
local sierpinski = grid local sierpinski = grid
for i = 1, 10, 1 do for i = 1, 10, 1 do
sierpinski = b.any{ sierpinski =
b.any {
sierpinski, sierpinski,
b.scale(grid, 3^i,3^i) b.scale(grid, 3 ^ i, 3 ^ i)
} }
end end
local function quadrant(x, y) local function quadrant(x, y)
return not(x<0 or y >0) return not (x < 0 or y > 0)
end end
sierpinski = b.invert(sierpinski) sierpinski = b.invert(sierpinski)
sierpinski = b.choose(quadrant,sierpinski,b.empty_shape) -- Restricts the Sierpinski pattern to one quadrant of the map co-ordinate system. Comment line to have whole map sierpinski = b.choose(quadrant, sierpinski, b.empty_shape) -- Restricts the Sierpinski pattern to one quadrant of the map co-ordinate system. Comment line to have whole map
sierpinski= b.scale(sierpinski,10,10) -- Scale it up so it's playable sierpinski = b.scale(sierpinski, 10, 10) -- Scale it up so it's playable
-- Create a grid of tiles to make it look pretty. The sierpinski shape will be used as a mask to select some of these tiles. -- Create a grid of tiles to make it look pretty. The sierpinski shape will be used as a mask to select some of these tiles.
local tile1 = b.rectangle(10,10) local tile1 = b.rectangle(10, 10)
tile1 = b.change_tile(tile1, true, 'sand-1') tile1 = b.change_tile(tile1, true, 'sand-1')
local tile2 = b.rectangle(8,8) local tile2 = b.rectangle(8, 8)
tile2 = b.change_tile(tile2, true, 'grass-1') tile2 = b.change_tile(tile2, true, 'grass-1')
local tile = b.any{tile2, tile1} local tile = b.any {tile2, tile1}
local pattern = {{tile}} local pattern = {{tile}}
local tile_grid = b.grid_pattern(pattern,1,1,10,10) local tile_grid = b.grid_pattern(pattern, 1, 1, 10, 10)
tile_grid = b.translate(tile_grid,5,5) tile_grid = b.translate(tile_grid, 5, 5)
-- sets the ore value depending upon X, Y coordinate -- sets the ore value depending upon X, Y coordinate
local value = b.manhattan_value local value = b.manhattan_value
@ -90,7 +97,7 @@ end
local ores = { local ores = {
{transform = non_transform, resource = 'iron-ore', value = value(1000, 10), weight = 16}, {transform = non_transform, resource = 'iron-ore', value = value(1000, 10), weight = 16},
{transform = non_transform, resource = 'copper-ore', value = value(800, 10), weight = 10}, {transform = non_transform, resource = 'copper-ore', value = value(800, 10), weight = 10},
{transform = non_transform, resource = 'stone', value = value(500,10), weight = 3}, {transform = non_transform, resource = 'stone', value = value(500, 10), weight = 3},
{transform = non_transform, resource = 'coal', value = value(600, 10), weight = 5}, {transform = non_transform, resource = 'coal', value = value(600, 10), weight = 5},
{transform = uranium_transform, resource = 'uranium-ore', value = value(200, 10), weight = 3}, {transform = uranium_transform, resource = 'uranium-ore', value = value(200, 10), weight = 3},
{transform = oil_transform, resource = 'crude-oil', value = value(100000, 5000), weight = 6}, {transform = oil_transform, resource = 'crude-oil', value = value(100000, 5000), weight = 6},
@ -103,7 +110,7 @@ local total_weights = {}
local t = 0 local t = 0
for _, v in ipairs(ores) do for _, v in ipairs(ores) do
t = t + v.weight t = t + v.weight
table.insert(total_weights, t) insert(total_weights, t)
end end
local p_cols = 50 local p_cols = 50
@ -112,9 +119,9 @@ local ore_pattern = {}
for _ = 1, p_rows do for _ = 1, p_rows do
local row = {} local row = {}
table.insert(ore_pattern, row) insert(ore_pattern, row)
for _ = 1, p_cols do for _ = 1, p_cols do
local shape = b.rectangle(2,2) local shape = b.rectangle(2, 2)
local i = random:next_int(1, t) local i = random:next_int(1, t)
local index = table.binary_search(total_weights, i) local index = table.binary_search(total_weights, i)
@ -126,27 +133,28 @@ for _ = 1, p_rows do
shape = ore_data.transform(shape) shape = ore_data.transform(shape)
local ore = b.resource(shape, ore_data.resource, ore_data.value) local ore = b.resource(shape, ore_data.resource, ore_data.value)
table.insert(row, ore) insert(row, ore)
end end
end end
local ore_shape = b.grid_pattern(ore_pattern, 50,50,10,10) local ore_shape = b.grid_pattern(ore_pattern, 50, 50, 10, 10)
-- Apply the Sierpinski carpet shape to the tiles as a mask -- Apply the Sierpinski carpet shape to the tiles as a mask
local map = b.choose(sierpinski,tile_grid,b.empty_shape) local map = b.choose(sierpinski, tile_grid, b.empty_shape)
map = b.translate(map,-5,5) map = b.translate(map, -5, 5)
-- Make a sea to place underneath the tiles to fill the voids. Gives players somewhere to get water for power -- Make a sea to place underneath the tiles to fill the voids. Gives players somewhere to get water for power
local sea = b.change_tile(b.full_shape, true, 'water') local sea = b.change_tile(b.full_shape, true, 'water')
sea = b.choose(quadrant,sea,b.empty_shape) sea = b.choose(quadrant, sea, b.empty_shape)
sea = b.fish(sea, 0.00125) sea = b.fish(sea, 0.00125)
map = b.any{map,sea} map = b.any {map, sea}
map = b.apply_entity(map,ore_shape) map = b.apply_entity(map, ore_shape)
local function on_init() local function on_init()
local player_force = game.forces.player local player_force = game.forces.player
player_force.technologies["landfill"].enabled = false -- disable landfill player_force.technologies['landfill'].enabled = false -- disable landfill
end end
Event.on_init(on_init) Event.on_init(on_init)
return map return map