Quantcast

Fix error in using "more" or "less" with decreasing values.

Johnny C. Lam [03-12-13 - 04:46]
Fix error in using "more" or "less" with decreasing values.

When using a script condition that has a decreasing value, e.g.,
BuffRemains(), the value is a function

    f(t) = value + (t - origin) * rate

where rate is negative.  When using the "more"/"less" comparators, e.g.,
BuffRemains(more 3), this effectively solves the following inequality:

    f(t) = value + (t - origin) * rate > 3

When the rate is negative, the inequality is reversed, and you end up
with:

   t < (3 - value)/rate + origin

Prior to this commit, Ovale was using the wrong answer of:

   t > (3 - value)/rate + origin

This had broken scripts that were using the verbose method of comparing
values.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@751 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCondition.lua
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index 1cd43ef..f202d80 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -286,10 +286,10 @@ local function testValue(comparator, limit, value, atTime, rate)
 			else
 				Ovale:Error("Unknown operator "..comparator)
 			end
-		elseif comparator == "more" then
-			return (limit-value)/rate + atTime
-		elseif comparator == "less" then
-			return 0, (limit-value)/rate + atTime
+		elseif (comparator == "more" and rate > 0) or (comparator == "less" and rate < 0) then
+			return (limit - value) / rate + atTime
+		elseif (comparator == "more" and rate < 0) or (comparator == "less" and rate > 0) then
+			return 0, (limit - value) / rate + atTime
 		else
 			Ovale:Error("Unknown operator "..comparator)
 		end