From 668ecddf163084a8958ce52a3730aad7a6cf67d7 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Fri, 1 Feb 2013 15:11:59 +0000 Subject: [PATCH] Fix ``wait'' nodes that are part of ``if'' and ``unless'' nodes. Slightly change the way that the ``wait'' node is flagged by directly setting and clearing a flag instead of fiddling with a negative/positive priority. This is simpler and more clear. Only clear ``wait'' flag in elements returned from ``if'' and ``unless''. This fixes ``wait'' to work as expected in the following example: { if Conditions() wait if PoolingConditions() Actions() MoreActions() } If Conditions() is false, then treat the ``wait'' like it's not there and fall through to MoreActions(). If Conditions() is true, then wait for ``if PoolingConditions() Actions()'' to be true and stop processing the script at that point. Before this fix, ``wait'' was tainting the element returned by the ``if'' so that the entire group stopped processing at the wait statement, regardless of the return value of Conditions(). git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@675 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleBestAction.lua | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua index 998c377..c2d9aa2 100644 --- a/OvaleBestAction.lua +++ b/OvaleBestAction.lua @@ -59,6 +59,10 @@ local function minTime(time1, time2) end end +local function isBetween(checkTime, startTime, endTime) + return isBeforeEqual(startTime, checkTime) and isAfterEqual(endTime, checkTime) +end + local function maxTime(time1, time2) if isAfter(time1, time2) then return time1 @@ -415,6 +419,10 @@ function OvaleBestAction:Compute(element) else startB, endB, prioriteB, elementB = self:ComputeBool(element.b) end + -- If the "then" clause is a "wait" node, then only wait if the conditions are true. + if elementB and elementB.wait and not isBetween(OvaleState.currentTime, startA, endA) then + elementB.wait = nil + end if isAfter(startB, endA) or isAfter(startA, endB) then if Ovale.trace then Ovale:Print(element.type.." return nil ["..element.nodeId.."]") end return nil @@ -436,6 +444,11 @@ function OvaleBestAction:Compute(element) local startA, endA = self:ComputeBool(element.a) local startB, endB, prioriteB, elementB = self:Compute(element.b) + -- If the "then" clause is a "wait" node, then only wait if the conditions are false. + if elementB and elementB.wait and isBetween(OvaleState.currentTime, startA, endA) then + elementB.wait = nil + end + if isBeforeEqual(startA, startB) and isAfterEqual(endA, endB) then if Ovale.trace then Ovale:Print(element.type.." return nil") end return nil @@ -453,7 +466,7 @@ function OvaleBestAction:Compute(element) if isAfter(endA, startB) and isBefore(endA, endB) then startB = endA end - + if Ovale.trace then Ovale:Print(element.type.." return "..tostring(startB)..","..tostring(endB)) end return startB, endB, prioriteB, elementB elseif element.type == "wait" then @@ -461,10 +474,7 @@ function OvaleBestAction:Compute(element) Ovale:Print(element.type.." ["..element.nodeId.."]") end local startA, endA, prioriteA, elementA = self:Compute(element.a) - -- Special priority value as signal for group Compute(). - if prioriteA then - prioriteA = -1 * prioriteA - end + elementA.wait = true if Ovale.trace then Ovale:Print(element.type.." return "..tostring(startA)..","..tostring(endA).." ["..element.nodeId.."]") end return startA, endA, prioriteA, elementA elseif element.type == "not" then @@ -681,18 +691,13 @@ function OvaleBestAction:Compute(element) for k, v in ipairs(element.nodes) do local newStart, newEnd, priorite, nouveauElement = self:Compute(v) - local wait = priorite and priorite < 0 - if wait then - priorite = -1 * priorite - end + if newStart~=nil and newStart