1
0
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:
Maik Wild 2018-10-02 21:58:22 +02:00
parent a8e883b8ec
commit be8ab3d42f
17 changed files with 58 additions and 56 deletions

View File

@ -82,9 +82,9 @@ return function(x, y)
return nil
end
local d = math.sqrt(x * x + y * y)
local d_sq = x * x + y * y
local name
if d < 200 then
if d_sq < 40000 then
name = 'car'
else
if math.random(10) == 1 then

View File

@ -17,8 +17,8 @@ end
Event.on_init(run_ores_module_setup)
return function(x, y, world)
local d = math.sqrt(world.x * world.x + world.y * world.y)
if d < 96 then
local d_sq = world.x * world.x + world.y * world.y
if d_sq < 9216 then
return
end

View File

@ -9,6 +9,7 @@ end
Event.on_init(init)
local radius = 10
local radius_sq = radius * radius
return function(x, y, world)
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 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 resource_amount = world.resource_amount
@ -49,9 +50,9 @@ return function(x, y, world)
amount = world.oil_amount
else
amount = resource_amount
if d < radius / 2 then
if d_sq < radius_sq / 4 then
amount = resource_amount * 1.5
elseif d < radius / 3 then
elseif d_sq < radius_sq / 9 then
amount = resource_amount * 2
end
end

View File

@ -20,8 +20,8 @@ Global.register_init(
local function value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d ^ (pow / 2)
end
end

View File

@ -392,12 +392,12 @@ local function init()
local function enemy(x, y, world)
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
return nil
end ]]
local spawner_chance = d - 128
local spawner_chance = d_sq - 16384 --d - 128
if spawner_chance > 0 then
spawner_chance = spawner_chance * spawner_chance_factor
@ -408,26 +408,26 @@ local function init()
end
end
local worm_chance = d - 128
local worm_chance = d_sq - 16384 --d - 128
if worm_chance > 0 then
worm_chance = worm_chance * worm_chance_factor
worm_chance = math.min(worm_chance, max_worm_chance)
if math.random() < worm_chance then
if d < 256 then
if d_sq < 65536 then --d < 256
return {name = 'small-worm-turret'}
else
local max_lvl
local min_lvl
if d < 512 then
if d_sq < 262144 then --d < 512
max_lvl = 2
min_lvl = 1
else
max_lvl = 3
min_lvl = 2
end
local lvl = math.random() ^ (384 / d) * max_lvl
local lvl = math.random() ^ (147456 / d_sq) * max_lvl --384 / d
lvl = math.ceil(lvl)
--local lvl = math.floor(d / 256) + 1
lvl = math.clamp(lvl, min_lvl, 3)
@ -442,8 +442,8 @@ local function init()
local ores_patch = b.circle(16)
local function value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d_sq ^ (pow / 2) -- d^pow
end
end

View File

@ -11,8 +11,8 @@ local seed2 = seed1 * 2
local function value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d_sq ^ (pow / 2) -- d ^ pow
end
end

View File

@ -46,8 +46,8 @@ local ore_spider = b.scale(spider, 0.125, 0.125)
local function value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d_sq ^ ( pow / 2 ) -- d ^ pow
end
end

View File

@ -18,8 +18,8 @@ local ball_shape = b.any {ball, line1, line2}
local function value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d_sq ^ ( pow / 2 ) -- d ^ pow
end
end
local ore_shape = b.circle(5)

View File

@ -1,5 +1,6 @@
local b = require 'map_gen.shared.builders'
local Random = require 'map_gen.shared.random'
local math = require "utils.math"
local seed1 = 17000
local seed2 = seed1 * 2
@ -97,8 +98,6 @@ end
local map_ores = do_resources()
local root2 = math.sqrt(2)
local big_circle = b.circle(150)
local small_circle = b.circle(140)
local crop = b.rectangle(300, 150)
@ -121,8 +120,9 @@ local function h_arc()
return b.any {arc, ball1, ball2, ball3, arm1, arm2, arm3}
end
local div_100_sqrt2 = 100 / math.sqrt2
local function v_arc()
local circle = b.circle(100 / root2)
local circle = b.circle(div_100_sqrt2)
circle = b.apply_entity(circle, map_ores)
local ball1 = b.translate(circle, -0, 385)
local ball2 = b.translate(circle, -460, 345)
@ -140,7 +140,7 @@ arc1 = b.single_pattern(arc1, 1380, 1380)
local arc2 = v_arc()
arc2 = b.single_pattern(arc2, 1380, 1380)
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)
local map = b.any {arc1, arc2}

