Minor health integration progress
Rewrote vital_check function for use in tick logic. Tweaked logic to run with tail calls, predicated all on vital_check. Other misc changes to some functions: - altered separated on_x hook constructor loop to return logical values indicating run or not-run in it's daughter functions. - marked several places where internal function definition is unnecessary and likely slows down performance for rewriting. -misc other functions that require larger refactors of more than just function definition simplification (eg. growth function still clunky).master
parent
9f8f40853a
commit
cc2233c423
5
comp.lua
5
comp.lua
|
@ -3,12 +3,13 @@
|
|||
-- -- -- -- -- -- -- -- General
|
||||
|
||||
local function register_on_hooks()
|
||||
local acts = {"sprout","tick","grow","stagnate","die","health_change","fruit","propagate"}
|
||||
local acts = {"sprout","tick","grow","stagnate","wither","health_change","fruit","propagate"}
|
||||
|
||||
for n = 1, #acts do -- Register act wrappers.
|
||||
local a = "on_"..acts[n]
|
||||
rhynia.f[a] = function(pos, genus)
|
||||
return rhynia.genera[genus].acts[a] and rhynia.genera[genus].acts[a](pos,genus)
|
||||
if(rhynia.genera[genus].acts[a]) then rhynia.genera[genus].acts[a](pos,genus) return true end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,12 +13,12 @@ rhynia.f.condition_tick = function(pos, genus, tf)
|
|||
return v
|
||||
end
|
||||
|
||||
rhynia.f.calc_condition_limits = function(r,min,max,genus,gl)
|
||||
rhynia.f.calc_condition_limits = function(r,min,max,genus,gl) -- WIP: undo unnecessary function definition ~~
|
||||
--local switch = genus and rhynia.genera[genus].traits["pt2condition"]
|
||||
min,max = min or 1, max or 4
|
||||
local maxim = {}
|
||||
maxim[1] = math.floor((((r*min)*2)+1)^2) -- previously maxim.lowest
|
||||
maxim[5] = math.floor(((max*((r*2)+1)^2))*(1+math.log10(3))) -- Replace 4 here with the value of the highest value substrate, here maxim[5] was maxim.highest
|
||||
maxim[5] = math.floor(((max*((r*2)+1)^2))*(1+math.log10(1.7))) -- Replace 4 here with the value of the highest value substrate, here maxim[5] was maxim.highest
|
||||
|
||||
|
||||
for s = 4, 2, -1 do
|
||||
|
@ -27,7 +27,7 @@ rhynia.f.calc_condition_limits = function(r,min,max,genus,gl)
|
|||
end
|
||||
local function limit_adjust() -- adjusts limit values by multiplying by growth interval (necessary to time-expand the limits as they only represent a single snapshot of nutrition up to this point).
|
||||
local gi_factor = rhynia.genera[genus].growth_interval
|
||||
local opt_factor = 1
|
||||
local opt_factor = rhynia.genera[genus].traits.growth_opt and 0.25 or 1
|
||||
gi_factor = type(gi_factor) == "number" and gi_factor or gi_factor[gl]
|
||||
for s = 1, 5 do
|
||||
maxim[s] = maxim[s] * (gi_factor/opt_factor)
|
||||
|
@ -38,12 +38,13 @@ rhynia.f.calc_condition_limits = function(r,min,max,genus,gl)
|
|||
end
|
||||
|
||||
rhynia.f.calc_condition = function(ci,gl,p2,r,genus) -- returns condition value given flat radius r
|
||||
local lims = rhynia.f.calc_condition_limits(r or 1,_,_,gl)
|
||||
local lims = rhynia.f.calc_condition_limits(r or 1,_,_,genus,gl)
|
||||
|
||||
local p2 = p2 > 0 and p2 or 1
|
||||
local cs = lims[p2]
|
||||
local v = ci-(cs*(gl-2 >-1 and gl-2 or 0)) -- where ci = condition index, gl = growth level, cs = condition standard (the value at the level for that condition as calculated)
|
||||
local function incr_chk(a) -- Logical comparison of current ci with standard condition values, checks value incrementally and stops when ci isnt higher than the next number
|
||||
-- WIP: undo unnecessary function definition ~~
|
||||
local ind = 0
|
||||
local function igi(a,b) return a >= b and ind+1 or ind end
|
||||
for s = 1, 4 do
|
||||
|
@ -57,7 +58,7 @@ rhynia.f.calc_condition = function(ci,gl,p2,r,genus) -- returns condition value
|
|||
return incr_chk(v)
|
||||
end
|
||||
|
||||
rhynia.f.average_light_spot = function(pos)
|
||||
rhynia.f.average_light_spot = function(pos) -- WIP: undo unnecessary function definition ~~
|
||||
local area = {a = {x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}, b = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}}
|
||||
area = minetest.find_nodes_in_area(area.a,area.b,"air")
|
||||
local function lux_iterate()
|
||||
|
|
|
@ -43,7 +43,7 @@ rhynia.f.grow = function(pos, genus, stage) -- Rebuilds plant using next genus s
|
|||
return s and rhynia.f.senescence_clear(pos,data.genus,data.gl)
|
||||
end
|
||||
|
||||
local function despues(val)
|
||||
local function despues(val) -- WIP: Definitely in need to a Refactor ~~
|
||||
-- val must always be an integer to reference a value in genus[structure] either directly or proximally via growth_order when present.
|
||||
local v,g = val, data.genus
|
||||
local tab = rhynia.genera[g].structure
|
||||
|
@ -64,7 +64,9 @@ rhynia.f.grow = function(pos, genus, stage) -- Rebuilds plant using next genus s
|
|||
end
|
||||
|
||||
local function build(pos)
|
||||
local p2 = math.random(4)--data.nd.param2 -- ToDo: Add support for multiple param2s
|
||||
local m = minetest.get_meta(pos)
|
||||
local gl,ci,p2 = m:get_int("rhynnia_gl"),m:get_int("rhynia_ci"),data.nd.param2
|
||||
local p2 = rhynia.f.calc_condition(ci,gl,p2,_,genus)
|
||||
local p, s = pos and {x = pos.x, y = pos.y, z = pos.z},rhynia.genera[data.genus].structure[v]
|
||||
|
||||
for n = 1, #s do
|
||||
|
|
|
@ -28,7 +28,10 @@ rhynia.f.MA13_456 = function(pos,prob)
|
|||
end
|
||||
|
||||
rhynia.f.check_vitals = function(pos, genus)
|
||||
return not rhynia.f.is_live(pos) and rhynia.genera[genus].acts.on_wither(pos, genus) and rhynia.f.kill_if_health(pos, 1)
|
||||
local switch_s = not rhynia.f.is_live(pos)
|
||||
local wire_s = switch_s and rhynia.f.on_wither(pos, genus)
|
||||
local wire_s2 = wire_s and rhynia.f.kill_if_health(pos, 1)
|
||||
return not wire_s2 -- to return true if plant is living and false if plant is dead
|
||||
end
|
||||
|
||||
rhynia.f.spot_check = function(pos, name, tf) -- Searches for node [name] 1 node around pos, returns integer of # found. If BOOL "tf" is true, returns table of all values of group "name". (some kind of "verbose" search)
|
||||
|
|
13
logic.lua
13
logic.lua
|
@ -7,11 +7,16 @@ nodecore.register_limited_abm({
|
|||
chance = 1,
|
||||
ignore_stasis = false,
|
||||
action = function(pos, node)
|
||||
local dat = node.name and rhynia.f.nominate(node.name) -- Identity check
|
||||
local dat,switch_s = node.name and rhynia.f.nominate(node.name),nil -- Identity check, is_alive switch
|
||||
-- check for can_exist
|
||||
-- kill if no, continue if yes
|
||||
-- if kill, do on wither. if not kill, continue to survival check
|
||||
-- survival check returns loop back to step 2 above
|
||||
-- If survive then do on_tick behaviour
|
||||
-- on_tick behaviour should contain other on_behaviour such as propagate and grow
|
||||
if(dat)then
|
||||
rhynia.genera[dat.genus].acts.on_tick(pos,dat.genus) -- Do tick behaviour
|
||||
rhynia.f.on_propagate(pos,dat.genus)
|
||||
switch_s = rhynia.f.check_vitals(pos,dat.genus) -- plant life state
|
||||
end
|
||||
return
|
||||
return switch_s and rhynia.genera[dat.genus].acts.on_tick(pos,dat.genus),rhynia.f.on_propagate(pos,dat.genus)
|
||||
end
|
||||
})
|
|
@ -34,7 +34,7 @@ rhynia.f.geo_area = function(p,r,t) -- uses vector p and radius r to determine a
|
|||
return a
|
||||
end
|
||||
|
||||
rhynia.f.ass_check = function(pos, r, t, genus)
|
||||
rhynia.f.ass_check = function(pos, r, t, genus) -- WIP: Unnecessary internal function definition, logic should also be simplifiable, rewrite soon. ~~
|
||||
-- Grabs soil data underneath pos, to a max radius of r, depending on the shape specifier t(bool)
|
||||
local upos = {x = pos.x, y = pos.y - (t and (r+1) or 1), z = pos.z}
|
||||
local cals = rhynia.f.geo_area(upos,r,t)
|
||||
|
|
6
util.lua
6
util.lua
|
@ -29,7 +29,7 @@ end
|
|||
-- -- -- -- -- -- -- ---- -- -- -- -- -- -- --
|
||||
|
||||
-- -- -- -- -- -- -- -- Plant
|
||||
rhynia.f.nominate = function(name)
|
||||
rhynia.f.nominate = function(name) -- WIP: internal local functions unnecessary if only used once, fix. ~~
|
||||
-- Returns a table containing string-genus[1] and int-state[2] from the very end of a string. Causes naming convention requirement ("modname:genus_int").
|
||||
local function get_genus(name)
|
||||
local n = name
|
||||
|
@ -50,3 +50,7 @@ end
|
|||
rhynia.f.select = function(pos) -- Performs the above nomination query on a position.
|
||||
return rhynia.f.nominate(rhynia.u.gn(pos).name)
|
||||
end
|
||||
|
||||
rhynia.u.table_or_int_gi = function(genus)
|
||||
return type(rhynia.genera[genus].growth_interval) == "number"
|
||||
end
|
Loading…
Reference in New Issue