| 26 | } |
| 27 | |
| 28 | NodeStatus WhileDoElseNode::tick() |
| 29 | { |
| 30 | const size_t children_count = children_nodes_.size(); |
| 31 | |
| 32 | if(children_count != 2 && children_count != 3) |
| 33 | { |
| 34 | throw std::logic_error("WhileDoElseNode must have either 2 or 3 children"); |
| 35 | } |
| 36 | |
| 37 | setStatus(NodeStatus::RUNNING); |
| 38 | |
| 39 | const NodeStatus condition_status = children_nodes_[0]->executeTick(); |
| 40 | |
| 41 | if(condition_status == NodeStatus::RUNNING) |
| 42 | { |
| 43 | return condition_status; |
| 44 | } |
| 45 | |
| 46 | NodeStatus status = NodeStatus::IDLE; |
| 47 | |
| 48 | if(condition_status == NodeStatus::SUCCESS) |
| 49 | { |
| 50 | if(children_count == 3) |
| 51 | { |
| 52 | haltChild(2); |
| 53 | } |
| 54 | status = children_nodes_[1]->executeTick(); |
| 55 | } |
| 56 | else if(condition_status == NodeStatus::FAILURE) |
| 57 | { |
| 58 | if(children_count == 3) |
| 59 | { |
| 60 | haltChild(1); |
| 61 | status = children_nodes_[2]->executeTick(); |
| 62 | } |
| 63 | else if(children_count == 2) |
| 64 | { |
| 65 | status = NodeStatus::FAILURE; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if(status == NodeStatus::RUNNING) |
| 70 | { |
| 71 | return NodeStatus::RUNNING; |
| 72 | } |
| 73 | resetChildren(); |
| 74 | return status; |
| 75 | } |
| 76 | |
| 77 | } // namespace BT |
nothing calls this directly
no test coverage detected