Quantcast

Made the intermediate list in the queue order by priority values matching the items from which they came.

pschifferer [10-21-09 - 04:32]
Made the intermediate list in the queue order by priority values matching the items from which they came.
Filename
CauldronQueue.lua
diff --git a/CauldronQueue.lua b/CauldronQueue.lua
index 9f8054c..81a7892 100644
--- a/CauldronQueue.lua
+++ b/CauldronQueue.lua
@@ -107,7 +107,7 @@ function CauldronQueue:GetIntermediates(queue)
 	end

 	-- sort the list
---	table.sort(items, function(r1, r2) return r2.priority < r1.priority; end);
+	table.sort(items, function(r1, r2) return r2.priority < r1.priority; end);

 	return items;
 end
@@ -178,12 +178,12 @@ function CauldronQueue:CalculateAllRequiredItems(queue)
 	-- iterate over the queued items
 	for name, queueInfo in pairs(queue.main) do
 		local skillInfo = Cauldron:GetSkillInfo(queueInfo.tradeskill, queueInfo.name);
-		CauldronQueue:CalculateRequiredItems(queue, skillInfo, queueInfo.amount);
+		CauldronQueue:CalculateRequiredItems(queue, skillInfo, queueInfo.amount, queueInfo.priority);
 	end

 end

-function CauldronQueue:CalculateRequiredItems(queue, skillInfo, amount)
+function CauldronQueue:CalculateRequiredItems(queue, skillInfo, amount, priority)

 	-- sanity checks
 	if not queue then
@@ -234,7 +234,7 @@ function CauldronQueue:CalculateRequiredItems(queue, skillInfo, amount)
 					end
 				end

-				CauldronQueue:AddIntermediate(queue, reagent, amount);
+				CauldronQueue:AddIntermediate(queue, reagent, amount, priority);

 				-- add the intermediate's reagents also
 				CauldronQueue:CalculateRequiredItems(queue, intSkillInfo, amount);
@@ -248,7 +248,7 @@ function CauldronQueue:CalculateRequiredItems(queue, skillInfo, amount)

 end

-function CauldronQueue:AddIntermediate(queue, reagent, amount)
+function CauldronQueue:AddIntermediate(queue, reagent, amount, priority)

 	-- sanity checks
 	if not queue then
@@ -272,7 +272,9 @@ function CauldronQueue:AddIntermediate(queue, reagent, amount)
 		if reagent.name then
 			local skillInfo = Cauldron:GetSkillInfoForItem(reagent.name);
 			if skillInfo then
-				queue.intermediate[reagent.name] = CauldronQueue:NewItem(reagent.name, reagent.icon, amount, nil, skillInfo.tradeskill, reagent.link);
+				local newItem = CauldronQueue:NewItem(reagent.name, reagent.icon, amount, nil, skillInfo.tradeskill, reagent.link);
+				newItem.priority = priority or 0;
+				queue.intermediate[reagent.name] = newItem;
 			else
 				Cauldron:error("AddIntermediate: no skill info found for reagent: "..reagent.name);
 			end