@@ -35,29 +35,40 @@ class BlackboardPreconditionNode : public DecoratorNode
35
35
}
36
36
37
37
private:
38
- virtual BT::NodeStatus tick () override
38
+ virtual BT::NodeStatus tick () override ;
39
+ };
40
+
41
+ // ----------------------------------------------------
42
+
43
+ template <typename T> inline
44
+ NodeStatus BlackboardPreconditionNode<T>::tick()
45
+ {
46
+ std::string key;
47
+ T expected_value;
48
+ T current_value;
49
+
50
+ getParam (" key" , key);
51
+ setStatus (NodeStatus::RUNNING);
52
+
53
+ // check if the key is present in the blackboard
54
+ if ( !blackboard () || !(blackboard ()->contains (key)) )
39
55
{
40
- std::string key;
41
- T expected;
42
- T value;
43
-
44
- setStatus (NodeStatus::RUNNING);
45
-
46
- if (blackboard () && // blackboard not null
47
- getParam (" key" , key) && // parameter key provided
48
- getParam (" expected" , expected) && // parameter expected provided
49
- blackboard ()->get (key, value) && // value found in blackboard
50
- (value == expected ||
51
- initializationParameters ().at (" expected" ) == " *" )) // is expected value or "*"
52
- {
53
- return child_node_->executeTick ();
54
- }
55
- else
56
- {
57
- return NodeStatus::FAILURE;
58
- }
56
+ return NodeStatus::FAILURE;
59
57
}
60
- };
58
+
59
+ if ( initializationParameters ().at (" expected" ) == " *" )
60
+ {
61
+ return child_node_->executeTick ();
62
+ }
63
+
64
+ bool same = ( getParam (" expected" , expected_value) &&
65
+ blackboard ()->get (key, current_value) &&
66
+ current_value == expected_value ) ;
67
+
68
+ return same ? child_node_->executeTick () :
69
+ NodeStatus::FAILURE;
70
+ }
71
+
61
72
}
62
73
63
74
#endif
0 commit comments