sorcery  Diff

Differences From Artifact [c145d6a94a]:

  • File metallurgy-cold.lua — part of check-in [72eebac4bc] at 2020-09-26 18:49:51 on branch trunk — add writing stand for editing codexes; add scissors, ink, erasure fluid, pens; touch up codex UI; add many recipe notes; add craft divination type for crafttools; defuckulate fucktarded crafttool impl; enhance table library with missing features like lua's table.unpack; many bug fixes and enhancements; blood for the blood god (user: lexi, size: 11980) [annotate] [blame] [check-ins using]

To Artifact [0187673a26]:

  • File metallurgy-cold.lua — part of check-in [3f6a913e4e] at 2020-09-29 12:40:28 on branch trunk — * remove former hacky registration system, replace with consistent and flexible API; rewrite metal/gem generation to take advantage of this new API; tweaks to init system to enable world-local tweaks to lore and sorcery behavior * initial documentation commit * initial steps towards calendar - add default date format, astrolabe; prepare infra for division/melding/transmutation spells, various tweaks and fixes (user: lexi, size: 12204) [annotate] [blame] [check-ins using]

79
80
81
82
83
84
85



86
87
88
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
...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
	minetest.get_node_timer(pos):start(constants.mill_refresh)
end
local mill_fits_in_slot = function(slot,item)
	if slot == 'grinder' then
		if minetest.get_item_group(item:get_name(), 'sorcery_mill_grindhead')~=0 
			then return 1 end
	elseif slot == 'input' then



		local metal = sorcery.data.metallookup[item:get_name()]
		local mat = sorcery.matreg.lookup[item:get_name()]
		local comp = sorcery.data.compat.grindables[item:get_name()]
		if metal or (mat and mat.metal) or comp then
			return item:get_count()
		else
			mat = item:get_definition()._sorcery and
			      item:get_definition()._sorcery.material
			if mat and mat.grindvalue then
				return item:get_count() 
			end
		end
	end
	return 0
end
local matprops = function(item)
	local metal = sorcery.data.metallookup[item:get_name()]

	if not metal then
		-- allow grinding of armor and tools back to their
		-- original components
		local mat = sorcery.matreg.lookup[item:get_name()]
		if mat and mat.metal then
			metal = mat


		end
	end
	local mp = (item:get_definition()._sorcery and
		item:get_definition()._sorcery.material)

		or sorcery.data.compat.grindables[item:get_name()]
		or {}

	if metal then mp = {
		hardness = mp.hardness or metal.data.hardness;
		grindvalue = ((mp.grindvalue or metal.value) or (metal and constants.metal_grindvalue));
		powder = mp.powder or metal.data.parts.powder;
		grindcost = mp.grindcost or constants.metal_grindcost; -- invariant for metal
	} end


	mp.torque     = constants.grind_torque_factor * mp.hardness
	mp.grindvalue = mp.grindvalue or constants.default_grindvalue
	mp.grindcost  = mp.grindcost  or constants.default_grindcost
	mp.hardness   = mp.hardness   or constants.default_hardness;

	if item:get_wear() ~= 0 then
		-- prevent cheating by recovering metal from items before they
		-- are destroyed
		local wearfac = (item:get_wear() / 65535)
		mp.grindvalue = math.max(1,math.ceil(mp.grindvalue * wearfac))
		mp.hardness = math.max(1,math.ceil(mp.grindcost * wearfac))
................................................................................
				local speedboost = math.max(0.05,((grindpower - mp.hardness)/constants.grind_range) * grinders)
				reqtime = mp.grindvalue * mp.hardness * constants.grind_factor * (1-speedboost)
				if elapsed >= reqtime then
					item:take_item(mp.grindcost)
					inv:set_stack('input',1,item)
					local pw = ItemStack{
						name=mp.powder;
						count=mp.grindvalue;
					}
					if inv:room_for_item('output',pw) then
						inv:add_item('output',pw)
					else
						minetest.add_item(pos,pw)
					end
					elapsed = 0







>
>
>
|
|
|
|
|
|
|
|
|
|
|
|





>






>
>


<
<
>










>



<







 







|







79
80
81
82
83
84
85
86
87
88
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
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
	minetest.get_node_timer(pos):start(constants.mill_refresh)
end
local mill_fits_in_slot = function(slot,item)
	if slot == 'grinder' then
		if minetest.get_item_group(item:get_name(), 'sorcery_mill_grindhead')~=0 
			then return 1 end
	elseif slot == 'input' then
		if sorcery.itemclass.get(item,'grindable') then
			return item:get_count()
		end
		-- local metal = sorcery.data.metallookup[item:get_name()]
		-- local mat = sorcery.matreg.lookup[item:get_name()]
		-- local comp = sorcery.data.compat.grindables[item:get_name()]
		-- if metal or (mat and mat.metal) or comp then
		-- 	return item:get_count()
		-- else
		-- 	mat = item:get_definition()._sorcery and
		-- 	      item:get_definition()._sorcery.material
		-- 	if mat and mat.metal or mat.powder then
		-- 		return item:get_count() 
		-- 	end
		-- end
	end
	return 0
end
local matprops = function(item)
	local metal = sorcery.data.metallookup[item:get_name()]
	local props = item:get_definition()._sorcery
	if not metal then
		-- allow grinding of armor and tools back to their
		-- original components
		local mat = sorcery.matreg.lookup[item:get_name()]
		if mat and mat.metal then
			metal = mat
		elseif props and props.material and props.material.metal then
			metal = props.material
		end
	end


	local mp = (props and props.material)
		or sorcery.data.compat.grindables[item:get_name()]
		or {}

	if metal then mp = {
		hardness = mp.hardness or metal.data.hardness;
		grindvalue = ((mp.grindvalue or metal.value) or (metal and constants.metal_grindvalue));
		powder = mp.powder or metal.data.parts.powder;
		grindcost = mp.grindcost or constants.metal_grindcost; -- invariant for metal
	} end

	mp.hardness   = mp.hardness   or constants.default_hardness;
	mp.torque     = constants.grind_torque_factor * mp.hardness
	mp.grindvalue = mp.grindvalue or constants.default_grindvalue
	mp.grindcost  = mp.grindcost  or constants.default_grindcost


	if item:get_wear() ~= 0 then
		-- prevent cheating by recovering metal from items before they
		-- are destroyed
		local wearfac = (item:get_wear() / 65535)
		mp.grindvalue = math.max(1,math.ceil(mp.grindvalue * wearfac))
		mp.hardness = math.max(1,math.ceil(mp.grindcost * wearfac))
................................................................................
				local speedboost = math.max(0.05,((grindpower - mp.hardness)/constants.grind_range) * grinders)
				reqtime = mp.grindvalue * mp.hardness * constants.grind_factor * (1-speedboost)
				if elapsed >= reqtime then
					item:take_item(mp.grindcost)
					inv:set_stack('input',1,item)
					local pw = ItemStack{
						name=mp.powder;
						count=math.floor(mp.grindvalue);
					}
					if inv:room_for_item('output',pw) then
						inv:add_item('output',pw)
					else
						minetest.add_item(pos,pw)
					end
					elapsed = 0