mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-27 19:21:11 +00:00
23 lines
608 B
Lua
23 lines
608 B
Lua
BTNodeType = {SELECTOR = 0, SEQUENCE = 1, FUNCTION = 2}
|
|
|
|
function executeBtNode(agent, btNode)
|
|
for i = 1, #btNode.children do
|
|
if btNode.children[i].type == BTNodeType.FUNCTION then
|
|
func = btNode.children[i].func
|
|
res = agent[func](agent)
|
|
else
|
|
res = executeBtNode(agent, btNode.children[i])
|
|
end
|
|
|
|
if btNode.type == BTNodeType.SELECTOR then
|
|
if res then return true end
|
|
|
|
if i == #btNode.children and not res then return false end
|
|
elseif btNode.type == BTNodeType.SEQUENCE then
|
|
if not res then return false end
|
|
|
|
if i == #btNode.children and res then return true end
|
|
end
|
|
end
|
|
end
|