sorcery  Diff

Differences From Artifact [43b3147bb9]:

To Artifact [87f184e80e]:


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
			end
		end do
			return
		end ::found::

		local tposhash = minetest.hash_node_position(tpos)
		local live, should_cache
		local mass_leaves, mass_trunk, topnode, prevalidate
		if abm_cache.treehash[tposhash] then
			live = true
			local c = abm_cache.treehash[tposhash]
			mass_leaves = c.mass_leaves
			mass_trunk = c.mass_trunk
			prevalidate = true
		else
			local tbody
			live, tbody = sorcery.lib.node.tree_is_live(tpos)
			if live then
				should_cache = tbody.nodes[tbody.trunk]
				mass_leaves = #(tbody.nodes[tbody.leaves])
				mass_trunk = #(tbody.nodes[tbody.trunk]) * 12
				topnode = tbody.topnode
			end
		end

		if (not live)
			or tree.sap == false
			or not tree.sapliq then return end
		if mass_trunk < 12*3 then return end -- too small

		tapdrip(tree.sapliq,pos)

		local mass = mass_leaves + mass_trunk
		local max_mass = 400
		local ltratio = mass_leaves / mass_trunk
		local mratio = mass / max_mass
		local outof = 15 / mratio
		local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3

		local diceroll = math.random(1,chance)
		-- log.act('rolling dice: ', chance,diceroll, '(lt ratio =', ltratio, '; mass ratio = ', mratio, '; tree mass =', mass, '; outof =', outof)
		if diceroll ~= 1 then return end -- failed roll

		if not prevalidate then
			if minetest.get_natural_light(vector.offset(topnode,0,1,0), 0.5) < 13
				then return false end
		end


		for i=1,8 do
			local at = vector.offset(pos, 0,-i,0)
			if sorcery.lib.node.is_air(at) then goto skip end

			local trough = minetest.get_node(at)
			if minetest.get_item_group(trough.name, 'sorcery_trough') ~= 0 then
................................................................................
							else
								node.name = nct.make((ctr.charge or 0) + nct.res,1):get_name()
							end
							minetest.swap_node(at, node)
						end
						if should_cache then
							for _,v in pairs(should_cache) do
								abm_cache.treehash[v:to_string()] = {
									mass_leaves = mass_leaves;
									mass_trunk = mass_trunk;
								}
							end
						end
					end
				else
					log.err('item',trough.name,'is marked as a trough but lacks a _sorcery.container property table')
				end
			end
			do return end
		::skip::end
	end;
}







|



|







|












|
|
|
|
|
|
>
|



|
|
|
|
>







 







|
|













89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
			end
		end do
			return
		end ::found::

		local tposhash = minetest.hash_node_position(tpos)
		local live, should_cache
		local mass_trunk, topnode, prevalidate
		if abm_cache.treehash[tposhash] then
			live = true
			local c = abm_cache.treehash[tposhash]
			-- mass_leaves = c.mass_leaves
			mass_trunk = c.mass_trunk
			prevalidate = true
		else
			local tbody
			live, tbody = sorcery.lib.node.tree_is_live(tpos)
			if live then
				should_cache = tbody.nodes[tbody.trunk]
				-- mass_leaves = #(tbody.nodes[tbody.leaves])
				mass_trunk = #(tbody.nodes[tbody.trunk]) * 12
				topnode = tbody.topnode
			end
		end

		if (not live)
			or tree.sap == false
			or not tree.sapliq then return end
		if mass_trunk < 12*3 then return end -- too small

		tapdrip(tree.sapliq,pos)

		local mass = mass_trunk -- + mass_leaves
		local max_mass = 250 -- 400
		-- local ltratio = mass_leaves / mass_trunk
		-- local mratio = mass / max_mass
		-- local outof = 15 / mratio
		-- local chance = math.max(1, math.floor(outof - (25 * ltratio))) / 3
		local chance = mass / max_mass
		local diceroll = math.random(1,math.ceil(chance))
		-- log.act('rolling dice: ', chance,diceroll, '(lt ratio =', ltratio, '; mass ratio = ', mratio, '; tree mass =', mass, '; outof =', outof)
		if diceroll ~= 1 then return end -- failed roll

		-- if not prevalidate then
		-- 	if minetest.get_natural_light(vector.offset(topnode,0,1,0), 0.5) < 13
		-- 		then return false end
		-- end
		-- FIXME

		for i=1,8 do
			local at = vector.offset(pos, 0,-i,0)
			if sorcery.lib.node.is_air(at) then goto skip end

			local trough = minetest.get_node(at)
			if minetest.get_item_group(trough.name, 'sorcery_trough') ~= 0 then
................................................................................
							else
								node.name = nct.make((ctr.charge or 0) + nct.res,1):get_name()
							end
							minetest.swap_node(at, node)
						end
						if should_cache then
							for _,v in pairs(should_cache) do
								abm_cache.treehash[minetest.hash_node_position(v)] = {
									-- mass_leaves = mass_leaves;
									mass_trunk = mass_trunk;
								}
							end
						end
					end
				else
					log.err('item',trough.name,'is marked as a trough but lacks a _sorcery.container property table')
				end
			end
			do return end
		::skip::end
	end;
}