Quantcast

Add a "wait" statement to interrupt evaluation of a group.

Johnny C. Lam [12-13-12 - 03:52]
Add a "wait" statement to interrupt evaluation of a group.

The syntax is "wait <node>" that returns the given node.  If part of a
group node, then it causes the group to evaluate to the best node of the
group up to and including the wait statement.

A "wait" node has the same priority as its child node.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@661 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleBestAction.lua
OvaleCompile.lua
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index 705001b..998c377 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -456,6 +456,17 @@ function OvaleBestAction:Compute(element)

 		if Ovale.trace then Ovale:Print(element.type.." return "..tostring(startB)..","..tostring(endB)) end
 		return startB, endB, prioriteB, elementB
+	elseif element.type == "wait" then
+		if (Ovale.trace) then
+			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
+		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
 		local startA, endA = self:ComputeBool(element.a)
 		if startA then
@@ -670,6 +681,10 @@ 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<OvaleState.currentTime then
 				newStart = OvaleState.currentTime
 			end
@@ -719,6 +734,8 @@ function OvaleBestAction:Compute(element)
 					bestCastTime = newCastTime
 				end
 			end
+			-- If the node is a "wait" node, then skip the remaining nodes.
+			if wait then break end
 		end

 		if (meilleurTempsFils) then
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index b7657f7..4798f67 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -329,6 +329,11 @@ local function ParseUnless(a, b)
 	return AddNode(newNode)
 end

+local function ParseWait(a)
+	local newNode = {type="wait", a=node[tonumber(a)]}
+	return AddNode(newNode)
+end
+
 local function ParseAnd(a,b)
 	local newNode = {type="and", a=node[tonumber(a)], b=node[tonumber(b)]}
 	return AddNode(newNode)
@@ -486,6 +491,7 @@ local function ParseCommands(text)
 		text = strgsub(text, "node(%d+)%s+or%s+node(%d+)", ParseOr)
 		text = strgsub(text, "if%s+node(%d+)%s+node(%d+)",ParseIf)
 		text = strgsub(text, "unless%s+node(%d+)%s+node(%d+)",ParseUnless)
+		text = strgsub(text, "wait%s+node(%d+)",ParseWait)
 		text = strgsub(text, "{([node%d ]*)}", ParseGroup)
 		if (was == text) then
 			break
@@ -666,6 +672,8 @@ function OvaleCompile:DebugNode(node)
 		text = "if "..self:DebugNode(node.a).." "..self:DebugNode(node.b)
 	elseif (node.type == "unless") then
 		text = "unless "..self:DebugNode(node.a).." "..self:DebugNode(node.b)
+	elseif (node.type == "wait") then
+		text = "wait "..self:DebugNode(node.a)
 	elseif (node.type == "and") then
 		text = self:DebugNode(node.a).." and "..self:DebugNode(node.b)
 	elseif (node.type == "or") then