Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions addons/beehave/beehave.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ BeehaveTree = "res://addons/beehave/icons/tree.svg"
BeehaveTreeNode = "res://addons/beehave/icons/category_bt.svg"
BeehaveBlackboard = "res://addons/beehave/icons/blackboard.svg"
BeehaveComposite = "res://addons/beehave/icons/category_composite.svg"
BeehaveCompositeRandom = "res://addons/beehave/icons/category_composite.svg"
BeehaveSelector = "res://addons/beehave/icons/selector.svg"
BeehaveSelectorRandom = "res://addons/beehave/icons/selector_random.svg"
BeehaveSelectorReactive = "res://addons/beehave/icons/selector_reactive.svg"
BeehaveSequence = "res://addons/beehave/icons/sequence.svg"
BeehaveSequenceRandom = "res://addons/beehave/icons/sequence_random.svg"
BeehaveSequenceReactive = "res://addons/beehave/icons/sequence_reactive.svg"
BeehaveSequenceStar = "res://addons/beehave/icons/sequence_star.svg"
BeehaveSequenceStar = "res://addons/beehave/icons/sequence_star.svg"
BeehaveSequenceStar = "res://addons/beehave/icons/sequence_reactive.svg"
BeehaveSimpleParallel = "res://addons/beehave/icons/simple_parallel.svg"
BeehaveDecorator = "res://addons/beehave/icons/category_decorator.svg"
BeehaveCooldown = "res://addons/beehave/icons/cooldown.svg"
BeehaveDelayer = "res://addons/beehave/icons/delayer.svg"
Expand Down
13 changes: 13 additions & 0 deletions addons/beehave/icons/simple_parallel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified addons/beehave/libs/windows/beehave.windows.editor.x86_64.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion extension/src/nodes/composites/beehave_composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace godot {

class BeehaveComposite : public BeehaveTreeNode {
GDCLASS(BeehaveComposite, BeehaveTreeNode);
GDCLASS(BeehaveComposite, BeehaveTreeNode);

public:
BeehaveComposite();
Expand Down
68 changes: 68 additions & 0 deletions extension/src/nodes/composites/beehave_composite_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**************************************************************************/
/* beehave_composite_random.cpp */
/**************************************************************************/
/* This file is part of: */
/* BEEHAVE */
/* https://bitbra.in/beehave */
/**************************************************************************/
/* Copyright (c) 2024-present Beehave Contributors. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, 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: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, 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, 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. */
/**************************************************************************/

#include "beehave_composite_random.h"
#include <core/class_db.hpp>
#include <variant/utility_functions.hpp>

using namespace godot;

BeehaveCompositeRandom::BeehaveCompositeRandom():
random_seed(0) {

}

BeehaveCompositeRandom::~BeehaveCompositeRandom() {

}

void BeehaveCompositeRandom::set_random_seed(int random_seed) {
this->random_seed = random_seed;
if (random_seed != 0) UtilityFunctions::seed(random_seed);
else UtilityFunctions::randomize();
}

int BeehaveCompositeRandom::get_random_seed() const {
return random_seed;
}

void BeehaveCompositeRandom::_bind_methods() {
// methods
ClassDB::bind_method(D_METHOD("set_random_seed", "random_seed"), &BeehaveCompositeRandom::set_random_seed);
ClassDB::bind_method(D_METHOD("get_random_seed"), &BeehaveCompositeRandom::get_random_seed);

// exports
ADD_PROPERTY(PropertyInfo(Variant::INT, "random_seed"), "set_random_seed", "get_random_seed");
}

TypedArray<Node> BeehaveCompositeRandom::get_shuffled_children() {
TypedArray<Node> children_bag = get_children().duplicate();
children_bag.shuffle();
return children_bag;
}
61 changes: 61 additions & 0 deletions extension/src/nodes/composites/beehave_composite_random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**************************************************************************/
/* beehave_composite_random.h */
/**************************************************************************/
/* This file is part of: */
/* BEEHAVE */
/* https://bitbra.in/beehave */
/**************************************************************************/
/* Copyright (c) 2024-present Beehave Contributors. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, 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: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, 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, 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. */
/**************************************************************************/

#ifndef BEEHAVE_COMPOSITE_RANDOM_H
#define BEEHAVE_COMPOSITE_RANDOM_H

#include "nodes/composites/beehave_composite.h"
#include <classes/node.hpp>

namespace godot {

class BeehaveCompositeRandom : public BeehaveComposite {
GDCLASS(BeehaveCompositeRandom, BeehaveComposite);

protected:
// Sets a predictable seed.
int random_seed;

// TODO: Add weights back in.

public:
BeehaveCompositeRandom();
~BeehaveCompositeRandom();

void set_random_seed(int random_seed);
int get_random_seed() const;

protected:
static void _bind_methods();

TypedArray<Node> get_shuffled_children();
};
} //namespace godot

#endif //BEEHAVE_COMPOSITE_RANDOM_H
76 changes: 76 additions & 0 deletions extension/src/nodes/composites/beehave_selector_random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**************************************************************************/
/* beehave_selector_random.cpp */
/**************************************************************************/
/* This file is part of: */
/* BEEHAVE */
/* https://bitbra.in/beehave */
/**************************************************************************/
/* Copyright (c) 2024-present Beehave Contributors. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, 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: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, 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, 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. */
/**************************************************************************/

#include "beehave_selector_random.h"
#include <variant/utility_functions.hpp>

using namespace godot;

BeehaveSelectorRandom::BeehaveSelectorRandom() {
if (random_seed == 0) {
UtilityFunctions::randomize();
}
}

BeehaveSelectorRandom::~BeehaveSelectorRandom() {

}

void BeehaveSelectorRandom::_bind_methods() {

}

BeehaveTickStatus BeehaveSelectorRandom::tick(Ref<BeehaveContext> context) {
if (_children_bag.is_empty()) {
_children_bag = get_shuffled_children();
}

// Since we're going to remove children from the array, iterate it in reverse order.
for (int i = _children_bag.size() -1; i >= 0; --i) {
BeehaveTreeNode *child = cast_node(Object::cast_to<Node>(_children_bag[i]));
if (child == nullptr) {
// skip anything that is not a valid beehave node
continue;
}
BeehaveTickStatus response = child->tick(context);

switch (response) {
case SUCCESS:
// TODO: introduce after_run mechanism
_children_bag.erase(child);
return SUCCESS;
case FAILURE:
_children_bag.erase(child);
break;
case RUNNING:
return RUNNING;
}
}
return BeehaveTickStatus::FAILURE;
}
55 changes: 55 additions & 0 deletions extension/src/nodes/composites/beehave_selector_random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**************************************************************************/
/* beehave_selector_random.h */
/**************************************************************************/
/* This file is part of: */
/* BEEHAVE */
/* https://bitbra.in/beehave */
/**************************************************************************/
/* Copyright (c) 2024-present Beehave Contributors. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, 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: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, 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, 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. */
/**************************************************************************/

#ifndef BEEHAVE_SELECTOR_RANDOM_H
#define BEEHAVE_SELECTOR_RANDOM_H

#include "nodes/composites/beehave_composite_random.h"
#include <classes/node.hpp>

namespace godot {

class BeehaveSelectorRandom : public BeehaveCompositeRandom {
GDCLASS(BeehaveSelectorRandom, BeehaveCompositeRandom);

protected:
static void _bind_methods();

public:
BeehaveSelectorRandom();
~BeehaveSelectorRandom();

BeehaveTickStatus tick(Ref<BeehaveContext> context);

private:
TypedArray<Node> _children_bag;
};
}// namespace godot

#endif // BEEHAVE_SELECTOR_RANDOM_H
67 changes: 67 additions & 0 deletions extension/src/nodes/composites/beehave_selector_reactive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**************************************************************************/
/* beehave_selector_reactive.cpp */
/**************************************************************************/
/* This file is part of: */
/* BEEHAVE */
/* https://bitbra.in/beehave */
/**************************************************************************/
/* Copyright (c) 2024-present Beehave Contributors. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, 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: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, 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, 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. */
/**************************************************************************/

#include "beehave_selector_reactive.h"

using namespace godot;

BeehaveSelectorReactive::BeehaveSelectorReactive() {

}

BeehaveSelectorReactive::~BeehaveSelectorReactive() {

}

void BeehaveSelectorReactive::_bind_methods() {

}

BeehaveTickStatus BeehaveSelectorReactive::tick(Ref<BeehaveContext> context) {
TypedArray<Node> children = get_children();
for (int i = 0; i < children.size(); ++i) {
BeehaveTreeNode *child = cast_node(Object::cast_to<Node>(children[i]));
if (child == nullptr) {
// skip anything that is not a valid beehave node
continue;
}
BeehaveTickStatus response = child->tick(context);

switch (response) {
case SUCCESS:
// TODO: introduce after_run mechanism
return SUCCESS;
case FAILURE:
break;
case RUNNING:
return RUNNING;
}
}
return BeehaveTickStatus::FAILURE;
}
Loading
Loading