build table of items for calculating prices
parent
1d26ea1990
commit
058f943863
34
api.lua
34
api.lua
|
@ -1,4 +1,6 @@
|
|||
|
||||
local has_value=basic_functions.has_value
|
||||
|
||||
function kiosk.demangle_for_formspec(str)
|
||||
-- copied from unified_inventory
|
||||
return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end)
|
||||
|
@ -62,6 +64,38 @@ kiosk.add_inventar=function(name,buy_value,sell_value,stock,fixed)
|
|||
end
|
||||
end
|
||||
|
||||
kiosk.is_drop_item=function(name)
|
||||
if kiosk.inventar[name] == nil then
|
||||
kiosk.add_inv(name,{})
|
||||
end
|
||||
kiosk.inventar[name].is_drop = 1
|
||||
end
|
||||
|
||||
kiosk.register_craft_relation=function(input,output)
|
||||
if kiosk.inventar[input] == nil then
|
||||
kiosk.add_inv(input,{})
|
||||
end
|
||||
if kiosk.inventar[output] == nil then
|
||||
kiosk.add_inv(output,{})
|
||||
end
|
||||
local source=kiosk.inventar[input]
|
||||
local dest=kiosk.inventar[output]
|
||||
if source.dest == nil then
|
||||
source.dest = {output}
|
||||
else
|
||||
if not has_value(source.dest,output) then
|
||||
table.insert(source.dest,output)
|
||||
end
|
||||
end
|
||||
if dest.source == nil then
|
||||
dest.source = {input}
|
||||
else
|
||||
if not has_value(dest.source,input) then
|
||||
table.insert(dest.source,input)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
kiosk.is_inventar=function(name)
|
||||
return kiosk.inventar[name] ~= nil
|
||||
end
|
||||
|
|
96
config.lua
96
config.lua
|
@ -23,11 +23,8 @@ local int_pri={}
|
|||
for i,v in pairs(price_def) do
|
||||
v.groups=nil
|
||||
kiosk.add_inv(i,v)
|
||||
print(dump2(minetest.registered_items[i]))
|
||||
end
|
||||
|
||||
local new_inv={}
|
||||
|
||||
for i,v in pairs(minetest.registered_nodes) do
|
||||
local node_price=0
|
||||
if v.groups then
|
||||
|
@ -38,19 +35,16 @@ for i,v in pairs(minetest.registered_nodes) do
|
|||
end
|
||||
end
|
||||
if v.drop and node_price > 0 then
|
||||
-- print(i,node_price)
|
||||
-- print(type(v.drop))
|
||||
if type(v.drop)=="string" and v.drop ~= "" then
|
||||
local dn=v.drop:split(" ")[1]
|
||||
local dcount=v.drop:split(" ")[2]
|
||||
if dcount==nil then dcount=1 end
|
||||
if new_inv[dn]==nil then
|
||||
new_inv[dn] = {node_price/(dcount*10)}
|
||||
else
|
||||
table.insert(new_inv[dn],node_price/(dcount*10))
|
||||
|
||||
if not kiosk.is_inventar(dn) then
|
||||
kiosk.add_inv(dn,{buy_value=node_price/(dcount*10)})
|
||||
end
|
||||
kiosk.is_drop_item(dn)
|
||||
elseif type(v.drop)=="table" then
|
||||
-- print(dump2(v.drop))
|
||||
if v.drop.items then
|
||||
for j,w in pairs(v.drop.items) do
|
||||
local dn=w.items[1]:split(" ")[1]
|
||||
|
@ -59,82 +53,46 @@ for i,v in pairs(minetest.registered_nodes) do
|
|||
if w.rarity then
|
||||
dcount=dcount/w.rarity
|
||||
end
|
||||
if new_inv[dn]==nil then
|
||||
new_inv[dn] = {node_price/(dcount*10)}
|
||||
else
|
||||
table.insert(new_inv[dn],node_price/(dcount*10))
|
||||
if not kiosk.is_inventar(dn) then
|
||||
kiosk.add_inv(dn,{buy_value=node_price/(dcount*10)})
|
||||
end
|
||||
kiosk.is_drop_item(dn)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for i,v in pairs(new_inv) do
|
||||
|
||||
for i,v in pairs(minetest.registered_items) do
|
||||
if not kiosk.is_inventar(i) then
|
||||
local np=math.huge
|
||||
for _,j in ipairs(v) do
|
||||
np=math.min(np,j)
|
||||
kiosk.add_inv(i,{})
|
||||
end
|
||||
local recipes=minetest.get_all_craft_recipes(i)
|
||||
if recipes ~= nil then
|
||||
for j,w in pairs(recipes) do
|
||||
for k,x in pairs(w.items) do
|
||||
kiosk.register_craft_relation(x,i)
|
||||
end
|
||||
end
|
||||
kiosk.add_inventar(i,np)
|
||||
end
|
||||
end
|
||||
|
||||
for i,v in pairs(kiosk.inventar) do
|
||||
local reci=minetest.get_craft_result({method="cooking",items={ItemStack(i)}})
|
||||
if reci.time>0 then
|
||||
local lpr=math.ceil((v.buy*1.1+reci.time*0.25/40)*100)/100
|
||||
local ni=reci.item:get_name()
|
||||
local count=reci.item:get_count()
|
||||
local lpr=math.ceil((v.buy*1.1+reci.time*0.25/40)*100)/(count*100)
|
||||
if not kiosk.is_inventar(ni) then
|
||||
kiosk.add_inventar(ni,lpr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local missing_item={}
|
||||
local missing_sources={}
|
||||
local missing_group={}
|
||||
for i,v in pairs(minetest.registered_items) do
|
||||
if not kiosk.is_inventar(i) then
|
||||
missing_item[i]=1
|
||||
|
||||
local reci=minetest.get_all_craft_recipes(i)
|
||||
if reci then
|
||||
for j,w in pairs(reci) do
|
||||
if w.items then
|
||||
local rprice=0
|
||||
local fullcalc=1
|
||||
for _,n in pairs(w.items) do
|
||||
if kiosk.is_inventar(n) then
|
||||
rprice=rprice+kiosk.get_buy(n)
|
||||
else
|
||||
fullcalc=0
|
||||
if n:split(":")[1]=="group" then
|
||||
local ng=n:split(":")[2]
|
||||
for k,x in ipairs(ng:split(",")) do
|
||||
missing_group[x]=1
|
||||
end
|
||||
else
|
||||
missing_sources[n]=1
|
||||
end
|
||||
end
|
||||
end
|
||||
if fullcalc==1 and rprice>0 then
|
||||
rprice=math.ceil(rprice*110)/100
|
||||
kiosk.add_inventar(i,rprice)
|
||||
end
|
||||
end
|
||||
if v.source ~= nil and v.dest ~= nil and v.is_drop ~= nil then
|
||||
local ts=table.copy(v.source)
|
||||
local ns={}
|
||||
for j,w in ipairs(ts) do
|
||||
if not has_value(v.dest,w) then
|
||||
table.insert(ns,w)
|
||||
end
|
||||
end
|
||||
v.source=ns
|
||||
if #ns == 0 then
|
||||
print(dump2(v))
|
||||
end
|
||||
end
|
||||
end
|
||||
print(dump2(missing_item))
|
||||
print(dump2(missing_sources))
|
||||
print(dump2(missing_group))
|
||||
|
||||
|
||||
--print(dump2(minetest.registered_items["default:coal_lump"]))
|
||||
-- initialise map_extend with values, which are corrected in first run
|
||||
kiosk.map_extend={emin={x=31000,y=31000,z=31000},emax={x=(-31000),y=(-31000),z=(-31000)},volume=0}
|
||||
|
||||
|
|
Loading…
Reference in New Issue