mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
removed some math.sqrt
This commit is contained in:
parent
a8e883b8ec
commit
be8ab3d42f
@ -82,9 +82,9 @@ return function(x, y)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
local name
|
local name
|
||||||
if d < 200 then
|
if d_sq < 40000 then
|
||||||
name = 'car'
|
name = 'car'
|
||||||
else
|
else
|
||||||
if math.random(10) == 1 then
|
if math.random(10) == 1 then
|
||||||
|
@ -17,8 +17,8 @@ end
|
|||||||
Event.on_init(run_ores_module_setup)
|
Event.on_init(run_ores_module_setup)
|
||||||
|
|
||||||
return function(x, y, world)
|
return function(x, y, world)
|
||||||
local d = math.sqrt(world.x * world.x + world.y * world.y)
|
local d_sq = world.x * world.x + world.y * world.y
|
||||||
if d < 96 then
|
if d_sq < 9216 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ end
|
|||||||
Event.on_init(init)
|
Event.on_init(init)
|
||||||
|
|
||||||
local radius = 10
|
local radius = 10
|
||||||
|
local radius_sq = radius * radius
|
||||||
|
|
||||||
return function(x, y, world)
|
return function(x, y, world)
|
||||||
local entities = world.surface.find_entities_filtered {position = {world.x + 0.5, world.y + 0.5}, type = "resource"}
|
local entities = world.surface.find_entities_filtered {position = {world.x + 0.5, world.y + 0.5}, type = "resource"}
|
||||||
@ -38,9 +39,9 @@ return function(x, y, world)
|
|||||||
|
|
||||||
local x = world.x - world.top_x - 16
|
local x = world.x - world.top_x - 16
|
||||||
local y = world.y - world.top_y - 16
|
local y = world.y - world.top_y - 16
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
|
|
||||||
if d < radius then
|
if d_sq < radius_sq then
|
||||||
local ore_spawn = world.ore_spawn
|
local ore_spawn = world.ore_spawn
|
||||||
local resource_amount = world.resource_amount
|
local resource_amount = world.resource_amount
|
||||||
|
|
||||||
@ -49,9 +50,9 @@ return function(x, y, world)
|
|||||||
amount = world.oil_amount
|
amount = world.oil_amount
|
||||||
else
|
else
|
||||||
amount = resource_amount
|
amount = resource_amount
|
||||||
if d < radius / 2 then
|
if d_sq < radius_sq / 4 then
|
||||||
amount = resource_amount * 1.5
|
amount = resource_amount * 1.5
|
||||||
elseif d < radius / 3 then
|
elseif d_sq < radius_sq / 9 then
|
||||||
amount = resource_amount * 2
|
amount = resource_amount * 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,8 +20,8 @@ Global.register_init(
|
|||||||
|
|
||||||
local function value(base, mult, pow)
|
local function value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d ^ (pow / 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -392,12 +392,12 @@ local function init()
|
|||||||
|
|
||||||
local function enemy(x, y, world)
|
local function enemy(x, y, world)
|
||||||
local wx, wy = world.x, world.y
|
local wx, wy = world.x, world.y
|
||||||
local d = math.sqrt(wx * wx + wy * wy)
|
local d_sq = wx * wx + wy * wy
|
||||||
|
|
||||||
--[[ if Perlin.noise(x * scale_factor, y * scale_factor, enemy_seed) < 0 then
|
--[[ if Perlin.noise(x * scale_factor, y * scale_factor, enemy_seed) < 0 then
|
||||||
return nil
|
return nil
|
||||||
end ]]
|
end ]]
|
||||||
local spawner_chance = d - 128
|
local spawner_chance = d_sq - 16384 --d - 128
|
||||||
|
|
||||||
if spawner_chance > 0 then
|
if spawner_chance > 0 then
|
||||||
spawner_chance = spawner_chance * spawner_chance_factor
|
spawner_chance = spawner_chance * spawner_chance_factor
|
||||||
@ -408,26 +408,26 @@ local function init()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local worm_chance = d - 128
|
local worm_chance = d_sq - 16384 --d - 128
|
||||||
|
|
||||||
if worm_chance > 0 then
|
if worm_chance > 0 then
|
||||||
worm_chance = worm_chance * worm_chance_factor
|
worm_chance = worm_chance * worm_chance_factor
|
||||||
worm_chance = math.min(worm_chance, max_worm_chance)
|
worm_chance = math.min(worm_chance, max_worm_chance)
|
||||||
|
|
||||||
if math.random() < worm_chance then
|
if math.random() < worm_chance then
|
||||||
if d < 256 then
|
if d_sq < 65536 then --d < 256
|
||||||
return {name = 'small-worm-turret'}
|
return {name = 'small-worm-turret'}
|
||||||
else
|
else
|
||||||
local max_lvl
|
local max_lvl
|
||||||
local min_lvl
|
local min_lvl
|
||||||
if d < 512 then
|
if d_sq < 262144 then --d < 512
|
||||||
max_lvl = 2
|
max_lvl = 2
|
||||||
min_lvl = 1
|
min_lvl = 1
|
||||||
else
|
else
|
||||||
max_lvl = 3
|
max_lvl = 3
|
||||||
min_lvl = 2
|
min_lvl = 2
|
||||||
end
|
end
|
||||||
local lvl = math.random() ^ (384 / d) * max_lvl
|
local lvl = math.random() ^ (147456 / d_sq) * max_lvl --384 / d
|
||||||
lvl = math.ceil(lvl)
|
lvl = math.ceil(lvl)
|
||||||
--local lvl = math.floor(d / 256) + 1
|
--local lvl = math.floor(d / 256) + 1
|
||||||
lvl = math.clamp(lvl, min_lvl, 3)
|
lvl = math.clamp(lvl, min_lvl, 3)
|
||||||
@ -442,8 +442,8 @@ local function init()
|
|||||||
local ores_patch = b.circle(16)
|
local ores_patch = b.circle(16)
|
||||||
local function value(base, mult, pow)
|
local function value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d_sq ^ (pow / 2) -- d^pow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ local seed2 = seed1 * 2
|
|||||||
|
|
||||||
local function value(base, mult, pow)
|
local function value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d_sq ^ (pow / 2) -- d ^ pow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ local ore_spider = b.scale(spider, 0.125, 0.125)
|
|||||||
|
|
||||||
local function value(base, mult, pow)
|
local function value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d_sq ^ ( pow / 2 ) -- d ^ pow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ local ball_shape = b.any {ball, line1, line2}
|
|||||||
|
|
||||||
local function value(base, mult, pow)
|
local function value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d_sq ^ ( pow / 2 ) -- d ^ pow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local ore_shape = b.circle(5)
|
local ore_shape = b.circle(5)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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 math = require "utils.math"
|
||||||
|
|
||||||
local seed1 = 17000
|
local seed1 = 17000
|
||||||
local seed2 = seed1 * 2
|
local seed2 = seed1 * 2
|
||||||
@ -97,8 +98,6 @@ end
|
|||||||
|
|
||||||
local map_ores = do_resources()
|
local map_ores = do_resources()
|
||||||
|
|
||||||
local root2 = math.sqrt(2)
|
|
||||||
|
|
||||||
local big_circle = b.circle(150)
|
local big_circle = b.circle(150)
|
||||||
local small_circle = b.circle(140)
|
local small_circle = b.circle(140)
|
||||||
local crop = b.rectangle(300, 150)
|
local crop = b.rectangle(300, 150)
|
||||||
@ -121,8 +120,9 @@ local function h_arc()
|
|||||||
return b.any {arc, ball1, ball2, ball3, arm1, arm2, arm3}
|
return b.any {arc, ball1, ball2, ball3, arm1, arm2, arm3}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local div_100_sqrt2 = 100 / math.sqrt2
|
||||||
local function v_arc()
|
local function v_arc()
|
||||||
local circle = b.circle(100 / root2)
|
local circle = b.circle(div_100_sqrt2)
|
||||||
circle = b.apply_entity(circle, map_ores)
|
circle = b.apply_entity(circle, map_ores)
|
||||||
local ball1 = b.translate(circle, -0, 385)
|
local ball1 = b.translate(circle, -0, 385)
|
||||||
local ball2 = b.translate(circle, -460, 345)
|
local ball2 = b.translate(circle, -460, 345)
|
||||||
@ -140,7 +140,7 @@ arc1 = b.single_pattern(arc1, 1380, 1380)
|
|||||||
local arc2 = v_arc()
|
local arc2 = v_arc()
|
||||||
arc2 = b.single_pattern(arc2, 1380, 1380)
|
arc2 = b.single_pattern(arc2, 1380, 1380)
|
||||||
arc2 = b.rotate(arc2, degrees(45))
|
arc2 = b.rotate(arc2, degrees(45))
|
||||||
arc2 = b.scale(arc2, root2, root2)
|
arc2 = b.scale(arc2, math.sqrt2, math.sqrt2)
|
||||||
arc2 = b.translate(arc2, -165, -688)
|
arc2 = b.translate(arc2, -165, -688)
|
||||||
|
|
||||||
local map = b.any {arc1, arc2}
|
local map = b.any {arc1, arc2}
|
||||||
|
@ -65,7 +65,7 @@ local function effect(x, y, world, tile)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
||||||
if max_axis_distance(world_x, world_y, -2144, 0) < safe_distance then
|
if max_axis_distance(world_x, world_y, -2144, 0) < safe_distance then
|
||||||
for _, e in ipairs(surface.find_entities_filtered({ force = "enemy", position = { world_x, world_y } } )) do
|
for _, e in ipairs(surface.find_entities_filtered({ force = "enemy", position = { world_x, world_y } } )) do
|
||||||
e.destroy()
|
e.destroy()
|
||||||
@ -75,12 +75,12 @@ local function effect(x, y, world, tile)
|
|||||||
e.destroy()
|
e.destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, e in ipairs(surface.find_entities_filtered({ type = "resource", area = {{world_x, world_y }, {world_x + 1, world_y + 1 } } })) do -- I want to use position but for some reason it doesn't seem to work for ores.
|
for _, e in ipairs(surface.find_entities_filtered({ type = "resource", area = {{world_x, world_y }, {world_x + 1, world_y + 1 } } })) do -- I want to use position but for some reason it doesn't seem to work for ores.
|
||||||
local dist1 = distance(world_x, world_y, -2144, 0)
|
local dist1 = distance(world_x, world_y, -2144, 0)
|
||||||
local dist2 = distance(world_x, world_y, 2144, 0)
|
local dist2 = distance(world_x, world_y, 2144, 0)
|
||||||
local amount = math.min(dist1, dist2)
|
local amount = math.min(dist1, dist2)
|
||||||
|
|
||||||
local name = e.name
|
local name = e.name
|
||||||
if name == "iron-ore" then
|
if name == "iron-ore" then
|
||||||
amount = 800 + 0.4 * amount
|
amount = 800 + 0.4 * amount
|
||||||
@ -95,10 +95,10 @@ local function effect(x, y, world, tile)
|
|||||||
elseif name == "crude-oil" then
|
elseif name == "crude-oil" then
|
||||||
amount = 50000 + 50 * amount
|
amount = 50000 + 50 * amount
|
||||||
end
|
end
|
||||||
|
|
||||||
e.amount = amount
|
e.amount = amount
|
||||||
end
|
end
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
return tile
|
return tile
|
||||||
end
|
end
|
||||||
|
@ -16,8 +16,8 @@ map = b.scale(map, 64)
|
|||||||
|
|
||||||
local function value(base, mult, pow)
|
local function value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d_sq ^ (pow / 2) --d ^ pow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -277,9 +277,9 @@ local function loot(x, y)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
local name
|
local name
|
||||||
if d < 600 then
|
if d_sq < 360000 then --d < 600
|
||||||
name = 'car'
|
name = 'car'
|
||||||
else
|
else
|
||||||
if math.random(5) == 1 then
|
if math.random(5) == 1 then
|
||||||
|
@ -63,24 +63,26 @@ local function sprinkle(shape)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function radial(shape, radius)
|
local function radial(shape, radius)
|
||||||
local stone_r = radius * 0.55
|
local radius_sq = radius * radius
|
||||||
local coal_r = radius * 0.65
|
local stone_r_sq = radius * 0.3025 -- radius * 0.55
|
||||||
local copper_r = radius * 0.8
|
local coal_r_sq = radius * 0.4225 -- radius * 0.65
|
||||||
|
local copper_r_sq = radius * 0.64 -- radius * 0.8
|
||||||
|
|
||||||
return function(x, y, world)
|
return function(x, y, world)
|
||||||
if not shape(x, y) then
|
if not shape(x, y) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
|
|
||||||
local ore
|
local ore
|
||||||
if d < stone_r then
|
if d_sq < stone_r_sq then
|
||||||
ore = ores[4]
|
ore = ores[4]
|
||||||
elseif d < coal_r then
|
elseif d_sq < coal_r_sq then
|
||||||
ore = ores[3]
|
ore = ores[3]
|
||||||
elseif d < copper_r then
|
elseif d_sq < copper_r_sq then
|
||||||
ore = ores[2]
|
ore = ores[2]
|
||||||
else
|
else
|
||||||
ore = ores[1]
|
ore = ores[1]
|
||||||
|
@ -4,8 +4,8 @@ local inv_pi = 1 / math.pi
|
|||||||
local thickness2 = thickness * 2
|
local thickness2 = thickness * 2
|
||||||
|
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
if d < 128 then
|
if d_sq < 16384 then --d < 128
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1435,8 +1435,8 @@ end
|
|||||||
|
|
||||||
function Builders.exponential_value(base, mult, pow)
|
function Builders.exponential_value(base, mult, pow)
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local d = math.sqrt(x * x + y * y)
|
local d_sq = x * x + y * y
|
||||||
return base + mult * d ^ pow
|
return base + mult * d_sq ^ (pow / 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,16 +38,16 @@ local function dot(g, ...)
|
|||||||
return sum
|
return sum
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local F2 = 0.5*(math.sqrt(3.0)-1.0)
|
||||||
|
local G2 = (3.0-math.sqrt(3.0))/6.0
|
||||||
function Simplex.d2(xin, yin,seed)
|
function Simplex.d2(xin, yin,seed)
|
||||||
xin = xin + seed
|
xin = xin + seed
|
||||||
yin = yin + seed
|
yin = yin + seed
|
||||||
local n0, n1, n2 -- Noise contributions from the three corners
|
local n0, n1, n2 -- Noise contributions from the three corners
|
||||||
-- Skew the input space to determine which simplex cell we're in
|
-- Skew the input space to determine which simplex cell we're in
|
||||||
local F2 = 0.5*(math.sqrt(3.0)-1.0)
|
|
||||||
local s = (xin+yin)*F2; -- Hairy factor for 2D
|
local s = (xin+yin)*F2; -- Hairy factor for 2D
|
||||||
local i = math.floor(xin+s)
|
local i = math.floor(xin+s)
|
||||||
local j = math.floor(yin+s)
|
local j = math.floor(yin+s)
|
||||||
local G2 = (3.0-math.sqrt(3.0))/6.0
|
|
||||||
local t = (i+j)*G2
|
local t = (i+j)*G2
|
||||||
local X0 = i-t -- Unskew the cell origin back to (x,y) space
|
local X0 = i-t -- Unskew the cell origin back to (x,y) space
|
||||||
local Y0 = j-t
|
local Y0 = j-t
|
||||||
@ -103,4 +103,4 @@ function Simplex.d2(xin, yin,seed)
|
|||||||
return 70.0 * (n0 + n1 + n2)
|
return 70.0 * (n0 + n1 + n2)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Simplex
|
return Simplex
|
||||||
|
@ -3,8 +3,7 @@ local Game = require 'utils.game'
|
|||||||
|
|
||||||
local mines_factor = 1
|
local mines_factor = 1
|
||||||
|
|
||||||
--Do not change this:
|
mines_factor_sq = 16384 * 16384 / mines_factor / mines_factor
|
||||||
mines_factor = 16384 / mines_factor
|
|
||||||
|
|
||||||
local death_messages = {
|
local death_messages = {
|
||||||
"went exploring, and didn't bring a minesweeping kit.",
|
"went exploring, and didn't bring a minesweeping kit.",
|
||||||
@ -47,13 +46,13 @@ end
|
|||||||
Event.add(defines.events.on_player_died, player_died)
|
Event.add(defines.events.on_player_died, player_died)
|
||||||
|
|
||||||
return function(x, y)
|
return function(x, y)
|
||||||
local distance = math.sqrt(x * x + y * y)
|
local distance_sq = x * x + y * y
|
||||||
|
|
||||||
if distance <= 210 then
|
if distance_sq <= 44100 then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local chance = math.floor(mines_factor / distance) + 1
|
local chance = math.floor(mines_factor_sq / distance_sq) + 1
|
||||||
|
|
||||||
if math.random(chance) == 1 then
|
if math.random(chance) == 1 then
|
||||||
return {name = 'land-mine', force = 'enemy'}
|
return {name = 'land-mine', force = 'enemy'}
|
||||||
|
Loading…
Reference in New Issue
Block a user