2014-12-29 20:16:14 +01:00
|
|
|
-- global table and register_* functions
|
|
|
|
|
|
|
|
rocks = {}
|
|
|
|
|
|
|
|
rocks.layers = {}
|
2015-02-08 16:58:57 +01:00
|
|
|
rocks.layers_name = {}
|
2014-12-29 20:16:14 +01:00
|
|
|
rocks.veins = {}
|
|
|
|
rocks.ores = {}
|
|
|
|
|
|
|
|
rocks.register_layer=function(name,params,rock)
|
|
|
|
assert(name)
|
|
|
|
assert(params)
|
2015-02-08 21:20:07 +01:00
|
|
|
assert(rock)
|
2014-12-29 20:16:14 +01:00
|
|
|
assert(params.gain)
|
|
|
|
assert(params.height)
|
|
|
|
local maxheight
|
2015-02-08 16:58:57 +01:00
|
|
|
|
|
|
|
local ld= {
|
2014-12-29 20:16:14 +01:00
|
|
|
gain=params.gain,
|
|
|
|
height=params.height,
|
|
|
|
maxheight=maxheight,
|
2015-02-08 21:20:07 +01:00
|
|
|
limit=((params.limit or 2)*params.gain)+params.height,
|
|
|
|
seed=params.seed or 0,
|
2014-12-29 21:47:55 +01:00
|
|
|
rock={ node=rock },
|
2015-02-08 16:58:57 +01:00
|
|
|
veins={},
|
|
|
|
name=name
|
2014-12-29 20:16:14 +01:00
|
|
|
}
|
2015-02-08 16:58:57 +01:00
|
|
|
rocks.layers_name[name]= ld
|
|
|
|
print("[rocks] layer "..ld.name)
|
2014-12-29 20:16:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
rocks.register_vein=function(name,params)
|
|
|
|
assert(name)
|
|
|
|
assert(params)
|
|
|
|
assert(not rocks.veins[name])
|
|
|
|
rocks.veins[name]={
|
|
|
|
np={
|
|
|
|
offset=0, scale=1, octaves=1, presist=0.8,
|
2015-02-08 21:20:07 +01:00
|
|
|
spread={x=params.spread.x, y=params.spread.y, z=params.spread.z},
|
2014-12-29 21:47:55 +01:00
|
|
|
-- swapped, becouse we generate by horizontal layers
|
|
|
|
seed=params.seed
|
2014-12-29 20:16:14 +01:00
|
|
|
},
|
|
|
|
treshold=params.treshold,
|
|
|
|
hmin=params.hmin, hmax=params.hmax,
|
|
|
|
layers=params.layers,
|
|
|
|
ores={}
|
|
|
|
}
|
2015-02-08 21:20:07 +01:00
|
|
|
for i,layername in pairs(params.layers) do
|
|
|
|
rocks.layers_name[layername].veins[name]=rocks.veins[name]
|
2014-12-29 20:16:14 +01:00
|
|
|
end
|
|
|
|
print("[rocks] vein "..name)
|
|
|
|
end
|
|
|
|
|
|
|
|
rocks.register_ore=function( vein, node, params )
|
|
|
|
-- params= {treshold=0, chance=1 }
|
|
|
|
ore={ node=node }
|
2014-12-29 21:47:55 +01:00
|
|
|
ore.treshold=(params.treshold or rocks.veins[vein].treshold)
|
|
|
|
ore.chance= (params.chance or 1)
|
2014-12-29 20:16:14 +01:00
|
|
|
table.insert(rocks.veins[vein].ores, ore)
|
2014-12-29 21:47:55 +01:00
|
|
|
print("[rocks] ore "..node.." in "..vein.." chance="..ore.chance.." treshold="..ore.treshold)
|
2014-12-29 20:16:14 +01:00
|
|
|
end
|