starlit  Diff

Differences From Artifact [4823845880]:

To Artifact [cdaabd4e00]:


    96     96   world.ecology.plants.foreach('starlit:plant-gen', {}, function(id, b)
    97     97   	local stageCt = #b.stages
    98     98   	local function stageID(n)
    99     99   		if n == stageCt then return id end
   100    100   		return id .. string.format('_stage_%s', n)
   101    101   	end
   102    102   	b.stageNodes = {}
          103  +	b.req = b.req or {}
   103    104   	local function regStage(n, st)
   104    105   		local base = {
   105    106   			description = b.name;
   106    107   			drawtype = "plantlike";
   107    108   			tiles = { tostring(st.tex) };
   108    109   			paramtype = "light";
   109    110   			paramtype2 = "meshoptions";
   110    111   			place_param2 = b.meshOpt;
   111    112   			walkable = false;
   112    113   			buildable_to = true;
   113    114   			groups = {
   114    115   				plant = 1;
   115    116   				plant_grow = stageCt ~= n and 1 or 0;
          117  +				attached_node = 3;
   116    118   			};
   117    119   			drop = st.drop;
   118    120   			_starlit = {
   119    121   				plant = {
   120    122   					id = id, stage = n;
   121    123   				};
   122    124   				recover = starlit.type.fab {
................................................................................
   130    132   							potassium = rng:int(0,1);
   131    133   						}
   132    134   					};
   133    135   				end;
   134    136   			};
   135    137   		}
   136    138   		if st.swap then
   137         -			base.node_dig_prediction = stageID(st.swap)
          139  +			base.node_dig_prediction = ""
   138    140   			function base.after_dig_node(pos, node, digger)
   139    141   				node.name = stageID(st.swap)
   140    142   				minetest.swap_node(pos, node)
   141    143   				return true
   142    144   			end
   143    145   		end
   144    146   		if st.biolum then base.light_source = st.biolum; end
................................................................................
   232    234   			user:statDelta('health', -dmg)
   233    235   		end
   234    236   	end
   235    237   end)
   236    238   
   237    239   
   238    240   world.ecology.trees.foreach('starlit:tree-gen', {}, function(id, t)
   239         -	local dec = {
   240         -		deco_type = 'lsystem';
   241         -		treedef = t.def;
   242         -	}
   243         -	for k,v in pairs(t.decorate) do dec[k]=v end
   244         -	minetest.register_decoration(dec)
          241  +	for i,td in ipairs(t.decorate) do
          242  +		local dec = {
          243  +			deco_type = 'lsystem';
          244  +			treedef = t.def;
          245  +		}
          246  +		for k,v in pairs(td) do dec[k]=v end
          247  +		minetest.register_decoration(dec)
          248  +	end
   245    249   end)
   246    250   
   247    251   minetest.register_abm {
   248    252   	label = "plant growth";
   249    253   	nodenames = {'group:plant_grow'};
   250    254   	chance = 15;
   251    255   	interval = 20;
   252    256   	catch_up = true;
   253    257   	action = function(pos, node)
   254    258   		local def = minetest.registered_nodes[node.name]._starlit.plant
   255         -		local plant = starlit.world.ecology.plants.db[def.id]
   256         -		local nextStage = plant.stageNodes[def.stage + 1]
   257         -		minetest.swap_node(pos, {name=nextStage})
          259  +		-- 5 W: maximum power for UV lamps
          260  +		-- 7 W: maximum solar power
          261  +		local uv = (minetest.get_natural_light(pos) / 15) * 7
          262  +		-- TODO compute artificial contribution
          263  +		local req = lib.tbl.defaults({
          264  +			uv = 3;
          265  +			soil = 'soil';
          266  +			temp = -10;
          267  +			humid = nil;
          268  +		}, def.growReq);
          269  +
          270  +		-- TODO check other reqs
          271  +
          272  +		if uv > req.uv then
          273  +			local plant = starlit.world.ecology.plants.db[def.id]
          274  +			local nextStage = plant.stageNodes[def.stage + 1]
          275  +			minetest.swap_node(pos, {name=nextStage})
          276  +		end
   258    277   	end;
   259    278   }