Remove local functions.

This commit is contained in:
Duane 2016-06-14 02:18:21 -05:00
parent 3f0b5d08b2
commit e5cd050121
9 changed files with 157 additions and 209 deletions

180
abms.lua
View file

@ -10,26 +10,12 @@ local dps_count = hunger_delay
-- maximum number of mobs near player in fortresses
local fortress_mob_count = 5
local get_us_time = minetest.get_us_time
local floor = math.floor
local abs = math.abs
local max = math.max
local min = math.min
local rand = math.random
local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"}
local get_node_light = minetest.get_node_light
local remove_node = minetest.remove_node
local set_node = minetest.set_node
local get_node_or_nil = minetest.get_node_or_nil
local get_connected_players = minetest.get_connected_players
local find_nodes_in_area = minetest.find_nodes_in_area
local get_item_group = minetest.get_item_group
local find_nodes_in_area_under_air = minetest.find_nodes_in_area_under_air
local hunger_mod = minetest.get_modpath("hunger")
minetest.register_globalstep(function(dtime)
local time = get_us_time()
local time = minetest.get_us_time()
if last_dps_check and time - last_dps_check < dps_delay then
return
@ -40,13 +26,13 @@ minetest.register_globalstep(function(dtime)
if not mob.initial_promotion then
local pos = mob.object:getpos()
if mob.hp_max and mob.object and mob.health and mob.damage then
local factor = 1 + (max(abs(pos.x), abs(pos.y), abs(pos.z)) / 6200)
local factor = 1 + (math.max(math.abs(pos.x), math.abs(pos.y), math.abs(pos.z)) / 6200)
if fun_caves.is_fortress(pos) then
mob.started_in_fortress = true
factor = factor * 1.5
end
mob.hp_max = floor(mob.hp_max * factor)
mob.damage = floor(mob.damage * factor)
mob.hp_max = math.floor(mob.hp_max * factor)
mob.damage = math.floor(mob.damage * factor)
--print("Promoting "..mob.name..": "..mob.hp_max.." at "..pos.x..","..pos.y..","..pos.z)
mob.object:set_hp(mob.hp_max)
mob.health = mob.hp_max
@ -57,7 +43,7 @@ minetest.register_globalstep(function(dtime)
end
-- Spawn mobs in fortresses -- only when a player is near
local players = get_connected_players()
local players = minetest.get_connected_players()
for i = 1, #players do
local player = players[i]
local pos = player:getpos()
@ -69,7 +55,7 @@ minetest.register_globalstep(function(dtime)
for _, mob in pairs(minetest.luaentities) do
if mob.health and mob.started_in_fortress then
local dist = vector.subtract(pos, mob.object:getpos())
local dist2 = max(abs(dist.x), abs(dist.y * 5), abs(dist.z))
local dist2 = math.max(math.abs(dist.x), math.abs(dist.y * 5), math.abs(dist.z))
if dist2 < 30 then
--print(mob.name, dist.y)
mob_count = mob_count + 1
@ -81,11 +67,11 @@ minetest.register_globalstep(function(dtime)
end
if mob_count < fortress_mob_count then
local pos1, count = find_nodes_in_area_under_air({x=pos.x-30, y=pos.y-2, z=pos.z-30}, {x=pos.x+30, y=pos.y+2, z=pos.z+30}, {"group:fortress"})
local pos1, count = minetest.find_nodes_in_area_under_air({x=pos.x-30, y=pos.y-2, z=pos.z-30}, {x=pos.x+30, y=pos.y+2, z=pos.z+30}, {"group:fortress"})
if #pos1 > 0 then
local pos2 = pos1[rand(#pos1)]
local pos2 = pos1[math.random(#pos1)]
pos2.y = pos2.y + 2
local name = fun_caves.fortress_spawns[rand(#fun_caves.fortress_spawns)]
local name = fun_caves.fortress_spawns[math.random(#fun_caves.fortress_spawns)]
local mob = minetest.add_entity(pos2, name)
if mob then
print("Fun Caves: Spawned "..name.." at ("..pos2.x..","..pos2.y..","..pos2.z..")")
@ -102,19 +88,19 @@ minetest.register_globalstep(function(dtime)
return
else
-- Environmental damage from surfaces/hunger
local counts = find_nodes_in_area(minp, maxp, {"group:surface_hot"})
local counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_hot"})
if #counts > 1 then
player:set_hp(player:get_hp() - 1)
end
-- Environmental damage from surfaces/hunger
local counts = find_nodes_in_area(minp, maxp, {"group:poison"})
local counts = minetest.find_nodes_in_area(minp, maxp, {"group:poison"})
if #counts > 1 then
player:set_hp(player:get_hp() - 1)
end
if dps_count % cold_delay == 0 then
counts = find_nodes_in_area(minp, maxp, {"group:surface_cold"})
counts = minetest.find_nodes_in_area(minp, maxp, {"group:surface_cold"})
if #counts > 1 then
player:set_hp(player:get_hp() - 1)
end
@ -132,7 +118,7 @@ minetest.register_globalstep(function(dtime)
end
end
last_dps_check = get_us_time()
last_dps_check = minetest.get_us_time()
dps_count = dps_count - 1
end)
@ -148,21 +134,21 @@ minetest.register_abm({
return
end
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
local node_up = get_node_or_nil(pos_up)
local node_up = minetest.get_node_or_nil(pos_up)
if not node_up then
return
end
if node_up.name ~= "air" then
return
end
local node_under = get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
if not node_under then
return
end
if get_item_group(node_under.name, "soil") ~= 0 and
(get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"})
set_node(pos, {name = "fun_caves:giant_mushroom_stem"})
if minetest.get_item_group(node_under.name, "soil") ~= 0 and
(minetest.get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
minetest.set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"})
minetest.set_node(pos, {name = "fun_caves:giant_mushroom_stem"})
end
end
})
@ -173,30 +159,30 @@ minetest.register_abm({
interval = 500 * fun_caves.time_factor,
chance = 30,
action = function(pos, node)
if get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
set_node(pos, {name = "air"})
if minetest.get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
minetest.set_node(pos, {name = "air"})
return
end
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
local node_up = get_node_or_nil(pos_up)
local node_up = minetest.get_node_or_nil(pos_up)
if not node_up then
return
end
if node_up.name ~= "air" then
return
end
local node_under = get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
if not node_under or node_under.name ~= "fun_caves:giant_mushroom_stem" then
return
end
node_under = get_node_or_nil({x = pos.x, y = pos.y - 2, z = pos.z})
node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 2, z = pos.z})
if not node_under then
return
end
if get_item_group(node_under.name, "soil") ~= 0 and
(get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
set_node(pos_up, {name = "fun_caves:giant_mushroom_cap"})
set_node(pos, {name = "fun_caves:giant_mushroom_stem"})
if minetest.get_item_group(node_under.name, "soil") ~= 0 and
(minetest.get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
minetest.set_node(pos_up, {name = "fun_caves:giant_mushroom_cap"})
minetest.set_node(pos, {name = "fun_caves:giant_mushroom_stem"})
end
end
})
@ -208,15 +194,15 @@ minetest.register_abm({
chance = 10,
action = function(pos, node)
local pos_up = {x=pos.x,y=pos.y+1,z=pos.z}
local node_up = get_node_or_nil(pos_up)
local node_up = minetest.get_node_or_nil(pos_up)
if not node_up then
return
end
if node_up.name ~= "air" then
return
end
if (get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"})
if (minetest.get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
minetest.set_node(pos_up, {name = "fun_caves:huge_mushroom_cap"})
end
end
})
@ -227,20 +213,20 @@ minetest.register_abm({
interval = 15 * fun_caves.time_factor,
chance = 10,
action = function(pos, node)
if get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
set_node(pos, {name = "air"})
if minetest.get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
minetest.set_node(pos, {name = "air"})
return
end
local pos_down = pos
pos_down.y = pos_down.y - 1
local pos1, count = find_nodes_in_area_under_air(vector.subtract(pos_down, 4), vector.add(pos_down, 4), {"group:soil"})
local pos1, count = minetest.find_nodes_in_area_under_air(vector.subtract(pos_down, 4), vector.add(pos_down, 4), {"group:soil"})
if #pos1 < 1 then
return
end
local random = pos1[rand(1, #pos1)]
local random = pos1[math.random(1, #pos1)]
random.y = random.y + 1
if (get_node_light(random, nil) or 99) <= fun_caves.light_max then
set_node(random, {name = mushrooms[rand(#mushrooms)]})
if (minetest.get_node_light(random, nil) or 99) <= fun_caves.light_max then
minetest.set_node(random, {name = mushrooms[math.random(#mushrooms)]})
end
end
})
@ -297,10 +283,10 @@ minetest.register_abm({
end
local grow_pos = {x=pos.x, y=pos.y+1, z=pos.z}
local grow_node = get_node_or_nil(grow_pos)
local grow_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" then
if (get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
set_node(grow_pos, {name = mushrooms[rand(#mushrooms)]})
if (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
minetest.set_node(grow_pos, {name = mushrooms[math.random(#mushrooms)]})
return
end
end
@ -319,20 +305,20 @@ minetest.register_abm({
end
if spike_num < #fun_caves.hot_spikes then
set_node(pos, {name=fun_caves.hot_spikes[spike_num+1]})
minetest.set_node(pos, {name=fun_caves.hot_spikes[spike_num+1]})
return
end
local random = {
x = pos.x + rand(-2, 2),
y = pos.y + rand(-1, 1),
z = pos.z + rand(-2, 2)
x = pos.x + math.random(-2, 2),
y = pos.y + math.random(-1, 1),
z = pos.z + math.random(-2, 2)
}
local random_node = get_node_or_nil(random)
local random_node = minetest.get_node_or_nil(random)
if not random_node or (random_node.name ~= "air" and random_node.name ~= "default:lava_source" and random_node.name ~= "default:lava_flowing") then
return
end
local node_under = get_node_or_nil({x = random.x,
local node_under = minetest.get_node_or_nil({x = random.x,
y = random.y - 1, z = random.z})
if not node_under then
return
@ -341,7 +327,7 @@ minetest.register_abm({
--print("node_under ("..random.x..","..(random.y-1)..","..random.z.."): "..node_under.name)
if node_under.name == "fun_caves:hot_cobble" or node_under.name == "fun_caves:black_sand" then
--print("setting ("..random.x..","..random.y..","..random.z.."): "..node_under.name)
set_node(random, {name = hot_spikes[1]})
minetest.set_node(random, {name = hot_spikes[1]})
end
end
})
@ -388,35 +374,35 @@ minetest.register_abm({
chance = 10,
catch_up = false,
action = function(pos, node)
if get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
remove_node(pos)
if minetest.get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
minetest.remove_node(pos)
return
end
local grow_pos = {x=pos.x, y=pos.y-1, z=pos.z}
local grow_node = get_node_or_nil(grow_pos)
local grow_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" then
set_node(grow_pos, {name = node.name})
minetest.set_node(grow_pos, {name = node.name})
return
end
grow_pos = {x=rand(-1,1)+pos.x, y=rand(-1,1)+pos.y, z=rand(-1,1)+pos.z}
grow_node = get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" and get_node_light(grow_pos, nil) <= fun_caves.light_max then
set_node(grow_pos, {name = node.name})
grow_pos = {x=math.random(-1,1)+pos.x, y=math.random(-1,1)+pos.y, z=math.random(-1,1)+pos.z}
grow_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" and minetest.get_node_light(grow_pos, nil) <= fun_caves.light_max then
minetest.set_node(grow_pos, {name = node.name})
return
elseif grow_node and leaves[grow_node.name] and grow_node.name ~= node.name then
set_node(grow_pos, {name = 'air'})
minetest.set_node(grow_pos, {name = 'air'})
return
end
if rand(40) == 1 then
set_node(pos, {name = "fun_caves:fungal_tree_fruit"})
if math.random(40) == 1 then
minetest.set_node(pos, {name = "fun_caves:fungal_tree_fruit"})
return
end
if rand(100) == 1 then
set_node(pos, {name = fungal_tree_leaves[rand(#fungal_tree_leaves)]})
if math.random(100) == 1 then
minetest.set_node(pos, {name = fungal_tree_leaves[math.random(#fungal_tree_leaves)]})
return
end
end
@ -434,9 +420,9 @@ minetest.register_abm({
end
local grow_pos = {x=pos.x, y=pos.y+1, z=pos.z}
local grow_node = get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" and (get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
set_node(grow_pos, {name = fungal_tree_leaves[rand(#fungal_tree_leaves)]})
local grow_node = minetest.get_node_or_nil(grow_pos)
if grow_node and grow_node.name == "air" and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
minetest.set_node(grow_pos, {name = fungal_tree_leaves[math.random(#fungal_tree_leaves)]})
return
end
end
@ -492,15 +478,15 @@ local function destroy(pos, cid)
return
end
local new = "air"
--if rand(1,2) == 1 then
--if math.random(1,2) == 1 then
if true then
local node_under = get_node_or_nil({x = pos.x,
local node_under = minetest.get_node_or_nil({x = pos.x,
y = pos.y - 1, z = pos.z})
if node_under and node_under.name ~= "air" then
--new = node.name
end
end
set_node(pos, {name=new})
minetest.set_node(pos, {name=new})
end
local function explode(pos, radius)
@ -522,7 +508,7 @@ local function explode(pos, radius)
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
if (x * x) + (y * y / 4) + (z * z) <=
(radius * radius) + rand(-radius, radius) then
(radius * radius) + math.random(-radius, radius) then
local cid = data[vi]
p.x = pos.x + x
p.y = pos.y + y
@ -544,7 +530,7 @@ local function calc_velocity(pos1, pos2, old_vel, power)
-- Divide by distance
local dist = vector.distance(pos1, pos2)
dist = max(dist, 1)
dist = math.max(dist, 1)
vel = vector.divide(vel, dist)
-- Add old velocity
@ -559,7 +545,7 @@ local function entity_physics(pos, radius)
for _, obj in pairs(objs) do
local obj_pos = obj:getpos()
local obj_vel = obj:getvelocity()
local dist = max(1, vector.distance(pos, obj_pos))
local dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then
obj:setvelocity(calc_velocity(pos, obj_pos,
@ -576,14 +562,14 @@ fun_caves.soft_boom = function(pos)
return
end
local node = get_node_or_nil(pos)
local node = minetest.get_node_or_nil(pos)
if not node then
return
end
minetest.sound_play("tnt_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
local radius = 5
set_node(pos, {name="air"})
minetest.set_node(pos, {name="air"})
explode(pos, radius)
entity_physics(pos, radius)
add_effects(pos, radius)
@ -603,30 +589,30 @@ end
-- interval = 1 * fun_caves.time_factor,
-- chance = 50,
-- action = function(pos, node)
-- if get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
-- remove_node(pos)
-- if minetest.get_node_light(pos, nil) >= default.LIGHT_MAX - 2 then
-- minetest.remove_node(pos)
-- return
-- end
-- local random = {
-- x = pos.x + rand(-2, 2),
-- y = pos.y + rand(-1, 1),
-- z = pos.z + rand(-2, 2)
-- x = pos.x + math.random(-2, 2),
-- y = pos.y + math.random(-1, 1),
-- z = pos.z + math.random(-2, 2)
-- }
-- local random_node = get_node_or_nil(random)
-- local random_node = minetest.get_node_or_nil(random)
-- if not random_node or random_node.name ~= "air" then
-- return
-- end
-- local node_under = get_node_or_nil({x = random.x,
-- local node_under = minetest.get_node_or_nil({x = random.x,
-- y = random.y - 1, z = random.z})
-- if not node_under then
-- return
-- end
--
-- if (get_item_group(node_under.name, "soil") ~= 0 or
-- get_item_group(node_under.name, "tree") ~= 0) and
-- get_node_light(pos, 0.5) <= fun_caves.light_max and
-- get_node_light(random, 0.5) <= fun_caves.light_max then
-- set_node(random, {name = node.name})
-- if (minetest.get_item_group(node_under.name, "soil") ~= 0 or
-- minetest.get_item_group(node_under.name, "tree") ~= 0) and
-- minetest.get_node_light(pos, 0.5) <= fun_caves.light_max and
-- minetest.get_node_light(random, 0.5) <= fun_caves.light_max then
-- minetest.set_node(random, {name = node.name})
-- end
-- end
--})

View file

@ -7,9 +7,6 @@ local cave_noise_2 = {offset = 0, scale = 1, seed = -8402, spread = {x = 40, y =
local cave_noise_3 = {offset = 15, scale = 10, seed = 3721, spread = {x = 40, y = 40, z = 40}, octaves = 3, persist = 1, lacunarity = 2}
local rand = math.random
fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
local csize = vector.add(vector.subtract(maxp, minp), 1)
local map_max = {x = csize.x, y = csize.y + 2, z = csize.z}
@ -54,7 +51,7 @@ fun_caves.cavegen = function(minp, maxp, data, area, node, heightmap, underzone)
data[ivm] = node[underzone.column_node]
write = true
elseif underzone and underzone.column_node and not underzone.regular_columns and column == 2 then
if underzone.column_node_rare and rand(70) == 1 then
if underzone.column_node_rare and math.random(70) == 1 then
data[ivm] = node[underzone.column_node_rare]
else
data[ivm] = node[underzone.column_node]

View file

@ -1,11 +1,6 @@
dofile(fun_caves.path .. "/deco_clouds.lua")
local rand = math.random
local min = math.min
local floor = math.floor
local ceil = math.ceil
local abs = math.abs
local max_depth = 31000
@ -45,12 +40,12 @@ fun_caves.cloudgen = function(minp, maxp, data, p2data, area, node)
cloud = 'cloud'
end
cloud_1[index] = floor(cloud_1[index] + 0.5)
cloud_1[index] = math.floor(cloud_1[index] + 0.5)
for y = minp.y, maxp.y do
local dy = y - minp.y
if dy > 32 and cloud_1[index] > 15 and dy < 47 then
if dy < 48 - (cloud_1[index] - 15) then
if cloud == 'cloud' and rand(10000) == 1 then
if cloud == 'cloud' and math.random(10000) == 1 then
data[ivm] = node['fun_caves:silver_lining']
else
data[ivm] = node['fun_caves:'..cloud]
@ -60,24 +55,24 @@ fun_caves.cloudgen = function(minp, maxp, data, p2data, area, node)
write = true
end
elseif cloud_1[index] > 0 and (dy <= 32 or cloud_1[index] <= 15) and dy >= 32 - cloud_1[index] and dy <= 32 + cloud_1[index] then
if cloud == 'cloud' and rand(10000) == 1 then
if cloud == 'cloud' and math.random(10000) == 1 then
data[ivm] = node['fun_caves:silver_lining']
else
data[ivm] = node['fun_caves:'..cloud]
end
write = true
elseif data[ivm - area.ystride] == node['fun_caves:'..cloud] and data[ivm] == node['air'] then
if rand(30) == 1 and plant_n[index] > 0.5 then
if math.random(30) == 1 and plant_n[index] > 0.5 then
data[ivm] = node['fun_caves:moon_weed']
write = true
elseif rand(60) == 1 and plant_n[index] > 0.5 then
elseif math.random(60) == 1 and plant_n[index] > 0.5 then
fun_caves.place_schematic(minp, maxp, data, p2data, area, node, {x=x,y=y,z=z}, fun_caves.schematics['lumin_tree'], true)
write = true
elseif rand(10) == 1 then
data[ivm] = node['default:grass_'..rand(4)]
elseif math.random(10) == 1 then
data[ivm] = node['default:grass_'..math.random(4)]
write = true
end
elseif data[ivm] == node['air'] and (dy < 29 - cloud_1[index] or dy > 35 + cloud_1[index]) and cloud_2[index3d] > abs((dy - 40) / 20) then
elseif data[ivm] == node['air'] and (dy < 29 - cloud_1[index] or dy > 35 + cloud_1[index]) and cloud_2[index3d] > math.abs((dy - 40) / 20) then
data[ivm] = node['fun_caves:wispy_cloud']
write = true
end
@ -102,11 +97,11 @@ fun_caves.cloudgen = function(minp, maxp, data, p2data, area, node)
cloud = 'cloud'
end
cloud_1[index] = floor(cloud_1[index] + 0.5)
cloud_1[index] = math.floor(cloud_1[index] + 0.5)
if cloud_1[index] > 0 then
for y = minp.y, maxp.y do
local dy = y - minp.y
if data[ivm] == node['fun_caves:'..cloud] and data[ivm + area.ystride] == node['default:water_source'] and rand(30) == 1 and fun_caves.surround(node, data, area, ivm) then
if data[ivm] == node['fun_caves:'..cloud] and data[ivm + area.ystride] == node['default:water_source'] and math.random(30) == 1 and fun_caves.surround(node, data, area, ivm) then
data[ivm] = node['fun_caves:water_plant_1_water_'..cloud]
end

View file

@ -16,12 +16,6 @@ for _, i in pairs({"desert_ocean", "savanna_ocean", "rainforest_ocean", }) do
end
local rand = math.random
local max = math.max
local min = math.min
local log = math.log
local floor = math.floor
local find_nodes_in_area = minetest.find_nodes_in_area
local csize
local node_match_cache = {}
@ -46,9 +40,9 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
for i = 0, 10, 2 do
dis_map[i] = {}
for j = 0, 10, 2 do
dis_map[i][j] = rand(6)
dis_map[i][j] = math.random(6)
if dis_map[i][j] == 6 then
dis_map[i][j] = 5 + rand(10)
dis_map[i][j] = 5 + math.random(10)
end
end
end
@ -90,7 +84,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- Compress biomes at the surface to avoid fluids.
if y > fluid_compression then
biome_val = biome_val / max(1, log(y - fluid_compression))
biome_val = biome_val / math.max(1, math.log(y - fluid_compression))
end
for _, bi in pairs(fun_caves.cave_biomes) do
@ -123,7 +117,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
if data[ivm] == node["default:stone"] then
if node_above == node["air"] and biome and biome.dirt and rand(biome.dirt_chance) == 1 then
if node_above == node["air"] and biome and biome.dirt and math.random(biome.dirt_chance) == 1 then
data[ivm] = node[biome.dirt]
write = true
break
@ -137,7 +131,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
if air_above then
if biome and biome.deco and rand(biome.deco_chance) == 1 then
if biome and biome.deco and math.random(biome.deco_chance) == 1 then
data[ivm] = node[biome.deco]
write = true
break
@ -162,7 +156,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
if air_below then
if biome and biome.deco and rand(biome.deco_chance) == 1 then
if biome and biome.deco and math.random(biome.deco_chance) == 1 then
data[ivm] = node[biome.deco]
write = true
break
@ -175,7 +169,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
-- smallest city generator ever
if underzone and underzone.name == 'Dis' and data[ivm] == node['air'] and floor((x - minp.x) / 8) % 2 == 0 and floor((z - minp.z) / 8) % 2 == 0 and y - underzone.floor < dis_map[floor((x - minp.x) / 8)][floor((z - minp.z) / 8)] * 4 + 1 and y - underzone.floor >= 0 then
if underzone and underzone.name == 'Dis' and data[ivm] == node['air'] and math.floor((x - minp.x) / 8) % 2 == 0 and math.floor((z - minp.z) / 8) % 2 == 0 and y - underzone.floor < dis_map[math.floor((x - minp.x) / 8)][math.floor((z - minp.z) / 8)] * 4 + 1 and y - underzone.floor >= 0 then
local dx = (x - minp.x) % 16
local dy = y - underzone.floor + 1
local dz = (z - minp.z) % 16
@ -195,22 +189,22 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
if data[ivm] == node["air"] and y < maxp.y then
-- hanging down
-- stone hasn't yet been changed
if biome and biome.stalactite and node_above == node["default:stone"] and rand(biome.stalactite_chance) == 1 then
if biome and biome.stalactite and node_above == node["default:stone"] and math.random(biome.stalactite_chance) == 1 then
data[ivm] = node[biome.stalactite]
write = true
break
end
-- fluids
if y > minp.y and biome and biome.fluid and node_below == node[biome.floor_node] and rand(biome.fluid_chance) == 1 then
if y > minp.y and biome and biome.fluid and node_below == node[biome.floor_node] and math.random(biome.fluid_chance) == 1 then
data[ivm] = node[biome.fluid]
write = true
break
-- standing up
elseif node_below == node[biome.floor_node] and biome and biome.stalagmite and rand(biome.stalagmite_chance) == 1 then
elseif node_below == node[biome.floor_node] and biome and biome.stalagmite and math.random(biome.stalagmite_chance) == 1 then
if type(biome.stalagmite) == 'table' then
data[ivm] = node[biome.stalagmite[rand(#biome.stalagmite)]]
data[ivm] = node[biome.stalagmite[math.random(#biome.stalagmite)]]
else
data[ivm] = node[biome.stalagmite]
end
@ -219,11 +213,11 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- vegetation
elseif node_below == node["fun_caves:polluted_dirt"] then
if rand(10) == 1 then
if math.random(10) == 1 then
data[ivm] = node["default:dry_shrub"]
write = true
break
elseif rand(50) == 1 then
elseif math.random(50) == 1 then
local air_count = 0
local j
for i = 1, 9 do
@ -237,19 +231,19 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
end
elseif node_below == node["default:dirt"] and biome and biome.fungi then
if rand(10) == 1 then
if math.random(10) == 1 then
data[ivm] = node["flowers:mushroom_red"]
write = true
break
elseif rand(10) == 1 then
elseif math.random(10) == 1 then
data[ivm] = node["flowers:mushroom_brown"]
write = true
break
elseif node_above == node["air"] and rand(10) == 1 then
elseif node_above == node["air"] and math.random(10) == 1 then
data[ivm] = node["fun_caves:giant_mushroom_stem"]
write = true
break
elseif rand(30) == 1 then
elseif math.random(30) == 1 then
local air_count = 0
local j
for i = 1, 12 do
@ -259,7 +253,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
end
if air_count > 5 then
fun_caves.make_fungal_tree(data, area, ivm, rand(2, min(air_count, 12)))
fun_caves.make_fungal_tree(data, area, ivm, math.random(2, math.min(air_count, 12)))
end
end
elseif node_below == node["fun_caves:giant_mushroom_stem"] and data[ivm - area.ystride * 2] == node["fun_caves:giant_mushroom_stem"] then
@ -267,7 +261,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
write = true
break
elseif node_below == node["fun_caves:giant_mushroom_stem"] then
if node_above == node["air"] and rand(3) == 1 then
if node_above == node["air"] and math.random(3) == 1 then
data[ivm] = node["fun_caves:giant_mushroom_stem"]
write = true
break
@ -305,20 +299,20 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
local node_below = data[ivm - area.ystride]
local node_above = data[ivm + area.ystride]
if y < water_level and data[ivm] == node["default:sand"] and node_above == node["default:water_source"] and data[ivm + area.ystride * 2] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and rand(5) == 1 and fun_caves.surround(node, data, area, ivm) then
if rand(100) == 1 then
if y < water_level and data[ivm] == node["default:sand"] and node_above == node["default:water_source"] and data[ivm + area.ystride * 2] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math.random(5) == 1 and fun_caves.surround(node, data, area, ivm) then
if math.random(100) == 1 then
data[ivm] = node["fun_caves:precious_coral_water_sand"]
else
data[ivm] = node["fun_caves:staghorn_coral_water_sand"]
end
write = true
break
elseif y < water_level and node_below == node["default:sand"] and node_above == node["default:water_source"] and data[ivm] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and rand(5) < 3 then
if rand(15) == 1 then
elseif y < water_level and node_below == node["default:sand"] and node_above == node["default:water_source"] and data[ivm] == node["default:water_source"] and coral_biomes[biome] and pn < -0.1 and math.random(5) < 3 then
if math.random(15) == 1 then
data[ivm] = node["fun_caves:brain_coral"]
write = true
break
elseif rand(15) == 1 then
elseif math.random(15) == 1 then
data[ivm] = node["fun_caves:dragon_eye"]
write = true
break
@ -346,7 +340,7 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
-- against a given node (or nodes). However, it's slow.
-- To speed it up, we cache the results for each plant
-- on each node, and avoid calling find_nodes every time.
local posm, count = find_nodes_in_area({x=x, y=y, z=z}, {x=x, y=y, z=z}, desc.place_on)
local posm, count = minetest.find_nodes_in_area({x=x, y=y, z=z}, {x=x, y=y, z=z}, desc.place_on)
if #posm > 0 then
node_match_cache[desc.content_id][data[ivm]] = "good"
else
@ -354,14 +348,14 @@ fun_caves.decogen = function(minp, maxp, data, p2data, area, node, heightmap, bi
end
end
if node_match_cache[desc.content_id][data[ivm]] == "good" and desc.fill_ratio and (not desc.biomes or (biome and desc.biomes and table.contains(desc.biomes, biome))) and rand() <= desc.fill_ratio then
if node_match_cache[desc.content_id][data[ivm]] == "good" and desc.fill_ratio and (not desc.biomes or (biome and desc.biomes and table.contains(desc.biomes, biome))) and math.random() <= desc.fill_ratio then
data[ivm] = desc.content_id
write = true
break
end
end
end
elseif y > minp.y and node_below == node["default:river_water_source"] and data[ivm] == node["air"] and water_lily_biomes[biome] and pn > 0.5 and rand(water_lily_ratio) == 1 then
elseif y > minp.y and node_below == node["default:river_water_source"] and data[ivm] == node["air"] and water_lily_biomes[biome] and pn > 0.5 and math.random(water_lily_ratio) == 1 then
-- on top of the water
-- I haven't figured out what the decoration manager is
-- doing with the noise functions, but this works ok.

View file

@ -1,8 +1,4 @@
local rand = math.random
local floor = math.floor
local ceil = math.ceil
local max = math.max
local map_max = 31000
local max_depth = 31000
fun_caves.fortress = function(minp, maxp, data, area, node)
@ -13,7 +9,7 @@ fun_caves.fortress = function(minp, maxp, data, area, node)
-- hidden doors/downs
-- hot/ice floors
--
local level = max(6, ceil(maxp.y / floor(map_max / 6)))
local level = math.max(6, math.ceil(maxp.y / math.floor(max_depth / 6)))
local n = 16
local walls = {}
local inner_floor = node['fun_caves:dungeon_floor_1']
@ -29,7 +25,7 @@ fun_caves.fortress = function(minp, maxp, data, area, node)
end
table.shuffle(walls)
local dox, doz = rand(0, n-1), rand(0, n-1)
local dox, doz = math.random(0, n-1), math.random(0, n-1)
for z = minp.z, maxp.z do
for y = minp.y + y2 * 5, minp.y + y2 * 5 + 4 do
local ivm = area:index(minp.x, y, z)
@ -37,14 +33,14 @@ fun_caves.fortress = function(minp, maxp, data, area, node)
if x == minp.x or z == minp.z or x == maxp.x or z == maxp.z then
data[ivm] = outer_wall
elseif (y - minp.y) % 5 == 0 then
if floor((z - minp.z) / 5) == doz and floor((x - minp.x) / 5) == dox and (z - minp.z) % 5 ~= 0 and (x - minp.x) % 5 ~= 0 and y ~= minp.y then
if math.floor((z - minp.z) / 5) == doz and math.floor((x - minp.x) / 5) == dox and (z - minp.z) % 5 ~= 0 and (x - minp.x) % 5 ~= 0 and y ~= minp.y then
data[ivm] = node["air"]
else
data[ivm] = inner_floor
end
elseif (z - minp.z) % 5 == 0 or (x - minp.x) % 5 == 0 then
--data[ivm] = fun_caves.DEBUG and node["default:glass"] or inner_wall
if y2 == 0 and rand(3000) == 1 then
if y2 == 0 and math.random(3000) == 1 then
treasure_count = treasure_count + 1
data[ivm] = node['fun_caves:coffer']
else
@ -62,9 +58,9 @@ fun_caves.fortress = function(minp, maxp, data, area, node)
for m = 0, #walls do
local c = walls[m]
local a = floor(c / 2)
local a = math.floor(c / 2)
local i = a % n
local j = floor(a / n)
local j = math.floor(a / n)
local u = c % 2 == 0 and 1 or 0
local v = c % 2 == 1 and 1 or 0
local b = a + u + n * v
@ -73,7 +69,7 @@ fun_caves.fortress = function(minp, maxp, data, area, node)
local x = (i + u) * 5 + minp.x
local y = minp.y + y2 * 5
local z = (j + v) * 5 + minp.z
--if y > minp.y and rand(20) == 1 then
--if y > minp.y and math.random(20) == 1 then
-- for z1 = z + 1, z + 4 do
-- ivm = area:index(x+1, y, z1)
-- for x1 = x + 1, x + 4 do

View file

@ -2,9 +2,6 @@
-- Fungal Tree --
-------------------
local rand = math.random
local max = math.max
local colors = {}
colors["^[colorize:#FF00FF:60"] = "dye:violet"
colors["^[colorize:#0000FF:60"] = "dye:blue"
@ -42,7 +39,7 @@ minetest.register_node("fun_caves:fungal_tree_fruit", {
local fruit = minetest.get_content_id("fun_caves:fungal_tree_fruit")
function fun_caves.make_fungal_tree(data, area, ivm, height)
local leaf = minetest.get_content_id(fungal_tree_leaves[rand(#fungal_tree_leaves)])
local leaf = minetest.get_content_id(fungal_tree_leaves[math.random(#fungal_tree_leaves)])
local air = minetest.get_content_id('air')
for y = 0, height do
local radius = 1
@ -51,7 +48,7 @@ function fun_caves.make_fungal_tree(data, area, ivm, height)
end
for z = -radius,radius do
for x = -radius,radius do
local sr = rand(1,100)
local sr = math.random(1,100)
local i = ivm + z*area.zstride + y*area.ystride + x
if data[i] == air then
if x == 0 and y == 0 and z == 0 then

View file

@ -5,11 +5,6 @@ local seed_noise = {offset = 0, scale = 32768, seed = 5202, spread = {x = 80, y
local fortress_noise = {offset = 0, scale = 1, seed = -4082, spread = {x = 7, y = 7, z = 7}, octaves = 4, persist = 1, lacunarity = 2}
-- These may speed up function access.
local rand = math.random
local min = math.min
local floor = math.floor
-- This tables looks up nodes that aren't already stored.
local node = setmetatable({}, {
__index = function(t, k)
@ -33,7 +28,7 @@ end
-- if not deco.biomes or deco.biomes[biome] then
-- local range = 1000
-- if deco.deco_type == "simple" then
-- if deco.fill_ratio and rand(range) - 1 < deco.fill_ratio * 1000 then
-- if deco.fill_ratio and math.random(range) - 1 < deco.fill_ratio * 1000 then
-- return deco.decoration
-- end
-- else
@ -49,9 +44,9 @@ fun_caves.is_fortress = function(pos, cs, debug)
-- before any chunks are generated.
local cs = cs or {x=80, y=80, z=80}
local offset = floor(cs.y / 2) - 8 + 1
local offset = math.floor(cs.y / 2) - 8 + 1
local y = floor((pos.y + offset) / cs.y)
local y = math.floor((pos.y + offset) / cs.y)
-- Fortresses show up below ground.
-- Calls from the first dungeon level should return false.
@ -59,15 +54,15 @@ fun_caves.is_fortress = function(pos, cs, debug)
return false
end
local x = floor((pos.x + offset) / cs.x)
local z = floor((pos.z + offset) / cs.z)
local x = math.floor((pos.x + offset) / cs.x)
local z = math.floor((pos.z + offset) / cs.z)
local n = minetest.get_perlin(fortress_noise):get3d({x=x, y=y, z=z})
if fun_caves.DEBUG and floor((n * 10000) % 4) == 1 then
if fun_caves.DEBUG and math.floor((n * 10000) % 4) == 1 then
--print('fortress ('..x..','..y..','..z..')')
return true
end
if floor((n * 10000) % 19) == 1 then
if math.floor((n * 10000) % 19) == 1 then
return true
end
@ -75,7 +70,7 @@ fun_caves.is_fortress = function(pos, cs, debug)
end
fun_caves.place_schematic = function(minp, maxp, data, p2data, area, node, pos, schem, center)
local rot = rand(4) - 1
local rot = math.random(4) - 1
local yslice = {}
if schem.yslice_prob then
for _, ys in pairs(schem.yslice_prob) do
@ -84,8 +79,8 @@ fun_caves.place_schematic = function(minp, maxp, data, p2data, area, node, pos,
end
if center then
pos.x = pos.x - floor(schem.size.x / 2)
pos.z = pos.z - floor(schem.size.z / 2)
pos.x = pos.x - math.floor(schem.size.x / 2)
pos.z = pos.z - math.floor(schem.size.z / 2)
end
for z1 = 0, schem.size.z - 1 do
@ -108,9 +103,9 @@ fun_caves.place_schematic = function(minp, maxp, data, p2data, area, node, pos,
for y = 0, schem.size.y - 1 do
local dy = pos.y - minp.y + y
--if math.min(dx, csize.x - dx) + math.min(dy, csize.y - dy) + math.min(dz, csize.z - dz) > bevel then
if yslice[y] or 255 >= rand(255) then
if yslice[y] or 255 >= math.random(255) then
local prob = schem.data[isch].prob or schem.data[isch].param1 or 255
if prob >= rand(255) and schem.data[isch].name ~= "air" then
if prob >= math.random(255) and schem.data[isch].name ~= "air" then
data[ivm] = node[schem.data[isch].name]
end
local param2 = schem.data[isch].param2 or 0

View file

@ -1,8 +1,3 @@
local rand = math.random
local min = math.min
local floor = math.floor
local ceil = math.ceil
local abs = math.abs
local max_depth = 31000
@ -44,7 +39,7 @@ fun_caves.skysea = function(minp, maxp, data, p2data, area, node)
index3d = (z - minp.z) * (csize.y) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y, z)
terrain_1[index] = floor(terrain_1[index] + 0.5)
terrain_1[index] = math.floor(terrain_1[index] + 0.5)
for y = minp.y, maxp.y do
local dy = y - minp.y
if dy == 0 then
@ -83,7 +78,7 @@ fun_caves.skysea = function(minp, maxp, data, p2data, area, node)
local cloud
--if biome_n[index] < 0 then
terrain_1[index] = floor(terrain_1[index] + 0.5)
terrain_1[index] = math.floor(terrain_1[index] + 0.5)
if terrain_1[index] > 0 then
for y = minp.y, maxp.y do
local dy = y - minp.y

View file

@ -1,10 +1,3 @@
local rand = math.random
local min = math.min
local max = math.max
local floor = math.floor
local ceil = math.ceil
local abs = math.abs
local sqrt = math.sqrt
local max_depth = 31000
@ -191,7 +184,7 @@ local wood_noise = {offset = 0, scale = 1, seed = -4640, spread = {x = 32, y = 3
fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
local tree_n = minetest.get_perlin(tree_noise_1):get2d({x=floor((minp.x + 32) / 160) * 80, y=floor((minp.z + 32) / 160) * 80})
local tree_n = minetest.get_perlin(tree_noise_1):get2d({x=math.floor((minp.x + 32) / 160) * 80, y=math.floor((minp.z + 32) / 160) * 80})
if minp.y < -112 or minp.y > 208 or (not fun_caves.DEBUG and tree_n < 1) then
return
end
@ -210,23 +203,23 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
for x = minp.x, maxp.x do
local dx = (x + 32) % 160 - 80
local dz = (z + 32) % 160 - 80
local r2 = 70 + floor(dx / 4) % 3 * 6 + floor(dz / 4) % 3 * 6
local r2 = 70 + math.floor(dx / 4) % 3 * 6 + math.floor(dz / 4) % 3 * 6
index = index + 1
index3d = (z - minp.z) * (csize.y + 2) * csize.x + (x - minp.x) + 1
local ivm = area:index(x, minp.y - 1, z)
local distance = floor(sqrt(dx ^ 2 + dz ^ 2))
local distance = math.floor(math.sqrt(dx ^ 2 + dz ^ 2))
for y = minp.y - 1, maxp.y + 1 do
local dy = y - minp.y
local r = 20
if abs(y - 50) > 130 then
r = max(0, r - floor((abs(y - 50) - 130) / 2))
if math.abs(y - 50) > 130 then
r = math.max(0, r - math.floor((math.abs(y - 50) - 130) / 2))
end
local distance3
if y > 112 then
distance3 = floor(sqrt(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2))
distance3 = math.floor(math.sqrt(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2))
end
if distance < r then
@ -248,7 +241,7 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
data[ivm] = node['fun_caves:diamondwood']
end
if data[ivm] ~= node['air'] and data[ivm] ~= node['fun_caves:weightless_water'] and rand(500) == 1 then
if data[ivm] ~= node['air'] and data[ivm] ~= node['fun_caves:weightless_water'] and math.random(500) == 1 then
data[ivm] = node['fun_caves:sap']
end
write = true
@ -257,15 +250,15 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
write = true
-- foliage
elseif y < 272 and y > 112 and distance3 and distance3 < r2 and y % 10 == 0 and (floor(dx / 4) % 3 == 0 or floor(dz / 4) % 3 == 0) then
elseif y < 272 and y > 112 and distance3 and distance3 < r2 and y % 10 == 0 and (math.floor(dx / 4) % 3 == 0 or math.floor(dz / 4) % 3 == 0) then
if data[ivm] == node['air'] then
data[ivm] = node['fun_caves:bark']
write = true
end
elseif y < 275 and y > 115 and distance3 and distance3 < r2 and (y + 3) % 10 < 7 and (floor((dx + 3) / 4) % 3 < 2 or floor((dz + 3) / 4) % 3 < 2) then
local r = abs(((y + 3) % 10) - 3)
if (r < 2 or rand(r) == 1) and data[ivm] == node['air'] then
if distance3 > r2 - 10 and rand(10) == 1 then
elseif y < 275 and y > 115 and distance3 and distance3 < r2 and (y + 3) % 10 < 7 and (math.floor((dx + 3) / 4) % 3 < 2 or math.floor((dz + 3) / 4) % 3 < 2) then
local r = math.abs(((y + 3) % 10) - 3)
if (r < 2 or math.random(r) == 1) and data[ivm] == node['air'] then
if distance3 > r2 - 10 and math.random(10) == 1 then
data[ivm] = node['fun_caves:leaves_special']
else
data[ivm] = node['fun_caves:leaves']