Add/Get name for nodes in behaviour tree

This commit is contained in:
2024-01-10 07:45:26 +01:00
parent 113ac72181
commit 3b77d5cdcf
3 changed files with 16 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ struct BzBTNode {
BzBTNode *next;
BzBTNodeType type;
const char *name;
union {
struct {
i32 n;
@@ -24,10 +25,8 @@ struct BzBTNode {
} delay;
struct {
BzBTActionFn fn;
const char *name;
} action;
} as;
};
struct BzBTNodeState {
@@ -167,14 +166,19 @@ BzBTNode *bzBTDecorDelay(BzObjectPool *nodePool, BzBTNode *parent, f32 ms) {
return node;
}
BzBTNode *bzBTAction(BzObjectPool *nodePool, BzBTNode *parent, BzBTActionFn fn,
const char *name) {
BzBTNode *bzBTAction(BzObjectPool *nodePool, BzBTNode *parent, BzBTActionFn fn) {
BzBTNode *node = bzBTNodeMake(nodePool, parent, BZ_BT_ACTION);
node->as.action.fn = fn;
node->as.action.name = name;
return node;
}
void bzBTNodeSetName(BzBTNode *node, const char *name) {
node->name = name;
}
const char *bzBTNodeGetName(const BzBTNode *node) {
return node->name;
}
i32 bzBTDecorGetRepeat(const BzBTNode *node) {
BZ_ASSERT(node->type == BZ_BT_DECOR_REPEAT);
return node->as.repeat.n;
@@ -188,10 +192,6 @@ BzBTActionFn bzBTActionGetFn(const BzBTNode *node) {
BZ_ASSERT(node->type == BZ_BT_ACTION);
return node->as.action.fn;
}
const char *bzBTActionGetName(const BzBTNode *node) {
BZ_ASSERT(node->type == BZ_BT_ACTION);
return node->as.action.name;
}
BzBTNodeType bzBTGetNodeType(const BzBTNode *node) {
return node->type;