BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
force_success_node.h
1/* Copyright (C) 2018-2025 Davide Faconti, Eurecat - All Rights Reserved
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7*
8* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11*/
12
13#pragma once
14
15#include "behaviortree_cpp/decorator_node.h"
16
17namespace BT
18{
19/**
20 * @brief The ForceSuccessNode always returns SUCCESS when the child completes,
21 * regardless of whether the child returned SUCCESS or FAILURE.
22 *
23 * - If the child returns RUNNING, this node returns RUNNING.
24 * - If the child returns SUCCESS or FAILURE, this node returns SUCCESS.
25 */
27{
28public:
29 ForceSuccessNode(const std::string& name) : DecoratorNode(name, {})
30 {
31 setRegistrationID("ForceSuccess");
32 }
33
34private:
35 virtual BT::NodeStatus tick() override;
36};
37
38//------------ implementation ----------------------------
39
40inline NodeStatus ForceSuccessNode::tick()
41{
42 setStatus(NodeStatus::RUNNING);
43
44 const NodeStatus child_status = child_node_->executeTick();
45
46 if(isStatusCompleted(child_status))
47 {
48 resetChild();
49 return NodeStatus::SUCCESS;
50 }
51
52 // RUNNING or skipping
53 return child_status;
54}
55} // namespace BT
The DecoratorNode is the base class for nodes that have exactly one child.
Definition: decorator_node.h:19
The ForceSuccessNode always returns SUCCESS when the child completes, regardless of whether the child...
Definition: force_success_node.h:27
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
void setStatus(NodeStatus new_status)
setStatus changes the status of the node. it will throw if you try to change the status to IDLE,...
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34