Behavior tree retry node: support retrying a fixed number of times

This commit is contained in:
Nikita Lisitsa 2021-10-30 13:14:02 +03:00
parent 25c93a7699
commit 8571bc9c6d

View file

@ -565,13 +565,17 @@ namespace psemek::util
struct retry
{
Child child;
std::optional<int> max_count;
int count;
retry(Child child)
retry(Child child, std::optional<int> max_count = std::nullopt)
: child(std::move(child))
, max_count(max_count)
{}
void start(Args ... args)
{
count = 0;
child.start(args...);
}
@ -584,7 +588,10 @@ namespace psemek::util
return finished{true};
else
{
start(args...);
++count;
if (max_count && count == *max_count)
return finished{false};
child.start(args...);
return running{};
}
}