diff utils.lua @ 116:7ce304c296b0

Display then number of makable items instead of the number of times the recipe is craftable
author contrebasse
date Wed, 15 Jun 2011 01:14:00 +0200
parents af23986010ef
children c32d6bf6cfc1
line wrap: on
line diff
--- a/utils.lua	Wed Jun 15 00:05:35 2011 +0200
+++ b/utils.lua	Wed Jun 15 01:14:00 2011 +0200
@@ -69,18 +69,38 @@
 		end -- if
 	end
 
-	-- Gives the total number of craftable objects
+	-- Gives the total number of craftable items
 	function A.numMakable(reagentID)
 		-- No recipe
 		if not A.data[reagentID] then return 0 end
 
 		-- Many recipes
-		local n = 0
-		local itemCount
+		local n1 = 0
+		local n2 = 0
+		local m
+		local approx = nil
 		for _,recipe in pairs(A.data[reagentID]) do
-			n = n + A.numRecipeMakable(recipe[1],recipe[2])
+			-- number of times the recipe is makable
+			m = A.numRecipeMakable(recipe[1],recipe[2])
+			if not m then return end
+
+			-- number of items it gives
+			if not recipe[3] or recipe[3]==1 then
+				n1 = n1 + m
+				n2 = n2 + m
+			elseif recipe[3]<1 then
+				approx = approx or m>0 -- 0 is not approx
+				n1 = n1 + m*recipe[3]
+				n2 = n2 + m*recipe[3]
+			elseif recipe[4] then
+				n1 = n1 + m*recipe[3]
+				n2 = n2 + m*recipe[4]
+			else
+				n1 = n1 + m*recipe[3]
+				n2 = n2 + m*recipe[3]				
+			end
 		end -- for
-		return n
+		return n1,n2,approx
 	end -- function
 
 	-- Find the first tradeskill index of the recipe to make an item