local world = starlit.world
local lib = starlit.mod.lib
local function dropCat(a,b)
local function strdrop(s)
if type(s) == 'string' then
return {max_items = 1; items = {{items={s}}}}
else return s end
end
a = strdrop(a)
b = strdrop(b)
return {
max_items = a.max_items + b.max_items;
items = lib.tbl.append(a.items, b.items);
}
end
local function stalkPlant(def)
local function stage(s, drops, swap)
return {
tex = lib.image(string.format('starlit-eco-plant-stalk%s.png',s)):shift(def.color);
drop = drops;
swap = swap;
}
end
local function plantMatter(opts)
local dps = {
seed = def.seed;
fiber = def.fiber;
leaf = def.leaf and def.leaf.drop or nil;
berry = def.berries and def.berries.drop or nil;
}
local t = {max_items=0, items={}}
for k,v in pairs(opts) do
if dps[v] then t = dropCat(dps[v], t) end
end
return t
end
local fg
local stages = {
stage('-grow-1', '');
stage('-grow-2', plantMatter{'seed'});
stage('-grow-3', plantMatter{'seed','fiber'});
stage('', plantMatter{'seed','seed','fiber'});
};
if def.leaf then
local ps = stage('', plantMatter{'seed','seed','seed','fiber','leaf'})
ps.tex = ps.tex .. lib.image('starlit-eco-plant-stalk-petals.png'):shift(def.leaf.color)
table.insert(stages, ps)
end
if def.berries then
local ps = lib.image.clone(stages[#stages])
ps.tex = ps.tex:blit(lib.image('starlit-eco-plant-stalk-berries.png'):shift(def.berries.color))
ps.drop = def.berries.drop;
ps.swap = #stages
table.insert(stages, ps)
end
if def.biolum then for i,v in ipairs(stages) do
v.biolum = math.floor(def.biolum * (i/#stages))
end end
world.ecology.plants.link(def.id, {
name = def.name;
stages = stages;
decoration = def.decoration;
meshOpt = 3;
})
end
local function simpleDrop(rarity, what)
return {
max_items = 1;
items = {
{rarity = rarity, items = {what}};
};
};
end
function stalkPlantAuto(def)
local id = def.id
local id_berries = def.id .. '_berry'
local id_seed = def.id .. '_seed'
local p = lib.tbl.proto({}, def)
if def.berries then
local bdef = lib.tbl.defaults({
name = def.name .. ' Berry';
tex = lib.image('starlit-eco-plant-berry-bunch.png'):shift(def.berries.color or def.color):render();
color = def.color;
}, def.berries)
bdef.name = bdef.name
starlit.item.food.link(id_berries, bdef)
p.berries = {
color = def.berries.color;
drop = id_berries;
}
end
if def.seed then
local sdef = lib.tbl.defaults({
name = def.name .. ' Seed';
tex = lib.image('starlit-eco-plant-seeds.png'):shift(def.seed.color or def.color):render();
color = def.color;
grow = {kind = 'plant', id = id};
}, def.seed)
starlit.item.seed.link(id_seed, sdef)
p.seed = id_seed
end
return stalkPlant(p)
end
stalkPlantAuto {
id = 'starlit_eco:moondrop';
name = "Moondrop";
fiber = simpleDrop(2, 'starlit_eco:fiber');
seed = {};
color = lib.color(.5, .7, 1);
biolum = 5;
leaf = {
color = lib.color(.6, .8, .8);
drop = simpleDrop(2, 'starlit_eco:moondrop_petal');
};
berries = {
desc = "The fruits of the moondrop are not very nutritious, but their peculiar sweet-sour flavor profile makes them one Thousand Petal's great delicacies";
color = lib.color(1,0,.4);
nourish = 10;
hydrate = 0.05;
taste = 1 * 60;
mass = 1;
};
decoration = {
place_on = 'starlit:greengraze';
fill_ratio = 0.03;
biomes = {'starlit:steppe', 'starlit:forest'};
y_min = 10;
y_max = 100;
};
}
stalkPlantAuto {
id = 'starlit_eco:dustrose';
name = "Dust Rose";
fiber = simpleDrop(2, 'starlit_eco:fiber');
seed = {};
color = lib.color(.3, .1, .2);
leaf = {
color = lib.color(.7, .4, .8);
drop = simpleDrop(2, 'starlit_eco:dustrose_petal');
};
decoration = {
place_on = 'starlit:greengraze';
fill_ratio = 0.03;
biomes = {'starlit:forest'};
y_min = -50;
y_max = 50;
};
}
stalkPlantAuto {
id = 'starlit_eco:harrowstalk';
name = "Harrowstalk";
fiber = simpleDrop(2, 'starlit_eco:fiber');
seed = {};
color = lib.color(.3, .2, .1);
decoration = {
place_on = 'starlit:sand';
fill_ratio = 0.03;
biomes = {'starlit:ocean', 'starlit:desert'};
y_min = -30;
y_max = 400;
};
}