View File

@ -65,7 +65,7 @@ local function effect(x, y, world, tile)
end
--[[
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
e.destroy()
@ -75,12 +75,12 @@ local function effect(x, y, world, tile)
e.destroy()
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.
local dist1 = distance(world_x, world_y, -2144, 0)
local dist2 = distance(world_x, world_y, 2144, 0)
local amount = math.min(dist1, dist2)
local name = e.name
if name == "iron-ore" then
amount = 800 + 0.4 * amount
@ -95,10 +95,10 @@ local function effect(x, y, world, tile)
elseif name == "crude-oil" then
amount = 50000 + 50 * amount
end
e.amount = amount
end
--]]
return tile
end

View File

@ -16,8 +16,8 @@ map = b.scale(map, 64)
local function value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d_sq ^ (pow / 2) --d ^ pow
end
end

View File

@ -277,9 +277,9 @@ local function loot(x, y)
return nil
end
local d = math.sqrt(x * x + y * y)
local d_sq = x * x + y * y
local name
if d < 600 then
if d_sq < 360000 then --d < 600
name = 'car'
else
if math.random(5) == 1 then

View File

@ -63,24 +63,26 @@ local function sprinkle(shape)
end
end
local function radial(shape, radius)
local stone_r = radius * 0.55
local coal_r = radius * 0.65
local copper_r = radius * 0.8
local radius_sq = radius * radius
local stone_r_sq = radius * 0.3025 -- radius * 0.55
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)
if not shape(x, y) then
return nil
end
local d = math.sqrt(x * x + y * y)
local d_sq = x * x + y * y
local ore
if d < stone_r then
if d_sq < stone_r_sq then
ore = ores[4]
elseif d < coal_r then
elseif d_sq < coal_r_sq then
ore = ores[3]
elseif d < copper_r then
elseif d_sq < copper_r_sq then
ore = ores[2]
else
ore = ores[1]

View File

@ -4,8 +4,8 @@ local inv_pi = 1 / math.pi
local thickness2 = thickness * 2
return function(x, y)
local d = math.sqrt(x * x + y * y)
if d < 128 then
local d_sq = x * x + y * y
if d_sq < 16384 then --d < 128
return true
end

View File

@ -1435,8 +1435,8 @@ end
function Builders.exponential_value(base, mult, pow)
return function(x, y)
local d = math.sqrt(x * x + y * y)
return base + mult * d ^ pow
local d_sq = x * x + y * y
return base + mult * d_sq ^ (pow / 2)
end
end

View File

@ -38,16 +38,16 @@ local function dot(g, ...)
return sum
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)
xin = xin + seed
yin = yin + seed
local n0, n1, n2 -- Noise contributions from the three corners
-- 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 i = math.floor(xin+s)
local j = math.floor(yin+s)
local G2 = (3.0-math.sqrt(3.0))/6.0
local t = (i+j)*G2
local X0 = i-t -- Unskew the cell origin back to (x,y) space
local Y0 = j-t
@ -103,4 +103,4 @@ function Simplex.d2(xin, yin,seed)
return 70.0 * (n0 + n1 + n2)
end
return Simplex
return Simplex

View File

@ -3,8 +3,7 @@ local Game = require 'utils.game'
local mines_factor = 1
--Do not change this:
mines_factor = 16384 / mines_factor
mines_factor_sq = 16384 * 16384 / mines_factor / mines_factor
local death_messages = {
"went exploring, and didn't bring a minesweeping kit.",
@ -47,13 +46,13 @@ end
Event.add(defines.events.on_player_died, player_died)
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
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
return {name = 'land-mine', force = 'enemy'}