1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-28 21:08:52 +02:00
RedMew/map_gen/presets/cookies.lua

112 lines
2.7 KiB
Lua
Raw Normal View History

2018-05-08 22:23:07 +02:00
local b = require "map_gen.shared.builders"
2018-03-27 17:15:43 +02:00
local seed1 = 666
local seed2 = 999
local function value(a, b)
return 1000000
end
local Random = require "map_gen.shared.random"
local random = Random.new(seed1, seed2)
local pic = require "map_gen.data.presets.cookie"
2018-05-08 22:23:07 +02:00
local pic = b.decompress(pic)
local cookie1 = b.picture(pic)
local cookie = b.scale(cookie1, 0.1, 0.1)
2018-03-27 17:15:43 +02:00
2018-05-08 22:23:07 +02:00
local ore_shape = b.circle(1.5)
2018-03-27 17:15:43 +02:00
local ores = {
2018-05-08 22:23:07 +02:00
{b.resource(ore_shape, "iron-ore", value), 24},
{b.resource(ore_shape, "copper-ore", value), 12},
{b.resource(ore_shape, "stone", value), 4},
{b.resource(ore_shape, "coal", value), 8},
{b.resource(ore_shape, "uranium-ore", value), 1},
{b.resource(b.circle(1), "crude-oil", b.manhattan_value(250000, 250)), 3},
--{b.empty_shape, 10}
2018-03-27 17:15:43 +02:00
}
local total_weights = {}
local t = 0
for _, v in pairs(ores) do
t = t + v[2]
table.insert(total_weights, t)
end
local function makeChips()
local n = random:next_int(1, t)
local index = table.binary_search(total_weights, n)
if (index < 0) then
index = bit32.bnot(index)
end
local shape = ores[index][1]
2018-05-08 22:23:07 +02:00
if shape == b.empty_shape then
2018-03-27 17:15:43 +02:00
return nil
end
local chips = {}
for i = 1, 6 do
local x_offset = random:next_int(-20, 20)
local y_offset = random:next_int(-20, 20)
2018-05-08 22:23:07 +02:00
local shape2 = b.translate(shape, x_offset, y_offset)
2018-03-27 17:15:43 +02:00
table.insert(chips, shape2)
end
return chips
end
local p_cols = 50
local p_rows = 50
local pattern = {}
for c = 1, p_cols do
local row = {}
table.insert(pattern, row)
for r = 1, p_rows do
local chips = makeChips()
local shape
if chips then
2018-05-08 22:23:07 +02:00
shape = b.apply_entity(cookie, b.any(chips))
2018-03-27 17:15:43 +02:00
else
shape = cookie
end
local angle = random:next_int(-30, 30)
local s = random:next() * .25 + 1
local x_offset = random:next_int(-8, 8)
local y_offset = random:next_int(-8, 8)
2018-05-08 22:23:07 +02:00
shape = b.rotate(shape, degrees(angle))
shape = b.scale(shape, s, s * 0.75)
shape = b.translate(shape, x_offset, y_offset)
2018-03-27 17:15:43 +02:00
table.insert(row, shape)
end
end
2018-05-08 22:23:07 +02:00
local cookies = b.grid_pattern_full_overlap(pattern, p_cols, p_rows, 64 * 1.25, 41 * 1.25 * 0.5)
cookies = b.flip_y(cookies)
2018-03-27 17:15:43 +02:00
local tablecloth = {
height = 2,
width = 2,
data = {
{"concrete", "water"},
{"water", "deepwater", }
}
}
2018-05-08 22:23:07 +02:00
local tablecloth = b.picture(tablecloth)
tablecloth = b.single_pattern(tablecloth, 2, 2)
tablecloth = b.scale(tablecloth, 42, 42)
tablecloth = b.fish(tablecloth, 0.005)
2018-03-27 17:15:43 +02:00
2018-05-08 22:23:07 +02:00
map = b.if_else(cookies, tablecloth)
2018-03-27 17:15:43 +02:00
return map